[dconf-editor] Better pathbar notifications.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Better pathbar notifications.
- Date: Wed, 14 Feb 2018 04:44:26 +0000 (UTC)
commit 1fd3a64eaca09ba8e3daa2b4306ad22f0eed878f
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed Feb 14 05:42:30 2018 +0100
Better pathbar notifications.
editor/dconf-window.vala | 23 ++++++++++++++++++++++-
editor/pathbar.ui | 1 +
editor/pathbar.vala | 39 ++++++++++++++++++++++++++++++++-------
3 files changed, 55 insertions(+), 8 deletions(-)
---
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 17ba4bf..3ef92e6 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -362,7 +362,10 @@ class DConfWindow : ApplicationWindow
private const GLib.ActionEntry [] action_entries =
{
- { "empty", empty , "*" },
+ { "empty", empty, "*" },
+
+ { "notify-folder-emptied", notify_folder_emptied, "s" },
+ { "notify-object-deleted", notify_object_deleted, "(ss)" },
{ "open-folder", open_folder, "s" },
{ "open-object", open_object, "(ss)" },
@@ -387,6 +390,24 @@ class DConfWindow : ApplicationWindow
private void empty (/* SimpleAction action, Variant? variant */) {}
+ private void notify_folder_emptied (SimpleAction action, Variant? path_variant)
+ requires (path_variant != null)
+ {
+ string full_name = ((!) path_variant).get_string ();
+
+ show_notification (_("Folder ā%sā is now empty.").printf (full_name));
+ }
+
+ private void notify_object_deleted (SimpleAction action, Variant? path_variant)
+ requires (path_variant != null)
+ {
+ string full_name;
+ string unused; // GAction parameter type switch is a little touchy, see pathbar.vala
+ ((!) path_variant).@get ("(ss)", out full_name, out unused);
+
+ show_notification (_("Key ā%sā has been deleted.").printf (full_name));
+ }
+
private void open_folder (SimpleAction action, Variant? path_variant)
requires (path_variant != null)
{
diff --git a/editor/pathbar.ui b/editor/pathbar.ui
index 6bd1315..30f70cc 100644
--- a/editor/pathbar.ui
+++ b/editor/pathbar.ui
@@ -10,6 +10,7 @@
<object class="PathBarItem" id="root_button">
<property name="visible">True</property>
<property name="action-name">ui.open-folder</property>
+ <property name="alternative-action">ui.open-folder('/')</property>
<property name="default-action">ui.open-folder('/')</property>
<property name="action-target">'/'</property>
<style>
diff --git a/editor/pathbar.vala b/editor/pathbar.vala
index 242140b..3c38a12 100644
--- a/editor/pathbar.vala
+++ b/editor/pathbar.vala
@@ -120,6 +120,7 @@ public class PathBar : Box
{
string action_target = "";
@foreach ((child) => {
+ StyleContext context = child.get_style_context ();
if (child is PathBarItem)
{
PathBarItem item = (PathBarItem) child;
@@ -133,9 +134,27 @@ public class PathBar : Box
string unused;
((!) variant).get ("(ss)", out action_target, out unused);
}
+
+ if (non_ghost_path == action_target)
+ {
+ item.cursor_type = PathBarItem.CursorType.CONTEXT;
+ item.set_action_name ("ui.empty");
+ context.remove_class ("inexistent");
+ }
+ else if (non_ghost_path.has_prefix (action_target))
+ {
+ item.cursor_type = PathBarItem.CursorType.POINTER;
+ item.set_detailed_action_name (item.default_action);
+ context.remove_class ("inexistent");
+ }
+ else
+ {
+ item.cursor_type = PathBarItem.CursorType.DEFAULT;
+ item.set_detailed_action_name (item.alternative_action);
+ context.add_class ("inexistent");
+ }
}
- StyleContext context = child.get_style_context ();
- if (non_ghost_path.has_prefix (action_target))
+ else if (non_ghost_path.has_prefix (action_target))
context.remove_class ("inexistent");
else
context.add_class ("inexistent");
@@ -157,12 +176,14 @@ public class PathBar : Box
if (is_folder)
{
Variant variant = new Variant.string (complete_path);
- path_bar_item = new PathBarItem (label, "ui.open-folder(" + variant.print (false) + ")");
+ string _variant = variant.print (false);
+ path_bar_item = new PathBarItem (label, "ui.open-folder(" + _variant + ")",
"ui.notify-folder-emptied(" + _variant + ")");
}
else
{
Variant variant = new Variant ("(ss)", complete_path, "");
- path_bar_item = new PathBarItem (label, "ui.open-object(" + variant.print (false) + ")");
+ string _variant = variant.print (false);
+ path_bar_item = new PathBarItem (label, "ui.open-object(" + _variant + ")",
"ui.notify-object-deleted(" + _variant + ")");
}
add (path_bar_item);
activate_item (path_bar_item, block); // has to be after add()
@@ -191,6 +212,7 @@ public class PathBar : Box
[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/pathbar-item.ui")]
private class PathBarItem : Button
{
+ public string alternative_action { get; construct; }
public string default_action { get; construct; }
public string text_string { get; construct; }
[GtkChild] private Label text_label;
@@ -228,6 +250,9 @@ private class PathBarItem : Button
[GtkCallback]
private void update_cursor ()
{
+ if (get_style_context ().has_class ("inexistent"))
+ return;
+
if (cursor_type != CursorType.CONTEXT)
{
cursor_type = CursorType.CONTEXT;
@@ -243,10 +268,10 @@ private class PathBarItem : Button
popover_test.popup ();
}
- public PathBarItem (string label, string action)
+ public PathBarItem (string label, string _default_action, string _alternative_action)
{
- Object (text_string: label, default_action: action);
+ Object (text_string: label, default_action: _default_action, alternative_action:
_alternative_action);
text_label.set_text (label);
- set_detailed_action_name (action);
+ set_detailed_action_name (_default_action);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]