Add max tabs preference for statusbar

This commit is contained in:
James Booth
2018-03-08 23:11:49 +00:00
parent 720dce866e
commit a957c545d3
7 changed files with 111 additions and 59 deletions

View File

@@ -1544,6 +1544,7 @@ cons_show_ui_prefs(void)
cons_presence_setting();
cons_inpblock_setting();
cons_tlsshow_setting();
cons_statusbar_setting();
cons_alert();
}
@@ -1750,7 +1751,6 @@ cons_inpblock_setting(void)
void
cons_statusbar_setting(void)
{
cons_winpos_setting();
if (prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY)) {
cons_show("Show empty tabs (/statusbar) : ON");
} else {
@@ -1761,6 +1761,8 @@ cons_statusbar_setting(void)
} else {
cons_show("Show tab names (/statusbar) : OFF");
}
cons_show("Max tabs (/statusbar) : %d", prefs_get_statusbartabs());
}
void

View File

@@ -63,24 +63,13 @@ typedef struct _status_bar_t {
int current_tab;
} StatusBar;
#define MAX_TABS 10
static GTimeZone *tz;
static StatusBar *statusbar;
static WINDOW *statusbar_win;
static void _status_bar_draw(void);
void
_destroy_tab(StatusBarTab *tab)
{
if (tab) {
if (tab->display_name) {
free(tab->display_name);
}
free(tab);
}
}
static void _destroy_tab(StatusBarTab *tab);
static int _tabs_width(void);
void
status_bar_init(void)
@@ -241,47 +230,6 @@ status_bar_clear_message(void)
_status_bar_draw();
}
static int
_tabs_width(void)
{
gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY);
gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME);
if (show_name) {
if (show_empty) {
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) {
width += strlen(tab->display_name);
width += 4;
} else {
width += 3;
}
}
return width;
} else {
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) {
width += strlen(tab->display_name);
width += 4;
}
}
return width;
}
} else {
if (show_empty) {
return MAX_TABS * 3 + 4;
} else {
return g_hash_table_size(statusbar->tabs) * 3 + 4;
}
}
}
static void
_status_bar_draw(void)
{
@@ -339,9 +287,10 @@ _status_bar_draw(void)
gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY);
gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME);
gint max_tabs = prefs_get_statusbartabs();
int i = 1;
for (i = 1; i <= MAX_TABS; i++) {
for (i = 1; i <= max_tabs; i++) {
int display_num = i == 10 ? 0 : i;
StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i));
@@ -409,3 +358,56 @@ _status_bar_draw(void)
wnoutrefresh(statusbar_win);
inp_put_back();
}
static void
_destroy_tab(StatusBarTab *tab)
{
if (tab) {
if (tab->display_name) {
free(tab->display_name);
}
free(tab);
}
}
static int
_tabs_width(void)
{
gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY);
gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME);
gint max_tabs = prefs_get_statusbartabs();
if (show_name) {
if (show_empty) {
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) {
width += strlen(tab->display_name);
width += 4;
} else {
width += 3;
}
}
return width;
} else {
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) {
width += strlen(tab->display_name);
width += 4;
}
}
return width;
}
} else {
if (show_empty) {
return max_tabs * 3 + 4;
} else {
return g_hash_table_size(statusbar->tabs) * 3 + 4;
}
}
}