Search in sources :

Example 1 with TextFileType

use of org.rstudio.studio.client.common.filetypes.TextFileType in project rstudio by rstudio.

the class TextEditingTarget method initStatusBar.

private void initStatusBar() {
    statusBar_ = view_.getStatusBar();
    docDisplay_.addCursorChangedHandler(new CursorChangedHandler() {

        public void onCursorChanged(CursorChangedEvent event) {
            updateStatusBarPosition();
            if (docDisplay_.isScopeTreeReady(event.getPosition().getRow()))
                updateCurrentScope();
        }
    });
    updateStatusBarPosition();
    updateStatusBarLanguage();
    // build file type menu dynamically (so it can change according
    // to whether e.g. knitr is installed)
    statusBar_.getLanguage().addMouseDownHandler(new MouseDownHandler() {

        @Override
        public void onMouseDown(MouseDownEvent event) {
            // build menu with all file types - also track whether we need
            // to add the current type (may be the case for types which we 
            // support but don't want to expose on the menu -- e.g. Rmd 
            // files when knitr isn't installed)
            boolean addCurrentType = true;
            final StatusBarPopupMenu menu = new StatusBarPopupMenu();
            TextFileType[] fileTypes = fileTypeCommands_.statusBarFileTypes();
            for (TextFileType type : fileTypes) {
                menu.addItem(createMenuItemForType(type));
                if (addCurrentType && type.equals(fileType_))
                    addCurrentType = false;
            }
            // add the current type if isn't on the menu 
            if (addCurrentType)
                menu.addItem(createMenuItemForType(fileType_));
            // show the menu
            menu.showRelativeToUpward((UIObject) statusBar_.getLanguage(), true);
        }
    });
    statusBar_.getScope().addMouseDownHandler(new MouseDownHandler() {

        public void onMouseDown(MouseDownEvent event) {
            // Unlike the other status bar elements, the function outliner
            // needs its menu built on demand
            JsArray<Scope> tree = docDisplay_.getScopeTree();
            final StatusBarPopupMenu menu = new StatusBarPopupMenu();
            MenuItem defaultItem = null;
            if (fileType_.isRpres()) {
                String path = docUpdateSentinel_.getPath();
                if (path != null) {
                    presentationHelper_.buildSlideMenu(docUpdateSentinel_.getPath(), dirtyState_.getValue(), TextEditingTarget.this, new CommandWithArg<StatusBarPopupRequest>() {

                        @Override
                        public void execute(StatusBarPopupRequest request) {
                            showStatusBarPopupMenu(request);
                        }
                    });
                }
            } else {
                defaultItem = addFunctionsToMenu(menu, tree, "", docDisplay_.getCurrentScope(), true);
                showStatusBarPopupMenu(new StatusBarPopupRequest(menu, defaultItem));
            }
        }
    });
}
Also used : UIObject(com.google.gwt.user.client.ui.UIObject) JsArray(com.google.gwt.core.client.JsArray) StatusBarPopupMenu(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu) MenuItem(com.google.gwt.user.client.ui.MenuItem) JsArrayString(com.google.gwt.core.client.JsArrayString) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) StatusBarPopupRequest(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupRequest)

Example 2 with TextFileType

use of org.rstudio.studio.client.common.filetypes.TextFileType 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 3 with TextFileType

use of org.rstudio.studio.client.common.filetypes.TextFileType in project rstudio by rstudio.

the class RmdOutput method onWebsiteFileSaved.

