Search in sources :

Example 1 with OperationWithInput

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

the class RmdOutput method onRmdRenderCompleted.

@Override
public void onRmdRenderCompleted(RmdRenderCompletedEvent event) {
    renderInProgress_ = false;
    // that instead
    if (onRenderCompleted_ != null) {
        onRenderCompleted_.execute();
        onRenderCompleted_ = null;
        return;
    }
    // ignore failures and completed Shiny docs (the latter are handled when
    // the server starts rather than when the render process is finished)
    final RmdRenderResult result = event.getResult();
    if (result.isShinyDocument()) {
        shinyDoc_ = null;
        return;
    }
    if (result.hasShinyContent() && !result.isShinyDocument()) {
        // If the result has Shiny content but wasn't rendered as a Shiny
        // document, suggest rendering as a Shiny document instead
        new ShinyDocumentWarningDialog(new OperationWithInput<Integer>() {

            @Override
            public void execute(Integer input) {
                switch(input) {
                    case ShinyDocumentWarningDialog.RENDER_SHINY_NO:
                        if (result.getSucceeded())
                            displayRenderResult(result);
                        break;
                    case ShinyDocumentWarningDialog.RENDER_SHINY_ONCE:
                        rerenderAsShiny(result);
                        break;
                    case ShinyDocumentWarningDialog.RENDER_SHINY_ALWAYS:
                        events_.fireEvent(new ConvertToShinyDocEvent(result.getTargetFile()));
                        break;
                }
            }
        }).showModal();
    } else if (result.getSucceeded()) {
        displayRenderResult(event.getResult());
    }
}
Also used : ShinyDocumentWarningDialog(org.rstudio.studio.client.rmarkdown.ui.ShinyDocumentWarningDialog) OperationWithInput(org.rstudio.core.client.widget.OperationWithInput) ConvertToShinyDocEvent(org.rstudio.studio.client.rmarkdown.events.ConvertToShinyDocEvent) RmdRenderResult(org.rstudio.studio.client.rmarkdown.model.RmdRenderResult)

Example 2 with OperationWithInput

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

the class Packages method doUpdatePackages.

private void doUpdatePackages(final PackageInstallContext installContext) {
    new CheckForUpdatesDialog(globalDisplay_, new ServerDataSource<JsArray<PackageUpdate>>() {

        public void requestData(ServerRequestCallback<JsArray<PackageUpdate>> requestCallback) {
            server_.checkForPackageUpdates(requestCallback);
        }
    }, new OperationWithInput<ArrayList<PackageUpdate>>() {

        @Override
        public void execute(ArrayList<PackageUpdate> updates) {
            InstallCommand cmd = buildUpdatePackagesCommand(updates, installContext);
            executeWithLoadedPackageCheck(cmd);
        }
    }, new Operation() {

        @Override
        public void execute() {
            // cancel emits an empty console input line to clear
            // the busy indicator
            events_.fireEvent(new SendToConsoleEvent("", true));
        }
    }).showModal();
}
Also used : ServerDataSource(org.rstudio.studio.client.server.ServerDataSource) ProgressOperationWithInput(org.rstudio.core.client.widget.ProgressOperationWithInput) OperationWithInput(org.rstudio.core.client.widget.OperationWithInput) ArrayList(java.util.ArrayList) SendToConsoleEvent(org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent) PackageUpdate(org.rstudio.studio.client.workbench.views.packages.model.PackageUpdate) VoidServerRequestCallback(org.rstudio.studio.client.server.VoidServerRequestCallback) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) CheckForUpdatesDialog(org.rstudio.studio.client.workbench.views.packages.ui.CheckForUpdatesDialog) Operation(org.rstudio.core.client.widget.Operation)

Example 3 with OperationWithInput

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

the class SourceBuildHelper method withSaveFilesBeforeCommand.

private void withSaveFilesBeforeCommand(final Command command, final Command cancelCommand, String commandSource) {
    if (uiPrefs_.saveAllBeforeBuild().getValue()) {
        sourceShim_.saveAllUnsaved(command);
    } else {
        String alwaysSaveOption = !uiPrefs_.saveAllBeforeBuild().getValue() ? "Always save files before build" : null;
        ArrayList<UnsavedChangesTarget> unsavedSourceDocs = sourceShim_.getUnsavedChanges(Source.TYPE_FILE_BACKED);
        if (unsavedSourceDocs.size() > 0) {
            new UnsavedChangesDialog(commandSource, alwaysSaveOption, unsavedSourceDocs, new OperationWithInput<UnsavedChangesDialog.Result>() {

                @Override
                public void execute(Result result) {
                    if (result.getAlwaysSave()) {
                        uiPrefs_.saveAllBeforeBuild().setGlobalValue(true);
                        uiPrefs_.writeUIPrefs();
                    }
                    sourceShim_.handleUnsavedChangesBeforeExit(result.getSaveTargets(), command);
                }
            }, cancelCommand).showModal();
        } else {
            command.execute();
        }
    }
}
Also used : UnsavedChangesDialog(org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) OperationWithInput(org.rstudio.core.client.widget.OperationWithInput) Result(org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog.Result)

