From 960a773ed1d724cac94f1a4c2249e072fc259e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 12 Mar 2019 19:39:36 +0100 Subject: [PATCH] Implement fucntion to force sort of the layer selector --- layer-selector.c | 19 +++++++++++++------ layer-selector.h | 10 ++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/layer-selector.c b/layer-selector.c index 35e6142..da3ac94 100644 --- a/layer-selector.c +++ b/layer-selector.c @@ -190,7 +190,6 @@ void generate_layer_widgets(GtkListBox *listbox, GList *libs) global_list_box = listbox; clear_list_box_widgets(listbox); - gtk_list_box_set_sort_func(listbox, sort_func, NULL, NULL); for (; libs != NULL; libs = libs->next) { lib = (struct gds_library *)libs->data; @@ -199,11 +198,8 @@ void generate_layer_widgets(GtkListBox *listbox, GList *libs) } /* For Cell List */ } /* For libs */ - /* Force sort */ - gtk_list_box_invalidate_sort(listbox); - - /* Disable sort, so user can sort layers */ - gtk_list_box_set_sort_func(listbox, NULL, NULL, NULL); + /* Sort the layers */ + layer_selector_force_sort(LAYER_SELECTOR_SORT_DOWN); /* Activate Buttons */ gtk_widget_set_sensitive(global_load_button, TRUE); @@ -446,4 +442,15 @@ void setup_save_mapping_callback(GtkWidget *button, GtkWindow *main_window) g_signal_connect(button, "clicked", G_CALLBACK(save_mapping_clicked), main_window); } +void layer_selector_force_sort(enum layer_selector_sort_algo sort_function) +{ + if (!global_list_box) + return; + + /* Set dorting function, sort, and disable sorting function */ + gtk_list_box_set_sort_func(global_list_box, sort_func, (gpointer)&sort_function, NULL); + gtk_list_box_invalidate_sort(global_list_box); + gtk_list_box_set_sort_func(global_list_box, NULL, NULL, NULL); +} + /** @} */ diff --git a/layer-selector.h b/layer-selector.h index 23bed29..7b5e414 100644 --- a/layer-selector.h +++ b/layer-selector.h @@ -69,4 +69,14 @@ GList *export_rendered_layer_info(); * @note The layer_info::name Element has to be freed manually */ void delete_layer_info_struct(struct layer_info *info); + +/** + * @brief Force sorting of the layer selector in a specified way + * + * If the layer selector is not yet set up, this function has no effect. + * + * @param sort_function Sorting direction + */ +void layer_selector_force_sort(enum layer_selector_sort_algo sort_function); + #endif /* __LAYER_SELECTOR_H__ */