Search in sources :

Example 16 with Command

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

the class DocsMenu method setDocs.

public void setDocs(ImageResource[] icons, String[] names, String[] paths) {
    clearItems();
    names_.clear();
    menuItems_.clear();
    // de-duplicate names
    names = deduplicate(names, paths);
    assert icons.length == names.length && names.length == paths.length;
    if (icons.length == 0) {
        addItem(new DisabledMenuItem("(No documents)"));
    }
    for (int i = 0; i < icons.length; i++) {
        String label = AppCommand.formatMenuLabel(icons[i], names[i] + "   ", null);
        final int tabIndex = i;
        MenuItem item = addItem(label, true, new Command() {

            public void execute() {
                if (panel_ != null)
                    panel_.hide(false);
                events_.fireEvent(new SwitchToDocEvent(tabIndex));
            }
        });
        item.setTitle(paths[i]);
        names_.add(names[i]);
        menuItems_.add(item);
    }
}
Also used : DisabledMenuItem(org.rstudio.core.client.command.DisabledMenuItem) AppCommand(org.rstudio.core.client.command.AppCommand) Command(com.google.gwt.user.client.Command) SwitchToDocEvent(org.rstudio.studio.client.workbench.views.source.events.SwitchToDocEvent) MenuItem(com.google.gwt.user.client.ui.MenuItem) DisabledMenuItem(org.rstudio.core.client.command.DisabledMenuItem)

Example 17 with Command

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

the class Presentation method onPresentationFullscreen.

@Handler
void onPresentationFullscreen() {
    // clear the internal iframe so there is no conflict over handling
    // presentation events (we'll restore it on zoom close)
    view_.clear();
    // show the zoomed version of the presentation. after it closes
    // restore the inline version
    view_.zoom(session_.getSessionInfo().getPresentationName(), buildPresentationUrl("zoom"), new Command() {

        @Override
        public void execute() {
            view_.load(buildPresentationUrl(), currentState_.getFilePath());
        }
    });
}
Also used : Command(com.google.gwt.user.client.Command) TimeBufferedCommand(org.rstudio.core.client.TimeBufferedCommand) Handler(org.rstudio.core.client.command.Handler)

Example 18 with Command

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

the class Source method onNewRPresentationDoc.

@Handler
public void onNewRPresentationDoc() {
    dependencyManager_.withRMarkdown("Authoring R Presentations", new Command() {

        @Override
        public void execute() {
            fileDialogs_.saveFile("New R Presentation", fileContext_, workbenchContext_.getDefaultFileDialogDir(), ".Rpres", true, new ProgressOperationWithInput<FileSystemItem>() {

                @Override
                public void execute(final FileSystemItem input, final ProgressIndicator indicator) {
                    if (input == null) {
                        indicator.onCompleted();
                        return;
                    }
                    indicator.onProgress("Creating Presentation...");
                    server_.createNewPresentation(input.getPath(), new VoidServerRequestCallback(indicator) {

                        @Override
                        public void onSuccess() {
                            openFile(input, FileTypeRegistry.RPRESENTATION, new CommandWithArg<EditingTarget>() {

                                @Override
                                public void execute(EditingTarget arg) {
                                    server_.showPresentationPane(input.getPath(), new VoidServerRequestCallback());
                                }
                            });
                        }
                    });
                }
            });
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) 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) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ProgressOperationWithInput(org.rstudio.core.client.widget.ProgressOperationWithInput) NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) FileTypeChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.FileTypeChangedHandler) Handler(org.rstudio.core.client.command.Handler) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) SelectionHandler(com.google.gwt.event.logical.shared.SelectionHandler) CloseHandler(com.google.gwt.event.logical.shared.CloseHandler) ViewDataHandler(org.rstudio.studio.client.workbench.views.data.events.ViewDataHandler) SourceOnSaveChangedHandler(org.rstudio.studio.client.workbench.views.source.editors.text.events.SourceOnSaveChangedHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) OpenSourceFileHandler(org.rstudio.studio.client.common.filetypes.events.OpenSourceFileHandler)

Example 19 with Command

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

the class Source method closeAllLocalSourceDocs.

private void closeAllLocalSourceDocs(String caption, Command onCompleted, final boolean excludeActive) {
    // save active editor for exclusion (it changes as we close tabs)
    final EditingTarget activeEditor = activeEditor_;
    // collect up a list of dirty documents
    ArrayList<EditingTarget> dirtyTargets = new ArrayList<EditingTarget>();
    for (EditingTarget target : editors_) {
        if (excludeActive && target == activeEditor)
            continue;
        if (target.dirtyState().getValue())
            dirtyTargets.add(target);
    }
    // create a command used to close all tabs 
    final Command closeAllTabsCommand = new Command() {

        @Override
        public void execute() {
            cpsExecuteForEachEditor(editors_, new CPSEditingTargetCommand() {

                @Override
                public void execute(EditingTarget target, Command continuation) {
                    if (excludeActive && target == activeEditor) {
                        continuation.execute();
                        return;
                    } else {
                        view_.closeTab(target.asWidget(), false, continuation);
                    }
                }
            });
        }
    };
    // save targets
    saveEditingTargetsWithPrompt(caption, dirtyTargets, CommandUtil.join(closeAllTabsCommand, onCompleted), null);
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) 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) ArrayList(java.util.ArrayList)

Example 20 with Command

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

the class Source method openProjectDocs.

private void openProjectDocs(final Session session) {
    JsArrayString openDocs = session.getSessionInfo().getProjectOpenDocs();
    if (openDocs.length() > 0) {
        // set new tab pending for the duration of the continuation
        newTabPending_++;
        // create a continuation for opening the source docs
        SerializedCommandQueue openCommands = new SerializedCommandQueue();
        for (int i = 0; i < openDocs.length(); i++) {
            String doc = openDocs.get(i);
            final FileSystemItem fsi = FileSystemItem.createFile(doc);
            openCommands.addCommand(new SerializedCommand() {

                @Override
                public void onExecute(final Command continuation) {
                    openFile(fsi, fileTypeRegistry_.getTextTypeForFile(fsi), new CommandWithArg<EditingTarget>() {

                        @Override
                        public void execute(EditingTarget arg) {
                            continuation.execute();
                        }
                    });
                }
            });
        }
        // decrement newTabPending and select first tab when done
        openCommands.addCommand(new SerializedCommand() {

            @Override
            public void onExecute(Command continuation) {
                newTabPending_--;
                onFirstTab();
                continuation.execute();
            }
        });
        // execute the continuation
        openCommands.run();
    }
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) AppCommand(org.rstudio.core.client.command.AppCommand) 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) JsArrayString(com.google.gwt.core.client.JsArrayString) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString)

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