예제 #1
0
    def save_file(self, editorWidget=None):
        if not editorWidget:
            editorWidget = self.get_actual_editor()
        if not editorWidget:
            return False
        try:
            if editorWidget.newDocument or \
            not file_manager.has_write_permission(editorWidget.ID):
                return self.save_file_as()

            fileName = editorWidget.ID
            self.emit(SIGNAL("beforeFileSaved(QString)"), fileName)
            if settings.REMOVE_TRAILING_SPACES:
                helpers.remove_trailing_spaces(editorWidget)
            content = editorWidget.get_text()
            file_manager.store_file_content(
                fileName, content, addExtension=False)
            editorWidget.ID = fileName
            encoding = file_manager._search_coding_line(content)
            editorWidget.encoding = encoding
            self.emit(SIGNAL("fileSaved(QString)"),
                self.tr("File Saved: %1").arg(fileName))
            editorWidget._file_saved()
            return True
        except Exception, reason:
            logger.error('save_file: %s', reason)
            QMessageBox.information(self, self.tr("Save Error"),
                self.tr("The file couldn't be saved!"))
예제 #2
0
    def save_file(self, editorWidget=None):
        if not editorWidget:
            editorWidget = self.get_actual_editor()
        if not editorWidget:
            return False
        try:
            if editorWidget.newDocument or \
            not file_manager.has_write_permission(editorWidget.ID):
                return self.save_file_as()

            fileName = editorWidget.ID
            self.emit(SIGNAL("beforeFileSaved(QString)"), fileName)
            if settings.REMOVE_TRAILING_SPACES:
                helpers.remove_trailing_spaces(editorWidget)
            content = editorWidget.get_text()
            file_manager.store_file_content(
                fileName, content, addExtension=False)
            editorWidget.ID = fileName
            encoding = file_manager._search_coding_line(content)
            editorWidget.encoding = encoding
            self.emit(SIGNAL("fileSaved(QString)"),
                self.tr("File Saved: %1").arg(fileName))
            editorWidget._file_saved()
            return True
        except Exception, reason:
            logger.error('save_file: %s', reason)
            QMessageBox.information(self, self.tr("Save Error"),
                self.tr("The file couldn't be saved!"))
예제 #3
0
    def __open_file(self, fileName='', cursorPosition=0,\
                    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,
                    content=content)
                editorWidget.ID = fileName
                encoding = file_manager._search_coding_line(content)
                editorWidget.encoding = encoding
                if not positionIsLineNumber:
                    editorWidget.set_cursor_position(cursorPosition)
                else:
                    editorWidget.go_to_line(cursorPosition)

                if not editorWidget.has_write_permission():
                    fileName += unicode(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:
                    if positionIsLineNumber:
                        editorWidget.go_to_line(cursorPosition)
                    else:
                        editorWidget.set_cursor_position(cursorPosition)
            self.emit(SIGNAL("currentTabChanged(QString)"), fileName)
        except file_manager.NinjaIOException, reason:
            if not notStart:
                QMessageBox.information(self,
                    self.tr("The file couldn't be open"),
                    unicode(reason))
예제 #4
0
    def __open_file(self, fileName='', cursorPosition=0,\
                    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,
                    content=content)
                editorWidget.ID = fileName
                encoding = file_manager._search_coding_line(content)
                editorWidget.encoding = encoding
                if not positionIsLineNumber:
                    editorWidget.set_cursor_position(cursorPosition)
                else:
                    editorWidget.go_to_line(cursorPosition)

                if not editorWidget.has_write_permission():
                    fileName += unicode(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:
                    if positionIsLineNumber:
                        editorWidget.go_to_line(cursorPosition)
                    else:
                        editorWidget.set_cursor_position(cursorPosition)
            self.emit(SIGNAL("currentTabChanged(QString)"), fileName)
        except file_manager.NinjaIOException, reason:
            if not notStart:
                QMessageBox.information(self,
                    self.tr("The file couldn't be open"),
                    unicode(reason))