[dconf-editor] Add help methods.



commit 29ea91b98ab7c0431da82a1c75b39ed76482f318
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Aug 4 12:23:00 2019 +0200

    Add help methods.
    
    Sync a bit with Taquin.

 editor/base-window.vala  | 36 +++++++++++++++++++++++++++++++++---
 editor/dconf-window.vala |  1 +
 2 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/editor/base-window.vala b/editor/base-window.vala
index bff6732..4dc64c0 100644
--- a/editor/base-window.vala
+++ b/editor/base-window.vala
@@ -103,6 +103,8 @@ private class BaseWindow : AdaptativeWindow, AdaptativeWidget
         { "menu",               menu_pressed        },  // Menu
 
         { "show-default-view",  show_default_view   },
+
+        { "help",               help                },
         { "about",              about               }
     };
 
@@ -280,12 +282,14 @@ private class BaseWindow : AdaptativeWindow, AdaptativeWidget
     * * global callbacks
     \*/
 
+    [CCode (notify = false)] public string help_string_or_empty { private get; protected construct; default 
= ""; }
+
     [GtkCallback]
     protected virtual bool on_key_press_event (Widget widget, Gdk.EventKey event)
     {
-        return _on_key_press_event (widget, event);
+        return _on_key_press_event (widget, event, help_string_or_empty);
     }
-    private static bool _on_key_press_event (Widget widget, Gdk.EventKey event)
+    private static bool _on_key_press_event (Widget widget, Gdk.EventKey event, string help_string_or_empty)
     {
         string name = (!) (Gdk.keyval_name (event.keyval) ?? "");
 
@@ -295,8 +299,10 @@ private class BaseWindow : AdaptativeWindow, AdaptativeWidget
 
             _this.headerbar.close_popovers ();
             _this.main_view.close_popovers ();
+            if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0)
+                return false;                           // help overlay
             if ((event.state & Gdk.ModifierType.SHIFT_MASK) == 0)
-                return false;   // help overlay
+                return show_application_help (_this, help_string_or_empty);   // fallback on help overlay 
(TODO test)
             _this.about ();
             return true;
         }
@@ -304,6 +310,30 @@ private class BaseWindow : AdaptativeWindow, AdaptativeWidget
         return false;
     }
 
+    private void help (/* SimpleAction action, Variant? variant */)
+    {
+        show_application_help (this, help_string_or_empty);
+    }
+
+    private static inline bool show_application_help (BaseWindow _this, string help_string_or_empty)
+    {
+        if (help_string_or_empty == "")
+            return false;
+
+        bool success;
+        try
+        {
+            show_uri (_this.get_screen (), help_string_or_empty, get_current_event_time ());
+            success = true;
+        }
+        catch (Error e)
+        {
+            warning ("Failed to show help: %s", e.message);
+            success = false;
+        }
+        return success;
+    }
+
     /*\
     * * adaptative stuff
     \*/
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index ce6197d..defbb23 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -52,6 +52,7 @@ private class DConfWindow : BookmarksWindow, AdaptativeWidget
                 base_view                   : (BaseView) _main_view,
                 window_title                : ConfigurationEditor.PROGRAM_NAME,
                 specific_css_class_or_empty : "dconf-editor",
+                help_string_or_empty        : "",
                 schema_path                 : "/ca/desrt/dconf-editor/");
 
         model = _model;


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