mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-11-04 23:34:39 +00:00
Add shortcuts and buttons to navigate through search results
This commit is contained in:
parent
23afe668e8
commit
287e925cbc
5 changed files with 131 additions and 4 deletions
|
@ -90,6 +90,10 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
|
|||
private unowned Gtk.SearchBar d_search_bar;
|
||||
[GtkChild]
|
||||
private unowned Gtk.SearchEntry d_search_entry;
|
||||
[GtkChild]
|
||||
private unowned Gtk.Button d_search_up_button;
|
||||
[GtkChild]
|
||||
private unowned Gtk.Button d_search_down_button;
|
||||
|
||||
[GtkChild]
|
||||
private unowned Gtk.Stack d_main_stack;
|
||||
|
@ -247,12 +251,25 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
|
|||
d_search_entry.text = searchable.search_text;
|
||||
searchable.search_visible = true;
|
||||
searchable.search_entry = d_search_entry;
|
||||
var has_text = d_search_entry.text.length > 0;
|
||||
d_search_up_button.set_sensitive(has_text);
|
||||
d_search_down_button.set_sensitive(has_text);
|
||||
}
|
||||
else
|
||||
{
|
||||
searchable.search_visible = false;
|
||||
searchable.search_entry = null;
|
||||
d_search_up_button.set_sensitive(false);
|
||||
d_search_down_button.set_sensitive(false);
|
||||
}
|
||||
|
||||
var show_buttons = false;
|
||||
if (current_activity is GitgExt.Searchable)
|
||||
{
|
||||
show_buttons = searchable.show_buttons();
|
||||
}
|
||||
d_search_up_button.set_visible(show_buttons);
|
||||
d_search_down_button.set_visible(show_buttons);
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
|
@ -264,6 +281,9 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
|
|||
if (ntext != searchable.search_text)
|
||||
{
|
||||
searchable.search_text = ntext;
|
||||
var has_text = ntext.length > 0;
|
||||
d_search_up_button.set_sensitive(has_text);
|
||||
d_search_down_button.set_sensitive(has_text);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,6 +298,18 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
|
|||
return ret;
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
private void search_up_clicked(Gtk.Button button)
|
||||
{
|
||||
search_move(true);
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
private void search_down_clicked(Gtk.Button button)
|
||||
{
|
||||
search_move(false);
|
||||
}
|
||||
|
||||
construct
|
||||
{
|
||||
if (Gitg.PlatformSupport.use_native_window_controls())
|
||||
|
@ -1364,6 +1396,16 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
|
|||
{
|
||||
owned get { return d_notifications; }
|
||||
}
|
||||
|
||||
private void search_move(bool up)
|
||||
{
|
||||
if (current_activity is GitgExt.Searchable)
|
||||
{
|
||||
var searchable = current_activity as GitgExt.Searchable;
|
||||
var key = d_search_entry.text;
|
||||
searchable.search_move(key, up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1257,6 +1257,36 @@ namespace GitgHistory
|
|||
|
||||
public string search_text { owned get; set; default = ""; }
|
||||
public bool search_visible { get; set; }
|
||||
|
||||
public override void search_move(string key, bool up)
|
||||
{
|
||||
// Move the tree selection by sending key press event,
|
||||
// see: https://gitlab.gnome.org/GNOME/gtk/merge_requests/1167
|
||||
var search_entry = d_main.commit_list_view.get_search_entry();
|
||||
var keyval = up ? Gdk.Key.Up : Gdk.Key.Down;
|
||||
|
||||
Gdk.KeymapKey[] keys;
|
||||
if(!Gdk.Keymap.get_for_display(search_entry.get_display()).get_entries_for_keyval(keyval, out keys))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
search_entry.grab_focus();
|
||||
|
||||
Gdk.EventKey* event = new Gdk.Event(Gdk.EventType.KEY_PRESS);
|
||||
event->window = search_entry.get_window();
|
||||
event->keyval = keyval;
|
||||
event->hardware_keycode = (uint16) keys[0].keycode;
|
||||
event->group = (uint8) keys[0].group;
|
||||
((Gdk.Event*) event)->put();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public override bool show_buttons()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,20 @@
|
|||
<property name="title" translatable="yes" context="shortcut window">Find</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut">
|
||||
<property name="visible">true</property>
|
||||
<property name="accelerator"><primary>G</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Move to next search result</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut">
|
||||
<property name="visible">true</property>
|
||||
<property name="accelerator"><primary><shift>G</property>
|
||||
<property name="title" translatable="yes" context="shortcut window">Move to previous search result</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkShortcutsShortcut">
|
||||
<property name="visible">true</property>
|
||||
|
|
|
@ -247,11 +247,50 @@
|
|||
<property name="can_focus">False</property>
|
||||
<property name="show-close-button">False</property>
|
||||
<child>
|
||||
<object class="GtkSearchEntry" id="d_search_entry">
|
||||
<object class="GtkBox" id="d_search_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="width-request">500</property>
|
||||
<signal name="changed" handler="search_entry_changed" swapped="no"/>
|
||||
<property name="orientation">horizontal</property>
|
||||
<style>
|
||||
<class name="linked"/>
|
||||
</style>
|
||||
<child>
|
||||
<object class="GtkSearchEntry" id="d_search_entry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="width-request">500</property>
|
||||
<signal name="changed" handler="search_entry_changed" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="d_search_up_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<signal name="clicked" handler="search_up_clicked" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkImage" id="up_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_size">1</property>
|
||||
<property name="icon_name">go-up-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="d_search_down_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<signal name="clicked" handler="search_down_clicked" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkImage" id="down_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_size">1</property>
|
||||
<property name="icon_name">go-down-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
|
|
@ -32,6 +32,8 @@ public interface Searchable : Object, Activity
|
|||
public abstract bool search_visible { get; set; }
|
||||
public abstract bool search_available { get; }
|
||||
public abstract Gtk.Entry? search_entry { set; }
|
||||
public virtual void search_move(string key, bool up) {}
|
||||
public virtual bool show_buttons() { return false; }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue