[dconf-editor] Create pathbars on the fly.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Create pathbars on the fly.
- Date: Wed, 28 Nov 2018 20:27:05 +0000 (UTC)
commit 8b0896eaefb84021e16947eb80848d49ef98d2b4
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed Nov 28 14:06:58 2018 +0100
Create pathbars on the fly.
editor/adaptative-pathbar.ui | 20 -------
editor/adaptative-pathbar.vala | 118 +++++++++++++++++++++++++++++++++-----
editor/dconf-editor.gresource.xml | 1 -
editor/meson.build | 1 -
4 files changed, 104 insertions(+), 36 deletions(-)
---
diff --git a/editor/adaptative-pathbar.vala b/editor/adaptative-pathbar.vala
index cd55689..2e869d8 100644
--- a/editor/adaptative-pathbar.vala
+++ b/editor/adaptative-pathbar.vala
@@ -17,11 +17,46 @@
using Gtk;
-[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/adaptative-pathbar.ui")]
private class AdaptativePathbar : Stack, Pathbar, AdaptativeWidget
{
- [GtkChild] private LargePathbar large_pathbar;
- [GtkChild] private ShortPathbar short_pathbar;
+ construct
+ {
+ hexpand = true;
+ hhomogeneous = false;
+ }
+
+ /*\
+ * * pathbars creation
+ \*/
+
+ private bool is_startup = 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 ()
+ {
+ large_pathbar = new LargePathbar ();
+ large_pathbar.valign = Align.CENTER;
+ large_pathbar.show ();
+ add (large_pathbar);
+ large_pathbar_created = true;
+ }
+
+ private void create_short_pathbar ()
+ {
+ short_pathbar = new ShortPathbar ();
+ short_pathbar.valign = Align.CENTER;
+ short_pathbar.show ();
+ add (short_pathbar);
+ short_pathbar_created = true;
+ }
+
+ /*\
+ * * window size state
+ \*/
private bool thin_window = false;
private void set_window_size (AdaptativeWidget.WindowSize new_size)
@@ -31,15 +66,54 @@ private class AdaptativePathbar : Stack, Pathbar, AdaptativeWidget
return;
thin_window = _thin_window;
+ if (is_startup)
+ 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);
+ }
}
- internal string get_complete_path ()
+ /*\
+ * * current path state
+ \*/
+
+ private ViewType current_type;
+ private string current_path;
+
+ internal void set_path (ViewType type, string path)
{
- return large_pathbar.get_complete_path (); // or the short_pathbar one; do not require their
equality, it warns on window closing
+ current_type = type;
+ current_path = path;
+
+ if (is_startup)
+ {
+ is_startup = false;
+ if (thin_window)
+ create_short_pathbar ();
+ else
+ create_large_pathbar ();
+ }
+
+ if (large_pathbar_created)
+ large_pathbar.set_path (type, path);
+ if (short_pathbar_created)
+ short_pathbar.set_path (type, path);
}
/*\
@@ -48,37 +122,53 @@ private class AdaptativePathbar : Stack, Pathbar, AdaptativeWidget
internal bool has_popover ()
{
- return large_pathbar.has_popover () || short_pathbar.has_popover ();
+ return (large_pathbar_created && large_pathbar.has_popover ())
+ || (short_pathbar_created && short_pathbar.has_popover ());
}
internal void close_menu ()
{
- large_pathbar.close_menu ();
- short_pathbar.close_menu ();
+ if (large_pathbar_created)
+ large_pathbar.close_menu ();
+ if (short_pathbar_created)
+ short_pathbar.close_menu ();
}
internal void toggle_menu ()
{
if (thin_window)
+ {
+ if (!short_pathbar_created)
+ assert_not_reached ();
short_pathbar.toggle_menu ();
+ }
else
+ {
+ if (!large_pathbar_created)
+ assert_not_reached ();
large_pathbar.toggle_menu ();
+ }
}
/*\
- * * main public calls
+ * * public calls
\*/
- internal void set_path (ViewType type, string path)
+ internal string get_complete_path ()
{
- large_pathbar.set_path (type, path);
- short_pathbar.set_path (type, path);
+ if (large_pathbar_created)
+ return large_pathbar.get_complete_path ();
+ else if (short_pathbar_created)
+ return short_pathbar.get_complete_path ();
+ assert_not_reached ();
}
internal void update_ghosts (string non_ghost_path, bool is_search)
{
- large_pathbar.update_ghosts (non_ghost_path, is_search);
- short_pathbar.update_ghosts (non_ghost_path, is_search);
+ if (large_pathbar_created)
+ large_pathbar.update_ghosts (non_ghost_path, is_search);
+ if (short_pathbar_created)
+ short_pathbar.update_ghosts (non_ghost_path, is_search);
}
}
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index 8e39d9a..6d7212d 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/ca/desrt/dconf-editor/ui">
- <file preprocess="xml-stripblanks">adaptative-pathbar.ui</file>
<file preprocess="xml-stripblanks">bookmark.ui</file>
<file preprocess="xml-stripblanks">bookmarks.ui</file>
<file preprocess="xml-stripblanks">bookmarks-controller.ui</file>
diff --git a/editor/meson.build b/editor/meson.build
index f637d4e..ab25c67 100644
--- a/editor/meson.build
+++ b/editor/meson.build
@@ -104,7 +104,6 @@ sources = files(
)
resource_data = files(
- 'adaptative-pathbar.ui',
'bookmarks.ui',
'bookmarks-controller.ui',
'bookmark.ui',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]