1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

Added /STATUSBAR commands for most commonly used tasks.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2459 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2002-02-15 21:42:31 +00:00 committed by cras
parent fa3d6dcd75
commit c9fd2197e3
5 changed files with 151 additions and 19 deletions

View File

@ -25,12 +25,18 @@ FORMAT_REC gui_text_formats[] =
{
{ MODULE_NAME, "Text user interface", 0 },
/* ---- */
{ NULL, "Lastlog", 0 },
{ "lastlog_too_long", "/LASTLOG would print $0 lines. If you really want to print all these lines use -force option.", 1, { 1 } },
{ "lastlog_count", "{hilight Lastlog}: $0 lines", 1, { 1 } },
{ "lastlog_start", "{hilight Lastlog}:", 0 },
{ "lastlog_end", "{hilight End of Lastlog}", 0 },
{ "lastlog_separator", "--", 0 },
/* ---- */
{ NULL, "Windows", 0 },
{ "refnum_not_found", "Window number $0 not found", 1, { 0 } },
{ "window_too_small", "Not enough room to resize this window", 0 },
{ "cant_hide_last", "You can't hide the last window", 0 },
@ -43,5 +49,11 @@ FORMAT_REC gui_text_formats[] =
{ "window_scroll", "Window scroll mode is now $0", 1, { 0 } },
{ "window_scroll_unknown", "Unknown scroll mode $0, must be ON, OFF or DEFAULT", 1, { 0 } },
/* ---- */
{ NULL, "Statusbars", 0 },
{ "statusbar_not_found", "Statusbar doesn't exist: $0", 1, { 0 } },
{ "statusbar_item_not_found", "Statusbar item doesn't exist: $0", 1, { 0 } },
{ "statusbar_unknown_command", "Unknown statusbar command: $0", 1, { 0 } },
{ NULL, NULL, 0 }
};

View File

@ -3,12 +3,16 @@
enum {
TXT_MODULE_NAME,
TXT_FILL_1,
TXT_LASTLOG_TOO_LONG,
TXT_LASTLOG_COUNT,
TXT_LASTLOG_START,
TXT_LASTLOG_END,
TXT_LASTLOG_SEPARATOR,
TXT_FILL_2,
TXT_REFNUM_NOT_FOUND,
TXT_WINDOW_TOO_SMALL,
TXT_CANT_HIDE_LAST,
@ -19,7 +23,13 @@ enum {
TXT_WINDOW_UNSET_STICKY,
TXT_WINDOW_INFO_STICKY,
TXT_WINDOW_SCROLL,
TXT_WINDOW_SCROLL_UNKNOWN
TXT_WINDOW_SCROLL_UNKNOWN,
TXT_FILL_3,
TXT_STATUSBAR_NOT_FOUND,
TXT_STATUSBAR_ITEM_NOT_FOUND,
TXT_STATUSBAR_UNKNOWN_COMMAND
};
extern FORMAT_REC gui_text_formats[];

View File

@ -19,11 +19,15 @@
*/
#include "module.h"
#include "module-formats.h"
#include "signals.h"
#include "commands.h"
#include "settings.h"
#include "levels.h"
#include "lib-config/iconfig.h"
#include "statusbar.h"
#include "printtext.h"
static void read_statusbar_config_from_node(CONFIG_NODE *node);
@ -141,21 +145,11 @@ static void statusbar_read(STATUSBAR_GROUP_REC *group, CONFIG_NODE *node)
{
STATUSBAR_CONFIG_REC *bar;
GSList *tmp;
int visible;
const char *visible_str;
bar = statusbar_config_find(group, node->key);
visible = bar == NULL ? STATUSBAR_VISIBLE_ALWAYS : bar->visible;
/* first make sure we want to see this statusbar */
visible_str = config_node_get_str(node, "visible", "");
if (strcmp(visible_str, "active") == 0)
visible = STATUSBAR_VISIBLE_ACTIVE;
else if (strcmp(visible_str, "inactive") == 0)
visible = STATUSBAR_VISIBLE_INACTIVE;
else if (strcmp(visible_str, "never") == 0) {
/* we don't want this statusbar -
destroy it if it already exists */
if (config_node_get_bool(node, "disabled", FALSE)) {
/* disabled, destroy it if it already exists */
if (bar != NULL)
statusbar_config_destroy(group, bar);
return;
@ -167,7 +161,14 @@ static void statusbar_read(STATUSBAR_GROUP_REC *group, CONFIG_NODE *node)
bar->placement = STATUSBAR_BOTTOM;
bar->position = 0;
}
bar->visible = visible;
visible_str = config_node_get_str(node, "visible", "");
if (strcmp(visible_str, "active") == 0)
bar->visible = STATUSBAR_VISIBLE_ACTIVE;
else if (strcmp(visible_str, "inactive") == 0)
bar->visible = STATUSBAR_VISIBLE_INACTIVE;
else
bar->visible = STATUSBAR_VISIBLE_ALWAYS;
if (strcmp(config_node_get_str(node, "type", ""), "window") == 0)
bar->type = STATUSBAR_TYPE_WINDOW;
@ -247,15 +248,127 @@ static void read_statusbar_config(void)
read_statusbar_config_from_node(node);
create_root_statusbars();
statusbars_create_window_bars();
}
static void cmd_statusbar_enable(CONFIG_NODE *node, const char *data)
{
iconfig_node_set_str(node, "disabled", NULL);
}
static void cmd_statusbar_disable(CONFIG_NODE *node, const char *data)
{
iconfig_node_set_bool(node, "disabled", TRUE);
}
static CONFIG_NODE *statusbar_items_section(CONFIG_NODE *parent)
{
STATUSBAR_CONFIG_REC *bar;
CONFIG_NODE *node;
GSList *tmp;
node = config_node_section(parent, "items", -1);
if (node != NULL)
return node;
/* find the statusbar configuration from memory */
bar = statusbar_config_find(active_statusbar_group, parent->key);
if (bar == NULL) {
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
TXT_STATUSBAR_NOT_FOUND, parent->key);
return NULL;
}
/* since items list in config file overrides defaults,
we'll need to copy the whole list. */
parent = config_node_section(parent, "items", NODE_TYPE_BLOCK);
for (tmp = bar->items; tmp != NULL; tmp = tmp->next) {
SBAR_ITEM_CONFIG_REC *rec = tmp->data;
node = config_node_section(parent, rec->name,
NODE_TYPE_BLOCK);
if (rec->priority != 0)
iconfig_node_set_int(node, "priority", rec->priority);
if (rec->right_alignment)
iconfig_node_set_str(node, "alignment", "right");
}
return parent;
}
static void cmd_statusbar_add(CONFIG_NODE *node, const char *data)
{
node = statusbar_items_section(node);
if (node == NULL)
return;
node = config_node_section(node, data, NODE_TYPE_BLOCK);
}
static void cmd_statusbar_remove(CONFIG_NODE *node, const char *data)
{
node = statusbar_items_section(node);
if (node == NULL)
return;
if (config_node_section(node, data, -1) != NULL)
iconfig_node_set_str(node, data, NULL);
else {
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
TXT_STATUSBAR_ITEM_NOT_FOUND, data);
}
}
/* SYNTAX: STATUSBAR <name> [enable | disable] | [add|remove <item>] */
static void cmd_statusbar(const char *data)
{
CONFIG_NODE *node;
char *name, *cmd, *params, *signal;
void *free_arg;
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
&name, &cmd, &params))
return;
if (*cmd == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
/* lookup/create the statusbar node */
node = iconfig_node_traverse("statusbar", TRUE);
node = config_node_section(node, active_statusbar_group->name,
NODE_TYPE_BLOCK);
node = config_node_section(node, name, NODE_TYPE_BLOCK);
/* call the subcommand */
signal = g_strconcat("statusbar command ", cmd, NULL);
if (!signal_emit(signal, 2, node, params)) {
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
TXT_STATUSBAR_UNKNOWN_COMMAND, cmd);
} else {
read_statusbar_config();
}
g_free(signal);
cmd_params_free(free_arg);
}
void statusbar_config_init(void)
{
read_statusbar_config();
signal_add("setup reread", (SIGNAL_FUNC) read_statusbar_config);
command_bind("statusbar", NULL, (SIGNAL_FUNC) cmd_statusbar);
signal_add("statusbar command enable", (SIGNAL_FUNC) cmd_statusbar_enable);
signal_add("statusbar command disable", (SIGNAL_FUNC) cmd_statusbar_disable);
signal_add("statusbar command add", (SIGNAL_FUNC) cmd_statusbar_add);
signal_add("statusbar command remove", (SIGNAL_FUNC) cmd_statusbar_remove);
}
void statusbar_config_deinit(void)
{
signal_remove("setup reread", (SIGNAL_FUNC) read_statusbar_config);
command_unbind("statusbar", (SIGNAL_FUNC) cmd_statusbar);
signal_remove("statusbar command enable", (SIGNAL_FUNC) cmd_statusbar_enable);
signal_remove("statusbar command disable", (SIGNAL_FUNC) cmd_statusbar_disable);
signal_remove("statusbar command add", (SIGNAL_FUNC) cmd_statusbar_remove);
signal_remove("statusbar command remove", (SIGNAL_FUNC) cmd_statusbar_remove);
}

View File

@ -1070,10 +1070,8 @@ static void statusbar_item_signal_destroy(void *key, GSList *value)
g_slist_free(value);
}
static void sig_setup_reload(void)
void statusbars_create_window_bars(void)
{
/* statusbar-config.c recreates root statusbars,
we need to create window-statusbars */
g_slist_foreach(mainwindows, (GFunc) statusbars_add_visible, NULL);
}
@ -1099,7 +1097,6 @@ void statusbar_init(void)
signal_add("gui window created", (SIGNAL_FUNC) sig_gui_window_created);
signal_add("window changed", (SIGNAL_FUNC) sig_window_changed);
signal_add("mainwindow destroyed", (SIGNAL_FUNC) sig_mainwindow_destroyed);
signal_add_last("setup reread", (SIGNAL_FUNC) sig_setup_reload);
statusbar_items_init();
statusbar_config_init(); /* signals need to be before this call */
@ -1131,7 +1128,6 @@ void statusbar_deinit(void)
signal_remove("gui window created", (SIGNAL_FUNC) sig_gui_window_created);
signal_remove("window changed", (SIGNAL_FUNC) sig_window_changed);
signal_remove("mainwindow destroyed", (SIGNAL_FUNC) sig_mainwindow_destroyed);
signal_remove("setup reread", (SIGNAL_FUNC) sig_setup_reload);
statusbar_items_deinit();
statusbar_config_deinit();

View File

@ -110,6 +110,7 @@ void statusbar_items_redraw(const char *name);
void statusbar_recreate_items(STATUSBAR_REC *bar);
void statusbars_recreate_items(void);
void statusbars_create_window_bars(void);
void statusbar_redraw_dirty(void);