📄 jedit.java
字号:
{ if(view != null && parent == null) { File file = view.getBuffer().getFile(); if(file != null) parent = file.getParent(); } String protocol; if(MiscUtilities.isURL(path)) { protocol = MiscUtilities.getProtocolOfURL(path); if(protocol.equals("file")) path = path.substring(5); } else protocol = "file"; if(protocol.equals("file")) path = MiscUtilities.constructPath(parent,path); 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) { int caret = entry.caret; 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); } final Buffer newBuffer = new Buffer(view,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; } /** * 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 readOnly True if the file should be read only * @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) { File file = view.getBuffer().getFile(); if(file != null) parent = file.getParent(); } String protocol; if(MiscUtilities.isURL(path)) { protocol = MiscUtilities.getProtocolOfURL(path); if(protocol.equals("file")) path = path.substring(5); } else protocol = "file"; if(protocol.equals("file")) path = MiscUtilities.constructPath(parent,path); Buffer buffer = getBuffer(path); if(buffer != null) return buffer; buffer = new Buffer(null,path,newFile,true,new Hashtable()); if(!buffer.load(view,false)) return null; else return buffer; } /** * 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; buffer.setMode(); buffer.propertiesChanged(); addBufferToList(buffer); buffer.commitTemporary(); EditBus.send(new BufferUpdate(buffer,null,BufferUpdate.CREATED)); } /** * Creates a new `untitled' file. * @param view The view to create the file in */ public static Buffer newFile(View view) { return newFile(view,null); } /** * 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); } /** * 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)) return false; } else if(result != JOptionPane.NO_OPTION) return false; } _closeBuffer(view,buffer); return true; } /** * Closes the buffer, even if it has unsaved changes. * @param view The view * @param buffer The buffer * * @since jEdit 2.2pre1 */ public static void _closeBuffer(View view, Buffer buffer) { if(buffer.isClosed()) { // can happen if the user presses C+w twice real // quick and the buffer has unsaved changes return; } if(!buffer.isNewFile()) { view.getEditPane().saveCaretInfo(); Integer _caret = (Integer)buffer.getProperty(Buffer.CARET); int caret = (_caret == null ? 0 : _caret.intValue()); BufferHistory.setEntry(buffer.getPath(),caret, (Selection[])buffer.getProperty(Buffer.SELECTION), (String)buffer.getProperty(Buffer.ENCODING)); } removeBufferFromList(buffer); buffer.close(); EditBus.send(new BufferUpdate(buffer,view,BufferUpdate.CLOSED)); // Create a new file when the last is closed if(buffersFirst == null && buffersLast == null) newFile(view); } /** * Closes all open buffers. * @param view The view */ public static boolean closeAllBuffers(View view) { return closeAllBuffers(view,false); } /** * Closes all open buffers. * @param view The view * @param isExiting This must be false unless this method is * being called by the exit() method */ public static boolean closeAllBuffers(View view, boolean isExiting) { boolean dirty = false; Buffer buffer = buffersFirst; while(buffer != null) { if(buffer.isDirty()) { dirty = true; break; } buffer = buffer.next; } if(dirty) { boolean ok = new CloseDialog(view).isOK(); if(!ok) return false; } // Wait for pending I/O requests VFSManager.waitForRequests(); if(VFSManager.errorOccurred()) return false; // close remaining buffers (the close dialog only deals with // dirty ones) buffer = buffersFirst; // zero it here so that BufferTabs doesn't have any problems buffersFirst = buffersLast = null; bufferCount = 0; while(buffer != null) { if(!buffer.isNewFile()) { Integer _caret = (Integer)buffer.getProperty(Buffer.CARET); int caret = (_caret == null ? 0 : _caret.intValue()); BufferHistory.setEntry(buffer.getPath(),caret, (Selection[])buffer.getProperty(Buffer.SELECTION), (String)buffer.getProperty(Buffer.ENCODING)); } buffer.close(); if(!isExiting) { EditBus.send(new BufferUpdate(buffer,view, BufferUpdate.CLOSED)); } buffer = buffer.next; } if(!isExiting) newFile(view); return true; } /** * Saves all open buffers. * @param view The view * @param confirm If true, a confirmation dialog will be shown first * @since jEdit 2.7pre2 */ public static void saveAllBuffers(View view, boolean confirm) { if(confirm) { int result = GUIUtilities.confirm(view,"saveall",null, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(result != JOptionPane.YES_OPTION) return; } Buffer buffer = buffersFirst; while(buffer != null) { if(buffer.isDirty()) buffer.save(view,null,true); buffer = buffer.next; } } /** * Reloads all open buffers. * @param view The view * @param confirm If true, a confirmation dialog will be shown first * @since jEdit 2.7pre2 */ public static void reloadAllBuffers(final View view, boolean confirm) { if(confirm) { int result = GUIUtilities.confirm(view,"reload-all",null, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(result != JOptionPane.YES_OPTION) return; } // save caret info. Buffer.load() will load it. View _view = viewsFirst; while(_view != null) { EditPane[] panes = _view.getEditPanes(); for(int i = 0; i < panes.length; i++) { panes[i].saveCaretInfo(); } _view = _view.next; } Buffer[] buffers = jEdit.getBuffers(); for(int i = 0; i < buffers.length; i++) { Buffer buffer = buffers[i]; buffer.load(view,true); } } /** * Returns the buffer with the specified path name. The path name * must be an absolute, canonical, path. * @param path The path name * @see MiscUtilities#constructPath(String,String) */ public static Buffer getBuffer(String path) { boolean caseInsensitiveFilesystem = (File.separatorChar == '\\' || File.separatorChar == ':' /* Windows or MacOS */); Buffer buffer = buffersFirst; while(buffer != null) { String _path = buffer.getPath(); if(caseInsensitiveFilesystem) { if(_path.equalsIgnoreCase(path)) return buffer; } else { if(_path.equals(path)) return buffer; } buffer = buffer.next; } return null; } /** * Returns an array of open buffers. */ public static Buffer[] getBuffers() { Buffer[] buffers = new Buffer[bufferCount]; Buffer buffer = buffersFirst; for(int i = 0; i < bufferCount; i++) { buffers[i] = buffer; buffer = buffer.next; } return buffers; } /** * Returns the number of open buffers. */ public static int getBufferCount() { return bufferCount; } /** * Returns the first buffer. */ public static Buffer getFirstBuffer() { return buffersFirst; } /** * Returns the last buffer. */ public static Buffer getLastBuffer() { return buffersLast; } /** * Returns the current input handler (key binding to action mapping) * @see org.gjt.sp.jedit.gui.InputHandler */ public static InputHandler getInputHandler() { return inputHandler; } /** * Creates a new view of a buffer. * @param view An existing view * @param buffer The buffer */ public static View newView(View view, Buffer buffer) { if(view != null) { view.showWaitCursor(); view.getEditPane().saveCaretInfo(); } View newView = new View(buffer,null); // Do this crap here so that the view is created // and added to the list before it is shown // (for the sake of plugins that add stuff to views) newView.pack(); // newView.setSize(view.getSize()) creates incorrectly // sized views, for some reason... if(view != null) { GUIUtilities.saveGeometry(view,"view"); view.hideWaitCursor(); } GUIUtilities.loadGeometry(newView,"view"); addViewToList(newView); EditBus.send(new ViewUpdate(newView,ViewUpdate.CREATED)); newView.show(); return newView; } /** * Creates a new view. * @param view An existing view * @since jEdit 3.2pre2 */ public static View newView(View view) { return newView(view,view.getSplitConfig()); } /** * Creates a new view. * @param view An existing view * @param splitConfig The split configuration * @since jEdit 3.2pre2 */ public static View newView(View view, String splitConfig) { if(view != null) { view.showWaitCursor(); view.getEditPane().saveCaretInfo(); } View newView = new View(null,splitConfig); // Do this crap here so that the view is created // and added to the list before it is shown // (for the sake of plugins that add stuff to views) newView.pack(); // newView.setSize(view.getSize()) creates incorrectly // sized views, for some reason... if(view != null) { GUIUtilities.saveGeometry(view,"view"); view.hideWaitCursor(); } GUIUtilities.loadGeometry(newView,"view"); addViewToList(newView); EditBus.send(new ViewUpdate(newView,ViewUpdate.CREATED));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -