def save_editor_state(self, editor, ident=None): """Save a single editor's state :param editor: The editor with state to be saved. :param ident: The identifier to use when saving editor state. It is assumed that the profile has been setup when this argument is provided; ``editor.id`` will be used when not provided. :returns: The name of the state file. """ if ident is None: raise NotImplementedError ident = editor.id self.setup_profile(editors=True) state_name = const.EDITOR_STATE.format(ident) state_file = os.path.join(self.profile_path, const.STATE_DIR, state_name) state = editor.state try: with atomicfile(state_file, encoding="utf-8") as fh: dump_yaml(state, fh) except Exception: log.error('cannot write %s\n%s\n', state_file, state, exc_info=True) return state_name
def test(c): def objcstr(value): value = ak.NSString.alloc().initWithString_(value) isinstance(value, objc.pyobjc_unicode), (type(value), value) return value def check(flag, key, serial, value=None): if flag: assert key in serial, (key, serial) if value is not None: eq_(serial[key], value) else: assert key not in serial, key proj = Project(None) recent = [objcstr("/file.txt"), objcstr("/doc.xml")] if c.recent: proj.recent.extend(Recent(p) for p in recent) if c.name: proj.name = objcstr("<name>") if c.docs: proj.editors = [MockDoc(1)] proj.expanded = c.expn serial = proj.serialize() check(False, "path", serial, proj.path) check(c.name, "name", serial, proj.name) check(c.docs, "documents", serial) check(True, "expanded", serial, c.expn) check(c.recent, "recent", serial, recent) dump_yaml(serial) # verify that it does not crash
def save_window_state(self, window, state_dir, ident): """Save a single window's state :param window: The window with state to be saved. :param state_dir: The directory in which to write the state file. :param ident: The identifier to use when saving window state. :returns: The name of the state file. """ state_name = const.EDITOR_STATE.format(ident) state_file = os.path.join(state_dir, state_name) state = window.state try: with atomicfile(state_file, encoding="utf-8") as fh: dump_yaml(state, fh) except Exception: log.error('cannot write %s\n%s\n', state_file, state, exc_info=True) return state_name
def test(c): def check(flag, key, serial, value=None): if flag: assert key in serial, key if value is not None: eq_(serial[key], value) else: assert key not in serial, key proj = Project.create() if c.path: proj.path = "<path>" if c.name: proj.name = ak.NSString.alloc().initWithString_("<name>") assert isinstance(proj.name, objc.pyobjc_unicode), type(proj.name) if c.docs: proj._documents = [MockDoc(1)] proj.expanded = c.expn serial = proj.serialize_full() check(c.path, "path", serial, proj.path) check(c.name, "name", serial, proj.name) check(c.docs, "documents", serial) check(True, "expanded", serial, c.expn) dump_yaml(serial) # verify that it does not crash
def save_editor_state(self, editor, ident=None): """Save a single editor's state :param editor: The editor with state to be saved. :param ident: The identifier to use when saving editor state. It is assumed that the profile has been setup when this argument is provided; ``editor.id`` will be used when not provided. :returns: The name of the state file. """ if ident is None: raise NotImplementedError ident = editor.id self.setup_profile(editors=True) state_name = const.EDITOR_STATE.format(ident) state_file = os.path.join( self.profile_path, const.STATE_DIR, state_name) state = editor.state try: with atomicfile(state_file, encoding="utf-8") as fh: dump_yaml(state, fh) except Exception: log.error('cannot write %s\n%s\n', state_file, state, exc_info=True) return state_name