Search in sources :

Example 71 with Command

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

the class ModalDialogBase method showModal.

public void showModal() {
    if (mainWidget_ == null) {
        mainWidget_ = createMainWidget();
        // get the main widget to line up with the right edge of the buttons.
        mainWidget_.getElement().getStyle().setMarginRight(2, Unit.PX);
        mainPanel_.insert(mainWidget_, 0);
    }
    originallyActiveElement_ = DomUtils.getActiveElement();
    if (originallyActiveElement_ != null)
        originallyActiveElement_.blur();
    // position the dialog
    positionAndShowDialog(new Command() {

        @Override
        public void execute() {
            // defer shown notification to allow all elements to render
            // before attempting to interact w/ them programatically (e.g. setFocus)
            Timer timer = new Timer() {

                public void run() {
                    onDialogShown();
                }
            };
            timer.schedule(100);
        }
    });
}
Also used : Timer(com.google.gwt.user.client.Timer) Command(com.google.gwt.user.client.Command)

Example 72 with Command

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

the class ApplicationQuit method prepareForQuit.

public void prepareForQuit(final String caption, final boolean forceSaveAll, final QuitContext quitContext) {
    boolean busy = workbenchContext_.isServerBusy() || workbenchContext_.isTerminalBusy();
    String msg = null;
    if (busy) {
        if (workbenchContext_.isServerBusy() && !workbenchContext_.isTerminalBusy())
            msg = "The R session is currently busy.";
        else if (workbenchContext_.isServerBusy() && workbenchContext_.isTerminalBusy())
            msg = "The R session and the terminal are currently busy.";
        else
            msg = "The terminal is currently busy.";
    }
    eventBus_.fireEvent(new QuitInitiatedEvent());
    if (busy && !forceSaveAll) {
        globalDisplay_.showYesNoMessage(MessageDialog.QUESTION, caption, msg + " Are you sure you want to quit?", new Operation() {

            @Override
            public void execute() {
                handleUnsavedChanges(caption, forceSaveAll, quitContext);
            }
        }, true);
    } else {
        // if we aren't restoring source documents then close them all now
        if (!pUiPrefs_.get().restoreSourceDocuments().getValue()) {
            sourceShim_.closeAllSourceDocs(caption, new Command() {

                @Override
                public void execute() {
                    handleUnsavedChanges(caption, forceSaveAll, quitContext);
                }
            });
        } else {
            handleUnsavedChanges(caption, forceSaveAll, quitContext);
        }
    }
}
Also used : Command(com.google.gwt.user.client.Command) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) QuitInitiatedEvent(org.rstudio.studio.client.application.events.QuitInitiatedEvent) Operation(org.rstudio.core.client.widget.Operation)

Example 73 with Command

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

the class ApplicationQuit method handleUnsavedChanges.

