Compare commits

...

2 Commits

2 changed files with 42 additions and 1 deletions

View File

@ -103,10 +103,21 @@ void layer_selector_select_all_layers(LayerSelector *layer_selector, gboolean se
* @brief Apply colors from palette to all layers. Aditionally set alpha
* @param layer_selector LayerSelector object
* @param palette Color palette to use
* @param global_alpha Additional alpha value that is applied to all layers
* @param global_alpha Additional alpha value that is applied to all layers. Must be > 0
*/
void layer_selector_auto_color_layers(LayerSelector *layer_selector, ColorPalette *palette, double global_alpha);
/**
* @brief Auto name all layers in the layer selector.
*
* This functions sets the name of the layer equal to its number.
* The \p overwrite parameter specifies if already set layer names are overwritten.
*
* @param layer_selector LayerSelector
* @param overwrite Overwrite existing layer names
*/
void layer_selector_auto_name_layers(LayerSelector *layer_selector, gboolean overwrite);
G_END_DECLS
#endif /* __LAYER_SELECTOR_H__ */

View File

@ -857,4 +857,34 @@ ret_free_le_list:
g_list_free(le_list);
}
void layer_selector_auto_name_layers(LayerSelector *layer_selector, gboolean overwrite)
{
GList *le_list;
GList *le_list_ptr;
LayerElement *le;
const char *old_layer_name;
GString *new_layer_name;
g_return_if_fail(LAYER_IS_SELECTOR(layer_selector));
new_layer_name = g_string_new_len(NULL, 10);
le_list = gtk_container_get_children(GTK_CONTAINER(layer_selector->list_box));
for (le_list_ptr = le_list; le_list_ptr != NULL; le_list_ptr = g_list_next(le_list_ptr)) {
le = LAYER_ELEMENT(le_list_ptr->data);
if (!le)
continue;
old_layer_name = layer_element_get_name(le);
/* Check if layer name is empty or may be overwritten */
if (!old_layer_name || *old_layer_name == '\0' || overwrite) {
g_string_printf(new_layer_name, "Layer %d", layer_element_get_layer(le));
layer_element_set_name(le, new_layer_name->str);
}
}
g_string_free(new_layer_name, TRUE);
g_list_free(le_list);
}
/** @} */