mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-17 02:57:33 -05:00
Support custom clipboard names under X.
This required me to turn the drop-lists into combo boxes and add an extra string-typed Conf setting alongside each enumerated value.
This commit is contained in:
104
config.c
104
config.c
@ -1342,29 +1342,100 @@ static void clipboard_selector_handler(union control *ctrl, void *dlg,
|
||||
{
|
||||
Conf *conf = (Conf *)data;
|
||||
int setting = ctrl->generic.context.i;
|
||||
#ifdef NAMED_CLIPBOARDS
|
||||
int strsetting = ctrl->editbox.context2.i;
|
||||
#endif
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
int id;
|
||||
} options[] = {
|
||||
{"No action", CLIPUI_NONE},
|
||||
{CLIPNAME_IMPLICIT, CLIPUI_IMPLICIT},
|
||||
{CLIPNAME_EXPLICIT, CLIPUI_EXPLICIT},
|
||||
};
|
||||
|
||||
if (event == EVENT_REFRESH) {
|
||||
int i, val = conf_get_int(conf, setting);
|
||||
|
||||
dlg_update_start(ctrl, dlg);
|
||||
dlg_listbox_clear(ctrl, dlg);
|
||||
dlg_listbox_addwithid(ctrl, dlg, "No action", CLIPUI_NONE);
|
||||
dlg_listbox_addwithid(ctrl, dlg, CLIPNAME_IMPLICIT, CLIPUI_IMPLICIT);
|
||||
dlg_listbox_addwithid(ctrl, dlg, CLIPNAME_EXPLICIT, CLIPUI_EXPLICIT);
|
||||
|
||||
#ifdef NAMED_CLIPBOARDS
|
||||
for (i = 0; i < lenof(options); i++)
|
||||
dlg_listbox_add(ctrl, dlg, options[i].name);
|
||||
if (val == CLIPUI_CUSTOM) {
|
||||
const char *sval = conf_get_str(conf, strsetting);
|
||||
for (i = 0; i < lenof(options); i++)
|
||||
if (!strcmp(sval, options[i].name))
|
||||
break; /* needs escaping */
|
||||
if (i < lenof(options) || sval[0] == '=') {
|
||||
char *escaped = dupcat("=", sval, (const char *)NULL);
|
||||
dlg_editbox_set(ctrl, dlg, escaped);
|
||||
sfree(escaped);
|
||||
} else {
|
||||
dlg_editbox_set(ctrl, dlg, sval);
|
||||
}
|
||||
} else {
|
||||
dlg_editbox_set(ctrl, dlg, options[0].name); /* fallback */
|
||||
for (i = 0; i < lenof(options); i++)
|
||||
if (val == options[i].id)
|
||||
dlg_editbox_set(ctrl, dlg, options[i].name);
|
||||
}
|
||||
#else
|
||||
for (i = 0; i < lenof(options); i++)
|
||||
dlg_listbox_addwithid(ctrl, dlg, options[i].name, options[i].id);
|
||||
dlg_listbox_select(ctrl, dlg, 0); /* fallback */
|
||||
for (i = 0; i < 3; i++)
|
||||
if (val == dlg_listbox_getid(ctrl, dlg, i))
|
||||
for (i = 0; i < lenof(options); i++)
|
||||
if (val == options[i].id)
|
||||
dlg_listbox_select(ctrl, dlg, i);
|
||||
#endif
|
||||
dlg_update_done(ctrl, dlg);
|
||||
} else if (event == EVENT_SELCHANGE) {
|
||||
} else if (event == EVENT_SELCHANGE
|
||||
#ifdef NAMED_CLIPBOARDS
|
||||
|| event == EVENT_VALCHANGE
|
||||
#endif
|
||||
) {
|
||||
#ifdef NAMED_CLIPBOARDS
|
||||
const char *sval = dlg_editbox_get(ctrl, dlg);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < lenof(options); i++)
|
||||
if (!strcmp(sval, options[i].name)) {
|
||||
conf_set_int(conf, setting, options[i].id);
|
||||
conf_set_str(conf, strsetting, "");
|
||||
break;
|
||||
}
|
||||
if (i == lenof(options)) {
|
||||
conf_set_int(conf, setting, CLIPUI_CUSTOM);
|
||||
if (sval[0] == '=')
|
||||
sval++;
|
||||
conf_set_str(conf, strsetting, sval);
|
||||
}
|
||||
#else
|
||||
int index = dlg_listbox_index(ctrl, dlg);
|
||||
if (index >= 0) {
|
||||
int val = dlg_listbox_getid(ctrl, dlg, index);
|
||||
conf_set_int(conf, setting, val);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void clipboard_control(struct controlset *s, const char *label,
|
||||
char shortcut, int percentage, intorptr helpctx,
|
||||
int setting, int strsetting)
|
||||
{
|
||||
#ifdef NAMED_CLIPBOARDS
|
||||
ctrl_combobox(s, label, shortcut, percentage, helpctx,
|
||||
clipboard_selector_handler, I(setting), I(strsetting));
|
||||
#else
|
||||
/* strsetting isn't needed in this case */
|
||||
ctrl_droplist(s, label, shortcut, percentage, helpctx,
|
||||
clipboard_selector_handler, I(setting));
|
||||
#endif
|
||||
}
|
||||
|
||||
void setup_config_box(struct controlbox *b, int midsession,
|
||||
int protocol, int protcfginfo)
|
||||
{
|
||||
@ -1894,18 +1965,15 @@ void setup_config_box(struct controlbox *b, int midsession,
|
||||
CLIPNAME_EXPLICIT_OBJECT,
|
||||
NO_SHORTCUT, HELPCTX(selection_autocopy),
|
||||
conf_checkbox_handler, I(CONF_mouseautocopy));
|
||||
ctrl_droplist(s, "Mouse paste action:", NO_SHORTCUT, 60,
|
||||
HELPCTX(selection_clipactions),
|
||||
clipboard_selector_handler,
|
||||
I(CONF_mousepaste));
|
||||
ctrl_droplist(s, "{Ctrl,Shift} + Ins:", NO_SHORTCUT, 60,
|
||||
HELPCTX(selection_clipactions),
|
||||
clipboard_selector_handler,
|
||||
I(CONF_ctrlshiftins));
|
||||
ctrl_droplist(s, "Ctrl + Shift + {C,V}:", NO_SHORTCUT, 60,
|
||||
HELPCTX(selection_clipactions),
|
||||
clipboard_selector_handler,
|
||||
I(CONF_ctrlshiftcv));
|
||||
clipboard_control(s, "Mouse paste action:", NO_SHORTCUT, 60,
|
||||
HELPCTX(selection_clipactions),
|
||||
CONF_mousepaste, CONF_mousepaste_custom);
|
||||
clipboard_control(s, "{Ctrl,Shift} + Ins:", NO_SHORTCUT, 60,
|
||||
HELPCTX(selection_clipactions),
|
||||
CONF_ctrlshiftins, CONF_ctrlshiftins_custom);
|
||||
clipboard_control(s, "Ctrl + Shift + {C,V}:", NO_SHORTCUT, 60,
|
||||
HELPCTX(selection_clipactions),
|
||||
CONF_ctrlshiftcv, CONF_ctrlshiftcv_custom);
|
||||
|
||||
/*
|
||||
* The Window/Selection/Words panel.
|
||||
|
Reference in New Issue
Block a user