def save_file(self, editorWidget=None): # FIXME: check how we handle this if not editorWidget: editorWidget = self.get_current_editor() if editorWidget is None: return False # Ok, we have an editor instance # Save to file only if editor really was modified if editorWidget.is_modified: try: if (editorWidget.nfile.is_new_file or not editorWidget.nfile.has_write_permission()): return self.save_file_as() self.beforeFileSaved.emit(editorWidget.file_path) if settings.REMOVE_TRAILING_SPACES: helpers.remove_trailing_spaces(editorWidget) # New line at end # FIXME: from settings helpers.insert_block_at_end(editorWidget) # Save convent editorWidget.neditable.save_content() encoding = file_manager.get_file_encoding(editorWidget.text) editorWidget.encoding = encoding self.fileSaved.emit( self.tr("File Saved: {}".format(editorWidget.file_path))) return True except Exception as reason: logger.error('save_file: %s', reason) QMessageBox.information(self, self.tr("Save Error"), self.tr("The file couldn't be saved!")) return False
def save_file(self, editorWidget=None): #FIXME: check how we handle this if not editorWidget: editorWidget = self.get_current_editor() if not editorWidget: return False try: #editorWidget.just_saved = True nfile = editorWidget.nfile if nfile.is_new_file or not nfile.has_write_permission(): return self.save_file_as() self.emit(SIGNAL("beforeFileSaved(QString)"), nfile.file_path) if settings.REMOVE_TRAILING_SPACES: helpers.remove_trailing_spaces(editorWidget) content = editorWidget.get_text() nfile.save(content) #file_manager.store_file_content( #fileName, content, addExtension=False) encoding = file_manager.get_file_encoding(content) editorWidget.encoding = encoding self.emit(SIGNAL("fileSaved(QString)"), (self.tr("File Saved: %s") % nfile.file_path)) editorWidget._file_saved() return True except Exception as reason: #editorWidget.just_saved = False logger.error('save_file: %s', reason) QMessageBox.information(self, self.tr("Save Error"), self.tr("The file couldn't be saved!")) return False
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)
def save_file(self, editorWidget=None): #FIXME: check how we handle this if not editorWidget: editorWidget = self.get_current_editor() if not editorWidget: return False try: #editorWidget.just_saved = True if (editorWidget.nfile.is_new_file or not editorWidget.nfile.has_write_permission()): return self.save_file_as() self.emit(SIGNAL("beforeFileSaved(QString)"), editorWidget.file_path) if settings.REMOVE_TRAILING_SPACES: helpers.remove_trailing_spaces(editorWidget) editorWidget.neditable.save_content() #file_manager.store_file_content( #fileName, content, addExtension=False) encoding = file_manager.get_file_encoding(editorWidget.text()) editorWidget.encoding = encoding self.emit(SIGNAL("fileSaved(QString)"), (self.tr("File Saved: %s") % editorWidget.file_path)) return True except Exception as reason: logger.error('save_file: %s', reason) QMessageBox.information(self, self.tr("Save Error"), self.tr("The file couldn't be saved!")) return False
def reload_file(self): 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
def reload_file(self): if self._nfile: content = self._nfile.read() self._nfile.start_watching() self.__editor.text = content self.__editor.document().setModified(False) 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
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()
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)