Beispiel #1
0
  /**
   * Copy a file to another using VFS.
   *
   * @param progress the progress observer. It could be null if you don't want to monitor progress.
   *     If not null you should probably launch this command in a WorkThread
   * @param sourceVFS the source VFS
   * @param sourceSession the VFS session
   * @param sourcePath the source path
   * @param targetVFS the target VFS
   * @param targetSession the target session
   * @param targetPath the target path
   * @param comp comp The component that will parent error dialog boxes
   * @param canStop could this copy be stopped ?
   * @return true if the copy was successful
   * @throws IOException IOException If an I/O error occurs
   * @since jEdit 4.3pre3
   */
  public static boolean copy(
      ProgressObserver progress,
      VFS sourceVFS,
      Object sourceSession,
      String sourcePath,
      VFS targetVFS,
      Object targetSession,
      String targetPath,
      Component comp,
      boolean canStop)
      throws IOException {
    if (progress != null) progress.setStatus("Initializing");

    InputStream in = null;
    OutputStream out = null;
    try {
      VFSFile sourceVFSFile = sourceVFS._getFile(sourceSession, sourcePath, comp);
      if (sourceVFSFile == null) throw new FileNotFoundException(sourcePath);
      if (progress != null) {
        progress.setMaximum(sourceVFSFile.getLength());
      }
      VFSFile targetVFSFile = targetVFS._getFile(targetSession, targetPath, comp);
      if (targetVFSFile.getType() == VFSFile.DIRECTORY) {
        if (targetVFSFile.getPath().equals(sourceVFSFile.getPath())) return false;
        targetPath = MiscUtilities.constructPath(targetPath, sourceVFSFile.getName());
      }
      in =
          new BufferedInputStream(
              sourceVFS._createInputStream(sourceSession, sourcePath, false, comp));
      out =
          new BufferedOutputStream(targetVFS._createOutputStream(targetSession, targetPath, comp));
      boolean copyResult = IOUtilities.copyStream(IOBUFSIZE, progress, in, out, canStop);
      VFSManager.sendVFSUpdate(targetVFS, targetPath, true);
      return copyResult;
    } finally {
      IOUtilities.closeQuietly(in);
      IOUtilities.closeQuietly(out);
    }
  }
    @Override
    public void mouseReleased(MouseEvent evt) {
      if (evt.getClickCount() % 2 != 0 && !GUIUtilities.isMiddleButton(evt.getModifiers())) return;

      int row = parentDirectories.locationToIndex(evt.getPoint());
      if (row != -1) {
        Object obj = parentDirectories.getModel().getElementAt(row);
        if (obj instanceof VFSFile) {
          VFSFile dirEntry = (VFSFile) obj;
          if (!GUIUtilities.isPopupTrigger(evt)) {
            browser.setDirectory(dirEntry.getPath());
            if (browser.getMode() == VFSBrowser.BROWSER) focusOnFileView();
          }
        }
      }
    }
 @Override
 protected void processKeyEvent(KeyEvent evt) {
   if (evt.getID() == KeyEvent.KEY_PRESSED) {
     ActionContext ac = VFSBrowser.getActionContext();
     int row = parentDirectories.getSelectedIndex();
     switch (evt.getKeyCode()) {
       case KeyEvent.VK_DOWN:
         evt.consume();
         if (row < parentDirectories.getSize().height - 1)
           parentDirectories.setSelectedIndex(++row);
         break;
       case KeyEvent.VK_LEFT:
         if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) {
           evt.consume();
           browser.previousDirectory();
         } else super.processEvent(evt);
         break;
       case KeyEvent.VK_RIGHT:
         if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) {
           evt.consume();
           browser.nextDirectory();
         } else super.processEvent(evt);
         break;
       case KeyEvent.VK_TAB:
         evt.consume();
         if ((evt.getModifiers() & InputEvent.SHIFT_MASK) > 0) browser.focusOnDefaultComponent();
         else table.requestFocus();
         break;
       case KeyEvent.VK_UP:
         evt.consume();
         if (row > 0) {
           parentDirectories.setSelectedIndex(--row);
         }
         break;
       case KeyEvent.VK_BACK_SPACE:
         evt.consume();
         EditAction up = ac.getAction("vfs.browser.up");
         ac.invokeAction(evt, up);
         break;
       case KeyEvent.VK_F5:
         evt.consume();
         EditAction reload = ac.getAction("vfs.browser.reload");
         ac.invokeAction(evt, reload);
         break;
       case KeyEvent.VK_ENTER:
         evt.consume();
         if (row != -1) {
           // basically the same handling as in ParentMouseHandler#mouseReleased
           Object obj = parentDirectories.getModel().getElementAt(row);
           if (obj instanceof VFSFile) {
             VFSFile dirEntry = (VFSFile) obj;
             browser.setDirectory(dirEntry.getPath());
             if (browser.getMode() == VFSBrowser.BROWSER) focusOnFileView();
           }
         }
         break;
         /* These actions don't work because they look at the EntryTable for the current selected
         * 	item. We need actions that look at the parentDirectoryList item instead.
         *
         			case KeyEvent.VK_DELETE:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.delete");
         				ac.invokeAction(evt, ea);
         				break;
         			case KeyEvent.CTRL_MASK | KeyEvent.VK_N:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.new-file");
         				ac.invokeAction(evt, ea);
         				break;
         			case KeyEvent.VK_INSERT:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.new-directory");
         				ac.invokeAction(evt, ea);
         				break; */
     }
   } else if (evt.getID() == KeyEvent.KEY_TYPED) {
     if (evt.isControlDown() || evt.isAltDown() || evt.isMetaDown()) {
       evt.consume();
       return;
     }
     switch (evt.getKeyChar()) {
       case '~':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER)
           browser.setDirectory(System.getProperty("user.home"));
         break;
       case '/':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER) browser.rootDirectory();
         break;
       case '-':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER) {
           browser.setDirectory(browser.getView().getBuffer().getDirectory());
         }
         break;
     }
   }
   if (!evt.isConsumed()) super.processKeyEvent(evt);
 }
Beispiel #4
0
  // {{{ 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());
      }
    }
  } // }}}