[dconf-editor] Create LargePathbar when needed.



commit 405300f8deebfe610120f93c7c305f248d0111e7
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Jan 6 18:06:09 2019 +0100

    Create LargePathbar when needed.
    
    Until now, a LargePathbar was always created, as the window
    had a minimal start size; since commit 01f7559dc8, that has
    changed. Only create one when needed, not on small screens.

 editor/adaptative-pathbar.vala | 92 +++++++++++++++++++++++++-----------------
 editor/browser-headerbar.vala  |  2 +-
 editor/dconf-window.vala       | 16 +++++---
 editor/large-pathbar.vala      | 17 +++++---
 editor/pathwidget.vala         |  4 +-
 editor/short-pathbar.vala      | 11 ++---
 6 files changed, 87 insertions(+), 55 deletions(-)
---
diff --git a/editor/adaptative-pathbar.vala b/editor/adaptative-pathbar.vala
index f9a3b2c..9d6ec64 100644
--- a/editor/adaptative-pathbar.vala
+++ b/editor/adaptative-pathbar.vala
@@ -29,16 +29,18 @@ private class AdaptativePathbar : Stack, Pathbar, AdaptativeWidget
     * * pathbars creation
     \*/
 
-    private bool is_startup = true;
+    private bool start_infos_not_given = true;
+    private bool window_size_not_given = true;
+
     private bool large_pathbar_created = false;
     private bool short_pathbar_created = false;
 
     private LargePathbar large_pathbar;
     private ShortPathbar short_pathbar;
 
