From 90693ab10157ca91cee36baa1a757f92b7e817fa Mon Sep 17 00:00:00 2001 From: Osmo Salomaa Date: Fri, 12 Aug 2016 23:21:47 +0300 Subject: [PATCH] Fix save as dialog to always add filename extension Closes #32 --- TODO.md | 2 ++ gaupol/dialogs/save.py | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 5fcee231..c8357590 100644 --- a/TODO.md +++ b/TODO.md @@ -7,8 +7,10 @@ Gaupol 0.92 document is yet open ([#29][]) * [x] Fix action states after subtitle cell editing cancelled ([#30][]) * [x] Fix recent file menu states to update correctly ([#31][]) +* [x] Fix save as dialog to always add filename extension ([#32][]) [#28]: https://github.com/otsaloma/gaupol/issues/28 [#29]: https://github.com/otsaloma/gaupol/issues/29 [#30]: https://github.com/otsaloma/gaupol/issues/30 [#31]: https://github.com/otsaloma/gaupol/issues/31 +[#32]: https://github.com/otsaloma/gaupol/issues/32 diff --git a/gaupol/dialogs/save.py b/gaupol/dialogs/save.py index 600ce8a1..481674ed 100644 --- a/gaupol/dialogs/save.py +++ b/gaupol/dialogs/save.py @@ -174,13 +174,23 @@ def _on_response(self, dialog, response): gaupol.conf.file.format = self.get_format() gaupol.conf.file.newline = self.get_newline() gaupol.conf.editor.framerate = self.get_framerate() + if (response == Gtk.ResponseType.OK and + not self.get_filename().endswith(self.get_format().extension)): + # If the filename is lacking the extension, add it, stop this + # response and emit a new one so that overwrite confirmation gets + # called with the full filename. The filename extension might have + # already been added in self._on_save_button_event, but not + # necessarily if the user hit Enter on the keyboard. + self._format_combo.emit("changed") + gaupol.util.iterate_main() + self.stop_emission("response") + return self.response(Gtk.ResponseType.OK) def _on_save_button_event(self, button, event): """Ensure that the filename contains an extension.""" - # Catch all events on save button to ensure that a possibly - # lacking extension is added to the filename so that overwrite - # confirmation check is done correctly. + # Add possibly lacking extension to the filename. self._format_combo.emit("changed") + gaupol.util.iterate_main() def set_format(self, format): """Set the selected format."""