@Override
public void onWebsiteFileSaved(WebsiteFileSavedEvent event) {
    // skip if there is a build in progress
    if (workbenchContext_.isBuildInProgress())
        return;
    // skip if there is a render in progress
    if (renderInProgress_)
        return;
    // skip if there was a quit initiated since the last render
    if (quitInitiatedAfterLastRender_)
        return;
    // is there an output frame?
    if (outputFrame_ == null || outputFrame_.getWindowObject() == null)
        return;
    // is it showing a page from the current site?
    String websiteDir = session_.getSessionInfo().getBuildTargetDir();
    final RmdPreviewParams params = outputFrame_.getPreviewParams();
    if (!params.getTargetFile().startsWith(websiteDir))
        return;
    // is the changed file one that should always produce a rebuild?
    FileSystemItem file = event.getFileSystemItem();
    TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(file);
    String typeId = fileType.getTypeId();
    if (fileType.isR() || typeId.equals(FileTypeRegistry.HTML.getTypeId()) || typeId.equals(FileTypeRegistry.YAML.getTypeId()) || typeId.equals(FileTypeRegistry.JSON.getTypeId())) {
        reRenderPreview();
    } else // is the changed file a markdown document
    if (fileType.isMarkdown()) {
        // included Rmd files always produce a rebuild of the current file
        if (file.getStem().startsWith("_"))
            reRenderPreview();
        // files in subdirectories are also includes so re-render them also
        if (!file.getParentPathString().equals(websiteDir))
            reRenderPreview();
    // ...otherwise leave it alone (requires a knit)
    } else // see if this should result in a copy + refresh
    {
        server_.maybeCopyWebsiteAsset(file.getPath(), new SimpleRequestCallback<Boolean>() {

            @Override
            public void onResponseReceived(Boolean copied) {
                if (copied)
                    outputFrame_.showRmdPreview(params, true);
            }
        });
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) RmdPreviewParams(org.rstudio.studio.client.rmarkdown.model.RmdPreviewParams) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Example 4 with TextFileType

use of org.rstudio.studio.client.common.filetypes.TextFileType in project rstudio by rstudio.

the class PresentationDispatcher method performSourceCommand.

private void performSourceCommand(String param1, String param2) {
    if (param1 != null) {
        // get filename and type
        FileSystemItem file = FileSystemItem.createFile(getPresentationPath(param1));
        TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(file);
        // check for a file position and/or pattern
        FilePosition pos = null;
        String pattern = null;
        if (param2 != null) {
            if (param2.length() > 2 && param2.startsWith("/") && param2.endsWith("/")) {
                pattern = param2.substring(1, param2.length() - 1);
            } else {
                int line = StringUtil.parseInt(param2, 0);
                if (line > 0)
                    pos = FilePosition.create(line, 1);
            }
        }
        // dispatch
        fireOpenSourceFileEvent(new OpenPresentationSourceFileEvent(file, fileType, pos, pattern));
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) FilePosition(org.rstudio.core.client.FilePosition) OpenPresentationSourceFileEvent(org.rstudio.studio.client.common.filetypes.events.OpenPresentationSourceFileEvent)

Example 5 with TextFileType

use of org.rstudio.studio.client.common.filetypes.TextFileType in project rstudio by rstudio.

the class Source method attemptSourceNavigation.

private void attemptSourceNavigation(final SourceNavigation navigation, final AppCommand retryCommand) {
    // see if we can navigate by id
    String docId = navigation.getDocumentId();
    final EditingTarget target = getEditingTargetForId(docId);
    if (target != null) {
        // case execute the retry command
        if ((target == activeEditor_) && target.isAtSourceRow(navigation.getPosition())) {
            if (retryCommand.isEnabled())
                retryCommand.execute();
        } else {
            suspendSourceNavigationAdding_ = true;
            try {
                view_.selectTab(target.asWidget());
                target.restorePosition(navigation.getPosition());
            } finally {
                suspendSourceNavigationAdding_ = false;
            }
        }
    } else // check for code browser navigation
    if ((navigation.getPath() != null) && navigation.getPath().startsWith(CodeBrowserEditingTarget.PATH)) {
        activateCodeBrowser(navigation.getPath(), false, new SourceNavigationResultCallback<CodeBrowserEditingTarget>(navigation.getPosition(), retryCommand));
    } else // check for file path navigation
    if ((navigation.getPath() != null) && !navigation.getPath().startsWith(DataItem.URI_PREFIX)) {
        FileSystemItem file = FileSystemItem.createFile(navigation.getPath());
        TextFileType fileType = fileTypeRegistry_.getTextTypeForFile(file);
        // open the file and restore the position
        openFile(file, fileType, new SourceNavigationResultCallback<EditingTarget>(navigation.getPosition(), retryCommand));
    } else {
        // couldn't navigate to this item, retry
        if (retryCommand.isEnabled())
            retryCommand.execute();
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) TextEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget) EditingTarget(org.rstudio.studio.client.workbench.views.source.editors.EditingTarget) DataEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget) CodeBrowserEditingTarget(org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Aggregations

TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)9 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)4 JsArrayString (com.google.gwt.core.client.JsArrayString)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 JsArray (com.google.gwt.core.client.JsArray)1 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 JSONString (com.google.gwt.json.client.JSONString)1 Command (com.google.gwt.user.client.Command)1 MenuItem (com.google.gwt.user.client.ui.MenuItem)1 UIObject (com.google.gwt.user.client.ui.UIObject)1 FilePosition (org.rstudio.core.client.FilePosition)1 AppCommand (org.rstudio.core.client.command.AppCommand)1 SimpleRequestCallback (org.rstudio.studio.client.common.SimpleRequestCallback)1 OpenPresentationSourceFileEvent (org.rstudio.studio.client.common.filetypes.events.OpenPresentationSourceFileEvent)1 RmdPreviewParams (org.rstudio.studio.client.rmarkdown.model.RmdPreviewParams)1 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)1 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)1 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)1 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)1 CppCompletionOperation (org.rstudio.studio.client.workbench.views.source.editors.text.cpp.CppCompletionOperation)1