summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2012-08-18 11:53:01 +0200
committerSebastien Helleu <flashcode@flashtux.org>2012-08-18 11:53:01 +0200
commitfbbfcf95dd46a5b78ccb5829d2a0ed76cadc6554 (patch)
tree2f2be678fd2b14c5493a2f4390511f334c592316 /src
parent13b1d64aa1b63778b14f9e97c91847d1b7d96571 (diff)
downloadweechat-fbbfcf95dd46a5b78ccb5829d2a0ed76cadc6554.zip
script: add key alt+L to reload script, allow input on script buffer for actions on script, add option script.look.use_keys
Diffstat (limited to 'src')
-rw-r--r--src/plugins/script/script-buffer.c81
-rw-r--r--src/plugins/script/script-buffer.h1
-rw-r--r--src/plugins/script/script-command.c24
-rw-r--r--src/plugins/script/script-config.c25
-rw-r--r--src/plugins/script/script-config.h1
5 files changed, 108 insertions, 24 deletions
diff --git a/src/plugins/script/script-buffer.c b/src/plugins/script/script-buffer.c
index a46ee1770..3e4c501f6 100644
--- a/src/plugins/script/script-buffer.c
+++ b/src/plugins/script/script-buffer.c
@@ -509,9 +509,9 @@ script_buffer_refresh (int clear)
{
snprintf (str_title, sizeof (str_title),
_("%d/%d scripts (filter: %s) | Sort: %s | "
- "alt+i=install r=remove l=load u=unload h=(un)hold "
- "d=show detail | Input: 'q'=close 'r'=refresh 's:x,y'=sort "
- "'words'=filter '*'=reset filter"),
+ "Alt+key/input: i=install r=remove l=load L=reload "
+ "u=unload h=(un)hold d=show detail | Input: q=close "
+ "$=refresh s:x,y=sort words=filter *=reset filter"),
script_repo_count_displayed,
script_repo_count,
(script_repo_filter) ? script_repo_filter : "*",
@@ -701,16 +701,28 @@ int
script_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
const char *input_data)
{
+ char *actions[][2] = { { "l", "load" },
+ { "u", "unload" },
+ { "L", "reload" },
+ { "i", "install" },
+ { "r", "remove" },
+ { "h", "hold" },
+ { "d", "show" },
+ { NULL, NULL } };
+ char str_command[64];
+ int i;
+
/* make C compiler happy */
(void) data;
- (void) buffer;
+ /* close buffer */
if (strcmp (input_data, "q") == 0)
{
weechat_buffer_close (buffer);
return WEECHAT_RC_OK;
}
+ /* change sort keys on buffer */
if (strncmp (input_data, "s:", 2) == 0)
{
if (input_data[2])
@@ -720,7 +732,8 @@ script_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_OK;
}
- if (strcmp (input_data, "r") == 0)
+ /* refresh buffer */
+ if (strcmp (input_data, "$") == 0)
{
script_get_loaded_scripts ();
script_repo_remove_all ();
@@ -729,6 +742,19 @@ script_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_OK;
}
+ /* execute action on a script */
+ for (i = 0; actions[i][0]; i++)
+ {
+ if (strcmp (input_data, actions[i][0]) == 0)
+ {
+ snprintf (str_command, sizeof (str_command),
+ "/script %s", actions[i][1]);
+ weechat_command (buffer, str_command);
+ return WEECHAT_RC_OK;
+ }
+ }
+
+ /* filter scripts with given text */
script_repo_filter_scripts (input_data);
return WEECHAT_RC_OK;
@@ -772,6 +798,42 @@ script_buffer_set_callbacks ()
}
/*
+ * script_buffer_set_keys: set keys on script buffer
+ */
+
+void
+script_buffer_set_keys ()
+{
+ char *keys[][2] = { { "meta-l", "load" },
+ { "meta-u", "unload" },
+ { "meta-L", "reload" },
+ { "meta-i", "install" },
+ { "meta-r", "remove" },
+ { "meta-h", "hold" },
+ { "meta-d", "show" },
+ { NULL, NULL } };
+ char str_key[64], str_command[64];
+ int i;
+
+ weechat_buffer_set (script_buffer, "key_bind_meta2-A", "/script up");
+ weechat_buffer_set (script_buffer, "key_bind_meta2-B", "/script down");
+ for (i = 0; keys[i][0]; i++)
+ {
+ if (weechat_config_boolean (script_config_look_use_keys))
+ {
+ snprintf (str_key, sizeof (str_key), "key_bind_%s", keys[i][0]);
+ snprintf (str_command, sizeof (str_command), "/script %s", keys[i][1]);
+ weechat_buffer_set (script_buffer, str_key, str_command);
+ }
+ else
+ {
+ snprintf (str_key, sizeof (str_key), "key_unbind_%s", keys[i][0]);
+ weechat_buffer_set (script_buffer, str_key, "");
+ }
+ }
+}
+
+/*
* script_buffer_open: open script buffer (to display list of scripts)
*/
@@ -790,14 +852,7 @@ script_buffer_open ()
weechat_buffer_set (script_buffer, "type", "free");
weechat_buffer_set (script_buffer, "title", _("Scripts"));
- weechat_buffer_set (script_buffer, "key_bind_meta2-A", "/script up");
- weechat_buffer_set (script_buffer, "key_bind_meta2-B", "/script down");
- weechat_buffer_set (script_buffer, "key_bind_meta-l", "/script load");
- weechat_buffer_set (script_buffer, "key_bind_meta-u", "/script unload");
- weechat_buffer_set (script_buffer, "key_bind_meta-i", "/script install");
- weechat_buffer_set (script_buffer, "key_bind_meta-r", "/script remove");
- weechat_buffer_set (script_buffer, "key_bind_meta-h", "/script hold");
- weechat_buffer_set (script_buffer, "key_bind_meta-d", "/script show");
+ script_buffer_set_keys ();
weechat_buffer_set (script_buffer, "localvar_set_type", "script");
script_buffer_selected_line = 0;
diff --git a/src/plugins/script/script-buffer.h b/src/plugins/script/script-buffer.h
index a9a29d326..5f5b23fa7 100644
--- a/src/plugins/script/script-buffer.h
+++ b/src/plugins/script/script-buffer.h
@@ -39,6 +39,7 @@ extern int script_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
const char *input_data);
extern int script_buffer_close_cb (void *data, struct t_gui_buffer *buffer);
extern void script_buffer_set_callbacks ();
+extern void script_buffer_set_keys ();
extern void script_buffer_open ();
#endif /* __WEECHAT_SCRIPT_BUFFER_H */
diff --git a/src/plugins/script/script-command.c b/src/plugins/script/script-command.c
index 0ef3fd245..c1e369415 100644
--- a/src/plugins/script/script-command.c
+++ b/src/plugins/script/script-command.c
@@ -256,20 +256,22 @@ script_command_init ()
" | installed\n"
" popular script\n\n"
"Keys on script buffer:\n"
- " alt+i install script\n"
- " alt+r remove script\n"
- " alt+l load script\n"
- " alt+u unload script\n"
- " alt+h (un)hold script\n\n"
+ " alt+i install script\n"
+ " alt+r remove script\n"
+ " alt+l load script\n"
+ " alt+L reload script\n"
+ " alt+u unload script\n"
+ " alt+h (un)hold script\n\n"
"Input allowed on script buffer:\n"
- " q close buffer\n"
- " r refresh buffer\n"
- " s:x,y sort buffer using keys x and y (see /help "
+ " i/r/l/L/u/h action on script (same as keys above)\n"
+ " q close buffer\n"
+ " $ refresh buffer\n"
+ " s:x,y sort buffer using keys x and y (see /help "
"script.look.sort)\n"
- " s: reset sort (use default sort)\n"
- " word(s) filter scripts: search word(s) in "
+ " s: reset sort (use default sort)\n"
+ " word(s) filter scripts: search word(s) in "
"scripts (description, tags, ...)\n"
- " * remove filter\n\n"
+ " * remove filter\n\n"
"Examples:\n"
" /script search url\n"
" /script install iset.pl buffers.pl\n"
diff --git a/src/plugins/script/script-config.c b/src/plugins/script/script-config.c
index 7de9d1440..a8300f1b9 100644
--- a/src/plugins/script/script-config.c
+++ b/src/plugins/script/script-config.c
@@ -42,6 +42,7 @@ struct t_config_section *script_config_section_scripts = NULL;
struct t_config_option *script_config_look_columns;
struct t_config_option *script_config_look_sort;
struct t_config_option *script_config_look_translate_description;
+struct t_config_option *script_config_look_use_keys;
/* script config, color section */
@@ -192,6 +193,22 @@ script_config_reload_scripts_cb (void *data, struct t_config_option *option)
}
/*
+ * script_config_change_use_keys_cb: callback called when option "use_keys" is
+ * changed
+ */
+
+void
+script_config_change_use_keys_cb (void *data, struct t_config_option *option)
+{
+ /* make C compiler happy */
+ (void) data;
+ (void) option;
+
+ if (script_buffer)
+ script_buffer_set_keys ();
+}
+
+/*
* script_config_change_hold_cb: callback called when list of scripts to "hold"
* is changed
*/
@@ -359,6 +376,14 @@ script_config_init ()
"your language, otherwise english version is used)"),
NULL, 0, 0, "on", NULL, 0,
NULL, NULL, &script_config_reload_scripts_cb, NULL, NULL, NULL);
+ script_config_look_use_keys = weechat_config_new_option (
+ script_config_file, ptr_section,
+ "use_keys", "boolean",
+ N_("use keys alt+X in script buffer to do actions on scripts (alt+i = "
+ "install, alt+r = remove, ...); if disabled, only the input is "
+ "allowed: i, r, ..."),
+ NULL, 0, 0, "on", NULL, 0,
+ NULL, NULL, &script_config_change_use_keys_cb, NULL, NULL, NULL);
/* color */
ptr_section = weechat_config_new_section (script_config_file, "color",
diff --git a/src/plugins/script/script-config.h b/src/plugins/script/script-config.h
index ca9f5aaf8..811684234 100644
--- a/src/plugins/script/script-config.h
+++ b/src/plugins/script/script-config.h
@@ -27,6 +27,7 @@ struct t_repo_script;
extern struct t_config_option *script_config_look_columns;
extern struct t_config_option *script_config_look_sort;
extern struct t_config_option *script_config_look_translate_description;
+extern struct t_config_option *script_config_look_use_keys;
extern struct t_config_option *script_config_color_status_popular;
extern struct t_config_option *script_config_color_status_installed;