📄 jedit.java
字号:
} /** * Resets a property to its default value. * @param name The property * * @since jEdit 2.5pre3 */ public static final void resetProperty(String name) { props.remove(name); } /** * Reloads various settings from the properties. */ public static void propertiesChanged() { initKeyBindings(); int interval; try { interval = Integer.parseInt(getProperty("autosave")); } catch(NumberFormatException nf) { //Log.log(Log.ERROR,jEdit.class,nf); interval = 30; } Autosave.setInterval(interval); saveCaret = getBooleanProperty("saveCaret"); UIDefaults defaults = UIManager.getDefaults(); // give all Swing components our colors if(jEdit.getBooleanProperty("globalColors")) { Color background = new javax.swing.plaf.ColorUIResource( GUIUtilities.parseColor( jEdit.getProperty("view.bgColor"))); Color foreground = new javax.swing.plaf.ColorUIResource( GUIUtilities.parseColor( jEdit.getProperty("view.fgColor"))); Color caretColor = new javax.swing.plaf.ColorUIResource( GUIUtilities.parseColor( jEdit.getProperty("view.caretColor"))); Color selectionColor = new javax.swing.plaf.ColorUIResource( GUIUtilities.parseColor( jEdit.getProperty("view.selectionColor"))); String[] prefixes = { "TextField", "TextArea", "List", "Table" }; for(int i = 0; i < prefixes.length; i++) { String prefix = prefixes[i]; defaults.put(prefix + ".disabledBackground",background); defaults.put(prefix + ".background",background); defaults.put(prefix + ".disabledForeground",foreground); defaults.put(prefix + ".foreground",foreground); defaults.put(prefix + ".caretForeground",caretColor); defaults.put(prefix + ".selectionForeground",foreground); defaults.put(prefix + ".selectionBackground",selectionColor); //defaults.put(prefix + ".inactiveForeground",foreground); } defaults.put("Tree.background",background); defaults.put("Tree.foreground",foreground); defaults.put("Tree.textBackground",background); defaults.put("Tree.textForeground",foreground); defaults.put("Tree.selectionForeground",foreground); defaults.put("Tree.selectionBackground",selectionColor); } // give all text fields and text areas the same font String family = jEdit.getProperty("view.font"); int size; try { size = Integer.parseInt(jEdit.getProperty( "view.fontsize")); } catch(NumberFormatException nf) { size = 14; } int style; try { style = Integer.parseInt(jEdit.getProperty( "view.fontstyle")); } catch(NumberFormatException nf) { style = Font.PLAIN; } Font font = new Font(family,style,size); //defaults.put("TextField.font",font); defaults.put("TextArea.font",font); defaults.put("TextPane.font",font); EditBus.send(new PropertiesChanged(null)); } /** * Returns a list of plugin JARs that are not currently loaded * by examining the user and system plugin directories. * @since jEdit 3.2pre1 */ public static String[] getNotLoadedPluginJARs() { Vector returnValue = new Vector(); if(jEditHome != null) { String systemPluginDir = MiscUtilities .constructPath(jEditHome,"jars"); String[] list = new File(systemPluginDir).list(); if(list != null) getNotLoadedPluginJARs(returnValue,systemPluginDir,list); } if(settingsDirectory != null) { String userPluginDir = MiscUtilities .constructPath(settingsDirectory,"jars"); String[] list = new File(userPluginDir).list(); if(list != null) { getNotLoadedPluginJARs(returnValue, userPluginDir,list); } } String[] _returnValue = new String[returnValue.size()]; returnValue.copyInto(_returnValue); return _returnValue; } /** * Returns the plugin with the specified class name. */ public static EditPlugin getPlugin(String name) { EditPlugin[] plugins = getPlugins(); for(int i = 0; i < plugins.length; i++) { if(plugins[i].getClassName().equals(name)) return plugins[i]; } return null; } /** * Returns an array of installed plugins. */ public static EditPlugin[] getPlugins() { Vector vector = new Vector(); for(int i = 0; i < jars.size(); i++) { ((EditPlugin.JAR)jars.elementAt(i)).getPlugins(vector); } plugins.getPlugins(vector); EditPlugin[] array = new EditPlugin[vector.size()]; vector.copyInto(array); return array; } /** * Returns an array of installed plugins. * @since jEdit 2.5pre3 */ public static EditPlugin.JAR[] getPluginJARs() { EditPlugin.JAR[] array = new EditPlugin.JAR[jars.size()]; jars.copyInto(array); return array; } /** * Returns the JAR with the specified path name. * @param path The path name * @since jEdit 2.6pre1 */ public static EditPlugin.JAR getPluginJAR(String path) { for(int i = 0; i < jars.size(); i++) { EditPlugin.JAR jar = (EditPlugin.JAR)jars.elementAt(i); if(jar.getPath().equals(path)) return jar; } return null; } /** * Adds a plugin JAR to the editor. * @param plugin The plugin * @since jEdit 3.2pre10 */ public static void addPluginJAR(EditPlugin.JAR plugin) { jars.addElement(plugin); } /** * Plugins should not be calling this method. */ public static void addAction(EditAction action) { actionHash.put(action.getName(),action); } /** * Returns a named action. * @param action The action */ public static EditAction getAction(String action) { return (EditAction)actionHash.get(action); } /** * Returns the list of actions registered with the editor. */ public static EditAction[] getActions() { EditAction[] actions = new EditAction[actionHash.size()]; Enumeration enum = actionHash.elements(); int i = 0; while(enum.hasMoreElements()) { actions[i++] = (EditAction)enum.nextElement(); } return actions; } /** * Reloads all edit modes. * @since jEdit 3.2pre2 */ public static void reloadModes() { /* Try to guess the eventual size to avoid unnecessary * copying */ modes = new Vector(50); // load the global catalog if(jEditHome == null) loadModeCatalog("/modes/catalog",true); else { loadModeCatalog(MiscUtilities.constructPath(jEditHome, "modes","catalog"),false); } // load user catalog if(settingsDirectory != null) { File userModeDir = new File(MiscUtilities.constructPath( settingsDirectory,"modes")); if(!userModeDir.exists()) userModeDir.mkdirs(); File userCatalog = new File(MiscUtilities.constructPath( settingsDirectory,"modes","catalog")); if(!userCatalog.exists()) { // create dummy catalog try { FileWriter out = new FileWriter(userCatalog); out.write(jEdit.getProperty("defaultCatalog")); out.close(); } catch(IOException io) { Log.log(Log.ERROR,jEdit.class,io); } } loadModeCatalog(userCatalog.getPath(),false); } Buffer buffer = buffersFirst; while(buffer != null) { // This reloads the token marker and sends a message // which causes edit panes to repaint their text areas buffer.setMode(); buffer = buffer.next; } } /** * Returns the edit mode with the specified name. * @param name The edit mode */ public static Mode getMode(String name) { for(int i = 0; i < modes.size(); i++) { Mode mode = (Mode)modes.elementAt(i); if(mode.getName().equals(name)) return mode; } return null; } /** * Returns an array of installed edit modes. */ public static Mode[] getModes() { Mode[] array = new Mode[modes.size()]; modes.copyInto(array); return array; } /** * Displays the open file dialog box, and opens any selected files. * * @param view The view * @since jEdit 2.7pre2 */ public static void showOpenFileDialog(View view) { showOpenFileDialog(view,null); } /** * Displays the open file dialog box, and opens any selected files, * but first prompts for a character encoding to use. * * @param view The view * @since jEdit 2.7pre2 */ public static void showOpenFileWithOtherEncodingDialog(View view) { String encoding = GUIUtilities.input(view,"encoding-prompt",null, jEdit.getProperty("buffer.encoding", System.getProperty("file.encoding"))); if(encoding == null) return; Macros.Recorder recorder = view.getMacroRecorder(); if(recorder != null) { recorder.record("props = new Hashtable();"); recorder.record("props.put(\"encoding\",\"" + encoding + "\");"); recorder.record("jEdit.showOpenFileDialog(view,props);"); } Hashtable props = new Hashtable(); props.put(Buffer.ENCODING,encoding); showOpenFileDialog(view,props); } /** * Displays the open file dialog box, and opens any selected files, * setting the properties specified in the hash table in the buffers. * * @param view The view * @param props The properties to set in the buffer * @since jEdit 3.2pre2 */ public static void showOpenFileDialog(View view, Hashtable props) { String[] files = GUIUtilities.showVFSFileDialog(view,null, VFSBrowser.OPEN_DIALOG,true); Buffer buffer = null; if(files != null) { for(int i = 0; i < files.length; i++) { Buffer newBuffer = openFile(null,null,files[i], false,props); if(newBuffer != null) buffer = newBuffer; } } if(buffer != null) view.setBuffer(buffer); } /** * Opens files that were open last time. * @since jEdit 3.2pre2 */ public static String restoreOpenFiles() { if(settingsDirectory == null) return null; File session = new File(MiscUtilities.constructPath( settingsDirectory,"session")); if(!session.exists()) return null; String splitConfig = null; try { BufferedReader in = new BufferedReader(new FileReader( session)); String line; while((line = in.readLine()) != null) { if(line.startsWith("splits\t")) splitConfig = line.substring(7); else openFile(null,line); } in.close(); } catch(IOException io) { Log.log(Log.ERROR,jEdit.class,"Error while loading " + session); Log.log(Log.ERROR,jEdit.class,io); } return splitConfig; } /** * Saves the list of open files. * @since jEdit 3.1pre5 */ public static void saveOpenFiles(View view) { if(settingsDirectory == null) return; view.getEditPane().saveCaretInfo(); Buffer current = view.getBuffer(); File session = new File(MiscUtilities.constructPath( settingsDirectory,"session")); try { String lineSep = System.getProperty("line.separator"); BufferedWriter out = new BufferedWriter(new FileWriter( session)); Buffer buffer = buffersFirst; while(buffer != null) { out.write(buffer.getPath()); out.write(lineSep); buffer = buffer.next; } out.write("splits\t"); out.write(view.getSplitConfig()); out.write(lineSep); out.close(); } catch(IOException io) { Log.log(Log.ERROR,jEdit.class,"Error while saving " + session); Log.log(Log.ERROR,jEdit.class,io); } } /** * Opens the file names specified in the argument array. This * handles +line and +marker arguments just like the command * line parser. * @param parent The parent directory * @param args The file names to open * @since jEdit 3.2pre4 */ public static Buffer openFiles(View view, String parent, String[] args) { Buffer retVal = null; Buffer lastBuffer = null; for(int i = 0; i < args.length; i++) { String arg = args[i]; if(arg == null) continue; else if(arg.startsWith("+line:") || arg.startsWith("+marker:")) { if(lastBuffer != null) gotoMarker(view,lastBuffer,arg); continue; } lastBuffer = openFile(null,parent,arg,false,null); if(retVal == null && lastBuffer != null) retVal = lastBuffer; } if(view != null && retVal != null) view.setBuffer(retVal); return retVal; } /** * Opens a file. Note that as of jEdit 2.5pre1, this may return * null if the buffer could not be opened. * @param view The view to open the file in * @param path The file path * * @since jEdit 2.4pre1 */ public static Buffer openFile(View view, String path) { return openFile(view,null,path,false,new Hashtable()); } /** * @deprecated The openFile() forms with the readOnly parameter * should not be used. The readOnly prameter is no longer supported. */ public static Buffer openFile(View view, String parent, String path, boolean readOnly, boolean newFile) { return openFile(view,parent,path,newFile,new Hashtable()); } /** * @deprecated The openFile() forms with the readOnly parameter * should not be used. The readOnly prameter is no longer supported. */ public static Buffer openFile(View view, String parent, String path, boolean readOnly, boolean newFile, Hashtable props) { return openFile(view,parent,path,newFile,props); } /** * Opens a file. Note that as of jEdit 2.5pre1, this may return * null if the buffer could not be opened. * @param view The view to open the file in * @param parent The parent directory of the file * @param path The path name of the file * @param newFile True if the file should not be loaded from disk * be prompted if it should be reloaded * @param props Buffer-local properties to set in the buffer * * @since jEdit 3.2pre10 */ public static Buffer openFile(final View view, String parent, String path, boolean newFile, Hashtable props)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -