Skip to content

Commit

Permalink
Fix recent file menu states to update correctly
Browse files Browse the repository at this point in the history
Closes #31
  • Loading branch information
otsaloma committed Aug 12, 2016
1 parent dfc3f40 commit 4e7afda
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 4 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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
16 changes: 15 additions & 1 deletion gaupol/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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."""
Expand Down
5 changes: 4 additions & 1 deletion gaupol/agents/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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."""
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions gaupol/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -98,6 +99,7 @@ class Application(aeidon.Observable, metaclass=ApplicationMeta):
"""

signals = (
"init-done",
"page-added",
"page-changed",
"page-closed",
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 4e7afda

Please sign in to comment.