diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2017-03-31 21:07:32 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2017-03-31 21:07:32 +0200 |
commit | 2ab301511495da1496b2703ce77b28eb6eb5e738 (patch) | |
tree | 97d37694881343233c7cdd7c02c09f3517eed5db | |
parent | 92fc4692473b15a844730c31dff9ad099c2bafd2 (diff) | |
download | weechat-2ab301511495da1496b2703ce77b28eb6eb5e738.zip |
script: move default mouse keys for script plugin from core to script-mouse.c
-rw-r--r-- | doc/en/weechat_dev.en.adoc | 1 | ||||
-rw-r--r-- | doc/fr/weechat_dev.fr.adoc | 1 | ||||
-rw-r--r-- | doc/ja/weechat_dev.ja.adoc | 2 | ||||
-rw-r--r-- | po/POTFILES.in | 2 | ||||
-rw-r--r-- | po/srcfiles.cmake | 2 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-key.c | 4 | ||||
-rw-r--r-- | src/plugins/script/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/plugins/script/Makefile.am | 2 | ||||
-rw-r--r-- | src/plugins/script/script-mouse.c | 166 | ||||
-rw-r--r-- | src/plugins/script/script-mouse.h | 26 | ||||
-rw-r--r-- | src/plugins/script/script.c | 84 |
11 files changed, 207 insertions, 84 deletions
diff --git a/doc/en/weechat_dev.en.adoc b/doc/en/weechat_dev.en.adoc index 95a68f564..07709a12d 100644 --- a/doc/en/weechat_dev.en.adoc +++ b/doc/en/weechat_dev.en.adoc @@ -291,6 +291,7 @@ WeeChat "core" is located in following directories: | script-completion.c | Completions for scripts manager. | script-config.c | Config options for scripts manager (file script.conf). | script-info.c | Script manager info/infolists/hdata. +| script-mouse.c | Script mouse actions. | script-repo.c | Download and read repository file. | tcl/ | Tcl plugin. | weechat-tcl.c | Main tcl functions (load/unload scripts, execute tcl code). diff --git a/doc/fr/weechat_dev.fr.adoc b/doc/fr/weechat_dev.fr.adoc index 22e6ee886..4bff63df7 100644 --- a/doc/fr/weechat_dev.fr.adoc +++ b/doc/fr/weechat_dev.fr.adoc @@ -293,6 +293,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants : | script-completion.c | Complétions pour le gestionnaire de scripts. | script-config.c | Options de configuration pour le gestionnaire de scripts (fichier script.conf). | script-info.c | Info/infolists/hdata pour le gestionnaire de scripts. +| script-mouse.c | Actions souris pour le gestionnaire de scripts. | script-repo.c | Téléchargement et lecture du dépôt de scripts. | tcl/ | Extension Tcl. | weechat-tcl.c | Fonctions principales pour Tcl (chargement/déchargement des scripts, exécution de code Tcl). diff --git a/doc/ja/weechat_dev.ja.adoc b/doc/ja/weechat_dev.ja.adoc index ae9f51ccc..45e56927a 100644 --- a/doc/ja/weechat_dev.ja.adoc +++ b/doc/ja/weechat_dev.ja.adoc @@ -298,6 +298,8 @@ WeeChat "core" は以下のディレクトリに配置されています: | script-completion.c | スクリプトマネージャ用の補完 | script-config.c | スクリプトマネージャ用の設定オプション (script.conf ファイル) | script-info.c | スクリプトマネージャの情報/インフォリスト/hdata +// TRANSLATION MISSING +| script-mouse.c | Script mouse actions. | script-repo.c | リポジトリファイルのダウンロードとロード | tcl/ | tcl プラグイン | weechat-tcl.c | tcl の主要関数 (スクリプトのロード/アンロード、tcl コードの実行) diff --git a/po/POTFILES.in b/po/POTFILES.in index e8eefe27b..7285e7cad 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -290,6 +290,8 @@ ./src/plugins/script/script.h ./src/plugins/script/script-info.c ./src/plugins/script/script-info.h +./src/plugins/script/script-mouse.c +./src/plugins/script/script-mouse.h ./src/plugins/script/script-repo.c ./src/plugins/script/script-repo.h ./src/plugins/tcl/weechat-tcl-api.c diff --git a/po/srcfiles.cmake b/po/srcfiles.cmake index 53eace9c3..17fdcea8d 100644 --- a/po/srcfiles.cmake +++ b/po/srcfiles.cmake @@ -291,6 +291,8 @@ SET(WEECHAT_SOURCES ./src/plugins/script/script.h ./src/plugins/script/script-info.c ./src/plugins/script/script-info.h +./src/plugins/script/script-mouse.c +./src/plugins/script/script-mouse.h ./src/plugins/script/script-repo.c ./src/plugins/script/script-repo.h ./src/plugins/tcl/weechat-tcl-api.c diff --git a/src/gui/curses/gui-curses-key.c b/src/gui/curses/gui-curses-key.c index 4eadf0725..cc4ad6054 100644 --- a/src/gui/curses/gui-curses-key.c +++ b/src/gui/curses/gui-curses-key.c @@ -269,16 +269,12 @@ gui_key_default_bindings (int context) { /* mouse events on chat area */ BIND("@chat:button1", "/window ${_window_number}"); - BIND("@chat(script.scripts):button1", "/window ${_window_number};/script go ${_chat_line_y}"); - BIND("@chat(script.scripts):button2", "/window ${_window_number};/script go ${_chat_line_y};/script installremove -q ${script_name_with_extension}"); BIND("@chat:button1-gesture-left", "/window ${_window_number};/buffer -1"); BIND("@chat:button1-gesture-right", "/window ${_window_number};/buffer +1"); BIND("@chat:button1-gesture-left-long", "/window ${_window_number};/buffer 1"); BIND("@chat:button1-gesture-right-long", "/window ${_window_number};/input jump_last_buffer"); BIND("@chat:wheelup", "/window scroll_up -window ${_window_number}"); BIND("@chat:wheeldown", "/window scroll_down -window ${_window_number}"); - BIND("@chat(script.scripts):wheelup", "/script up 5"); - BIND("@chat(script.scripts):wheeldown", "/script down 5"); BIND("@chat:ctrl-wheelup", "/window scroll_horiz -window ${_window_number} -10%"); BIND("@chat:ctrl-wheeldown", "/window scroll_horiz -window ${_window_number} +10%"); /* mouse events on nicklist */ diff --git a/src/plugins/script/CMakeLists.txt b/src/plugins/script/CMakeLists.txt index 07627bce3..c0a5e5c63 100644 --- a/src/plugins/script/CMakeLists.txt +++ b/src/plugins/script/CMakeLists.txt @@ -25,6 +25,7 @@ script-command.c script-command.h script-completion.c script-completion.h script-config.c script-config.h script-info.c script-info.h +script-mouse.c script-mouse.h script-repo.c script-repo.h) set_target_properties(script PROPERTIES PREFIX "") diff --git a/src/plugins/script/Makefile.am b/src/plugins/script/Makefile.am index ebcb8c19d..a6507f8dd 100644 --- a/src/plugins/script/Makefile.am +++ b/src/plugins/script/Makefile.am @@ -37,6 +37,8 @@ script_la_SOURCES = script.c \ script-config.h \ script-info.c \ script-info.h \ + script-mouse.c \ + script-mouse.h \ script-repo.c \ script-repo.h diff --git a/src/plugins/script/script-mouse.c b/src/plugins/script/script-mouse.c new file mode 100644 index 000000000..534331697 --- /dev/null +++ b/src/plugins/script/script-mouse.c @@ -0,0 +1,166 @@ +/* + * script-mouse.c - mouse actions for script + * + * Copyright (C) 2003-2017 Sébastien Helleu <flashcode@flashtux.org> + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * WeeChat is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> +#include <stdio.h> + +#include "../weechat-plugin.h" +#include "script.h" +#include "script-mouse.h" +#include "script-buffer.h" +#include "script-repo.h" + + +/* + * Callback called when a mouse action occurs in chat area. + */ + +struct t_hashtable * +script_mouse_focus_chat_cb (const void *pointer, 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_script_repo *ptr_script; + struct tm *tm; + + /* make C compiler happy */ + (void) pointer; + (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; +} + +/* + * Initializes mouse. + * + * Returns: + * 1: OK + * 0: error + */ + +int +script_mouse_init () +{ + struct t_hashtable *keys; + + keys = weechat_hashtable_new (4, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, NULL); + if (!keys) + return 0; + + weechat_hook_focus ("chat", &script_mouse_focus_chat_cb, NULL, NULL); + + weechat_hashtable_set ( + keys, + "@chat(" SCRIPT_PLUGIN_NAME "." SCRIPT_BUFFER_NAME "):button1", + "/window ${_window_number};/script go ${_chat_line_y}"); + weechat_hashtable_set ( + keys, + "@chat(" SCRIPT_PLUGIN_NAME "." SCRIPT_BUFFER_NAME "):button2", + "/window ${_window_number};" + "/script go ${_chat_line_y};" + "/script installremove -q ${script_name_with_extension}"); + weechat_hashtable_set ( + keys, + "@chat(" SCRIPT_PLUGIN_NAME "." SCRIPT_BUFFER_NAME "):wheelup", + "/script up 5"); + weechat_hashtable_set ( + keys, + "@chat(" SCRIPT_PLUGIN_NAME "." SCRIPT_BUFFER_NAME "):wheeldown", + "/script down 5"); + weechat_hashtable_set (keys, "__quiet", "1"); + weechat_key_bind ("mouse", keys); + + weechat_hashtable_free (keys); + + return 1; +} + +/* + * Ends mouse. + */ + +void +script_mouse_end () +{ +} diff --git a/src/plugins/script/script-mouse.h b/src/plugins/script/script-mouse.h new file mode 100644 index 000000000..dcfb1dea4 --- /dev/null +++ b/src/plugins/script/script-mouse.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2003-2017 Sébastien Helleu <flashcode@flashtux.org> + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * WeeChat is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef WEECHAT_SCRIPT_MOUSE_H +#define WEECHAT_SCRIPT_MOUSE_H 1 + +extern int script_mouse_init (); +extern void script_mouse_end (); + +#endif /* WEECHAT_SCRIPT_MOUSE_H */ diff --git a/src/plugins/script/script.c b/src/plugins/script/script.c index 3337eebc3..43fc248e5 100644 --- a/src/plugins/script/script.c +++ b/src/plugins/script/script.c @@ -32,6 +32,7 @@ #include "script-completion.h" #include "script-config.h" #include "script-info.h" +#include "script-mouse.h" #include "script-repo.h" @@ -328,85 +329,6 @@ script_signal_script_cb (const void *pointer, void *data, } /* - * Callback called when a mouse action occurs in chat area. - */ - -struct t_hashtable * -script_focus_chat_cb (const void *pointer, 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_script_repo *ptr_script; - struct tm *tm; - - /* make C compiler happy */ - (void) pointer; - (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; -} - -/* * Initializes script plugin. */ @@ -448,7 +370,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat_hook_signal ("*_script_*", &script_signal_script_cb, NULL, NULL); - weechat_hook_focus ("chat", &script_focus_chat_cb, NULL, NULL); + script_mouse_init (); if (script_repo_file_exists ()) { @@ -474,6 +396,8 @@ weechat_plugin_end (struct t_weechat_plugin *plugin) /* make C compiler happy */ (void) plugin; + script_mouse_end (); + script_config_write (); script_repo_remove_all (); |