Search in sources :

Example 1 with SavePlotAsPdfOptions

use of org.rstudio.studio.client.workbench.views.plots.model.SavePlotAsPdfOptions 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)

Aggregations

Size (org.rstudio.core.client.Size)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 OperationWithInput (org.rstudio.core.client.widget.OperationWithInput)1 ProgressIndicator (org.rstudio.core.client.widget.ProgressIndicator)1 ServerError (org.rstudio.studio.client.server.ServerError)1 UIPrefs (org.rstudio.studio.client.workbench.prefs.model.UIPrefs)1 SavePlotAsPdfOptions (org.rstudio.studio.client.workbench.views.plots.model.SavePlotAsPdfOptions)1