-    private void create_large_pathbar ()        // FIXME large pathbar is created at startup, even on thin 
window
+    private void create_large_pathbar ()
     {
-        large_pathbar = new LargePathbar ();    // TODO _get_complete_path (/* allow empty */ true));
+        large_pathbar = new LargePathbar (complete_path, current_type, current_path);
         large_pathbar.valign = Align.FILL;
         large_pathbar.vexpand = true;
         large_pathbar.show ();
@@ -48,13 +50,27 @@ private class AdaptativePathbar : Stack, Pathbar, AdaptativeWidget
 
     private void create_short_pathbar ()
     {
-        short_pathbar = new ShortPathbar (_get_complete_path (/* allow empty */ true));
+        short_pathbar = new ShortPathbar (complete_path, current_type, current_path);
         short_pathbar.valign = Align.CENTER;
         short_pathbar.show ();
         add (short_pathbar);
         short_pathbar_created = true;
     }
 
+    private void create_initial_pathbar ()
+    {
+        if (thin_window)
+        {
+            create_short_pathbar ();
+            set_visible_child (short_pathbar);
+        }
+        else
+        {
+            create_large_pathbar ();
+            set_visible_child (large_pathbar);
+        }
+    }
+
     /*\
     * * window size state
     \*/
@@ -62,30 +78,34 @@ private class AdaptativePathbar : Stack, Pathbar, AdaptativeWidget
     private bool thin_window = false;
     private void set_window_size (AdaptativeWidget.WindowSize new_size)
     {
+        if (window_size_not_given)
+        {
+            thin_window = AdaptativeWidget.WindowSize.is_extra_thin (new_size);
+            window_size_not_given = false;
+            if (start_infos_not_given)
+                return;
+            create_initial_pathbar ();
+            return;
+        }
+
         bool _thin_window = AdaptativeWidget.WindowSize.is_extra_thin (new_size);
         if (thin_window == _thin_window)
             return;
         thin_window = _thin_window;
 
-        if (is_startup)
+        if (start_infos_not_given)
             return;
 
         if (_thin_window)
         {
             if (!short_pathbar_created)
-            {
                 create_short_pathbar ();
-                short_pathbar.set_path (current_type, current_path);
-            }
             set_visible_child (short_pathbar);
         }
         else
         {
             if (!large_pathbar_created)
-            {
                 create_large_pathbar ();
-                large_pathbar.set_path (current_type, current_path);
-            }
             set_visible_child (large_pathbar);
         }
     }
@@ -96,21 +116,30 @@ private class AdaptativePathbar : Stack, Pathbar, AdaptativeWidget
 
     private ViewType current_type;
     private string current_path;
+    private string complete_path = "";
 
     internal void set_path (ViewType type, string path)
     {
         current_type = type;
         current_path = path;
 
-        if (is_startup)
+        if (complete_path == ""
+         || !path.has_suffix ("/")
+         || !complete_path.has_prefix (path))
+            complete_path = path;
+
+        if (start_infos_not_given)
         {
-            is_startup = false;
-            if (thin_window)
-                create_short_pathbar ();
-            else
-                create_large_pathbar ();
+            start_infos_not_given = false;
+            if (window_size_not_given)
+                return;
+            create_initial_pathbar ();
+            return;
         }
 
+        if (window_size_not_given)
+            return;
+
         if (large_pathbar_created)
             large_pathbar.set_path (type, path);
         if (short_pathbar_created)
@@ -155,28 +184,17 @@ private class AdaptativePathbar : Stack, Pathbar, AdaptativeWidget
     * * public calls
     \*/
 
-    internal string get_complete_path ()
+    internal void get_complete_path (out string _complete_path)
     {
-        return _get_complete_path (false);
-    }
-    private string _get_complete_path (bool private_call)
-    {
-        if (large_pathbar_created)
-            return large_pathbar.get_complete_path ();
-        else if (short_pathbar_created)
-            return short_pathbar.get_complete_path ();
-        else if (private_call)
-            return "";
-        else
-            assert_not_reached ();
+        _complete_path = complete_path;
     }
 
-    internal void get_fallback_path_and_complete_path (out string fallback_path, out string complete_path)
+    internal void get_fallback_path_and_complete_path (out string _fallback_path, out string _complete_path)
     {
         if (large_pathbar_created)
-            large_pathbar.get_fallback_path_and_complete_path (out fallback_path, out complete_path);
+            large_pathbar.get_fallback_path_and_complete_path (out _fallback_path, out _complete_path);
         else if (short_pathbar_created)
-            short_pathbar.get_fallback_path_and_complete_path (out fallback_path, out complete_path);
+            short_pathbar.get_fallback_path_and_complete_path (out _fallback_path, out _complete_path);
         else
             assert_not_reached ();
     }
@@ -201,12 +219,14 @@ private interface Pathbar
     internal abstract void update_ghosts (string non_ghost_path, bool is_search);
 
     /* complex proxy calls */
-    internal abstract string get_complete_path ();
-    internal abstract void get_fallback_path_and_complete_path (out string fallback_path, out string 
complete_path);
+    internal abstract void get_complete_path (out string _complete_path);
+    internal abstract void get_fallback_path_and_complete_path (out string _fallback_path, out string 
_complete_path);
 
     internal virtual string get_selected_child (string current_path)
     {
-        return _get_selected_child (current_path, get_complete_path ());
+        string complete_path;
+        get_complete_path (out complete_path);
+        return _get_selected_child (current_path, complete_path);
     }
     private static string _get_selected_child (string current_path, string complete_path)
     {
diff --git a/editor/browser-headerbar.vala b/editor/browser-headerbar.vala
index b75ae2c..7390700 100644
--- a/editor/browser-headerbar.vala
+++ b/editor/browser-headerbar.vala
@@ -114,7 +114,7 @@ private abstract class BrowserHeaderBar : BaseHeaderBar, AdaptativeWidget
     [CCode (notify = false)] internal bool entry_has_focus       { get { return path_widget.entry_has_focus; 
}}
     [CCode (notify = false)] internal string text                { get { return path_widget.text; }}
 
-    internal string get_complete_path ()    { return path_widget.get_complete_path (); }
+    internal void get_complete_path (out string complete_path)   { path_widget.get_complete_path (out 
complete_path); }
     internal void get_fallback_path_and_complete_path (out string fallback_path, out string complete_path)
     {
         path_widget.get_fallback_path_and_complete_path (out fallback_path, out complete_path);
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 905c108..52965ac 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -165,8 +165,8 @@ private class DConfWindow : BrowserWindow
             if (((!) settings_saved_view).contains ("//"))
                 settings_saved_view = "/";
 
-            string saved_path = settings.get_string ("saved-pathbar-path");
-            string fallback_path = model.get_fallback_path (saved_path);
+            /* string saved_path = settings.get_string ("saved-pathbar-path"); */
+            string fallback_path = model.get_fallback_path (settings.get_string ("saved-pathbar-path"));
             /* headerbar.set_path (ModelUtils.is_folder_path (saved_path) ? ViewType.FOLDER : 
ViewType.OBJECT, saved_path);
             headerbar.update_ghosts (fallback_path);  // TODO allow a complete state restoration (including 
search and this) */
             headerbar.set_path (ModelUtils.is_folder_path (fallback_path) ? ViewType.FOLDER : 
ViewType.OBJECT, fallback_path);
@@ -302,7 +302,9 @@ private class DConfWindow : BrowserWindow
         else if (main_view.check_reload (current_type, current_path, !internal_changes))    // handle 
infobars in needed
             reload_view ();
 
-        headerbar.update_ghosts (((SettingsModel) _model).get_fallback_path (headerbar.get_complete_path 
()));
+        string complete_path;
+        headerbar.get_complete_path (out complete_path);
+        headerbar.update_ghosts (((SettingsModel) _model).get_fallback_path (complete_path));
     }
     private void propagate_gkey_value_push (string full_name, uint16 context_id, Variant key_value, bool 
is_key_default)
     {
@@ -402,7 +404,9 @@ private class DConfWindow : BrowserWindow
 
         settings.delay ();
         settings.set_string ("saved-view", saved_view);
-        settings.set_string ("saved-pathbar-path", headerbar.get_complete_path ());
+        string complete_path;
+        headerbar.get_complete_path (out complete_path);
+        settings.set_string ("saved-pathbar-path", complete_path);
         settings.apply ();
     }
 
@@ -999,7 +1003,9 @@ private class DConfWindow : BrowserWindow
                     cannot_find_folder (full_name);
             }
             request_folder (ModelUtils.get_parent_path (full_name), full_name, false);
-            headerbar.update_ghosts (model.get_fallback_path (headerbar.get_complete_path ()));
+            string complete_path;
+            headerbar.get_complete_path (out complete_path);
+            headerbar.update_ghosts (model.get_fallback_path (complete_path));
         }
         else
         {
diff --git a/editor/large-pathbar.vala b/editor/large-pathbar.vala
index 60b692b..6d37972 100644
--- a/editor/large-pathbar.vala
+++ b/editor/large-pathbar.vala
@@ -24,9 +24,9 @@ private class LargePathbar : Box, Pathbar
     private LargePathbarItem active_button;
 
     private string complete_path = "";
-    internal string get_complete_path ()
+    internal void get_complete_path (out string _complete_path)
     {
-        return complete_path;
+        _complete_path = complete_path;
     }
     private string fallback_path = "";
     internal void get_fallback_path_and_complete_path (out string _fallback_path, out string _complete_path)
@@ -45,10 +45,15 @@ private class LargePathbar : Box, Pathbar
         add_slash_label ();
     }
 
- // internal LargePathbar (string complete_path_or_empty)   // TODO
- // {
- //     complete_path = complete_path_or_empty;
- // }
+    internal LargePathbar (string complete_path_or_empty, ViewType type, string path)
+    {
+        if (complete_path_or_empty != "")
+        {
+            complete_path = complete_path_or_empty;
+            _set_path (ModelUtils.is_folder_path (complete_path_or_empty) ? ViewType.FOLDER : 
ViewType.OBJECT, complete_path_or_empty);
+        }
+        set_path (type, path);
+    }
 
     /*\
     * * keyboard
diff --git a/editor/pathwidget.vala b/editor/pathwidget.vala
index 7bb8b81..467e13c 100644
--- a/editor/pathwidget.vala
+++ b/editor/pathwidget.vala
@@ -126,9 +126,9 @@ private class PathWidget : Box, AdaptativeWidget
     }
 
     /* path bar */
-    internal string get_complete_path ()
+    internal void get_complete_path (out string complete_path)
     {
-        return pathbar.get_complete_path ();
+        pathbar.get_complete_path (out complete_path);
     }
     internal void get_fallback_path_and_complete_path (out string fallback_path, out string complete_path)
     {
diff --git a/editor/short-pathbar.vala b/editor/short-pathbar.vala
index dd84a4d..f02496a 100644
--- a/editor/short-pathbar.vala
+++ b/editor/short-pathbar.vala
@@ -23,9 +23,9 @@ private class ShortPathbar : Grid, Pathbar
     private string non_ghost_path = "";
 
     private string complete_path = "";
-    internal string get_complete_path ()
+    internal void get_complete_path (out string _complete_path)
     {
-        return complete_path;
+        _complete_path = complete_path;
     }
     internal void get_fallback_path_and_complete_path (out string _fallback_path, out string _complete_path)
     {
@@ -40,11 +40,11 @@ private class ShortPathbar : Grid, Pathbar
     [GtkChild] private MenuButton   menu_button;
     [GtkChild] private Label        view_label;
 
-    internal ShortPathbar (string complete_path_or_empty)
+    internal ShortPathbar (string complete_path_or_empty, ViewType type, string path)
     {
         complete_path = complete_path_or_empty;
         non_ghost_path = complete_path_or_empty;
-        update_menu ();
+        set_path (type, path);
     }
 
     /*\
@@ -75,7 +75,8 @@ private class ShortPathbar : Grid, Pathbar
         if (type == ViewType.SEARCH)
             return;
 
-        if (!path.has_suffix ("/")
+        if (complete_path == ""
+         || !path.has_suffix ("/")
          || !complete_path.has_prefix (path))
         {
             complete_path = path;


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