From fbc57765a3627666be096e476b0a3b4a6ef6e786 Mon Sep 17 00:00:00 2001 From: Pete Date: Fri, 29 May 2015 14:25:14 +0100 Subject: Added window auto tidy. --- src/command/command.c | 10 +++++++++- src/command/commands.c | 17 ++++++++++++++++- src/command/commands.h | 1 + src/config/preferences.c | 4 ++++ src/config/preferences.h | 1 + src/ui/console.c | 10 ++++++++++ src/ui/ui.h | 1 + 7 files changed, 42 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/command/command.c b/src/command/command.c index bd0d741c..25571e81 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -684,6 +684,14 @@ static struct cmd_t command_defs[] = "Enable or disable word wrapping in the main window.", NULL } } }, + { "/winstidy", + cmd_winstidy, parse_args, 1, 1, &cons_winstidy_setting, + { "/winstidy on|off", "Auto tidy windows.", + { "/winstidy on|off", + "------------", + "Enable or disable auto window tidy.", + NULL } } }, + { "/time", cmd_time, parse_args, 1, 2, &cons_time_setting, { "/time setting|statusbar [setting]", "Time display.", @@ -1921,7 +1929,7 @@ _cmd_complete_parameters(const char * const input) // autocomplete boolean settings gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", "/chlog", "/grlog", "/mouse", "/history", - "/vercheck", "/privileges", "/presence", "/wrap", "/carbons" }; + "/vercheck", "/privileges", "/presence", "/wrap", "/winstidy", "/carbons" }; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice); diff --git a/src/command/commands.c b/src/command/commands.c index b942acd4..89ded432 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -718,6 +718,16 @@ cmd_wins(gchar **args, struct cmd_help_t help) return TRUE; } +gboolean +cmd_winstidy(gchar **args, struct cmd_help_t help) +{ + gboolean result = _cmd_set_boolean_preference(args[0], help, "Wins Auto Tidy", PREF_WINS_AUTO_TIDY); + + wins_resize_all(); + + return result; +} + gboolean cmd_win(gchar **args, struct cmd_help_t help) { @@ -804,7 +814,7 @@ cmd_help(gchar **args, struct cmd_help_t help) "/carbons", "/chlog", "/flash", "/gone", "/grlog", "/history", "/intype", "/log", "/mouse", "/notify", "/outtype", "/prefs", "/priority", "/reconnect", "/roster", "/splash", "/states", "/statuses", "/theme", - "/titlebar", "/vercheck", "/privileges", "/occupants", "/presence", "/wrap" }; + "/titlebar", "/vercheck", "/privileges", "/occupants", "/presence", "/wrap", "/winstidy" }; _cmd_show_filtered_help("Settings commands", filter, ARRAY_SIZE(filter)); } else if (strcmp(args[0], "navigation") == 0) { @@ -3242,6 +3252,11 @@ cmd_close(gchar **args, struct cmd_help_t help) ui_close_win(index); cons_show("Closed window %d", index); + // Tidy up the window list. + if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) { + ui_tidy_wins(); + } + return TRUE; } diff --git a/src/command/commands.h b/src/command/commands.h index 7b7e7c93..fb5372a6 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -125,6 +125,7 @@ gboolean cmd_vercheck(gchar **args, struct cmd_help_t help); gboolean cmd_who(gchar **args, struct cmd_help_t help); gboolean cmd_win(gchar **args, struct cmd_help_t help); gboolean cmd_wins(gchar **args, struct cmd_help_t help); +gboolean cmd_winstidy(gchar **args, struct cmd_help_t help); gboolean cmd_xa(gchar **args, struct cmd_help_t help); gboolean cmd_alias(gchar **args, struct cmd_help_t help); gboolean cmd_xmlconsole(gchar **args, struct cmd_help_t help); diff --git a/src/config/preferences.c b/src/config/preferences.c index 59a6a7ca..b7ca113e 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -507,6 +507,7 @@ _get_group(preference_t pref) case PREF_MUC_PRIVILEGES: case PREF_PRESENCE: case PREF_WRAP: + case PREF_WINS_AUTO_TIDY: case PREF_TIME: case PREF_TIME_STATUSBAR: case PREF_ROSTER: @@ -654,6 +655,8 @@ _get_key(preference_t pref) return "presence"; case PREF_WRAP: return "wrap"; + case PREF_WINS_AUTO_TIDY: + return "wins.autotidy"; case PREF_TIME: return "time"; case PREF_TIME_STATUSBAR: @@ -700,6 +703,7 @@ _get_default_boolean(preference_t pref) case PREF_MUC_PRIVILEGES: case PREF_PRESENCE: case PREF_WRAP: + case PREF_WINS_AUTO_TIDY: case PREF_INPBLOCK_DYNAMIC: case PREF_RESOURCE_TITLE: case PREF_RESOURCE_MESSAGE: diff --git a/src/config/preferences.h b/src/config/preferences.h index 4455eca1..d1faca63 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -74,6 +74,7 @@ typedef enum { PREF_MUC_PRIVILEGES, PREF_PRESENCE, PREF_WRAP, + PREF_WINS_AUTO_TIDY, PREF_TIME, PREF_TIME_STATUSBAR, PREF_STATUSES, diff --git a/src/ui/console.c b/src/ui/console.c index a41ccad6..1fa8b7b1 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -871,6 +871,15 @@ cons_wrap_setting(void) cons_show("Word wrap (/wrap) : OFF"); } +void +cons_winstidy_setting(void) +{ + if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) + cons_show("Window Auto Tidy (/winstidy) : ON"); + else + cons_show("Window Auto Tidy (/winstidy) : OFF"); +} + void cons_presence_setting(void) { @@ -1035,6 +1044,7 @@ cons_show_ui_prefs(void) cons_flash_setting(); cons_splash_setting(); cons_wrap_setting(); + cons_winstidy_setting(); cons_time_setting(); cons_resource_setting(); cons_vercheck_setting(); diff --git a/src/ui/ui.h b/src/ui/ui.h index 0ee21be4..8f6a364e 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -305,6 +305,7 @@ void cons_occupants_setting(void); void cons_roster_setting(void); void cons_presence_setting(void); void cons_wrap_setting(void); +void cons_winstidy_setting(void); void cons_time_setting(void); void cons_mouse_setting(void); void cons_statuses_setting(void); -- cgit 1.4.1-2-gfad0 From 0564976264f532b48050656b12dc2d4a3c15d8c3 Mon Sep 17 00:00:00 2001 From: Pete Date: Mon, 1 Jun 2015 11:27:01 +0100 Subject: Refactored 'ui_tidy_wins()' to return bool and not output text, Corrected underline, removed call to function 'wins_resize_all()'. --- src/command/command.c | 2 +- src/command/commands.c | 9 ++++++--- src/ui/core.c | 10 ++-------- src/ui/ui.h | 2 +- tests/ui/stub_ui.c | 5 ++++- 5 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/command/command.c b/src/command/command.c index 25571e81..ea6df2ba 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -688,7 +688,7 @@ static struct cmd_t command_defs[] = cmd_winstidy, parse_args, 1, 1, &cons_winstidy_setting, { "/winstidy on|off", "Auto tidy windows.", { "/winstidy on|off", - "------------", + "---------------", "Enable or disable auto window tidy.", NULL } } }, diff --git a/src/command/commands.c b/src/command/commands.c index 89ded432..86781330 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -689,7 +689,11 @@ cmd_wins(gchar **args, struct cmd_help_t help) if (args[0] == NULL) { cons_show_wins(); } else if (strcmp(args[0], "tidy") == 0) { - ui_tidy_wins(); + if ( ui_tidy_wins() ) { + cons_show("Windows tidied."); + } else { + cons_show("No tidy needed."); + } } else if (strcmp(args[0], "prune") == 0) { ui_prune_wins(); } else if (strcmp(args[0], "swap") == 0) { @@ -723,8 +727,6 @@ cmd_winstidy(gchar **args, struct cmd_help_t help) { gboolean result = _cmd_set_boolean_preference(args[0], help, "Wins Auto Tidy", PREF_WINS_AUTO_TIDY); - wins_resize_all(); - return result; } @@ -3254,6 +3256,7 @@ cmd_close(gchar **args, struct cmd_help_t help) // Tidy up the window list. if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) { + // TODO: Any benefit of checking the return value? ui_tidy_wins(); } diff --git a/src/ui/core.c b/src/ui/core.c index e7059ef0..c028e818 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1105,16 +1105,10 @@ ui_close_win(int index) status_bar_active(1); } -void +gboolean ui_tidy_wins(void) { - gboolean tidied = wins_tidy(); - - if (tidied) { - cons_show("Windows tidied."); - } else { - cons_show("No tidy needed."); - } + return wins_tidy(); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 8f6a364e..29ee6bef 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -216,7 +216,7 @@ void ui_show_all_room_rosters(void); void ui_hide_all_room_rosters(void); gboolean ui_chat_win_exists(const char * const barejid); -void ui_tidy_wins(void); +gboolean ui_tidy_wins(void); void ui_prune_wins(void); gboolean ui_swap_wins(int source_win, int target_win); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index c2f2465b..4c53eae5 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -315,7 +315,10 @@ void ui_redraw_all_room_rosters(void) {} void ui_show_all_room_rosters(void) {} void ui_hide_all_room_rosters(void) {} -void ui_tidy_wins(void) {} +gboolean ui_tidy_wins(void) { + // TODO: I'm assuming it should return true, but lack knowledge about the tests. + return TRUE; +} void ui_prune_wins(void) {} gboolean ui_swap_wins(int source_win, int target_win) { -- cgit 1.4.1-2-gfad0 From 7bc671e07cc5398a314751917bc1897c615fe12d Mon Sep 17 00:00:00 2001 From: Pete Maynard Date: Mon, 1 Jun 2015 11:33:19 +0100 Subject: Extra underline --- src/command/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/command/command.c b/src/command/command.c index ea6df2ba..c62c7784 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -688,7 +688,7 @@ static struct cmd_t command_defs[] = cmd_winstidy, parse_args, 1, 1, &cons_winstidy_setting, { "/winstidy on|off", "Auto tidy windows.", { "/winstidy on|off", - "---------------", + "----------------", "Enable or disable auto window tidy.", NULL } } }, -- cgit 1.4.1-2-gfad0 From 2ce35fe61c2d5d77069397d1b8ce5a714d174da9 Mon Sep 17 00:00:00 2001 From: Pete Date: Mon, 1 Jun 2015 11:44:52 +0100 Subject: Added Theme UI option for window auto tidy --- src/config/theme.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/config/theme.c b/src/config/theme.c index f73dee19..537771b1 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -428,6 +428,7 @@ _load_preferences(void) _set_boolean_preference("flash", PREF_FLASH); _set_boolean_preference("splash", PREF_SPLASH); _set_boolean_preference("wrap", PREF_WRAP); + _set_boolean_preference("wins.autotidy", PREF_WINS_AUTO_TIDY); _set_string_preference("time", PREF_TIME); _set_string_preference("time.statusbar", PREF_TIME_STATUSBAR); -- cgit 1.4.1-2-gfad0 From a0a7d04a5f28957f7b07c533e38a4cc59888164c Mon Sep 17 00:00:00 2001 From: Pete Date: Mon, 1 Jun 2015 14:47:02 +0100 Subject: Tidy up windows when enabling --- src/command/commands.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/command/commands.c b/src/command/commands.c index 86781330..9b4d6635 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -727,6 +727,10 @@ cmd_winstidy(gchar **args, struct cmd_help_t help) { gboolean result = _cmd_set_boolean_preference(args[0], help, "Wins Auto Tidy", PREF_WINS_AUTO_TIDY); + if( result ) { + ui_tidy_wins(); + } + return result; } -- cgit 1.4.1-2-gfad0