Search in sources :

Example 1 with JSObjectStateValue

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

the class Files method initSession.

private void initSession() {
    final SessionInfo sessionInfo = session_.getSessionInfo();
    ClientInitState state = sessionInfo.getClientState();
    // make the column sort order persistent
    new JSObjectStateValue(MODULE_FILES, KEY_SORT_ORDER, ClientState.PROJECT_PERSISTENT, state, false) {

        @Override
        protected void onInit(JsObject value) {
            if (value != null)
                columnSortOrder_ = value.cast();
            else
                columnSortOrder_ = null;
            lastKnownState_ = columnSortOrder_;
            view_.setColumnSortOrder(columnSortOrder_);
        }

        @Override
        protected JsObject getValue() {
            if (columnSortOrder_ != null)
                return columnSortOrder_.cast();
            else
                return null;
        }

        @Override
        protected boolean hasChanged() {
            if (lastKnownState_ != columnSortOrder_) {
                lastKnownState_ = columnSortOrder_;
                return true;
            } else {
                return false;
            }
        }

        private JsArray<ColumnSortInfo> lastKnownState_ = null;
    };
    // navigate to previous directory (works for resumed case)
    new StringStateValue(MODULE_FILES, KEY_PATH, ClientState.PROJECT_PERSISTENT, state) {

        @Override
        protected void onInit(final String value) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                public void execute() {
                    // we don't need to initialize from client state
                    if (hasNavigatedToDirectory_)
                        return;
                    // compute start dir
                    String path = transformPathStateValue(value);
                    FileSystemItem start = path != null ? FileSystemItem.createDir(path) : FileSystemItem.createDir(sessionInfo.getInitialWorkingDir());
                    navigateToDirectory(start);
                }
            });
        }

        @Override
        protected String getValue() {
            return currentPath_.getPath();
        }

        private String transformPathStateValue(String value) {
            // if the value is null then return null
            if (value == null)
                return null;
            // only respect the value for projects
            String projectFile = session_.getSessionInfo().getActiveProjectFile();
            if (projectFile == null)
                return null;
            // ensure that the value is within the project dir (it wouldn't 
            // be if the project directory has been moved or renamed)
            String projectDirPath = FileSystemItem.createFile(projectFile).getParentPathString();
            if (value.startsWith(projectDirPath))
                return value;
            else
                return null;
        }
    };
}
Also used : JsObject(org.rstudio.core.client.js.JsObject) JsArray(com.google.gwt.core.client.JsArray) FileSystemItem(org.rstudio.core.client.files.FileSystemItem) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) StringStateValue(org.rstudio.studio.client.workbench.model.helper.StringStateValue) ClientInitState(org.rstudio.studio.client.workbench.model.ClientInitState) JSObjectStateValue(org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue)

Example 2 with JSObjectStateValue

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

the class DesktopApplicationHeader method initialize.

