Improve Autonaming in GUI
Autonaming now only asks for overwrite confirmation, if there are layers with non empty names. Otherwise, the dialog is not shown.
This commit is contained in:
parent
554b73c406
commit
238f2cea82
@ -691,19 +691,13 @@ static void on_select_all_layers_clicked(GtkWidget *button, gpointer user_data)
|
||||
layer_selector_select_all_layers(gui->layer_selector, TRUE);
|
||||
}
|
||||
|
||||
static void auto_naming_clicked(GtkWidget *button, gpointer user_data)
|
||||
static gboolean auto_naming_ask_for_override(GdsRenderGui *gui)
|
||||
{
|
||||
GdsRenderGui *gui;
|
||||
GtkDialog *dialog;
|
||||
gboolean overwrite;
|
||||
int dialog_result;
|
||||
(void)button;
|
||||
gint dialog_result;
|
||||
gboolean overwrite = FALSE;
|
||||
|
||||
gui = RENDERER_GUI(user_data);
|
||||
|
||||
/* Don't do anything if the selector is empty. */
|
||||
if (!layer_selector_contains_elements(gui->layer_selector))
|
||||
return;
|
||||
g_return_val_if_fail(RENDERER_IS_GUI(gui), FALSE);
|
||||
|
||||
/* Ask for overwrite */
|
||||
dialog = GTK_DIALOG(gtk_message_dialog_new(gui->main_window, GTK_DIALOG_USE_HEADER_BAR, GTK_MESSAGE_QUESTION,
|
||||
@ -720,6 +714,25 @@ static void auto_naming_clicked(GtkWidget *button, gpointer user_data)
|
||||
}
|
||||
gtk_widget_destroy(GTK_WIDGET(dialog));
|
||||
|
||||
return overwrite;
|
||||
}
|
||||
|
||||
static void auto_naming_clicked(GtkWidget *button, gpointer user_data)
|
||||
{
|
||||
GdsRenderGui *gui;
|
||||
gboolean overwrite = FALSE;
|
||||
(void)button;
|
||||
|
||||
gui = RENDERER_GUI(user_data);
|
||||
|
||||
/* Don't do anything if the selector is empty. */
|
||||
if (!layer_selector_contains_elements(gui->layer_selector))
|
||||
return;
|
||||
|
||||
/* Ask, if names shall be overwritten, if they are not empty */
|
||||
if (layer_selector_num_of_named_elements(gui->layer_selector) > 0)
|
||||
overwrite = auto_naming_ask_for_override(gui);
|
||||
|
||||
layer_selector_auto_name_layers(gui->layer_selector, overwrite);
|
||||
}
|
||||
|
||||
|
@ -130,6 +130,13 @@ void layer_selector_auto_name_layers(LayerSelector *layer_selector, gboolean ove
|
||||
*/
|
||||
gboolean layer_selector_contains_elements(LayerSelector *layer_selector);
|
||||
|
||||
/**
|
||||
* @brief Get number of layer elements that are named
|
||||
* @param[in] layer_selector Layer selector
|
||||
* @return Number of layers with a name != NULL or != ""
|
||||
*/
|
||||
size_t layer_selector_num_of_named_elements(LayerSelector *layer_selector);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __LAYER_SELECTOR_H__ */
|
||||
|
@ -822,12 +822,10 @@ void layer_selector_auto_color_layers(LayerSelector *layer_selector, ColorPalett
|
||||
unsigned int color_count;
|
||||
GdkRGBA color;
|
||||
|
||||
if (GDS_RENDER_IS_COLOR_PALETTE(palette) == FALSE || LAYER_IS_SELECTOR(layer_selector) == FALSE)
|
||||
return;
|
||||
if (global_alpha <= 0)
|
||||
return;
|
||||
if (GTK_IS_LIST_BOX(layer_selector->list_box) == FALSE)
|
||||
return;
|
||||
g_return_if_fail(GDS_RENDER_IS_COLOR_PALETTE(palette));
|
||||
g_return_if_fail(LAYER_IS_SELECTOR(layer_selector));
|
||||
g_return_if_fail(global_alpha > 0);
|
||||
g_return_if_fail(GTK_IS_LIST_BOX(layer_selector->list_box));
|
||||
|
||||
le_list = gtk_container_get_children(GTK_CONTAINER(layer_selector->list_box));
|
||||
|
||||
@ -898,4 +896,31 @@ gboolean layer_selector_contains_elements(LayerSelector *layer_selector)
|
||||
return (layer_element_list ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
size_t layer_selector_num_of_named_elements(LayerSelector *layer_selector)
|
||||
{
|
||||
GList *le_list;
|
||||
GList *le_list_ptr;
|
||||
LayerElement *le;
|
||||
const char *layer_name;
|
||||
size_t count = 0U;
|
||||
|
||||
g_return_val_if_fail(LAYER_IS_SELECTOR(layer_selector), 0U);
|
||||
|
||||
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;
|
||||
layer_name = layer_element_get_name(le);
|
||||
|
||||
if (layer_name && *layer_name) {
|
||||
/* Layer name is not empty. Count it */
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user