Пример #1
0
    protected int doCompare(FileSystemItem arg0, FileSystemItem arg1) {
      int ascendingResult = activeSortColumnAscending_ ? 1 : -1;

      if (arg0.isDirectory() && !arg1.isDirectory()) return ascendingResult * sortFactor_;
      else if (arg1.isDirectory() && !arg0.isDirectory()) return -ascendingResult * sortFactor_;
      else return doItemCompare(arg0, arg1);
    }
Пример #2
0
 public void showOpenProjectDialog(
     FileSystemContext fsContext,
     ProjectsServerOperations server,
     String defaultLocation,
     int defaultType,
     boolean showNewSession,
     final ProgressOperationWithInput<OpenProjectParams> onCompleted) {
   // use the default dialog on desktop mode or single-session mode
   FileDialogs dialogs = RStudioGinjector.INSTANCE.getFileDialogs();
   if (Desktop.isDesktop()
       || !RStudioGinjector.INSTANCE.getSession().getSessionInfo().getMultiSession()) {
     dialogs.openFile(
         "Open Project",
         fsContext,
         FileSystemItem.createDir(defaultLocation),
         "R Projects (*.Rproj)",
         new ProgressOperationWithInput<FileSystemItem>() {
           @Override
           public void execute(FileSystemItem input, ProgressIndicator indicator) {
             onCompleted.execute(new OpenProjectParams(input, null, false), indicator);
           }
         });
   } else {
     // in multi-session mode, we have a special dialog for opening projects
     WebFileDialogs webDialogs = (WebFileDialogs) dialogs;
     webDialogs.openProject(
         fsContext, FileSystemItem.createDir(defaultLocation), defaultType, onCompleted);
   }
 }
Пример #3
0
  public final int compareTo(FileSystemItem other) {
    // If we ever need to compare files that don't share the same
    // parent, then maybe we would need to compare parent directory
    // before anything else.

    if (isDirectory() ^ other.isDirectory()) return isDirectory() ? -1 : 1;
    return String.CASE_INSENSITIVE_ORDER.compare(getPath(), other.getPath());
  }
Пример #4
0
  public ImageResource getIconForFile(FileSystemItem file) {
    if (file.isDirectory()) {
      if (file.isPublicFolder()) return ICONS.iconPublicFolder();
      else return ICONS.iconFolder();
    }

    return getIconForFilename(file.getName());
  }
Пример #5
0
 public void setDirectory(FileSystemItem directoryItem) {
   if (directoryItem.equalTo(FileSystemItem.home())) {
     image_.setResource(FileDialogResources.INSTANCE.homeImage());
     name_.setHTML("Home");
   } else {
     image_.setResource(FileIconResources.INSTANCE.iconFolder());
     name_.setHTML("&nbsp;" + directoryItem.getPath());
   }
 }
Пример #6
0
 @Override
 public void onOpenProjectNewWindow(OpenProjectNewWindowEvent event) {
   // call the desktop to open the project (since it is
   // a conventional foreground gui application it has
   // less chance of running afowl of desktop app creation
   // & activation restrictions)
   FileSystemItem project = FileSystemItem.createFile(event.getProject());
   if (Desktop.isDesktop()) Desktop.getFrame().openProjectInNewWindow(project.getPath());
   else serverOpenProjectInNewWindow(project, null);
 }
Пример #7
0
  void openFile(String filePath) {
    // get the file system item
    FileSystemItem file = FileSystemItem.createFile(filePath);

    // don't open directories (these can sneak in if the user
    // passes a directory on the command line)
    if (!file.isDirectory()) {
      // open the file. pass false for second param to prevent
      // the default handler (the browser) from taking it
      fileTypeRegistry_.openFile(file, false);
    }
  }
Пример #8
0
  @Handler
  void onRenameFile() {
    // get currently selected files
    ArrayList<FileSystemItem> selectedFiles = view_.getSelectedFiles();

    // validation: some selection exists
    if (selectedFiles.size() == 0) return;

    // validation: no more than one file selected
    if (selectedFiles.size() > 1) {
      globalDisplay_.showErrorMessage("Invalid Selection", "Please select only one file to rename");
      return;
    }

    // prompt for new file name then execute the rename
    final FileSystemItem file = selectedFiles.get(0);
    globalDisplay_.promptForText(
        "Rename File",
        "Please enter the new file name:",
        file.getName(),
        0,
        file.getStem().length(),
        null,
        new ProgressOperationWithInput<String>() {

          public void execute(String input, final ProgressIndicator progress) {
            progress.onProgress("Renaming file...");

            String path = file.getParentPath().completePath(input);
            FileSystemItem target;
            if (file.isDirectory()) target = FileSystemItem.createDir(path);
            else target = FileSystemItem.createFile(path);

            // clear selection
            view_.selectNone();

            // premptively rename in the UI then fallback to refreshing
            // the view if there is an error
            view_.renameFile(file, target);

            // execute on the server
            server_.renameFile(
                file,
                target,
                new VoidServerRequestCallback(progress) {
                  @Override
                  protected void onFailure() {
                    onRefreshFiles();
                  }
                });
          }
        });
  }
Пример #9
0
  public void updateWithAction(FileChange viewAction) {
    final FileSystemItem file = viewAction.getFile();
    final List<FileSystemItem> files = getFiles();
    switch (viewAction.getType()) {
      case FileChange.ADD:
        if (file.getParentPath().equalTo(containingPath_)) {
          int row = rowForFile(file);
          if (row == -1) {
            files.add(file);
            filesDataGrid_.setPageSize(files.size() + 1);
          } else {
            // since we eagerly perform renames at the client UI
            // layer then sometimes an "added" file is really just
            // a rename. in this case the file already exists due
            // to the eager rename in the client but still needs its
            // metadata updated
            files.set(row, file);
          }
        }
        break;

      case FileChange.MODIFIED:
        {
          int row = rowForFile(file);
          if (row != -1) files.set(row, file);
        }
        break;

      case FileChange.DELETE:
        {
          int row = rowForFile(file);
          if (row != -1) {
            files.remove(row);

            // if a file is deleted and then re-added within the same
            // event loop (as occurs when gedit saves a text file) the
            // table doesn't always update correctly (it has a duplicate
            // of the item deleted / re-added). the call to flush overcomes
            // this issue
            dataProvider_.flush();
          }
        }
        break;

      default:
        Debug.log("Unexpected file change type: " + viewAction.getType());

        break;
    }
  }
Пример #10
0
 public void onFileNavigation(FileSystemItem file) {
   if (file.isDirectory()) {
     navigateToDirectory(file);
   } else {
     navigateToFile(file);
   }
 }
Пример #11
0
  private void saveFileAs() {
    fileDialogs_.saveFile(
        "Save File - " + targetFile_.getName(),
        fileContext_,
        FileSystemItem.createFile(
            session_.getSessionInfo().getActiveProjectDir().completePath(targetFile_.getName())),
        targetFile_.getExtension(),
        false,
        new ProgressOperationWithInput<FileSystemItem>() {

          @Override
          public void execute(FileSystemItem input, ProgressIndicator indicator) {
            if (input == null) {
              indicator.onCompleted();
              return;
            }

            indicator.onProgress("Saving file...");

            server_.gitExportFile(
                commitId_,
                targetFile_.getPath(),
                input.getPath(),
                new VoidServerRequestCallback(indicator));
          }
        });
  }
