[gnome-clocks] Use a proper accelerator for "new"



commit 1203f007a18eee77c6a4ef5e141324f4defe822e
Author: Paolo Borelli <pborelli gnome org>
Date:   Tue Aug 21 21:46:37 2012 +0200

    Use a proper accelerator for "new"
    
    Turn new into an Action, associate the action with the toolbutton and
    give it an accelerator. Remove the manual key-press-event handling.

 gnomeclocks/app.py |   27 +++++++--------------------
 1 files changed, 7 insertions(+), 20 deletions(-)
---
diff --git a/gnomeclocks/app.py b/gnomeclocks/app.py
index b39755a..77c38a7 100644
--- a/gnomeclocks/app.py
+++ b/gnomeclocks/app.py
@@ -30,7 +30,10 @@ class Window(Gtk.ApplicationWindow):
                                        application=app,
                                        hide_titlebar_when_maximized=True)
 
-        self.app = app
+        action = Gio.SimpleAction.new("new", None)
+        action.connect("activate", self._on_new_activated)
+        self.add_action(action)
+        app.add_accelerator("<Primary>n", "win.new", None)
 
         css_provider = Gtk.CssProvider()
         css_provider.load_from_path(os.path.join(Dirs.get_data_dir(),
@@ -68,12 +71,9 @@ class Window(Gtk.ApplicationWindow):
 
         self.world.connect("show-clock", self._on_show_clock)
         self.toolbar.connect("view-clock", self._on_view_clock)
-        self.toolbar.newButton.connect("clicked", self._on_new_clicked)
         self.show_all()
         self.toolbar.selection_toolbar.hide()
 
-        self.connect('key-press-event', self._on_key_press)
-
     def _set_up_menu(self):
         pass
 
@@ -91,11 +91,8 @@ class Window(Gtk.ApplicationWindow):
         self.notebook.set_current_page(self.views.index(view))
         self.toolbar._set_overview_toolbar()
 
-    def _on_new_clicked(self, button):
-        self.show()
-
-    def _on_cancel_clicked(self, button):
-        self.show()
+    def _on_new_activated(self, action, param):
+        self.toolbar.current_view.open_new_dialog()
 
     def show_about(self):
         about = Gtk.AboutDialog(title=_("About GNOME Clocks"))
@@ -131,12 +128,6 @@ class Window(Gtk.ApplicationWindow):
         about.set_transient_for(self)
         about.show()
 
-    def _on_key_press(self, widget, event):
-        keyname = Gdk.keyval_name(event.keyval)
-        if event.state and Gdk.ModifierType.CONTROL_MASK:
-            if keyname == 'n':
-                self.toolbar._on_new_clicked(None)
-
 
 class SelectionToolbar(Gtk.Toolbar):
     def __init__(self):
@@ -256,6 +247,7 @@ class ClocksToolbar(Gtk.Toolbar):
         self.newButton = Gtk.Button()
 
         label = Gtk.Label(_("New"))
+        self.newButton.set_action_name("win.new")
         self.newButton.get_style_context().add_class('suggested-action')
         self.newButton.add(label)
         self.newButton.set_size_request(64, -1)
@@ -274,8 +266,6 @@ class ClocksToolbar(Gtk.Toolbar):
         self.backButton.connect("clicked",
             lambda w: self.emit("view-clock", self.current_view))
 
-        self.newButton.connect("clicked", self._on_new_clicked)
-
         toolbox.pack_start(Gtk.Label(""), True, True, 0)
 
         self.buttonBox = Gtk.Box()
@@ -306,9 +296,6 @@ class ClocksToolbar(Gtk.Toolbar):
         self.selection_toolbar.doneButton.connect("clicked",
             self._on_selection_mode, False)
 
-    def _on_new_clicked(self, widget):
-        self.current_view.open_new_dialog()
-
     def set_clocks(self, views):
         self.views = views
         for view in views:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]