📄 jedit.java
字号:
else { jar.uninit(false); jars.removeElement(jar); initKeyBindings(); } EditBus.send(new PluginUpdate(jar,PluginUpdate.UNLOADED,exit)); if(!isMainThread() && !exit) EditBus.send(new DynamicMenuChanged("plugins")); } //}}} //}}} //{{{ Action methods //{{{ getActionContext() method /** * Returns the action context used to store editor actions. * @since jEdit 4.2pre1 */ public static ActionContext getActionContext() { return actionContext; } //}}} //{{{ addActionSet() method /** * Adds a new action set to jEdit's list. Plugins probably won't * need to call this method. * @since jEdit 4.0pre1 */ public static void addActionSet(ActionSet actionSet) { actionContext.addActionSet(actionSet); } //}}} //{{{ removeActionSet() method /** * Removes an action set from jEdit's list. Plugins probably won't * need to call this method. * @since jEdit 4.2pre1 */ public static void removeActionSet(ActionSet actionSet) { actionContext.removeActionSet(actionSet); } //}}} //{{{ getBuiltInActionSet() method /** * Returns the set of commands built into jEdit. * @since jEdit 4.2pre1 */ public static ActionSet getBuiltInActionSet() { return builtInActionSet; } //}}} //{{{ getActionSets() method /** * Returns all registered action sets. * @since jEdit 4.0pre1 */ public static ActionSet[] getActionSets() { return actionContext.getActionSets(); } //}}} //{{{ getAction() method /** * Returns the specified action. * @param name The action name */ public static EditAction getAction(String name) { return actionContext.getAction(name); } //}}} //{{{ getActionSetForAction() method /** * Returns the action set that contains the specified action. * * @param action The action * @since jEdit 4.2pre1 */ public static ActionSet getActionSetForAction(String action) { return actionContext.getActionSetForAction(action); } //}}} //{{{ getActionSetForAction() method /** * @deprecated Use the form that takes a String instead */ public static ActionSet getActionSetForAction(EditAction action) { return actionContext.getActionSetForAction(action.getName()); } //}}} //{{{ getActions() method /** * @deprecated Call getActionNames() instead */ public static EditAction[] getActions() { String[] names = actionContext.getActionNames(); EditAction[] actions = new EditAction[names.length]; for(int i = 0; i < actions.length; i++) { actions[i] = actionContext.getAction(names[i]); if(actions[i] == null) Log.log(Log.ERROR,jEdit.class,"wtf: " + names[i]); } return actions; } //}}} //{{{ getActionNames() method /** * Returns all registered action names. */ public static String[] getActionNames() { return actionContext.getActionNames(); } //}}} //}}} //{{{ Edit mode methods //{{{ reloadModes() method /** * 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 FileWriter out = null; try { out = new FileWriter(userCatalog); out.write(jEdit.getProperty("defaultCatalog")); out.close(); } catch(IOException io) { Log.log(Log.ERROR,jEdit.class,io); } finally { try { if(out != null) out.close(); } catch(IOException e) { } } } 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; } } //}}} //{{{ getMode() method /** * 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; } //}}} //{{{ getModes() method /** * Returns an array of installed edit modes. */ public static Mode[] getModes() { Mode[] array = new Mode[modes.size()]; modes.copyInto(array); return array; } //}}} //}}} //{{{ Buffer creation methods //{{{ openFiles() method /** * 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; } //}}} //{{{ openFile() method /** * 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()); } //}}} //{{{ openFile() method /** * @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()); } //}}} //{{{ openFile() method /** * @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); } //}}} //{{{ openFile() method /** * Opens a file. This may return null if the buffer could not be * opened for some reason. * @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(View view, String parent, String path, boolean newFile, Hashtable props) { PerspectiveManager.setPerspectiveDirty(true); if(view != null && parent == null) parent = view.getBuffer().getDirectory(); if(MiscUtilities.isURL(path)) { if(MiscUtilities.getProtocolOfURL(path).equals("file")) path = path.substring(5); } path = MiscUtilities.constructPath(parent,path); Buffer newBuffer; synchronized(bufferListLock) { Buffer buffer = getBuffer(path); if(buffer != null) { if(view != null) view.setBuffer(buffer); return buffer; } if(props == null) props = new Hashtable(); BufferHistory.Entry entry = BufferHistory.getEntry(path); if(entry != null && saveCaret && props.get(Buffer.CARET) == null) { props.put(Buffer.CARET,new Integer(entry.caret)); /* if(entry.selection != null) { // getSelection() converts from string to // Selection[] props.put(Buffer.SELECTION,entry.getSelection()); } */ } if(entry != null && props.get(Buffer.ENCODING) == null) { if(entry.encoding != null) props.put(Buffer.ENCODING,entry.encoding); } newBuffer = new Buffer(path,newFile,false,props); if(!newBuffer.load(view,false)) return null; addBufferToList(newBuffer); } EditBus.send(new BufferUpdate(newBuffer,view,BufferUpdate.CREATED)); if(view != null) view.setBuffer(newBuffer); return newBuffer; } //}}} //{{{ openTemporary() method /** * Opens a temporary buffer. A temporary buffer is like a normal * buffer, except that an event is not fired, the the buffer is * not added to the buffers list. * * @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 * * @since jEdit 3.2pre10 */ public static Buffer openTemporary(View view, String parent, String path, boolean newFile) { if(view != null && parent == null) parent = view.getBuffer().getDirectory(); if(MiscUtilities.isURL(path)) { if(MiscUtilities.getProtocolOfURL(path).equals("file")) path = path.substring(5); } path = MiscUtilities.constructPath(parent,path); synchronized(bufferListLock) { Buffer buffer = getBuffer(path); if(buffer != null) return buffer; buffer = new Buffer(path,newFile,true,new Hashtable()); if(!buffer.load(view,false)) return null; else return buffer; } } //}}} //{{{ commitTemporary() method /** * Adds a temporary buffer to the buffer list. This must be done * before allowing the user to interact with the buffer in any * way. * @param buffer The buffer */ public static void commitTemporary(Buffer buffer) { if(!buffer.isTemporary()) return; PerspectiveManager.setPerspectiveDirty(true); addBufferToList(buffer); buffer.commitTemporary(); // send full range of events to avoid breaking plugins EditBus.send(new BufferUpdate(buffer,null,BufferUpdate.CREATED)); EditBus.send(new BufferUpdate(buffer,null,BufferUpdate.LOAD_STARTED)); EditBus.send(new BufferUpdate(buffer,null,BufferUpdate.LOADED)); } //}}} //{{{ newFile() method /** * Creates a new `untitled' file. * @param view The view to create the file in */ public static Buffer newFile(View view) { String path; if(view != null && view.getBuffer() != null) { path = view.getBuffer().getDirectory(); VFS vfs = VFSManager.getVFSForPath(path); // don't want 'New File' to create a read only buffer // if current file is on SQL VFS or something if((vfs.getCapabilities() & VFS.WRITE_CAP) == 0) path = System.getProperty("user.home"); } else path = null; return newFile(view,path); } //}}} //{{{ newFile() method /** * Creates a new `untitled' file. * @param view The view to create the file in * @param dir The directory to create the file in * @since jEdit 3.1pre2 */ public static Buffer newFile(View view, String dir) { // If only one new file is open which is clean, just close // it, which will create an 'Untitled-1' if(dir != null && buffersFirst != null && buffersFirst == buffersLast && buffersFirst.isUntitled() && !buffersFirst.isDirty()) { closeBuffer(view,buffersFirst); // return the newly created 'untitled-1' return buffersFirst; } // Find the highest Untitled-n file int untitledCount = 0; Buffer buffer = buffersFirst; while(buffer != null) { if(buffer.getName().startsWith("Untitled-")) { try { untitledCount = Math.max(untitledCount, Integer.parseInt(buffer.getName() .substring(9))); } catch(NumberFormatException nf) { } } buffer = buffer.next; } return openFile(view,dir,"Untitled-" + (untitledCount+1),true,null); } //}}} //}}} //{{{ Buffer management methods //{{{ closeBuffer() method /** * Closes a buffer. If there are unsaved changes, the user is * prompted if they should be saved first. * @param view The view * @param buffer The buffer * @return True if the buffer was really closed, false otherwise */ public static boolean closeBuffer(View view, Buffer buffer) { // Wait for pending I/O requests if(buffer.isPerformingIO()) { VFSManager.waitForRequests(); if(VFSManager.errorOccurred()) return false; } if(buffer.isDirty()) { Object[] args = { buffer.getName() }; int result = GUIUtilities.confirm(view,"notsaved",args, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if(result == JOptionPane.YES_OPTION) { if(!buffer.save(view,null,true))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -