Search in sources :

Example 31 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class DesktopHooks method openFile.

void openFile(String filePath) {
    // get the file system item
    FileSystemItem file = FileSystemItem.createFile(filePath);
    if (file.isDirectory())
        return;
    // within DesktopMain.cpp
    if (file.getExtension().equalsIgnoreCase(".rproj"))
        return;
    // open the file. pass false for second param to prevent
    // the default handler (the browser) from taking it
    fileTypeRegistry_.openFile(file, false);
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem)

Example 32 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class TextEditingTarget method saveNewFileWithEncoding.

private void saveNewFileWithEncoding(String suggestedPath, final String encoding, final Command executeOnSuccess) {
    view_.ensureVisible();
    FileSystemItem fsi;
    if (suggestedPath != null)
        fsi = FileSystemItem.createFile(suggestedPath);
    else
        fsi = getSaveFileDefaultDir();
    fileDialogs_.saveFile("Save File - " + getName().getValue(), fileContext_, fsi, fileType_.getDefaultExtension(), false, new ProgressOperationWithInput<FileSystemItem>() {

        public void execute(final FileSystemItem saveItem, ProgressIndicator indicator) {
            if (saveItem == null)
                return;
            try {
                workbenchContext_.setDefaultFileDialogDir(saveItem.getParentPath());
                final TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(saveItem);
                final Command saveCommand = new Command() {

                    @Override
                    public void execute() {
                        if (!getPath().equals(saveItem.getPath())) {
                            // breakpoints are file-specific, so when saving
                            // as a different file, clear the display of
                            // breakpoints from the old file name
                            docDisplay_.removeAllBreakpoints();
                            // update publish settings 
                            syncPublishPath(saveItem.getPath());
                        }
                        fixupCodeBeforeSaving();
                        docUpdateSentinel_.save(saveItem.getPath(), fileType.getTypeId(), encoding, new SaveProgressIndicator(saveItem, fileType, executeOnSuccess));
                        events_.fireEvent(new SourceFileSavedEvent(getId(), saveItem.getPath()));
                    }
                };
                // to a non-R file type then confirm
                if (fileType_.isR() && !fileType.isR()) {
                    globalDisplay_.showYesNoMessage(MessageDialog.WARNING, "Confirm Change File Type", "This file was created as an R script however " + "the file extension you specified will change " + "it into another file type that will no longer " + "open as an R script.\n\n" + "Are you sure you want to change the type of " + "the file so that it is no longer an R script?", new Operation() {

                        @Override
                        public void execute() {
                            saveCommand.execute();
                        }
                    }, false);
                } else {
                    saveCommand.execute();
                }
            } catch (Exception e) {
                indicator.onError(e.toString());
                return;
            }
            indicator.onCompleted();
        }
    });
}
Also used : SourceFileSavedEvent(org.rstudio.studio.client.workbench.views.source.events.SourceFileSavedEvent) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) CppCompletionOperation(org.rstudio.studio.client.workbench.views.source.editors.text.cpp.CppCompletionOperation)

Example 33 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class TextEditingTarget method registerPrefs.

