use strongly typed enum for overlay_mode

This commit is contained in:
Daniel Micay 2012-07-20 11:05:30 -04:00
parent bd4b0bd144
commit 497b8667fa
1 changed files with 14 additions and 14 deletions

View File

@ -14,11 +14,11 @@
// http://blog.dieweltistgarnichtso.net/constructing-a-regular-expression-that-matches-uris // http://blog.dieweltistgarnichtso.net/constructing-a-regular-expression-that-matches-uris
static const char * const url_regex = R"XXX(((?<=\()[A-Za-z][A-Za-z0-9\+\.\-]*:([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+(?=\)))|([A-Za-z][A-Za-z0-9\+\.\-]*:([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+))XXX"; static const char * const url_regex = R"XXX(((?<=\()[A-Za-z][A-Za-z0-9\+\.\-]*:([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+(?=\)))|([A-Za-z][A-Za-z0-9\+\.\-]*:([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+))XXX";
enum overlay_mode { enum class overlay_mode {
OVERLAY_HIDDEN = 0, hidden = 0,
OVERLAY_SEARCH, search,
OVERLAY_RSEARCH, rsearch,
OVERLAY_COMPLETION completion
}; };
enum select_mode { enum select_mode {
@ -261,10 +261,10 @@ gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, keybind_info *info)
vte_terminal_copy_clipboard(vte); vte_terminal_copy_clipboard(vte);
break; break;
case GDK_KEY_slash: case GDK_KEY_slash:
overlay_show(&info->panel, OVERLAY_SEARCH, true); overlay_show(&info->panel, overlay_mode::search, true);
break; break;
case GDK_KEY_question: case GDK_KEY_question:
overlay_show(&info->panel, OVERLAY_RSEARCH, true); overlay_show(&info->panel, overlay_mode::rsearch, true);
break; break;
case GDK_KEY_n: case GDK_KEY_n:
vte_terminal_search_find_next(vte); vte_terminal_search_find_next(vte);
@ -303,7 +303,7 @@ gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, keybind_info *info)
return TRUE; return TRUE;
} }
} else if (modifiers == GDK_CONTROL_MASK && event->keyval == GDK_KEY_Tab) { } else if (modifiers == GDK_CONTROL_MASK && event->keyval == GDK_KEY_Tab) {
overlay_show(&info->panel, OVERLAY_COMPLETION, true); overlay_show(&info->panel, overlay_mode::completion, true);
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -318,23 +318,23 @@ gboolean entry_key_press_cb(GtkEntry *entry, GdkEventKey *event, search_panel_in
const char *text = gtk_entry_get_text(entry); const char *text = gtk_entry_get_text(entry);
switch (info->mode) { switch (info->mode) {
case OVERLAY_SEARCH: case overlay_mode::search:
search(info->vte, text, false); search(info->vte, text, false);
break; break;
case OVERLAY_RSEARCH: case overlay_mode::rsearch:
search(info->vte, text, true); search(info->vte, text, true);
break; break;
case OVERLAY_COMPLETION: case overlay_mode::completion:
vte_terminal_feed_child(info->vte, text, -1); vte_terminal_feed_child(info->vte, text, -1);
break; break;
case OVERLAY_HIDDEN: case overlay_mode::hidden:
break; break;
} }
ret = TRUE; ret = TRUE;
} }
if (ret) { if (ret) {
info->mode = OVERLAY_HIDDEN; info->mode = overlay_mode::hidden;
gtk_widget_hide(info->panel); gtk_widget_hide(info->panel);
gtk_widget_grab_focus(GTK_WIDGET(info->vte)); gtk_widget_grab_focus(GTK_WIDGET(info->vte));
} }
@ -753,7 +753,7 @@ int main(int argc, char **argv) {
search_panel_info panel = {vte, gtk_entry_new(), search_panel_info panel = {vte, gtk_entry_new(),
gtk_alignment_new(0, 0, 1, 1), gtk_alignment_new(0, 0, 1, 1),
OVERLAY_HIDDEN}; overlay_mode::hidden};
keybind_info info = {panel, {SELECT_OFF, 0, 0, 0, 0}, {FALSE, FALSE, FALSE, -1}}; keybind_info info = {panel, {SELECT_OFF, 0, 0, 0, 0}, {FALSE, FALSE, FALSE, -1}};
load_config(GTK_WINDOW(window), vte, &info.config, &term); load_config(GTK_WINDOW(window), vte, &info.config, &term);