diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-06-28 12:43:57 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-06-28 12:43:57 +0200 |
commit | e5745e4d146d5ead13e026280a87b51fec7acb49 (patch) | |
tree | 4eab732d49c0251288e9150b2f0f96192fdcac53 /src/gui/gui-bar-item.c | |
parent | f7706ff40090525fca2ba1b06930cccca095dc00 (diff) | |
download | weechat-e5745e4d146d5ead13e026280a87b51fec7acb49.zip |
Add "default" option to command /bar, to create default bars (today only input and status)
Diffstat (limited to 'src/gui/gui-bar-item.c')
-rw-r--r-- | src/gui/gui-bar-item.c | 106 |
1 files changed, 72 insertions, 34 deletions
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index 8f16cad16..3533c7faa 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -61,16 +61,16 @@ struct t_hook *gui_bar_item_timer = NULL; */ struct t_gui_bar_item * -gui_bar_item_search (const char *name) +gui_bar_item_search (const char *item_name) { struct t_gui_bar_item *ptr_item; - if (!name || !name[0]) + if (!item_name || !item_name[0]) return NULL; for (ptr_item = gui_bar_items; ptr_item; ptr_item = ptr_item->next_item) { - if (strcmp (ptr_item->name, name) == 0) + if (strcmp (ptr_item->name, item_name) == 0) return ptr_item; } @@ -123,7 +123,7 @@ gui_bar_item_string_get_item_start (const char *string) */ int -gui_bar_item_string_is_item (const char *string, const char *name) +gui_bar_item_string_is_item (const char *string, const char *item_name) { const char *item_start; int length; @@ -132,8 +132,8 @@ gui_bar_item_string_is_item (const char *string, const char *name) if (!item_start) return 0; - length = strlen (name); - if (strncmp (item_start, name, length) == 0) + length = strlen (item_name); + if (strncmp (item_start, item_name, length) == 0) { if (!gui_bar_item_valid_char_name (item_start[length])) return 1; @@ -147,17 +147,18 @@ gui_bar_item_string_is_item (const char *string, const char *name) */ struct t_gui_bar_item * -gui_bar_item_search_with_plugin (struct t_weechat_plugin *plugin, const char *name) +gui_bar_item_search_with_plugin (struct t_weechat_plugin *plugin, + const char *item_name) { struct t_gui_bar_item *ptr_item; - if (!name || !name[0]) + if (!item_name || !item_name[0]) return NULL; for (ptr_item = gui_bar_items; ptr_item; ptr_item = ptr_item->next_item) { if ((ptr_item->plugin == plugin) - && (strcmp (ptr_item->name, name) == 0)) + && (strcmp (ptr_item->name, item_name) == 0)) return ptr_item; } @@ -166,6 +167,66 @@ gui_bar_item_search_with_plugin (struct t_weechat_plugin *plugin, const char *na } /* + * gui_bar_contains_item: return 1 if a bar contains item, O otherwise + */ + +int +gui_bar_contains_item (struct t_gui_bar *bar, const char *item_name) +{ + int i; + + if (!bar || !item_name || !item_name[0]) + return 0; + + for (i = 0; i < bar->items_count; i++) + { + /* skip non letters chars at beginning (prefix) */ + if (gui_bar_item_string_is_item (bar->items_array[i], item_name)) + return 1; + } + + /* item is not in bar */ + return 0; +} + +/* + * gui_bar_item_used_in_a_bar: return 1 if an item is used in at least one bar + * if partial_name == 1, then search a bar that + * contains item beginning with "item_name" + */ + +int +gui_bar_item_used_in_a_bar (const char *item_name, int partial_name) +{ + struct t_gui_bar *ptr_bar; + int i, length; + const char *ptr_start; + + length = strlen (item_name); + + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + for (i = 0; i < ptr_bar->items_count; i++) + { + ptr_start = gui_bar_item_string_get_item_start (ptr_bar->items_array[i]); + if (ptr_start) + { + if ((partial_name + && strncmp (ptr_start, item_name, length) == 0) + || (!partial_name + && strcmp (ptr_start, item_name) == 0)) + { + return 1; + } + } + } + } + + /* item not used by any bar */ + return 0; +} + +/* * gui_bar_item_input_text_update_for_display: update input text item for * display: * - scroll if needed, to see only @@ -457,41 +518,18 @@ gui_bar_item_new (struct t_weechat_plugin *plugin, const char *name, } /* - * gui_bar_contains_item: return 1 if a bar contains item, O otherwise - */ - -int -gui_bar_contains_item (struct t_gui_bar *bar, const char *name) -{ - int i; - - if (!bar || !name || !name[0]) - return 0; - - for (i = 0; i < bar->items_count; i++) - { - /* skip non letters chars at beginning (prefix) */ - if (gui_bar_item_string_is_item (bar->items_array[i], name)) - return 1; - } - - /* item is not in bar */ - return 0; -} - -/* * gui_bar_item_update: update an item on all bars displayed on screen */ void -gui_bar_item_update (const char *name) +gui_bar_item_update (const char *item_name) { struct t_gui_bar *ptr_bar; for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) { if (!CONFIG_BOOLEAN(ptr_bar->hidden) - && gui_bar_contains_item (ptr_bar, name)) + && gui_bar_contains_item (ptr_bar, item_name)) { gui_bar_draw (ptr_bar); } |