public static void registerPrefs(ArrayList<HandlerRegistration> releaseOnDismiss, UIPrefs prefs, final DocDisplay docDisplay, final PrefsContext context) {
    releaseOnDismiss.add(prefs.highlightSelectedLine().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.setHighlightSelectedLine(arg);
        }
    }));
    releaseOnDismiss.add(prefs.highlightSelectedWord().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.setHighlightSelectedWord(arg);
        }
    }));
    releaseOnDismiss.add(prefs.showLineNumbers().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.setShowLineNumbers(arg);
        }
    }));
    releaseOnDismiss.add(prefs.useSpacesForTab().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            // Makefile always uses tabs
            FileSystemItem file = context.getActiveFile();
            if ((file != null) && ("Makefile".equals(file.getName()) || "Makevars".equals(file.getName()) || "Makevars.win".equals(file.getName()))) {
                docDisplay.setUseSoftTabs(false);
            } else {
                docDisplay.setUseSoftTabs(arg);
            }
        }
    }));
    releaseOnDismiss.add(prefs.numSpacesForTab().bind(new CommandWithArg<Integer>() {

        public void execute(Integer arg) {
            docDisplay.setTabSize(arg);
        }
    }));
    releaseOnDismiss.add(prefs.showMargin().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.setShowPrintMargin(arg);
        }
    }));
    releaseOnDismiss.add(prefs.blinkingCursor().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.setBlinkingCursor(arg);
        }
    }));
    releaseOnDismiss.add(prefs.printMarginColumn().bind(new CommandWithArg<Integer>() {

        public void execute(Integer arg) {
            docDisplay.setPrintMarginColumn(arg);
        }
    }));
    releaseOnDismiss.add(prefs.showInvisibles().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.setShowInvisibles(arg);
        }
    }));
    releaseOnDismiss.add(prefs.showIndentGuides().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.setShowIndentGuides(arg);
        }
    }));
    releaseOnDismiss.add(prefs.scrollPastEndOfDocument().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.setScrollPastEndOfDocument(arg);
        }
    }));
    releaseOnDismiss.add(prefs.highlightRFunctionCalls().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.setHighlightRFunctionCalls(arg);
        }
    }));
    releaseOnDismiss.add(prefs.useVimMode().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.setUseVimMode(arg);
        }
    }));
    releaseOnDismiss.add(prefs.enableEmacsKeybindings().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.setUseEmacsKeybindings(arg);
        }
    }));
    releaseOnDismiss.add(prefs.codeCompleteOther().bind(new CommandWithArg<String>() {

        public void execute(String arg) {
            docDisplay.syncCompletionPrefs();
        }
    }));
    releaseOnDismiss.add(prefs.alwaysCompleteCharacters().bind(new CommandWithArg<Integer>() {

        public void execute(Integer arg) {
            docDisplay.syncCompletionPrefs();
        }
    }));
    releaseOnDismiss.add(prefs.alwaysCompleteDelayMs().bind(new CommandWithArg<Integer>() {

        public void execute(Integer arg) {
            docDisplay.syncCompletionPrefs();
        }
    }));
    releaseOnDismiss.add(prefs.enableSnippets().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.syncCompletionPrefs();
        }
    }));
    releaseOnDismiss.add(prefs.showDiagnosticsOther().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.syncDiagnosticsPrefs();
        }
    }));
    releaseOnDismiss.add(prefs.diagnosticsOnSave().bind(new CommandWithArg<Boolean>() {

        @Override
        public void execute(Boolean arg) {
            docDisplay.syncDiagnosticsPrefs();
        }
    }));
    releaseOnDismiss.add(prefs.backgroundDiagnosticsDelayMs().bind(new CommandWithArg<Integer>() {

        public void execute(Integer arg) {
            docDisplay.syncDiagnosticsPrefs();
        }
    }));
    releaseOnDismiss.add(prefs.showInlineToolbarForRCodeChunks().bind(new CommandWithArg<Boolean>() {

        public void execute(Boolean arg) {
            docDisplay.forceImmediateRender();
        }
    }));
    releaseOnDismiss.add(prefs.foldStyle().bind(new CommandWithArg<String>() {

        public void execute(String style) {
            docDisplay.setFoldStyle(style);
        }
    }));
    releaseOnDismiss.add(prefs.surroundSelection().bind(new CommandWithArg<String>() {

        public void execute(String string) {
            docDisplay.setSurroundSelectionPref(string);
        }
    }));
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 34 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class TextEditingTarget method isPackageFile.

private boolean isPackageFile() {
    // not a package file if we're not in package development mode
    String type = session_.getSessionInfo().getBuildToolsType();
    if (!type.equals(SessionInfo.BUILD_TOOLS_PACKAGE)) {
        return false;
    }
    // get the directory associated with the project and see if the file is
    // inside that directory
    FileSystemItem projectDir = session_.getSessionInfo().getActiveProjectDir();
    return getPath().startsWith(projectDir.getPath() + "/R");
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 35 with FileSystemItem

use of org.rstudio.core.client.files.FileSystemItem in project rstudio by rstudio.

the class TextEditingTarget method fireVcsViewOnGithubEvent.

private void fireVcsViewOnGithubEvent(int type) {
    FileSystemItem file = FileSystemItem.createFile(docUpdateSentinel_.getPath());
    if (docDisplay_.getSelectionValue().length() > 0) {
        int start = docDisplay_.getSelectionStart().getRow() + 1;
        int end = docDisplay_.getSelectionEnd().getRow() + 1;
        events_.fireEvent(new VcsViewOnGitHubEvent(new GitHubViewRequest(file, type, start, end)));
    } else {
        events_.fireEvent(new VcsViewOnGitHubEvent(new GitHubViewRequest(file, type)));
    }
}
Also used : GitHubViewRequest(org.rstudio.studio.client.workbench.views.vcs.common.model.GitHubViewRequest) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) VcsViewOnGitHubEvent(org.rstudio.studio.client.workbench.views.vcs.common.events.VcsViewOnGitHubEvent) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Aggregations

FileSystemItem (org.rstudio.core.client.files.FileSystemItem)89 ServerError (org.rstudio.studio.client.server.ServerError)18 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)16 JsArrayString (com.google.gwt.core.client.JsArrayString)14 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)10 Handler (org.rstudio.core.client.command.Handler)10 Command (com.google.gwt.user.client.Command)9 ArrayList (java.util.ArrayList)7 AppCommand (org.rstudio.core.client.command.AppCommand)7 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)6 TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)5 JsArray (com.google.gwt.core.client.JsArray)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 JSONString (com.google.gwt.json.client.JSONString)4 FilePosition (org.rstudio.core.client.FilePosition)4 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)4 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)4 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)4 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)4 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)4