Skip to content

Commit

Permalink
Fixed #74: added document saver interface and default filename extens…
Browse files Browse the repository at this point in the history
…ions for Save As
  • Loading branch information
robmcmullen committed Jul 26, 2016
1 parent 148ce5e commit f6a581e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
12 changes: 7 additions & 5 deletions omnivore/framework/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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)

Expand All @@ -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'
Expand Down Expand Up @@ -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)

Expand Down
18 changes: 16 additions & 2 deletions omnivore/framework/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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__

Expand Down
4 changes: 4 additions & 0 deletions omnivore/tasks/jumpman/jumpman_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f6a581e

Please sign in to comment.