parent
ac83d890c7
commit
2525224a0f
@ -1,116 +1,91 @@
|
|||||||
#include "ubl-settings-bootloader.h"
|
#include "ubl-settings-bootloader.h"
|
||||||
|
|
||||||
|
void on_menu_chosen(GtkWidget *widget, dictionary *dict) {
|
||||||
|
yon_menu_item *item = yon_dictionary_get_data(dict->first, yon_menu_item *);
|
||||||
|
main_window *widgets = yon_dictionary_get_data(dict->first->next, main_window *);
|
||||||
|
gtk_entry_set_text(GTK_ENTRY(widgets->OSEntry), item->target);
|
||||||
|
|
||||||
|
yon_menu_window *window = yon_dictionary_get_data(dict->first->next->next, yon_menu_window *);
|
||||||
|
GdkDisplay *display = gdk_display_get_default();
|
||||||
|
GdkSeat *seat = gdk_display_get_default_seat(display);
|
||||||
|
gdk_seat_ungrab(seat);
|
||||||
|
gtk_widget_destroy(window->MenuWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_submenu_open(GtkWidget *widget, dictionary *dict) {
|
||||||
|
yon_menu_window *window = yon_dictionary_get_data(dict->first, yon_menu_window *);
|
||||||
|
yon_menu_item *item = yon_dictionary_get_data(dict->first->next, yon_menu_item *);
|
||||||
|
main_window *widgets = yon_dictionary_get_data(dict->first->next->next, main_window *);
|
||||||
|
|
||||||
void on_menu_chosen(GtkWidget *,dictionary *){
|
on_children_clean(NULL, window);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_submenu_open(GtkWidget *,dictionary *dict){
|
|
||||||
yon_menu_window *window = yon_dictionary_get_data(dict->first,yon_menu_window*);
|
|
||||||
yon_menu_item *item = yon_dictionary_get_data(dict->first->next,yon_menu_item*);
|
|
||||||
dictionary *dact = NULL;
|
dictionary *dact = NULL;
|
||||||
for_dictionaries(dact,item->children){
|
for_dictionaries(dact, item->children) {
|
||||||
yon_menu_item *child = yon_dictionary_get_data(dact,yon_menu_item*);
|
yon_menu_item *child = yon_dictionary_get_data(dact, yon_menu_item *);
|
||||||
gtk_list_box_insert(GTK_LIST_BOX(window->ChildrenListBox),child->MenuItemBox,-1);
|
gtk_list_box_insert(GTK_LIST_BOX(window->ChildrenListBox), child->MenuItemBox, -1);
|
||||||
g_signal_connect(G_OBJECT(child->MenuButton),"clicked",G_CALLBACK(on_menu_chosen),item);
|
|
||||||
|
dictionary *child_dict = NULL;
|
||||||
|
yon_dictionary_add_or_create_if_exists_with_data(child_dict, "item", child);
|
||||||
|
yon_dictionary_add_or_create_if_exists_with_data(child_dict, "widgets", widgets);
|
||||||
|
yon_dictionary_add_or_create_if_exists_with_data(child_dict, "window", window);
|
||||||
|
g_signal_connect(G_OBJECT(child->MenuButton), "clicked", G_CALLBACK(on_menu_chosen), child_dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gtk_revealer_set_reveal_child(GTK_REVEALER(window->ItemsRevealer), FALSE);
|
||||||
|
gtk_revealer_set_reveal_child(GTK_REVEALER(window->ChildrenRevealer), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
yon_menu_window *yon_menu_window_open(GtkWidget *, main_window *widgets){
|
yon_menu_window *yon_menu_window_open(GtkWidget *widget, main_window *widgets) {
|
||||||
yon_menu_window *window = yon_menu_window_new();
|
yon_menu_window *window = yon_menu_window_new();
|
||||||
int size;
|
int size;
|
||||||
config_str parsed = yon_config_load(get_menus_entry_command,&size);
|
config_str parsed = yon_config_load(get_menus_entry_command, &size);
|
||||||
for (int i=0;i<size;i++){
|
|
||||||
yon_char_remove_last_symbol(parsed[i],'\n');
|
for (int i = 0; i < size; i++) {
|
||||||
|
yon_char_remove_last_symbol(parsed[i], '\n');
|
||||||
int param_size;
|
int param_size;
|
||||||
config_str parameter = yon_char_parse(parsed[i],¶m_size,">");
|
config_str parameter = yon_char_parse(parsed[i], ¶m_size, ">");
|
||||||
if (yon_dictionary_get(&window->menu_items,parameter[0])){
|
|
||||||
|
|
||||||
} else {
|
yon_menu_item *item = yon_dictionary_get(window->menu_items, parameter[0]);
|
||||||
yon_menu_item *item = yon_menu_item_new();
|
if (!item) {
|
||||||
|
item = yon_menu_item_new();
|
||||||
gtk_widget_hide(item->NextIconButton);
|
gtk_widget_hide(item->NextIconButton);
|
||||||
gtk_label_set_text(GTK_LABEL(item->MenuTextLabel),parameter[0]);
|
gtk_label_set_text(GTK_LABEL(item->MenuTextLabel), parameter[0]);
|
||||||
item->target=yon_char_new(parameter[0]);
|
item->target = yon_char_new(parameter[0]);
|
||||||
gtk_list_box_insert(GTK_LIST_BOX(window->ItemsListBox),item->MenuItemBox,-1);
|
gtk_list_box_insert(GTK_LIST_BOX(window->ItemsListBox), item->MenuItemBox, -1);
|
||||||
yon_dictionary_add_or_create_if_exists_with_data(window->menu_items,parameter[0],item);
|
yon_dictionary_add_or_create_if_exists_with_data(window->menu_items, parameter[0], item);
|
||||||
gtk_widget_show(item->MenuItemBox);
|
gtk_widget_show(item->MenuItemBox);
|
||||||
if (size==2){
|
|
||||||
yon_menu_item *item_child = yon_menu_item_new();
|
|
||||||
g_signal_connect(G_OBJECT(item->MenuButton),"clicked",G_CALLBACK(on_submenu_open),item);
|
|
||||||
yon_dictionary_add_or_create_if_exists_with_data(item->children,parameter[1],item_child);
|
|
||||||
} else {
|
|
||||||
g_signal_connect(G_OBJECT(item->MenuButton),"clicked",G_CALLBACK(on_menu_chosen),item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (param_size == 2) {
|
||||||
|
if (!item->children) item->children = NULL;
|
||||||
|
yon_menu_item *item_child = yon_menu_item_new();
|
||||||
|
gtk_widget_hide(item_child->NextIconButton);
|
||||||
|
gtk_label_set_text(GTK_LABEL(item_child->MenuTextLabel), parameter[1]);
|
||||||
|
item_child->target = yon_char_new(parameter[1]);
|
||||||
|
yon_dictionary_add_or_create_if_exists_with_data(item->children, parameter[1], item_child);
|
||||||
|
|
||||||
|
dictionary *sub_dict = NULL;
|
||||||
|
yon_dictionary_add_or_create_if_exists_with_data(sub_dict, "window", window);
|
||||||
|
yon_dictionary_add_or_create_if_exists_with_data(sub_dict, "item", item);
|
||||||
|
yon_dictionary_add_or_create_if_exists_with_data(sub_dict, "widgets", widgets);
|
||||||
|
g_signal_connect(G_OBJECT(item->MenuButton), "clicked", G_CALLBACK(on_submenu_open), sub_dict);
|
||||||
|
} else {
|
||||||
|
dictionary *item_dict = NULL;
|
||||||
|
yon_dictionary_add_or_create_if_exists_with_data(item_dict, "item", item);
|
||||||
|
yon_dictionary_add_or_create_if_exists_with_data(item_dict, "widgets", widgets);
|
||||||
|
yon_dictionary_add_or_create_if_exists_with_data(item_dict, "window", window);
|
||||||
|
g_signal_connect(G_OBJECT(item->MenuButton), "clicked", G_CALLBACK(on_menu_chosen), item_dict);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int x,y,x2,y2,width;
|
|
||||||
gdk_window_get_position(gtk_widget_get_window(widgets->MenuButton),&x,&y);
|
int x, y, x2, y2, width;
|
||||||
gtk_widget_translate_coordinates(widgets->MenuButton,widgets->Window,x,y,&x2,&y2);
|
gdk_window_get_position(gtk_widget_get_window(widgets->MenuButton), &x, &y);
|
||||||
gtk_window_get_size(GTK_WINDOW(window->MenuWindow),&width,NULL);
|
gtk_widget_translate_coordinates(widgets->MenuButton, widgets->Window, x, y, &x2, &y2);
|
||||||
gtk_window_get_position(GTK_WINDOW(widgets->Window),&x,&y);
|
gtk_window_get_size(GTK_WINDOW(window->MenuWindow), &width, NULL);
|
||||||
gtk_window_move(GTK_WINDOW(window->MenuWindow),x+x2-width,y+y2);
|
gtk_window_get_position(GTK_WINDOW(widgets->Window), &x, &y);
|
||||||
|
gtk_window_move(GTK_WINDOW(window->MenuWindow), x + x2 - width, y + y2);
|
||||||
gtk_widget_realize(window->MenuWindow);
|
gtk_widget_realize(window->MenuWindow);
|
||||||
gtk_widget_show(window->MenuWindow);
|
gtk_widget_show(window->MenuWindow);
|
||||||
gdk_seat_grab(gdk_display_get_default_seat(gdk_display_get_default()),gtk_widget_get_window(window->MenuWindow),GDK_SEAT_CAPABILITY_POINTER,TRUE,NULL,NULL,NULL,NULL);
|
gdk_seat_grab(gdk_display_get_default_seat(gdk_display_get_default()), gtk_widget_get_window(window->MenuWindow), GDK_SEAT_CAPABILITY_POINTER, TRUE, NULL, NULL, NULL, NULL);
|
||||||
return window;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean on_menu_clicked(GtkWidget *, GdkEventButton *event, yon_menu_window *window){
|
|
||||||
int x,y,width,height;
|
|
||||||
gtk_window_get_size(GTK_WINDOW(window->MenuWindow),&width,&height);
|
|
||||||
gtk_window_get_position(GTK_WINDOW(window->MenuWindow),&x,&y);
|
|
||||||
if (event->x_root<x||event->y_root<y||event->x_root>x+width||event->y_root>y+height){
|
|
||||||
|
|
||||||
GdkDisplay *display = gdk_display_get_default();
|
|
||||||
GdkSeat *seat = gdk_display_get_default_seat(display);
|
|
||||||
gdk_seat_ungrab(seat);
|
|
||||||
// gtk_grab_remove(widget);
|
|
||||||
gtk_widget_destroy(window->MenuWindow);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_children_clean(GtkWidget*, yon_menu_window *window){
|
|
||||||
GList *list = gtk_container_get_children(GTK_CONTAINER(window->ChildrenListBox));
|
|
||||||
for (guint i=0;i<g_list_length(list);i++){
|
|
||||||
GList *item = gtk_container_get_children(GTK_CONTAINER(list->data));
|
|
||||||
g_object_ref(G_OBJECT(item->data));
|
|
||||||
gtk_container_remove(GTK_CONTAINER(list->data),GTK_WIDGET(item->data));
|
|
||||||
gtk_widget_destroy(GTK_WIDGET(list->data));
|
|
||||||
g_list_free(item);
|
|
||||||
list=list->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
yon_menu_window *yon_menu_window_new(){
|
|
||||||
yon_menu_window *window = new(yon_menu_window);
|
|
||||||
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_menu_window);
|
|
||||||
window->MenuWindow = yon_gtk_builder_get_widget(builder,"MainWindow");
|
|
||||||
window->ItemsRevealer = yon_gtk_builder_get_widget(builder,"ItemsRevealer");
|
|
||||||
window->BackButton = yon_gtk_builder_get_widget(builder,"BackButton");
|
|
||||||
window->ItemsListBox = yon_gtk_builder_get_widget(builder,"ItemsListBox");
|
|
||||||
window->ChildrenRevealer = yon_gtk_builder_get_widget(builder,"ChildrenRevealer");
|
|
||||||
window->ChildrenListBox = yon_gtk_builder_get_widget(builder,"ChildrenListBox");
|
|
||||||
|
|
||||||
window->menu_items=NULL;
|
|
||||||
|
|
||||||
g_signal_connect(G_OBJECT(window->BackButton),"clicked",G_CALLBACK(on_children_clean),window);
|
|
||||||
g_signal_connect(G_OBJECT(window->MenuWindow),"button-press-event",G_CALLBACK(on_menu_clicked),window);
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
yon_menu_item *yon_menu_item_new(){
|
|
||||||
yon_menu_item *item = new(yon_menu_item);
|
|
||||||
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_menu_item);
|
|
||||||
item->MenuItemBox = yon_gtk_builder_get_widget(builder,"MenuItemBox");
|
|
||||||
item->MenuButton = yon_gtk_builder_get_widget(builder,"MenuButton");
|
|
||||||
item->MenuTextLabel = yon_gtk_builder_get_widget(builder,"MenuTextLabel");
|
|
||||||
item->NextIconButton = yon_gtk_builder_get_widget(builder,"NextIconButton");
|
|
||||||
item->children=NULL;
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
Loading…
Reference in new issue