@Inject
public void initialize(final Commands commands, EventBus events, final Session session, ApplicationServerOperations server, Provider<DesktopHooks> pDesktopHooks, Provider<CodeSearch> pCodeSearch, Provider<UIPrefs> pUIPrefs, ErrorManager errorManager, GlobalDisplay globalDisplay, ApplicationQuit appQuit) {
    session_ = session;
    eventBus_ = events;
    pUIPrefs_ = pUIPrefs;
    globalDisplay_ = globalDisplay;
    ignoredUpdates_ = IgnoredUpdates.create();
    server_ = server;
    appQuit_ = appQuit;
    binder_.bind(commands, this);
    commands.mainMenu(new DesktopMenuCallback());
    pDesktopHooks.get();
    commands.uploadFile().remove();
    commands.exportFiles().remove();
    commands.updateCredentials().remove();
    commands.checkForUpdates().setVisible(true);
    commands.showLogFiles().setVisible(true);
    commands.diagnosticsReport().setVisible(true);
    commands.showFolder().setVisible(true);
    events.addHandler(SessionInitEvent.TYPE, new SessionInitHandler() {

        public void onSessionInit(SessionInitEvent sie) {
            final SessionInfo sessionInfo = session.getSessionInfo();
            toolbar_.completeInitialization(sessionInfo);
            new JSObjectStateValue("updates", "ignoredUpdates", ClientState.PERSISTENT, session_.getSessionInfo().getClientState(), false) {

                @Override
                protected void onInit(JsObject value) {
                    if (value != null)
                        ignoredUpdates_ = value.cast();
                }

                @Override
                protected JsObject getValue() {
                    ignoredUpdatesDirty_ = false;
                    return ignoredUpdates_.cast();
                }

                @Override
                protected boolean hasChanged() {
                    return ignoredUpdatesDirty_;
                }
            };
            Scheduler.get().scheduleFinally(new ScheduledCommand() {

                public void execute() {
                    Desktop.getFrame().onWorkbenchInitialized(sessionInfo.getScratchDir());
                    if (sessionInfo.getDisableCheckForUpdates())
                        commands.checkForUpdates().remove();
                    if (!sessionInfo.getDisableCheckForUpdates() && pUIPrefs_.get().checkForUpdates().getValue()) {
                        checkForUpdates(false);
                    }
                }
            });
        }
    });
    events.addHandler(ShowFolderEvent.TYPE, new ShowFolderHandler() {

        public void onShowFolder(ShowFolderEvent event) {
            Desktop.getFrame().showFolder(event.getPath().getPath());
        }
    });
    toolbar_ = new GlobalToolbar(commands, events, pCodeSearch);
    ThemeStyles styles = ThemeResources.INSTANCE.themeStyles();
    toolbar_.addStyleName(styles.desktopGlobalToolbar());
}
Also used : JsObject(org.rstudio.core.client.js.JsObject) SessionInitEvent(org.rstudio.studio.client.workbench.events.SessionInitEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) DesktopMenuCallback(org.rstudio.core.client.command.impl.DesktopMenuCallback) ShowFolderEvent(org.rstudio.studio.client.workbench.views.files.events.ShowFolderEvent) GlobalToolbar(org.rstudio.studio.client.application.ui.GlobalToolbar) ThemeStyles(org.rstudio.core.client.theme.res.ThemeStyles) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) SessionInitHandler(org.rstudio.studio.client.workbench.events.SessionInitHandler) JSObjectStateValue(org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue) ShowFolderHandler(org.rstudio.studio.client.workbench.views.files.events.ShowFolderHandler) Inject(com.google.inject.Inject)

Example 3 with JSObjectStateValue

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

the class BreakpointManager method onSessionInit.

// Event handlers ----------------------------------------------------------
@Override
public void onSessionInit(SessionInitEvent sie) {
    // Establish a persistent object for the breakpoints. Note that this 
    // object is read by the server on init, so the scope/name pair here 
    // needs to match the pair on the server. 
    new JSObjectStateValue("debug-breakpoints", "debugBreakpointsState", ClientState.PROJECT_PERSISTENT, session_.getSessionInfo().getClientState(), false) {

        @Override
        protected void onInit(JsObject value) {
            if (value != null) {
                BreakpointState state = value.cast();
                // restore all of the breakpoints
                JsArray<Breakpoint> breakpoints = state.getPersistedBreakpoints();
                for (int idx = 0; idx < breakpoints.length(); idx++) {
                    Breakpoint breakpoint = breakpoints.get(idx);
                    // make sure the next breakpoint we create after a restore 
                    // has a value larger than any existing breakpoint
                    currentBreakpointId_ = Math.max(currentBreakpointId_, breakpoint.getBreakpointId() + 1);
                    addBreakpoint(breakpoint);
                }
                // this initialization happens after the source windows are
                // up, so fire an event to the editor to show all known 
                // breakpoints. as new source windows are opened, they will
                // call getBreakpointsInFile to populate themselves.
                events_.fireEvent(new BreakpointsSavedEvent(breakpoints_, true));
            }
        }

        @Override
        protected JsObject getValue() {
            BreakpointState state = BreakpointState.create();
            for (Breakpoint breakpoint : breakpoints_) {
                state.addPersistedBreakpoint(breakpoint);
            }
            breakpointStateDirty_ = false;
            return state.cast();
        }

        @Override
        protected boolean hasChanged() {
            return breakpointStateDirty_;
        }
    };
}
Also used : JsObject(org.rstudio.core.client.js.JsObject) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint) BreakpointsSavedEvent(org.rstudio.studio.client.common.debugging.events.BreakpointsSavedEvent) JSObjectStateValue(org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue) BreakpointState(org.rstudio.studio.client.common.debugging.model.BreakpointState) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 4 with JSObjectStateValue

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

