def set_editor(self, editor):
        """Set the Editor (UI component) associated with this object."""
        self.__editor = editor
        # If we have an editor, let's include the checkers:
        self.include_checkers(self.language())
        content = ''
        if not self._nfile.is_new_file:
            content = self._nfile.read()
            self._nfile.start_watching()
            self.__editor.text = content
            self.__editor.document().setModified(False)
            # self.create_swap_file()
            encoding = file_manager.get_file_encoding(content)
            self.__editor.encoding = encoding
            if not self.ignore_checkers:
                self.run_checkers(content)
            else:
                self.ignore_checkers = False

        # New file then try to add a coding line
        if not content:
            helpers.insert_coding_line(self.__editor)

        self.fileLoaded.emit(self)
        self.fileLoaded[str].emit(self.file_path)
Beispiel #2
0
    def __open_file(self,
                    fileName='',
                    cursorPosition=-1,
                    tabIndex=None,
                    positionIsLineNumber=False,
                    notStart=True):
        try:
            if not self.is_open(fileName):
                self.actualTab.notOpening = False
                content = file_manager.read_file_content(fileName)
                editorWidget = self.add_editor(fileName,
                                               tabIndex=tabIndex,
                                               use_open_highlight=True)
                editorWidget.highlighter.set_open_visible_area(
                    positionIsLineNumber, cursorPosition)

                #Add content
                #we HAVE to add the editor's content before set the ID
                #because of the minimap logic
                editorWidget.setPlainText(content)
                editorWidget.ID = fileName
                editorWidget.async_highlight()
                encoding = file_manager.get_file_encoding(content)
                editorWidget.encoding = encoding
                if cursorPosition == -1:
                    cursorPosition = 0
                if not positionIsLineNumber:
                    editorWidget.set_cursor_position(cursorPosition)
                else:
                    editorWidget.go_to_line(cursorPosition)
                self.add_standalone_watcher(editorWidget.ID, notStart)

                #New file then try to add a coding line
                if not content:
                    helpers.insert_coding_line(editorWidget)
                    self.save_file(editorWidget=editorWidget)

                if not editorWidget.has_write_permission():
                    fileName += self.tr(" (Read-Only)")
                    index = self.actualTab.currentIndex()
                    self.actualTab.setTabText(index, fileName)

            else:
                self.move_to_open(fileName)
                editorWidget = self.get_actual_editor()
                if editorWidget and notStart and cursorPosition != -1:
                    if positionIsLineNumber:
                        editorWidget.go_to_line(cursorPosition)
                    else:
                        editorWidget.set_cursor_position(cursorPosition)
            self.emit(SIGNAL("currentTabChanged(QString)"), fileName)
        except file_manager.NinjaIOException as reason:
            if notStart:
                QMessageBox.information(self,
                                        self.tr("The file couldn't be open"),
                                        str(reason))
        except Exception as reason:
            logger.error('open_file: %s', reason)
        self.actualTab.notOpening = True
    def __open_file(self, fileName='', cursorPosition=-1,
                    tabIndex=None, positionIsLineNumber=False, notStart=True):
        try:
            if not self.is_open(fileName):
                print("can not opened!")
                self.actualTab.notOpening = False
                content = file_manager.read_file_content(fileName)
                editorWidget = self.add_editor(fileName, tabIndex=tabIndex,
                    use_open_highlight=True)

                #Add content
                #we HAVE to add the editor's content before set the ID
                #because of the minimap logic
                editorWidget.setPlainText(content)
                editorWidget.ID = fileName
                editorWidget.async_highlight()
                encoding = file_manager.get_file_encoding(content)
                editorWidget.encoding = encoding
                if cursorPosition == -1:
                    cursorPosition = 0
                if not positionIsLineNumber:
                    editorWidget.set_cursor_position(cursorPosition)
                else:
                    editorWidget.go_to_line(cursorPosition)
                self.add_standalone_watcher(editorWidget.ID, notStart)

                #New file then try to add a coding line
                if not content:
                    helpers.insert_coding_line(editorWidget)
                    self.save_file(editorWidget=editorWidget)

                if not editorWidget.has_write_permission():
                    fileName += _translate("_s_MainContainer", " (Read-Only)")
                    index = self.actualTab.currentIndex()
                    self.actualTab.setTabText(index, fileName)

            else:
                print("has opened")
                self.move_to_open(fileName)
                editorWidget = self.get_actual_editor()
                if editorWidget and notStart and cursorPosition != -1:
                    if positionIsLineNumber:
                        editorWidget.go_to_line(cursorPosition)
                    else:
                        editorWidget.set_cursor_position(cursorPosition)
            print("file.FileName::", fileName)
            self.currentTabChanged.emit(fileName)
        except file_manager.NinjaIOException as reason:
            if notStart:
                QMessageBox.information(self,
                    _translate("_s_MainContainer", "The file couldn't be open"), str(reason))
        except Exception as reason:
            logger.error('open_file: %s', reason)
        self.actualTab.notOpening = True
