Skip to content

Commit

Permalink
As a defualt, populate the Save Segment As dialog with the segment name
Browse files Browse the repository at this point in the history
  • Loading branch information
robmcmullen committed Feb 9, 2016
1 parent ff32ec6 commit 4ff6340
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions omnivore/tasks/hex_edit/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,14 @@ def perform(self, event):
class SaveSegmentAsFormatAction(EditorAction):
saver = Any

segment_number = Int

def _name_default(self):
return "%s (%s)" % (self.saver.name, self.saver.extensions[0])

def perform(self, event):
dialog = FileDialog(parent=event.task.window.control, action='save as', wildcard=self.saver.get_file_dialog_wildcard())
segment = self.task.active_editor.document.segments[self.segment_number]
dialog = FileDialog(default_filename=segment.name, parent=event.task.window.control, action='save as', wildcard=self.saver.get_file_dialog_wildcard())
if dialog.open() == OK:
self.active_editor.save_segment(self.saver, dialog.path)

Expand All @@ -306,7 +309,7 @@ def _get_items(self, event_data=None):
segment_number = event_data
segment = self.task.active_editor.document.segments[segment_number]
for saver in segment.savers:
action = SaveSegmentAsFormatAction(saver=saver)
action = SaveSegmentAsFormatAction(saver=saver, segment_number=segment_number)
items.append(ActionItem(action=action))

return items
Expand Down
2 changes: 1 addition & 1 deletion omnivore/tasks/hex_edit/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def on_popup(self, event):
# because it may be different than the selected item
actions = [Action(name=segment.name, task=self.task, enabled=False)]
for saver in segment.savers:
action = SaveSegmentAsFormatAction(saver=saver, task=self.task, name="Save as %s" % saver.name)
action = SaveSegmentAsFormatAction(saver=saver, segment_number=selected, task=self.task, name="Save as %s" % saver.name)
actions.append(action)
if actions:
self.task.active_editor.popup_context_menu_from_actions(self, actions)

0 comments on commit 4ff6340

Please sign in to comment.