From f6a581eec31ce19b03b36b56c6db53d93965971f Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Tue, 26 Jul 2016 16:02:07 -0700 Subject: [PATCH] Fixed #74: added document saver interface and default filename extensions for Save As --- omnivore/framework/actions.py | 12 +++++++----- omnivore/framework/editor.py | 18 ++++++++++++++++-- omnivore/tasks/jumpman/jumpman_editor.py | 4 ++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/omnivore/framework/actions.py b/omnivore/framework/actions.py index fc08c6af..072f8997 100644 --- a/omnivore/framework/actions.py +++ b/omnivore/framework/actions.py @@ -12,6 +12,7 @@ from omnivore.framework.about import AboutDialog from omnivore.utils.file_guess import FileGuess +from omnivore.utils.wx.dialogs import get_file_dialog_wildcard import logging log = logging.getLogger(__name__) @@ -106,9 +107,9 @@ def perform(self, event): most_recent = os.path.dirname(fs_.getsyspath(relpath)) except fs.errors.FSError: pass - dialog = FileDialog(default_directory=most_recent, parent=event.task.window.control) + dialog = FileDialog(default_directory=most_recent, parent=event.task.window.control, title="Open File") else: - dialog = FileDialog(parent=event.task.window.control) + dialog = FileDialog(parent=event.task.window.control, title="Open File") if dialog.open() == OK: event.task.window.application.load_file(dialog.path, event.task) @@ -129,9 +130,10 @@ class SaveAsAction(EditorAction): image = ImageResource('file_save_as') def perform(self, event): - dialog = FileDialog(parent=event.task.window.control, action='save as') + + dialog = FileDialog(default_filename=self.active_editor.document.name, parent=event.task.window.control, action='save as', title="Save File As", wildcard=get_file_dialog_wildcard(self.active_editor.export_data_name, self.active_editor.export_extensions)) if dialog.open() == OK: - self.active_editor.save(dialog.path) + self.active_editor.save(dialog.path, saver=self.active_editor.encode_data) class RevertAction(EditorAction): name = 'Revert' @@ -175,7 +177,7 @@ class SaveAsPDFAction(EditorAction): enabled_name = 'printable' def perform(self, event): - dialog = FileDialog(parent=event.task.window.control, action='save as') + dialog = FileDialog(parent=event.task.window.control, action='save as', title="Save PDF") if dialog.open() == OK: self.active_editor.save_as_pdf(dialog.path) diff --git a/omnivore/framework/editor.py b/omnivore/framework/editor.py index 7e810f21..22d14fa1 100644 --- a/omnivore/framework/editor.py +++ b/omnivore/framework/editor.py @@ -251,14 +251,17 @@ def copy_view_properties(self, old_editor): def document_length(self): return len(self.document) - def save(self, uri=None): + def save(self, uri=None, saver=None): """ Saves the contents of the editor. """ if uri is None: uri = self.document.uri try: - bytes = self.document.bytes.tostring() + if saver is None: + bytes = self.document.bytes.tostring() + else: + bytes = saver(self.document) self.save_to_uri(bytes, uri) self.document.undo_stack.set_save_point() @@ -312,6 +315,17 @@ def save_to_uri(self, bytes, uri, save_metadata=True): fs.close() + # Segment saver interface for menu item display + export_data_name = "Any" + export_extensions = [".*"] + + def encode_data(self, document): + """Document saver interface: take a document and produce a byte + representation to save to disk. + """ + data = document.bytes.tostring() + return data + def get_extra_metadata_header(self): return "# omnivore %s extra_metadata=v1\n" % __version__ diff --git a/omnivore/tasks/jumpman/jumpman_editor.py b/omnivore/tasks/jumpman/jumpman_editor.py index fb4b2959..a0b11279 100644 --- a/omnivore/tasks/jumpman/jumpman_editor.py +++ b/omnivore/tasks/jumpman/jumpman_editor.py @@ -834,6 +834,10 @@ def _mouse_mode_default(self): ########################################################################### # 'FrameworkEditor' interface. ########################################################################### + + # Segment saver interface for menu item display + export_data_name = "Jumpman Level Tester ATR" + export_extensions = [".atr"] def made_current_active_editor(self): self.update_mouse_mode(AnticDSelectMode)