mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
[Theme] Validate variables in theme and throw error on fail.
issue: #1580
This commit is contained in:
parent
af8a3505b5
commit
a34c13bdb2
3 changed files with 58 additions and 1 deletions
|
@ -412,6 +412,11 @@ char *rofi_theme_parse_prepare_file(const char *file, const char *parent_file);
|
|||
*/
|
||||
void rofi_theme_parse_process_conditionals(void);
|
||||
|
||||
/**
|
||||
* Process links.
|
||||
*/
|
||||
void rofi_theme_parse_process_links(void);
|
||||
|
||||
/**
|
||||
* @param parent target theme tree
|
||||
* @param child source theme three
|
||||
|
|
|
@ -1069,6 +1069,7 @@ int main(int argc, char *argv[]) {
|
|||
TICK_N("Setup late Display");
|
||||
|
||||
rofi_theme_parse_process_conditionals();
|
||||
rofi_theme_parse_process_links();
|
||||
TICK_N("Theme setup");
|
||||
|
||||
// Setup signal handling sources.
|
||||
|
@ -1091,6 +1092,7 @@ int main(int argc, char *argv[]) {
|
|||
extern GList *list_of_error_msgs;
|
||||
int rofi_theme_rasi_validate(const char *filename) {
|
||||
rofi_theme_parse_file(filename);
|
||||
rofi_theme_parse_process_links();
|
||||
if (list_of_error_msgs == NULL) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -1098,6 +1100,7 @@ int rofi_theme_rasi_validate(const char *filename) {
|
|||
for (GList *iter = g_list_first(list_of_error_msgs); iter != NULL;
|
||||
iter = g_list_next(iter)) {
|
||||
fputs(((GString *)iter->data)->str, stderr);
|
||||
fputs("\n", stderr);
|
||||
}
|
||||
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -715,7 +715,6 @@ static void rofi_theme_resolve_link_property(Property *p, int depth) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
g_warning("Failed to resolve variable '%s'", name);
|
||||
// No found and we have default value.
|
||||
if (p->value.link.def_value) {
|
||||
p->value.link.ref = p->value.link.def_value;
|
||||
|
@ -1543,6 +1542,56 @@ static void rofi_theme_parse_process_conditionals_int(workarea mon,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char *rofi_theme_widget_get_name(ThemeWidget *wid) {
|
||||
GString *str = g_string_new(wid->name);
|
||||
for (ThemeWidget *i = wid->parent; i->parent != NULL; i = i->parent) {
|
||||
g_string_prepend_c(str, ' ');
|
||||
g_string_prepend(str, i->name);
|
||||
}
|
||||
char *retv = str->str;
|
||||
g_string_free(str, FALSE);
|
||||
return retv;
|
||||
}
|
||||
|
||||
static void rofi_theme_parse_process_links_int(ThemeWidget *wid) {
|
||||
if (wid == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < wid->num_widgets; i++) {
|
||||
ThemeWidget *widget = wid->widgets[i];
|
||||
rofi_theme_parse_process_links_int(widget);
|
||||
if (widget->properties == NULL) {
|
||||
continue;
|
||||
}
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
g_hash_table_iter_init(&iter, widget->properties);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
Property *pv = (Property *)value;
|
||||
if (pv->type == P_LINK) {
|
||||
if (pv->value.link.ref == NULL) {
|
||||
rofi_theme_resolve_link_property(pv, 0);
|
||||
if (pv->value.link.ref == pv) {
|
||||
char *n = rofi_theme_widget_get_name(widget);
|
||||
GString *str = g_string_new(NULL);
|
||||
g_string_printf(str, "Failed to resolve: `%s { %s: var(%s);}`", n,
|
||||
pv->name, pv->value.link.name);
|
||||
|
||||
rofi_add_error_message(str);
|
||||
g_free(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rofi_theme_parse_process_links(void) {
|
||||
rofi_theme_parse_process_links_int(rofi_theme);
|
||||
}
|
||||
|
||||
void rofi_theme_parse_process_conditionals(void) {
|
||||
workarea mon;
|
||||
monitor_active(&mon);
|
||||
|
|
Loading…
Reference in a new issue