2 * Copyright Neil Brown ©2015-2023 <neil@brown.name>
3 * May be distributed under terms of GPLv2 - see file:COPYING
5 * Keymap management panes for edlib.
7 * A keymap pane makes it easy to attach keymaps into a pane tree.
9 * is given a command which is used to as all incoming requests.
14 #define PANE_DATA_TYPE struct key_data
18 struct command *globalcmd;
20 #include "core-pane.h"
22 static struct pane *safe do_keymap_attach(struct pane *p safe);
24 DEF_CMD(keymap_handle)
26 struct key_data *kd = ci->home->data;
28 if (strcmp(ci->key, "Close") == 0) {
29 command_put(kd->globalcmd);
32 if (strcmp(ci->key, "Clone") == 0) {
33 struct pane *p = do_keymap_attach(ci->focus);
34 struct key_data *kd_old = ci->home->data;
35 struct key_data *kd_new;
39 if (kd_old->globalcmd)
40 kd_new->globalcmd = command_get(kd_old->globalcmd);
42 pane_clone_children(ci->home, p);
48 ((struct cmd_info*)ci)->comm = kd->globalcmd;
49 ret = kd->globalcmd->func(ci);
53 if (strcmp(ci->key, "global-set-keymap") == 0) {
54 struct command *cm = ci->comm2;
57 command_put(kd->globalcmd);
58 kd->globalcmd = command_get(cm);
65 static struct pane *safe do_keymap_attach(struct pane *p safe)
67 return pane_register(p, 0, &keymap_handle);
70 DEF_CMD(keymap_attach)
72 struct pane *p = do_keymap_attach(ci->focus);
74 return comm_call(ci->comm2, "callback:attach", p);
78 void edlib_init(struct pane *ed safe)
80 call_comm("global-set-command", ed, &keymap_attach, 0, NULL,
81 "attach-global-keymap");