Search in sources :

Example 26 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class ToolbarPopupMenuButton method addMenuItem.

public void addMenuItem(final MenuItem item, final String value) {
    final ScheduledCommand cmd = item.getScheduledCommand();
    item.setScheduledCommand(new Command() {

        @Override
        public void execute() {
            setText(value);
            if (cmd != null)
                cmd.execute();
        }
    });
    getMenu().addItem(item);
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand)

Example 27 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class Wizard method goBack.

private void goBack() {
    final boolean isNavigationPage = activeParentNavigationPage_ != null;
    // determine behavior based on whether we are going back to a
    // navigation page or a selector page
    final Widget toWidget = isNavigationPage ? activeParentNavigationPage_ : firstPage_;
    final String pageCaptionLabel = isNavigationPage ? activeParentNavigationPage_.getPageCaption() : "";
    final WizardPage<I, T> newActivePage = isNavigationPage ? activeParentNavigationPage_ : firstPage_;
    final CanFocus focusWidget = (CanFocus) toWidget;
    activeParentNavigationPage_ = null;
    onPageDeactivated(activePage_);
    activePage_.onDeactivate(new Operation() {

        public void execute() {
            animate(activePage_, toWidget, false, new Command() {

                @Override
                public void execute() {
                    // update active page
                    activePage_ = newActivePage;
                    // update header
                    subCaptionLabel_.setVisible(newActivePage == firstPage_);
                    pageCaptionLabel_.setVisible(newActivePage != firstPage_ && isNavigationPage);
                    pageCaptionLabel_.setText(pageCaptionLabel);
                    setNextButtonState(newActivePage);
                    backButton_.setVisible(newActivePage != firstPage_);
                    // make ok button invisible
                    setOkButtonVisible(false);
                    // call hook
                    onSelectorActivated();
                    // set focus
                    focusWidget.focus();
                }
            });
        }
    });
}
Also used : Command(com.google.gwt.user.client.Command) Widget(com.google.gwt.user.client.ui.Widget)

Example 28 with Command

use of com.google.gwt.user.client.Command 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 29 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class TextEditingTarget method executeChunks.

public void executeChunks(final Position position, int which) {
    if (docDisplay_.showChunkOutputInline()) {
        executeChunksNotebookMode(position, which);
        return;
    }
    // HACK: This is just to force the entire function tree to be built.
    // It's the easiest way to make sure getCurrentScope() returns
    // a Scope with an end.
    docDisplay_.getScopeTree();
    // execute the chunks
    Scope[] previousScopes = scopeHelper_.getSweaveChunks(position, which);
    StringBuilder builder = new StringBuilder();
    for (Scope scope : previousScopes) {
        if (isRChunk(scope) && isExecutableChunk(scope)) {
            builder.append("# " + scope.getLabel() + "\n");
            builder.append(scopeHelper_.getSweaveChunkText(scope));
            builder.append("\n\n");
        }
    }
    final String code = builder.toString().trim();
    if (fileType_.isRmd()) {
        docUpdateSentinel_.withSavedDoc(new Command() {

            @Override
            public void execute() {
                rmarkdownHelper_.prepareForRmdChunkExecution(docUpdateSentinel_.getId(), docUpdateSentinel_.getContents(), new Command() {

                    @Override
                    public void execute() {
                        events_.fireEvent(new SendToConsoleEvent(code, true));
                    }
                });
            }
        });
    } else {
        events_.fireEvent(new SendToConsoleEvent(code, true));
    }
}
Also used : 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) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 30 with Command

use of com.google.gwt.user.client.Command in project rstudio by rstudio.

the class TextEditingTarget method previewRpresentation.

void previewRpresentation() {
    SessionInfo sessionInfo = session_.getSessionInfo();
    if (!fileTypeCommands_.getHTMLCapabiliites().isRMarkdownSupported()) {
        globalDisplay_.showMessage(MessageDisplay.MSG_WARNING, "Unable to Preview", "R Presentations require the knitr package " + "(version 1.2 or higher)");
        return;
    }
    PresentationState state = sessionInfo.getPresentationState();
    // if we are showing a tutorial then don't allow preview
    if (state.isTutorial()) {
        globalDisplay_.showMessage(MessageDisplay.MSG_WARNING, "Unable to Preview", "R Presentations cannot be previewed when a Tutorial " + "is active");
        return;
    }
    // if this presentation is already showing then just activate 
    if (state.isActive() && state.getFilePath().equals(docUpdateSentinel_.getPath())) {
        commands_.activatePresentation().execute();
        save();
    } else // otherwise reload
    {
        saveThenExecute(null, new Command() {

            @Override
            public void execute() {
                server_.showPresentationPane(docUpdateSentinel_.getPath(), new VoidServerRequestCallback());
            }
        });
    }
}
Also used : PresentationState(org.rstudio.studio.client.workbench.views.presentation.model.PresentationState) 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) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback)

Aggregations

Command (com.google.gwt.user.client.Command)208 AppCommand (org.rstudio.core.client.command.AppCommand)39 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)38 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)21 JsArrayString (com.google.gwt.core.client.JsArrayString)16 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)16 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)16 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)12 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)11 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)11 ServerError (org.rstudio.studio.client.server.ServerError)11 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)9 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)9 MenuItem (com.google.gwt.user.client.ui.MenuItem)8 Handler (org.rstudio.core.client.command.Handler)8 TextEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget)8 Timer (com.google.gwt.user.client.Timer)7 Widget (com.google.gwt.user.client.ui.Widget)7 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)7