Search in sources :

Example 1 with UnsavedChangesTarget

use of org.rstudio.studio.client.workbench.model.UnsavedChangesTarget in project rstudio by rstudio.

the class UnsavedChangesDialog method createMainWidget.

@Override
protected Widget createMainWidget() {
    // create cell table
    targetsCellTable_ = new CellTable<UnsavedChangesTarget>(15, UnsavedChangesCellTableResources.INSTANCE, KEY_PROVIDER);
    selectionModel_ = new MultiSelectionModel<UnsavedChangesTarget>(KEY_PROVIDER);
    targetsCellTable_.setSelectionModel(selectionModel_, DefaultSelectionEventManager.<UnsavedChangesTarget>createCheckboxManager());
    targetsCellTable_.setWidth("100%", true);
    // add columns
    addSelectionColumn();
    addIconColumn();
    addNameAndPathColumn();
    // hook-up data provider 
    dataProvider_ = new ListDataProvider<UnsavedChangesTarget>();
    dataProvider_.setList(targets_);
    dataProvider_.addDataDisplay(targetsCellTable_);
    targetsCellTable_.setPageSize(targets_.size());
    // select all by default
    for (UnsavedChangesTarget editingTarget : dataProvider_.getList()) selectionModel_.setSelected(editingTarget, true);
    // enclose cell table in scroll panel
    ScrollPanel scrollPanel = new ScrollPanel();
    scrollPanel.setStylePrimaryName(RESOURCES.styles().targetScrollPanel());
    scrollPanel.setWidget(targetsCellTable_);
    if (dataProvider_.getList().size() > 4)
        scrollPanel.setHeight("280px");
    // always save check box (may not be shown)
    chkAlwaysSave_ = new CheckBox(alwaysSaveOption_);
    // main widget
    VerticalPanel panel = new VerticalPanel();
    Label captionLabel = new Label("The following files have unsaved changes:");
    captionLabel.setStylePrimaryName(RESOURCES.styles().captionLabel());
    panel.add(captionLabel);
    panel.add(scrollPanel);
    if (!StringUtil.isNullOrEmpty(alwaysSaveOption_)) {
        panel.add(chkAlwaysSave_);
        panel.setCellHeight(chkAlwaysSave_, "30px");
        panel.setCellVerticalAlignment(chkAlwaysSave_, HasVerticalAlignment.ALIGN_MIDDLE);
    }
    return panel;
}
Also used : VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) CheckBox(com.google.gwt.user.client.ui.CheckBox) Label(com.google.gwt.user.client.ui.Label) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel)

Example 2 with UnsavedChangesTarget

use of org.rstudio.studio.client.workbench.model.UnsavedChangesTarget in project rstudio by rstudio.

the class SourceWindow method getUnsavedChanges.

private JsArray<UnsavedChangesItem> getUnsavedChanges() {
    JsArray<UnsavedChangesItem> items = JsArray.createArray().cast();
    ArrayList<UnsavedChangesTarget> targets = sourceShim_.getUnsavedChanges(Source.TYPE_FILE_BACKED);
    for (UnsavedChangesTarget target : targets) {
        items.push(UnsavedChangesItem.create(target));
    }
    return items;
}
Also used : UnsavedChangesItem(org.rstudio.studio.client.workbench.model.UnsavedChangesItem) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget)

Example 3 with UnsavedChangesTarget

use of org.rstudio.studio.client.workbench.model.UnsavedChangesTarget in project rstudio by rstudio.

the class SourceWindowManager method handleUnsavedChangesBeforeExit.

public void handleUnsavedChangesBeforeExit(ArrayList<UnsavedChangesTarget> targets, Command onCompleted) {
    // accumulate the unsaved change targets that represent satellite windows
    final JsArray<UnsavedChangesItem> items = JsArray.createArray().cast();
    for (UnsavedChangesTarget target : targets) {
        if (target instanceof UnsavedChangesItem) {
            items.push((UnsavedChangesItem) target);
        }
    }
    // let each window have a crack at saving the targets (the windows will
    // discard any targets they don't own)
    doForAllSourceWindows(new SourceWindowCommand() {

        @Override
        public void execute(String windowId, WindowEx window, Command continuation) {
            handleUnsavedChangesBeforeExit(window, items, continuation);
        }
    }, onCompleted);
}
Also used : UnsavedChangesItem(org.rstudio.studio.client.workbench.model.UnsavedChangesItem) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) Command(com.google.gwt.user.client.Command) JsArrayString(com.google.gwt.core.client.JsArrayString) WindowEx(org.rstudio.core.client.dom.WindowEx)

Example 4 with UnsavedChangesTarget

use of org.rstudio.studio.client.workbench.model.UnsavedChangesTarget 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 5 with UnsavedChangesTarget

use of org.rstudio.studio.client.workbench.model.UnsavedChangesTarget in project rstudio by rstudio.

the class UnsavedChangesDialog method addIconColumn.

private Column<UnsavedChangesTarget, ImageResource> addIconColumn() {
    Column<UnsavedChangesTarget, ImageResource> iconColumn = new Column<UnsavedChangesTarget, ImageResource>(new ImageResourceCell()) {

        @Override
        public ImageResource getValue(UnsavedChangesTarget object) {
            return object.getIcon();
        }
    };
    targetsCellTable_.addColumn(iconColumn);
    targetsCellTable_.setColumnWidth(iconColumn, 20, Unit.PX);
    return iconColumn;
}
Also used : ImageResource(com.google.gwt.resources.client.ImageResource) IdentityColumn(com.google.gwt.user.cellview.client.IdentityColumn) Column(com.google.gwt.user.cellview.client.Column) UnsavedChangesTarget(org.rstudio.studio.client.workbench.model.UnsavedChangesTarget) ImageResourceCell(com.google.gwt.cell.client.ImageResourceCell)

Aggregations

UnsavedChangesTarget (org.rstudio.studio.client.workbench.model.UnsavedChangesTarget)9 Command (com.google.gwt.user.client.Command)4 UnsavedChangesItem (org.rstudio.studio.client.workbench.model.UnsavedChangesItem)3 Column (com.google.gwt.user.cellview.client.Column)2 IdentityColumn (com.google.gwt.user.cellview.client.IdentityColumn)2 ArrayList (java.util.ArrayList)2 Operation (org.rstudio.core.client.widget.Operation)2 UnsavedChangesDialog (org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog)2 Result (org.rstudio.studio.client.workbench.ui.unsaved.UnsavedChangesDialog.Result)2 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)1 ImageResourceCell (com.google.gwt.cell.client.ImageResourceCell)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 Scheduler (com.google.gwt.core.client.Scheduler)1 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 CheckBox (com.google.gwt.user.client.ui.CheckBox)1 Label (com.google.gwt.user.client.ui.Label)1 ScrollPanel (com.google.gwt.user.client.ui.ScrollPanel)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1