Search in sources :

Example 41 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class SourceWindow method closeSourceWindow.

private void closeSourceWindow() {
    final ApplicationQuit.QuitContext quitContext = new ApplicationQuit.QuitContext() {

        @Override
        public void onReadyToQuit(boolean saveChanges) {
            markReadyToClose();
            // we may be in the middle of closing the window already, so
            // defer the closure request
            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                @Override
                public void execute() {
                    WindowEx.get().close();
                }
            });
        }
    };
    // collect titled and untitled changes -- we don't prompt for untitled 
    // changes in the main window, but we do in the source window 
    ArrayList<UnsavedChangesTarget> untitled = sourceShim_.getUnsavedChanges(Source.TYPE_UNTITLED);
    ArrayList<UnsavedChangesTarget> fileBacked = sourceShim_.getUnsavedChanges(Source.TYPE_FILE_BACKED);
    if (Desktop.isDesktop() && untitled.size() > 0) {
        // so handle that gracefully
        if (fileBacked.size() == 0 && untitled.size() == 1) {
            sourceShim_.saveWithPrompt(untitled.get(0), new Command() {

                @Override
                public void execute() {
                    quitContext.onReadyToQuit(false);
                }
            }, null);
            return;
        } else {
            // if we have multiple unsaved untitled targets or a mix of untitled
            // and file backed targets, we just fall back to a generic prompt
            RStudioGinjector.INSTANCE.getGlobalDisplay().showYesNoMessage(GlobalDisplay.MSG_WARNING, "Unsaved Changes", "There are unsaved documents in this window. Are you sure " + "you want to close it?", // include cancel
            false, new Operation() {

                @Override
                public void execute() {
                    quitContext.onReadyToQuit(false);
                }
            }, null, null, "Close and Discard Changes", "Cancel", false);
            return;
        }
    }
    // prompt to save any unsaved documents
    if (fileBacked.size() == 0)
        quitContext.onReadyToQuit(false);
    else
        ApplicationQuit.handleUnsavedChanges(SaveAction.SAVEASK, "Close Source Window", false, sourceShim_, null, null, quitContext);
}
Also used : ApplicationQuit(org.rstudio.studio.client.application.ApplicationQuit) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) Command(com.google.gwt.user.client.Command) Scheduler(com.google.gwt.core.client.Scheduler) Operation(org.rstudio.core.client.widget.Operation)

Example 42 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class Source method openFile.

// top-level wrapper for opening files. takes care of:
//  - making sure the view is visible
//  - checking whether it is already open and re-selecting its tab
//  - prohibit opening very large files (>500KB)
//  - confirmation of opening large files (>100KB)
//  - finally, actually opening the file from the server
//    via the call to the lower level openFile method
private void openFile(final FileSystemItem file, final TextFileType fileType, final ResultCallback<EditingTarget, ServerError> resultCallback) {
    ensureVisible(true);
    if (fileType.isRNotebook()) {
        openNotebook(file, fileType, resultCallback);
        return;
    }
    if (file == null) {
        newDoc(fileType, resultCallback);
        return;
    }
    if (openFileAlreadyOpen(file, resultCallback))
        return;
    EditingTarget target = editingTargetSource_.getEditingTarget(fileType);
    if (file.getLength() > target.getFileSizeLimit()) {
        if (resultCallback != null)
            resultCallback.onCancelled();
        showFileTooLargeWarning(file, target.getFileSizeLimit());
    } else if (file.getLength() > target.getLargeFileSize()) {
        confirmOpenLargeFile(file, new Operation() {

            public void execute() {
                openFileFromServer(file, fileType, resultCallback);
            }
        }, new Operation() {

            public void execute() {
                // user (wisely) cancelled
                if (resultCallback != null)
                    resultCallback.onCancelled();
            }
        });
    } else {
        openFileFromServer(file, fileType, resultCallback);
    }
}
Also used : 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) Operation(org.rstudio.core.client.widget.Operation)

Example 43 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class TerminalTabPresenter method confirmClose.

public void confirmClose(final Command onConfirmed) {
    if (view_.activeTerminals()) {
        globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_QUESTION, "Close Terminal(s) ", "Are you sure you want to close all terminals? Any running jobs " + "will be stopped.", false, new Operation() {

            @Override
            public void execute() {
                shutDownTerminals();
                onConfirmed.execute();
            }
        }, null, null, "Close Terminals", "Cancel", true);
    } else {
        shutDownTerminals();
        onConfirmed.execute();
    }
}
Also used : Operation(org.rstudio.core.client.widget.Operation)

Example 44 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class CreateBranchToolbarButton method promptUserRegardingLocalBranchOfSameName.

private boolean promptUserRegardingLocalBranchOfSameName(final CreateBranchDialog.Input input, final BranchesInfo branchesInfo) {
    boolean hasBranch = false;
    for (String branch : JsUtil.asIterable(branchesInfo.getBranches())) {
        if (branch.equals(input.getBranch())) {
            hasBranch = true;
            break;
        }
    }
    if (hasBranch) {
        String message = "A local branch named '" + input.getBranch() + "' already exists. " + "Would you like to check out that branch, or overwrite it?";
        List<String> labels = new ArrayList<String>();
        labels.add("Checkout");
        labels.add("Overwrite");
        labels.add("Cancel");
        List<Operation> operations = new ArrayList<Operation>();
        operations.add(new Operation() {

            @Override
            public void execute() {
                onCheckout(input);
            }
        });
        operations.add(new Operation() {

            @Override
            public void execute() {
                onCreate(input);
            }
        });
        operations.add(new Operation() {

            @Override
            public void execute() {
            // no-op
            }
        });
        globalDisplay_.showGenericDialog(MessageDialog.INFO, "Local Branch Already Exists", message, labels, operations, 2);
    }
    return hasBranch;
}
Also used : ArrayList(java.util.ArrayList) Operation(org.rstudio.core.client.widget.Operation)

Example 45 with Operation

use of org.rstudio.core.client.widget.Operation in project rstudio by rstudio.

the class GitPresenter method doRevert.

private void doRevert(final ArrayList<String> revertList, final Command onRevertConfirmed) {
    String noun = revertList.size() == 1 ? "file" : "files";
    globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_WARNING, "Revert Changes", "Changes to the selected " + noun + " will be lost, including " + "staged changes.\n\nAre you sure you want to continue?", new Operation() {

        @Override
        public void execute() {
            if (onRevertConfirmed != null)
                onRevertConfirmed.execute();
            server_.gitRevert(revertList, new SimpleRequestCallback<Void>("Revert Changes"));
        }
    }, false);
}
Also used : Operation(org.rstudio.core.client.widget.Operation) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Aggregations

Operation (org.rstudio.core.client.widget.Operation)47 ServerError (org.rstudio.studio.client.server.ServerError)8 Command (com.google.gwt.user.client.Command)7 ArrayList (java.util.ArrayList)6 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)5 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)5 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)4 SimpleRequestCallback (org.rstudio.studio.client.common.SimpleRequestCallback)4 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)4 JsArrayString (com.google.gwt.core.client.JsArrayString)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 ProgressOperation (org.rstudio.core.client.widget.ProgressOperation)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 Timer (com.google.gwt.user.client.Timer)2 HTML (com.google.gwt.user.client.ui.HTML)2 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)2 WindowEx (org.rstudio.core.client.dom.WindowEx)2 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)2