예제 #1
0
파일: project.py 프로젝트: khairy/editxt
 def create_document_view(self):
     dc = ak.NSDocumentController.sharedDocumentController()
     doc, err = dc.makeUntitledDocumentOfType_error_(const.TEXT_DOCUMENT, None)
     if err:
         raise Exception(err)
     dc.addDocument_(doc)
     dv = TextDocumentView.create_with_document(doc)
     self.append_document_view(dv)
     return dv
예제 #2
0
파일: project.py 프로젝트: khairy/editxt
 def create_document_view(self):
     dc = ak.NSDocumentController.sharedDocumentController()
     doc, err = dc.makeUntitledDocumentOfType_error_(
         const.TEXT_DOCUMENT, None)
     if err:
         raise Exception(err)
     dc.addDocument_(doc)
     dv = TextDocumentView.create_with_document(doc)
     self.append_document_view(dv)
     return dv
예제 #3
0
    def open_documents_with_paths(self, paths):
        from editxt.document import TextDocumentView

        editor = self.current_editor()
        if editor is None:
            editor = self.create_editor()
        focus = None
        for path in paths:
            if os.path.isfile(path) or not os.path.exists(path):
                view = TextDocumentView.create_with_path(path)
                focus = editor.add_document_view(view)
            else:
                log.info("cannot open path: %s", path)
        if focus is not None:
            editor.current_view = focus
예제 #4
0
 def open_error_log(self, set_current=True):
     from editxt.document import TextDocumentView
     doc = errlog.document
     try:
         view = next(self.iter_views_of_document(doc))
     except StopIteration:
         editor = self.current_editor()
         if editor is None:
             editor = self.create_editor()
         view = TextDocumentView.create_with_document(doc)
         editor.add_document_view(view)
         if set_current:
             editor.current_view = view
     else:
         if set_current:
             self.set_current_document_view(view)
예제 #5
0
 def open_error_log(self, set_current=True):
     from editxt.document import TextDocumentView
     doc = errlog.document
     try:
         view = next(self.iter_views_of_document(doc))
     except StopIteration:
         editor = self.current_editor()
         if editor is None:
             editor = self.create_editor()
         view = TextDocumentView.create_with_document(doc)
         editor.add_document_view(view)
         if set_current:
             editor.current_view = view
     else:
         if set_current:
             self.set_current_document_view(view)
예제 #6
0
 def open_documents_with_paths(self, paths):
     from editxt.document import TextDocumentView
     editor = self.current_editor()
     if editor is None:
         editor = self.create_editor()
     focus = None
     views = []
     for path in paths:
         if os.path.isfile(path) or not os.path.exists(path):
             view = TextDocumentView.create_with_path(path)
             focus = editor.add_document_view(view)
             views.append(view)
         else:
             log.info("cannot open path: %s", path)
     if focus is not None:
         editor.current_view = focus
     return views
예제 #7
0
파일: project.py 프로젝트: khairy/editxt
 def create_document_view_with_state(self, state):
     dv = TextDocumentView.create_with_state(state)
     self.append_document_view(dv)
     return dv
예제 #8
0
파일: project.py 프로젝트: khairy/editxt
 def create_document_view_with_state(self, state):
     dv = TextDocumentView.create_with_state(state)
     self.append_document_view(dv)
     return dv
예제 #9
0
    def accept_dropped_items(self, items, project, index, action):
        """Insert dropped items into the document tree

        :param items: A sequence of dropped projects and/or documents.
        :param project: The parent project into which items are being dropped.
        :param index: The index in the outline view or parent project at which
            the drop occurred.
        :param action: The type of drop: None (unspecified), MOVE, or COPY.
        :returns: True if the items were accepted, otherwise False.
        """
        if project is None:
            # a new project will be created if/when needed
            if index < 0:
                proj_index = 0
            else:
                proj_index = index
            index = 0
        else:
            proj_index = len(self.projects) # insert projects at end of list
            assert isinstance(project, Project), project
            if index < 0:
                index = len(project.documents())
        accepted = False
        focus = None
        is_move = action is not const.COPY
        self.suspend_recent_updates()
        try:
            for item in items:
                accepted = True
                if isinstance(item, Project):
                    if not is_move:
                        raise NotImplementedError('cannot copy project yet')
                    editors = self.app.find_editors_with_project(item)
                    assert len(editors) < 2, editors
                    if item in self.projects:
                        editor = self
                        pindex = self.projects.index(item)
                        if pindex == proj_index:
                            continue
                        if pindex - proj_index <= 0:
                            proj_index -= 1
                    else:
                        editor = editors[0]

                    # BEGIN HACK crash on remove project with documents
                    pdocs = item.documents()
                    docs, pdocs[:] = list(pdocs), []
                    editor.projects.remove(item) # this line should be all that's necessary
                    pdocs.extend(docs)
                    # END HACK

                    self.projects.insert(proj_index, item)
                    proj_index += 1
                    focus = item
                    continue

                if project is None:
                    if isinstance(item, TextDocumentView) and is_move:
                        view = item
                        item.project.remove_document_view(view)
                    else:
                        view = TextDocumentView.create_with_document(item)
                    project = Project.create()
                    self.projects.insert(proj_index, project)
                    proj_index += 1
                    index = 0
                else:
                    if isinstance(item, TextDocumentView):
                        view, item = item, item.document
                    else:
                        view = project.document_view_for_document(item)
                    if is_move and view is not None:
                        if view.project == project:
                            vindex = project.documents().index(view)
                            if vindex in [index - 1, index]:
                                continue
                            if vindex - index <= 0:
                                index -= 1
                        view.project.remove_document_view(view)
                    else:
                        view = TextDocumentView.create_with_document(item)
                project.insert_document_view(index, view)
                focus = view
                index += 1
        finally:
            self.resume_recent_updates()
        if focus is not None:
            self.current_view = focus
        return accepted