mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Changed the behaviour of how to handle "send command" signal (text you
typed to entry field). git-svn-id: http://svn.irssi.org/repos/irssi/trunk@317 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
fbb5cd6990
commit
89b47010b3
@ -419,41 +419,17 @@ void cmd_get_remove_func(CMD_GET_FUNC func)
|
|||||||
cmdget_funcs = g_slist_prepend(cmdget_funcs, (void *) func);
|
cmdget_funcs = g_slist_prepend(cmdget_funcs, (void *) func);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_outgoing(const char *line, SERVER_REC *server, void *item)
|
static void parse_command(const char *command, int expand_aliases, SERVER_REC *server, void *item)
|
||||||
{
|
{
|
||||||
const char *alias;
|
const char *alias;
|
||||||
char *cmd, *str, *args, *oldcmd, *cmdchar;
|
char *cmd, *str, *args, *oldcmd;
|
||||||
int use_alias = TRUE;
|
|
||||||
|
|
||||||
g_return_if_fail(line != NULL);
|
cmd = str = g_strconcat("command ", command, NULL);
|
||||||
|
|
||||||
if (*line == '\0') {
|
|
||||||
/* empty line, forget it. */
|
|
||||||
signal_stop();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdchar = strchr(settings_get_str("cmdchars"), *line);
|
|
||||||
if (cmdchar == NULL)
|
|
||||||
return; /* handle only /commands here */
|
|
||||||
line++;
|
|
||||||
if (*line == ' ') {
|
|
||||||
/* "/ text" = same as sending "text" to active channel. */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* same cmdchar twice ignores aliases ignores aliases */
|
|
||||||
if (*line == *cmdchar) {
|
|
||||||
line++;
|
|
||||||
use_alias = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = str = g_strconcat("command ", line, NULL);
|
|
||||||
args = strchr(cmd+8, ' ');
|
args = strchr(cmd+8, ' ');
|
||||||
if (args != NULL) *args++ = '\0'; else args = "";
|
if (args != NULL) *args++ = '\0'; else args = "";
|
||||||
|
|
||||||
/* check if there's an alias for command */
|
/* check if there's an alias for command */
|
||||||
alias = use_alias ? alias_find(cmd+8) : NULL;
|
alias = expand_aliases ? alias_find(cmd+8) : NULL;
|
||||||
if (alias != NULL)
|
if (alias != NULL)
|
||||||
eval_special_string(alias, args, server, item);
|
eval_special_string(alias, args, server, item);
|
||||||
else {
|
else {
|
||||||
@ -464,13 +440,48 @@ static void parse_outgoing(const char *line, SERVER_REC *server, void *item)
|
|||||||
oldcmd = current_command;
|
oldcmd = current_command;
|
||||||
current_command = cmd+8;
|
current_command = cmd+8;
|
||||||
if (!signal_emit(cmd, 3, args, server, item))
|
if (!signal_emit(cmd, 3, args, server, item))
|
||||||
signal_emit_id(signal_default_command, 3, line, server, item);
|
signal_emit_id(signal_default_command, 3, command, server, item);
|
||||||
current_command = oldcmd;
|
current_command = oldcmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(str);
|
g_free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void event_command(const char *line, SERVER_REC *server, void *item)
|
||||||
|
{
|
||||||
|
char *cmdchar;
|
||||||
|
int expand_aliases = TRUE;
|
||||||
|
|
||||||
|
g_return_if_fail(line != NULL);
|
||||||
|
|
||||||
|
if (*line == '\0') {
|
||||||
|
/* empty line, forget it. */
|
||||||
|
signal_stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmdchar = strchr(settings_get_str("cmdchars"), *line);
|
||||||
|
if (cmdchar != NULL && line[1] == ' ') {
|
||||||
|
/* "/ text" = same as sending "text" to active channel. */
|
||||||
|
line += 2;
|
||||||
|
cmdchar = NULL;
|
||||||
|
}
|
||||||
|
if (cmdchar == NULL) {
|
||||||
|
/* non-command - let someone else handle this */
|
||||||
|
signal_emit("send text", 3, line, server, item);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* same cmdchar twice ignores aliases ignores aliases */
|
||||||
|
line++;
|
||||||
|
if (*line == *cmdchar) {
|
||||||
|
line++;
|
||||||
|
expand_aliases = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
parse_command(line, expand_aliases, server, item);
|
||||||
|
}
|
||||||
|
|
||||||
static void cmd_eval(const char *data, SERVER_REC *server, void *item)
|
static void cmd_eval(const char *data, SERVER_REC *server, void *item)
|
||||||
{
|
{
|
||||||
g_return_if_fail(data != NULL);
|
g_return_if_fail(data != NULL);
|
||||||
@ -514,7 +525,7 @@ void commands_init(void)
|
|||||||
signal_default_command = module_get_uniq_id_str("signals", "default command");
|
signal_default_command = module_get_uniq_id_str("signals", "default command");
|
||||||
|
|
||||||
settings_add_str("misc", "cmdchars", "/");
|
settings_add_str("misc", "cmdchars", "/");
|
||||||
signal_add("send command", (SIGNAL_FUNC) parse_outgoing);
|
signal_add("send command", (SIGNAL_FUNC) event_command);
|
||||||
|
|
||||||
command_bind("eval", NULL, (SIGNAL_FUNC) cmd_eval);
|
command_bind("eval", NULL, (SIGNAL_FUNC) cmd_eval);
|
||||||
command_bind("cd", NULL, (SIGNAL_FUNC) cmd_cd);
|
command_bind("cd", NULL, (SIGNAL_FUNC) cmd_cd);
|
||||||
@ -527,7 +538,7 @@ void commands_deinit(void)
|
|||||||
g_free_not_null(current_command);
|
g_free_not_null(current_command);
|
||||||
g_slist_free(cmdget_funcs);
|
g_slist_free(cmdget_funcs);
|
||||||
|
|
||||||
signal_remove("send command", (SIGNAL_FUNC) parse_outgoing);
|
signal_remove("send command", (SIGNAL_FUNC) event_command);
|
||||||
|
|
||||||
command_unbind("eval", (SIGNAL_FUNC) cmd_eval);
|
command_unbind("eval", (SIGNAL_FUNC) cmd_eval);
|
||||||
command_unbind("cd", (SIGNAL_FUNC) cmd_cd);
|
command_unbind("cd", (SIGNAL_FUNC) cmd_cd);
|
||||||
|
@ -269,7 +269,7 @@ static GList *completion_getmsglist(IRC_SERVER_REC *server, gchar *nick)
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_command(gchar *line, IRC_SERVER_REC *server, WI_IRC_REC *item)
|
static void event_text(gchar *line, IRC_SERVER_REC *server, WI_IRC_REC *item)
|
||||||
{
|
{
|
||||||
CHANNEL_REC *channel;
|
CHANNEL_REC *channel;
|
||||||
GList *comp;
|
GList *comp;
|
||||||
@ -280,14 +280,6 @@ static void event_command(gchar *line, IRC_SERVER_REC *server, WI_IRC_REC *item)
|
|||||||
if (!irc_item_check(item))
|
if (!irc_item_check(item))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (strchr(settings_get_str("cmdchars"), *line) != NULL) {
|
|
||||||
if (line[1] != ' ')
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* "/ text" = same as sending "text" to active channel. */
|
|
||||||
line += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
line = g_strdup(line);
|
line = g_strdup(line);
|
||||||
|
|
||||||
/* check for nick completion */
|
/* check for nick completion */
|
||||||
@ -584,7 +576,7 @@ void completion_init(void)
|
|||||||
settings_add_int("completion", "completion_keep_privates", 10);
|
settings_add_int("completion", "completion_keep_privates", 10);
|
||||||
|
|
||||||
signal_add("event privmsg", (SIGNAL_FUNC) event_privmsg);
|
signal_add("event privmsg", (SIGNAL_FUNC) event_privmsg);
|
||||||
signal_add("send command", (SIGNAL_FUNC) event_command);
|
signal_add("send text", (SIGNAL_FUNC) event_text);
|
||||||
signal_add("server disconnected", (SIGNAL_FUNC) completion_deinit_server);
|
signal_add("server disconnected", (SIGNAL_FUNC) completion_deinit_server);
|
||||||
signal_add("channel destroyed", (SIGNAL_FUNC) completion_deinit_channel);
|
signal_add("channel destroyed", (SIGNAL_FUNC) completion_deinit_channel);
|
||||||
command_bind("msg", NULL, (SIGNAL_FUNC) cmd_msg);
|
command_bind("msg", NULL, (SIGNAL_FUNC) cmd_msg);
|
||||||
@ -601,7 +593,7 @@ void completion_deinit(void)
|
|||||||
g_source_remove(comptag);
|
g_source_remove(comptag);
|
||||||
|
|
||||||
signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg);
|
signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg);
|
||||||
signal_remove("send command", (SIGNAL_FUNC) event_command);
|
signal_remove("send text", (SIGNAL_FUNC) event_text);
|
||||||
signal_remove("server disconnected", (SIGNAL_FUNC) completion_deinit_server);
|
signal_remove("server disconnected", (SIGNAL_FUNC) completion_deinit_server);
|
||||||
signal_remove("channel destroyed", (SIGNAL_FUNC) completion_deinit_channel);
|
signal_remove("channel destroyed", (SIGNAL_FUNC) completion_deinit_channel);
|
||||||
command_unbind("msg", (SIGNAL_FUNC) cmd_msg);
|
command_unbind("msg", (SIGNAL_FUNC) cmd_msg);
|
||||||
|
Loading…
Reference in New Issue
Block a user