You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
4.7 KiB
95 lines
4.7 KiB
#include "ubl-settings-manager.h"
|
|
|
|
struct config_chooser {
|
|
GtkWidget *RootBox;
|
|
GtkWidget *PathEntry;
|
|
GtkWidget *PathButton;
|
|
GtkWidget *ClearButton;
|
|
};
|
|
|
|
void on_config_destroy(GtkWidget *, struct config_chooser *parameter);
|
|
void on_config_destroy(GtkWidget *, struct config_chooser *parameter){
|
|
free(parameter);
|
|
}
|
|
|
|
void on_config_chooser_opened(GtkWidget *, struct config_chooser *parameter);
|
|
void on_config_chooser_opened(GtkWidget *, struct config_chooser *parameter){
|
|
filechooser_window *window = yon_file_chooser_window_new(GTK_FILE_CHOOSER_ACTION_SAVE);
|
|
yon_gtk_window_setup(GTK_WINDOW(window->Window),NULL,CHOOSE_FILE_LABEL,icon_path,"file_chooser");
|
|
GtkFileFilter *ini_filter = gtk_file_filter_new();
|
|
GtkFileFilter *yaml_filter = gtk_file_filter_new();
|
|
GtkFileFilter *json_filter = gtk_file_filter_new();
|
|
gtk_file_filter_add_pattern(ini_filter,"*.ini");
|
|
gtk_file_filter_set_name(ini_filter,"*.ini");
|
|
gtk_file_filter_add_pattern(yaml_filter,"*.yaml");
|
|
gtk_file_filter_set_name(yaml_filter,"*.yaml");
|
|
gtk_file_filter_add_pattern(json_filter,"*.json");
|
|
gtk_file_filter_set_name(json_filter,"*.json");
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(window->MainFileChooser),ini_filter);
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(window->MainFileChooser),yaml_filter);
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(window->MainFileChooser),json_filter);
|
|
if (yon_file_chooser_start(window) != GTK_RESPONSE_CANCEL){
|
|
char *full_name = NULL;
|
|
gtk_entry_set_text(GTK_ENTRY(parameter->PathEntry),window->last_success_selection);
|
|
GtkFileFilter *cur_filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(window->MainFileChooser));
|
|
|
|
if ((cur_filter == ini_filter&&!strstr(window->last_success_selection,".ini"))){
|
|
full_name = yon_char_append(window->last_success_selection,".ini");
|
|
} else if ((cur_filter == yaml_filter&&!strstr(window->last_success_selection,".yaml"))){
|
|
full_name = yon_char_append(window->last_success_selection,".yaml");
|
|
} else if ((cur_filter == json_filter&&!strstr(window->last_success_selection,".json"))){
|
|
full_name = yon_char_append(window->last_success_selection,".json");
|
|
} else {
|
|
full_name = yon_char_new(window->last_success_selection);
|
|
}
|
|
if (access(full_name,F_OK)){
|
|
yon_launch(ubconfig_file_create(full_name));
|
|
}
|
|
}
|
|
}
|
|
|
|
void on_config_chooser_clear(GtkWidget *,struct config_chooser *parameter);
|
|
void on_config_chooser_clear(GtkWidget *,struct config_chooser *parameter){
|
|
yon_window_config_erase_instant_parameter("file",yon_configuration_window_section);
|
|
gtk_entry_set_text(GTK_ENTRY(parameter->PathEntry),"");
|
|
}
|
|
|
|
GtkWidget *yon_config_chooser_new( char *){
|
|
struct config_chooser *parameter = malloc(sizeof(struct config_chooser));
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_config);
|
|
|
|
parameter->RootBox = yon_gtk_builder_get_widget(builder,"RootBox");
|
|
parameter->PathEntry = yon_gtk_builder_get_widget(builder,"PathEntry");
|
|
parameter->PathButton = yon_gtk_builder_get_widget(builder,"PathButton");
|
|
parameter->ClearButton = yon_gtk_builder_get_widget(builder,"ClearButton");
|
|
|
|
g_object_set_data(G_OBJECT(parameter->RootBox),"data_struct",parameter);
|
|
g_signal_connect(G_OBJECT(parameter->PathButton),"clicked",G_CALLBACK(on_config_chooser_opened),parameter);
|
|
g_signal_connect(G_OBJECT(parameter->ClearButton),"clicked",G_CALLBACK(on_config_chooser_clear),parameter);
|
|
g_signal_connect(G_OBJECT(parameter->RootBox),"destroy",G_CALLBACK(on_config_destroy),parameter);
|
|
return parameter->RootBox;
|
|
}
|
|
|
|
void yon_config_chooser_update(GtkWidget *root){
|
|
struct config_chooser *parameter = g_object_get_data(G_OBJECT(root),"data_struct");
|
|
char *target;
|
|
if (!yon_window_config_get_parameter(yon_configuration_window_section,"file",&target,YON_TYPE_STRING)){
|
|
target = NULL;
|
|
}
|
|
if (target){
|
|
gtk_entry_set_text(GTK_ENTRY(parameter->PathEntry),target);
|
|
}
|
|
|
|
}
|
|
|
|
void yon_config_chooser_save(GtkWidget *root){
|
|
struct config_chooser *parameter = g_object_get_data(G_OBJECT(root),"data_struct");
|
|
char *path = (char*)gtk_entry_get_text(GTK_ENTRY(parameter->PathEntry));
|
|
if (!yon_char_is_empty(path)){
|
|
yon_window_config_add_instant_parameter("file",yon_configuration_window_section,path,YON_TYPE_STRING);
|
|
yon_ubl_status_box_spawn_infinite(GTK_CONTAINER(main_config.widgets->StatusBox),"config_mode",CONFIG_MODE_LABEL(path),BACKGROUND_IMAGE_INFO_TYPE);
|
|
} else {
|
|
yon_window_config_erase_instant_parameter("file",yon_configuration_window_section);
|
|
yon_ubl_status_box_despawn_infinite(GTK_CONTAINER(main_config.widgets->StatusBox));
|
|
}
|
|
} |