Here we add tool state, this is done by tools as well As modules that restore saved state
509129
function addFrameOfReferenceSpecificToolState(
    frameOfReference,
    toolType,
    data
  ) {
    // If we don't have any tool state for this frameOfReference, add an empty object
    if (toolState.hasOwnProperty(frameOfReference) === false) {
      toolState[frameOfReference] = {};
    }

    const frameOfReferenceToolState = toolState[frameOfReference];

    // If we don't have tool state for this type of tool, add an empty object
    if (frameOfReferenceToolState.hasOwnProperty(toolType) === false) {
      frameOfReferenceToolState[toolType] = {
        data: [],
      };
    }

    const toolData = frameOfReferenceToolState[toolType];

    // Finally, add this new tool to the state
    toolData.data.push(data);
  }
462716
def update(self):
        
        # with self._update_lock:
        self._update_lock.acquire()
        self._store_expansion_state()
        self.history_tree_store.clear()
        selected_sm_m = self.model.get_selected_state_machine_model()
        if not selected_sm_m:
            return

        for execution_number, execution_history in enumerate(selected_sm_m.state_machine.execution_histories):
            if len(execution_history) > 0:
                first_history_item = execution_history[0]
                # the next lines filter out the StateMachineStartItem, which is not intended to
                # be displayed, but merely as convenient entry point in the saved log file
                if isinstance(first_history_item, StateMachineStartItem):
                    if len(execution_history) > 1:
                        first_history_item = execution_history[1]
                        tree_item = self.history_tree_store.insert_after(
                            None,
                            None,
                            (first_history_item.state_reference.name + " - Run " + str(execution_number + 1),
                             first_history_item, self.TOOL_TIP_TEXT))
                        self.insert_execution_history(tree_item, execution_history[1:], is_root=True)
                    else:
                        pass  # there was only the Start item in the history
                else:
                    tree_item = self.history_tree_store.insert_after(
                        None,
                        None,
                        (first_history_item.state_reference.name + " - Run " + str(execution_number + 1),
                         first_history_item, self.TOOL_TIP_TEXT))
                    self.insert_execution_history(tree_item, execution_history, is_root=True)

        self._restore_expansion_state()
        self._update_lock.release()
1025436
public void saveState (Path dir, State state) throws IOException {
    saveState(this.fs, dir, state);
  }
1336728
function restore() {
    if (isOriginal) return;
    else isOriginal = true;
    ['log', 'debug', 'info', 'warn', 'error'].forEach((item) => {
        console[item] = originalConsoleFunctions[item];
    });
}
535209
def restore_state(self):
        
        settings = QSettings()
        try:
            last_path = settings.value('directory', type=str)
        except TypeError:
            last_path = ''
        self.output_directory.setText(last_path)
1045598
public void addState() {
        DiffHistoryDataState nextState = new DiffHistoryDataState(stateEngine, typeDiffInstructions);

        if(currentDataState != null)
            newHistoricalState(currentDataState, nextState);

        currentDataState = nextState;
    }
960039
def on_state_changed(self, state):
        
        super(GoToDefinitionMode, self).on_state_changed(state)
        if state:
            self.editor.mouse_moved.connect(self._on_mouse_moved)
            self.editor.mouse_released.connect(self._on_mouse_released)
            self.editor.add_action(self.action_goto, sub_menu='COBOL')
            self.editor.mouse_double_clicked.connect(
                self._timer.cancel_requests)
        else:
            self.editor.mouse_moved.disconnect(self._on_mouse_moved)
            self.editor.mouse_released.disconnect(self._on_mouse_released)
            self.editor.remove_action(self.action_goto, sub_menu='Python')
            self.editor.mouse_double_clicked.disconnect(
                self._timer.cancel_requests)