the class MainSplitPanel method initialize.

public void initialize(Widget left, Widget right) {
    left_ = left;
    right_ = right;
    new JSObjectStateValue(GROUP_WORKBENCH, KEY_RIGHTPANESIZE, ClientState.PERSISTENT, session_.getSessionInfo().getClientState(), false) {

        @Override
        protected void onInit(JsObject value) {
            State state = value == null ? null : (State) value.cast();
            if (state != null && state.hasSplitterPos()) {
                if (state.hasPanelWidth() && state.hasWindowWidth() && state.getWindowWidth() != Window.getClientWidth()) {
                    int delta = state.getWindowWidth() - state.getPanelWidth();
                    int offsetWidth = Window.getClientWidth() - delta;
                    double pct = (double) state.getSplitterPos() / state.getPanelWidth();
                    addEast(right_, pct * offsetWidth);
                } else {
                    addEast(right_, state.getSplitterPos());
                }
            } else {
                addEast(right_, Window.getClientWidth() * 0.45);
            }
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                public void execute() {
                    enforceBoundaries();
                }
            });
        }

        @Override
        protected JsObject getValue() {
            State state = JavaScriptObject.createObject().cast();
            state.setPanelWidth(getOffsetWidth());
            state.setWindowWidth(Window.getClientWidth());
            state.setSplitterPos(right_.getOffsetWidth());
            return state.cast();
        }

        @Override
        protected boolean hasChanged() {
            JsObject newValue = getValue();
            if (!State.equals(lastKnownValue_, (State) newValue.cast())) {
                lastKnownValue_ = newValue.cast();
                return true;
            }
            return false;
        }

        private State lastKnownValue_;
    };
    add(left);
    setWidgetMinSize(right_, 0);
}
Also used : JsObject(org.rstudio.core.client.js.JsObject) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ClientState(org.rstudio.studio.client.workbench.model.ClientState) JSObjectStateValue(org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue)

Aggregations

JsObject (org.rstudio.core.client.js.JsObject)4 JSObjectStateValue (org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue)4 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)3 SessionInfo (org.rstudio.studio.client.workbench.model.SessionInfo)2 JsArray (com.google.gwt.core.client.JsArray)1 Inject (com.google.inject.Inject)1 DesktopMenuCallback (org.rstudio.core.client.command.impl.DesktopMenuCallback)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 ThemeStyles (org.rstudio.core.client.theme.res.ThemeStyles)1 GlobalToolbar (org.rstudio.studio.client.application.ui.GlobalToolbar)1 BreakpointsSavedEvent (org.rstudio.studio.client.common.debugging.events.BreakpointsSavedEvent)1 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)1 BreakpointState (org.rstudio.studio.client.common.debugging.model.BreakpointState)1 SessionInitEvent (org.rstudio.studio.client.workbench.events.SessionInitEvent)1 SessionInitHandler (org.rstudio.studio.client.workbench.events.SessionInitHandler)1 ClientInitState (org.rstudio.studio.client.workbench.model.ClientInitState)1 ClientState (org.rstudio.studio.client.workbench.model.ClientState)1 StringStateValue (org.rstudio.studio.client.workbench.model.helper.StringStateValue)1 ShowFolderEvent (org.rstudio.studio.client.workbench.views.files.events.ShowFolderEvent)1 ShowFolderHandler (org.rstudio.studio.client.workbench.views.files.events.ShowFolderHandler)1