[dconf-editor] Introduce BookmarksHeaderBar.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Introduce BookmarksHeaderBar.
- Date: Fri, 11 Jan 2019 13:00:58 +0000 (UTC)
commit 2a96024111b64139ada73d1040eccd31da0ebb5d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Jan 10 20:23:05 2019 +0100
Introduce BookmarksHeaderBar.
A DConfHeaderBar is now a BookmarksHeaderBar which
is a BrowserHeaderBar that is a BaseHeaderBar that
is a NightLightAwareHeaderBar. Ok, looks good now.
editor/base-headerbar.vala | 27 ++--
editor/bookmarks-headerbar.vala | 337 ++++++++++++++++++++++++++++++++++++++++
editor/bookmarks-list.vala | 10 +-
editor/bookmarks.ui | 2 +-
editor/bookmarks.vala | 26 ++--
editor/browser-headerbar.vala | 52 +++----
editor/dconf-headerbar.vala | 327 ++------------------------------------
editor/meson.build | 1 +
8 files changed, 404 insertions(+), 378 deletions(-)
---
diff --git a/editor/base-headerbar.vala b/editor/base-headerbar.vala
index dfb2493..2a45a37 100644
--- a/editor/base-headerbar.vala
+++ b/editor/base-headerbar.vala
@@ -180,9 +180,9 @@ private class BaseHeaderBar : NightTimeAwareHeaderBar, AdaptativeWidget
[GtkChild] protected Stack quit_button_stack;
- protected void set_default_widgets_states (bool show_go_back_button,
+ protected void set_default_widgets_states (string? title_label_text_or_null,
+ bool show_go_back_button,
bool show_ltr_left_separator,
- string? title_label_text_or_null,
bool show_info_button,
bool show_ltr_right_separator,
bool show_quit_button_stack)
@@ -210,6 +210,7 @@ private class BaseHeaderBar : NightTimeAwareHeaderBar, AdaptativeWidget
protected const uint8 default_mode_id = 0;
private bool default_mode_on = true;
+ protected bool no_in_window_mode { get { return default_mode_on; }}
internal void show_default_view ()
{
@@ -226,9 +227,9 @@ private class BaseHeaderBar : NightTimeAwareHeaderBar, AdaptativeWidget
if (is_not_requested_mode (default_mode_id, requested_mode_id, ref _this.default_mode_on))
return;
- _this.set_default_widgets_states (/* show go_back_button */ false,
+ _this.set_default_widgets_states (/* title_label text or null */ null,
+ /* show go_back_button */ false,
/* show ltr_left_separator */ false,
- /* title_label text or null */ null,
/* show info_button */ true,
/* show ltr_right_separator */ _this.disable_action_bar,
/* show quit_button_stack */ _this.disable_action_bar);
@@ -260,17 +261,13 @@ private class BaseHeaderBar : NightTimeAwareHeaderBar, AdaptativeWidget
if (is_not_requested_mode (_this.about_mode_id, requested_mode_id, ref _this.about_mode_on))
return;
- _this.set_default_widgets_states (/* show go_back_button */ true,
- /* show ltr_left_separator */ false,
- /* title_label text or null */
-
-
-
- /* Translators: on really small windows, the about dialog is
replaced by an in-window view; here is the name of the view, displayed in the headerbar */
- _("About"),
- /* show info_button */ false,
- /* show ltr_right_separator */ false,
- /* show quit_button_stack */ true);
+ /* Translators: on really small windows, the about dialog is replaced by an in-window view; here is
the name of the view, displayed in the headerbar */
+ _this.set_default_widgets_states (_("About"), /* title_label text or null */
+ true, /* show go_back_button */
+ false, /* show ltr_left_separator */
+ false, /* show info_button */
+ false, /* show ltr_right_separator */
+ true); /* show quit_button_stack */
}
/*\
diff --git a/editor/bookmarks-headerbar.vala b/editor/bookmarks-headerbar.vala
new file mode 100644
index 0000000..7b119d5
--- /dev/null
+++ b/editor/bookmarks-headerbar.vala
@@ -0,0 +1,337 @@
+/*
+ This file is part of Dconf Editor
+
+ Dconf Editor is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Dconf Editor is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Dconf Editor. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+private abstract class BookmarksHeaderBar : BrowserHeaderBar, AdaptativeWidget
+{
+ construct
+ {
+ install_action_entries ();
+
+ add_bookmarks_revealer (out bookmarks_revealer,
+ out bookmarks_button, ref center_box);
+ connect_bookmarks_signals ();
+ add_bookmarks_controller (out bookmarks_controller, ref this);
+
+ register_bookmarks_modes ();
+ }
+
+ protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
+ {
+ bool _disable_popovers = disable_popovers;
+
+ base.set_window_size (new_size);
+
+ if (disable_popovers != _disable_popovers)
+ update_bookmarks_button_visibility (/* run transitions */ true);
+ }
+
+ private void update_bookmarks_button_visibility (bool transition)
+ {
+ bookmarks_revealer.set_transition_duration (transition ? 300 : 0);
+
+ if (!disable_popovers && no_in_window_mode)
+ set_bookmarks_button_visibility (/* visibility */ true, ref bookmarks_revealer, ref
bookmarks_button);
+ else
+ {
+ bookmarks_button.active = false;
+ set_bookmarks_button_visibility (/* visibility */ false, ref bookmarks_revealer, ref
bookmarks_button);
+ }
+ }
+ private static inline void set_bookmarks_button_visibility (bool visibility,
+ ref Revealer bookmarks_revealer,
+ ref Bookmarks bookmarks_button)
+ {
+ bookmarks_button.sensitive = visibility;
+ bookmarks_revealer.set_reveal_child (visibility);
+ }
+
+ /*\
+ * * bookmarks widget
+ \*/
+
+ private Revealer bookmarks_revealer;
+ private Bookmarks bookmarks_button;
+ private BookmarksController bookmarks_controller;
+
+ private static void add_bookmarks_revealer (out Revealer bookmarks_revealer, out Bookmarks
bookmarks_button, ref Box center_box)
+ {
+ bookmarks_revealer = new Revealer ();
+ bookmarks_revealer.transition_type = RevealerTransitionType.SLIDE_LEFT;
+ bookmarks_revealer.reveal_child = true;
+ bookmarks_revealer.get_style_context ().add_class ("headerbar-revealer");
+
+ bookmarks_button = new Bookmarks ("/ca/desrt/dconf-editor/");
+ bookmarks_button.valign = Align.CENTER;
+ bookmarks_button.focus_on_click = false;
+ bookmarks_button.get_style_context ().add_class ("image-button"); // TODO check
https://bugzilla.gnome.org/show_bug.cgi?id=756731
+
+ bookmarks_button.visible = true;
+ bookmarks_revealer.add (bookmarks_button);
+ bookmarks_revealer.visible = true;
+ center_box.pack_end (bookmarks_revealer);
+ }
+
+ private static void add_bookmarks_controller (out BookmarksController bookmarks_controller, ref unowned
BookmarksHeaderBar _this)
+ {
+ bookmarks_controller = new BookmarksController ("bmk", false);
+ bookmarks_controller.hexpand = true;
+
+ bookmarks_controller.visible = false;
+ _this.pack_start (bookmarks_controller);
+ }
+
+ internal signal void update_bookmarks_icons (Variant bookmarks_variant);
+
+ private inline void connect_bookmarks_signals ()
+ {
+ bookmarks_button.update_bookmarks_icons.connect (update_bookmarks_icons_cb);
+ }
+
+ private void update_bookmarks_icons_cb (Variant bookmarks_variant)
+ {
+ update_bookmarks_icons (bookmarks_variant);
+ }
+
+ /*\
+ * * use-bookmarks mode
+ \*/
+
+ private uint8 use_bookmarks_mode_id = 0;
+ private bool use_bookmarks_mode_on = false;
+
+ internal void show_use_bookmarks_view ()
+ requires (use_bookmarks_mode_id > 0)
+ {
+ change_mode (use_bookmarks_mode_id);
+ }
+
+ private void register_bookmarks_modes ()
+ {
+ use_bookmarks_mode_id = register_new_mode ();
+ edit_bookmarks_mode_id = register_new_mode ();
+
+ this.change_mode.connect (mode_changed_bookmarks);
+ }
+
+ private static void mode_changed_bookmarks (BaseHeaderBar _this, uint8 requested_mode_id)
+ {
+ BookmarksHeaderBar real_this = (BookmarksHeaderBar) _this;
+ mode_changed_use_bookmarks (real_this, requested_mode_id);
+ mode_changed_edit_bookmarks (real_this, requested_mode_id);
+ real_this.update_bookmarks_button_visibility (/* run transitions */ false);
+ }
+
+ private static void mode_changed_use_bookmarks (BookmarksHeaderBar _this, uint8 requested_mode_id)
+ requires (_this.use_bookmarks_mode_id > 0)
+ {
+ if (is_not_requested_mode (_this.use_bookmarks_mode_id, requested_mode_id, ref
_this.use_bookmarks_mode_on))
+ {
+ _this.update_hamburger_menu (); // should not be useful, but <Ctrl>c-ing a bookmarks calls
somehow a menu update 1/2
+ return;
+ }
+
+ /* Translators: on really small windows, the bookmarks popover is replaced by an in-window view;
here is the name of the view, displayed in the headerbar */
+ _this.set_default_widgets_states (_("Bookmarks"), /* title_label text or null */
+ true, /* show go_back_button */
+ false, /* show ltr_left_separator */
+ false, /* show info_button */
+ false, /* show ltr_right_separator */
+ true); /* show quit_button_stack */
+ }
+
+ /*\
+ * * edit-bookmarks mode
+ \*/
+
+ private uint8 edit_bookmarks_mode_id = 0;
+ private bool edit_bookmarks_mode_on = false;
+
+ internal void show_edit_bookmarks_view ()
+ requires (edit_bookmarks_mode_id > 0)
+ {
+ change_mode (edit_bookmarks_mode_id);
+ }
+
+ private static void mode_changed_edit_bookmarks (BookmarksHeaderBar _this, uint8 requested_mode_id)
+ requires (_this.edit_bookmarks_mode_id > 0)
+ {
+ if (is_not_requested_mode (_this.edit_bookmarks_mode_id, requested_mode_id, ref
_this.edit_bookmarks_mode_on))
+ {
+ _this.bookmarks_controller.hide ();
+ _this.update_hamburger_menu (); // should not be useful, but <Ctrl>c-ing a bookmarks calls
somehow a menu update 2/2
+ return;
+ }
+
+ _this.set_default_widgets_states (/* title_label text or null */ null,
+ /* show go_back_button */ true,
+ /* show ltr_left_separator */ true,
+ /* show info_button */ false,
+ /* show ltr_right_separator */ false,
+ /* show quit_button_stack */ true);
+ _this.bookmarks_controller.show ();
+ }
+
+ /*\
+ * * action entries
+ \*/
+
+ private void install_action_entries ()
+ {
+ SimpleActionGroup action_group = new SimpleActionGroup ();
+ action_group.add_action_entries (action_entries, this);
+ insert_action_group ("headerbar", action_group);
+ }
+
+ private const GLib.ActionEntry [] action_entries =
+ {
+ { "bookmark-current", bookmark_current },
+ { "unbookmark-current", unbookmark_current }
+ };
+
+ private void bookmark_current (/* SimpleAction action, Variant? variant */)
+ {
+ bookmark_current_path ();
+ }
+
+ private void unbookmark_current (/* SimpleAction action, Variant? variant */)
+ {
+ unbookmark_current_path ();
+ }
+
+ /*\
+ * * bookmarks_button proxy calls
+ \*/
+
+ internal string [] get_bookmarks () { return bookmarks_button.get_bookmarks (); }
+
+ internal void update_bookmark_icon (string bookmark, BookmarkIcon icon) {
bookmarks_button.update_bookmark_icon (bookmark, icon); }
+
+ /*\
+ * * should move back
+ \*/
+
+ private string bookmark_name = "/";
+
+ internal override void set_path (ViewType type, string path)
+ {
+ bookmark_name = BookmarksList.get_bookmark_name (type, path);
+
+ bookmarks_button.set_path (type, path);
+ base.set_path (type, path);
+ }
+
+ internal void click_bookmarks_button ()
+ {
+ hide_hamburger_menu ();
+ if (bookmarks_button.sensitive)
+ bookmarks_button.clicked ();
+ }
+
+ internal void bookmark_current_path ()
+ {
+ hide_hamburger_menu ();
+ bookmarks_button.bookmark_current_path ();
+ update_hamburger_menu ();
+ }
+
+ internal void unbookmark_current_path ()
+ {
+ hide_hamburger_menu ();
+ bookmarks_button.unbookmark_current_path ();
+ update_hamburger_menu ();
+ }
+
+ /*\
+ * * hamburger menu
+ \*/
+
+ protected override void populate_menu (ref GLib.Menu menu)
+ {
+ base.populate_menu (ref menu); // does nothing for now
+
+ bool bookmarks_mode_on = use_bookmarks_mode_on || edit_bookmarks_mode_on;
+
+ if (disable_popovers)
+ append_bookmark_section (bookmark_name in get_bookmarks (), bookmarks_mode_on, ref menu);
+ }
+
+ private static void append_bookmark_section (bool is_in_bookmarks, bool bookmarks_mode_on, ref GLib.Menu
menu)
+ {
+ GLib.Menu section = new GLib.Menu ();
+
+ if (bookmarks_mode_on)
+ /* Translators: hamburger menu entry on small windows (not used in current design) */
+ section.append (_("Hide bookmarks"), "ui.empty");
+ else
+ {
+ if (is_in_bookmarks)
+ /* Translators: hamburger menu entry on small windows, to unbookmark the currently browsed
path */
+ section.append (_("Unbookmark"), "headerbar.unbookmark-current");
+ else
+ /* Translators: hamburger menu entry on small windows, to bookmark the currently browsed
path */
+ section.append (_("Bookmark"), "headerbar.bookmark-current");
+
+ /* Translators: hamburger menu entry on small windows, to show the bookmarks list */
+ section.append (_("Show bookmarks"), "ui.show-in-window-bookmarks");
+ }
+ section.freeze ();
+ menu.append_section (null, section);
+ }
+
+ /*\
+ * * keyboard calls
+ \*/
+
+ internal override bool next_match ()
+ {
+ if (bookmarks_button.active)
+ return bookmarks_button.next_match ();
+ return base.next_match (); // false
+ }
+
+ internal override bool previous_match ()
+ {
+ if (bookmarks_button.active)
+ return bookmarks_button.previous_match ();
+ return base.previous_match (); // false
+ }
+
+ internal bool handle_copy_text (out string copy_text)
+ {
+ if (bookmarks_button.active)
+ return bookmarks_button.handle_copy_text (out copy_text);
+ return BaseWindow.no_copy_text (out copy_text);
+ }
+
+ /*\
+ * * popovers methods
+ \*/
+
+ internal override void close_popovers ()
+ {
+ base.close_popovers ();
+ if (bookmarks_button.active)
+ bookmarks_button.active = false;
+ }
+
+ internal override bool has_popover ()
+ {
+ return bookmarks_button.active || base.has_popover ();
+ }
+}
diff --git a/editor/bookmarks-list.vala b/editor/bookmarks-list.vala
index 96d4968..f920db6 100644
--- a/editor/bookmarks-list.vala
+++ b/editor/bookmarks-list.vala
@@ -454,9 +454,9 @@ private class BookmarksList : OverlayedList
return bookmarks;
} */
- internal void append_bookmark (string bookmark, ViewType type)
+ internal void append_bookmark (ViewType type, string bookmark)
{
- _append_bookmark (settings, get_bookmark_name (bookmark, type));
+ _append_bookmark (settings, get_bookmark_name (type, bookmark));
}
private static void _append_bookmark (GLib.Settings settings, string bookmark_name)
{
@@ -468,9 +468,9 @@ private class BookmarksList : OverlayedList
settings.set_strv ("bookmarks", bookmarks);
}
- internal void remove_bookmark (string bookmark, ViewType type)
+ internal void remove_bookmark (ViewType type, string bookmark)
{
- _remove_bookmark (settings, get_bookmark_name (bookmark, type));
+ _remove_bookmark (settings, get_bookmark_name (type, bookmark));
}
private static void _remove_bookmark (GLib.Settings settings, string bookmark_name)
{
@@ -496,7 +496,7 @@ private class BookmarksList : OverlayedList
settings.set_strv ("bookmarks", new_bookmarks);
}
- internal static inline string get_bookmark_name (string path, ViewType type)
+ internal static inline string get_bookmark_name (ViewType type, string path)
{
if (type == ViewType.SEARCH)
return "?" + path;
diff --git a/editor/bookmarks.ui b/editor/bookmarks.ui
index a1954cb..67dd91d 100644
--- a/editor/bookmarks.ui
+++ b/editor/bookmarks.ui
@@ -46,7 +46,7 @@
<property name="visible">True</property>
<property name="halign">end</property>
<property name="action-name">browser.empty</property>
- <property name="action-target">('',byte 255)</property>
+ <property name="action-target">(byte 255,'')</property>
<child internal-child="accessible">
<object class="AtkObject">
<!-- Translators: accessible name of the switch for bookmarking current path in the
bookmarks popover -->
diff --git a/editor/bookmarks.vala b/editor/bookmarks.vala
index d931151..e86e59a 100644
--- a/editor/bookmarks.vala
+++ b/editor/bookmarks.vala
@@ -221,14 +221,14 @@ private class Bookmarks : MenuButton
{
if (bookmarked_switch.get_active ())
return;
- bookmarks_list.append_bookmark (current_path, current_type);
+ bookmarks_list.append_bookmark (current_type, current_path);
}
internal void unbookmark_current_path ()
{
if (!bookmarked_switch.get_active ())
return;
- bookmarks_list.remove_bookmark (current_path, current_type);
+ bookmarks_list.remove_bookmark (current_type, current_path);
}
internal void update_bookmark_icon (string bookmark, BookmarkIcon icon)
@@ -300,8 +300,8 @@ private class Bookmarks : MenuButton
{ "move-down", move_down },
{ "move-bottom", move_bottom },
- { "bookmark", bookmark, "(sy)" },
- { "unbookmark", unbookmark, "(sy)" }
+ { "bookmark", bookmark, "(ys)" },
+ { "unbookmark", unbookmark, "(ys)" }
};
private void set_edit_mode (SimpleAction action, Variant? variant)
@@ -371,10 +371,10 @@ private class Bookmarks : MenuButton
{
bookmarks_popover.closed (); // if the popover is visible, the size of the listbox could change
1/2
- string bookmark;
uint8 type;
- ((!) path_variant).@get ("(sy)", out bookmark, out type);
- bookmarks_list.append_bookmark (bookmark, ViewType.from_byte (type));
+ string bookmark;
+ ((!) path_variant).@get ("(ys)", out type, out bookmark);
+ bookmarks_list.append_bookmark (ViewType.from_byte (type), bookmark);
}
private void unbookmark (SimpleAction action, Variant? path_variant)
@@ -382,10 +382,10 @@ private class Bookmarks : MenuButton
{
bookmarks_popover.closed (); // if the popover is visible, the size of the listbox could change
2/2
- string bookmark;
uint8 type;
- ((!) path_variant).@get ("(sy)", out bookmark, out type);
- bookmarks_list.remove_bookmark (bookmark, ViewType.from_byte (type));
+ string bookmark;
+ ((!) path_variant).@get ("(ys)", out type, out bookmark);
+ bookmarks_list.remove_bookmark (ViewType.from_byte (type), bookmark);
}
/*\
@@ -408,8 +408,8 @@ private class Bookmarks : MenuButton
private void update_icon_and_switch (Variant bookmarks_variant)
{
- Variant variant = new Variant ("(sy)", current_path, ViewType.to_byte (current_type));
- string bookmark_name = BookmarksList.get_bookmark_name (current_path, current_type);
+ Variant variant = new Variant ("(ys)", ViewType.to_byte (current_type), current_path);
+ string bookmark_name = BookmarksList.get_bookmark_name (current_type, current_path);
if (bookmark_name in bookmarks_variant.get_strv ())
{
if (bookmarks_icon.icon_name != "starred-symbolic")
@@ -429,7 +429,7 @@ private class Bookmarks : MenuButton
{
if (bookmarked == bookmarked_switch.active)
return;
- bookmarked_switch.set_detailed_action_name ("browser.empty(('',byte 255))");
+ bookmarked_switch.set_detailed_action_name ("browser.empty((byte 255,''))");
bookmarked_switch.active = bookmarked;
}
}
diff --git a/editor/browser-headerbar.vala b/editor/browser-headerbar.vala
index 7390700..681f3ed 100644
--- a/editor/browser-headerbar.vala
+++ b/editor/browser-headerbar.vala
@@ -19,7 +19,7 @@ using Gtk;
private abstract class BrowserHeaderBar : BaseHeaderBar, AdaptativeWidget
{
- protected PathWidget path_widget;
+ private PathWidget path_widget;
construct
{
@@ -28,20 +28,26 @@ private abstract class BrowserHeaderBar : BaseHeaderBar, AdaptativeWidget
register_properties_mode ();
}
- private ViewType current_type = ViewType.FOLDER;
+ private bool current_type_is_config = false;
internal virtual void set_path (ViewType type, string path)
{
path_widget.set_path (type, path);
- current_type = type;
- update_properties_view (); // takes care of the hamburger menu
+ if (current_type_is_config != (type == ViewType.CONFIG))
+ {
+ current_type_is_config = !current_type_is_config;
+ update_properties_view ();
+ }
}
private bool is_extra_thin = false;
protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
{
- is_extra_thin = AdaptativeWidget.WindowSize.is_extra_thin (new_size);
- update_properties_view ();
+ if (is_extra_thin != AdaptativeWidget.WindowSize.is_extra_thin (new_size))
+ {
+ is_extra_thin = !is_extra_thin;
+ update_properties_view ();
+ }
base.set_window_size (new_size);
@@ -148,13 +154,8 @@ private abstract class BrowserHeaderBar : BaseHeaderBar, AdaptativeWidget
private void update_properties_view ()
{
- if (is_extra_thin)
- {
- if (current_type == ViewType.CONFIG)
- show_properties_view ();
- else
- hide_properties_view ();
- }
+ if (is_extra_thin && current_type_is_config)
+ show_properties_view ();
else
hide_properties_view ();
}
@@ -170,7 +171,6 @@ private abstract class BrowserHeaderBar : BaseHeaderBar, AdaptativeWidget
{
if (properties_mode_on)
change_mode (default_mode_id);
- update_hamburger_menu ();
}
private void register_properties_mode ()
@@ -186,17 +186,13 @@ private abstract class BrowserHeaderBar : BaseHeaderBar, AdaptativeWidget
if (is_not_requested_mode (real_this.properties_mode_id, requested_mode_id, ref
real_this.properties_mode_on))
return;
- real_this.set_default_widgets_states (/* show go_back_button */ true,
- /* show ltr_left_separator */ false,
- /* title_label text or null */
-
-
-
- /* Translators: on really small windows, name of the view when
showing a folder properties, displayed in the headerbar */
- _("Properties"),
- /* show info_button */ false,
- /* show ltr_right_separator */ false,
- /* show quit_button_stack */ true);
+ /* Translators: on really small windows, name of the view when showing a folder properties,
displayed in the headerbar */
+ real_this.set_default_widgets_states (_("Properties"), /* title_label text or null */
+ true, /* show go_back_button */
+ false, /* show ltr_left_separator */
+ false, /* show info_button */
+ false, /* show ltr_right_separator */
+ true); /* show quit_button_stack */
}
/*\
@@ -225,10 +221,6 @@ private abstract class BrowserHeaderBar : BaseHeaderBar, AdaptativeWidget
internal override bool has_popover ()
{
- if (base.has_popover ())
- return true;
- if (path_widget.has_popover ())
- return true;
- return false;
+ return base.has_popover () || path_widget.has_popover ();
}
}
diff --git a/editor/dconf-headerbar.vala b/editor/dconf-headerbar.vala
index 0c1968b..e0dfaa9 100644
--- a/editor/dconf-headerbar.vala
+++ b/editor/dconf-headerbar.vala
@@ -17,7 +17,7 @@
using Gtk;
-private class DConfHeaderBar : BrowserHeaderBar, AdaptativeWidget
+private class DConfHeaderBar : BookmarksHeaderBar, AdaptativeWidget
{
private bool _delay_mode = false;
[CCode (notify = false)] internal bool delay_mode
@@ -35,20 +35,12 @@ private class DConfHeaderBar : BrowserHeaderBar, AdaptativeWidget
construct
{
- install_action_entries ();
-
- add_bookmarks_revealer (out bookmarks_revealer,
- out bookmarks_button, ref center_box);
- connect_bookmarks_signals ();
- add_bookmarks_controller (out bookmarks_controller, ref this);
-
add_show_modifications_button (out show_modifications_button, ref quit_button_stack);
add_modification_actions_button (out modification_actions_button, ref quit_button_stack);
add_modifications_actions_button (out modifications_actions_button, ref this);
construct_changes_pending_menu (out changes_pending_menu);
construct_quit_delayed_mode_menu (out quit_delayed_mode_menu);
- register_bookmarks_modes ();
register_modifications_mode ();
}
@@ -60,168 +52,11 @@ private class DConfHeaderBar : BrowserHeaderBar, AdaptativeWidget
protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
{
- bool _disable_popovers = disable_popovers;
-
base.set_window_size (new_size);
- if (disable_popovers != _disable_popovers)
- update_bookmarks_button_visibility ();
update_modifications_button ();
}
- private void update_bookmarks_button_visibility ()
- {
- if (disable_popovers || modifications_mode_on)
- hide_bookmarks_button (in_window_properties, ref bookmarks_revealer, ref bookmarks_button);
- else
- show_bookmarks_button (ref bookmarks_revealer, ref bookmarks_button);
- }
- private static inline void hide_bookmarks_button (bool no_transition, ref Revealer bookmarks_revealer,
ref Bookmarks bookmarks_button)
- {
- bookmarks_button.active = false;
-
- bookmarks_button.sensitive = false;
- if (no_transition)
- bookmarks_revealer.set_transition_duration (0);
- bookmarks_revealer.set_reveal_child (false);
- if (no_transition)
- bookmarks_revealer.set_transition_duration (300);
- }
- private static inline void show_bookmarks_button (ref Revealer bookmarks_revealer, ref Bookmarks
bookmarks_button)
- {
- bookmarks_button.sensitive = true;
- bookmarks_revealer.set_reveal_child (true);
- }
-
- /*\
- * * bookmarks widget
- \*/
-
- private Revealer bookmarks_revealer;
- private Bookmarks bookmarks_button;
- private BookmarksController bookmarks_controller;
-
- private static void add_bookmarks_revealer (out Revealer bookmarks_revealer, out Bookmarks
bookmarks_button, ref Box center_box)
- {
- bookmarks_revealer = new Revealer ();
- bookmarks_revealer.transition_type = RevealerTransitionType.SLIDE_LEFT;
- bookmarks_revealer.reveal_child = true;
- bookmarks_revealer.get_style_context ().add_class ("headerbar-revealer");
-
- bookmarks_button = new Bookmarks ("/ca/desrt/dconf-editor/");
- bookmarks_button.valign = Align.CENTER;
- bookmarks_button.focus_on_click = false;
- bookmarks_button.get_style_context ().add_class ("image-button"); // TODO check
https://bugzilla.gnome.org/show_bug.cgi?id=756731
-
- bookmarks_button.visible = true;
- bookmarks_revealer.add (bookmarks_button);
- bookmarks_revealer.visible = true;
- center_box.pack_end (bookmarks_revealer);
- }
-
- private static void add_bookmarks_controller (out BookmarksController bookmarks_controller, ref unowned
DConfHeaderBar _this)
- {
- bookmarks_controller = new BookmarksController ("bmk", false);
- bookmarks_controller.hexpand = true;
-
- bookmarks_controller.visible = false;
- _this.pack_start (bookmarks_controller);
- }
-
- internal signal void update_bookmarks_icons (Variant bookmarks_variant);
-
- private inline void connect_bookmarks_signals ()
- {
- bookmarks_button.update_bookmarks_icons.connect (update_bookmarks_icons_cb);
- }
-
- private void update_bookmarks_icons_cb (Variant bookmarks_variant)
- {
- update_bookmarks_icons (bookmarks_variant);
- }
-
- /*\
- * * use-bookmarks mode
- \*/
-
- private uint8 use_bookmarks_mode_id = 0;
- private bool use_bookmarks_mode_on = false;
-
- internal void show_use_bookmarks_view ()
- requires (use_bookmarks_mode_id > 0)
- {
- change_mode (use_bookmarks_mode_id);
- }
-
- private void register_bookmarks_modes ()
- {
- use_bookmarks_mode_id = register_new_mode ();
- edit_bookmarks_mode_id = register_new_mode ();
-
- this.change_mode.connect (mode_changed_bookmarks);
- }
-
- private static void mode_changed_bookmarks (BaseHeaderBar _this, uint8 requested_mode_id)
- {
- DConfHeaderBar real_this = (DConfHeaderBar) _this;
- mode_changed_use_bookmarks (real_this, requested_mode_id);
- mode_changed_edit_bookmarks (real_this, requested_mode_id);
- }
-
- private static void mode_changed_use_bookmarks (DConfHeaderBar _this, uint8 requested_mode_id)
- requires (_this.use_bookmarks_mode_id > 0)
- {
- if (is_not_requested_mode (_this.use_bookmarks_mode_id, requested_mode_id, ref
_this.use_bookmarks_mode_on))
- {
- _this.update_hamburger_menu (); // should not be useful, but <Ctrl>c-ing a bookmarks calls
somehow a menu update 1/2
- return;
- }
-
- _this.set_default_widgets_states (/* show go_back_button */ true,
- /* show ltr_left_separator */ false,
- /* title_label text or null */
-
-
-
- /* Translators: on really small windows, the bookmarks popover is
replaced by an in-window view; here is the name of the view, displayed in the headerbar */
- _("Bookmarks"),
- /* show info_button */ false,
- /* show ltr_right_separator */ false,
- /* show quit_button_stack */ true);
- }
-
- /*\
- * * edit-bookmarks mode
- \*/
-
- private uint8 edit_bookmarks_mode_id = 0;
- private bool edit_bookmarks_mode_on = false;
-
- internal void show_edit_bookmarks_view ()
- requires (edit_bookmarks_mode_id > 0)
- {
- change_mode (edit_bookmarks_mode_id);
- }
-
- private static void mode_changed_edit_bookmarks (DConfHeaderBar _this, uint8 requested_mode_id)
- requires (_this.edit_bookmarks_mode_id > 0)
- {
- if (is_not_requested_mode (_this.edit_bookmarks_mode_id, requested_mode_id, ref
_this.edit_bookmarks_mode_on))
- {
- _this.bookmarks_controller.hide ();
- _this.update_hamburger_menu (); // should not be useful, but <Ctrl>c-ing a bookmarks calls
somehow a menu update 2/2
- return;
- }
-
- _this.set_default_widgets_states (/* show go_back_button */ true,
- /* show ltr_left_separator */ true,
- /* title_label text or null */ null,
- /* show info_button */ false,
- /* show ltr_right_separator */ false,
- /* show quit_button_stack */ true);
- _this.bookmarks_controller.show ();
- }
-
/*\
* * modifications buttons and actions
\*/
@@ -314,51 +149,21 @@ private class DConfHeaderBar : BrowserHeaderBar, AdaptativeWidget
}
}
- /*\
- * * bookmarks_button proxy calls
- \*/
-
- internal string [] get_bookmarks () { return bookmarks_button.get_bookmarks (); }
-
- internal void update_bookmark_icon (string bookmark, BookmarkIcon icon) {
bookmarks_button.update_bookmark_icon (bookmark, icon); }
-
/*\
* * should move back
\*/
- private ViewType current_type = ViewType.FOLDER;
+ private bool is_folder_view = true;
private string current_path = "/";
internal override void set_path (ViewType type, string path)
{
- current_type = type;
+ is_folder_view = type == ViewType.FOLDER;
current_path = path;
- bookmarks_button.set_path (type, path);
base.set_path (type, path);
}
- internal void click_bookmarks_button ()
- {
- hide_hamburger_menu ();
- if (bookmarks_button.sensitive)
- bookmarks_button.clicked ();
- }
-
- internal void bookmark_current_path ()
- {
- hide_hamburger_menu ();
- bookmarks_button.bookmark_current_path ();
- update_hamburger_menu ();
- }
-
- internal void unbookmark_current_path ()
- {
- hide_hamburger_menu ();
- bookmarks_button.unbookmark_current_path ();
- update_hamburger_menu ();
- }
-
/*\
* * hamburger menu
\*/
@@ -373,36 +178,9 @@ private class DConfHeaderBar : BrowserHeaderBar, AdaptativeWidget
protected override void populate_menu (ref GLib.Menu menu)
{
- bool bookmarks_mode_on = use_bookmarks_mode_on || edit_bookmarks_mode_on;
+ base.populate_menu (ref menu);
- if (disable_popovers)
- append_bookmark_section (current_type, current_path, BookmarksList.get_bookmark_name
(current_path, current_type) in get_bookmarks (), bookmarks_mode_on, ref menu);
-
- if (!bookmarks_mode_on)
- append_or_not_delay_mode_section (delay_mode, current_type == ViewType.FOLDER, current_path, ref
menu);
- }
-
- private static void append_bookmark_section (ViewType current_type, string current_path, bool
is_in_bookmarks, bool bookmarks_mode_on, ref GLib.Menu menu)
- {
- GLib.Menu section = new GLib.Menu ();
-
- if (bookmarks_mode_on)
- /* Translators: hamburger menu entry on small windows (not used in current design) */
- section.append (_("Hide bookmarks"), "ui.empty");
- else
- {
- if (is_in_bookmarks)
- /* Translators: hamburger menu entry on small windows, to unbookmark the currently browsed
path */
- section.append (_("Unbookmark"), "headerbar.unbookmark-current");
- else
- /* Translators: hamburger menu entry on small windows, to bookmark the currently browsed
path */
- section.append (_("Bookmark"), "headerbar.bookmark-current");
-
- /* Translators: hamburger menu entry on small windows, to show the bookmarks list */
- section.append (_("Show bookmarks"), "ui.show-in-window-bookmarks");
- }
- section.freeze ();
- menu.append_section (null, section);
+ append_or_not_delay_mode_section (delay_mode, is_folder_view, current_path, ref menu);
}
private static void append_or_not_delay_mode_section (bool delay_mode, bool is_folder_view, string
current_path, ref GLib.Menu menu)
@@ -427,6 +205,7 @@ private class DConfHeaderBar : BrowserHeaderBar, AdaptativeWidget
section.freeze ();
menu.append_section (null, section);
}
+
/*\
* * in-window modifications
\*/
@@ -453,26 +232,18 @@ private class DConfHeaderBar : BrowserHeaderBar, AdaptativeWidget
if (is_not_requested_mode (real_this.modifications_mode_id, requested_mode_id, ref
real_this.modifications_mode_on))
{
real_this.modifications_actions_button.hide ();
- real_this.bookmarks_revealer.show ();
- real_this.update_bookmarks_button_visibility ();
// if (path_widget.search_mode_enabled)
// path_widget.entry_grab_focus_without_selecting ();
return;
}
- real_this.set_default_widgets_states (/* show go_back_button */ true,
- /* show ltr_left_separator */ false,
- /* title_label text or null */
- /* Translators: on really small windows, the bottom bar that
appears in "delay mode" or when there're pending changes is replaced by an in-window view; here is the name
of the view, displayed in the headerbar */
- _("Pending"),
- /* show info_button */ false,
- /* show ltr_right_separator */ false,
- /* show quit_button_stack */ false);
- if (real_this.disable_action_bar && !real_this.disable_popovers)
- {
- real_this.bookmarks_button.sensitive = false;
- real_this.bookmarks_revealer.hide ();
- }
+ /* Translators: on really small windows, the bottom bar that appears in "delay mode" or when
there're pending changes is replaced by an in-window view; here is the name of the view, displayed in the
headerbar */
+ real_this.set_default_widgets_states (_("Pending"), /* title_label text or null */
+ true, /* show go_back_button */
+ false, /* show ltr_left_separator */
+ false, /* show info_button */
+ false, /* show ltr_right_separator */
+ false); /* show quit_button_stack */
real_this.modifications_actions_button.show ();
}
@@ -496,76 +267,4 @@ private class DConfHeaderBar : BrowserHeaderBar, AdaptativeWidget
quit_button_stack.set_visible_child_name ("quit-button");
}
}
-
- /*\
- * * action entries
- \*/
-
- private void install_action_entries ()
- {
- SimpleActionGroup action_group = new SimpleActionGroup ();
- action_group.add_action_entries (action_entries, this);
- insert_action_group ("headerbar", action_group);
- }
-
- private const GLib.ActionEntry [] action_entries =
- {
- { "bookmark-current", bookmark_current },
- { "unbookmark-current", unbookmark_current }
- };
-
- private void bookmark_current (/* SimpleAction action, Variant? variant */)
- {
- bookmark_current_path ();
- }
-
- private void unbookmark_current (/* SimpleAction action, Variant? variant */)
- {
- unbookmark_current_path ();
- }
-
- /*\
- * * keyboard calls
- \*/
-
- internal override bool next_match ()
- {
- if (bookmarks_button.active)
- return bookmarks_button.next_match ();
- return base.next_match (); // false
- }
-
- internal override bool previous_match ()
- {
- if (bookmarks_button.active)
- return bookmarks_button.previous_match ();
- return base.previous_match (); // false
- }
-
- internal bool handle_copy_text (out string copy_text)
- {
- if (bookmarks_button.active)
- return bookmarks_button.handle_copy_text (out copy_text);
- return BaseWindow.no_copy_text (out copy_text);
- }
-
- /*\
- * * popovers methods
- \*/
-
- internal override void close_popovers ()
- {
- base.close_popovers ();
- if (bookmarks_button.active)
- bookmarks_button.active = false;
- }
-
- internal override bool has_popover ()
- {
- if (base.has_popover ())
- return true;
- if (bookmarks_button.active)
- return true;
- return false;
- }
}
diff --git a/editor/meson.build b/editor/meson.build
index a47164a..c64b1e2 100644
--- a/editor/meson.build
+++ b/editor/meson.build
@@ -74,6 +74,7 @@ sources = files(
'base-window.vala',
'bookmarks.vala',
'bookmarks-controller.vala',
+ 'bookmarks-headerbar.vala',
'bookmarks-list.vala',
'browser-content.vala',
'browser-headerbar.vala',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]