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

📄 jedit.java

📁 用java 编写的源码开放的文本编辑器。有很多有用的特性
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	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	//{{{ restoreOpenFiles() method	/**	 * Opens files that were open last time.	 * @since jEdit 3.2pre2	 */	public static String restoreOpenFiles()	{		if(settingsDirectory == null)			return null;		File session = new File(MiscUtilities.constructPath(			settingsDirectory,"session"));		if(!session.exists())			return null;		String splitConfig = null;		try		{			BufferedReader in = new BufferedReader(new FileReader(				session));			String line;			while((line = in.readLine()) != null)			{				if(line.startsWith("splits\t"))					splitConfig = line.substring(7);				else					openFile(null,line);			}			in.close();		}		catch(IOException io)		{			Log.log(Log.ERROR,jEdit.class,"Error while loading " + session);			Log.log(Log.ERROR,jEdit.class,io);		}		return splitConfig;	} //}}}	//{{{ saveOpenFiles() method	/**	 * Saves the list of open files.	 * @since jEdit 3.1pre5	 */	public static void saveOpenFiles(View view)	{		if(settingsDirectory == null)			return;		view.getEditPane().saveCaretInfo();		File session = new File(MiscUtilities.constructPath(			settingsDirectory,"session"));		// maybe not, since it's autosaved now		//backupSettingsFile(session);		try		{			String lineSep = System.getProperty("line.separator");			BufferedWriter out = new BufferedWriter(new FileWriter(				session));			Buffer buffer = buffersFirst;			while(buffer != null)			{				if(!buffer.isUntitled())				{					out.write(buffer.getPath());					out.write(lineSep);				}				buffer = buffer.next;			}			out.write("splits\t");			out.write(view.getSplitConfig());			out.write(lineSep);			out.close();		}		catch(IOException io)		{			Log.log(Log.ERROR,jEdit.class,"Error while saving " + session);			Log.log(Log.ERROR,jEdit.class,io);		}	} //}}}	//{{{ 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)	{		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);		if(!MiscUtilities.isURL(path))			path = MiscUtilities.canonPath(path);		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);			}			Buffer 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;		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))					return false;				VFSManager.waitForRequests();				if(buffer.getBooleanProperty(BufferIORequest					.ERROR_OCCURRED))				{					return false;				}			}			else if(result != JOptionPane.NO_OPTION)				return false;		}		_closeBuffer(view,buffer);		return true;	} //}}}	//{{{ _closeBuffer() method	/**	 * 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),				buffer.getStringProperty(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);	} //}}}	//{{{ closeAllBuffers() method	/**	 * Closes all open buffers.	 * @param view The view	 */	public static boolean closeAllBuffers(View view)	{		return closeAllBuffers(view,false);	} //}}}	//{{{ closeAllBuffers() method	/**	 * 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;

⌨️ 快捷键说明

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