public static void handleUnsavedChanges(final int saveAction, String caption, boolean forceSaveAll, final SourceShim sourceShim, final WorkbenchContext workbenchContext, final UnsavedChangesTarget globalEnvTarget, final QuitContext quitContext) {
    // see what the unsaved changes situation is and prompt accordingly
    ArrayList<UnsavedChangesTarget> unsavedSourceDocs = sourceShim.getUnsavedChanges(Source.TYPE_FILE_BACKED);
    // force save all
    if (forceSaveAll) {
        // save all unsaved documents and then quit
        sourceShim.handleUnsavedChangesBeforeExit(unsavedSourceDocs, new Command() {

            @Override
            public void execute() {
                boolean saveChanges = saveAction != SaveAction.NOSAVE;
                quitContext.onReadyToQuit(saveChanges);
            }
        });
        return;
    } else // no unsaved changes at all
    if (saveAction != SaveAction.SAVEASK && unsavedSourceDocs.size() == 0) {
        // define quit operation
        final Operation quitOperation = new Operation() {

            public void execute() {
                quitContext.onReadyToQuit(saveAction == SaveAction.SAVE);
            }
        };
        // if this is a quit session then we always prompt
        if (ApplicationAction.isQuit()) {
            RStudioGinjector.INSTANCE.getGlobalDisplay().showYesNoMessage(MessageDialog.QUESTION, caption, "Are you sure you want to quit the R session?", quitOperation, true);
        } else {
            quitOperation.execute();
        }
        return;
    }
    // just an unsaved environment
    if (unsavedSourceDocs.size() == 0 && workbenchContext != null) {
        // confirm quit and do it
        String prompt = "Save workspace image to " + workbenchContext.getREnvironmentPath() + "?";
        RStudioGinjector.INSTANCE.getGlobalDisplay().showYesNoMessage(GlobalDisplay.MSG_QUESTION, caption, prompt, true, new Operation() {

            public void execute() {
                quitContext.onReadyToQuit(true);
            }
        }, new Operation() {

            public void execute() {
                quitContext.onReadyToQuit(false);
            }
        }, new Operation() {

            public void execute() {
            }
        }, "Save", "Don't Save", true);
    } else // must be from the main window in web mode)
    if (saveAction != SaveAction.SAVEASK && unsavedSourceDocs.size() == 1 && (Desktop.isDesktop() || !(unsavedSourceDocs.get(0) instanceof UnsavedChangesItem))) {
        sourceShim.saveWithPrompt(unsavedSourceDocs.get(0), sourceShim.revertUnsavedChangesBeforeExitCommand(new Command() {

            @Override
            public void execute() {
                quitContext.onReadyToQuit(saveAction == SaveAction.SAVE);
            }
        }), null);
    } else // multiple save targets
    {
        ArrayList<UnsavedChangesTarget> unsaved = new ArrayList<UnsavedChangesTarget>();
        if (saveAction == SaveAction.SAVEASK && globalEnvTarget != null)
            unsaved.add(globalEnvTarget);
        unsaved.addAll(unsavedSourceDocs);
        new UnsavedChangesDialog(caption, unsaved, new OperationWithInput<UnsavedChangesDialog.Result>() {

            @Override
            public void execute(Result result) {
                ArrayList<UnsavedChangesTarget> saveTargets = result.getSaveTargets();
                // remote global env target from list (if specified) and 
                // compute the saveChanges value
                boolean saveGlobalEnv = saveAction == SaveAction.SAVE;
                if (saveAction == SaveAction.SAVEASK && globalEnvTarget != null)
                    saveGlobalEnv = saveTargets.remove(globalEnvTarget);
                final boolean saveChanges = saveGlobalEnv;
                // save specified documents and then quit
                sourceShim.handleUnsavedChangesBeforeExit(saveTargets, new Command() {

                    @Override
                    public void execute() {
                        quitContext.onReadyToQuit(saveChanges);
                    }
                });
            }
        }, // no cancel operation
        null).showModal();
    }
}
Also used : UnsavedChangesItem(org.rstudio.studio.client.workbench.model.UnsavedChangesItem) UnsavedChangesDialog(org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) Command(com.google.gwt.user.client.Command) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) ArrayList(java.util.ArrayList) Operation(org.rstudio.core.client.widget.Operation) Result(org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog.Result)

Example 74 with Command

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

the class ApplicationQuit method onSuspendAndRestart.