Пример #12
0
  public void showFile(FileSystemItem file, String commitId, String contents) {
    commitId_ = commitId;
    targetFile_ = file;

    docDisplay_.setCode(contents, false);

    adaptToFileType(fileTypeRegistry_.getTextTypeForFile(file));

    // header widget has icon + label
    HorizontalPanel panel = new HorizontalPanel();

    Image imgFile = new Image(fileTypeRegistry_.getIconForFile(file));
    imgFile.addStyleName(RES.styles().captionIcon());
    panel.add(imgFile);

    Label lblCaption = new Label(file.getPath() + " @ " + commitId);
    lblCaption.addStyleName(RES.styles().captionLabel());
    panel.add(lblCaption);

    popupPanel_ = new FullscreenPopupPanel(panel, asWidget(), false);
    popupPanel_.center();

    // set focus to the doc display after 100ms
    Timer timer =
        new Timer() {
          public void run() {
            docDisplay_.focus();
          }
        };
    timer.schedule(100);
  }
Пример #13
0
 public final FileSystemItem getActiveProjectDir() {
   String projFile = getActiveProjectFile();
   if (projFile != null) {
     return FileSystemItem.createFile(projFile).getParentPath();
   } else {
     return null;
   }
 }
Пример #14
0
 public void setShinyPreview(ShinyApplicationParams params) {
   String ext =
       params.getPath() == null
           ? ""
           : FileSystemItem.getExtensionFromPath(params.getPath()).toLowerCase();
   setContentPath(params.getPath(), "");
   setContentType(ext == ".r" ? RSConnect.CONTENT_TYPE_APP_SINGLE : RSConnect.CONTENT_TYPE_APP);
 }
Пример #15
0
 private String buildSwitchMessage(String switchToProject) {
   String msg =
       !switchToProject.equals("none")
           ? "Switching to project "
               + FileSystemItem.createFile(switchToProject).getParentPathString()
           : "Closing project";
   return msg + "...";
 }
Пример #16
0
  public ImageResource getIconForFilename(String filename) {
    ImageResource icon = iconsByFilename_.get(filename.toLowerCase());
    if (icon != null) return icon;
    String ext = FileSystemItem.getExtensionFromPath(filename);
    icon = iconsByFileExtension_.get(ext.toLowerCase());
    if (icon != null) return icon;

    return ICONS.iconText();
  }
Пример #17
0
  public FileType getTypeForFile(FileSystemItem file, String defaultType) {
    if (file != null) {
      String filename = file.getName().toLowerCase();
      FileType result = fileTypesByFilename_.get(filename);
      if (result != null) return result;

      String extension = FileSystemItem.getExtensionFromPath(filename);
      result = fileTypesByFileExtension_.get(extension);
      if (result != null) return result;

      if (defaultType != null) {
        String mimeType = file.mimeType(defaultType);
        if (mimeType.startsWith("text/")) return TEXT;
      }
    }

    return null;
  }
Пример #18
0
 private void showOpenProjectDialog(ProgressOperationWithInput<FileSystemItem> onCompleted) {
   // choose project file
   fileDialogs_.openFile(
       "Open Project",
       fsContext_,
       FileSystemItem.createDir(pUIPrefs_.get().defaultProjectLocation().getValue()),
       "R Projects (*.Rproj)",
       onCompleted);
 }
Пример #19
0
  public void editFile(FileSystemItem file, FilePosition position) {
    if (satellite_.isCurrentWindowSatellite()) {
      satellite_.focusMainWindow();
      callSatelliteEditFile(file.cast(), position.cast());
    } else {
      FileType fileType = getTypeForFile(file);
      if (!(fileType instanceof TextFileType)) fileType = TEXT;

      if (fileType != null) fileType.openFile(file, position, eventBus_);
    }
  }
Пример #20
0
 public final FileSystemItem getParentPath() {
   String parentPath;
   String path = getPath();
   int lastSlash = path.lastIndexOf('/');
   if (lastSlash <= 0) {
     return null;
   } else {
     parentPath = path.substring(0, lastSlash);
     return FileSystemItem.createDir(parentPath);
   }
 }
