[gnome-music/wip/gbsneto/flowbox: 5/6] albums: bring back selection mode on right click



commit d5629a91adbf4e8af922b48c21648f5b885ab402
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Aug 9 14:13:02 2016 -0300

    albums: bring back selection mode on right click
    
    We used to have this for free when using GdMainView but,
    as long as we're not using it anymore, we have to deal with
    it manually.
    
    This patch reimplements the selection mode on Albums view
    with right-click.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760164

 data/AlbumCover.ui |   90 +++++++++++++++++++++++++++------------------------
 gnomemusic/view.py |   14 +++++++-
 2 files changed, 61 insertions(+), 43 deletions(-)
---
diff --git a/data/AlbumCover.ui b/data/AlbumCover.ui
index 800850d..e8cffbb 100644
--- a/data/AlbumCover.ui
+++ b/data/AlbumCover.ui
@@ -1,63 +1,69 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="3.18"/>
-  <object class="GtkBox" id="main_box">
+  <object class="GtkEventBox" id="main_box">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="orientation">vertical</property>
     <child>
-      <object class="GtkOverlay">
+      <object class="GtkBox">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="margin_bottom">4</property>
+        <property name="orientation">vertical</property>
         <child>
-          <object class="GtkImage" id="image">
+          <object class="GtkOverlay">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="vexpand">True</property>
-            <property name="valign">end</property>
-            <property name="halign">center</property>
+            <property name="margin_bottom">4</property>
+            <child>
+              <object class="GtkImage" id="image">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="vexpand">True</property>
+                <property name="valign">end</property>
+                <property name="halign">center</property>
+              </object>
+            </child>
+            <child type="overlay">
+              <object class="GtkCheckButton" id="check">
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="halign">end</property>
+                <property name="valign">end</property>
+                <property name="margin_end">6</property>
+                <property name="draw_indicator">True</property>
+                <style>
+                  <class name="osd"/>
+                  <class name="content-view"/>
+                </style>
+              </object>
+            </child>
           </object>
         </child>
-        <child type="overlay">
-          <object class="GtkCheckButton" id="check">
-            <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="halign">end</property>
-            <property name="valign">end</property>
-            <property name="margin_end">6</property>
-            <property name="draw_indicator">True</property>
+        <child>
+          <object class="GtkLabel" id="title">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="max_width_chars">22</property>
+            <property name="ellipsize">middle</property>
+            <property name="tooltip_text" bind-source="title" bind-property="label" bind-flags="default" />
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="subtitle">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="max_width_chars">22</property>
+            <property name="ellipsize">middle</property>
+            <property name="tooltip_text" bind-source="subtitle" bind-property="label" bind-flags="default" 
/>
+            <attributes>
+              <attribute name="scale" value="0.88"/>
+            </attributes>
             <style>
-              <class name="osd"/>
-              <class name="content-view"/>
+              <class name="dim-label"/>
             </style>
           </object>
         </child>
       </object>
     </child>
-    <child>
-      <object class="GtkLabel" id="title">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="max_width_chars">22</property>
-        <property name="ellipsize">middle</property>
-        <property name="tooltip_text" bind-source="title" bind-property="label" bind-flags="default" />
-      </object>
-    </child>
-    <child>
-      <object class="GtkLabel" id="subtitle">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="max_width_chars">22</property>
-        <property name="ellipsize">middle</property>
-        <property name="tooltip_text" bind-source="subtitle" bind-property="label" bind-flags="default" />
-        <attributes>
-          <attribute name="scale" value="0.88"/>
-        </attributes>
-        <style>
-          <class name="dim-label"/>
-        </style>
-      </object>
-    </child>
   </object>
 </interface>
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 615f995..865ba4f 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -483,18 +483,23 @@ class Albums(ViewContainer):
         child.check = builder.get_object('check')
         child.title = builder.get_object('title')
         child.subtitle = builder.get_object('subtitle')
+        child.main_box = builder.get_object('main_box')
         child.media_item = item
 
         child.title.set_label(title)
         child.subtitle.set_label(artist)
         child.image.set_from_pixbuf(self._loadingIcon)
 
+        child.main_box.connect('button-release-event',
+                               self._on_album_event_triggered,
+                               child)
+
         child.check.connect('notify::active', self._on_child_toggled, child)
 
         child.check.bind_property('visible', self, 'selection_mode',
                                   GObject.BindingFlags.BIDIRECTIONAL)
 
-        child.add(builder.get_object('main_box'))
+        child.add(child.main_box)
         child.show()
 
         self.cache.lookup(item, self._iconWidth, self._iconHeight,
@@ -502,6 +507,13 @@ class Albums(ViewContainer):
 
         return child
 
+    @log
+    def _on_album_event_triggered(self, evbox, event, child):
+        if event.button is 3:
+            self._on_selection_mode_request()
+            child.check.set_active(not child.check.get_active())
+            child.check.show()
+
     def _on_lookup_ready(self, icon, path, child):
         child.image.set_from_pixbuf(icon)
 


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