Example 4 with OperationWithInput

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

the class Plots method onSavePlotAsPdf.

void onSavePlotAsPdf() {
    view_.bringToFront();
    final ProgressIndicator indicator = globalDisplay_.getProgressIndicator("Error");
    indicator.onProgress("Preparing to export plot...");
    // get the default directory
    final FileSystemItem defaultDir = ExportPlotUtils.getDefaultSaveDirectory(workbenchContext_.getCurrentWorkingDir());
    // get context
    server_.getUniqueSavePlotStem(defaultDir.getPath(), new SimpleRequestCallback<String>() {

        @Override
        public void onResponseReceived(String stem) {
            indicator.onCompleted();
            Size size = getPlotSize();
            final SavePlotAsPdfOptions currentOptions = uiPrefs_.get().savePlotAsPdfOptions().getValue();
            exportPlot_.savePlotAsPdf(globalDisplay_, server_, session_.getSessionInfo(), defaultDir, stem, currentOptions, pixelsToInches(size.width), pixelsToInches(size.height), new OperationWithInput<SavePlotAsPdfOptions>() {

                @Override
                public void execute(SavePlotAsPdfOptions options) {
                    if (!SavePlotAsPdfOptions.areEqual(options, currentOptions)) {
                        UIPrefs prefs = uiPrefs_.get();
                        prefs.savePlotAsPdfOptions().setGlobalValue(options);
                        prefs.writeUIPrefs();
                    }
                }
            });
        }

        @Override
        public void onError(ServerError error) {
            indicator.onError(error.getUserMessage());
        }
    });
}
Also used : FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) Size(org.rstudio.core.client.Size) ServerError(org.rstudio.studio.client.server.ServerError) OperationWithInput(org.rstudio.core.client.widget.OperationWithInput) SavePlotAsPdfOptions(org.rstudio.studio.client.workbench.views.plots.model.SavePlotAsPdfOptions) UIPrefs(org.rstudio.studio.client.workbench.prefs.model.UIPrefs)

Example 5 with OperationWithInput

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

the class SVNCommandHandler method onVcsResolve.

@Handler
void onVcsResolve() {
    ArrayList<StatusAndPath> items = display_.getSelectedItems();
    if (items.size() == 0)
        return;
    final ArrayList<String> paths = new ArrayList<String>();
    boolean conflict = false;
    for (StatusAndPath item : items) {
        paths.add(item.getPath());
        if ("C".equals(item.getStatus()))
            conflict = true;
        else if (item.isDirectory())
            conflict = true;
    }
    Operation resolveOperation = new Operation() {

        @Override
        public void execute() {
            new SVNResolveDialog(paths.size(), "Resolve", new OperationWithInput<String>() {

                @Override
                public void execute(String input) {
                    server_.svnResolve(input, paths, new ProcessCallback("SVN Resolve"));
                }
            }).showModal();
        }
    };
    if (conflict) {
        resolveOperation.execute();
    } else {
        String message = (paths.size() > 1 ? "None of the selected paths appear to have conflicts." : "The selected path does not appear to have conflicts.") + "\n\nDo you want to resolve anyway?";
        globalDisplay_.showYesNoMessage(GlobalDisplay.MSG_WARNING, "No Conflicts Detected", message, resolveOperation, true);
    }
}
Also used : ProcessCallback(org.rstudio.studio.client.workbench.views.vcs.common.ProcessCallback) StatusAndPath(org.rstudio.studio.client.common.vcs.StatusAndPath) ArrayList(java.util.ArrayList) OperationWithInput(org.rstudio.core.client.widget.OperationWithInput) Operation(org.rstudio.core.client.widget.Operation) Handler(org.rstudio.core.client.command.Handler)

Aggregations

OperationWithInput (org.rstudio.core.client.widget.OperationWithInput)5 ArrayList (java.util.ArrayList)2 Operation (org.rstudio.core.client.widget.Operation)2 Size (org.rstudio.core.client.Size)1 Handler (org.rstudio.core.client.command.Handler)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)1 ProgressOperationWithInput (org.rstudio.core.client.widget.ProgressOperationWithInput)1 StatusAndPath (org.rstudio.studio.client.common.vcs.StatusAndPath)1 ConvertToShinyDocEvent (org.rstudio.studio.client.rmarkdown.events.ConvertToShinyDocEvent)1 RmdRenderResult (org.rstudio.studio.client.rmarkdown.model.RmdRenderResult)1 ShinyDocumentWarningDialog (org.rstudio.studio.client.rmarkdown.ui.ShinyDocumentWarningDialog)1 ServerDataSource (org.rstudio.studio.client.server.ServerDataSource)1 ServerError (org.rstudio.studio.client.server.ServerError)1 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)1 VoidServerRequestCallback (org.rstudio.studio.client.server.VoidServerRequestCallback)1 UnsavedChangesTarget (org.rstudio.studio.client.workbench.model.UnsavedChangesTarget)1 UIPrefs (org.rstudio.studio.client.workbench.prefs.model.UIPrefs)1 UnsavedChangesDialog (org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog)1 Result (org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog.Result)1