Beispiel #4
0
    def set_editor(self, editor):
        """Set the Editor (UI component) associated with this object."""
        self.__editor = editor
        content = self._nfile.read()
        self.__editor.setPlainText(content)
        encoding = file_manager.get_file_encoding(content)
        self.__editor.encoding = encoding

        #New file then try to add a coding line
        if not content:
            helpers.insert_coding_line(self.__editor)
        # If we have an editor, let's include the checkers:
        self.include_checkers()
Beispiel #5
0
    def set_editor(self, editor):
        """Set the Editor (UI component) associated with this object."""
        self.__editor = editor
        content = self._nfile.read()
        self.__editor.setPlainText(content)
        encoding = file_manager.get_file_encoding(content)
        self.__editor.encoding = encoding

        #New file then try to add a coding line
        if not content:
            helpers.insert_coding_line(self.__editor)
        # If we have an editor, let's include the checkers:
        self.include_checkers()
Beispiel #6
0
    def __open_file(self, fileName='', cursorPosition=-1,
                    tabIndex=None, positionIsLineNumber=False, notStart=True):
        try:
            if not self.is_open(fileName):
                self.actualTab.notOpening = False
                content = file_manager.read_file_content(fileName)
                editorWidget = self.add_editor(fileName, tabIndex=tabIndex,
                    use_open_highlight=True)
                editorWidget.highlighter.set_open_visible_area(
                    positionIsLineNumber, cursorPosition)

                #Add content
                editorWidget.ID = fileName
                editorWidget.setPlainText(content)
                editorWidget.async_highlight()
                encoding = file_manager.get_file_encoding(content)
                editorWidget.encoding = encoding
                if cursorPosition == -1:
                    cursorPosition = 0
                if not positionIsLineNumber:
                    editorWidget.set_cursor_position(cursorPosition)
                else:
                    editorWidget.go_to_line(cursorPosition)
                self.add_standalone_watcher(editorWidget.ID, notStart)

                #New file then try to add a coding line
                if not content:
                    helpers.insert_coding_line(editorWidget)
                    self.save_file(editorWidget=editorWidget)

                if not editorWidget.has_write_permission():
                    fileName += self.tr(" (Read-Only)")
                    index = self.actualTab.currentIndex()
                    self.actualTab.setTabText(index, fileName)

            else:
                self.move_to_open(fileName)
                editorWidget = self.get_actual_editor()
                if editorWidget and notStart and cursorPosition != -1:
                    if positionIsLineNumber:
                        editorWidget.go_to_line(cursorPosition)
                    else:
                        editorWidget.set_cursor_position(cursorPosition)
            self.emit(SIGNAL("currentTabChanged(QString)"), fileName)
        except file_manager.NinjaIOException as reason:
            if not notStart:
                QMessageBox.information(self,
                    self.tr("The file couldn't be open"), reason)
        except Exception as reason:
            logger.error('open_file: %s', reason)
        self.actualTab.notOpening = True
Beispiel #7
0
    def set_editor(self, editor):
        """Set the Editor (UI component) associated with this object."""
        self.__editor = editor
        # If we have an editor, let's include the checkers:
        self.include_checkers()
        content = ''
        if not self._nfile.is_new_file:
            content = self._nfile.read()
            self._nfile.start_watching()
            self.__editor.setPlainText(content)
            encoding = file_manager.get_file_encoding(content)
            self.__editor.encoding = encoding
            if not self.ignore_checkers:
                self.run_checkers(content)
            else:
                self.ignore_checkers = False

        #New file then try to add a coding line
        if not content:
            helpers.insert_coding_line(self.__editor)
Beispiel #8
0
    def set_editor(self, editor):
        """Set the Editor (UI component) associated with this object."""
        self.__editor = editor
        # If we have an editor, let's include the checkers:
        self.include_checkers()
        content = ''
        if not self._nfile.is_new_file:
            content = self._nfile.read()
            self._nfile.start_watching()
            self.__editor.setPlainText(content)
            encoding = file_manager.get_file_encoding(content)
            self.__editor.encoding = encoding
            if not self.ignore_checkers:
                self.run_checkers(content)
            else:
                self.ignore_checkers = False

        #New file then try to add a coding line
        if not content:
            helpers.insert_coding_line(self.__editor)