PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/browser/VFSBrowser.java

#
Java | 1626 lines | 1178 code | 204 blank | 244 comment | 228 complexity | a6a4428b5c134c498f74f93253a1f717 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * VFSBrowser.java - VFS browser
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2003 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.browser;
  23. //{{{ Imports
  24. import bsh.*;
  25. import gnu.regexp.*;
  26. import javax.swing.border.EmptyBorder;
  27. import javax.swing.event.*;
  28. import javax.swing.tree.DefaultMutableTreeNode;
  29. import javax.swing.*;
  30. import java.awt.event.*;
  31. import java.awt.*;
  32. import java.io.File;
  33. import java.util.*;
  34. import org.gjt.sp.jedit.io.*;
  35. import org.gjt.sp.jedit.gui.*;
  36. import org.gjt.sp.jedit.msg.*;
  37. import org.gjt.sp.jedit.search.*;
  38. import org.gjt.sp.jedit.*;
  39. import org.gjt.sp.util.Log;
  40. //}}}
  41. /**
  42. * The main class of the VFS browser.
  43. * @author Slava Pestov
  44. * @version $Id: VFSBrowser.java 4842 2003-08-04 00:23:07Z spestov $
  45. */
  46. public class VFSBrowser extends JPanel implements EBComponent, DefaultFocusComponent
  47. {
  48. public static final String NAME = "vfs.browser";
  49. //{{{ Browser types
  50. /**
  51. * Open file dialog mode. Equals JFileChooser.OPEN_DIALOG for
  52. * backwards compatibility.
  53. */
  54. public static final int OPEN_DIALOG = 0;
  55. /**
  56. * Save file dialog mode. Equals JFileChooser.SAVE_DIALOG for
  57. * backwards compatibility.
  58. */
  59. public static final int SAVE_DIALOG = 1;
  60. /**
  61. * Choose directory dialog mode.
  62. */
  63. public static final int BROWSER_DIALOG = 4;
  64. /**
  65. * Choose directory dialog mode.
  66. */
  67. public static final int CHOOSE_DIRECTORY_DIALOG = 3;
  68. /**
  69. * Stand-alone browser mode.
  70. */
  71. public static final int BROWSER = 2;
  72. //}}}
  73. //{{{ browseDirectoryInNewWindow() method
  74. /**
  75. * Opens the specified directory in a new, floating, file system browser.
  76. * @param view The view
  77. * @param path The directory's path
  78. * @since jEdit 4.1pre2
  79. */
  80. public static void browseDirectoryInNewWindow(View view, String path)
  81. {
  82. DockableWindowManager wm = view.getDockableWindowManager();
  83. if(path != null)
  84. {
  85. // this is such a bad way of doing it, but oh well...
  86. jEdit.setTemporaryProperty("vfs.browser.path.tmp",path);
  87. }
  88. wm.floatDockableWindow("vfs.browser");
  89. jEdit.unsetProperty("vfs.browser.path.tmp");
  90. } //}}}
  91. //{{{ browseDirectory() method
  92. /**
  93. * Opens the specified directory in a file system browser.
  94. * @param view The view
  95. * @param path The directory's path
  96. * @since jEdit 4.0pre3
  97. */
  98. public static void browseDirectory(View view, String path)
  99. {
  100. DockableWindowManager wm = view.getDockableWindowManager();
  101. VFSBrowser browser = (VFSBrowser)wm.getDockable(NAME);
  102. if(browser != null)
  103. {
  104. wm.showDockableWindow(NAME);
  105. browser.setDirectory(path);
  106. }
  107. else
  108. {
  109. if(path != null)
  110. {
  111. // this is such a bad way of doing it, but oh well...
  112. jEdit.setTemporaryProperty("vfs.browser.path.tmp",path);
  113. }
  114. wm.addDockableWindow("vfs.browser");
  115. jEdit.unsetProperty("vfs.browser.path.tmp");
  116. }
  117. } //}}}
  118. //{{{ getActionContext() method
  119. /**
  120. * Returns the browser action context.
  121. * @since jEdit 4.2pre1
  122. */
  123. public static ActionContext getActionContext()
  124. {
  125. return actionContext;
  126. } //}}}
  127. //{{{ VFSBrowser constructor
  128. /**
  129. * Creates a new VFS browser.
  130. * @param view The view to open buffers in by default
  131. */
  132. public VFSBrowser(View view, String position)
  133. {
  134. this(view,null,BROWSER,true,position);
  135. } //}}}
  136. //{{{ VFSBrowser constructor
  137. /**
  138. * Creates a new VFS browser.
  139. * @param view The view to open buffers in by default
  140. * @param path The path to display
  141. * @param mode The browser mode
  142. * @param multipleSelection True if multiple selection should be allowed
  143. * @param position Where the browser is located
  144. * @since jEdit 4.2pre1
  145. */
  146. public VFSBrowser(View view, String path, int mode,
  147. boolean multipleSelection, String position)
  148. {
  149. super(new BorderLayout());
  150. listenerList = new EventListenerList();
  151. this.mode = mode;
  152. this.multipleSelection = multipleSelection;
  153. this.floating = floating;
  154. this.view = view;
  155. currentEncoding = jEdit.getProperty("buffer.encoding",
  156. System.getProperty("file.encoding"));
  157. ActionHandler actionHandler = new ActionHandler();
  158. Box topBox = new Box(BoxLayout.Y_AXIS);
  159. horizontalLayout = (mode != BROWSER
  160. || DockableWindowManager.TOP.equals(position)
  161. || DockableWindowManager.BOTTOM.equals(position));
  162. toolbarBox = new Box(horizontalLayout
  163. ? BoxLayout.X_AXIS
  164. : BoxLayout.Y_AXIS);
  165. topBox.add(toolbarBox);
  166. GridBagLayout layout = new GridBagLayout();
  167. JPanel pathAndFilterPanel = new JPanel(layout);
  168. GridBagConstraints cons = new GridBagConstraints();
  169. cons.gridwidth = cons.gridheight = 1;
  170. cons.gridx = cons.gridy = 0;
  171. cons.fill = GridBagConstraints.BOTH;
  172. cons.anchor = GridBagConstraints.EAST;
  173. JLabel label = new JLabel(jEdit.getProperty("vfs.browser.path"),
  174. SwingConstants.RIGHT);
  175. label.setBorder(new EmptyBorder(0,0,0,12));
  176. layout.setConstraints(label,cons);
  177. pathAndFilterPanel.add(label);
  178. pathField = new HistoryTextField("vfs.browser.path");
  179. pathField.setInstantPopups(true);
  180. pathField.setEnterAddsToHistory(false);
  181. pathField.setSelectAllOnFocus(true);
  182. if(floating)
  183. {
  184. label.setDisplayedMnemonic(jEdit.getProperty(
  185. "vfs.browser.path.mnemonic").charAt(0));
  186. label.setLabelFor(pathField);
  187. }
  188. // because its preferred size can be quite wide, we
  189. // don't want it to make the browser way too big,
  190. // so set the preferred width to 0.
  191. Dimension prefSize = pathField.getPreferredSize();
  192. prefSize.width = 0;
  193. pathField.setPreferredSize(prefSize);
  194. pathField.addActionListener(actionHandler);
  195. cons.gridx = 1;
  196. cons.weightx = 1.0f;
  197. layout.setConstraints(pathField,cons);
  198. pathAndFilterPanel.add(pathField);
  199. filterCheckbox = new JCheckBox(jEdit.getProperty("vfs.browser.filter"));
  200. filterCheckbox.setMargin(new Insets(0,0,0,0));
  201. filterCheckbox.setRequestFocusEnabled(false);
  202. filterCheckbox.setBorder(new EmptyBorder(0,0,0,12));
  203. filterCheckbox.setSelected(jEdit.getBooleanProperty(
  204. "vfs.browser.filter-enabled"));
  205. filterCheckbox.addActionListener(actionHandler);
  206. if(mode != CHOOSE_DIRECTORY_DIALOG)
  207. {
  208. cons.gridx = 0;
  209. cons.weightx = 0.0f;
  210. cons.gridy = 1;
  211. layout.setConstraints(filterCheckbox,cons);
  212. pathAndFilterPanel.add(filterCheckbox);
  213. }
  214. filterField = new HistoryTextField("vfs.browser.filter");
  215. filterField.setInstantPopups(true);
  216. filterField.setSelectAllOnFocus(true);
  217. filterField.addActionListener(actionHandler);
  218. if(mode != CHOOSE_DIRECTORY_DIALOG)
  219. {
  220. cons.gridx = 1;
  221. cons.weightx = 1.0f;
  222. layout.setConstraints(filterField,cons);
  223. pathAndFilterPanel.add(filterField);
  224. }
  225. topBox.add(pathAndFilterPanel);
  226. add(BorderLayout.NORTH,topBox);
  227. add(BorderLayout.CENTER,browserView = new BrowserView(this));
  228. propertiesChanged();
  229. String filter;
  230. if(mode == BROWSER || !jEdit.getBooleanProperty(
  231. "vfs.browser.currentBufferFilter"))
  232. {
  233. filter = jEdit.getProperty("vfs.browser.last-filter");
  234. if(filter == null)
  235. filter = jEdit.getProperty("vfs.browser.default-filter");
  236. }
  237. else
  238. {
  239. String ext = MiscUtilities.getFileExtension(
  240. view.getBuffer().getName());
  241. if(ext.length() == 0)
  242. filter = jEdit.getProperty("vfs.browser.default-filter");
  243. else
  244. filter = "*" + ext;
  245. }
  246. filterField.setText(filter);
  247. filterField.addCurrentToHistory();
  248. updateFilterEnabled();
  249. // see VFSBrowser.browseDirectory()
  250. if(path == null)
  251. path = jEdit.getProperty("vfs.browser.path.tmp");
  252. if(path == null || path.length() == 0)
  253. {
  254. String userHome = System.getProperty("user.home");
  255. String defaultPath = jEdit.getProperty("vfs.browser.defaultPath");
  256. if(defaultPath.equals("home"))
  257. path = userHome;
  258. else if(defaultPath.equals("working"))
  259. path = System.getProperty("user.dir");
  260. else if(defaultPath.equals("buffer"))
  261. {
  262. if(view != null)
  263. {
  264. Buffer buffer = view.getBuffer();
  265. path = buffer.getDirectory();
  266. }
  267. else
  268. path = userHome;
  269. }
  270. else if(defaultPath.equals("last"))
  271. {
  272. HistoryModel pathModel = HistoryModel.getModel("vfs.browser.path");
  273. if(pathModel.getSize() == 0)
  274. path = "~";
  275. else
  276. path = pathModel.getItem(0);
  277. }
  278. else if(defaultPath.equals("favorites"))
  279. path = "favorites:";
  280. else
  281. {
  282. // unknown value??!!!
  283. path = userHome;
  284. }
  285. }
  286. final String _path = path;
  287. SwingUtilities.invokeLater(new Runnable()
  288. {
  289. public void run()
  290. {
  291. setDirectory(_path);
  292. }
  293. });
  294. } //}}}
  295. //{{{ focusOnDefaultComponent() method
  296. public void focusOnDefaultComponent()
  297. {
  298. browserView.focusOnFileView();
  299. } //}}}
  300. //{{{ addNotify() method
  301. public void addNotify()
  302. {
  303. super.addNotify();
  304. EditBus.addToBus(this);
  305. } //}}}
  306. //{{{ removeNotify() method
  307. public void removeNotify()
  308. {
  309. super.removeNotify();
  310. jEdit.setBooleanProperty("vfs.browser.filter-enabled",
  311. filterCheckbox.isSelected());
  312. if(mode == BROWSER || !jEdit.getBooleanProperty(
  313. "vfs.browser.currentBufferFilter"))
  314. {
  315. jEdit.setProperty("vfs.browser.last-filter",
  316. filterField.getText());
  317. }
  318. EditBus.removeFromBus(this);
  319. } //}}}
  320. //{{{ handleMessage() method
  321. public void handleMessage(EBMessage msg)
  322. {
  323. if(msg instanceof PropertiesChanged)
  324. propertiesChanged();
  325. else if(msg instanceof BufferUpdate)
  326. {
  327. BufferUpdate bmsg = (BufferUpdate)msg;
  328. if(bmsg.getWhat() == BufferUpdate.CREATED
  329. || bmsg.getWhat() == BufferUpdate.CLOSED)
  330. browserView.updateFileView();
  331. // hacked BufferIORequest to send VFSUpdates in case
  332. // two stage save is off now...
  333. /* else if(bmsg.getWhat() == BufferUpdate.SAVED)
  334. {
  335. maybeReloadDirectory(MiscUtilities.getParentOfPath(
  336. bmsg.getBuffer().getPath()));
  337. } */
  338. }
  339. else if(msg instanceof VFSUpdate)
  340. {
  341. maybeReloadDirectory(((VFSUpdate)msg).getPath());
  342. }
  343. } //}}}
  344. //{{{ getView() method
  345. public View getView()
  346. {
  347. return view;
  348. } //}}}
  349. //{{{ getMode() method
  350. public int getMode()
  351. {
  352. return mode;
  353. } //}}}
  354. //{{{ isMultipleSelectionEnabled() method
  355. public boolean isMultipleSelectionEnabled()
  356. {
  357. return multipleSelection;
  358. } //}}}
  359. //{{{ isHorizontalLayout() method
  360. public boolean isHorizontalLayout()
  361. {
  362. return horizontalLayout;
  363. } //}}}
  364. //{{{ getShowHiddenFiles() method
  365. public boolean getShowHiddenFiles()
  366. {
  367. return showHiddenFiles;
  368. } //}}}
  369. //{{{ setShowHiddenFiles() method
  370. public void setShowHiddenFiles(boolean showHiddenFiles)
  371. {
  372. this.showHiddenFiles = showHiddenFiles;
  373. } //}}}
  374. //{{{ getFilenameFilter() method
  375. /**
  376. * Returns the file name filter glob.
  377. * @since jEdit 3.2pre2
  378. */
  379. public String getFilenameFilter()
  380. {
  381. if(filterCheckbox.isSelected())
  382. {
  383. String filter = filterField.getText();
  384. if(filter.length() == 0)
  385. return "*";
  386. else
  387. return filter;
  388. }
  389. else
  390. return "*";
  391. } //}}}
  392. //{{{ setFilenameFilter() method
  393. public void setFilenameFilter(String filter)
  394. {
  395. if(filter == null || filter.length() == 0 || filter.equals("*"))
  396. filterCheckbox.setSelected(false);
  397. else
  398. {
  399. filterCheckbox.setSelected(true);
  400. filterField.setText(filter);
  401. }
  402. } //}}}
  403. //{{{ getDirectoryField() method
  404. public HistoryTextField getDirectoryField()
  405. {
  406. return pathField;
  407. } //}}}
  408. //{{{ getDirectory() method
  409. public String getDirectory()
  410. {
  411. return path;
  412. } //}}}
  413. //{{{ setDirectory() method
  414. public void setDirectory(String path)
  415. {
  416. if(path.startsWith("file:"))
  417. path = path.substring(5);
  418. pathField.setText(path);
  419. if(!startRequest())
  420. return;
  421. updateFilenameFilter();
  422. browserView.saveExpansionState();
  423. browserView.loadDirectory(null,path);
  424. this.path = path;
  425. VFSManager.runInAWTThread(new Runnable()
  426. {
  427. public void run()
  428. {
  429. endRequest();
  430. }
  431. });
  432. } //}}}
  433. //{{{ rootDirectory() method
  434. /**
  435. * Goes to the local drives directory.
  436. * @since jEdit 4.0pre4
  437. */
  438. public void rootDirectory()
  439. {
  440. if(OperatingSystem.isMacOS() || OperatingSystem.isDOSDerived())
  441. setDirectory(FileRootsVFS.PROTOCOL + ":");
  442. else
  443. setDirectory("/");
  444. } //}}}
  445. //{{{ reloadDirectory() method
  446. public void reloadDirectory()
  447. {
  448. // used by FTP plugin to clear directory cache
  449. VFSManager.getVFSForPath(path).reloadDirectory(path);
  450. updateFilenameFilter();
  451. browserView.saveExpansionState();
  452. browserView.loadDirectory(null,path);
  453. } //}}}
  454. //{{{ delete() method
  455. /**
  456. * Note that all files must be on the same VFS.
  457. */
  458. public void delete(VFS.DirectoryEntry[] files)
  459. {
  460. String dialogType;
  461. if(MiscUtilities.isURL(files[0].deletePath)
  462. && FavoritesVFS.PROTOCOL.equals(
  463. MiscUtilities.getProtocolOfURL(files[0].deletePath)))
  464. {
  465. dialogType = "vfs.browser.delete-favorites";
  466. }
  467. else
  468. {
  469. dialogType = "vfs.browser.delete-confirm";
  470. }
  471. StringBuffer buf = new StringBuffer();
  472. for(int i = 0; i < files.length; i++)
  473. {
  474. buf.append(files[i].path);
  475. buf.append('\n');
  476. }
  477. Object[] args = { buf.toString() };
  478. int result = GUIUtilities.confirm(this,dialogType,args,
  479. JOptionPane.YES_NO_OPTION,
  480. JOptionPane.WARNING_MESSAGE);
  481. if(result != JOptionPane.YES_OPTION)
  482. return;
  483. VFS vfs = VFSManager.getVFSForPath(files[0].deletePath);
  484. if(!startRequest())
  485. return;
  486. for(int i = 0; i < files.length; i++)
  487. {
  488. Object session = vfs.createVFSSession(files[i].deletePath,this);
  489. if(session == null)
  490. continue;
  491. VFSManager.runInWorkThread(new BrowserIORequest(
  492. BrowserIORequest.DELETE,this,
  493. session,vfs,files[i].deletePath,
  494. null,null,null));
  495. }
  496. VFSManager.runInAWTThread(new Runnable()
  497. {
  498. public void run()
  499. {
  500. endRequest();
  501. }
  502. });
  503. } //}}}
  504. //{{{ rename() method
  505. public void rename(String from)
  506. {
  507. VFS vfs = VFSManager.getVFSForPath(from);
  508. String filename = vfs.getFileName(from);
  509. String[] args = { filename };
  510. String to = GUIUtilities.input(this,"vfs.browser.rename",
  511. args,filename);
  512. if(to == null)
  513. return;
  514. to = MiscUtilities.constructPath(vfs.getParentOfPath(from),to);
  515. Object session = vfs.createVFSSession(from,this);
  516. if(session == null)
  517. return;
  518. if(!startRequest())
  519. return;
  520. VFSManager.runInWorkThread(new BrowserIORequest(
  521. BrowserIORequest.RENAME,this,
  522. session,vfs,from,to,null,null));
  523. VFSManager.runInAWTThread(new Runnable()
  524. {
  525. public void run()
  526. {
  527. endRequest();
  528. }
  529. });
  530. } //}}}
  531. //{{{ mkdir() method
  532. public void mkdir()
  533. {
  534. String newDirectory = GUIUtilities.input(this,"vfs.browser.mkdir",null);
  535. if(newDirectory == null)
  536. return;
  537. // if a directory is selected, create new dir in there.
  538. // if a file is selected, create new dir inside its parent.
  539. VFS.DirectoryEntry[] selected = getSelectedFiles();
  540. String parent;
  541. if(selected.length == 0)
  542. parent = path;
  543. else if(selected[0].type == VFS.DirectoryEntry.FILE)
  544. {
  545. parent = selected[0].path;
  546. parent = VFSManager.getVFSForPath(parent)
  547. .getParentOfPath(parent);
  548. }
  549. else
  550. parent = selected[0].path;
  551. VFS vfs = VFSManager.getVFSForPath(parent);
  552. // path is the currently viewed directory in the browser
  553. newDirectory = MiscUtilities.constructPath(parent,newDirectory);
  554. Object session = vfs.createVFSSession(newDirectory,this);
  555. if(session == null)
  556. return;
  557. if(!startRequest())
  558. return;
  559. VFSManager.runInWorkThread(new BrowserIORequest(
  560. BrowserIORequest.MKDIR,this,
  561. session,vfs,newDirectory,null,null,null));
  562. VFSManager.runInAWTThread(new Runnable()
  563. {
  564. public void run()
  565. {
  566. endRequest();
  567. }
  568. });
  569. } //}}}
  570. //{{{ newFile() method
  571. /**
  572. * Creates a new file in the current directory.
  573. * @since jEdit 4.0pre2
  574. */
  575. public void newFile()
  576. {
  577. VFS.DirectoryEntry[] selected = getSelectedFiles();
  578. if(selected.length >= 1)
  579. {
  580. VFS.DirectoryEntry file = selected[0];
  581. if(file.type == VFS.DirectoryEntry.DIRECTORY)
  582. jEdit.newFile(view,file.path);
  583. else
  584. {
  585. VFS vfs = VFSManager.getVFSForPath(file.path);
  586. jEdit.newFile(view,vfs.getParentOfPath(file.path));
  587. }
  588. }
  589. else
  590. jEdit.newFile(view,path);
  591. } //}}}
  592. //{{{ searchInDirectory() method
  593. /**
  594. * Opens a directory search in the current directory.
  595. * @since jEdit 4.0pre2
  596. */
  597. public void searchInDirectory()
  598. {
  599. VFS.DirectoryEntry[] selected = getSelectedFiles();
  600. if(selected.length >= 1)
  601. {
  602. VFS.DirectoryEntry file = selected[0];
  603. searchInDirectory(file.path,file.type != VFS.DirectoryEntry.FILE);
  604. }
  605. else
  606. {
  607. searchInDirectory(this.path,true);
  608. }
  609. } //}}}
  610. //{{{ searchInDirectory() method
  611. /**
  612. * Opens a directory search in the specified directory.
  613. * @param path The path name
  614. * @param directory True if the path is a directory, false if it is a file
  615. * @since jEdit 4.2pre1
  616. */
  617. public void searchInDirectory(String path, boolean directory)
  618. {
  619. String filter;
  620. if(directory)
  621. {
  622. filter = getFilenameFilter();
  623. }
  624. else
  625. {
  626. String name = MiscUtilities.getFileName(path);
  627. String ext = MiscUtilities.getFileExtension(name);
  628. filter = (ext == null || ext.length() == 0
  629. ? getFilenameFilter()
  630. : "*" + ext);
  631. path = MiscUtilities.getParentOfPath(path);
  632. }
  633. SearchAndReplace.setSearchFileSet(new DirectoryListSet(
  634. path,filter,true));
  635. SearchDialog.showSearchDialog(view,null,SearchDialog.DIRECTORY);
  636. } //}}}
  637. //{{{ getBrowserView() method
  638. public BrowserView getBrowserView()
  639. {
  640. return browserView;
  641. } //}}}
  642. //{{{ getSelectedFiles() method
  643. public VFS.DirectoryEntry[] getSelectedFiles()
  644. {
  645. return browserView.getSelectedFiles();
  646. } //}}}
  647. //{{{ locateFile() method
  648. /**
  649. * Goes to the given file's directory and selects the file in the list.
  650. * @param path The file
  651. * @since jEdit 4.2pre2
  652. */
  653. public void locateFile(final String path)
  654. {
  655. if(!filenameFilter.isMatch(MiscUtilities.getFileName(path)))
  656. setFilenameFilter(null);
  657. setDirectory(MiscUtilities.getParentOfPath(path));
  658. VFSManager.runInAWTThread(new Runnable()
  659. {
  660. public void run()
  661. {
  662. browserView.getTable().selectFile(path);
  663. }
  664. });
  665. } //}}}
  666. //{{{ addBrowserListener() method
  667. public void addBrowserListener(BrowserListener l)
  668. {
  669. listenerList.add(BrowserListener.class,l);
  670. } //}}}
  671. //{{{ removeBrowserListener() method
  672. public void removeBrowserListener(BrowserListener l)
  673. {
  674. listenerList.remove(BrowserListener.class,l);
  675. } //}}}
  676. //{{{ filesActivated() method
  677. // canDoubleClickClose set to false when ENTER pressed
  678. public static final int M_OPEN = 0;
  679. public static final int M_OPEN_NEW_VIEW = 1;
  680. public static final int M_OPEN_NEW_PLAIN_VIEW = 2;
  681. public static final int M_OPEN_NEW_SPLIT = 3;
  682. /**
  683. * This method does the "double-click" handling. It is public so that
  684. * <code>browser.actions.xml</code> can bind to it.
  685. * @since jEdit 4.2pre2
  686. */
  687. public void filesActivated(int mode, boolean canDoubleClickClose)
  688. {
  689. VFS.DirectoryEntry[] selectedFiles = browserView.getSelectedFiles();
  690. Buffer buffer = null;
  691. check_selected: for(int i = 0; i < selectedFiles.length; i++)
  692. {
  693. VFS.DirectoryEntry file = selectedFiles[i];
  694. if(file.type == VFS.DirectoryEntry.DIRECTORY
  695. || file.type == VFS.DirectoryEntry.FILESYSTEM)
  696. {
  697. if(mode == M_OPEN_NEW_VIEW && this.mode == BROWSER)
  698. browseDirectoryInNewWindow(view,file.path);
  699. else
  700. setDirectory(file.path);
  701. }
  702. else if(this.mode == BROWSER || this.mode == BROWSER_DIALOG)
  703. {
  704. Buffer _buffer = jEdit.getBuffer(file.path);
  705. if(_buffer == null)
  706. {
  707. Hashtable props = new Hashtable();
  708. props.put(Buffer.ENCODING,currentEncoding);
  709. _buffer = jEdit.openFile(null,null,file.path,
  710. false,props);
  711. }
  712. else if(doubleClickClose && canDoubleClickClose
  713. && this.mode != BROWSER_DIALOG
  714. && selectedFiles.length == 1)
  715. {
  716. // close if this buffer is currently
  717. // visible in the view.
  718. EditPane[] editPanes = view.getEditPanes();
  719. for(int j = 0; j < editPanes.length; j++)
  720. {
  721. if(editPanes[j].getBuffer() == _buffer)
  722. {
  723. jEdit.closeBuffer(view,_buffer);
  724. return;
  725. }
  726. }
  727. }
  728. if(_buffer != null)
  729. buffer = _buffer;
  730. }
  731. else
  732. {
  733. // if a file is selected in OPEN_DIALOG or
  734. // SAVE_DIALOG mode, just let the listener(s)
  735. // handle it
  736. }
  737. }
  738. if(buffer != null)
  739. {
  740. switch(mode)
  741. {
  742. case M_OPEN:
  743. view.setBuffer(buffer);
  744. break;
  745. case M_OPEN_NEW_VIEW:
  746. jEdit.newView(view,buffer,false);
  747. break;
  748. case M_OPEN_NEW_PLAIN_VIEW:
  749. jEdit.newView(view,buffer,true);
  750. break;
  751. case M_OPEN_NEW_SPLIT:
  752. view.splitHorizontally().setBuffer(buffer);
  753. break;
  754. }
  755. }
  756. Object[] listeners = listenerList.getListenerList();
  757. for(int i = 0; i < listeners.length; i++)
  758. {
  759. if(listeners[i] == BrowserListener.class)
  760. {
  761. BrowserListener l = (BrowserListener)listeners[i+1];
  762. l.filesActivated(this,selectedFiles);
  763. }
  764. }
  765. } //}}}
  766. //{{{ Package-private members
  767. String currentEncoding;
  768. //{{{ pathsEqual() method
  769. /**
  770. * This will be made public at some stage, in the io package, but not
  771. * yet.
  772. */
  773. static boolean pathsEqual(String p1, String p2)
  774. {
  775. if(p1.endsWith("/") || p1.endsWith(File.separator))
  776. p1 = p1.substring(0,p1.length() - 1);
  777. if(p2.endsWith("/") || p2.endsWith(File.separator))
  778. p2 = p2.substring(0,p2.length() - 1);
  779. return p1.equals(p2);
  780. } //}}}
  781. //{{{ updateFilenameFilter() method
  782. void updateFilenameFilter()
  783. {
  784. try
  785. {
  786. String filter = filterField.getText();
  787. if(filter.length() == 0)
  788. filter = "*";
  789. filenameFilter = new RE(MiscUtilities.globToRE(filter),RE.REG_ICASE);
  790. }
  791. catch(Exception e)
  792. {
  793. Log.log(Log.ERROR,VFSBrowser.this,e);
  794. String[] args = { filterField.getText(),
  795. e.getMessage() };
  796. GUIUtilities.error(this,"vfs.browser.bad-filter",args);
  797. }
  798. } //}}}
  799. //{{{ directoryLoaded() method
  800. void directoryLoaded(Object node, Object[] loadInfo)
  801. {
  802. VFSManager.runInAWTThread(new DirectoryLoadedAWTRequest(
  803. node,loadInfo));
  804. } //}}}
  805. //{{{ filesSelected() method
  806. void filesSelected()
  807. {
  808. VFS.DirectoryEntry[] selectedFiles = browserView.getSelectedFiles();
  809. if(mode == BROWSER)
  810. {
  811. for(int i = 0; i < selectedFiles.length; i++)
  812. {
  813. VFS.DirectoryEntry file = selectedFiles[i];
  814. Buffer buffer = jEdit.getBuffer(file.path);
  815. if(buffer != null && view != null)
  816. view.setBuffer(buffer);
  817. }
  818. }
  819. Object[] listeners = listenerList.getListenerList();
  820. for(int i = 0; i < listeners.length; i++)
  821. {
  822. if(listeners[i] == BrowserListener.class)
  823. {
  824. BrowserListener l = (BrowserListener)listeners[i+1];
  825. l.filesSelected(this,selectedFiles);
  826. }
  827. }
  828. } //}}}
  829. //{{{ endRequest() method
  830. void endRequest()
  831. {
  832. requestRunning = false;
  833. } //}}}
  834. //}}}
  835. //{{{ Private members
  836. private static ActionContext actionContext;
  837. static
  838. {
  839. actionContext = new ActionContext()
  840. {
  841. public void invokeAction(EventObject evt,
  842. EditAction action)
  843. {
  844. VFSBrowser browser = (VFSBrowser)
  845. GUIUtilities.getComponentParent(
  846. (Component)evt.getSource(),
  847. VFSBrowser.class);
  848. // in the future we will want something better,
  849. // eg. having an 'evt' object passed to
  850. // EditAction.invoke().
  851. // for now, since all browser actions are
  852. // written in beanshell we set the 'browser'
  853. // variable directly.
  854. NameSpace global = BeanShell.getNameSpace();
  855. try
  856. {
  857. global.setVariable("browser",
  858. browser);
  859. global.setVariable("files",
  860. browser.getSelectedFiles());
  861. action.invoke(browser.getView());
  862. }
  863. catch(UtilEvalError err)
  864. {
  865. Log.log(Log.ERROR,this,err);
  866. }
  867. finally
  868. {
  869. try
  870. {
  871. global.setVariable("browser",null);
  872. global.setVariable("files",null);
  873. }
  874. catch(UtilEvalError err)
  875. {
  876. Log.log(Log.ERROR,this,err);
  877. }
  878. }
  879. }
  880. };
  881. ActionSet builtInActionSet = new ActionSet(null,null,null,
  882. jEdit.class.getResource("browser.actions.xml"));
  883. builtInActionSet.load();
  884. actionContext.addActionSet(builtInActionSet);
  885. }
  886. //{{{ Instance variables
  887. private EventListenerList listenerList;
  888. private View view;
  889. private boolean floating;
  890. private boolean horizontalLayout;
  891. private String path;
  892. private HistoryTextField pathField;
  893. private JCheckBox filterCheckbox;
  894. private HistoryTextField filterField;
  895. private Box toolbarBox;
  896. private FavoritesMenuButton favorites;
  897. private BrowserView browserView;
  898. private RE filenameFilter;
  899. private int mode;
  900. private boolean multipleSelection;
  901. private boolean showHiddenFiles;
  902. private boolean sortMixFilesAndDirs;
  903. private boolean sortIgnoreCase;
  904. private boolean doubleClickClose;
  905. private boolean requestRunning;
  906. //}}}
  907. //{{{ createMenuBar() method
  908. private JPanel createMenuBar()
  909. {
  910. JPanel menuBar = new JPanel();
  911. menuBar.setLayout(new BoxLayout(menuBar,BoxLayout.X_AXIS));
  912. menuBar.setBorder(new EmptyBorder(0,3,1,0));
  913. menuBar.add(new CommandsMenuButton());
  914. menuBar.add(Box.createHorizontalStrut(3));
  915. menuBar.add(new PluginsMenuButton());
  916. menuBar.add(Box.createHorizontalStrut(3));
  917. menuBar.add(favorites = new FavoritesMenuButton());
  918. return menuBar;
  919. } //}}}
  920. //{{{ createToolBar() method
  921. private Box createToolBar()
  922. {
  923. if(mode == BROWSER)
  924. return GUIUtilities.loadToolBar(actionContext,
  925. "vfs.browser.toolbar-browser");
  926. else
  927. return GUIUtilities.loadToolBar(actionContext,
  928. "vfs.browser.toolbar-dialog");
  929. } //}}}
  930. //{{{ propertiesChanged() method
  931. private void propertiesChanged()
  932. {
  933. showHiddenFiles = jEdit.getBooleanProperty("vfs.browser.showHiddenFiles");
  934. sortMixFilesAndDirs = jEdit.getBooleanProperty("vfs.browser.sortMixFilesAndDirs");
  935. sortIgnoreCase = jEdit.getBooleanProperty("vfs.browser.sortIgnoreCase");
  936. doubleClickClose = jEdit.getBooleanProperty("vfs.browser.doubleClickClose");
  937. browserView.propertiesChanged();
  938. toolbarBox.removeAll();
  939. if(jEdit.getBooleanProperty("vfs.browser.showToolbar"))
  940. {
  941. Box toolbar = createToolBar();
  942. if(horizontalLayout)
  943. toolbarBox.add(toolbar);
  944. else
  945. {
  946. toolbar.add(Box.createGlue());
  947. toolbarBox.add(toolbar);
  948. }
  949. }
  950. if(jEdit.getBooleanProperty("vfs.browser.showMenubar"))
  951. {
  952. JPanel menubar = createMenuBar();
  953. if(horizontalLayout)
  954. {
  955. toolbarBox.add(Box.createHorizontalStrut(6));
  956. toolbarBox.add(menubar,0);
  957. }
  958. else
  959. {
  960. menubar.add(Box.createGlue());
  961. toolbarBox.add(menubar);
  962. }
  963. }
  964. else
  965. favorites = null;
  966. toolbarBox.add(Box.createGlue());
  967. revalidate();
  968. if(path != null)
  969. reloadDirectory();
  970. } //}}}
  971. /* We do this stuff because the browser is not able to handle
  972. * more than one request yet */
  973. //{{{ startRequest() method
  974. private boolean startRequest()
  975. {
  976. if(requestRunning)
  977. {
  978. // dump stack trace for debugging purposes
  979. Log.log(Log.DEBUG,this,new Throwable("For debugging purposes"));
  980. GUIUtilities.error(this,"browser-multiple-io",null);
  981. return false;
  982. }
  983. else
  984. {
  985. requestRunning = true;
  986. return true;
  987. }
  988. } //}}}
  989. //{{{ updateFilterEnabled() method
  990. private void updateFilterEnabled()
  991. {
  992. filterField.setEnabled(filterCheckbox.isSelected());
  993. } //}}}
  994. //{{{ maybeReloadDirectory() method
  995. private void maybeReloadDirectory(String dir)
  996. {
  997. if(MiscUtilities.isURL(dir)
  998. && MiscUtilities.getProtocolOfURL(dir).equals(
  999. FavoritesVFS.PROTOCOL))
  1000. {
  1001. if(favorites != null)
  1002. favorites.popup = null;
  1003. }
  1004. // this is a dirty hack and it relies on the fact
  1005. // that updates for parents are sent before updates
  1006. // for the changed nodes themselves (if this was not
  1007. // the case, the browser wouldn't be updated properly
  1008. // on delete, etc).
  1009. //
  1010. // to avoid causing '> 1 request' errors, don't reload
  1011. // directory if request already active
  1012. if(requestRunning)
  1013. return;
  1014. // save a file -> sends vfs update. if a VFS file dialog box
  1015. // is shown from the same event frame as the save, the
  1016. // VFSUpdate will be delivered before the directory is loaded,
  1017. // and before the path is set.
  1018. if(path != null)
  1019. {
  1020. try
  1021. {
  1022. requestRunning = true;
  1023. browserView.maybeReloadDirectory(dir);
  1024. }
  1025. finally
  1026. {
  1027. VFSManager.runInAWTThread(new Runnable()
  1028. {
  1029. public void run()
  1030. {
  1031. requestRunning = false;
  1032. }
  1033. });
  1034. }
  1035. }
  1036. } //}}}
  1037. //}}}
  1038. //{{{ Inner classes
  1039. //{{{ ActionHandler class
  1040. class ActionHandler implements ActionListener
  1041. {
  1042. public void actionPerformed(ActionEvent evt)
  1043. {
  1044. Object source = evt.getSource();
  1045. if(source == pathField || source == filterField
  1046. || source == filterCheckbox)
  1047. {
  1048. updateFilterEnabled();
  1049. String path = pathField.getText();
  1050. if(path != null)
  1051. setDirectory(path);
  1052. browserView.focusOnFileView();
  1053. }
  1054. }
  1055. } //}}}
  1056. //{{{ CommandsMenuButton class
  1057. class CommandsMenuButton extends JButton
  1058. {
  1059. //{{{ CommandsMenuButton constructor
  1060. CommandsMenuButton()
  1061. {
  1062. setText(jEdit.getProperty("vfs.browser.commands.label"));
  1063. setIcon(GUIUtilities.loadIcon("ToolbarMenu.gif"));
  1064. setHorizontalTextPosition(SwingConstants.LEADING);
  1065. popup = new BrowserCommandsMenu(VFSBrowser.this,null);
  1066. CommandsMenuButton.this.setRequestFocusEnabled(false);
  1067. setMargin(new Insets(1,1,1,1));
  1068. CommandsMenuButton.this.addMouseListener(new MouseHandler());
  1069. if(OperatingSystem.isMacOSLF())
  1070. CommandsMenuButton.this.putClientProperty("JButton.buttonType","toolbar");
  1071. } //}}}
  1072. BrowserCommandsMenu popup;
  1073. //{{{ MouseHandler class
  1074. class MouseHandler extends MouseAdapter
  1075. {
  1076. public void mousePressed(MouseEvent evt)
  1077. {
  1078. if(!popup.isVisible())
  1079. {
  1080. popup.update();
  1081. GUIUtilities.showPopupMenu(
  1082. popup,CommandsMenuButton.this,0,
  1083. CommandsMenuButton.this.getHeight(),
  1084. false);
  1085. }
  1086. else
  1087. {
  1088. popup.setVisible(false);
  1089. }
  1090. }
  1091. } //}}}
  1092. } //}}}
  1093. //{{{ PluginsMenuButton class
  1094. class PluginsMenuButton extends JButton
  1095. {
  1096. //{{{ PluginsMenuButton constructor
  1097. PluginsMenuButton()
  1098. {
  1099. setText(jEdit.getProperty("vfs.browser.plugins.label"));
  1100. setIcon(GUIUtilities.loadIcon("ToolbarMenu.gif"));
  1101. setHorizontalTextPosition(SwingConstants.LEADING);
  1102. PluginsMenuButton.this.setRequestFocusEnabled(false);
  1103. setMargin(new Insets(1,1,1,1));
  1104. PluginsMenuButton.this.addMouseListener(new MouseHandler());
  1105. if(OperatingSystem.isMacOSLF())
  1106. PluginsMenuButton.this.putClientProperty("JButton.buttonType","toolbar");
  1107. } //}}}
  1108. JPopupMenu popup;
  1109. //{{{ createPopupMenu() method
  1110. private void createPopupMenu()
  1111. {
  1112. if(popup != null)
  1113. return;
  1114. popup = new JPopupMenu();
  1115. ActionHandler actionHandler = new ActionHandler();
  1116. if(getMode() == BROWSER)
  1117. {
  1118. popup.add(GUIUtilities.loadMenuItem("plugin-manager",false));
  1119. popup.add(GUIUtilities.loadMenuItem("plugin-options",false));
  1120. popup.addSeparator();
  1121. }
  1122. else
  1123. /* we're in a modal dialog */;
  1124. ArrayList vec = new ArrayList();
  1125. //{{{ old API
  1126. Enumeration enum = VFSManager.getFilesystems();
  1127. while(enum.hasMoreElements())
  1128. {
  1129. VFS vfs = (VFS)enum.nextElement();
  1130. if((vfs.getCapabilities() & VFS.BROWSE_CAP) == 0)
  1131. continue;
  1132. JMenuItem menuItem = new JMenuItem(jEdit.getProperty(
  1133. "vfs." + vfs.getName() + ".label"));
  1134. menuItem.setActionCommand(vfs.getName());
  1135. menuItem.addActionListener(actionHandler);
  1136. vec.add(menuItem);
  1137. } //}}}
  1138. //{{{ new API
  1139. EditPlugin[] plugins = jEdit.getPlugins();
  1140. for(int i = 0; i < plugins.length; i++)
  1141. {
  1142. JMenuItem menuItem = plugins[i].createBrowserMenuItems();
  1143. if(menuItem != null)
  1144. vec.add(menuItem);
  1145. } //}}}
  1146. if(vec.size() != 0)
  1147. {
  1148. MiscUtilities.quicksort(vec,new MiscUtilities.MenuItemCompare());
  1149. for(int i = 0; i < vec.size(); i++)
  1150. popup.add((JMenuItem)vec.get(i));
  1151. }
  1152. else
  1153. {
  1154. JMenuItem mi = new JMenuItem(jEdit.getProperty(
  1155. "vfs.browser.plugins.no-plugins.label"));
  1156. mi.setEnabled(false);
  1157. popup.add(mi);
  1158. }
  1159. } //}}}
  1160. //{{{ ActionHandler class
  1161. class ActionHandler implements ActionListener
  1162. {
  1163. public void actionPerformed(ActionEvent evt)
  1164. {
  1165. VFS vfs = VFSManager.getVFSByName(evt.getActionCommand());
  1166. String directory = vfs.showBrowseDialog(null,
  1167. VFSBrowser.this);
  1168. if(directory != null)
  1169. setDirectory(directory);
  1170. }
  1171. } //}}}
  1172. //{{{ MouseHandler class
  1173. class MouseHandler extends MouseAdapter
  1174. {
  1175. public void mousePressed(MouseEvent evt)
  1176. {
  1177. createPopupMenu();
  1178. if(!popup.isVisible())
  1179. {
  1180. GUIUtilities.showPopupMenu(
  1181. popup,PluginsMenuButton.this,0,
  1182. PluginsMenuButton.this.getHeight(),
  1183. false);
  1184. }
  1185. else
  1186. {
  1187. popup.setVisible(false);
  1188. }
  1189. }
  1190. } //}}}
  1191. } //}}}
  1192. //{{{ FavoritesMenuButton class
  1193. class FavoritesMenuButton extends JButton
  1194. {
  1195. //{{{ FavoritesMenuButton constructor
  1196. FavoritesMenuButton()
  1197. {
  1198. setText(jEdit.getProperty("vfs.browser.favorites.label"));
  1199. setIcon(GUIUtilities.loadIcon("ToolbarMenu.gif"));
  1200. setHorizontalTextPosition(SwingConstants.LEADING);
  1201. FavoritesMenuButton.this.setRequestFocusEnabled(false);
  1202. setMargin(new Insets(1,1,1,1));
  1203. FavoritesMenuButton.this.addMouseListener(new MouseHandler());
  1204. if(OperatingSystem.isMacOSLF())
  1205. FavoritesMenuButton.this.putClientProperty("JButton.buttonType","toolbar");
  1206. } //}}}
  1207. JPopupMenu popup;
  1208. //{{{ createPopupMenu() method
  1209. void createPopupMenu()
  1210. {
  1211. popup = new JPopupMenu();
  1212. ActionHandler actionHandler = new ActionHandler();
  1213. JMenuItem mi = new JMenuItem(
  1214. jEdit.getProperty(
  1215. "vfs.browser.favorites"
  1216. + ".add-to-favorites.label"));
  1217. mi.setActionCommand("add-to-favorites");
  1218. mi.addActionListener(actionHandler);
  1219. popup.add(mi);
  1220. mi = new JMenuItem(
  1221. jEdit.getProperty(
  1222. "vfs.browser.favorites"
  1223. + ".edit-favorites.label"));
  1224. mi.setActionCommand("dir@favorites:");
  1225. mi.addActionListener(actionHandler);
  1226. popup.add(mi);
  1227. popup.addSeparator();
  1228. VFS.DirectoryEntry[] favorites
  1229. = FavoritesVFS.getFavorites();
  1230. if(favorites.length == 0)
  1231. {
  1232. mi = new JMenuItem(
  1233. jEdit.getProperty(
  1234. "vfs.browser.favorites"
  1235. + ".no-favorites.label"));
  1236. mi.setEnabled(false);
  1237. popup.add(mi);
  1238. }
  1239. else
  1240. {
  1241. MiscUtilities.quicksort(favorites,
  1242. new VFS.DirectoryEntryCompare(
  1243. sortMixFilesAndDirs,
  1244. sortIgnoreCase));
  1245. for(int i = 0; i < favorites.length; i++)
  1246. {
  1247. VFS.DirectoryEntry favorite
  1248. = favorites[i];
  1249. mi = new JMenuItem(favorite.path);
  1250. mi.setIcon(FileCellRenderer
  1251. .getIconForFile(
  1252. favorite,false));
  1253. String cmd = (favorite.type ==
  1254. VFS.DirectoryEntry.FILE
  1255. ? "file@" : "dir@")
  1256. + favorite.path;
  1257. mi.setActionCommand(cmd);
  1258. mi.addActionListener(actionHandler);
  1259. popup.add(mi);
  1260. }
  1261. }
  1262. } //}}}
  1263. //{{{ ActionHandler class
  1264. class ActionHandler implements ActionListener
  1265. {
  1266. public void actionPerformed(ActionEvent evt)
  1267. {
  1268. String actionCommand = evt.getActionCommand();
  1269. if(actionCommand.equals("add-to-favorites"))
  1270. {
  1271. // if any directories are selected, add
  1272. // them, otherwise add current directory
  1273. ArrayList toAdd = new ArrayList();
  1274. VFS.DirectoryEntry[] selected = getSelectedFiles();
  1275. if(selected == null || selected.length == 0)
  1276. {
  1277. if(path.equals(FavoritesVFS.PROTOCOL + ":"))
  1278. {
  1279. GUIUtilities.error(VFSBrowser.this,
  1280. "vfs.browser.recurse-favorites",
  1281. null);
  1282. }
  1283. else
  1284. {
  1285. FavoritesVFS.addToFavorites(path,
  1286. VFS.DirectoryEntry.DIRECTORY);
  1287. }
  1288. }
  1289. else
  1290. {
  1291. for(int i = 0; i < selected.length; i++)
  1292. {
  1293. VFS.DirectoryEntry file
  1294. = selected[i];
  1295. FavoritesVFS.addToFavorites(file.path,file.type);
  1296. }
  1297. }
  1298. }
  1299. else if(actionCommand.startsWith("dir@"))
  1300. {
  1301. setDirectory(actionCommand.substring(4));
  1302. }
  1303. else if(actionCommand.startsWith("file@"))
  1304. {
  1305. switch(getMode())
  1306. {
  1307. case BROWSER:
  1308. jEdit.openFile(view,actionCommand.substring(5));
  1309. break;
  1310. default:
  1311. locateFile(actionCommand.substring(5));
  1312. break;
  1313. }
  1314. }
  1315. }
  1316. } //}}}
  1317. //{{{ MouseHandler class
  1318. class MouseHandler extends MouseAdapter
  1319. {
  1320. public void mousePressed(MouseEvent evt)
  1321. {
  1322. if(popup != null && popup.isVisible())
  1323. {
  1324. popup.setVisible(false);
  1325. return;
  1326. }
  1327. if(popup == null)
  1328. createPopupMenu();
  1329. GUIUtilities.showPopupMenu(
  1330. popup,FavoritesMenuButton.this,0,
  1331. FavoritesMenuButton.this.getHeight(),
  1332. false);
  1333. }
  1334. } //}}}
  1335. } //}}}
  1336. //{{{ DirectoryLoadedAWTRequest class
  1337. class DirectoryLoadedAWTRequest implements Runnable
  1338. {
  1339. Object node;
  1340. Object[] loadInfo;
  1341. DirectoryLoadedAWTRequest(Object node, Object[] loadInfo)
  1342. {
  1343. this.node = node;
  1344. this.loadInfo = loadInfo;
  1345. }
  1346. public void run()
  1347. {
  1348. String path = (String)loadInfo[0];
  1349. VFS.DirectoryEntry[] list = (VFS.DirectoryEntry[])
  1350. loadInfo[1];
  1351. if(node == null)
  1352. {
  1353. // This is the new, canonical path
  1354. VFSBrowser.this.path = path;
  1355. if(!pathField.getText().equals(path))
  1356. pathField.setText(path);
  1357. if(path.endsWith("/") ||
  1358. path.endsWith(File.separator))
  1359. {
  1360. // ensure consistent history;
  1361. // eg we don't want both
  1362. // foo/ and foo
  1363. path = path.substring(0,
  1364. path.length() - 1);
  1365. }
  1366. HistoryModel.getModel("vfs.browser.path")
  1367. .addItem(path);
  1368. }
  1369. boolean filterEnabled = filterCheckbox.isSelected();
  1370. ArrayList directoryVector = new ArrayList();
  1371. int directories = 0;
  1372. int files = 0;
  1373. int invisible = 0;
  1374. if(list != null)
  1375. {
  1376. for(int i = 0; i < list.length; i++)
  1377. {
  1378. VFS.DirectoryEntry file = list[i];
  1379. if(file.hidden && !showHiddenFiles)
  1380. {
  1381. invisible++;
  1382. continue;
  1383. }
  1384. if(file.type == VFS.DirectoryEntry.FILE
  1385. && filterEnabled
  1386. && filenameFilter != null
  1387. && !filenameFilter.isMatch(file.name))
  1388. {
  1389. invisible++;
  1390. continue;
  1391. }
  1392. if(file.type == VFS.DirectoryEntry.FILE)
  1393. files++;
  1394. else
  1395. directories++;
  1396. directoryVector.add(file);
  1397. }
  1398. MiscUtilities.quicksort(directoryVector,
  1399. new VFS.DirectoryEntryCompare(
  1400. sortMixFilesAndDirs,
  1401. sortIgnoreCase));
  1402. }
  1403. browserView.directoryLoaded(node,path,
  1404. directoryVector);
  1405. // to notify listeners that any existing
  1406. // selection has been deactivated
  1407. // turns out under some circumstances this
  1408. // method can switch the current buffer in
  1409. // BROWSER mode.
  1410. // in any case, this is only needed for the
  1411. // directory chooser (why?), so we add a
  1412. // check. otherwise poor Rick will go insane.
  1413. if(mode == CHOOSE_DIRECTORY_DIALOG)
  1414. filesSelected();
  1415. }
  1416. public String toString()
  1417. {
  1418. return (String)loadInfo[0];
  1419. }
  1420. } //}}}
  1421. //}}}
  1422. }