@Override
public void onSuspendAndRestart(final SuspendAndRestartEvent event) {
    // Ignore nested restarts once restart starts
    if (suspendingAndRestarting_)
        return;
    // set restart pending for desktop
    setPendinqQuit(DesktopFrame.PENDING_QUIT_AND_RESTART);
    final TimedProgressIndicator progress = new TimedProgressIndicator(globalDisplay_.getProgressIndicator("Error"));
    progress.onTimedProgress("Restarting R", 1000);
    final Operation onRestartComplete = new Operation() {

        @Override
        public void execute() {
            suspendingAndRestarting_ = false;
            progress.onCompleted();
        }
    };
    // perform the suspend and restart
    suspendingAndRestarting_ = true;
    eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_INITIATED));
    server_.suspendForRestart(event.getSuspendOptions(), new VoidServerRequestCallback() {

        @Override
        protected void onSuccess() {
            // send pings until the server restarts
            sendPing(event.getAfterRestartCommand(), 200, 25, new Command() {

                @Override
                public void execute() {
                    onRestartComplete.execute();
                    eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_COMPLETED));
                }
            });
        }

        @Override
        protected void onFailure() {
            onRestartComplete.execute();
            eventBus_.fireEvent(new RestartStatusEvent(RestartStatusEvent.RESTART_COMPLETED));
            setPendinqQuit(DesktopFrame.PENDING_QUIT_NONE);
        }
    });
}
Also used : TimedProgressIndicator(org.rstudio.studio.client.common.TimedProgressIndicator) Command(com.google.gwt.user.client.Command) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) RestartStatusEvent(org.rstudio.studio.client.application.events.RestartStatusEvent) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) Operation(org.rstudio.core.client.widget.Operation)

Example 75 with Command

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

the class ModifyKeyboardShortcutsWidget method collectShortcuts.

