Activities can process key events

Commit activity uses <kbd>Ctrl</kbd>+<kbd>Enter</kbd> to launch commit dialog
This commit is contained in:
Alberto Fanjul 2019-10-29 07:40:25 +01:00
parent ada23635b2
commit 81cece0ded
3 changed files with 28 additions and 0 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}
}
}