// {{{ maybeReloadDirectory() method public void maybeReloadDirectory(String path) { String browserDir = browser.getDirectory(); String symlinkBrowserDir; if (MiscUtilities.isURL(browserDir)) { symlinkBrowserDir = browserDir; } else { symlinkBrowserDir = MiscUtilities.resolveSymlinks(browserDir); } if (MiscUtilities.pathsEqual(path, symlinkBrowserDir)) { saveExpansionState(); loadDirectory(null, browserDir, false); } // because this method is called for *every* VFS update, // we don't want to scan the tree all the time. So we // use the following algorithm to determine if the path // might be part of the tree: // - if the path starts with the browser's current directory, // we do the tree scan // - if the browser's directory is 'favorites:' -- we have to // do the tree scan, as every path can appear under the // favorites list // - if the browser's directory is 'roots:' and path is on // the local filesystem, do a tree scan if (!browserDir.startsWith(FavoritesVFS.PROTOCOL) && !browserDir.startsWith(FileRootsVFS.PROTOCOL) && !path.startsWith(symlinkBrowserDir)) return; if (browserDir.startsWith(FileRootsVFS.PROTOCOL) && MiscUtilities.isURL(path) && !"file".equals(MiscUtilities.getProtocolOfURL(path))) return; table.maybeReloadDirectory(path); } // }}}
/** * Displays the specified URL in the HTML component. * * @param url The URL * @param addToHistory Should the URL be added to the back/forward history? * @param scrollPosition The vertical scrollPosition */ public void gotoURL(String url, boolean addToHistory, final int scrollPosition) { // the TOC pane looks up user's guide URLs relative to the // doc directory... String shortURL; if (MiscUtilities.isURL(url)) { if (url.startsWith(baseURL)) { shortURL = url.substring(baseURL.length()); if (shortURL.startsWith("/")) { shortURL = shortURL.substring(1); } } else { shortURL = url; } } else { shortURL = url; if (baseURL.endsWith("/")) { url = baseURL + url; } else { url = baseURL + '/' + url; } } // reset default cursor so that the hand cursor doesn't // stick around viewer.setCursor(Cursor.getDefaultCursor()); try { URL _url = new URL(url); if (!_url.equals(viewer.getPage())) { title.setText(jEdit.getProperty("helpviewer.loading")); } else { /* don't show loading msg because we won't receive a propertyChanged */ } historyModel.setCurrentScrollPosition(viewer.getPage(), getCurrentScrollPosition()); viewer.setPage(_url); if (0 != scrollPosition) { SwingUtilities.invokeLater( new Runnable() { public void run() { viewerScrollPane.getVerticalScrollBar().setValue(scrollPosition); } }); } if (addToHistory) { historyModel.addToHistory(url); } } catch (MalformedURLException mf) { Log.log(Log.ERROR, this, mf); String[] args = {url, mf.getMessage()}; GUIUtilities.error(this, "badurl", args); return; } catch (IOException io) { Log.log(Log.ERROR, this, io); String[] args = {url, io.toString()}; GUIUtilities.error(this, "read-error", args); return; } this.shortURL = shortURL; // select the appropriate tree node. if (shortURL != null) { toc.selectNode(shortURL); } viewer.requestFocus(); } // }}}
public static VFS getVFSForPath(String path) { if (MiscUtilities.isURL(path)) return getVFSForProtocol(MiscUtilities.getProtocolOfURL(path)); else return fileVFS; }
public ToolBarEditDialog( Component comp, DefaultComboBoxModel iconListModel, ToolBarOptionPane.Button current) { super( GUIUtilities.getParentDialog(comp), jEdit.getProperty("options.toolbar.edit.title"), true); JPanel content = new JPanel(new BorderLayout()); content.setBorder(new EmptyBorder(12, 12, 12, 12)); setContentPane(content); ActionHandler actionHandler = new ActionHandler(); ButtonGroup grp = new ButtonGroup(); JPanel typePanel = new JPanel(new GridLayout(3, 1, 6, 6)); typePanel.setBorder(new EmptyBorder(0, 0, 6, 0)); typePanel.add(new JLabel(jEdit.getProperty("options.toolbar.edit.caption"))); separator = new JRadioButton(jEdit.getProperty("options.toolbar" + ".edit.separator")); separator.addActionListener(actionHandler); grp.add(separator); typePanel.add(separator); action = new JRadioButton(jEdit.getProperty("options.toolbar" + ".edit.action")); action.addActionListener(actionHandler); grp.add(action); typePanel.add(action); content.add(BorderLayout.NORTH, typePanel); JPanel actionPanel = new JPanel(new BorderLayout(6, 6)); ActionSet[] actionsList = jEdit.getActionSets(); Vector vec = new Vector(actionsList.length); for (int i = 0; i < actionsList.length; i++) { ActionSet actionSet = actionsList[i]; if (actionSet.getActionCount() != 0) vec.addElement(actionSet); } combo = new JComboBox(vec); combo.addActionListener(actionHandler); actionPanel.add(BorderLayout.NORTH, combo); list = new JList(); list.setVisibleRowCount(8); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); actionPanel.add(BorderLayout.CENTER, new JScrollPane(list)); JPanel iconPanel = new JPanel(new BorderLayout(0, 3)); JPanel labelPanel = new JPanel(new GridLayout(2, 1)); labelPanel.setBorder(new EmptyBorder(0, 0, 0, 12)); JPanel compPanel = new JPanel(new GridLayout(2, 1)); grp = new ButtonGroup(); labelPanel.add(builtin = new JRadioButton(jEdit.getProperty("options.toolbar.edit.builtin"))); builtin.addActionListener(actionHandler); grp.add(builtin); labelPanel.add(file = new JRadioButton(jEdit.getProperty("options.toolbar.edit.file"))); grp.add(file); file.addActionListener(actionHandler); iconPanel.add(BorderLayout.WEST, labelPanel); builtinCombo = new JComboBox(iconListModel); builtinCombo.setRenderer(new ToolBarOptionPane.IconCellRenderer()); compPanel.add(builtinCombo); fileButton = new JButton(jEdit.getProperty("options.toolbar.edit.no-icon")); fileButton.setMargin(new Insets(1, 1, 1, 1)); fileButton.setIcon(GUIUtilities.loadIcon("Blank24.gif")); fileButton.setHorizontalAlignment(SwingConstants.LEFT); fileButton.addActionListener(actionHandler); compPanel.add(fileButton); iconPanel.add(BorderLayout.CENTER, compPanel); actionPanel.add(BorderLayout.SOUTH, iconPanel); content.add(BorderLayout.CENTER, actionPanel); JPanel southPanel = new JPanel(); southPanel.setLayout(new BoxLayout(southPanel, BoxLayout.X_AXIS)); southPanel.setBorder(new EmptyBorder(12, 0, 0, 0)); southPanel.add(Box.createGlue()); ok = new JButton(jEdit.getProperty("common.ok")); ok.addActionListener(actionHandler); getRootPane().setDefaultButton(ok); southPanel.add(ok); southPanel.add(Box.createHorizontalStrut(6)); cancel = new JButton(jEdit.getProperty("common.cancel")); cancel.addActionListener(actionHandler); southPanel.add(cancel); southPanel.add(Box.createGlue()); content.add(BorderLayout.SOUTH, southPanel); if (current == null) { action.setSelected(true); builtin.setSelected(true); updateList(); } else { if (current.actionName.equals("-")) { separator.setSelected(true); builtin.setSelected(true); } else { action.setSelected(true); ActionSet set = jEdit.getActionSetForAction(current.actionName); combo.setSelectedItem(set); updateList(); list.setSelectedValue(current, true); if (MiscUtilities.isURL(current.iconName)) { file.setSelected(true); fileIcon = current.iconName; try { fileButton.setIcon(new ImageIcon(new URL(fileIcon))); } catch (MalformedURLException mf) { Log.log(Log.ERROR, this, mf); } fileButton.setText(MiscUtilities.getFileName(fileIcon)); } else { String iconName = MiscUtilities.getFileName(current.iconName); builtin.setSelected(true); ListModel model = builtinCombo.getModel(); for (int i = 0; i < model.getSize(); i++) { ToolBarOptionPane.IconListEntry entry = (ToolBarOptionPane.IconListEntry) model.getElementAt(i); if (entry.name.equals(iconName)) { builtinCombo.setSelectedIndex(i); break; } } } } } updateEnabled(); pack(); setLocationRelativeTo(GUIUtilities.getParentDialog(comp)); show(); }
// {{{ run() method public void run() { /* if the VFS supports renaming files, we first * save to #<filename>#save#, then rename that * to <filename>, so that if the save fails, * data will not be lost. * * as of 4.1pre7 we now call vfs.getTwoStageSaveName() * instead of constructing the path directly * since some VFS's might not allow # in filenames. */ boolean vfsRenameCap = (vfs.getCapabilities() & VFS.RENAME_CAP) != 0; boolean wantTwoStage = wantTwoStageSave(buffer); boolean twoStageSave = vfsRenameCap && wantTwoStage; try { String[] args = {vfs.getFileName(path)}; setStatus(jEdit.getProperty("vfs.status.save", args)); // the entire save operation can be aborted... setAbortable(true); path = vfs._canonPath(session, path, view); if (!MiscUtilities.isURL(path)) path = MiscUtilities.resolveSymlinks(path); String savePath; if (twoStageSave) { savePath = vfs.getTwoStageSaveName(path); if (savePath == null) { throw new IOException("Can't get a temporary path for two-stage save: " + path); } } else { makeBackup(); savePath = path; } OutputStream out = vfs._createOutputStream(session, savePath, view); if (out == null) { buffer.setBooleanProperty(ERROR_OCCURRED, true); return; } try { // this must be after the stream is created or // we deadlock with SSHTools. buffer.readLock(); try { // Can't use buffer.getName() here because // it is not changed until the save is // complete if (path.endsWith(".gz")) buffer.setBooleanProperty(Buffer.GZIPPED, true); else if (buffer.getName().endsWith(".gz")) { // The path do not ends with gz. // The buffer name was .gz. // So it means it's blabla.txt.gz -> blabla.txt, I remove // the gz property buffer.setBooleanProperty(Buffer.GZIPPED, false); } if (buffer.getBooleanProperty(Buffer.GZIPPED)) out = new GZIPOutputStream(out); write(buffer, out); } finally { buffer.readUnlock(); } } finally { IOUtilities.closeQuietly(out); } if (twoStageSave) { makeBackup(); if (!vfs._rename(session, savePath, path, view)) throw new IOException("Rename failed: " + savePath); } if (!twoStageSave) VFSManager.sendVFSUpdate(vfs, path, true); } catch (FileNotFoundException e) { Log.log(Log.ERROR, this, "Unable to save buffer " + e); String[] pp = {e.getMessage()}; VFSManager.error(view, path, "ioerror.write-error", pp); buffer.setBooleanProperty(ERROR_OCCURRED, true); } catch (UnsupportedCharsetException e) { Log.log(Log.ERROR, this, e, e); String[] pp = {e.getCharsetName()}; VFSManager.error(view, path, "ioerror.unsupported-encoding-error", pp); buffer.setBooleanProperty(ERROR_OCCURRED, true); } catch (Exception e) { Log.log(Log.ERROR, this, e); String[] pp = {e.toString()}; VFSManager.error(view, path, "ioerror.write-error", pp); buffer.setBooleanProperty(ERROR_OCCURRED, true); } catch (WorkThread.Abort a) { buffer.setBooleanProperty(ERROR_OCCURRED, true); } finally { try { vfs._saveComplete(session, buffer, path, view); if (twoStageSave) { vfs._finishTwoStageSave(session, buffer, path, view); } // clean up left-over markers file if (!jEdit.getBooleanProperty("persistentMarkers")) vfs._delete(session, Buffer.getMarkersPath(vfs, path), view); vfs._endVFSSession(session, view); } catch (Exception e) { Log.log(Log.ERROR, this, e); String[] pp = {e.toString()}; VFSManager.error(view, path, "ioerror.write-error", pp); buffer.setBooleanProperty(ERROR_OCCURRED, true); } catch (WorkThread.Abort a) { buffer.setBooleanProperty(ERROR_OCCURRED, true); } } } // }}}
// {{{ recursive listFiles() method private void listFiles( Object session, Collection<String> stack, List<String> files, String directory, VFSFileFilter filter, boolean recursive, Component comp, boolean skipBinary, boolean skipHidden) throws IOException { String resolvedPath = directory; if (recursive && !MiscUtilities.isURL(directory)) { resolvedPath = MiscUtilities.resolveSymlinks(directory); /* * If looking at a symlink, do not traverse the * resolved path more than once. */ if (!directory.equals(resolvedPath)) { if (stack.contains(resolvedPath)) { Log.log(Log.ERROR, this, "Recursion in listFiles(): " + directory); return; } stack.add(resolvedPath); } } Thread ct = Thread.currentThread(); WorkThread wt = null; if (ct instanceof WorkThread) { wt = (WorkThread) ct; } VFSFile[] _files = _listFiles(session, directory, comp); if (_files == null || _files.length == 0) return; for (int i = 0; i < _files.length; i++) { if (wt != null && wt.isAborted()) break; VFSFile file = _files[i]; if (skipHidden && (file.isHidden() || MiscUtilities.isBackup(file.getName()))) continue; if (!filter.accept(file)) continue; if (file.getType() == VFSFile.DIRECTORY || file.getType() == VFSFile.FILESYSTEM) { if (recursive) { String canonPath = _canonPath(session, file.getPath(), comp); listFiles( session, stack, files, canonPath, filter, recursive, comp, skipBinary, skipHidden); } } else // It's a regular file { if (skipBinary) { try { if (file.isBinary(session)) { Log.log(Log.NOTICE, this, file.getPath() + ": skipped as a binary file"); continue; } } catch (IOException e) { Log.log(Log.ERROR, this, e); // may be not binary... } } files.add(file.getPath()); } } } // }}}