[meld/ui-next] meldwindow: Move recent opening to new popover widget



commit ccadf7deac770f3509f3aa0a3129dac5317d5670
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Feb 22 10:32:13 2019 +1000

    meldwindow: Move recent opening to new popover widget

 data/ui/meldapp-ui.xml               |  3 --
 meld/meldwindow.py                   | 37 +++++-----------------
 meld/resources/ui/appwindow.ui       | 59 ++++++++++++++++++++++++++++++------
 meld/resources/ui/recent-selector.ui |  2 --
 meld/ui/gladesupport.py              |  1 +
 5 files changed, 59 insertions(+), 43 deletions(-)
---
diff --git a/data/ui/meldapp-ui.xml b/data/ui/meldapp-ui.xml
index 799f9768..1535a48c 100644
--- a/data/ui/meldapp-ui.xml
+++ b/data/ui/meldapp-ui.xml
@@ -1,8 +1,5 @@
 <ui>
   <menubar name="Menubar">
-    <menu action="FileMenu">
-      <menuitem action="Recent" />
-    </menu>
     <menu action="EditMenu">
       <menuitem action="Undo"/>
       <menuitem action="Redo"/>
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index 39b00831..051245ae 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -56,8 +56,6 @@ class MeldWindow(Gtk.ApplicationWindow):
         self.init_template()
 
         actions = (
-            ("FileMenu", None, _("_File")),
-
             ("EditMenu", None, _("_Edit")),
             ("Undo", Gtk.STOCK_UNDO, None, "<Primary>Z",
                 _("Undo the last action"),
@@ -102,15 +100,6 @@ class MeldWindow(Gtk.ApplicationWindow):
         self.actiongroup.set_translation_domain("meld")
         self.actiongroup.add_actions(actions)
 
-        recent_action = Gtk.RecentAction(
-            name="Recent",  label=_("Open Recent"),
-            tooltip=_("Open recent files"), stock_id=None)
-        recent_action.set_show_private(True)
-        recent_action.set_filter(recent_comparisons.recent_filter)
-        recent_action.set_sort_type(Gtk.RecentSortType.MRU)
-        recent_action.connect("item-activated", self.on_action_recent)
-        self.actiongroup.add_action(recent_action)
-
         self.ui = Gtk.UIManager()
         self.ui.insert_action_group(self.actiongroup, 0)
         self.ui.add_ui_from_file(ui_file("meldapp-ui.xml"))
@@ -183,10 +172,6 @@ class MeldWindow(Gtk.ApplicationWindow):
         self.ui.ensure_update()
         self.undo_handlers = tuple()
 
-        # Set tooltip on map because the recentmenu is lazily created
-        rmenu = self.ui.get_widget('/Menubar/FileMenu/Recent').get_submenu()
-        rmenu.connect("map", self._on_recentmenu_map)
-
     def do_realize(self):
         Gtk.ApplicationWindow.do_realize(self)
 
@@ -197,10 +182,6 @@ class MeldWindow(Gtk.ApplicationWindow):
 
         meld.ui.util.extract_accels_from_menu(menu, self.get_application())
 
-    def _on_recentmenu_map(self, recentmenu):
-        for imagemenuitem in recentmenu.get_children():
-            imagemenuitem.set_tooltip_text(imagemenuitem.get_label())
-
     def on_widget_drag_data_received(
             self, wid, context, x, y, selection_data, info, time):
         uris = selection_data.get_uris()
@@ -330,16 +311,6 @@ class MeldWindow(Gtk.ApplicationWindow):
     def on_action_new_tab_activate(self, action, parameter):
         self.append_new_comparison()
 
-    def on_action_recent(self, action):
-        uri = action.get_current_uri()
-        if not uri:
-            return
-        try:
-            self.append_recent(uri)
-        except (IOError, ValueError):
-            # FIXME: Need error handling, but no sensible display location
-            log.exception(f'Error opening recent file {uri}')
-
     def action_close(self, *extra):
         i = self.notebook.get_current_page()
         if i >= 0:
@@ -443,6 +414,14 @@ class MeldWindow(Gtk.ApplicationWindow):
             if page != srcpage:
                 page.on_file_changed(filename)
 
+    @Template.Callback()
+    def on_open_recent(self, recent_selector, uri):
+        try:
+            self.append_recent(uri)
+        except (IOError, ValueError):
+            # FIXME: Need error handling, but no sensible display location
+            log.exception(f'Error opening recent file {uri}')
+
     def _append_page(self, page, icon):
         nbl = NotebookLabel(icon_name=icon, page=page)
         self.notebook.append_page(page, nbl)
diff --git a/meld/resources/ui/appwindow.ui b/meld/resources/ui/appwindow.ui
index cf0696ef..a625af51 100644
--- a/meld/resources/ui/appwindow.ui
+++ b/meld/resources/ui/appwindow.ui
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.24 -->
+  <!-- interface-requires meld.ui.gladesupport 0.0 -->
   <template class="MeldWindow" parent="GtkApplicationWindow">
     <property name="name">meldapp</property>
     <property name="height_request">400</property>
@@ -15,20 +16,47 @@
         <property name="show-close-button">true</property>
         <property name="visible">true</property>
         <child>
-          <object class="GtkButton">
-            <property name="action-name">win.new-tab</property>
-            <property name="visible">true</property>
-            <property name="tooltip-text">Start a new comparison</property>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="orientation">horizontal</property>
+            <property name="homogeneous">True</property>
+            <style>
+              <class name="linked"/>
+            </style>
             <child>
-              <object class="GtkImage">
-                <property name="icon-name">document-new-symbolic</property>
+              <object class="GtkButton">
+                <property name="action-name">win.new-tab</property>
                 <property name="visible">true</property>
+                <property name="tooltip-text">Start a new comparison</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="icon-name">tab-new-symbolic</property>
+                    <property name="visible">true</property>
+                  </object>
+                </child>
               </object>
+              <packing>
+                <property name="pack-type">start</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkMenuButton" id="recent_menu_button">
+                <property name="visible">true</property>
+                <property name="tooltip-text">Open a recent comparison</property>
+                <property name="use_popover">True</property>
+                <property name="popover">recent_popover</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="icon-name">document-open-recent-symbolic</property>
+                    <property name="visible">true</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="pack-type">start</property>
+              </packing>
             </child>
           </object>
-          <packing>
-            <property name="pack-type">start</property>
-          </packing>
         </child>
         <child>
           <object class="GtkBox">
@@ -141,4 +169,17 @@
       </object>
     </child>
   </template>
+  <object class="GtkPopover" id="recent_popover">
+    <property name="can_focus">True</property>
+    <property name="visible">False</property>
+    <property name="width-request">400</property>
+    <property name="height-request">500</property>
+    <child>
+      <object class="RecentSelector" id="recent_selector">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <signal name="open-recent" handler="on_open_recent" swapped="no"/>
+      </object>
+    </child>
+  </object>
 </interface>
diff --git a/meld/resources/ui/recent-selector.ui b/meld/resources/ui/recent-selector.ui
index ba63ed55..32fd36bb 100644
--- a/meld/resources/ui/recent-selector.ui
+++ b/meld/resources/ui/recent-selector.ui
@@ -3,8 +3,6 @@
 <interface>
   <requires lib="gtk+" version="3.20"/>
   <template class="RecentSelector" parent="GtkGrid">
-    <property name="width_request">400</property>
-    <property name="height_request">500</property>
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="border_width">6</property>
diff --git a/meld/ui/gladesupport.py b/meld/ui/gladesupport.py
index 9e4c7db7..3f4568d1 100644
--- a/meld/ui/gladesupport.py
+++ b/meld/ui/gladesupport.py
@@ -13,4 +13,5 @@ from meld.ui import emblemcellrenderer  # noqa: F401
 from meld.ui import historyentry  # noqa: F401
 from meld.ui import msgarea  # noqa: F401
 from meld.ui import notebook  # noqa: F401
+from meld.ui import recentselector  # noqa: F401
 from meld.ui import statusbar  # noqa: F401


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