[gitg/wip/albfan/commit-mesage-history: 6/7] Activities can process key events



commit 81cece0ded79825f19cd38246c0737c0e9b33b88
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Tue Oct 29 07:40:25 2019 +0100

    Activities can process key events
    
    Commit activity uses <kbd>Ctrl</kbd>+<kbd>Enter</kbd> to launch commit dialog

 gitg/commit/gitg-commit.vala       | 14 ++++++++++++++
 gitg/gitg-window.vala              |  2 ++
 libgitg-ext/gitg-ext-activity.vala | 12 ++++++++++++
 3 files changed, 28 insertions(+)
---
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index e7ff51c8..e3c966f3 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -141,6 +141,20 @@ namespace GitgCommit
                        return action == "commit";
                }
 
+               public bool on_key_pressed (Gdk.EventKey event) {
+                       var mmask = Gtk.accelerator_get_default_mod_mask();
+
+                       if ((mmask & event.state) == Gdk.ModifierType.CONTROL_MASK)
+                       {
+                               if ((event.keyval == Gdk.Key.Return || event.keyval == Gdk.Key.KP_Enter))
+                               {
+                                       on_commit_clicked ();
+                                       return true;
+                               }
+                       }
+                       return false;
+               }
+
                private delegate void StageUnstageCallback(Sidebar.Item item);
                private delegate void StageUnstageSubmoduleCommitCallback(Gitg.Commit commit);
 
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 8d995454..ca640d5b 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -271,6 +271,8 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                bool ret = d_search_bar.handle_event(event);
                if (ret) {
                        d_search_bar.search_mode_enabled = true;
+               } else {
+                       ret = d_activities.current.on_key_pressed(event);
                }
                return ret;
        }
diff --git a/libgitg-ext/gitg-ext-activity.vala b/libgitg-ext/gitg-ext-activity.vala
index 23528f05..b2adf6ff 100644
--- a/libgitg-ext/gitg-ext-activity.vala
+++ b/libgitg-ext/gitg-ext-activity.vala
@@ -41,6 +41,18 @@ public interface Activity : Object, UIElement
        {
                return false;
        }
+
+       /**
+        * Activity receives a key event to process it.
+        *
+        * @param event the key event
+        *
+        * @return true if the key event is consumed by this activity.
+        */
+       public virtual bool on_key_pressed (Gdk.EventKey event)
+       {
+               return false;
+       }
 }
 
 }


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