replace search_direction enum with a bool

This commit is contained in:
Daniel Micay 2012-05-30 04:29:25 -04:00
parent 2a225520e8
commit bce40a4666
1 changed files with 8 additions and 13 deletions

View File

@ -15,25 +15,20 @@
# define __attribute__(x) # define __attribute__(x)
#endif #endif
enum search_direction {
search_forward,
search_backward
};
typedef struct search_dialog_info { typedef struct search_dialog_info {
GtkWidget *vte; GtkWidget *vte;
GtkWidget *entry; GtkWidget *entry;
enum search_direction direction; bool reverse;
bool open; bool open;
} search_dialog_info; } search_dialog_info;
static void search(VteTerminal *vte, const char *pattern, enum search_direction direction) { static void search(VteTerminal *vte, const char *pattern, bool reverse) {
GRegex *regex = vte_terminal_search_get_gregex(vte); GRegex *regex = vte_terminal_search_get_gregex(vte);
if (regex) g_regex_unref(regex); if (regex) g_regex_unref(regex);
regex = g_regex_new(pattern, 0, 0, NULL); regex = g_regex_new(pattern, 0, 0, NULL);
vte_terminal_search_set_gregex(vte, regex); vte_terminal_search_set_gregex(vte, regex);
if (direction == search_forward) { if (!reverse) {
vte_terminal_search_find_next(vte); vte_terminal_search_find_next(vte);
} else { } else {
vte_terminal_search_find_previous(vte); vte_terminal_search_find_previous(vte);
@ -42,15 +37,15 @@ static void search(VteTerminal *vte, const char *pattern, enum search_direction
static void search_response_cb(GtkDialog *dialog, gint response_id, search_dialog_info *info) { static void search_response_cb(GtkDialog *dialog, gint response_id, search_dialog_info *info) {
if (response_id == GTK_RESPONSE_ACCEPT) { if (response_id == GTK_RESPONSE_ACCEPT) {
search(VTE_TERMINAL(info->vte), gtk_entry_get_text(GTK_ENTRY(info->entry)), info->direction); search(VTE_TERMINAL(info->vte), gtk_entry_get_text(GTK_ENTRY(info->entry)), info->reverse);
} }
gtk_widget_destroy(GTK_WIDGET(dialog)); gtk_widget_destroy(GTK_WIDGET(dialog));
info->open = false; info->open = false;
} }
static void open_search_dialog(GtkWidget *vte, enum search_direction direction, search_dialog_info *info) { static void open_search_dialog(GtkWidget *vte, bool reverse, search_dialog_info *info) {
info->direction = direction; info->reverse = reverse;
if (info->open) { if (info->open) {
return; return;
@ -94,10 +89,10 @@ static gboolean key_press_cb(GtkWidget *vte, GdkEventKey *event, search_dialog_i
vte_terminal_search_find_next(VTE_TERMINAL(vte)); vte_terminal_search_find_next(VTE_TERMINAL(vte));
return TRUE; return TRUE;
case GDK_f: case GDK_f:
open_search_dialog(vte, search_forward, info); open_search_dialog(vte, false, info);
return TRUE; return TRUE;
case GDK_b: case GDK_b:
open_search_dialog(vte, search_backward, info); open_search_dialog(vte, true, info);
return TRUE; return TRUE;
} }
} }