diff --git a/source/libublsettingsui-gtk3-filechooser.c b/source/libublsettingsui-gtk3-filechooser.c index 2e19d7b..7e41b5f 100644 --- a/source/libublsettingsui-gtk3-filechooser.c +++ b/source/libublsettingsui-gtk3-filechooser.c @@ -64,41 +64,52 @@ void on_file_chooser_selected(GtkWidget *self, filechooser_window *window){ if (success_size) yon_char_parsed_free(paths_success,success_size); } +filechooser_window *__yon_filechooser_window = NULL; + +void yon_file_chooser_set_button_label(char *label){ + +} + filechooser_window *yon_file_chooser_window_new(GtkFileChooserAction action){ - filechooser_window *window = malloc(sizeof(filechooser_window)); - GtkBuilder *builder = gtk_builder_new_from_resource(ui_glade_path_filechooser); - window->Window = yon_gtk_builder_get_widget(builder,"Window"); - window->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox"); - window->HeaderTopic = yon_gtk_builder_get_widget(builder,"HeaderTopic"); - window->MainFileChooser = yon_gtk_builder_get_widget(builder,"MainFileChooser"); - window->SaveButton = yon_gtk_builder_get_widget(builder,"SaveButton"); - window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton"); - window->ChooseFolderCheck = yon_gtk_builder_get_widget(builder,"ChooseFolderCheck"); - window->last_any_selection=NULL; - window->last_success_selection=NULL; - g_signal_connect(G_OBJECT(window->MainFileChooser),"selection-changed",G_CALLBACK(on_file_chooser_selected),window); - g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_file_chooser_cancel),window); - g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_file_chooser_accept),window); - - gtk_file_chooser_set_action(GTK_FILE_CHOOSER(window->MainFileChooser),action); - switch(action){ - case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: - gtk_widget_hide(window->ChooseFolderCheck); - break; - case GTK_FILE_CHOOSER_ACTION_OPEN: + if (!__yon_filechooser_window){ + filechooser_window *window = malloc(sizeof(filechooser_window)); + __yon_filechooser_window = window; + GtkBuilder *builder = gtk_builder_new_from_resource(ui_glade_path_filechooser); + window->Window = yon_gtk_builder_get_widget(builder,"Window"); + window->StatusBox = yon_gtk_builder_get_widget(builder,"StatusBox"); + window->HeaderTopic = yon_gtk_builder_get_widget(builder,"HeaderTopic"); + window->MainFileChooser = yon_gtk_builder_get_widget(builder,"MainFileChooser"); + window->SaveButton = yon_gtk_builder_get_widget(builder,"SaveButton"); + window->CancelButton = yon_gtk_builder_get_widget(builder,"CancelButton"); + window->ChooseFolderCheck = yon_gtk_builder_get_widget(builder,"ChooseFolderCheck"); + window->last_any_selection=NULL; + window->last_success_selection=NULL; + g_signal_connect(G_OBJECT(window->MainFileChooser),"selection-changed",G_CALLBACK(on_file_chooser_selected),window); + g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_file_chooser_cancel),window); + g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_file_chooser_accept),window); + + gtk_file_chooser_set_action(GTK_FILE_CHOOSER(window->MainFileChooser),action); + switch(action){ + case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: + gtk_widget_hide(window->ChooseFolderCheck); + break; + case GTK_FILE_CHOOSER_ACTION_OPEN: - break; - case GTK_FILE_CHOOSER_ACTION_SAVE: - gtk_widget_hide(window->ChooseFolderCheck); - break; - case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->ChooseFolderCheck),1); - gtk_widget_hide(window->ChooseFolderCheck); - break; - } + break; + case GTK_FILE_CHOOSER_ACTION_SAVE: + gtk_widget_hide(window->ChooseFolderCheck); + break; + case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->ChooseFolderCheck),1); + gtk_widget_hide(window->ChooseFolderCheck); + break; + } - g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL); - return window; + g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL); + return window; + } else { + return __yon_filechooser_window; + } } GtkResponseType yon_file_chooser_start(filechooser_window *window){ diff --git a/source/libublsettingsui-gtk3-save.c b/source/libublsettingsui-gtk3-save.c index 90beb0a..0ea0e47 100644 --- a/source/libublsettingsui-gtk3-save.c +++ b/source/libublsettingsui-gtk3-save.c @@ -454,8 +454,8 @@ struct loaded_config *yon_config_get_compared(char *command){ } -char *yon_custom_config_init(){ - filechooser_window *dialog = yon_file_chooser_window_new(GTK_FILE_CHOOSER_ACTION_OPEN); +char *yon_custom_config_init(GtkFileChooserAction type){ + filechooser_window *dialog = yon_file_chooser_window_new(type); gtk_widget_hide(dialog->ChooseFolderCheck); yon_gtk_window_setup(GTK_WINDOW(dialog->Window),NULL,template_app_information.app_title,yon_char_unite("com.ublinux.",template_app_information.app_tech_name,NULL),"ConfigFilechooserWindow"); @@ -537,7 +537,7 @@ template_saving_window *yon_save_proceed(char *path,YON_CONFIG_TYPE type, ...){ config_to_save = yon_config_get_type_path(type); if (!path&&type == YON_CONFIG_CUSTOM){ - path = yon_custom_config_init(); + path = yon_custom_config_init(GTK_FILE_CHOOSER_ACTION_SAVE); if (!path) return NULL; } diff --git a/source/libublsettingsui-gtk3.h b/source/libublsettingsui-gtk3.h index 281206f..b4d59a5 100644 --- a/source/libublsettingsui-gtk3.h +++ b/source/libublsettingsui-gtk3.h @@ -325,6 +325,8 @@ char *yon_custom_config_init(); #define CANCEL_LABEL _("Cancel") #define ACCEPT_LABEL _("Accept") #define OPEN_LABEL _("Open") + #define CREATE_FOLDER_LABEL _("Create directory") + #define SELECT_FOLDER_LABEL _("Select directory") #define HELP_TITLE_LABEL _("Would you like to read documentation in the Web?") #define HELP_INFO_LABEL _("You will be redirected to documentation website where documentation is\ntranslated and supported by community.") @@ -374,6 +376,7 @@ char *yon_custom_config_init(); #define PATH_INVALID_LABEL _("Invalid path") #define CHOOSE_FILE_LABEL _("Choose path") + #define FILE_CHOOSER_CHOOSE_FILDER_LABEL _("Choose directory instead of file")