Пример #21
0
  @Override
  public void onOpenProjectFile(final OpenProjectFileEvent event) {
    // project options for current project
    FileSystemItem projFile = event.getFile();
    if (projFile.getPath().equals(session_.getSessionInfo().getActiveProjectFile())) {
      onProjectOptions();
      return;
    }

    // prompt to confirm
    String projectPath = projFile.getParentPathString();
    globalDisplay_.showYesNoMessage(
        GlobalDisplay.MSG_QUESTION,
        "Confirm Open Project",
        "Do you want to open the project " + projectPath + "?",
        new Operation() {
          public void execute() {
            switchToProject(event.getFile().getPath());
          }
        },
        true);
  }
Пример #22
0
  public FileType getTypeForFile(FileSystemItem file, boolean canUseDefault) {
    if (file != null) {
      String filename = file.getName().toLowerCase();
      FileType result = fileTypesByFilename_.get(filename);
      if (result != null) return result;

      String extension = FileSystemItem.getExtensionFromPath(filename);
      result = fileTypesByFileExtension_.get(extension);
      if (result != null) return result;

      // last ditch -- see if this either a known text file type
      // or (for server mode) NOT a known binary type. the result of
      // this is that unknown files types are treated as text and
      // opened in the editor (we don't do this on desktop because
      // in that case users have the recourse of using a local editor)
      String defaultType = Desktop.isDesktop() ? "application/octet-stream" : "text/plain";
      String mimeType = file.mimeType(defaultType);
      if (mimeType.startsWith("text/")) return TEXT;
    }

    if (canUseDefault) return defaultType_;
    else return null;
  }
Пример #23
0
  private void serverOpenProjectInNewWindow(FileSystemItem project, final Command onSuccess) {
    appServer_.getNewSessionUrl(
        GWT.getHostPageBaseURL(),
        true,
        project.getParentPathString(),
        new SimpleRequestCallback<String>() {

          @Override
          public void onResponseReceived(String url) {
            if (onSuccess != null) onSuccess.execute();

            globalDisplay_.openWindow(url);
          }
        });
  }
        @Override
        public void onClick(ClickEvent event) {
          fileDialogs_.chooseFolder(
              "Add Local Repository",
              fileSystemContext_,
              FileSystemItem.home(),
              new ProgressOperationWithInput<FileSystemItem>() {

                @Override
                public void execute(FileSystemItem input, ProgressIndicator indicator) {
                  indicator.onCompleted();
                  if (input == null) return;

                  listBox_.addItem(input.getPath());
                }
              });
        }
Пример #25
0
  public void editFile(FileSystemItem file, FilePosition position, boolean highlightLine) {
    // edit the file in the main window unless this is a source satellite
    // (in which case we want to edit it locally)
    if (satellite_.isCurrentWindowSatellite()
        && !satellite_.getSatelliteName().startsWith(SourceSatellite.NAME_PREFIX)) {
      satellite_.focusMainWindow();
      callSatelliteEditFile(file.cast(), position.cast(), highlightLine);
    } else {
      FileType fileType = getTypeForFile(file);
      if (fileType != null && !(fileType instanceof TextFileType)) fileType = TEXT;

      if (fileType != null)
        fileType.openFile(
            file,
            position,
            highlightLine ? NavigationMethods.HIGHLIGHT_LINE : NavigationMethods.DEFAULT,
            eventBus_);
    }
  }
Пример #26
0
  public void openFile(final FileSystemItem file, final boolean canUseBrowser) {
    FileType fileType = getTypeForFile(file);
    if (fileType != null) {
      fileType.openFile(file, eventBus_);
    } else {
      // build default command to use if we have an error or the
      // file is not a text file
      final Command defaultCommand =
          new Command() {
            @Override
            public void execute() {
              if (canUseBrowser) {
                if (session_.getSessionInfo().getAllowFileDownloads()) {
                  BROWSER.openFile(file, eventBus_);
                } else {
                  globalDisplay_.showErrorMessage(
                      "File Download Error",
                      "Unable to show file because file downloads are "
                          + "restricted on this server.\n");
                }
              }
            }
          };

      // check with the server to see if this is likely to be a text file
      server_.isTextFile(
          file.getPath(),
          new ServerRequestCallback<Boolean>() {
            @Override
            public void onResponseReceived(Boolean isText) {
              if (isText) TEXT.openFile(file, eventBus_);
              else defaultCommand.execute();
            }

            @Override
            public void onError(ServerError error) {
              defaultCommand.execute();
            }
          });
    }
  }
