Search in sources :

Example 1 with BreakpointState

use of org.rstudio.studio.client.common.debugging.model.BreakpointState 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)

Aggregations

JsObject (org.rstudio.core.client.js.JsObject)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 JSObjectStateValue (org.rstudio.studio.client.workbench.model.helper.JSObjectStateValue)1