📄 jedit.java
字号:
/* * jEdit.java - Main class of the jEdit editor * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 1998, 2003 Slava Pestov * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package org.gjt.sp.jedit;//{{{ Importsimport com.microstar.xml.*;import javax.swing.plaf.metal.*;import javax.swing.*;import java.awt.*;import java.io.*;import java.net.*;import java.text.MessageFormat;import java.util.*;import org.gjt.sp.jedit.buffer.BufferIORequest;import org.gjt.sp.jedit.msg.*;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.help.HelpViewer;import org.gjt.sp.jedit.io.*;import org.gjt.sp.jedit.search.SearchAndReplace;import org.gjt.sp.jedit.syntax.*;import org.gjt.sp.jedit.textarea.*;import org.gjt.sp.util.Log;//}}}/** * The main class of the jEdit text editor. * @author Slava Pestov * @version $Id: jEdit.java,v 1.111 2003/02/23 04:05:21 spestov Exp $ */public class jEdit{ //{{{ getVersion() method /** * Returns the jEdit version as a human-readable string. */ public static String getVersion() { return MiscUtilities.buildToVersion(getBuild()); } //}}} //{{{ getBuild() method /** * Returns the internal version. MiscUtilities.compareStrings() can be used * to compare different internal versions. */ public static String getBuild() { // (major).(minor).(<99 = preX, 99 = final).(bug fix) return "04.01.99.00"; } //}}} //{{{ main() method /** * The main method of the jEdit application. * This should never be invoked directly. * @param args The command line arguments */ public static void main(String[] args) { String javaVersion = System.getProperty("java.version"); if(javaVersion.compareTo("1.3") < 0) { System.err.println("You are running Java version " + javaVersion + "."); System.err.println("jEdit requires Java 1.3 or later."); System.exit(1); } //{{{ Parse command line int level = Log.WARNING; if(args.length >= 1) { String levelStr = args[0]; if(levelStr.length() == 1 && Character.isDigit( levelStr.charAt(0))) { level = Integer.parseInt(levelStr); args[0] = null; } } boolean endOpts = false; settingsDirectory = MiscUtilities.constructPath( System.getProperty("user.home"),".jedit"); String portFile = "server"; boolean restore = true; boolean gui = true; // open initial view? boolean noPlugins = false; boolean noStartupScripts = false; String userDir = System.getProperty("user.dir"); // script to run String scriptFile = null; for(int i = 0; i < args.length; i++) { String arg = args[i]; if(arg == null) continue; else if(arg.length() == 0) args[i] = null; else if(arg.startsWith("-") && !endOpts) { if(arg.equals("--")) endOpts = true; else if(arg.equals("-usage")) { version(); System.err.println(); usage(); System.exit(1); } else if(arg.equals("-version")) { version(); System.exit(1); } else if(arg.equals("-nosettings")) settingsDirectory = null; else if(arg.startsWith("-settings=")) settingsDirectory = arg.substring(10); else if(arg.startsWith("-noserver")) portFile = null; else if(arg.equals("-server")) portFile = "server"; else if(arg.startsWith("-server=")) portFile = arg.substring(8); else if(arg.startsWith("-background")) background = true; else if(arg.equals("-nogui")) gui = false; else if(arg.equals("-norestore")) restore = false; else if(arg.equals("-noplugins")) noPlugins = true; else if(arg.equals("-nostartupscripts")) noStartupScripts = true; else if(arg.startsWith("-run=")) scriptFile = arg.substring(5); else { System.err.println("Unknown option: " + arg); usage(); System.exit(1); } args[i] = null; } } //}}} if(settingsDirectory != null && portFile != null) portFile = MiscUtilities.constructPath(settingsDirectory,portFile); else portFile = null; Log.init(true,level); //{{{ Try connecting to another running jEdit instance if(portFile != null && new File(portFile).exists()) { int port, key; try { BufferedReader in = new BufferedReader(new FileReader(portFile)); String check = in.readLine(); if(!check.equals("b")) throw new Exception("Wrong port file format"); port = Integer.parseInt(in.readLine()); key = Integer.parseInt(in.readLine()); in.close(); Socket socket = new Socket(InetAddress.getByName("127.0.0.1"),port); DataOutputStream out = new DataOutputStream( socket.getOutputStream()); out.writeInt(key); String script = makeServerScript(restore,args,scriptFile); out.writeUTF(script); out.close(); System.exit(0); } catch(Exception e) { // ok, this one seems to confuse newbies // endlessly, so log it as NOTICE, not // ERROR Log.log(Log.NOTICE,jEdit.class,"An error occurred" + " while connecting to the jEdit server instance."); Log.log(Log.NOTICE,jEdit.class,"This probably means that" + " jEdit crashed and/or exited abnormally"); Log.log(Log.NOTICE,jEdit.class,"the last time it was run."); Log.log(Log.NOTICE,jEdit.class,"If you don't" + " know what this means, don't worry."); Log.log(Log.NOTICE,jEdit.class,e); } } //}}} // don't show splash screen if there is a file named // 'nosplash' in the settings directory if(!new File(settingsDirectory,"nosplash").exists()) GUIUtilities.showSplashScreen(); //{{{ Initialize settings directory Writer stream; if(settingsDirectory != null) { File _settingsDirectory = new File(settingsDirectory); if(!_settingsDirectory.exists()) _settingsDirectory.mkdirs(); File _macrosDirectory = new File(settingsDirectory,"macros"); if(!_macrosDirectory.exists()) _macrosDirectory.mkdir(); String logPath = MiscUtilities.constructPath( settingsDirectory,"activity.log"); backupSettingsFile(new File(logPath)); try { stream = new BufferedWriter(new FileWriter(logPath)); // Write a warning message: String lineSep = System.getProperty("line.separator"); stream.write("Log file created on " + new Date()); stream.write(lineSep); stream.write("IMPORTANT:"); stream.write(lineSep); stream.write("Because updating this file after " + "every log message would kill"); stream.write(lineSep); stream.write("performance, it will be *incomplete* " + "unless you invoke the"); stream.write(lineSep); stream.write("Utilities->Troubleshooting->Update " + "Activity Log on Disk command!"); stream.write(lineSep); } catch(Exception e) { e.printStackTrace(); stream = null; } } else { stream = null; } //}}} Log.setLogWriter(stream); Log.log(Log.NOTICE,jEdit.class,"jEdit version " + getVersion()); Log.log(Log.MESSAGE,jEdit.class,"Settings directory is " + settingsDirectory); //{{{ Initialize server if(portFile != null) { server = new EditServer(portFile); if(!server.isOK()) server = null; } else { if(background) { background = false; Log.log(Log.WARNING,jEdit.class,"You cannot specify both the" + " -background and -noserver switches"); } } //}}} //{{{ Get things rolling initMisc(); initSystemProperties(); GUIUtilities.advanceSplashProgress(); BeanShell.init(); initUserProperties(); initPLAF(); if(OperatingSystem.hasJava14()) { try { ClassLoader loader = jEdit.class.getClassLoader(); Class clazz; if(loader != null) clazz = loader.loadClass("org.gjt.sp.jedit.Java14"); else clazz = Class.forName("org.gjt.sp.jedit.Java14"); java.lang.reflect.Method meth = clazz .getMethod("init",new Class[0]); meth.invoke(null,new Object[0]); } catch(Exception e) { Log.log(Log.ERROR,jEdit.class,e); System.exit(1); } } initActions(); initDockables(); GUIUtilities.advanceSplashProgress(); VFSManager.init(); if(!noPlugins) initPlugins(); if(jEditHome != null) initSiteProperties(); if(settingsDirectory != null) { File history = new File(MiscUtilities.constructPath( settingsDirectory,"history")); if(history.exists()) historyModTime = history.lastModified(); HistoryModel.loadHistory(history); File recent = new File(MiscUtilities.constructPath( settingsDirectory,"recent.xml")); if(recent.exists()) recentModTime = recent.lastModified(); BufferHistory.load(recent); } GUIUtilities.advanceSplashProgress(); // Buffer sort sortBuffers = getBooleanProperty("sortBuffers"); sortByName = getBooleanProperty("sortByName"); reloadModes(); GUIUtilities.advanceSplashProgress(); SearchAndReplace.load(); GUIUtilities.advanceSplashProgress(); //}}} //{{{ Start plugins for(int i = 0; i < jars.size(); i++) { ((EditPlugin.JAR)jars.elementAt(i)).getClassLoader() .startAllPlugins(); } //}}} //{{{ Load macros and run startup scripts, after plugins and settings are loaded Macros.loadMacros(); if(!noStartupScripts && jEditHome != null) { String path = MiscUtilities.constructPath(jEditHome,"startup"); File file = new File(path); if(file.exists()) runStartupScripts(file); } if(!noStartupScripts && settingsDirectory != null) { String path = MiscUtilities.constructPath(settingsDirectory,"startup"); File file = new File(path); if(!file.exists()) file.mkdirs(); else runStartupScripts(file); } //}}} //{{{ Run script specified with -run= parameter if(scriptFile != null) { scriptFile = MiscUtilities.constructPath(userDir,scriptFile); BeanShell.runScript(null,scriptFile,null,false); } //}}} // Must be after plugins are started!!! propertiesChanged(); GUIUtilities.advanceSplashProgress(); // Open files, create the view and hide the splash screen. finishStartup(gui,restore,userDir,args); } //}}} //{{{ Property methods //{{{ getProperties() method /** * Returns the properties object which contains all known * jEdit properties. * @since jEdit 3.1pre4 */ public static final Properties getProperties() { return props; } //}}} //{{{ getProperty() method /** * Fetches a property, returning null if it's not defined. * @param name The property */ public static final String getProperty(String name) { return props.getProperty(name); } //}}} //{{{ getProperty() method /** * Fetches a property, returning the default value if it's not * defined. * @param name The property * @param def The default value */ public static final String getProperty(String name, String def) { return props.getProperty(name,def); } //}}} //{{{ getProperty() method /** * Returns the property with the specified name.<p> * * The elements of the <code>args</code> array are substituted * into the value of the property in place of strings of the * form <code>{<i>n</i>}</code>, where <code><i>n</i></code> is an index * in the array.<p> * * You can find out more about this feature by reading the * documentation for the <code>format</code> method of the * <code>java.text.MessageFormat</code> class. * * @param name The property * @param args The positional parameters */ public static final String getProperty(String name, Object[] args) { if(name == null) return null; if(args == null) return props.getProperty(name); else { String value = props.getProperty(name); if(value == null) return null; else return MessageFormat.format(value,args); } } //}}} //{{{ getBooleanProperty() method /** * Returns the value of a boolean property. * @param name The property */ public static final boolean getBooleanProperty(String name) { return getBooleanProperty(name,false); } //}}} //{{{ getBooleanProperty() method /** * Returns the value of a boolean property. * @param name The property * @param def The default value */ public static final boolean getBooleanProperty(String name, boolean def) { String value = getProperty(name); if(value == null) return def; else if(value.equals("true") || value.equals("yes") || value.equals("on")) return true; else if(value.equals("false") || value.equals("no") || value.equals("off")) return false; else return def; } //}}} //{{{ getIntegerProperty() method /** * Returns the value of an integer property. * @param name The property * @param def The default value * @since jEdit 4.0pre1 */ public static final int getIntegerProperty(String name, int def) { String value = getProperty(name); if(value == null) return def; else { try { return Integer.parseInt(value.trim()); } catch(NumberFormatException nf) { return def; } } } //}}} //{{{ getDoubleProperty() method public static double getDoubleProperty(String name, double def) { String value = getProperty(name); if(value == null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -