Merge pull request #60 from numerical/master

Quick URL selection in the urlselection overlay
This commit is contained in:
Daniel Micay 2013-02-19 23:14:48 -08:00
commit edcc2887e9
1 changed files with 40 additions and 2 deletions

View File

@ -69,7 +69,7 @@ struct hint_info {
struct config_info { struct config_info {
hint_info hints; hint_info hints;
char *browser; char *browser;
gboolean dynamic_title, urgent_on_bell, clickable_url; gboolean dynamic_title, urgent_on_bell, clickable_url, quick_url;
int tag; int tag;
char *config_file; char *config_file;
}; };
@ -746,6 +746,43 @@ gboolean entry_key_press_cb(GtkEntry *entry, GdkEventKey *event, keybind_info *i
gboolean ret = FALSE; gboolean ret = FALSE;
switch (event->keyval) { switch (event->keyval) {
case GDK_KEY_0:
case GDK_KEY_1:
case GDK_KEY_2:
case GDK_KEY_3:
case GDK_KEY_4:
case GDK_KEY_5:
case GDK_KEY_6:
case GDK_KEY_7:
case GDK_KEY_8:
case GDK_KEY_9:
if(info->panel.mode == overlay_mode::urlselect && info->config.quick_url)
{
const char *const text = gtk_entry_get_text(entry);
char* fulltext = g_strndup(text, strlen(text)+1);
fulltext[strlen(text)] = (char)event->keyval;
gboolean exalpha = FALSE;
for(int i = 0; text[i] != '\0'; i++) {
if(!g_ascii_isdigit(text[i])) {
exalpha = TRUE;
break;
}
}
if(exalpha)
break;
char* str_ptr = (char*)malloc(sizeof(text));
sprintf(str_ptr, "%d", (int)info->panel.url_list.size());
int url_num = (int)strlen(str_ptr);
delete str_ptr;
int inp_num = (int)strlen(fulltext);
if(url_num == inp_num)
{
launch_url(info->config.browser, fulltext, &info->panel);
ret = TRUE;
}
}
break;
case GDK_KEY_Tab: case GDK_KEY_Tab:
synthesize_keypress(GTK_WIDGET(entry), GDK_KEY_Down); synthesize_keypress(GTK_WIDGET(entry), GDK_KEY_Down);
return TRUE; return TRUE;
@ -1088,6 +1125,7 @@ static void set_config(GtkWindow *window, VteTerminal *vte, config_info *info,
info->dynamic_title = cfg_bool("dynamic_title", TRUE); info->dynamic_title = cfg_bool("dynamic_title", TRUE);
info->urgent_on_bell = cfg_bool("urgent_on_bell", TRUE); info->urgent_on_bell = cfg_bool("urgent_on_bell", TRUE);
info->clickable_url = cfg_bool("clickable_url", TRUE); info->clickable_url = cfg_bool("clickable_url", TRUE);
info->quick_url = cfg_bool("quick_url", FALSE);
if (info->clickable_url) { if (info->clickable_url) {
info->tag = info->tag =
@ -1268,7 +1306,7 @@ int main(int argc, char **argv) {
std::vector<url_data>()}, std::vector<url_data>()},
{vi_mode::insert, 0, 0, 0, 0}, {vi_mode::insert, 0, 0, 0, 0},
{{nullptr, nullptr, nullptr, nullptr, 0, 0, 0}, {{nullptr, nullptr, nullptr, nullptr, 0, 0, 0},
nullptr, FALSE, FALSE, FALSE, -1, config_file} nullptr, FALSE, FALSE, FALSE, FALSE, -1, config_file}
}; };
load_config(GTK_WINDOW(window), vte, &info.config, &geometry); load_config(GTK_WINDOW(window), vte, &info.config, &geometry);