diff --git a/TODO.md b/TODO.md index b2d82bbb..5fcee231 100644 --- a/TODO.md +++ b/TODO.md @@ -1,12 +1,14 @@ -Gaupol 0.92/1.0 -=============== +Gaupol 0.92 +=========== * [x] Fix error saving document from a time-based format to a frame-based or vice versa ([#28][]) * [x] Fix error clicking undo or redo button dropdown arrow when no 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][]) [#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 diff --git a/gaupol/action.py b/gaupol/action.py index 91795760..f9f0cd2b 100644 --- a/gaupol/action.py +++ b/gaupol/action.py @@ -23,7 +23,12 @@ from gi.repository import GLib from gi.repository import GObject -__all__ = ("Action", "RadioAction", "ToggleAction") +__all__ = ( + "Action", + "OpenRecentTranslationFileAction", + "RadioAction", + "ToggleAction", +) class Action(Gio.SimpleAction): @@ -49,6 +54,15 @@ def update_enabled(self, application, page, selected_rows): self.set_enabled(False) +class OpenRecentTranslationFileAction(Action): + + """Baseclass for a dynamic menu of recent translation files to open.""" + + def _affirm_doable(self, application, page, selected_rows): + aeidon.util.affirm(page is not None) + aeidon.util.affirm(page.project.main_file is not None) + + class RadioAction(Action): """Baseclass for user-activatable radio actions.""" diff --git a/gaupol/agents/menu.py b/gaupol/agents/menu.py index 946f9b0f..dfc51164 100644 --- a/gaupol/agents/menu.py +++ b/gaupol/agents/menu.py @@ -63,6 +63,7 @@ def _init_signal_handlers(self): self.connect("page-saved", self._update_projects_menu) self.connect("page-switched", self._update_projects_menu) self.connect("pages-reordered", self._update_projects_menu) + self.connect("init-done", self._update_recent_menus) self.connect("page-added", self._update_recent_menus) self.connect("page-saved", self._update_recent_menus) @@ -290,6 +291,8 @@ def _update_recent_menus(self, *args): """Update the file menu lists of recent files.""" self._update_recent_main_menu() self._update_recent_translation_menu() + # Update enabled states of added actions. + self.update_gui() def _update_recent_translation_menu(self, *args): """Update the file menu list of recent translation files.""" @@ -307,7 +310,7 @@ def _update_recent_translation_menu(self, *args): menu.append(label, action) action = action.replace("win.", "") if not self.get_action(action): - ao = gaupol.Action(action) + ao = gaupol.OpenRecentTranslationFileAction(action) callback = self._on_open_recent_translation_file_activate ao.connect("activate", callback) self.window.add_action(ao) diff --git a/gaupol/application.py b/gaupol/application.py index e0b8461b..b435c6cb 100644 --- a/gaupol/application.py +++ b/gaupol/application.py @@ -88,6 +88,7 @@ class Application(aeidon.Observable, metaclass=ApplicationMeta): :ivar x_clipboard: A :class:`Gtk.Clipboard` used for desktop-wide copying Signals and their arguments for callback functions: + * ``init-done``: application * ``page-added``: application, page * ``page-changed``: application, page * ``page-closed``: application, page @@ -98,6 +99,7 @@ class Application(aeidon.Observable, metaclass=ApplicationMeta): """ signals = ( + "init-done", "page-added", "page-changed", "page-closed", @@ -139,6 +141,7 @@ def __init__(self): self.extension_manager.setup_extensions() self.update_gui() self.window.show() + self.emit("init-done") def __getattr__(self, name): """Return method delegated to an agent."""