Search in sources :

Example 1 with ClientInitState

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

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

the class Shell method sessionInit.

private void sessionInit(Session session) {
    SessionInfo sessionInfo = session.getSessionInfo();
    ClientInitState clientState = sessionInfo.getClientState();
    new StringStateValue(GROUP_CONSOLE, STATE_INPUT, ClientState.TEMPORARY, clientState) {

        @Override
        protected void onInit(String value) {
            initialInput_ = value;
        }

        @Override
        protected String getValue() {
            return view_.getInputEditorDisplay().getText();
        }
    };
    JsArrayString history = sessionInfo.getConsoleHistory();
    if (history != null)
        setHistory(history);
    RpcObjectList<ConsoleAction> actions = sessionInfo.getConsoleActions();
    if (actions != null) {
        view_.playbackActions(actions);
    }
    if (sessionInfo.getResumed()) {
    // no special UI for this (resuming session with all console
    // history and other UI state preserved deemed adequate feedback) 
    }
}
Also used : ConsoleAction(org.rstudio.studio.client.workbench.model.ConsoleAction) SessionInfo(org.rstudio.studio.client.workbench.model.SessionInfo) StringStateValue(org.rstudio.studio.client.workbench.model.helper.StringStateValue) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) ClientInitState(org.rstudio.studio.client.workbench.model.ClientInitState)

Aggregations

ClientInitState (org.rstudio.studio.client.workbench.model.ClientInitState)2 SessionInfo (org.rstudio.studio.client.workbench.model.SessionInfo)2 StringStateValue (org.rstudio.studio.client.workbench.model.helper.StringStateValue)2 JsArray (com.google.gwt.core.client.JsArray)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 FileSystemItem (org.rstudio.core.client.files.FileSystemItem)1 JsObject (org.rstudio.core.client.js.JsObject)1 ConsoleAction (org.rstudio.studio.client.workbench.model.ConsoleAction)1 JSObjectStateValue (org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue)1