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

📄 vfsbrowser.java

📁 Linux下面最好用的程序、文本编辑工具之一。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * VFSBrowser.java - VFS browser * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 2000, 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.browser;//{{{ Importsimport bsh.*;import gnu.regexp.*;import javax.swing.border.EmptyBorder;import javax.swing.event.*;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.*;import java.awt.event.*;import java.awt.*;import java.io.File;import java.util.*;import org.gjt.sp.jedit.io.*;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.msg.*;import org.gjt.sp.jedit.search.*;import org.gjt.sp.jedit.*;import org.gjt.sp.util.Log;//}}}/** * The main class of the VFS browser. * @author Slava Pestov * @version $Id: VFSBrowser.java,v 1.110 2004/07/14 05:18:50 spestov Exp $ */public class VFSBrowser extends JPanel implements EBComponent, DefaultFocusComponent{	public static final String NAME = "vfs.browser";	//{{{ Browser types	/**	 * Open file dialog mode. Equals JFileChooser.OPEN_DIALOG for	 * backwards compatibility.	 */	public static final int OPEN_DIALOG = 0;	/**	 * Save file dialog mode. Equals JFileChooser.SAVE_DIALOG for	 * backwards compatibility.	 */	public static final int SAVE_DIALOG = 1;	/**	 * Choose directory dialog mode.	 */	public static final int BROWSER_DIALOG = 4;	/**	 * Choose directory dialog mode.	 */	public static final int CHOOSE_DIRECTORY_DIALOG = 3;	/**	 * Stand-alone browser mode.	 */	public static final int BROWSER = 2;	//}}}	//{{{ browseDirectoryInNewWindow() method	/**	 * Opens the specified directory in a new, floating, file system browser.	 * @param view The view	 * @param path The directory's path	 * @since jEdit 4.1pre2	 */	public static void browseDirectoryInNewWindow(View view, String path)	{		DockableWindowManager wm = view.getDockableWindowManager();		if(path != null)		{			// this is such a bad way of doing it, but oh well...			jEdit.setTemporaryProperty("vfs.browser.path.tmp",path);		}		wm.floatDockableWindow("vfs.browser");		jEdit.unsetProperty("vfs.browser.path.tmp");	} //}}}	//{{{ browseDirectory() method	/**	 * Opens the specified directory in a file system browser.	 * @param view The view	 * @param path The directory's path	 * @since jEdit 4.0pre3	 */	public static void browseDirectory(View view, String path)	{		DockableWindowManager wm = view.getDockableWindowManager();		VFSBrowser browser = (VFSBrowser)wm.getDockable(NAME);		if(browser != null)		{			wm.showDockableWindow(NAME);			browser.setDirectory(path);		}		else		{			if(path != null)			{				// this is such a bad way of doing it, but oh well...				jEdit.setTemporaryProperty("vfs.browser.path.tmp",path);			}			wm.addDockableWindow("vfs.browser");			jEdit.unsetProperty("vfs.browser.path.tmp");		}	} //}}}	//{{{ getActionContext() method	/**	 * Returns the browser action context.	 * @since jEdit 4.2pre1	 */	public static ActionContext getActionContext()	{		return actionContext;	} //}}}	//{{{ VFSBrowser constructor	/**	 * Creates a new VFS browser.	 * @param view The view to open buffers in by default	 */	public VFSBrowser(View view, String position)	{		this(view,null,BROWSER,true,position);	} //}}}	//{{{ VFSBrowser constructor	/**	 * Creates a new VFS browser.	 * @param view The view to open buffers in by default	 * @param path The path to display	 * @param mode The browser mode	 * @param multipleSelection True if multiple selection should be allowed	 * @param position Where the browser is located	 * @since jEdit 4.2pre1	 */	public VFSBrowser(View view, String path, int mode,		boolean multipleSelection, String position)	{		super(new BorderLayout());		listenerList = new EventListenerList();		this.mode = mode;		this.multipleSelection = multipleSelection;		this.view = view;		currentEncoding = jEdit.getProperty("buffer.encoding",			System.getProperty("file.encoding"));		autoDetectEncoding = jEdit.getBooleanProperty(			"buffer.encodingAutodetect");		ActionHandler actionHandler = new ActionHandler();		Box topBox = new Box(BoxLayout.Y_AXIS);		horizontalLayout = (mode != BROWSER			|| DockableWindowManager.TOP.equals(position)			|| DockableWindowManager.BOTTOM.equals(position));		toolbarBox = new Box(horizontalLayout			? BoxLayout.X_AXIS			: BoxLayout.Y_AXIS);		topBox.add(toolbarBox);		GridBagLayout layout = new GridBagLayout();		JPanel pathAndFilterPanel = new JPanel(layout);		GridBagConstraints cons = new GridBagConstraints();		cons.gridwidth = cons.gridheight = 1;		cons.gridx = cons.gridy = 0;		cons.fill = GridBagConstraints.BOTH;		cons.anchor = GridBagConstraints.EAST;		JLabel label = new JLabel(jEdit.getProperty("vfs.browser.path"),			SwingConstants.RIGHT);		label.setBorder(new EmptyBorder(0,0,0,12));		layout.setConstraints(label,cons);		pathAndFilterPanel.add(label);		pathField = new HistoryTextField("vfs.browser.path");		pathField.setInstantPopups(true);		pathField.setEnterAddsToHistory(false);		pathField.setSelectAllOnFocus(true);		// because its preferred size can be quite wide, we		// don't want it to make the browser way too big,		// so set the preferred width to 0.		Dimension prefSize = pathField.getPreferredSize();		prefSize.width = 0;		pathField.setPreferredSize(prefSize);		pathField.addActionListener(actionHandler);		cons.gridx = 1;		cons.weightx = 1.0f;		layout.setConstraints(pathField,cons);		pathAndFilterPanel.add(pathField);		filterCheckbox = new JCheckBox(jEdit.getProperty("vfs.browser.filter"));		filterCheckbox.setMargin(new Insets(0,0,0,0));		filterCheckbox.setRequestFocusEnabled(false);		filterCheckbox.setBorder(new EmptyBorder(0,0,0,12));		filterCheckbox.setSelected(jEdit.getBooleanProperty(			"vfs.browser.filter-enabled"));		filterCheckbox.addActionListener(actionHandler);		if(mode != CHOOSE_DIRECTORY_DIALOG)		{			cons.gridx = 0;			cons.weightx = 0.0f;			cons.gridy = 1;			layout.setConstraints(filterCheckbox,cons);			pathAndFilterPanel.add(filterCheckbox);		}		filterField = new HistoryTextField("vfs.browser.filter");		filterField.setInstantPopups(true);		filterField.setSelectAllOnFocus(true);		filterField.addActionListener(actionHandler);		if(mode != CHOOSE_DIRECTORY_DIALOG)		{			cons.gridx = 1;			cons.weightx = 1.0f;			layout.setConstraints(filterField,cons);			pathAndFilterPanel.add(filterField);		}		topBox.add(pathAndFilterPanel);		add(BorderLayout.NORTH,topBox);		add(BorderLayout.CENTER,browserView = new BrowserView(this));		propertiesChanged();		String filter;		if(mode == BROWSER || !jEdit.getBooleanProperty(			"vfs.browser.currentBufferFilter"))		{			filter = jEdit.getProperty("vfs.browser.last-filter");			if(filter == null)				filter = jEdit.getProperty("vfs.browser.default-filter");		}		else		{			String ext = MiscUtilities.getFileExtension(				view.getBuffer().getName());			if(ext.length() == 0)				filter = jEdit.getProperty("vfs.browser.default-filter");			else				filter = "*" + ext;		}		filterField.setText(filter);		filterField.addCurrentToHistory();		updateFilterEnabled();		// see VFSBrowser.browseDirectory()		if(path == null)			path = jEdit.getProperty("vfs.browser.path.tmp");		if(path == null || path.length() == 0)		{			String userHome = System.getProperty("user.home");			String defaultPath = jEdit.getProperty("vfs.browser.defaultPath");			if(defaultPath.equals("home"))				path = userHome;			else if(defaultPath.equals("working"))				path = System.getProperty("user.dir");			else if(defaultPath.equals("buffer"))			{				if(view != null)				{					Buffer buffer = view.getBuffer();					path = buffer.getDirectory();				}				else					path = userHome;			}			else if(defaultPath.equals("last"))			{				HistoryModel pathModel = HistoryModel.getModel("vfs.browser.path");				if(pathModel.getSize() == 0)					path = "~";				else					path = pathModel.getItem(0);			}			else if(defaultPath.equals("favorites"))				path = "favorites:";			else			{				// unknown value??!!!				path = userHome;			}		}		final String _path = path;		SwingUtilities.invokeLater(new Runnable()		{			public void run()			{				setDirectory(_path);			}		});	} //}}}	//{{{ focusOnDefaultComponent() method	public void focusOnDefaultComponent()	{		browserView.focusOnFileView();	} //}}}	//{{{ addNotify() method	public void addNotify()	{		super.addNotify();		EditBus.addToBus(this);	} //}}}	//{{{ removeNotify() method	public void removeNotify()	{		super.removeNotify();		jEdit.setBooleanProperty("vfs.browser.filter-enabled",			filterCheckbox.isSelected());		if(mode == BROWSER || !jEdit.getBooleanProperty(			"vfs.browser.currentBufferFilter"))		{			jEdit.setProperty("vfs.browser.last-filter",				filterField.getText());		}		EditBus.removeFromBus(this);	} //}}}	//{{{ handleMessage() method	public void handleMessage(EBMessage msg)	{		if(msg instanceof PropertiesChanged)			propertiesChanged();		else if(msg instanceof BufferUpdate)		{			BufferUpdate bmsg = (BufferUpdate)msg;			if(bmsg.getWhat() == BufferUpdate.CREATED				|| bmsg.getWhat() == BufferUpdate.CLOSED)				browserView.updateFileView();			// hacked BufferIORequest to send VFSUpdates in case			// two stage save is off now...			/* else if(bmsg.getWhat() == BufferUpdate.SAVED)			{				maybeReloadDirectory(MiscUtilities.getParentOfPath(					bmsg.getBuffer().getPath()));			} */		}		else if(msg instanceof PluginUpdate)		{			PluginUpdate pmsg = (PluginUpdate)msg;			if(pmsg.getWhat() == PluginUpdate.LOADED				|| pmsg.getWhat() == PluginUpdate.UNLOADED)			{				plugins.updatePopupMenu();			}		}		else if(msg instanceof VFSUpdate)		{			maybeReloadDirectory(((VFSUpdate)msg).getPath());		}	} //}}}	//{{{ getView() method	public View getView()	{		return view;	} //}}}	//{{{ getMode() method	public int getMode()	{		return mode;	} //}}}	//{{{ isMultipleSelectionEnabled() method	public boolean isMultipleSelectionEnabled()	{		return multipleSelection;	} //}}}	//{{{ isHorizontalLayout() method	public boolean isHorizontalLayout()	{		return horizontalLayout;	} //}}}	//{{{ getShowHiddenFiles() method	public boolean getShowHiddenFiles()	{		return showHiddenFiles;	} //}}}	//{{{ setShowHiddenFiles() method	public void setShowHiddenFiles(boolean showHiddenFiles)	{		this.showHiddenFiles = showHiddenFiles;	} //}}}	//{{{ getFilenameFilter() method	/**	 * Returns the file name filter glob.	 * @since jEdit 3.2pre2	 */	public String getFilenameFilter()	{		if(filterCheckbox.isSelected())		{			String filter = filterField.getText();			if(filter.length() == 0)				return "*";			else				return filter;		}		else			return "*";	} //}}}	//{{{ setFilenameFilter() method	public void setFilenameFilter(String filter)	{		if(filter == null || filter.length() == 0 || filter.equals("*"))			filterCheckbox.setSelected(false);		else		{			filterCheckbox.setSelected(true);			filterField.setText(filter);		}	} //}}}	//{{{ getDirectoryField() method	public HistoryTextField getDirectoryField()	{		return pathField;	} //}}}	//{{{ getDirectory() method	public String getDirectory()	{		return path;	} //}}}	//{{{ setDirectory() method	public void setDirectory(String path)	{		if(path.startsWith("file:"))			path = path.substring(5);		pathField.setText(path);		if(!startRequest())			return;		updateFilenameFilter();		browserView.saveExpansionState();		browserView.loadDirectory(null,path);		this.path = path;		VFSManager.runInAWTThread(new Runnable()		{			public void run()			{				endRequest();			}		});	} //}}}	//{{{ rootDirectory() method	/**	 * Goes to the local drives directory.	 * @since jEdit 4.0pre4	 */	public void rootDirectory()	{		if(OperatingSystem.isMacOS() || OperatingSystem.isDOSDerived())			setDirectory(FileRootsVFS.PROTOCOL + ":");		else			setDirectory("/");	} //}}}	//{{{ reloadDirectory() method	public void reloadDirectory()	{		// used by FTP plugin to clear directory cache		VFSManager.getVFSForPath(path).reloadDirectory(path);		updateFilenameFilter();		browserView.saveExpansionState();		browserView.loadDirectory(null,path);	} //}}}	//{{{ delete() method	/**	 * Note that all files must be on the same VFS.	 */	public void delete(VFS.DirectoryEntry[] files)	{		String dialogType;		if(MiscUtilities.isURL(files[0].deletePath)			&& FavoritesVFS.PROTOCOL.equals(			MiscUtilities.getProtocolOfURL(files[0].deletePath)))		{			dialogType = "vfs.browser.delete-favorites";		}		else		{			dialogType = "vfs.browser.delete-confirm";		}		StringBuffer buf = new StringBuffer();		for(int i = 0; i < files.length; i++)		{			buf.append(files[i].path);			buf.append('\n');		}		Object[] args = { buf.toString() };		int result = GUIUtilities.confirm(this,dialogType,args,			JOptionPane.YES_NO_OPTION,			JOptionPane.WARNING_MESSAGE);		if(result != JOptionPane.YES_OPTION)			return;		VFS vfs = VFSManager.getVFSForPath(files[0].deletePath);		if(!startRequest())			return;		for(int i = 0; i < files.length; i++)		{			Object session = vfs.createVFSSession(files[i].deletePath,this);			if(session == null)				continue;			VFSManager.runInWorkThread(new BrowserIORequest(				BrowserIORequest.DELETE,this,				session,vfs,files[i].deletePath,				null,null));

⌨️ 快捷键说明

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