Skip to content

Commit

Permalink
Fix save as dialog to always add filename extension
Browse files Browse the repository at this point in the history
Closes #32
  • Loading branch information
otsaloma committed Aug 12, 2016
1 parent 4e7afda commit 90693ab
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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
16 changes: 13 additions & 3 deletions gaupol/dialogs/save.py
Original file line number Diff line number Diff line change
@@ -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."""

0 comments on commit 90693ab

Please sign in to comment.