[baobab/reroot-view: 21/30] Go up one level when FolderDisplay is clicked



commit 8d65fd72ff76031f7282a6336a506dda4a409300
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Sat Jun 20 11:42:25 2020 +0200

    Go up one level when FolderDisplay is clicked

 data/baobab.css                  |   7 +-
 data/ui/baobab-folder-display.ui | 225 ++++++++++++++++++++-------------------
 src/baobab-folder-display.vala   |  14 ++-
 src/baobab-window.vala           |   9 ++
 4 files changed, 143 insertions(+), 112 deletions(-)
---
diff --git a/data/baobab.css b/data/baobab.css
index 4a90cbe..3362d7a 100644
--- a/data/baobab.css
+++ b/data/baobab.css
@@ -65,7 +65,12 @@ folder-display {
     border-width: 0 1px 1px 0;
 }
 
-folder-display > label {
+folder-display:hover {
+    color: @theme_selected_fg_color;
+    background: @theme_selected_bg_color;
+}
+
+folder-display label {
     padding: 6px;
 }
 
diff --git a/data/ui/baobab-folder-display.ui b/data/ui/baobab-folder-display.ui
index bef1674..710c991 100644
--- a/data/ui/baobab-folder-display.ui
+++ b/data/ui/baobab-folder-display.ui
@@ -2,121 +2,126 @@
 <!-- Generated with glade 3.22.0 -->
 <interface>
   <requires lib="gtk+" version="3.22"/>
-  <template class="BaobabFolderDisplay" parent="GtkGrid">
+  <template class="BaobabFolderDisplay" parent="GtkButton">
     <property name="visible">True</property>
-    <property name="can_focus">False</property>
     <child>
-      <object class="GtkLabel" id="folder_name_primary">
+      <object class="GtkGrid">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="halign">start</property>
-        <property name="hexpand">True</property>
-        <property name="ellipsize">end</property>
-        <style>
-          <class name="folder-display-header"/>
-        </style>
+        <child>
+          <object class="GtkLabel" id="folder_name_primary">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="hexpand">True</property>
+            <property name="ellipsize">end</property>
+            <style>
+              <class name="folder-display-header"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">end</property>
+            <property name="label" translatable="yes">Size</property>
+            <style>
+              <class name="dim-label"/>
+              <class name="folder-display-header"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">end</property>
+            <property name="label" translatable="yes">Contents</property>
+            <style>
+              <class name="dim-label"/>
+              <class name="folder-display-header"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left_attach">2</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="folder_name_secondary">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="hexpand">True</property>
+            <property name="ellipsize">end</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="folder_size">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">end</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="folder_elements">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">end</property>
+          </object>
+          <packing>
+            <property name="left_attach">2</property>
+            <property name="top_attach">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">end</property>
+            <property name="label" translatable="yes">Modified</property>
+            <style>
+              <class name="dim-label"/>
+              <class name="folder-display-header"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left_attach">3</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="folder_time">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">end</property>
+          </object>
+          <packing>
+            <property name="left_attach">3</property>
+            <property name="top_attach">1</property>
+          </packing>
+        </child>
       </object>
-      <packing>
-        <property name="left_attach">0</property>
-        <property name="top_attach">0</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="halign">end</property>
-        <property name="label" translatable="yes">Size</property>
-        <style>
-          <class name="dim-label"/>
-          <class name="folder-display-header"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="top_attach">0</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="halign">end</property>
-        <property name="label" translatable="yes">Contents</property>
-        <style>
-          <class name="dim-label"/>
-          <class name="folder-display-header"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left_attach">2</property>
-        <property name="top_attach">0</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="folder_name_secondary">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="halign">start</property>
-        <property name="hexpand">True</property>
-        <property name="ellipsize">end</property>
-        <style>
-          <class name="dim-label"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left_attach">0</property>
-        <property name="top_attach">1</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="folder_size">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="halign">end</property>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="top_attach">1</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="folder_elements">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="halign">end</property>
-      </object>
-      <packing>
-        <property name="left_attach">2</property>
-        <property name="top_attach">1</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="halign">end</property>
-        <property name="label" translatable="yes">Modified</property>
-        <style>
-          <class name="dim-label"/>
-          <class name="folder-display-header"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left_attach">3</property>
-        <property name="top_attach">0</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="folder_time">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="halign">end</property>
-      </object>
-      <packing>
-        <property name="left_attach">3</property>
-        <property name="top_attach">1</property>
-      </packing>
     </child>
   </template>
 </interface>
diff --git a/src/baobab-folder-display.vala b/src/baobab-folder-display.vala
index 1e3c6a1..bfa7c89 100644
--- a/src/baobab-folder-display.vala
+++ b/src/baobab-folder-display.vala
@@ -20,7 +20,7 @@
 namespace Baobab {
 
     [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-folder-display.ui")]
-    public class FolderDisplay : Gtk.Grid {
+    public class FolderDisplay : Gtk.Button {
         static construct {
             set_css_name ("folder-display");
         }
@@ -36,6 +36,12 @@ namespace Baobab {
         [GtkChild]
         private Gtk.Label folder_time;
 
+        construct {
+            clicked.connect (() => { activated ();});
+        }
+
+        public signal void activated ();
+
         Location location_;
         public Location location {
             set {
@@ -52,8 +58,11 @@ namespace Baobab {
             }
         }
 
+        Gtk.TreePath path_;
         public new Gtk.TreePath path {
             set {
+                path_ = value;
+
                 Gtk.TreeIter iter;
                 location.scanner.get_iter (out iter, value);
 
@@ -80,6 +89,9 @@ namespace Baobab {
                 folder_elements.label = format_items (elements);
                 folder_time.label = format_time_approximate (time);
             }
+            get {
+                return path_;
+            }
         }
 
         void set_name_from_location () {
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 5a78deb..5252b21 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -141,6 +141,7 @@ namespace Baobab {
             rings_chart.item_activated.connect (on_chart_item_activated);
             treemap_chart.item_activated.connect (on_chart_item_activated);
             pathbar.item_activated.connect (on_pathbar_item_activated);
+            folder_display.activated.connect (on_folder_display_activated);
 
             // Setup drag-n-drop
             drag_data_received.connect (on_drag_data_received);
@@ -314,6 +315,14 @@ namespace Baobab {
             reroot_treeview (path);
         }
 
+        void on_folder_display_activated () {
+            var path = folder_display.path;
+            if (path.get_depth () > 1) {
+                path.up ();
+                reroot_treeview (path);
+            }
+        }
+
         void on_drag_data_received (Gtk.Widget widget, Gdk.DragContext context, int x, int y,
                                     Gtk.SelectionData selection_data, uint target_type, uint time) {
             File dir = null;


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