[pitivi/1.0] Fix main menu



commit c62ef1792384c1debe52667d92e304cc13203fa3
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Dec 18 00:21:40 2018 +0100

    Fix main menu
    
    The menu items connected to a signal were broken since
    4928787a2ffbef4d0e0ad96422800ae3c348e193 because they were not connected
    anymore.
    
    Later in 5c1d0e9fe3f034d6682974063b74efb2f9755c88 they would have broke
    again, for some reason.
    
    Fixed by converting all the menu items to use actions.

 data/ui/mainmenubutton.ui | 15 ++++++-------
 pitivi/mainwindow.py      | 55 ++++++++++++++++++++++++++++++++++-------------
 2 files changed, 46 insertions(+), 24 deletions(-)
---
diff --git a/data/ui/mainmenubutton.ui b/data/ui/mainmenubutton.ui
index 60366236..24583386 100644
--- a/data/ui/mainmenubutton.ui
+++ b/data/ui/mainmenubutton.ui
@@ -46,8 +46,8 @@
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="tooltip_text" translatable="yes">Reload the current project</property>
+            <property name="action_name">editor.revert-to-saved</property>
             <property name="text" translatable="yes">Revert to saved version</property>
-            <signal name="activate" handler="_revertToSavedProjectCb" swapped="no"/>
           </object>
         </child>
         <child>
@@ -55,8 +55,8 @@
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="tooltip_text" translatable="yes">Export the current project and all its media in 
a .tar archive</property>
+            <property name="action_name">editor.export-project</property>
             <property name="text" translatable="yes">Export as Archive...</property>
-            <signal name="activate" handler="_exportProjectAsTarCb" swapped="no"/>
           </object>
         </child>
         <child>
@@ -70,9 +70,8 @@
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="tooltip_text" translatable="yes">Export the frame at the current playhead 
position as an image file.</property>
+            <property name="action_name">editor.save-frame</property>
             <property name="text" translatable="yes">Export current frame...</property>
-            <property name="use_underline">True</property>
-            <signal name="activate" handler="_screenshotCb" swapped="no"/>
           </object>
         </child>
         <child>
@@ -86,9 +85,8 @@
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="tooltip_text" translatable="yes">Edit the project settings</property>
+            <property name="action_name">editor.project-settings</property>
             <property name="text" translatable="yes">Project Settings</property>
-            <property name="use_underline">True</property>
-            <signal name="activate" handler="_projectSettingsCb" swapped="no"/>
           </object>
         </child>
         <child>
@@ -101,8 +99,8 @@
           <object class="GtkModelButton" id="menu_preferences">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
+            <property name="action_name">win.preferences</property>
             <property name="text" translatable="yes">Preferences</property>
-            <signal name="activate" handler="_prefsCb" swapped="no"/>
           </object>
         </child>
         <child>
@@ -111,7 +109,6 @@
             <property name="can_focus">True</property>
             <property name="action_name">app.shortcuts_window</property>
             <property name="text" translatable="yes">Keyboard Shortcuts</property>
-            <property name="use_underline">True</property>
           </object>
         </child>
         <child>
@@ -126,8 +123,8 @@
           <object class="GtkModelButton" id="menu_about">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
+            <property name="action_name">win.about</property>
             <property name="text" translatable="yes">About Pitivi</property>
-            <signal name="activate" handler="_aboutCb" swapped="no"/>
           </object>
         </child>
       </object>
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index 51b762ff..bf3a27eb 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -407,10 +407,6 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
 
         self._menubutton = self.builder.get_object("menubutton")
 
-        self._menubutton_items = {}
-        for widget in self.builder.get_object("menu_box").get_children():
-            self._menubutton_items[Gtk.Buildable.get_name(widget)] = widget
-
         self._headerbar.pack_end(self._menubutton)
         self._headerbar.pack_end(self.save_button)
         self._headerbar.pack_end(self.render_button)
@@ -454,25 +450,57 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
                                _("Show the menu button content"),
                                group="app")
 
