Compare commits
5 Commits
2a204640bd
...
e24b4a8367
Author | SHA1 | Date | |
---|---|---|---|
e24b4a8367 | |||
960a773ed1 | |||
ab23be1cfc | |||
72d5352b09 | |||
3f198f870a |
@ -2,6 +2,16 @@
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stock">gtk-go-up</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="image2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stock">gtk-go-down</property>
|
||||
</object>
|
||||
<object class="GtkWindow" id="main-window">
|
||||
<property name="height_request">250</property>
|
||||
<property name="can_focus">False</property>
|
||||
@ -132,23 +142,74 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">never</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkViewport">
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkListBox" id="layer-list">
|
||||
<object class="GtkButton" id="button-up-sort">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="image">image1</property>
|
||||
<property name="always_show_image">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button-down-sort">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="image">image2</property>
|
||||
<property name="always_show_image">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">never</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkViewport">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="selection_mode">none</property>
|
||||
<child>
|
||||
<object class="GtkListBox" id="layer-list">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="selection_mode">none</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
|
@ -155,19 +155,30 @@ static void analyze_cell_layers(GtkListBox *listbox, struct gds_cell *cell)
|
||||
* @param row1
|
||||
* @param row2
|
||||
* @param unused
|
||||
* @note Do not use this function
|
||||
* @return
|
||||
* @note Do not use this function. This is an internal callback
|
||||
* @return See sort function documentation of GTK+
|
||||
*/
|
||||
static gint sort_func(GtkListBoxRow *row1, GtkListBoxRow *row2, gpointer unused)
|
||||
{
|
||||
LayerElement *le1, *le2;
|
||||
gint ret;
|
||||
static const enum layer_selector_sort_algo default_sort = LAYER_SELECTOR_SORT_DOWN;
|
||||
const enum layer_selector_sort_algo *algo = (const enum layer_selector_sort_algo *)unused;
|
||||
|
||||
/* Assume downward sorting */
|
||||
/* TODO: This is nasty. Find a better way */
|
||||
if (!algo)
|
||||
algo = &default_sort;
|
||||
|
||||
le1 = LAYER_ELEMENT(row1);
|
||||
le2 = LAYER_ELEMENT(row2);
|
||||
|
||||
/* Determine sort fow downward sort */
|
||||
ret = layer_element_get_layer(le1) - layer_element_get_layer(le2);
|
||||
|
||||
/* Change order if upward sort is requested */
|
||||
ret *= (*algo == LAYER_SELECTOR_SORT_DOWN ? 1 : -1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -179,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;
|
||||
@ -188,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);
|
||||
@ -435,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);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -30,6 +30,11 @@
|
||||
#include <glib.h>
|
||||
#include "mapping-parser.h"
|
||||
|
||||
/**
|
||||
* @brief Defines how to sort the layer selector list box.
|
||||
*/
|
||||
enum layer_selector_sort_algo {LAYER_SELECTOR_SORT_DOWN = 0, LAYER_SELECTOR_SORT_UP};
|
||||
|
||||
/**
|
||||
* @brief Generate layer widgets in \p listbox
|
||||
* @note This clears all previously inserted elements
|
||||
@ -64,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__ */
|
||||
|
@ -384,6 +384,22 @@ static void cell_selection_changed(GtkTreeSelection *sel, GtkWidget *convert_but
|
||||
}
|
||||
}
|
||||
|
||||
static void sort_up_callback(GtkWidget *widget, gpointer user)
|
||||
{
|
||||
(void)widget;
|
||||
(void)user;
|
||||
|
||||
layer_selector_force_sort(LAYER_SELECTOR_SORT_UP);
|
||||
}
|
||||
|
||||
static void sort_down_callback(GtkWidget *widget, gpointer user)
|
||||
{
|
||||
(void)widget;
|
||||
(void)user;
|
||||
|
||||
layer_selector_force_sort(LAYER_SELECTOR_SORT_DOWN);
|
||||
}
|
||||
|
||||
GtkWindow *create_main_window()
|
||||
{
|
||||
GtkBuilder *main_builder;
|
||||
@ -396,6 +412,8 @@ GtkWindow *create_main_window()
|
||||
static struct open_button_data open_data;
|
||||
static struct convert_button_data conv_data;
|
||||
struct tree_stores *cell_selector_stores;
|
||||
GtkWidget *sort_up_button;
|
||||
GtkWidget *sort_down_button;
|
||||
|
||||
main_builder = gtk_builder_new_from_resource("/main.glade");
|
||||
gtk_builder_connect_signals(main_builder, NULL);
|
||||
@ -440,6 +458,13 @@ GtkWindow *create_main_window()
|
||||
header_bar = GTK_HEADER_BAR(gtk_builder_get_object(main_builder, "header-bar"));
|
||||
gtk_header_bar_set_subtitle(header_bar, _app_version_string);
|
||||
|
||||
/* Get layer sorting buttons and set callbacks */
|
||||
sort_up_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "button-up-sort"));
|
||||
sort_down_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "button-down-sort"));
|
||||
|
||||
g_signal_connect(sort_up_button, "clicked", G_CALLBACK(sort_up_callback), NULL);
|
||||
g_signal_connect(sort_down_button, "clicked", G_CALLBACK(sort_down_callback), NULL);
|
||||
|
||||
g_object_unref(main_builder);
|
||||
|
||||
return conv_data.main_window;
|
||||
|
Loading…
Reference in New Issue
Block a user