📄 dialogs.c
字号:
} option = item->udata; if (!(option->flags & OPT_AUTOCREATE)) { if (option->root) option = option->root; if (!option || !(option->flags & OPT_AUTOCREATE)) goto invalid_option; } input_dialog(term, NULL, N_("Add option"), N_("Name"), option, NULL, MAX_STR_LEN, "", 0, 0, check_nonempty, add_option_to_tree, NULL); return EVENT_PROCESSED;}static t_handler_event_statuspush_save_button(struct dialog_data *dlg_data, struct widget_data *some_useless_info_button){ write_config(dlg_data->win->term); update_hierbox_browser(&option_browser); return EVENT_PROCESSED;}#define OPTION_MANAGER_BUTTONS 5static struct hierbox_browser_button option_buttons[] = { { N_("~Info"), push_hierbox_info_button, 1 }, { N_("~Edit"), push_edit_button, 0 }, { N_("~Add"), push_add_button, 0 }, { N_("~Delete"), push_hierbox_delete_button, 0 }, { N_("~Search"), push_hierbox_search_button, 1 }, { N_("Sa~ve"), push_save_button, 0 },};struct_hierbox_browser( option_browser, N_("Option manager"), option_buttons, &options_listbox_ops);/* Builds the "Options manager" dialog */voidoptions_manager(struct session *ses){ hierbox_browser(&option_browser, ses);}/**************************************************************************** Keybinding manager stuff.****************************************************************************/#ifdef CONFIG_SMALLstatic int keybinding_text_toggle = 1;#elsestatic int keybinding_text_toggle;#endif/* XXX: ACTION_BOX_SIZE is just a quick hack, we ought to allocate * the sub-arrays separately. --pasky */#define ACTION_BOX_SIZE 128static struct listbox_item *action_box_items[KEYMAP_MAX][ACTION_BOX_SIZE];struct listbox_item *get_keybinding_action_box_item(enum keymap km, int action){ assert(action < ACTION_BOX_SIZE); if_assert_failed return NULL; return action_box_items[km][action];}struct keymap_box_item_info { struct listbox_item *box_item; struct strtonum *first, *last;};struct keymap_box_item_info keymap_box_item_info[KEYMAP_MAX];voidinit_keybinding_listboxes(struct strtonum *keymaps, struct strtonum *actions[]){ struct listbox_item *root = &keybinding_browser.root; struct strtonum *act, *map; /* Do it backwards because add_listbox_item() add to front * of list. */ for (map = keymaps; map->str; map++) { struct listbox_item *keymap; keymap = add_listbox_item(NULL, root, BI_FOLDER, map, -1); if (!keymap) continue; keymap_box_item_info[map->num].box_item = keymap; for (act = actions[map->num]; act->str; act++) { struct listbox_item *item; assert(act->num < ACTION_BOX_SIZE); if_assert_failed continue; if (act->num == ACT_MAIN_SCRIPTING_FUNCTION || act->num == ACT_MAIN_NONE) continue;#ifndef CONFIG_SMALL assert(act->desc);#endif item = add_listbox_item(NULL, keymap, BI_FOLDER, act, -1); if (!item) continue; item->expanded = 1; action_box_items[map->num][act->num] = item; } keymap_box_item_info[map->num].first = actions[map->num]; keymap_box_item_info[map->num].last = act; }}voiddone_keybinding_listboxes(void){ struct listbox_item *action; foreach (action, keybinding_browser.root.child) { struct listbox_item *keymap; foreach (keymap, action->child) { free_list(keymap->child); } free_list(action->child); } free_list(keybinding_browser.root.child);}/* Implementation of the listbox operations *//* XXX: If anything but delete button will use these object_*() requiring * functions we have to check if it is action or keymap box items. */static voidlock_keybinding(struct listbox_item *item){ if (item->depth == 2) object_lock((struct keybinding *) item->udata);}static voidunlock_keybinding(struct listbox_item *item){ if (item->depth == 2) object_unlock((struct keybinding *) item->udata);}static intis_keybinding_used(struct listbox_item *item){ if (item->depth == 2) return 0; return is_object_used((struct keybinding *) item->udata);}static unsigned char *get_keybinding_text(struct listbox_item *item, struct terminal *term){ struct keybinding *keybinding = item->udata; unsigned char *keymap; struct string info; if (item->depth < 2) { struct strtonum *strtonum = item->udata; keymap = keybinding_text_toggle ? strtonum->str : _(strtonum->desc, term); return stracpy(keymap); } if (!init_string(&info)) return NULL; make_keystroke(&info, keybinding->key, keybinding->meta, 0); return info.source;}static unsigned char *get_keybinding_info(struct listbox_item *item, struct terminal *term){ struct keybinding *keybinding = item->udata; unsigned char *action, *keymap; struct string info; if (item->depth < 2) return NULL; if (item->type == BI_FOLDER) return NULL; if (!init_string(&info)) return NULL; action = write_action(keybinding->keymap, keybinding->action); keymap = write_keymap(keybinding->keymap); add_format_to_string(&info, "%s: ", _("Keystroke", term)); make_keystroke(&info, keybinding->key, keybinding->meta, 0); add_format_to_string(&info, "\n%s: %s", _("Action", term), action); add_format_to_string(&info, "\n%s: %s", _("Keymap", term), keymap); return info.source;}static struct listbox_item *get_keybinding_root(struct listbox_item *item){ /* .. at the bottom */ if (item->depth == 0) return NULL; if (item->depth == 1) { struct strtonum *action = item->udata; int keymap; for (keymap = 0; keymap < KEYMAP_MAX; keymap++) { if (keymap_box_item_info[keymap].first <= action && keymap_box_item_info[keymap].last > action) return keymap_box_item_info[keymap].box_item; } return NULL; } else { struct keybinding *kb = item->udata; return get_keybinding_action_box_item(kb->keymap, kb->action); }}static enum listbox_matchmatch_keybinding(struct listbox_item *item, struct terminal *term, unsigned char *text){ struct strtonum *strtonum = item->udata; unsigned char *desc; if (item->depth != 1) return LISTBOX_MATCH_IMPOSSIBLE; desc = keybinding_text_toggle ? strtonum->str : _(strtonum->desc, term); if ((desc && strcasestr(desc, text))) return LISTBOX_MATCH_OK; return LISTBOX_MATCH_NO;}static intcan_delete_keybinding(struct listbox_item *item){ return item->depth == 2;}static voiddelete_keybinding_item(struct listbox_item *item, int last){ struct keybinding *keybinding = item->udata; assert(item->depth == 2 && !is_object_used(keybinding)); free_keybinding(keybinding);}static struct listbox_ops keybinding_listbox_ops = { lock_keybinding, unlock_keybinding, is_keybinding_used, get_keybinding_text, get_keybinding_info, NULL, get_keybinding_root, match_keybinding, can_delete_keybinding, delete_keybinding_item, NULL, NULL,};struct kbdbind_add_hop { struct terminal *term; int action, keymap; long key, meta;};struct kbdbind_add_hop *new_hop_from(struct kbdbind_add_hop *hop) { struct kbdbind_add_hop *new_hop = mem_alloc(sizeof(*new_hop)); if (new_hop) copy_struct(new_hop, hop); return new_hop;}static voidreally_really_add_keybinding(void *data){ struct kbdbind_add_hop *hop = data; assert(hop); add_keybinding(hop->keymap, hop->action, hop->key, hop->meta, 0);}static voidreally_add_keybinding(void *data, unsigned char *keystroke){ struct kbdbind_add_hop *hop = data; int action; if (keybinding_exists(hop->keymap, hop->key, hop->meta, &action) && action != ACT_MAIN_NONE) { struct kbdbind_add_hop *new_hop; /* Same keystroke for same action, just return. */ if (action == hop->action) return; new_hop = new_hop_from(hop); if (!new_hop) return; /* out of mem */ msg_box(new_hop->term, getml(new_hop, NULL), MSGBOX_FREE_TEXT, N_("Keystroke already used"), ALIGN_CENTER, msg_text(new_hop->term, N_("The keystroke \"%s\" " "is currently used for \"%s\".\n" "Are you sure you want to replace it?"), keystroke, write_action(hop->keymap, action)), new_hop, 2, N_("~Yes"), really_really_add_keybinding, B_ENTER, N_("~No"), NULL, B_ESC); return; } really_really_add_keybinding((void *) hop);}t_handler_event_statuscheck_keystroke(struct dialog_data *dlg_data, struct widget_data *widget_data){ struct kbdbind_add_hop *hop = dlg_data->dlg->udata2; unsigned char *keystroke = widget_data->cdata; if (parse_keystroke(keystroke, &hop->key, &hop->meta) >= 0) return EVENT_PROCESSED; info_box(hop->term, 0, N_("Add keybinding"), ALIGN_CENTER, N_("Invalid keystroke.")); return EVENT_NOT_PROCESSED;}static t_handler_event_statuspush_kbdbind_add_button(struct dialog_data *dlg_data, struct widget_data *some_useless_info_button){ struct terminal *term = dlg_data->win->term; struct listbox_data *box = get_dlg_listbox_data(dlg_data); struct listbox_item *item = box->sel; struct kbdbind_add_hop *hop; unsigned char *text; if (!item || !item->depth) { info_box(term, 0, N_("Add keybinding"), ALIGN_CENTER, N_("Need to select a keymap.")); return EVENT_PROCESSED; } hop = mem_calloc(1, sizeof(*hop)); if (!hop) return EVENT_PROCESSED; hop->term = term; if (item->depth == 2) { struct keybinding *keybinding = item->udata; hop->action = keybinding->action; hop->keymap = keybinding->keymap; } else { struct strtonum *strtonum = item->udata; hop->action = strtonum->num; item = get_keybinding_root(item); if (!item) { mem_free(hop); return EVENT_PROCESSED; } strtonum = item->udata; hop->keymap = strtonum->num; } text = msg_text(term, "Action: %s\n" "Keymap: %s\n" "\n" "Keystroke should be written in the format: " "[Prefix-]Key\n" "Prefix: Shift, Ctrl, Alt\n" "Key: a,b,c,...,1,2,3,...,Space,Up,PageDown," "Tab,Enter,Insert,F5,..." "\n\n" "Keystroke", write_action(hop->keymap, hop->action), write_keymap(hop->keymap)); input_dialog(term, getml(hop, text, NULL), N_("Add keybinding"), text, hop, NULL, MAX_STR_LEN, "", 0, 0, check_keystroke, really_add_keybinding, NULL); return EVENT_PROCESSED;}static t_handler_event_statuspush_kbdbind_toggle_display_button(struct dialog_data *dlg_data, struct widget_data *some_useless_info_button){#ifndef CONFIG_SMALL keybinding_text_toggle = !keybinding_text_toggle; clear_dialog(dlg_data, some_useless_info_button);#endif return EVENT_PROCESSED;}/* FIXME: Races here, we need to lock the entry..? --pasky */static t_handler_event_statuspush_kbdbind_save_button(struct dialog_data *dlg_data, struct widget_data *some_useless_info_button){ write_config(dlg_data->win->term); return EVENT_PROCESSED;}#define KEYBINDING_MANAGER_BUTTONS 4static INIT_LIST_HEAD(keybinding_dialog_list);static struct hierbox_browser_button keybinding_buttons[] = { { N_("~Add"), push_kbdbind_add_button, 0 }, { N_("~Delete"), push_hierbox_delete_button, 0 }, { N_("~Toggle display"), push_kbdbind_toggle_display_button, 1 }, { N_("~Search"), push_hierbox_search_button, 1 }, { N_("Sa~ve"), push_kbdbind_save_button, 0 },};struct_hierbox_browser( keybinding_browser, N_("Keybinding manager"), keybinding_buttons, &keybinding_listbox_ops);/* Builds the "Keybinding manager" dialog */voidkeybinding_manager(struct session *ses){ hierbox_browser(&keybinding_browser, ses);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -