1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-28 22:06:38 +02:00

script: add focus info for mouse on script buffer, add two default mouse bindings: left button = select line, right button = install/remove script

This commit is contained in:
Sebastien Helleu
2012-08-20 13:36:29 +02:00
parent 08228492e6
commit 2944adc954
26 changed files with 329 additions and 56 deletions
+54 -11
View File
@@ -471,7 +471,7 @@ script_action_install ()
*/
void
script_action_remove (const char *name)
script_action_remove (const char *name, int quiet)
{
struct t_repo_script *ptr_script;
char str_signal[256];
@@ -481,15 +481,21 @@ script_action_remove (const char *name)
{
if (!(ptr_script->status & SCRIPT_STATUS_INSTALLED))
{
weechat_printf (NULL,
_("%s: script \"%s\" is not installed"),
SCRIPT_PLUGIN_NAME, name);
if (!quiet)
{
weechat_printf (NULL,
_("%s: script \"%s\" is not installed"),
SCRIPT_PLUGIN_NAME, name);
}
}
else if (ptr_script->status & SCRIPT_STATUS_HELD)
{
weechat_printf (NULL,
_("%s: script \"%s\" is held"),
SCRIPT_PLUGIN_NAME, name);
if (!quiet)
{
weechat_printf (NULL,
_("%s: script \"%s\" is held"),
SCRIPT_PLUGIN_NAME, name);
}
}
else
{
@@ -503,9 +509,12 @@ script_action_remove (const char *name)
}
else
{
weechat_printf (NULL,
_("%s: script \"%s\" not found"),
SCRIPT_PLUGIN_NAME, name);
if (!quiet)
{
weechat_printf (NULL,
_("%s: script \"%s\" not found"),
SCRIPT_PLUGIN_NAME, name);
}
}
}
@@ -714,9 +723,43 @@ script_action_run ()
{
for (j = 1; j < argc; j++)
{
script_action_remove (argv[j]);
script_action_remove (argv[j], quiet);
}
}
else if (weechat_strcasecmp (argv[0], "installremove") == 0)
{
script_found = 0;
for (j = 1; j < argc; j++)
{
ptr_script = script_repo_search_by_name_ext (argv[j]);
if (ptr_script)
{
if (ptr_script->status & SCRIPT_STATUS_HELD)
{
weechat_printf (NULL,
_("%s: script \"%s\" is held"),
SCRIPT_PLUGIN_NAME, argv[j]);
}
else if (ptr_script->status & SCRIPT_STATUS_INSTALLED)
{
script_action_remove (argv[j], quiet);
}
else
{
script_found++;
ptr_script->install_order = script_found;
}
}
else
{
weechat_printf (NULL,
_("%s: script \"%s\" not found"),
SCRIPT_PLUGIN_NAME, argv[j]);
}
}
if (script_found)
script_action_install ();
}
else if (weechat_strcasecmp (argv[0], "hold") == 0)
{
script_found = 0;
+11 -7
View File
@@ -511,7 +511,8 @@ script_buffer_refresh (int clear)
_("%d/%d scripts (filter: %s) | Sort: %s | "
"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"),
"$=refresh s:x,y=sort words=filter *=reset filter | "
"Mouse: left=select right=install/remove"),
script_repo_count_displayed,
script_repo_count,
(script_repo_filter) ? script_repo_filter : "*",
@@ -549,13 +550,16 @@ script_buffer_set_current_line (int line)
{
int old_line;
old_line = script_buffer_selected_line;
script_buffer_selected_line = line;
if ((line >= 0) && (line < script_repo_count_displayed))
{
old_line = script_buffer_selected_line;
script_buffer_selected_line = line;
script_buffer_display_line_script (old_line,
script_repo_search_displayed_by_number (old_line));
script_buffer_display_line_script (script_buffer_selected_line,
script_repo_search_displayed_by_number (script_buffer_selected_line));
script_buffer_display_line_script (old_line,
script_repo_search_displayed_by_number (old_line));
script_buffer_display_line_script (script_buffer_selected_line,
script_repo_search_displayed_by_number (script_buffer_selected_line));
}
}
/*
+43 -5
View File
@@ -40,15 +40,34 @@
void
script_command_action (struct t_gui_buffer *buffer, const char *action,
const char *action_with_args, int need_repository)
const char *arguments, int need_repository)
{
struct t_repo_script *ptr_script;
char str_action[4096];
long value;
char *error;
if (action_with_args)
if (arguments)
{
/* action with arguments on command line */
script_action_schedule (action_with_args, need_repository, 0);
error = NULL;
value = strtol (arguments, &error, 10);
if (error && !error[0])
{
ptr_script = script_repo_search_displayed_by_number (value);
if (ptr_script)
{
snprintf (str_action, sizeof (str_action),
"%s %s", action, ptr_script->name_with_extension);
script_action_schedule (str_action, need_repository, 0);
}
}
else
{
snprintf (str_action, sizeof (str_action),
"%s %s", action, arguments);
script_action_schedule (str_action, need_repository, 0);
}
}
else if (script_buffer && (buffer == script_buffer))
{
@@ -102,6 +121,20 @@ script_command_script (void *data, struct t_gui_buffer *buffer, int argc,
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp (argv[1], "go") == 0)
{
if ((argc > 2) && script_buffer && !script_buffer_detail_script)
{
error = NULL;
value = strtol (argv[2], &error, 10);
if (error && !error[0])
{
script_buffer_set_current_line (value);
}
}
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp (argv[1], "search") == 0)
{
if (repo_scripts)
@@ -124,19 +157,20 @@ script_command_script (void *data, struct t_gui_buffer *buffer, int argc,
{
script_command_action (buffer,
argv[1],
(argc > 2) ? argv_eol[1] : NULL,
(argc > 2) ? argv_eol[2] : NULL,
0);
return WEECHAT_RC_OK;
}
if ((weechat_strcasecmp (argv[1], "install") == 0)
|| (weechat_strcasecmp (argv[1], "remove") == 0)
|| (weechat_strcasecmp (argv[1], "installremove") == 0)
|| (weechat_strcasecmp (argv[1], "hold") == 0)
|| (weechat_strcasecmp (argv[1], "show") == 0))
{
script_command_action (buffer,
argv[1],
(argc > 2) ? argv_eol[1] : NULL,
(argc > 2) ? argv_eol[2] : NULL,
1);
return WEECHAT_RC_OK;
}
@@ -272,6 +306,10 @@ script_command_init ()
" word(s) filter scripts: search word(s) in "
"scripts (description, tags, ...)\n"
" * remove filter\n\n"
"Mouse actions on script buffer:\n"
" wheel scroll list\n"
" left button select script\n"
" right button install/remove script\n\n"
"Examples:\n"
" /script search url\n"
" /script install iset.pl buffers.pl\n"
+79
View File
@@ -221,6 +221,83 @@ script_signal_script_cb (void *data, const char *signal, const char *type_data,
return WEECHAT_RC_OK;
}
/*
* script_focus_chat_cb: callback called when a mouse action occurs in chat area
*/
struct t_hashtable *
script_focus_chat_cb (void *data, struct t_hashtable *info)
{
const char *buffer;
int rc;
long unsigned int value;
struct t_gui_buffer *ptr_buffer;
long x;
char *error, str_date[64];
struct t_repo_script *ptr_script;
struct tm *tm;
/* make C compiler happy */
(void) data;
if (!script_buffer)
return info;
buffer = weechat_hashtable_get (info, "_buffer");
if (!buffer)
return info;
rc = sscanf (buffer, "%lx", &value);
if ((rc == EOF) || (rc == 0))
return info;
ptr_buffer = (struct t_gui_buffer *)value;
if (!ptr_buffer || (ptr_buffer != script_buffer))
return info;
if (script_buffer_detail_script)
ptr_script = script_buffer_detail_script;
else
{
error = NULL;
x = strtol (weechat_hashtable_get (info, "_chat_line_y"), &error, 10);
if (!error || error[0])
return info;
if (x < 0)
return info;
ptr_script = script_repo_search_displayed_by_number (x);
if (!ptr_script)
return info;
}
weechat_hashtable_set (info, "script_name", ptr_script->name);
weechat_hashtable_set (info, "script_name_with_extension", ptr_script->name_with_extension);
weechat_hashtable_set (info, "script_language", script_language[ptr_script->language]);
weechat_hashtable_set (info, "script_author",ptr_script->author);
weechat_hashtable_set (info, "script_mail", ptr_script->mail);
weechat_hashtable_set (info, "script_version", ptr_script->version);
weechat_hashtable_set (info, "script_license", ptr_script->license);
weechat_hashtable_set (info, "script_description", ptr_script->description);
weechat_hashtable_set (info, "script_tags", ptr_script->tags);
weechat_hashtable_set (info, "script_requirements", ptr_script->requirements);
weechat_hashtable_set (info, "script_min_weechat", ptr_script->min_weechat);
weechat_hashtable_set (info, "script_max_weechat", ptr_script->max_weechat);
weechat_hashtable_set (info, "script_md5sum", ptr_script->md5sum);
weechat_hashtable_set (info, "script_url", ptr_script->url);
tm = localtime (&ptr_script->date_added);
strftime (str_date, sizeof (str_date), "%Y-%m-%d %H:%M:%S", tm);
weechat_hashtable_set (info, "script_date_added", str_date);
tm = localtime (&ptr_script->date_updated);
strftime (str_date, sizeof (str_date), "%Y-%m-%d %H:%M:%S", tm);
weechat_hashtable_set (info, "script_date_updated", str_date);
weechat_hashtable_set (info, "script_version_loaded", ptr_script->version_loaded);
return info;
}
/*
* weechat_plugin_init: initialize script plugin
*/
@@ -252,6 +329,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_signal ("window_scrolled", &script_buffer_window_scrolled_cb, NULL);
weechat_hook_signal ("*_script_*", &script_signal_script_cb, NULL);
weechat_hook_focus ("chat", &script_focus_chat_cb, NULL);
if (script_repo_file_exists ())
{
if (!script_repo_file_is_uptodate ())