From 4ff634030f3e0619bc58a5215c5e506b21da7500 Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Mon, 8 Feb 2016 23:13:48 -0800 Subject: [PATCH] As a defualt, populate the Save Segment As dialog with the segment name --- omnivore/tasks/hex_edit/actions.py | 7 +++++-- omnivore/tasks/hex_edit/segments.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/omnivore/tasks/hex_edit/actions.py b/omnivore/tasks/hex_edit/actions.py index 44101bef..1bc617bd 100644 --- a/omnivore/tasks/hex_edit/actions.py +++ b/omnivore/tasks/hex_edit/actions.py @@ -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) @@ -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 diff --git a/omnivore/tasks/hex_edit/segments.py b/omnivore/tasks/hex_edit/segments.py index c2724a07..eac8695d 100644 --- a/omnivore/tasks/hex_edit/segments.py +++ b/omnivore/tasks/hex_edit/segments.py @@ -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)