+        self.revert_to_saved_action = Gio.SimpleAction.new("revert-to-saved", None)
+        self.revert_to_saved_action.connect("activate", self.__revert_to_saved_cb)
+        self.add_action(self.revert_to_saved_action)
+
+        self.export_project_action = Gio.SimpleAction.new("export-project", None)
+        self.export_project_action.connect("activate", self.__export_project_cb)
+        self.add_action(self.export_project_action)
+
+        self.save_frame_action = Gio.SimpleAction.new("save-frame", None)
+        self.save_frame_action.connect("activate", self.__save_frame_cb)
+        self.add_action(self.save_frame_action)
+
+        self.project_settings_action = Gio.SimpleAction.new("project-settings", None)
+        self.project_settings_action.connect("activate", self.__project_settings_cb)
+        self.add_action(self.project_settings_action)
+
         import_asset_action = Gio.SimpleAction.new("import-asset", None)
         import_asset_action.connect("activate", self.__import_asset_cb)
         self.add_action(import_asset_action)
         self.app.shortcuts.add("win.import-asset", ["<Primary>i"],
                                _("Add media files to your project"))
 
-    def __import_asset_cb(self, unusdaction, unusedparam):
+        self.preferences_action = Gio.SimpleAction.new("preferences", None)
+        self.preferences_action.connect("activate", self.__preferences_cb)
+        self.add_action(self.preferences_action)
+
+        self.about_action = Gio.SimpleAction.new("about", None)
+        self.about_action.connect("activate", self.__about_cb)
+        self.add_action(self.about_action)
+        self.app.shortcuts.add("win.about", ["<Primary><Shift>a"],
+                               _("About"), group="app")
+
+    @staticmethod
+    def __user_manual_cb(unused_action, unused_param):
+        show_user_manual()
+
+    def __import_asset_cb(self, unused_action, unused_param):
         self.medialibrary.show_import_assets_dialog()
 
     def showProjectStatus(self):
         project = self.app.project_manager.current_project
         dirty = project.hasUnsavedModifications()
         self.save_action.set_enabled(dirty)
-        if project.uri:
-            self._menubutton_items["menu_revert_to_saved"].set_sensitive(dirty)
+        self.revert_to_saved_action.set_enabled(bool(project.uri) and dirty)
         self.updateTitle()
 
 # UI Callbacks
 
+    def __preferences_cb(self, unused_action, unused_param):
+        PreferencesDialog(self.app).run()
+
     def _configureCb(self, unused_widget, unused_event):
         """Saves the main window position and size."""
         # Takes window manager decorations into account.
@@ -541,10 +569,10 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
     def saveProjectAsDialog(self):
         self._saveProjectAsCb(None, None)
 
-    def _revertToSavedProjectCb(self, unused_action):
+    def __revert_to_saved_cb(self, unused_action, unused_param):
         return self.app.project_manager.revertToSavedProject()
 
-    def _exportProjectAsTarCb(self, unused_action):
+    def __export_project_cb(self, unused_action, unused_param):
         uri = self._showExportDialog(self.app.project_manager.current_project)
         result = None
         if uri:
@@ -555,7 +583,7 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
             self.log("Project couldn't be exported")
         return result
 
-    def _projectSettingsCb(self, unused_action):
+    def __project_settings_cb(self, unused_action, unused_param):
         self.showProjectSettingsDialog()
 
     def showProjectSettingsDialog(self):
@@ -573,7 +601,7 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
     def _aboutResponseCb(self, dialog, unused_response):
         dialog.destroy()
 
-    def _aboutCb(self, unused_action):
+    def __about_cb(self, unused_action, unused_param):
         abt = Gtk.AboutDialog()
         abt.set_program_name(APPNAME)
         abt.set_website(APPURL)
@@ -681,9 +709,6 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
         except:
             return False
 
-    def _prefsCb(self, unused_action):
-        PreferencesDialog(self.app).run()
-
 # Project management callbacks
 
     def _projectManagerNewProjectLoadedCb(self, project_manager, project):
@@ -1132,7 +1157,7 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
         chooser.destroy()
         return ret
 
-    def _screenshotCb(self, unused_action):
+    def __save_frame_cb(self, unused_action, unused_param):
         """Exports a snapshot of the current frame as an image file."""
         foo = self._showSaveScreenshotDialog()
         if foo:


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