1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Change theme handling

So far when loading a theme it also overwrote the preferences the user
set.

Lengthy discussion can be found at
https://github.com/profanity-im/profanity/issues/1077

Now we use `/theme load themename` to load the [colours] part of a
themem only.

`/theme full-load themename` will load the complete theme including
preferences set in there.

Regards https://github.com/profanity-im/profanity/issues/1077
This commit is contained in:
Michael Vetter 2020-01-29 12:33:55 +01:00
parent 5c41c5b380
commit cd80b6cbf2
6 changed files with 51 additions and 17 deletions

View File

@ -354,6 +354,7 @@ cmd_ac_init(void)
theme_ac = autocomplete_new();
autocomplete_add(theme_ac, "load");
autocomplete_add(theme_ac, "full-load");
autocomplete_add(theme_ac, "list");
autocomplete_add(theme_ac, "colours");
autocomplete_add(theme_ac, "properties");
@ -2414,23 +2415,49 @@ static char*
_theme_autocomplete(ProfWin *window, const char *const input, gboolean previous)
{
char *result = NULL;
if (strncmp(input, "/theme load ", 12) == 0) {
if (theme_load_ac == NULL) {
theme_load_ac = autocomplete_new();
GSList *themes = theme_list();
GSList *curr = themes;
while (curr) {
autocomplete_add(theme_load_ac, curr->data);
curr = g_slist_next(curr);
}
g_slist_free_full(themes, g_free);
autocomplete_add(theme_load_ac, "default");
}
result = autocomplete_param_with_ac(input, "/theme load", theme_load_ac, TRUE, previous);
if (result) {
return result;
}
}
if (strncmp(input, "/theme full-load ", 17) == 0) {
if (theme_load_ac == NULL) {
theme_load_ac = autocomplete_new();
GSList *themes = theme_list();
GSList *curr = themes;
while (curr) {
autocomplete_add(theme_load_ac, curr->data);
curr = g_slist_next(curr);
}
g_slist_free_full(themes, g_free);
autocomplete_add(theme_load_ac, "default");
}
result = autocomplete_param_with_ac(input, "/theme full-load", theme_load_ac, TRUE, previous);
if (result) {
return result;
}
}
result = autocomplete_param_with_ac(input, "/theme", theme_ac, TRUE, previous);
if (result) {
return result;

View File

@ -2136,15 +2136,17 @@ static struct cmd_t command_defs[] =
CMD_SYN(
"/theme list",
"/theme load <theme>",
"/theme full-load <theme>",
"/theme colours",
"/theme properties")
CMD_DESC(
"Load a theme, includes colours and UI options.")
CMD_ARGS(
{ "list", "List all available themes." },
{ "load <theme>", "Load the specified theme. 'default' will reset to the default theme." },
{ "colours", "Show colour values as rendered by the terminal." },
{ "properties", "Show colour settings for current theme." })
{ "list", "List all available themes." },
{ "load <theme>", "Load colours from specified theme. 'default' will reset to the default theme." },
{ "full-load <theme>", "Same as 'load' but will also load preferences set in the theme, not just colours." },
{ "colours", "Show colour values as rendered by the terminal." },
{ "properties", "Show colour settings for current theme." })
CMD_EXAMPLES(
"/theme list",
"/theme load forest")

View File

@ -804,7 +804,7 @@ _account_set_theme(char *account_name, char *theme)
ProfAccount *account = accounts_get_account(session_get_account_name());
if (account) {
if (g_strcmp0(account->name, account_name) == 0) {
theme_load(theme);
theme_load(theme, false);
ui_load_colours();
if (prefs_get_boolean(PREF_ROSTER)) {
ui_show_roster();
@ -1234,13 +1234,13 @@ cmd_disconnect(ProfWin *window, const char *const command, gchar **args)
char *theme = prefs_get_string(PREF_THEME);
if (theme) {
gboolean res = theme_load(theme);
gboolean res = theme_load(theme, false);
prefs_free_string(theme);
if (!res) {
theme_load("default");
theme_load("default", false);
}
} else {
theme_load("default");
theme_load("default", false);
}
ui_load_colours();
if (prefs_get_boolean(PREF_ROSTER)) {
@ -1699,6 +1699,9 @@ cmd_prefs(ProfWin *window, const char *const command, gchar **args)
gboolean
cmd_theme(ProfWin *window, const char *const command, gchar **args)
{
// 'full-load' means to load the theme including the settings (not just [colours])
gboolean fullload = (g_strcmp0(args[0], "full-load") == 0);
// list themes
if (g_strcmp0(args[0], "list") == 0) {
GSList *themes = theme_list();
@ -1706,10 +1709,10 @@ cmd_theme(ProfWin *window, const char *const command, gchar **args)
g_slist_free_full(themes, g_free);
// load a theme
} else if (g_strcmp0(args[0], "load") == 0) {
} else if (g_strcmp0(args[0], "load") == 0 || fullload) {
if (args[1] == NULL) {
cons_bad_cmd_usage(command);
} else if (theme_load(args[1])) {
} else if (theme_load(args[1], fullload)) {
ui_load_colours();
prefs_set_string(PREF_THEME, args[1]);
if (prefs_get_boolean(PREF_ROSTER)) {
@ -8619,12 +8622,12 @@ cmd_color(ProfWin *window, const char *const command, gchar **args)
char *theme = prefs_get_string(PREF_THEME);
if (theme) {
gboolean res = theme_load(theme);
gboolean res = theme_load(theme, false);
if (res) {
cons_show("Theme reloaded: %s", theme);
} else {
theme_load("default");
theme_load("default", false);
}
prefs_free_string(theme);

View File

@ -154,7 +154,7 @@ theme_init(const char *const theme_name)
g_hash_table_insert(defaults, strdup("untrusted"), strdup("red"));
g_hash_table_insert(defaults, strdup("cmd.wins.unread"), strdup("default"));
_load_preferences();
//_load_preferences();
}
gboolean
@ -174,12 +174,14 @@ theme_exists(const char *const theme_name)
}
gboolean
theme_load(const char *const theme_name)
theme_load(const char *const theme_name, gboolean load_theme_prefs)
{
color_pair_cache_reset();
if (_theme_load_file(theme_name)) {
_load_preferences();
if (load_theme_prefs) {
_load_preferences();
}
return TRUE;
} else {
return FALSE;

View File

@ -143,7 +143,7 @@ typedef enum {
void theme_init(const char *const theme_name);
void theme_init_colours(void);
gboolean theme_load(const char *const theme_name);
gboolean theme_load(const char *const theme_name, gboolean load_theme_prefs);
gboolean theme_exists(const char *const theme_name);
GSList* theme_list(void);
void theme_close(void);

View File

@ -364,7 +364,7 @@ void
ui_handle_login_account_success(ProfAccount *account, gboolean secured)
{
if (account->theme) {
if (theme_load(account->theme)) {
if (theme_load(account->theme, false)) {
ui_load_colours();
if (prefs_get_boolean(PREF_ROSTER)) {
ui_show_roster();