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

📄 vfsbrowser.java

📁 Linux下面最好用的程序、文本编辑工具之一。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		// and before the path is set.		if(path != null)		{			try			{				maybeReloadRequestRunning = true;				browserView.maybeReloadDirectory(dir);			}			finally			{				VFSManager.runInAWTThread(new Runnable()				{					public void run()					{						maybeReloadRequestRunning = false;					}				});			}		}	} //}}}	//}}}	//{{{ Inner classes	//{{{ ActionHandler class	class ActionHandler implements ActionListener	{		public void actionPerformed(ActionEvent evt)		{			Object source = evt.getSource();			if(source == pathField || source == filterField				|| source == filterCheckbox)			{				updateFilterEnabled();				String path = pathField.getText();				if(path != null)					setDirectory(path);				browserView.focusOnFileView();			}		}	} //}}}	//{{{ CommandsMenuButton class	class CommandsMenuButton extends JButton	{		//{{{ CommandsMenuButton constructor		CommandsMenuButton()		{			setText(jEdit.getProperty("vfs.browser.commands.label"));			setIcon(GUIUtilities.loadIcon("ToolbarMenu.gif"));			setHorizontalTextPosition(SwingConstants.LEADING);			popup = new BrowserCommandsMenu(VFSBrowser.this,null);			CommandsMenuButton.this.setRequestFocusEnabled(false);			setMargin(new Insets(1,1,1,1));			CommandsMenuButton.this.addMouseListener(new MouseHandler());			if(OperatingSystem.isMacOSLF())				CommandsMenuButton.this.putClientProperty("JButton.buttonType","toolbar");		} //}}}		BrowserCommandsMenu popup;		//{{{ MouseHandler class		class MouseHandler extends MouseAdapter		{			public void mousePressed(MouseEvent evt)			{				if(!popup.isVisible())				{					popup.update();					GUIUtilities.showPopupMenu(						popup,CommandsMenuButton.this,0,						CommandsMenuButton.this.getHeight(),						false);				}				else				{					popup.setVisible(false);				}			}		} //}}}	} //}}}	//{{{ PluginsMenuButton class	class PluginsMenuButton extends JButton	{		//{{{ PluginsMenuButton constructor		PluginsMenuButton()		{			setText(jEdit.getProperty("vfs.browser.plugins.label"));			setIcon(GUIUtilities.loadIcon("ToolbarMenu.gif"));			setHorizontalTextPosition(SwingConstants.LEADING);			PluginsMenuButton.this.setRequestFocusEnabled(false);			setMargin(new Insets(1,1,1,1));			PluginsMenuButton.this.addMouseListener(new MouseHandler());			if(OperatingSystem.isMacOSLF())				PluginsMenuButton.this.putClientProperty("JButton.buttonType","toolbar");		} //}}}		JPopupMenu popup;		//{{{ updatePopupMenu() method		void updatePopupMenu()		{			popup = null;		} //}}}		//{{{ createPopupMenu() method		private void createPopupMenu()		{			if(popup != null)				return;			popup = new JPopupMenu();			ActionHandler actionHandler = new ActionHandler();			if(getMode() == BROWSER)			{				popup.add(GUIUtilities.loadMenuItem("plugin-manager",false));				popup.add(GUIUtilities.loadMenuItem("plugin-options",false));				popup.addSeparator();			}			else				/* we're in a modal dialog */;			ArrayList vec = new ArrayList();			//{{{ old API			Enumeration e = VFSManager.getFilesystems();			while(e.hasMoreElements())			{				VFS vfs = (VFS)e.nextElement();				if((vfs.getCapabilities() & VFS.BROWSE_CAP) == 0)					continue;				JMenuItem menuItem = new JMenuItem(jEdit.getProperty(					"vfs." + vfs.getName() + ".label"));				menuItem.setActionCommand(vfs.getName());				menuItem.addActionListener(actionHandler);				vec.add(menuItem);			} //}}}			//{{{ new API			EditPlugin[] plugins = jEdit.getPlugins();			for(int i = 0; i < plugins.length; i++)			{				JMenuItem menuItem = plugins[i].createBrowserMenuItems();				if(menuItem != null)					vec.add(menuItem);			} //}}}			if(vec.size() != 0)			{				MiscUtilities.quicksort(vec,new MiscUtilities.MenuItemCompare());				for(int i = 0; i < vec.size(); i++)					popup.add((JMenuItem)vec.get(i));			}			else			{				JMenuItem mi = new JMenuItem(jEdit.getProperty(					"vfs.browser.plugins.no-plugins.label"));				mi.setEnabled(false);				popup.add(mi);			}		} //}}}		//{{{ ActionHandler class		class ActionHandler implements ActionListener		{			public void actionPerformed(ActionEvent evt)			{				VFS vfs = VFSManager.getVFSByName(evt.getActionCommand());				String directory = vfs.showBrowseDialog(null,					VFSBrowser.this);				if(directory != null)					setDirectory(directory);			}		} //}}}		//{{{ MouseHandler class		class MouseHandler extends MouseAdapter		{			public void mousePressed(MouseEvent evt)			{				createPopupMenu();				if(!popup.isVisible())				{					GUIUtilities.showPopupMenu(						popup,PluginsMenuButton.this,0,						PluginsMenuButton.this.getHeight(),						false);				}				else				{					popup.setVisible(false);				}			}		} //}}}	} //}}}	//{{{ FavoritesMenuButton class	class FavoritesMenuButton extends JButton	{		//{{{ FavoritesMenuButton constructor		FavoritesMenuButton()		{			setText(jEdit.getProperty("vfs.browser.favorites.label"));			setIcon(GUIUtilities.loadIcon("ToolbarMenu.gif"));			setHorizontalTextPosition(SwingConstants.LEADING);			FavoritesMenuButton.this.setRequestFocusEnabled(false);			setMargin(new Insets(1,1,1,1));			FavoritesMenuButton.this.addMouseListener(new MouseHandler());			if(OperatingSystem.isMacOSLF())				FavoritesMenuButton.this.putClientProperty("JButton.buttonType","toolbar");		} //}}}		JPopupMenu popup;		//{{{ createPopupMenu() method		void createPopupMenu()		{			popup = new JPopupMenu();			ActionHandler actionHandler = new ActionHandler();			JMenuItem mi = new JMenuItem(				jEdit.getProperty(				"vfs.browser.favorites"				+ ".add-to-favorites.label"));			mi.setActionCommand("add-to-favorites");			mi.addActionListener(actionHandler);			popup.add(mi);			mi = new JMenuItem(				jEdit.getProperty(				"vfs.browser.favorites"				+ ".edit-favorites.label"));			mi.setActionCommand("dir@favorites:");			mi.addActionListener(actionHandler);			popup.add(mi);			popup.addSeparator();			VFS.DirectoryEntry[] favorites				= FavoritesVFS.getFavorites();			if(favorites.length == 0)			{				mi = new JMenuItem(					jEdit.getProperty(					"vfs.browser.favorites"					+ ".no-favorites.label"));				mi.setEnabled(false);				popup.add(mi);			}			else			{				MiscUtilities.quicksort(favorites,					new VFS.DirectoryEntryCompare(					sortMixFilesAndDirs,					sortIgnoreCase));				for(int i = 0; i < favorites.length; i++)				{					VFS.DirectoryEntry favorite						= favorites[i];					mi = new JMenuItem(favorite.path);					mi.setIcon(FileCellRenderer						.getIconForFile(						favorite,false));					String cmd = (favorite.type ==						VFS.DirectoryEntry.FILE						? "file@" : "dir@")						+ favorite.path;					mi.setActionCommand(cmd);					mi.addActionListener(actionHandler);					popup.add(mi);				}			}		} //}}}		//{{{ ActionHandler class		class ActionHandler implements ActionListener		{			public void actionPerformed(ActionEvent evt)			{				String actionCommand = evt.getActionCommand();				if(actionCommand.equals("add-to-favorites"))				{					// if any directories are selected, add					// them, otherwise add current directory					VFS.DirectoryEntry[] selected = getSelectedFiles();					if(selected == null || selected.length == 0)					{						if(path.equals(FavoritesVFS.PROTOCOL + ":"))						{							GUIUtilities.error(VFSBrowser.this,								"vfs.browser.recurse-favorites",								null);						}						else						{							FavoritesVFS.addToFavorites(path,								VFS.DirectoryEntry.DIRECTORY);						}					}					else					{						for(int i = 0; i < selected.length; i++)						{							VFS.DirectoryEntry file								= selected[i];							FavoritesVFS.addToFavorites(file.path,file.type);						}					}				}				else if(actionCommand.startsWith("dir@"))				{					setDirectory(actionCommand.substring(4));				}				else if(actionCommand.startsWith("file@"))				{					switch(getMode())					{					case BROWSER:						jEdit.openFile(view,actionCommand.substring(5));						break;					default:						locateFile(actionCommand.substring(5));						break;					}				}			}		} //}}}		//{{{ MouseHandler class		class MouseHandler extends MouseAdapter		{			public void mousePressed(MouseEvent evt)			{				if(popup != null && popup.isVisible())				{					popup.setVisible(false);					return;				}				if(popup == null)					createPopupMenu();				GUIUtilities.showPopupMenu(					popup,FavoritesMenuButton.this,0,					FavoritesMenuButton.this.getHeight(),					false);			}		} //}}}	} //}}}	//{{{ DirectoryLoadedAWTRequest class	class DirectoryLoadedAWTRequest implements Runnable	{		Object node;		Object[] loadInfo;		DirectoryLoadedAWTRequest(Object node, Object[] loadInfo)		{			this.node = node;			this.loadInfo = loadInfo;		}		public void run()		{			String path = (String)loadInfo[0];			if(path == null)			{				// there was an error				return;			}			VFS.DirectoryEntry[] list = (VFS.DirectoryEntry[])				loadInfo[1];			if(node == null)			{				// This is the new, canonical path				VFSBrowser.this.path = path;				if(!pathField.getText().equals(path))					pathField.setText(path);				if(path.endsWith("/") ||					path.endsWith(File.separator))				{					// ensure consistent history;					// eg we don't want both					// foo/ and foo					path = path.substring(0,						path.length() - 1);				}				HistoryModel.getModel("vfs.browser.path")					.addItem(path);			}			boolean filterEnabled = filterCheckbox.isSelected();			ArrayList directoryVector = new ArrayList();			int directories = 0;			int files = 0;			int invisible = 0;			if(list != null)			{				for(int i = 0; i < list.length; i++)				{					VFS.DirectoryEntry file = list[i];					if(file.hidden && !showHiddenFiles)					{						invisible++;						continue;					}					if(file.type == VFS.DirectoryEntry.FILE						&& filterEnabled						&& filenameFilter != null						&& !filenameFilter.isMatch(file.name))					{						invisible++;						continue;					}					if(file.type == VFS.DirectoryEntry.FILE)						files++;					else						directories++;					directoryVector.add(file);				}				MiscUtilities.quicksort(directoryVector,					new VFS.DirectoryEntryCompare(					sortMixFilesAndDirs,					sortIgnoreCase));			}			browserView.directoryLoaded(node,path,				directoryVector);			// to notify listeners that any existing			// selection has been deactivated			// turns out under some circumstances this			// method can switch the current buffer in			// BROWSER mode.			// in any case, this is only needed for the			// directory chooser (why?), so we add a			// check. otherwise poor Rick will go insane.			if(mode == CHOOSE_DIRECTORY_DIALOG)				filesSelected();		}		public String toString()		{			return (String)loadInfo[0];		}	} //}}}	//{{{ BrowserActionContext class	static class BrowserActionContext extends ActionContext	{		/**		 * If event source hierarchy contains a VFSDirectoryEntryTable,		 * this is the currently selected files there. Otherwise, this		 * is the currently selected item in the parent directory list.		 */		private VFS.DirectoryEntry[] getSelectedFiles(EventObject evt,			VFSBrowser browser)		{			Component source = (Component)evt.getSource();			if(GUIUtilities.getComponentParent(source,JList.class)				!= null)			{				Object[] selected = browser.getBrowserView()					.getParentDirectoryList()					.getSelectedValues();				VFS.DirectoryEntry[] returnValue					= new VFS.DirectoryEntry[					selected.length];				System.arraycopy(selected,0,returnValue,0,					selected.length);				return returnValue;			}			else			{				return browser.getSelectedFiles();			}		}		public void invokeAction(EventObject evt, EditAction action)		{			VFSBrowser browser = (VFSBrowser)				GUIUtilities.getComponentParent(				(Component)evt.getSource(),				VFSBrowser.class);			VFS.DirectoryEntry[] files = getSelectedFiles(evt,				browser);			// in the future we will want something better,			// eg. having an 'evt' object passed to			// EditAction.invoke().			// for now, since all browser actions are			// written in beanshell we set the 'browser'			// variable directly.			NameSpace global = BeanShell.getNameSpace();			try			{				global.setVariable("browser",browser);				global.setVariable("files",files);				View view = browser.getView();				// I guess ideally all browsers				// should have views, but since they				// don't, we just use the active view				// in that case, since some actions				// depend on a view being there and				// I don't want to add checks to				// them all				if(view == null)					view = jEdit.getActiveView();				action.invoke(view);			}			catch(UtilEvalError err)			{				Log.log(Log.ERROR,this,err);			}			finally			{				try				{					global.setVariable("browser",null);					global.setVariable("files",null);				}				catch(UtilEvalError err)				{					Log.log(Log.ERROR,this,err);				}			}		}	} //}}}	//}}}}

⌨️ 快捷键说明

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