Esempio n. 1
0
 def create_window(self, state=None):
     from editxt.window import Window
     if state is None:
         state_dir = os.path.join(self.profile_path, const.STATE_DIR, const.CLOSED_DIR)
         for x, path in enumerate_state_paths(state_dir, reverse=True):
             try:
                 with open(path, encoding="utf-8") as f:
                     state = load_yaml(f)
             except Exception:
                 log.warn("cannot load editor state: %s", path)
                 continue
             try:
                 os.remove(path)
             except Exception:
                 log.exception('cannot remove %s', path)
             break
     window = Window(self, state)
     self.windows.append(window)
     window.show(self)
     return window
Esempio n. 2
0
 def _setup(self, app):
     from editxt.editor import Editor
     from editxt.project import Project
     from editxt.window import Window
     state = self.init_state
     docs_by_name = {}
     items = self.items
     if state is None:
         return
     window = project = None
     for i, state_item in enumerate(self.split(state)):
         match = self.editor_re.match(state_item)
         assert match, "unknown state item: {}".format(state_item)
         collapsed, item, name, current = match.groups()
         has_ext_name = name and ":" in name
         assert item == "project" or (not collapsed and not has_ext_name), \
             "unknown state item: {}".format(state_item)
         if not name:
             name = "<{}>".format(i)
         if item == "window" or window is None:
             window = Window(app)
             project = None
             app.windows.append(window)
             if item == "window":
                 items[window] = "window" + name
                 continue
             else:
                 items[window] = "window<{}>".format(i)
         if item == "project" or project is None:
             project = Project(window)
             if has_ext_name:
                 name_offset = name.index(":") + 1
                 project.name = name[1:name_offset - 1]
             else:
                 name_offset = 1
             if "/" in name:
                 project.path = self.temp_path(name[name_offset:-1])
             if collapsed:
                 project.expanded = False
             window.projects.append(project)
             if item == "project":
                 items[project] = "project" + name
                 if current:
                     if not window.selected_items:
                         window.current_editor = project
                     else:
                         window.selected_items.append(project)
                 continue
             else:
                 items[project] = "project<{}>".format(i)
         document = docs_by_name.get(name)
         if document is None:
             document = self.document_with_path(name[1:-1])
             docs_by_name[name] = document
         editor = Editor(project, document=document)
         items[editor] = "editor" + name
         items[document] = "document" + name
         project.editors.append(editor)
         if current:
             if not window.selected_items:
                 window.current_editor = editor
             else:
                 window.selected_items.append(editor)