⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jedit.java

📁 用java 编写的源码开放的文本编辑器。有很多有用的特性
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		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),					buffer.getStringProperty(Buffer.ENCODING));			}			buffer.close();			if(!isExiting)			{				EditBus.send(new BufferUpdate(buffer,view,					BufferUpdate.CLOSED));			}			buffer = buffer.next;		}		if(!isExiting)			newFile(view);		return true;	} //}}}	//{{{ saveAllBuffers() method	/**	 * 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 current = view.getBuffer();		Buffer buffer = buffersFirst;		while(buffer != null)		{			if(buffer.isDirty())			{				if(buffer.isNewFile())					view.setBuffer(buffer);				buffer.save(view,null,true);			}			buffer = buffer.next;		}		view.setBuffer(current);	} //}}}	//{{{ reloadAllBuffers() method	/**	 * 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);		}	} //}}}	//{{{ getBuffer() method	/**	 * 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 */);		synchronized(bufferListLock)		{			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;	} //}}}	//{{{ getBuffers() method	/**	 * Returns an array of open buffers.	 */	public static Buffer[] getBuffers()	{		synchronized(bufferListLock)		{			Buffer[] buffers = new Buffer[bufferCount];			Buffer buffer = buffersFirst;			for(int i = 0; i < bufferCount; i++)			{				buffers[i] = buffer;				buffer = buffer.next;			}			return buffers;		}	} //}}}	//{{{ getBufferCount() method	/**	 * Returns the number of open buffers.	 */	public static int getBufferCount()	{		return bufferCount;	} //}}}	//{{{ getFirstBuffer() method	/**	 * Returns the first buffer.	 */	public static Buffer getFirstBuffer()	{		return buffersFirst;	} //}}}	//{{{ getLastBuffer() method	/**	 * Returns the last buffer.	 */	public static Buffer getLastBuffer()	{		return buffersLast;	} //}}}	//}}}	//{{{ View methods	//{{{ getInputHandler() method	/**	 * Returns the current input handler (key binding to action mapping)	 * @see org.gjt.sp.jedit.gui.InputHandler	 */	public static InputHandler getInputHandler()	{		return inputHandler;	} //}}}	/* public static void newViewTest()	{		long time = System.currentTimeMillis();		for(int i = 0; i < 30; i++)		{			Buffer b = newFile(null);			b.insert(0,"x");			new View(b,null,false);		}		System.err.println(System.currentTimeMillis() - time);	} */	//{{{ newView() method	/**	 * Creates a new view of a buffer.	 * @param view An existing view	 * @param buffer The buffer	 */	public static View newView(View view, Buffer buffer)	{		return newView(view,buffer,false);	} //}}}	//{{{ newView() method	/**	 * Creates a new view of a buffer.	 * @param view An existing view	 * @param buffer The buffer	 * @param plainView If true, the view will not have dockable windows or	 * tool bars.	 *	 * @since 4.1pre2	 */	public static View newView(View view, Buffer buffer, boolean plainView)	{		if(view != null)		{			view.showWaitCursor();			view.getEditPane().saveCaretInfo();		}		View newView = new View(buffer,null,plainView);		// 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.isPlainView()				? "plain-view" : "view"));			view.hideWaitCursor();		}		GUIUtilities.loadGeometry(newView,(plainView				? "plain-view" : "view"));		addViewToList(newView);		EditBus.send(new ViewUpdate(newView,ViewUpdate.CREATED));		newView.show();		// show tip of the day		if(newView == viewsFirst)		{			newView.getTextArea().requestFocus();			// Don't show the welcome message if jEdit was started			// with the -nosettings switch			if(settingsDirectory != null && getBooleanProperty("firstTime"))				new HelpViewer();			else if(jEdit.getBooleanProperty("tip.show"))				new TipOfTheDay(newView);			setBooleanProperty("firstTime",false);		}		else			GUIUtilities.requestFocus(newView,newView.getTextArea());		return newView;	} //}}}	//{{{ newView() method	/**	 * Creates a new view.	 * @param view An existing view	 * @since jEdit 3.2pre2	 */	public static View newView(View view)	{		return newView(view,view.getSplitConfig(),false);	} //}}}	//{{{ newView() method	/**	 * 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)	{		return newView(view,splitConfig,false);	} //}}}	//{{{ newView() method	/**	 * Creates a new view.	 * @param view An existing view	 * @param splitConfig The split configuration	 * @param plainView If true, the view will not have dockable windows or	 * tool bars.	 * @since jEdit 4.1pre2	 */	public static View newView(View view, String splitConfig, boolean plainView)	{		if(view != null)		{			view.showWaitCursor();			view.getEditPane().saveCaretInfo();		}		View newView = new View(null,splitConfig,plainView);		// 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.isPlainView()				? "plain-view" : "view"));			view.hideWaitCursor();		}		GUIUtilities.loadGeometry(newView,(plainView ? "plain-view"				: "view"));		addViewToList(newView);		EditBus.send(new ViewUpdate(newView,ViewUpdate.CREATED));		newView.show();		// show tip of the day		if(newView == viewsFirst)		{			newView.getTextArea().requestFocus();			// Don't show the welcome message if jEdit was started			// with the -nosettings switch			if(settingsDirectory != null && getBooleanProperty("firstTime"))				new HelpViewer();			else if(jEdit.getBooleanProperty("tip.show"))				new TipOfTheDay(newView);			setBooleanProperty("firstTime",false);		}		else			GUIUtilities.requestFocus(newView,newView.getTextArea());		return newView;	} //}}}	//{{{ 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()	{		return activeView;	} //}}}	//}}}	//{{{ Miscellaneous methods	//{{{ 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;	} //}}}	//{{{ 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)		{			// Save the recent file list			File file1 = new File(MiscUtilities.constructPath(				settingsDirectory, "#recent.xml#save#"));			File file2 = new File(MiscUtilities.constructPath(				settingsDirectory, "recent.xml"));			if(file2.exists() && file2.lastModified() != recentModTime)			{				Log.log(Log.WARNING,jEdit.class,file2 + " changed"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -