1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 21:36:37 +02:00

script: move default mouse keys for script plugin from core to script-mouse.c

This commit is contained in:
Sébastien Helleu
2017-03-31 21:07:32 +02:00
parent 92fc469247
commit 2ab3015114
11 changed files with 207 additions and 84 deletions
+1
View File
@@ -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).
+1
View File
@@ -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).
+2
View File
@@ -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 コードの実行)
+2
View File
@@ -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
+2
View File
@@ -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
-4
View File
@@ -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 */
+1
View File
@@ -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 "")
+2
View File
@@ -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
+166
View File
@@ -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 ()
{
}
+26
View File
@@ -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 */
+4 -80
View File
@@ -32,6 +32,7 @@
#include "script-completion.h"
#include "script-config.h"
#include "script-info.h"
#include "script-mouse.h"
#include "script-repo.h"
@@ -327,85 +328,6 @@ script_signal_script_cb (const void *pointer, void *data,
return WEECHAT_RC_OK;
}
/*
* 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 ();