1035224
function restore_allstate(res)
{
    if (gli_windowlist || gli_streamlist || gli_filereflist)
        throw('restore_allstate: glkapi module has already been launched');

    /* We build and register all the bare objects first. (In reverse
       order so that the linked lists come out right way around.) */

    for (var ix=res.windows.length-1; ix>=0; ix--) {
        var obj = res.windows[ix];
        var win = {
            type: obj.type, rock: obj.rock, disprock: obj.disprock,
            style: obj.style, hyperlink: obj.hyperlink
        };
        GiDispa.class_register('window', win, win.disprock);

        win.prev = null;
        win.next = gli_windowlist;
        gli_windowlist = win;
        if (win.next)
            win.next.prev = win;
    }

    for (var ix=res.streams.length-1; ix>=0; ix--) {
        var obj = res.streams[ix];
        var str = {
            type: obj.type, rock: obj.rock, disprock: obj.disprock,
            unicode: obj.unicode, isbinary: obj.isbinary,
            readcount: obj.readcount, writecount: obj.writecount,
            readable: obj.readable, writable: obj.writable,
            streaming: obj.streaming
        };
        GiDispa.class_register('stream', str, str.disprock);

        str.prev = null;
        str.next = gli_streamlist;
        gli_streamlist = str;
        if (str.next)
            str.next.prev = str;
    }

    for (var ix=res.filerefs.length-1; ix>=0; ix--) {
        var obj = res.filerefs[ix];
        var fref = {
            type: obj.type, rock: obj.rock, disprock: obj.disprock,
            filename: obj.filename, textmode: obj.textmode,
            filetype: obj.filetype, filetypename: obj.filetypename
        };
        GiDispa.class_register('fileref', fref, fref.disprock);

        fref.prev = null;
        fref.next = gli_filereflist;
        gli_filereflist = fref;
        if (fref.next)
            fref.next.prev = fref;
    }

    /* ...Now we fill in the cross-references. */

    for (var ix=0; ix<res.windows.length; ix++) {
        var obj = res.windows[ix];
        var win = GiDispa.class_obj_from_id('window', obj.disprock);

        win.parent = GiDispa.class_obj_from_id('window', obj.parent);
        win.str = GiDispa.class_obj_from_id('stream', obj.str);
        win.echostr = GiDispa.class_obj_from_id('stream', obj.echostr);

        win.bbox = { 
            left: obj.bbox.left, right: obj.bbox.right,
            top: obj.bbox.top, bottom: obj.bbox.bottom 
        };

        win.input_generation = null;
        if (obj.char_request || obj.line_request)
            win.input_generation = event_generation;
        win.linebuf = null;
        if (obj.linebuf !== undefined) {
            // should clone that object
            win.linebuf = obj.linebuf.arr;
            GiDispa.retain_array(win.linebuf, obj.linebuf);
        }
        win.char_request = obj.char_request;
        win.line_request = obj.line_request;
        win.char_request_uni = obj.char_request_uni;
        win.line_request_uni = obj.line_request_uni;
        win.hyperlink_request = obj.hyperlink_request;
        win.mouse_request = obj.mouse_request;
        win.echo_line_input = obj.echo_line_input;
        win.request_echo_line_input = obj.request_echo_line_input;
        win.line_input_terminators = obj.line_input_terminators.slice(0);
        //### should have a request_line_input_terminators as well

        switch (win.type) {
        case Const.wintype_TextBuffer:
            win.accum = [];
            win.accumstyle = win.style;
            win.accumhyperlink = win.hyperlink;
            win.content = obj.reserve.slice(0);
            win.clearcontent = false;
            win.reserve = [];
            break;
        case Const.wintype_TextGrid:
            win.gridwidth = obj.gridwidth;
            win.gridheight = obj.gridheight;
            win.lines = [];
            for (var jx=0; jx<obj.lines.length; jx++) {
                var ln = obj.lines[jx];
                win.lines.push({
                        dirty: true,
                        chars: ln.chars.slice(0),
                        styles: ln.styles.slice(0),
                        hyperlinks: ln.hyperlinks.slice(0)
                    });
            }
            win.cursorx = obj.cursorx;
            win.cursory = obj.cursory;
            break;
        case Const.wintype_Graphics:
            win.graphwidth = obj.graphwidth;
            win.graphheight = obj.graphheight;
            win.content = obj.reserve.slice(0);
            win.reserve = [];
            break;
        case Const.wintype_Pair:
            win.pair_dir = obj.pair_dir;
            win.pair_division = obj.pair_division;
            win.pair_key = GiDispa.class_obj_from_id('window', obj.pair_key);
            win.pair_keydamage = false;
            win.pair_size = obj.pair_size;
            win.pair_hasborder = obj.pair_hasborder;
            win.pair_vertical = obj.pair_vertical;
            win.pair_backward = obj.pair_backward;
            win.child1 = GiDispa.class_obj_from_id('window', obj.child1);
            win.child2 = GiDispa.class_obj_from_id('window', obj.child2);
            break;
        }
    }

    for (var ix=0; ix<res.streams.length; ix++) {
        var obj = res.streams[ix];
        var str = GiDispa.class_obj_from_id('stream', obj.disprock);

        /* Defaults first... */
        str.win = null;
        str.ref = null;
        str.file = null;

        str.buf = null;
        str.bufpos = 0;
        str.buflen = 0;
        str.bufeof = 0;
        str.timer_id = null;
        str.flush_func = null;
        str.fstream = null;

        switch (str.type) {

        case strtype_Window:
            str.win = GiDispa.class_obj_from_id('window', obj.win);
            break;

        case strtype_Memory:
            if (obj.buf !== undefined) {
                // should clone that object
                str.buf = obj.buf.arr;
                GiDispa.retain_array(str.buf, obj.buf);
            }
            str.buflen = obj.buflen;
            str.bufpos = obj.bufpos;
            str.bufeof = obj.bufeof;
            break;

        case strtype_Resource:
            str.resfilenum = obj.resfilenum;
            var el = GiLoad.find_data_chunk(str.resfilenum);
            if (el) {
                str.buf = el.data;
            }
            str.buflen = obj.buflen;
            str.bufpos = obj.bufpos;
            str.bufeof = obj.bufeof;
            break;

        case strtype_File:
            str.origfmode = obj.origfmode;
            if (!Dialog.streaming) {
                str.ref = obj.ref;
                str.buflen = obj.buflen;
                str.bufpos = obj.bufpos;
                str.bufeof = obj.bufeof;

                var content = Dialog.file_read(str.ref);
                if (content == null) {
                    /* The file was somehow deleted. Create an empty
                       file (even in read mode). */
                    content = [];
                    Dialog.file_write(str.ref, '', true);
                }
                str.buf = content;

                /* If the file has been shortened, we might have to
                   trim bufeof to fit within it. The game might see
                   the file pos mysteriously move; sorry. */
                str.bufeof = content.length;
                if (str.bufpos > str.bufeof)
                    str.bufpos = str.bufeof;
            }
            else {
                str.ref = obj.ref;
                str.fstream = Dialog.file_fopen(str.origfmode, str.ref);
                if (!str.fstream) {
                    /* This is the panic case. We can't reopen the stream,
                       but the game expects an open stream! We'll just
                       have to open a temporary file; the user will never
                       get their data, but at least the game won't crash.
                       (Better policy would be to prompt the user for
                       a new file location...) */
                    var tempref = Dialog.file_construct_temp_ref(str.ref.usage);
                    str.fstream = Dialog.file_fopen(str.origfmode, tempref);
                    if (!str.fstream)
                        throw('restore_allstate: could not reopen even a temp stream for: ' + str.ref.filename);
                }

                if (str.origfmode != Const.filemode_WriteAppend) {
                    /* Jump to the last known filepos. */
                    str.fstream.fseek(obj.filepos, Const.seekmode_Start);
                }

                str.buffer4 = new str.fstream.BufferClass(4);
            }
            break;

        }
    }

    for (var ix=0; ix<res.filerefs.length; ix++) {
        var obj = res.filerefs[ix];
        var fref = GiDispa.class_obj_from_id('fileref', obj.disprock);

        fref.ref = obj.ref; // should deep clone
    }

    gli_rootwin = GiDispa.class_obj_from_id('window', res.rootwin);
    gli_currentstr = GiDispa.class_obj_from_id('stream', res.currentstr);

    if (res.timer_interval)
        glk_request_timer_events(res.timer_interval);

    /* Stash this for the next (first) GlkOte.update call. */
    gli_autorestore_glkstate = res.glkote;
}
1068577
function () {
			/** A stateful object to hold items till they are added to the compiler */
			var pkg = {
				exec          : [],
				aliases       : {},
				dependAliases : [],
				ignore        : [],
				publish       : [],
				externals     : [],
				modules       : [],
				noParse       : []
			};

			// process modules to ignore
			var ignore = task.data.ignore;
			if ( !sys.isEmpty( ignore ) && !sys.isEmpty( ignore.src ) ) {
				grunt.verbose.writeln( "Adding ignores" );

				pkg.ignore = sys.map( grunt.file.expand( ignore, ignore.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// process modules that won't be parsed
			var noParse = task.data.noParse;
			if ( !sys.isEmpty( noParse ) && !sys.isEmpty( noParse.src ) ) {
				grunt.verbose.writeln( "Adding ignores" );

				pkg.noParse = sys.map( grunt.file.expand( noParse, noParse.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// process executable modules
			var exec = task.data.exec;
			if ( !sys.isEmpty( exec ) && !sys.isEmpty( exec.src ) ) {
				grunt.verbose.writeln( "Adding executable modules" );

				pkg.exec = sys.map( grunt.file.expand( exec, exec.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// process module entries
			var modules = task.data.modules;
			if ( !sys.isEmpty( modules ) && !sys.isEmpty( modules.src ) ) {
				grunt.verbose.writeln( "Adding modules" );

				pkg.modules = sys.map( grunt.file.expand( modules, modules.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// process modules to be published
			var publish = task.data.publish;
			if ( !sys.isEmpty( publish ) && !sys.isEmpty( publish.src ) ) {
				grunt.verbose.writeln( "Adding published modules" );

				pkg.publish = sys.map( grunt.file.expand( publish, publish.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// process externals entries
			var externals = task.data.externals;
			if ( !sys.isEmpty( externals ) && !sys.isEmpty( externals.src ) ) {
				grunt.log.writeln( "Adding external modules" );

				pkg.externals = sys.map( grunt.file.expand( externals, externals.src ), function ( item ) {
					return resolvePath( item );
				} );
			}

			// get all task aliases
			sys.extend( pkg.aliases, getTaskAliases( task.target, options ) );
			if ( !sys.isEmpty( task.data.depends ) ) {
				sys.each( task.data.depends, function ( depends ) {
					var dependents = getTaskAliases( depends, options );

					sys.each( dependents, function ( val, key ) {
						pkg.dependAliases.push( key );
					} );
				} );
			}

			// get dependencies definitions and add them to this as external
			if ( options.autoExternals && !sys.isEmpty( task.data.depends ) ) {
				sys.each( task.data.depends, function ( depends ) {
					pkg.externals = pkg.externals.concat( getTaskSources( depends ) );
				} );
			}

			return pkg;
		}
265178
public void updateState() {
        // Applying zoom patch (needed in case if image size is changed)
        stateController.applyZoomPatch(state);
        stateController.applyZoomPatch(prevState);
        stateController.applyZoomPatch(stateStart);
        stateController.applyZoomPatch(stateEnd);
        exitController.applyZoomPatch();

        boolean reset = stateController.updateState(state);
        if (reset) {
            notifyStateReset();
        } else {
            notifyStateUpdated();
        }
    }
1201106
def save_initial_state(self):
        """"""
        paths = self.paths
        self.initial_widget = self.get_widget()
        self.initial_cursors = {}

        for i, editor in enumerate(self.widgets):
            if editor is self.initial_widget:
                self.initial_path = paths[i]
            # This try is needed to make the fileswitcher work with 
            # plugins that does not have a textCursor.
            try:
                self.initial_cursors[paths[i]] = editor.textCursor()
            except AttributeError:
                pass
713581
def save_state(state, output_dir, keep=False):
  """"""
  params_file = os.path.join(output_dir, "model.pkl")
  with gfile.GFile(params_file, "wb") as f:
    pickle.dump((state.params, state.step, state.history), f)
  if keep:
    params_file = os.path.join(output_dir, "model_{}.pkl".format(state.step))
    with gfile.GFile(params_file, "wb") as f:
      pickle.dump((state.params, state.step, state.history), f)
  log("Model saved to %s" % params_file, stdout=False)
1108948
def _release_save_states(self):
        """"""

        self.saving = False
        self.grid.Enable()
        wx.EndBusyCursor()

        # Mark content as unchanged
        try:
            post_command_event(self.main_window, self.ContentChangedMsg)
        except TypeError:
            # The main window does not exist any more
            pass
392707
def restore_expanded_state(self):
        """"""
        if self.__expanded_state is not None:
            # In the old project explorer, the expanded state was a dictionnary:
            if isinstance(self.__expanded_state, list):
                self.fsmodel.directoryLoaded.connect(
                                                  self.restore_directory_state)
                self.fsmodel.directoryLoaded.connect(
                                                self.follow_directories_loaded)
69049
def _set_save_states(self):
        """"""

        wx.BeginBusyCursor()
        self.saving = True
        self.grid.Disable()
666130
def _interfaces_added(self, object_path, interfaces_and_properties):
        """"""
        added = object_path not in self._objects
        self._objects.setdefault(object_path, {})
        old_state = copy(self._objects[object_path])
        self._objects[object_path].update(interfaces_and_properties)
        new_state = self._objects[object_path]
        if added:
            kind = object_kind(object_path)
            if kind in ('device', 'drive'):
                self.trigger('device_added', self[object_path])

        if Interface['Block'] in interfaces_and_properties:
            slave = self[object_path].luks_cleartext_slave
            if slave:
                if not self._has_job(slave.object_path, 'device_unlocked'):
                    self.trigger('device_unlocked', slave)

        if not added:
            self.trigger('device_changed',
                         self.get(object_path, old_state),
                         self.get(object_path, new_state))
684805
public void restoreTransientState(FacesContext context, Object state)
    {
        boolean forceCreate = (state != null);
        TransientStateHelper helper = getTransientStateHelper(forceCreate);

        if (helper != null) {
            helper.restoreTransientState(context, state);
        }
    }