Add shortcuts for history panels

This commit is contained in:
Alberto Fanjul 2020-02-05 01:44:42 +01:00
parent 127e92c902
commit 5327c161e7
5 changed files with 51 additions and 3 deletions

View File

@ -357,11 +357,11 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
d_infobar.hide();
});
unowned Gtk.BindingSet bset = Gtk.BindingSet.by_class(get_class());
unowned Gtk.BindingSet binding_set = Gtk.BindingSet.by_class(get_class());
for (int i = 0; i < 10; i++)
{
Gtk.BindingEntry.add_signal(bset,
Gtk.BindingEntry.add_signal(binding_set,
(Gdk.Key.@0 + i),
Gdk.ModifierType.MOD1_MASK,
"change-to-activity",
@ -370,7 +370,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
i);
}
Gtk.BindingEntry.add_signal(bset,
Gtk.BindingEntry.add_signal(binding_set,
Gdk.Key.Escape,
0,
"cancel",

View File

@ -584,6 +584,22 @@ namespace GitgHistory
d_panels = new Gitg.UIElements<GitgExt.HistoryPanel>(extset,
d_main.stack_panel);
unowned Gtk.BindingSet binding_set = Gtk.BindingSet.by_class(get_class());
foreach(var element in d_panels.get_available_elements()) {
GitgExt.HistoryPanel panel = (GitgExt.HistoryPanel)element;
uint? key = panel.shortcut;
if (key != null) {
Gtk.BindingEntry.add_signal(binding_set,
key,
Gdk.ModifierType.MOD1_MASK,
"change-to-panel",
1,
typeof(string),
element.id);
}
};
d_refs_list_popup = new Gitg.PopupMenu(d_main.refs_list);
d_refs_list_popup.populate_menu.connect(on_refs_list_populate_menu);
@ -605,6 +621,17 @@ namespace GitgHistory
d_commit_list_model.end_clear.connect(on_commit_model_end_clear);
}
[Signal(action = true)]
public virtual signal bool change_to_panel(string id)
{
var panel = d_panels.lookup(id);
if (panel != null) {
panel.activate();
}
return true;
}
private void update_walker_idle()
{
if (d_repository == null)

View File

@ -42,6 +42,17 @@ public interface HistoryPanel : Object, UIElement
* is created.
*/
public abstract GitgExt.History? history { owned get; construct set; }
/**
* The ui element shortcut.
*
* If provided, the key to mix with Gdk.ModifierType.MOD1_MASK to enable
* this element
*/
public virtual uint? shortcut
{
owned get { return null; }
}
}
}

View File

@ -32,6 +32,11 @@ namespace GitgDiff
private ulong d_selection_changed_id;
public virtual uint? shortcut
{
owned get { return Gdk.Key.d; }
}
protected override void constructed()
{
base.constructed();

View File

@ -48,6 +48,11 @@ namespace GitgFiles
history.selection_changed.connect(on_selection_changed);
}
public virtual uint? shortcut
{
owned get { return Gdk.Key.f; }
}
public string id
{
owned get { return "/org/gnome/gitg/Panels/Files"; }