gui/queue: Add a search entry widget

This gets cleared every time the queue is changed and disabled when we
show pages that cannot be filtered.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-01-15 09:35:25 -05:00
parent 24f53d88b6
commit d19e0b2cc0
5 changed files with 62 additions and 3 deletions

View File

@ -63,6 +63,7 @@ void gui_queue_show(struct gui_queue *queue)
{
GtkButton *random = GTK_BUTTON(gui_builder_widget("o_random"));
GtkButton *repeat = GTK_BUTTON(gui_builder_widget("o_repeat"));
GtkEntry *search = GTK_ENTRY(gui_builder_widget("o_search"));
bool has_random = false, has_repeat = false;
gq_queue = queue;
@ -84,4 +85,7 @@ void gui_queue_show(struct gui_queue *queue)
*/
gtk_widget_set_sensitive(gtk_button_get_image(random), has_random);
gtk_widget_set_sensitive(gtk_button_get_image(repeat), has_repeat);
gtk_widget_set_sensitive(GTK_WIDGET(search), queue != NULL);
gtk_entry_set_text(search, "");
}

View File

@ -405,6 +405,16 @@ static void on_switch_page(Gtk::Widget *page, int num)
Glib :: wrap(GTK_LABEL(gui_builder_widget("o_queue_time")), false)->set_text("");
}
static void on_search_changed()
{
Gtk::SearchEntry *search = Glib :: wrap(GTK_SEARCH_ENTRY(gui_builder_widget("o_search")), false);
std::string text = search->get_text();
Tab *tab = cur_tab();
if (tab)
tab->tab_window->filter(text);
}
void tab_focus_search()
{
int page = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false)->get_current_page();
@ -485,6 +495,10 @@ void init_tabs()
struct Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false);
notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page));
/* Search signals */
Gtk::SearchEntry *search = Glib :: wrap(GTK_SEARCH_ENTRY(gui_builder_widget("o_search")), false);
search->signal_search_changed().connect(sigc::ptr_fun(on_search_changed));
/* Menu signals */
Glib :: wrap(GTK_MENU(gui_builder_widget("o_rc_menu")), false)->show_all();
Glib :: wrap(GTK_MENU_ITEM(gui_builder_widget("o_new_pq")), false)->signal_activate().connect(

View File

@ -22,7 +22,6 @@ protected:
Gtk::VBox tab_vbox;
QueueToolbar *tab_toolbar;
QueueWindow *tab_window;
QueueLabel *tab_label;
/**
@ -32,6 +31,7 @@ protected:
void tab_unmap();
public:
QueueWindow *tab_window;
Tab(queue *);
virtual ~Tab();

View File

@ -842,6 +842,34 @@
<property name="can_focus">False</property>
<property name="margin_left">1</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox" id="box10">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkSearchEntry" id="o_search">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<property name="placeholder_text" translatable="yes">Type here to filter</property>
<accelerator key="slash" signal="grab-focus"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkNotebook" id="o_notebook">
<property name="visible">True</property>
@ -951,7 +979,7 @@ Manager</property>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
@ -1057,7 +1085,7 @@ Manager</property>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
@ -1142,4 +1170,11 @@ Manager</property>
</child>
<accelerator key="Escape" signal="grab-focus"/>
</object>
<object class="GtkSizeGroup" id="sizegroup1">
<property name="mode">vertical</property>
<widgets>
<widget name="buttonbox4"/>
<widget name="box10"/>
</widgets>
</object>
</interface>

View File

@ -30,11 +30,13 @@ static void test_queue()
GtkToggleButton *random, *repeat;
GtkWidget *random_img, *repeat_img;
struct gui_queue *gq;
GtkEntry *search;
struct queue q;
int argc = 0;
gtk_init(&argc, NULL);
gui_builder_init("share/ocarina/ocarina6.glade");
search = GTK_ENTRY(gui_builder_widget("o_search"));
random = GTK_TOGGLE_BUTTON(gui_builder_widget("o_random"));
repeat = GTK_TOGGLE_BUTTON(gui_builder_widget("o_repeat"));
random_img = gtk_button_get_image(GTK_BUTTON(random));
@ -50,6 +52,8 @@ static void test_queue()
test_equal(gui_queue_can_random(NULL), (bool)false);
test_equal(gui_queue_can_repeat(NULL), (bool)false);
gtk_entry_set_text(search, "Test text");
/* Show a queue where random and repeat are disabled */
gui_queue_show(gq);
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), false);
@ -58,6 +62,7 @@ static void test_queue()
test_equal(gtk_toggle_button_get_active(repeat), false);
test_equal(gtk_widget_get_sensitive(random_img), false);
test_equal(gtk_widget_get_sensitive(repeat_img), false);
test_equal(gtk_entry_get_text(search), "");
/* Test clicking random button. */
gtk_toggle_button_set_active(random, true);
@ -90,6 +95,7 @@ static void test_queue()
/* Attempt to show a NULL pointer */
gui_queue_show(NULL);
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(search)), false);
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), false);
test_equal(gtk_widget_get_sensitive(GTK_WIDGET(repeat)), false);
test_equal(gtk_toggle_button_get_active(random), false);