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

📄 vfsbrowser.java

📁 Linux下面最好用的程序、文本编辑工具之一。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		}		VFSManager.runInAWTThread(new Runnable()		{			public void run()			{				endRequest();			}		});	} //}}}	//{{{ rename() method	public void rename(String from)	{		VFS vfs = VFSManager.getVFSForPath(from);		String filename = vfs.getFileName(from);		String[] args = { filename };		String to = GUIUtilities.input(this,"vfs.browser.rename",			args,filename);		if(to == null)			return;		to = MiscUtilities.constructPath(vfs.getParentOfPath(from),to);		Object session = vfs.createVFSSession(from,this);		if(session == null)			return;		if(!startRequest())			return;		VFSManager.runInWorkThread(new BrowserIORequest(			BrowserIORequest.RENAME,this,			session,vfs,from,to,null));		VFSManager.runInAWTThread(new Runnable()		{			public void run()			{				endRequest();			}		});	} //}}}	//{{{ mkdir() method	public void mkdir()	{		String newDirectory = GUIUtilities.input(this,"vfs.browser.mkdir",null);		if(newDirectory == null)			return;		// if a directory is selected, create new dir in there.		// if a file is selected, create new dir inside its parent.		VFS.DirectoryEntry[] selected = getSelectedFiles();		String parent;		if(selected.length == 0)			parent = path;		else if(selected[0].type == VFS.DirectoryEntry.FILE)		{			parent = selected[0].path;			parent = VFSManager.getVFSForPath(parent)				.getParentOfPath(parent);		}		else			parent = selected[0].path;		VFS vfs = VFSManager.getVFSForPath(parent);		// path is the currently viewed directory in the browser		newDirectory = MiscUtilities.constructPath(parent,newDirectory);		Object session = vfs.createVFSSession(newDirectory,this);		if(session == null)			return;		if(!startRequest())			return;		VFSManager.runInWorkThread(new BrowserIORequest(			BrowserIORequest.MKDIR,this,			session,vfs,newDirectory,null,null));		VFSManager.runInAWTThread(new Runnable()		{			public void run()			{				endRequest();			}		});	} //}}}	//{{{ newFile() method	/**	 * Creates a new file in the current directory.	 * @since jEdit 4.0pre2	 */	public void newFile()	{		VFS.DirectoryEntry[] selected = getSelectedFiles();		if(selected.length >= 1)		{			VFS.DirectoryEntry file = selected[0];			if(file.type == VFS.DirectoryEntry.DIRECTORY)				jEdit.newFile(view,file.path);			else			{				VFS vfs = VFSManager.getVFSForPath(file.path);				jEdit.newFile(view,vfs.getParentOfPath(file.path));			}		}		else			jEdit.newFile(view,path);	} //}}}	//{{{ searchInDirectory() method	/**	 * Opens a directory search in the current directory.	 * @since jEdit 4.0pre2	 */	public void searchInDirectory()	{		VFS.DirectoryEntry[] selected = getSelectedFiles();		if(selected.length >= 1)		{			VFS.DirectoryEntry file = selected[0];			searchInDirectory(file.path,file.type != VFS.DirectoryEntry.FILE);		}		else		{			searchInDirectory(this.path,true);		}	} //}}}	//{{{ searchInDirectory() method	/**	 * Opens a directory search in the specified directory.	 * @param path The path name	 * @param directory True if the path is a directory, false if it is a file	 * @since jEdit 4.2pre1	 */	public void searchInDirectory(String path, boolean directory)	{		String filter;		if(directory)		{			filter = getFilenameFilter();		}		else		{			String name = MiscUtilities.getFileName(path);			String ext = MiscUtilities.getFileExtension(name);			filter = (ext == null || ext.length() == 0				? getFilenameFilter()				: "*" + ext);			path = MiscUtilities.getParentOfPath(path);		}		SearchAndReplace.setSearchFileSet(new DirectoryListSet(			path,filter,true));		SearchDialog.showSearchDialog(view,null,SearchDialog.DIRECTORY);	} //}}}	//{{{ getBrowserView() method	public BrowserView getBrowserView()	{		return browserView;	} //}}}	//{{{ getSelectedFiles() method	public VFS.DirectoryEntry[] getSelectedFiles()	{		return browserView.getSelectedFiles();	} //}}}	//{{{ locateFile() method	/**	 * Goes to the given file's directory and selects the file in the list.	 * @param path The file	 * @since jEdit 4.2pre2	 */	public void locateFile(final String path)	{		if(!filenameFilter.isMatch(MiscUtilities.getFileName(path)))			setFilenameFilter(null);		setDirectory(MiscUtilities.getParentOfPath(path));		VFSManager.runInAWTThread(new Runnable()		{			public void run()			{				browserView.getTable().selectFile(path);			}		});	} //}}}	//{{{ addBrowserListener() method	public void addBrowserListener(BrowserListener l)	{		listenerList.add(BrowserListener.class,l);	} //}}}	//{{{ removeBrowserListener() method	public void removeBrowserListener(BrowserListener l)	{		listenerList.remove(BrowserListener.class,l);	} //}}}	//{{{ filesActivated() method	// canDoubleClickClose set to false when ENTER pressed	public static final int M_OPEN = 0;	public static final int M_OPEN_NEW_VIEW = 1;	public static final int M_OPEN_NEW_PLAIN_VIEW = 2;	public static final int M_OPEN_NEW_SPLIT = 3;	public static final int M_INSERT = 4;	/**	 * This method does the "double-click" handling. It is public so that	 * <code>browser.actions.xml</code> can bind to it.	 * @since jEdit 4.2pre2	 */	public void filesActivated(int mode, boolean canDoubleClickClose)	{		VFS.DirectoryEntry[] selectedFiles = browserView.getSelectedFiles();		Buffer buffer = null;check_selected: for(int i = 0; i < selectedFiles.length; i++)		{			VFS.DirectoryEntry file = selectedFiles[i];			if(file.type == VFS.DirectoryEntry.DIRECTORY				|| file.type == VFS.DirectoryEntry.FILESYSTEM)			{				if(mode == M_OPEN_NEW_VIEW && this.mode == BROWSER)					browseDirectoryInNewWindow(view,file.path);				else					setDirectory(file.path);			}			else if(this.mode == BROWSER || this.mode == BROWSER_DIALOG)			{				if(mode == M_INSERT)				{					view.getBuffer().insertFile(view,						file.path);					continue check_selected;				}				Buffer _buffer = jEdit.getBuffer(file.path);				if(_buffer == null)				{					Hashtable props = new Hashtable();					props.put(Buffer.ENCODING,currentEncoding);					props.put(Buffer.ENCODING_AUTODETECT,						new Boolean(autoDetectEncoding));					_buffer = jEdit.openFile(null,null,						file.path,false,props);				}				else if(doubleClickClose && canDoubleClickClose					&& this.mode != BROWSER_DIALOG					&& selectedFiles.length == 1)				{					// close if this buffer is currently					// visible in the view.					EditPane[] editPanes = view.getEditPanes();					for(int j = 0; j < editPanes.length; j++)					{						if(editPanes[j].getBuffer() == _buffer)						{							jEdit.closeBuffer(view,_buffer);							return;						}					}				}				if(_buffer != null)					buffer = _buffer;			}			else			{				// if a file is selected in OPEN_DIALOG or				// SAVE_DIALOG mode, just let the listener(s)				// handle it			}		}		if(buffer != null)		{			switch(mode)			{			case M_OPEN:				view.setBuffer(buffer);				break;			case M_OPEN_NEW_VIEW:				jEdit.newView(view,buffer,false);				break;			case M_OPEN_NEW_PLAIN_VIEW:				jEdit.newView(view,buffer,true);				break;			case M_OPEN_NEW_SPLIT:				view.splitHorizontally().setBuffer(buffer);				break;			}		}		Object[] listeners = listenerList.getListenerList();		for(int i = 0; i < listeners.length; i++)		{			if(listeners[i] == BrowserListener.class)			{				BrowserListener l = (BrowserListener)listeners[i+1];				l.filesActivated(this,selectedFiles);			}		}	} //}}}	//{{{ Package-private members	String currentEncoding;	boolean autoDetectEncoding;	//{{{ pathsEqual() method	/**	 * This will be made public at some stage, in the io package, but not	 * yet.	 */	static boolean pathsEqual(String p1, String p2)	{		if(p1.endsWith("/") || p1.endsWith(File.separator))			p1 = p1.substring(0,p1.length() - 1);		if(p2.endsWith("/") || p2.endsWith(File.separator))			p2 = p2.substring(0,p2.length() - 1);		return p1.equals(p2);	} //}}}	//{{{ updateFilenameFilter() method	void updateFilenameFilter()	{		try		{			String filter = filterField.getText();			if(filter.length() == 0)				filter = "*";			filenameFilter = new RE(MiscUtilities.globToRE(filter),RE.REG_ICASE);		}		catch(Exception e)		{			Log.log(Log.ERROR,VFSBrowser.this,e);			String[] args = { filterField.getText(),				e.getMessage() };			GUIUtilities.error(this,"vfs.browser.bad-filter",args);		}	} //}}}	//{{{ directoryLoaded() method	void directoryLoaded(Object node, Object[] loadInfo)	{		VFSManager.runInAWTThread(new DirectoryLoadedAWTRequest(			node,loadInfo));	} //}}}	//{{{ filesSelected() method	void filesSelected()	{		VFS.DirectoryEntry[] selectedFiles = browserView.getSelectedFiles();		if(mode == BROWSER)		{			for(int i = 0; i < selectedFiles.length; i++)			{				VFS.DirectoryEntry file = selectedFiles[i];				Buffer buffer = jEdit.getBuffer(file.path);				if(buffer != null && view != null)					view.setBuffer(buffer);			}		}		Object[] listeners = listenerList.getListenerList();		for(int i = 0; i < listeners.length; i++)		{			if(listeners[i] == BrowserListener.class)			{				BrowserListener l = (BrowserListener)listeners[i+1];				l.filesSelected(this,selectedFiles);			}		}	} //}}}	//{{{ endRequest() method	void endRequest()	{		requestRunning = false;	} //}}}	//}}}	//{{{ Private members	private static ActionContext actionContext;	static	{		actionContext = new BrowserActionContext();		ActionSet builtInActionSet = new ActionSet(null,null,null,			jEdit.class.getResource("browser.actions.xml"));		builtInActionSet.setLabel(jEdit.getProperty("action-set.browser"));		builtInActionSet.load();		actionContext.addActionSet(builtInActionSet);	}	//{{{ Instance variables	private EventListenerList listenerList;	private View view;	private boolean horizontalLayout;	private String path;	private HistoryTextField pathField;	private JCheckBox filterCheckbox;	private HistoryTextField filterField;	private Box toolbarBox;	private FavoritesMenuButton favorites;	private PluginsMenuButton plugins;	private BrowserView browserView;	private RE filenameFilter;	private int mode;	private boolean multipleSelection;	private boolean showHiddenFiles;	private boolean sortMixFilesAndDirs;	private boolean sortIgnoreCase;	private boolean doubleClickClose;	private boolean requestRunning;	private boolean maybeReloadRequestRunning;	//}}}	//{{{ createMenuBar() method	private JPanel createMenuBar()	{		JPanel menuBar = new JPanel();		menuBar.setLayout(new BoxLayout(menuBar,BoxLayout.X_AXIS));		menuBar.setBorder(new EmptyBorder(0,1,0,3));		menuBar.add(new CommandsMenuButton());		menuBar.add(Box.createHorizontalStrut(3));		menuBar.add(plugins = new PluginsMenuButton());		menuBar.add(Box.createHorizontalStrut(3));		menuBar.add(favorites = new FavoritesMenuButton());		return menuBar;	} //}}}	//{{{ createToolBar() method	private Box createToolBar()	{		if(mode == BROWSER)			return GUIUtilities.loadToolBar(actionContext,				"vfs.browser.toolbar-browser");		else			return GUIUtilities.loadToolBar(actionContext,				"vfs.browser.toolbar-dialog");	} //}}}	//{{{ propertiesChanged() method	private void propertiesChanged()	{		showHiddenFiles = jEdit.getBooleanProperty("vfs.browser.showHiddenFiles");		sortMixFilesAndDirs = jEdit.getBooleanProperty("vfs.browser.sortMixFilesAndDirs");		sortIgnoreCase = jEdit.getBooleanProperty("vfs.browser.sortIgnoreCase");		doubleClickClose = jEdit.getBooleanProperty("vfs.browser.doubleClickClose");		browserView.propertiesChanged();		toolbarBox.removeAll();		if(jEdit.getBooleanProperty("vfs.browser.showToolbar"))		{			Box toolbar = createToolBar();			if(horizontalLayout)				toolbarBox.add(toolbar);			else			{				toolbar.add(Box.createGlue());				toolbarBox.add(toolbar);			}		}		if(jEdit.getBooleanProperty("vfs.browser.showMenubar"))		{			JPanel menubar = createMenuBar();			if(horizontalLayout)			{				toolbarBox.add(Box.createHorizontalStrut(6));				toolbarBox.add(menubar,0);			}			else			{				menubar.add(Box.createGlue());				toolbarBox.add(menubar);			}		}		else			favorites = null;		toolbarBox.add(Box.createGlue());		revalidate();		if(path != null)			reloadDirectory();	} //}}}	/* We do this stuff because the browser is not able to handle	 * more than one request yet */	//{{{ startRequest() method	private boolean startRequest()	{		if(requestRunning)		{			// dump stack trace for debugging purposes			Log.log(Log.DEBUG,this,new Throwable("For debugging purposes"));			GUIUtilities.error(this,"browser-multiple-io",null);			return false;		}		else		{			requestRunning = true;			return true;		}	} //}}}	//{{{ updateFilterEnabled() method	private void updateFilterEnabled()	{		filterField.setEnabled(filterCheckbox.isSelected());	} //}}}	//{{{ maybeReloadDirectory() method	private void maybeReloadDirectory(String dir)	{		if(MiscUtilities.isURL(dir)			&& MiscUtilities.getProtocolOfURL(dir).equals(			FavoritesVFS.PROTOCOL))		{			if(favorites != null)				favorites.popup = null;		}		// this is a dirty hack and it relies on the fact		// that updates for parents are sent before updates		// for the changed nodes themselves (if this was not		// the case, the browser wouldn't be updated properly		// on delete, etc).		//		// to avoid causing '> 1 request' errors, don't reload		// directory if request already active		if(maybeReloadRequestRunning)		{			//Log.log(Log.WARNING,this,"VFS update: request already in progress");			return;		}		// save a file -> sends vfs update. if a VFS file dialog box		// is shown from the same event frame as the save, the		// VFSUpdate will be delivered before the directory is loaded,

⌨️ 快捷键说明

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