Пример #27
0
  private void navigateToFile(final FileSystemItem file) {
    String ext = file.getExtension().toLowerCase();
    if (ext.equals(".htm") || ext.equals(".html")) {
      view_.showHtmlFileChoice(
          file,
          new Command() {

            @Override
            public void execute() {
              fileTypeRegistry_.openFile(file);
            }
          },
          new Command() {

            @Override
            public void execute() {
              showFileInBrowser(file);
            }
          });
    } else {
      fileTypeRegistry_.openFile(file);
    }
  }
Пример #28
0
  // rebuilds the popup menu--this can happen when the menu is invoked; it can
  // also happen when the button is created if we're aggressively checking
  // publish status
  private void rebuildPopupMenu(final ToolbarPopupMenu.DynamicPopupMenuCallback callback) {
    final ToolbarPopupMenu menu = publishMenu_;

    // prevent reentrancy
    if (populating_) {
      if (callback != null) callback.onPopupMenu(menu);
      return;
    }

    // handle case where we don't have a content path (i.e. plots)
    if (contentPath_ == null) {
      setPreviousDeployments(null);
      if (callback != null) callback.onPopupMenu(menu);
      return;
    }

    // avoid populating if we've already set the deployments for this path
    // (unless we're forcefully repopulating)
    if (populatedPath_ != null && populatedPath_.equals(contentPath_)) {
      if (callback != null) callback.onPopupMenu(menu);
      return;
    }

    String contentPath = contentPath_;
    boolean parent = false;

    // if this is a Shiny application and an .R file is being invoked, check
    // for deployments of its parent path (single-file apps have
    // CONTENT_TYPE_APP_SINGLE and their own deployment records)
    if (contentType_ == RSConnect.CONTENT_TYPE_APP
        && StringUtil.getExtension(contentPath_).equalsIgnoreCase("r")) parent = true;

    // if this is a document in a website, use the parent path
    if (contentType_ == RSConnect.CONTENT_TYPE_WEBSITE) parent = true;

    // apply parent path if needed
    if (parent) {
      FileSystemItem fsiContent = FileSystemItem.createFile(contentPath_);
      contentPath = fsiContent.getParentPathString();
    }

    populating_ = true;
    server_.getRSConnectDeployments(
        contentPath,
        outputPath_ == null ? "" : outputPath_,
        new ServerRequestCallback<JsArray<RSConnectDeploymentRecord>>() {
          @Override
          public void onResponseReceived(JsArray<RSConnectDeploymentRecord> recs) {
            populatedPath_ = contentPath_;
            populating_ = false;

            // if publishing a website but not content, filter deployments
            // that are static (as we can't update them)
            if (contentType_ == RSConnect.CONTENT_TYPE_WEBSITE
                && (docPreview_ == null || StringUtil.isNullOrEmpty(docPreview_.getOutputFile()))) {
              JsArray<RSConnectDeploymentRecord> codeRecs = JsArray.createArray().cast();
              for (int i = 0; i < recs.length(); i++) {
                if (!recs.get(i).getAsStatic()) codeRecs.push(recs.get(i));
              }
              recs = codeRecs;
            }

            setPreviousDeployments(recs);
            if (callback != null) callback.onPopupMenu(menu);
          }

          @Override
          public void onError(ServerError error) {
            populating_ = false;
            if (callback != null) callback.onPopupMenu(menu);
          }
        });
  }
Пример #29
0
 @Override
 public Object getKey(FileSystemItem item) {
   return item.getPath();
 }
Пример #30
0
 private void sendDefaultWorkspaceCommandToConsole(String command) {
   String renvPath = workbenchContext_.getREnvironmentPath();
   consoleDispatcher_.executeCommand(command, FileSystemItem.createFile(renvPath));
 }