📄 jedit.java
字号:
setBooleanProperty("firstTime",false); } else GUIUtilities.requestFocus(newView,newView.getTextArea()); return newView; } finally { if(view != null) view.hideWaitCursor(); } } //}}} //{{{ closeView() method /** * Closes a view. * * jEdit will exit if this was the last open view. */ public static void closeView(View view) { closeView(view,true); } //}}} //{{{ getViews() method /** * Returns an array of all open views. */ public static View[] getViews() { View[] views = new View[viewCount]; View view = viewsFirst; for(int i = 0; i < viewCount; i++) { views[i] = view; view = view.next; } return views; } //}}} //{{{ getViewCount() method /** * Returns the number of open views. */ public static int getViewCount() { return viewCount; } //}}} //{{{ getFirstView() method /** * Returns the first view. */ public static View getFirstView() { return viewsFirst; } //}}} //{{{ getLastView() method /** * Returns the last view. */ public static View getLastView() { return viewsLast; } //}}} //{{{ getActiveView() method /** * Returns the currently focused view. * @since jEdit 4.1pre1 */ public static View getActiveView() { if(activeView == null) { // eg user just closed a view and didn't focus another return viewsFirst; } else return activeView; } //}}} //}}} //{{{ Miscellaneous methods //{{{ isMainThread() method /** * Returns true if the currently running thread is the main thread. * @since jEdit 4.2pre1 */ public static boolean isMainThread() { return (Thread.currentThread() == mainThread); } //}}} //{{{ isBackgroundMode() method /** * Returns true if jEdit was started with the <code>-background</code> * command-line switch. * @since jEdit 4.0pre4 */ public static boolean isBackgroundModeEnabled() { return background; } //}}} //{{{ showMemoryStatusDialog() method /** * Performs garbage collection and displays a dialog box showing * memory status. * @param view The view * @since jEdit 4.0pre1 */ public static void showMemoryDialog(View view) { Runtime rt = Runtime.getRuntime(); int before = (int) (rt.freeMemory() / 1024); System.gc(); int after = (int) (rt.freeMemory() / 1024); int total = (int) (rt.totalMemory() / 1024); JProgressBar progress = new JProgressBar(0,total); progress.setValue(total - after); progress.setStringPainted(true); progress.setString(jEdit.getProperty("memory-status.use", new Object[] { new Integer(total - after), new Integer(total) })); Object[] message = new Object[4]; message[0] = getProperty("memory-status.gc", new Object[] { new Integer(after - before) }); message[1] = Box.createVerticalStrut(12); message[2] = progress; message[3] = Box.createVerticalStrut(6); JOptionPane.showMessageDialog(view,message, jEdit.getProperty("memory-status.title"), JOptionPane.INFORMATION_MESSAGE); } //}}} //{{{ getJEditHome() method /** * Returns the jEdit install directory. */ public static String getJEditHome() { return jEditHome; } //}}} //{{{ getSettingsDirectory() method /** * Returns the path of the directory where user-specific settings * are stored. This will be <code>null</code> if jEdit was * started with the <code>-nosettings</code> command-line switch; do not * blindly use this method without checking for a <code>null</code> * return value first. */ public static String getSettingsDirectory() { return settingsDirectory; } //}}} //{{{ getJARCacheDirectory() method /** * Returns the directory where plugin cache files are stored. * @since jEdit 4.2pre1 */ public static String getJARCacheDirectory() { return jarCacheDirectory; } //}}} //{{{ backupSettingsFile() method /** * Backs up the specified file in the settings directory. * You should call this on any settings files your plugin * writes. * @param file The file * @since jEdit 4.0pre1 */ public static void backupSettingsFile(File file) { if(settingsDirectory == null) return; String backupDir = MiscUtilities.constructPath( settingsDirectory,"settings-backup"); File dir = new File(backupDir); if(!dir.exists()) dir.mkdirs(); // ... sweet. saveBackup() will create backupDir if it // doesn't exist. MiscUtilities.saveBackup(file,5,null,"~",backupDir); } //}}} //{{{ saveSettings() method /** * Saves all user preferences to disk. */ public static void saveSettings() { if(settingsDirectory == null) return; Abbrevs.save(); FavoritesVFS.saveFavorites(); HistoryModel.saveHistory(); Registers.saveRegisters(); SearchAndReplace.save(); BufferHistory.save(); KillRing.save(); File file1 = new File(MiscUtilities.constructPath( settingsDirectory,"#properties#save#")); File file2 = new File(MiscUtilities.constructPath( settingsDirectory,"properties")); if(file2.exists() && file2.lastModified() != propsModTime) { Log.log(Log.WARNING,jEdit.class,file2 + " changed" + " on disk; will not save user properties"); } else { backupSettingsFile(file2); try { OutputStream out = new FileOutputStream(file1); propMgr.saveUserProps(out); file2.delete(); file1.renameTo(file2); } catch(IOException io) { Log.log(Log.ERROR,jEdit.class,io); } propsModTime = file2.lastModified(); } } //}}} //{{{ exit() method /** * Exits cleanly from jEdit, prompting the user if any unsaved files * should be saved first. * @param view The view from which this exit was called * @param reallyExit If background mode is enabled and this parameter * is true, then jEdit will close all open views instead of exiting * entirely. */ public static void exit(View view, boolean reallyExit) { // Close dialog, view.close() call need a view... if(view == null) view = activeView; // Wait for pending I/O requests VFSManager.waitForRequests(); // Send EditorExitRequested EditBus.send(new EditorExitRequested(view)); // Even if reallyExit is false, we still exit properly // if background mode is off reallyExit |= !background; PerspectiveManager.savePerspective(false); // Close all buffers if(!closeAllBuffers(view,reallyExit)) return; // If we are running in background mode and // reallyExit was not specified, then return here. if(!reallyExit) { // in this case, we can't directly call // view.close(); we have to call closeView() // for all open views view = viewsFirst; while(view != null) { closeView(view,false); view = view.next; } // Save settings in case user kills the backgrounded // jEdit process saveSettings(); } else { // Save view properties here if(view != null) view.close(); // Stop autosave timer Autosave.stop(); // Stop server if(server != null) server.stopServer(); // Stop all plugins PluginJAR[] plugins = getPluginJARs(); for(int i = 0; i < plugins.length; i++) { removePluginJAR(plugins[i],true); } // Send EditorExiting EditBus.send(new EditorExiting(null)); // Save settings saveSettings(); // Close activity log stream Log.closeStream(); // Byebye... System.exit(0); } } //}}} //{{{ getEditServer() method /** * Returns the edit server instance. You can use this to find out the * port number jEdit is listening on. * @since jEdit 4.2pre10 */ public static EditServer getEditServer() { return server; } //}}} //}}} //{{{ Package-private members //{{{ updatePosition() method /** * If buffer sorting is enabled, this repositions the buffer. */ static void updatePosition(String oldPath, Buffer buffer) { if((VFSManager.getVFSForPath(oldPath).getCapabilities() & VFS.CASE_INSENSITIVE_CAP) != 0) { oldPath = oldPath.toLowerCase(); } bufferHash.remove(oldPath); String path = buffer.getSymlinkPath(); if((VFSManager.getVFSForPath(path).getCapabilities() & VFS.CASE_INSENSITIVE_CAP) != 0) { path = path.toLowerCase(); } bufferHash.put(path,buffer); if(sortBuffers) { removeBufferFromList(buffer); addBufferToList(buffer); } } //}}} //{{{ addMode() method /** * Do not call this method. It is only public so that classes * in the org.gjt.sp.jedit.syntax package can access it. * @param mode The edit mode */ public static void addMode(Mode mode) { //Log.log(Log.DEBUG,jEdit.class,"Adding edit mode " // + mode.getName()); modes.addElement(mode); } //}}} //{{{ loadMode() method /** * Loads an XML-defined edit mode from the specified reader. * @param mode The edit mode */ /* package-private */ static void loadMode(Mode mode) { final String fileName = (String)mode.getProperty("file"); Log.log(Log.NOTICE,jEdit.class,"Loading edit mode " + fileName); final XmlParser parser = new XmlParser(); XModeHandler xmh = new XModeHandler(mode.getName()) { public void error(String what, Object subst) { int line = parser.getLineNumber(); int column = parser.getColumnNumber(); String msg; if(subst == null) msg = jEdit.getProperty("xmode-error." + what); else { msg = jEdit.getProperty("xmode-error." + what, new String[] { subst.toString() }); if(subst instanceof Throwable) Log.log(Log.ERROR,this,subst); } Object[] args = { fileName, new Integer(line), new Integer(column), msg }; GUIUtilities.error(null,"xmode-error",args); } public TokenMarker getTokenMarker(String modeName) { Mode mode = getMode(modeName); if(mode == null) return null; else return mode.getTokenMarker(); } }; mode.setTokenMarker(xmh.getTokenMarker()); Reader grammar = null; parser.setHandler(xmh); try { grammar = new BufferedReader(new FileReader(fileName)); parser.parse(null, null, grammar); mode.setProperties(xmh.getModeProperties()); } catch (Throwable e) { Log.log(Log.ERROR, jEdit.class, e); if (e instanceof XmlException) { XmlException xe = (XmlException) e; int line = xe.getLine(); String message = xe.getMessage(); Object[] args = { fileName, new Integer(line), null, message }; GUIUtilities.error(null,"xmode-error",args); } } finally { try { if(grammar != null) grammar.close(); } catch(IOException io) { Log.log(Log.ERROR,jEdit.class,io); } } } //}}} //{{{ addPluginProps() method static void addPluginProps(Properties map) { propMgr.addPluginProps(map); } //}}} //{{{ removePluginProps() method static void removePluginProps(Properties map) { propMgr.removePluginProps(map); } //}}} //{{{ pluginError() method static void pluginError(String path, String messageProp, Object[] args) { synchronized(pluginErrorLock) { if(pluginErrors == null) pluginErrors = new Vector(); ErrorListDialog.ErrorEntry newEntry = new ErrorListDialog.ErrorEntry( path,messageProp,args); for(int i = 0; i < pluginErrors.size(); i++) { if(pluginErrors.get(i).equals(newEntry)) return; } pluginErrors.addElement(newEntry); if(startupDone) { SwingUtilities.invokeLater(new Runnable() { public void run() { showPluginErrorDialog(); } }); } } } //}}} //{{{ setActiveView() method static void setActiveView(View view) { jEdit.activeView = view; } //}}} //}}} //{{{ Private members //{{{ Static variables private static String jEditHome; private static String settingsDirectory; private static String jarCacheDirectory; private static long propsModTime; private static PropertyManager propMgr; private static EditServer server; private static boolean background; private static ActionContext actionContext; private static ActionSet builtInActionSet; private static Vector pluginErrors; private static Object pluginErrorLock = new Object(); private static Vector jars; private static Vector modes; private static boolea
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -