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, editor_widget=None): if editor_widget is None: # This may return None if there is not editor present editor_widget = self.get_current_editor() if editor_widget is None: return False # Ok, we have an editor instance # Save to file only if editor really was modified if editor_widget.is_modified: try: if editor_widget.nfile.is_new_file or \ not editor_widget.nfile.has_write_permission(): return self.save_file_as(editor_widget) # FIXME: beforeFileSaved.emit if settings.REMOVE_TRAILING_SPACES: helpers.remove_trailing_spaces(editor_widget) # FIXME: new line at end if settings.ADD_NEW_LINE_AT_EOF: helpers.insert_block_at_end(editor_widget) # Save content editor_widget.neditable.save_content() # FIXME: encoding # FIXME: translations self.fileSaved.emit("File Saved: %s" % editor_widget.file_path) return True except Exception as reason: logger.error("Save file error: %s" % reason) QMessageBox.information( self, "Save Error", "The file could't be saved!" ) return False