From: <wi...@us...> - 2012-08-29 00:01:20
|
Revision: 22092 http://jedit.svn.sourceforge.net/jedit/?rev=22092&view=rev Author: wingser Date: 2012-08-29 00:01:13 +0000 (Wed, 29 Aug 2012) Log Message: ----------- add pth support, remove useless args options Modified Paths: -------------- plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionConfiguration.java plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionPlugin.java plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionProvider.java Modified: plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionConfiguration.java =================================================================== --- plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionConfiguration.java 2012-08-28 18:47:01 UTC (rev 22091) +++ plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionConfiguration.java 2012-08-29 00:01:13 UTC (rev 22092) @@ -6,7 +6,7 @@ import java.util.concurrent.Callable; import java.util.HashMap; import java.util.Vector; - +import java.io.*; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JFileChooser; @@ -23,22 +23,25 @@ import org.gjt.sp.jedit.OptionPane; import org.gjt.sp.jedit.jEdit; import org.gjt.sp.jedit.gui.RolloverButton; +import org.gjt.sp.jedit.View; +import org.gjt.sp.jedit.browser.VFSBrowser; +import org.gjt.sp.jedit.browser.VFSFileChooserDialog; import projectviewer.ProjectManager; import projectviewer.config.OptionsService; import projectviewer.vpt.VPTProject; - +import projectviewer.ProjectViewer; public class ClangCompletionConfiguration extends AbstractOptionPane { public static final String DEFINITIONS = "CLANG_DEFINITIONS"; public static final String INCLUDES = "CLANG_INCLUDES"; - public static final String ARGUMENTS = "CLANG_ARGUMENTS"; + public static final String PRECOMPILEDS = "CLANG_PRECOMPILEDS"; - private JList definitions, includes, arguments; + private JList definitions, includes, precompileds; - private DefaultListModel definitionModel, includesModel, argumentsModel; + private DefaultListModel definitionModel, includesModel, precompiledsModel; private VPTProject project; @@ -71,12 +74,12 @@ }); addSeparator(); - argumentsModel = getListModel(ARGUMENTS); - arguments = createList("Other Arguments:", argumentsModel, new Callable<String>() + precompiledsModel = getListModel(PRECOMPILEDS); + precompileds = createListPrecompileds("Pre-compiled headers:", precompiledsModel, new Callable<String>() { public String call() { - return ShowInputArgumentDialog(); + return ShowInputPrecompiledsDialog(); } }); addSeparator(); @@ -127,6 +130,81 @@ } } + private void clearPthBuffer() + { + View view = jEdit.getActiveView(); + VPTProject project = ProjectViewer.getActiveProject(view); + File filePth = new File(ClangCompletionPlugin.pluginHome, project.getName()+".pth"); + System.out.println(filePth); + filePth.delete(); + } + + private JList createListPrecompileds(String title, final DefaultListModel model, final Callable<String> callable) + { + addComponent(new JLabel(title)); + final JList list = new JList(model); + addComponent(new JScrollPane(list), GridBagConstraints.HORIZONTAL); + JPanel buttons = new JPanel(); + JButton add = new RolloverButton(GUIUtilities.loadIcon("Plus.png")); + add.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + try + { + String s = callable.call(); + if (s != null) + { + int index = list.getSelectedIndex(); + model.add(index + 1, s); + list.setSelectedIndex(index + 1); + + clearPthBuffer(); + } + }catch(Exception ex) + { + ex.printStackTrace(); + } + } + }); + JButton remove = new RolloverButton(GUIUtilities.loadIcon("Minus.png")); + remove.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + int index = list.getSelectedIndex(); + if (index >= 0) + { + model.removeElementAt(index); + if (index < model.size()) + { + list.setSelectedIndex(index); + }else if (! model.isEmpty()) + { + list.setSelectedIndex(model.size() - 1); + } + clearPthBuffer(); + } + } + }); + + + JButton refresh = new RolloverButton(GUIUtilities.loadIcon("Clear.png")); + refresh.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + clearPthBuffer(); + } + }); + + buttons.add(add); + buttons.add(remove); + buttons.add(refresh); + addComponent(buttons); + return list; + } + private JList createList(String title, final DefaultListModel model, final Callable<String> callable) { addComponent(new JLabel(title)); @@ -172,16 +250,28 @@ } } }); + + buttons.add(add); buttons.add(remove); addComponent(buttons); return list; } - private String ShowInputArgumentDialog() + private String ShowInputPrecompiledsDialog() { - return (String) JOptionPane.showInputDialog(this, "Input argument:", "Arguments", - JOptionPane.QUESTION_MESSAGE); + View view = jEdit.getActiveView(); + String path = jEdit.getProperty("projectviewer.filechooser.directory", + System.getProperty("user.home")); + String [] result = GUIUtilities.showVFSFileDialog(GUIUtilities.getParentDialog(this), + view, path, VFSBrowser.OPEN_DIALOG, false); + if(result != null && result.length > 0) + { + return result[0]; + }else + { + return null; + } } private String ShowInputDefinitionDialog() @@ -192,16 +282,18 @@ private String showIncludeSelectionDialog() { - JFileChooser fc = new JFileChooser(); - fc.setDialogTitle("Select include path"); - fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - int ret = fc.showOpenDialog(this); - if (ret != JFileChooser.APPROVE_OPTION) + View view = jEdit.getActiveView(); + String path = jEdit.getProperty("projectviewer.filechooser.directory", + System.getProperty("user.home")); + String [] result = GUIUtilities.showVFSFileDialog(GUIUtilities.getParentDialog(this), + view, path, VFSBrowser.CHOOSE_DIRECTORY_DIALOG, false); + if(result != null && result.length > 0) { - return null; + return result[0]; + }else + { + return null; } - String dir = fc.getSelectedFile().getAbsolutePath(); - return MiscUtilities.resolveSymlinks(dir); } @Override @@ -209,7 +301,7 @@ { setListModel(DEFINITIONS, definitionModel); setListModel(INCLUDES, includesModel); - setListModel(ARGUMENTS, argumentsModel); + setListModel(PRECOMPILEDS, precompiledsModel); } public static Vector<String> getListProperty(VPTProject project, String propertyName) @@ -246,8 +338,8 @@ Vector<String> includes = getListProperty(project, INCLUDES); map.put(INCLUDES, includes); - Vector<String> arguments = getListProperty(project, ARGUMENTS); - map.put(ARGUMENTS, arguments); + Vector<String> precompileds = getListProperty(project, PRECOMPILEDS); + map.put(PRECOMPILEDS, precompileds); return map; } Modified: plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionPlugin.java =================================================================== --- plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionPlugin.java 2012-08-28 18:47:01 UTC (rev 22091) +++ plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionPlugin.java 2012-08-29 00:01:13 UTC (rev 22092) @@ -1,5 +1,6 @@ package clangcompletion; //{{{ Imports +import java.io.*; import org.gjt.sp.jedit.EditPlugin; import errorlist.ErrorSource; import errorlist.DefaultErrorSource; @@ -8,8 +9,14 @@ public class ClangCompletionPlugin extends EditPlugin { public static DefaultErrorSource errorSrc; + + public static File pluginHome; + public void start() { + pluginHome = getPluginHome(); + pluginHome.mkdirs(); + new BufferWatcher(); if(errorSrc == null) { Modified: plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionProvider.java =================================================================== --- plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionProvider.java 2012-08-28 18:47:01 UTC (rev 22091) +++ plugins/ClangCompletion/trunk/src/clangcompletion/ClangCompletionProvider.java 2012-08-29 00:01:13 UTC (rev 22092) @@ -1,6 +1,6 @@ package clangcompletion; //{{{ Imports -import java.io.BufferedReader; +import java.io.*; import java.io.InputStreamReader; import java.io.IOException; import java.util.ArrayList; @@ -140,16 +140,24 @@ args.add("-D" +definitions.get(i) ); } } + tryGeneratePth(project); + File filePth = new File(ClangCompletionPlugin.pluginHome, project.getName()+".pth"); + if(filePth.exists()) + { + args.add("-include-pth"); + args.add(filePth.getPath() ); + } + /* Vector<String> arguments = properties.get(ClangCompletionConfiguration.ARGUMENTS); if(arguments != null) { - for(int i = 0; i < arguments.size(); i++) - { - args.add(arguments.get(i)); - } + for(int i = 0; i < arguments.size(); i++) + { + args.add(arguments.get(i)); } - + } + */ List<CompletionCandidate> codeCompletions = new ArrayList<CompletionCandidate>(); StringBuilder cmd = new StringBuilder(); @@ -223,5 +231,70 @@ return completionModes; } - + private void tryGeneratePth(VPTProject project) + { + File filePth = new File(ClangCompletionPlugin.pluginHome, project.getName()+".pth"); + if(!filePth.exists()) + { + HashMap<String, Vector<String>> properties = ClangCompletionConfiguration.getProperties(project.getName()); + + + ArrayList<String> args = new ArrayList<String>(); + args.add("clang"); + args.add("-cc1"); + args.add("-w"); + + Vector<String> precompileds = properties.get(ClangCompletionConfiguration.PRECOMPILEDS); + if(precompileds != null) + { + for(int i = 0; i < precompileds.size(); i++) + { + args.add(precompileds.get(i) ); + } + } + args.add("-emit-pth"); + args.add("-o"); + args.add(filePth.getPath()); + + + Vector<String> includes = properties.get(ClangCompletionConfiguration.INCLUDES); + if(includes != null) + { + for(int i = 0; i < includes.size(); i++) + { + args.add("-I" +includes.get(i) ); + } + } + + + + Vector<String> definitions = properties.get(ClangCompletionConfiguration.DEFINITIONS); + if(definitions != null) + { + for(int i = 0; i < definitions.size(); i++) + { + args.add("-D" +definitions.get(i) ); + } + } + + args.add("-x"); + args.add("c++-header"); + + StringBuilder cmd = new StringBuilder(); + for(int i = 0; i < args.size();i++) + { + cmd.append(args.get(i) +" "); + } + System.out.println(cmd); + + try + { + String [] argsArr = new String[args.size()]; + args.toArray(argsArr); + Process process = Runtime.getRuntime().exec(argsArr); + }catch(IOException ex) + { + } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |