From 6f5c0eb52505709fd92d01ed9102653cb47da4b4 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 9 Mar 2018 23:44:28 +0000 Subject: Preference to show/hide tab number --- src/command/cmd_ac.c | 1 + src/command/cmd_defs.c | 5 ++-- src/command/cmd_funcs.c | 22 +++++++++++++++ src/config/preferences.c | 5 ++++ src/config/preferences.h | 1 + src/ui/console.c | 5 ++++ src/ui/statusbar.c | 73 ++++++++++++++++++++++++++---------------------- 7 files changed, 77 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 31f719bd..de57ac82 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -797,6 +797,7 @@ cmd_ac_init(void) statusbar_show_ac = autocomplete_new(); autocomplete_add(statusbar_show_ac, "name"); + autocomplete_add(statusbar_show_ac, "number"); } void diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index fd1c5697..5a873309 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1358,8 +1358,8 @@ static struct cmd_t command_defs[] = CMD_TAGS( CMD_TAG_UI) CMD_SYN( - "/statusbar show name", - "/statusbar hide name", + "/statusbar show name|number", + "/statusbar hide name|number", "/statusbar maxtabs ", "/statusbar chat user|jid", "/statusbar room room|jid", @@ -1370,6 +1370,7 @@ static struct cmd_t command_defs[] = CMD_ARGS( { "maxtabs ", "Set the maximum number of tabs to display, must be between 0 and 10" }, { "show|hide name", "Show or hide names in tabs." }, + { "show|hide number", "Show or hide numbers in tabs." }, { "chat user|jid", "Show only the users name, or the full jid if no nick is present for chat tabs." }, { "room room|jid", "Show only the rooms name, or the full jid for room tabs." }, { "up", "Move the status bar up the screen." }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index ae7f2abc..e6e53ca4 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -5776,17 +5776,39 @@ cmd_statusbar(ProfWin *window, const char *const command, gchar **args) ui_resize(); return TRUE; } + if (g_strcmp0(args[1], "number") == 0) { + prefs_set_boolean(PREF_STATUSBAR_SHOW_NUMBER, TRUE); + cons_show("Enabled showing tab numbers."); + ui_resize(); + return TRUE; + } cons_bad_cmd_usage(command); return TRUE; } if (g_strcmp0(args[0], "hide") == 0) { if (g_strcmp0(args[1], "name") == 0) { + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER) == FALSE) { + cons_show("Cannot disable both names and numbers in statusbar."); + cons_show("Use '/statusbar maxtabs 0' to hide tabs."); + return TRUE; + } prefs_set_boolean(PREF_STATUSBAR_SHOW_NAME, FALSE); cons_show("Disabled showing tab names."); ui_resize(); return TRUE; } + if (g_strcmp0(args[1], "number") == 0) { + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME) == FALSE) { + cons_show("Cannot disable both names and numbers in statusbar."); + cons_show("Use '/statusbar maxtabs 0' to hide tabs."); + return TRUE; + } + prefs_set_boolean(PREF_STATUSBAR_SHOW_NUMBER, FALSE); + cons_show("Disabled showing tab numbers."); + ui_resize(); + return TRUE; + } cons_bad_cmd_usage(command); return TRUE; } diff --git a/src/config/preferences.c b/src/config/preferences.c index aea2786d..28883e76 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1587,6 +1587,7 @@ _get_group(preference_t pref) case PREF_CONSOLE_PRIVATE: case PREF_CONSOLE_CHAT: case PREF_STATUSBAR_SHOW_NAME: + case PREF_STATUSBAR_SHOW_NUMBER: case PREF_STATUSBAR_CHAT: case PREF_STATUSBAR_ROOM: return PREF_GROUP_UI; @@ -1844,6 +1845,8 @@ _get_key(preference_t pref) return "rooms.cache"; case PREF_STATUSBAR_SHOW_NAME: return "statusbar.show.name"; + case PREF_STATUSBAR_SHOW_NUMBER: + return "statusbar.show.number"; case PREF_STATUSBAR_CHAT: return "statusbar.chat"; case PREF_STATUSBAR_ROOM: @@ -1896,6 +1899,8 @@ _get_default_boolean(preference_t pref) case PREF_TRAY_READ: case PREF_BOOKMARK_INVITE: case PREF_ROOM_LIST_CACHE: + case PREF_STATUSBAR_SHOW_NAME: + case PREF_STATUSBAR_SHOW_NUMBER: return TRUE; default: return FALSE; diff --git a/src/config/preferences.h b/src/config/preferences.h index aef019e1..e1b666a0 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -144,6 +144,7 @@ typedef enum { PREF_PLUGINS_SOURCEPATH, PREF_ROOM_LIST_CACHE, PREF_STATUSBAR_SHOW_NAME, + PREF_STATUSBAR_SHOW_NUMBER, PREF_STATUSBAR_CHAT, PREF_STATUSBAR_ROOM, } preference_t; diff --git a/src/ui/console.c b/src/ui/console.c index dfc54df3..60c5c8f5 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1746,6 +1746,11 @@ cons_statusbar_setting(void) } else { cons_show("Show tab names (/statusbar) : OFF"); } + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER)) { + cons_show("Show tab numbers (/statusbar) : ON"); + } else { + cons_show("Show tab numbers (/statusbar) : OFF"); + } cons_show("Max tabs (/statusbar) : %d", prefs_get_statusbartabs()); diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 991d21f2..36011cbd 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -292,6 +292,7 @@ _status_bar_draw(void) pos = cols - _tabs_width(); int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); + gboolean show_number = prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER); gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); gint max_tabs = prefs_get_statusbartabs(); @@ -309,38 +310,28 @@ _status_bar_draw(void) } wattroff(statusbar_win, bracket_attrs); pos++; - if (tab) { - char *display_name = _display_name(tab); - if (tab->highlight) { - int status_attrs = theme_attrs(THEME_STATUS_NEW); - wattron(statusbar_win, status_attrs); - mvwprintw(statusbar_win, 0, pos, "%d", display_num); - if (show_name) { - pos++; - mvwprintw(statusbar_win, 0, pos, ":"); - pos++; - mvwprintw(statusbar_win, 0, pos, display_name); - pos += strlen(display_name) -1 ; - } - wattroff(statusbar_win, status_attrs); - } else { - int status_attrs = theme_attrs(THEME_STATUS_ACTIVE); - wattron(statusbar_win, status_attrs); - mvwprintw(statusbar_win, 0, pos, "%d", display_num); - if (show_name) { - pos++; - mvwprintw(statusbar_win, 0, pos, ":"); - pos++; - mvwprintw(statusbar_win, 0, pos, display_name); - pos += strlen(display_name) - 1; - } - wattroff(statusbar_win, status_attrs); - } - free(display_name); + char *display_name = _display_name(tab); + int status_attrs = 0; + if (tab->highlight) { + status_attrs = theme_attrs(THEME_STATUS_NEW); } else { - mvwprintw(statusbar_win, 0, pos, " "); + status_attrs = theme_attrs(THEME_STATUS_ACTIVE); } - pos++; + wattron(statusbar_win, status_attrs); + if (show_number) { + mvwprintw(statusbar_win, 0, pos, "%d", display_num); + pos++; + } + if (show_number && show_name) { + mvwprintw(statusbar_win, 0, pos, ":"); + pos++; + } + if (show_name) { + mvwprintw(statusbar_win, 0, pos, display_name); + pos += strlen(display_name); + } + wattroff(statusbar_win, status_attrs); + free(display_name); wattron(statusbar_win, bracket_attrs); if (i == statusbar->current_tab) { mvwprintw(statusbar_win, 0, pos, "-"); @@ -381,10 +372,11 @@ _destroy_tab(StatusBarTab *tab) static int _tabs_width(void) { + gboolean show_number = prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER); gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); gint max_tabs = prefs_get_statusbartabs(); - if (show_name) { + if (show_name && show_number) { int width = 4; int i = 0; for (i = 1; i <= max_tabs; i++) { @@ -397,9 +389,24 @@ _tabs_width(void) } } return width; - } else { - return g_hash_table_size(statusbar->tabs) * 3 + 4; } + + if (show_name && !show_number) { + int width = 4; + int i = 0; + for (i = 1; i <= max_tabs; i++) { + StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); + if (tab) { + char *display_name = _display_name(tab); + width += strlen(display_name); + width += 2; + free(display_name); + } + } + return width; + } + + return g_hash_table_size(statusbar->tabs) * 3 + 4; } static char* -- cgit 1.4.1-2-gfad0