private void collectShortcuts() {
    final List<KeyboardShortcutEntry> bindings = new ArrayList<KeyboardShortcutEntry>();
    SerializedCommandQueue queue = new SerializedCommandQueue();
    // Load addins discovered as part of package exports. This registers
    // the addin, with the actual keybinding to be registered later,
    // if discovered.
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            RAddins rAddins = addins_.getRAddins();
            for (String key : JsUtil.asIterable(rAddins.keys())) {
                RAddin addin = rAddins.get(key);
                bindings.add(new KeyboardShortcutEntry(addin.getPackage() + "::" + addin.getBinding(), addin.getName(), new KeySequence(), KeyboardShortcutEntry.TYPE_ADDIN, false, AppCommand.Context.Addin));
            }
            continuation.execute();
        }
    });
    // Load saved addin bindings
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            addins_.loadBindings(new CommandWithArg<EditorKeyBindings>() {

                @Override
                public void execute(EditorKeyBindings addinBindings) {
                    for (String commandId : addinBindings.iterableKeys()) {
                        EditorKeyBinding addinBinding = addinBindings.get(commandId);
                        for (KeyboardShortcutEntry binding : bindings) {
                            if (binding.getId() == commandId) {
                                List<KeySequence> keys = addinBinding.getKeyBindings();
                                if (keys.size() >= 1)
                                    binding.setDefaultKeySequence(keys.get(0));
                                if (keys.size() >= 2) {
                                    for (int i = 1; i < keys.size(); i++) {
                                        bindings.add(new KeyboardShortcutEntry(binding.getId(), binding.getName(), keys.get(i), KeyboardShortcutEntry.TYPE_ADDIN, false, AppCommand.Context.Addin));
                                    }
                                }
                            }
                        }
                    }
                    continuation.execute();
                }
            });
        }
    });
    // Ace loading command
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            // Ace Commands
            JsArray<AceCommand> aceCommands = editorCommands_.getCommands();
            for (int i = 0; i < aceCommands.length(); i++) {
                AceCommand command = aceCommands.get(i);
                JsArrayString shortcuts = command.getBindingsForCurrentPlatform();
                if (shortcuts != null) {
                    String id = command.getInternalName();
                    String name = command.getDisplayName();
                    boolean custom = command.isCustomBinding();
                    for (int j = 0; j < shortcuts.length(); j++) {
                        String shortcut = shortcuts.get(j);
                        KeySequence keys = KeySequence.fromShortcutString(shortcut);
                        int type = KeyboardShortcutEntry.TYPE_EDITOR_COMMAND;
                        bindings.add(new KeyboardShortcutEntry(id, name, keys, type, custom, AppCommand.Context.Editor));
                    }
                }
            }
            continuation.execute();
        }
    });
    // RStudio commands
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            // RStudio Commands
            appCommands_.loadBindings(new CommandWithArg<EditorKeyBindings>() {

                @Override
                public void execute(final EditorKeyBindings customBindings) {
                    Map<String, AppCommand> commands = commands_.getCommands();
                    for (Map.Entry<String, AppCommand> entry : commands.entrySet()) {
                        AppCommand command = entry.getValue();
                        if (isExcludedCommand(command))
                            continue;
                        String id = command.getId();
                        String name = getAppCommandName(command);
                        int type = KeyboardShortcutEntry.TYPE_RSTUDIO_COMMAND;
                        boolean isCustom = customBindings.hasKey(id);
                        List<KeySequence> keySequences = new ArrayList<KeySequence>();
                        if (isCustom)
                            keySequences = customBindings.get(id).getKeyBindings();
                        else
                            keySequences.add(command.getKeySequence());
                        for (KeySequence keys : keySequences) {
                            KeyboardShortcutEntry binding = new KeyboardShortcutEntry(id, name, keys, type, isCustom, command.getContext());
                            bindings.add(binding);
                        }
                    }
                    continuation.execute();
                }
            });
        }
    });
    // Sort and finish up
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(final Command continuation) {
            Collections.sort(bindings, new Comparator<KeyboardShortcutEntry>() {

                @Override
                public int compare(KeyboardShortcutEntry o1, KeyboardShortcutEntry o2) {
                    if (o1.getContext() != o2.getContext())
                        return o1.getContext().compareTo(o2.getContext());
                    return o1.getName().compareTo(o2.getName());
                }
            });
            originalBindings_ = bindings;
            updateData(bindings);
            continuation.execute();
        }
    });
    queue.addCommand(new SerializedCommand() {

        @Override
        public void onExecute(Command continuation) {
            if (initialFilterText_ != null) {
                filterWidget_.setText(initialFilterText_);
                filter();
            }
            continuation.execute();
        }
    });
    // Exhaust the queue
    queue.run();
}
Also used : SerializedCommand(org.rstudio.core.client.SerializedCommand) RAddins(org.rstudio.studio.client.workbench.addins.Addins.RAddins) SerializedCommandQueue(org.rstudio.core.client.SerializedCommandQueue) ArrayList(java.util.ArrayList) JsArrayString(com.google.gwt.core.client.JsArrayString) CommandWithArg(org.rstudio.core.client.CommandWithArg) Comparator(java.util.Comparator) EditorKeyBinding(org.rstudio.core.client.command.EditorCommandManager.EditorKeyBinding) EditorKeyBindings(org.rstudio.core.client.command.EditorCommandManager.EditorKeyBindings) JsArray(com.google.gwt.core.client.JsArray) RAddin(org.rstudio.studio.client.workbench.addins.Addins.RAddin) JsArrayString(com.google.gwt.core.client.JsArrayString) Command(com.google.gwt.user.client.Command) SerializedCommand(org.rstudio.core.client.SerializedCommand) AceCommand(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceCommand) AceCommand(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceCommand) KeySequence(org.rstudio.core.client.command.KeyboardShortcut.KeySequence) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Command (com.google.gwt.user.client.Command)141 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)11 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)11 ArrayList (java.util.ArrayList)11 ServerError (org.rstudio.studio.client.server.ServerError)11 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)10 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)10 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)9 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)8 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 Operation (org.rstudio.core.client.widget.Operation)7 EditingTarget (org.rstudio.studio.client.workbench.views.source.editors.EditingTarget)7 CodeBrowserEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.codebrowser.CodeBrowserEditingTarget)7 DataEditingTarget (org.rstudio.studio.client.workbench.views.source.editors.data.DataEditingTarget)7