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;
}
};
}
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());
}
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_;
}
};
}
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);
}
Aggregations