From b99f674d78f50e6f1bc37f96a615fe0035e9af35 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Fri, 27 Jun 2025 10:37:15 +0000 Subject: [PATCH] Filechooser update --- source/libublsettingsui-gtk3-filechooser.c | 19 +++++++++++++++++++ source/libublsettingsui-gtk3.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/source/libublsettingsui-gtk3-filechooser.c b/source/libublsettingsui-gtk3-filechooser.c index 4930a8c..869c2c8 100644 --- a/source/libublsettingsui-gtk3-filechooser.c +++ b/source/libublsettingsui-gtk3-filechooser.c @@ -70,6 +70,23 @@ void on_file_chooser_exit(GtkWidget *, filechooser_window *){ __yon_filechooser_window = NULL; } +void on_file_chooser_check_root(GtkWidget *, filechooser_window *window){ + char *cur_path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(window->MainFileChooser)); + if (!yon_char_is_empty(window->root)&&!strstr(cur_path,window->root)) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(window->MainFileChooser),window->root); +} + +void yon_file_chooser_set_root(filechooser_window *window, char *root_path){ + window->root = yon_char_new(root_path); + g_signal_connect(G_OBJECT(window->MainFileChooser),"current-folder-changed",G_CALLBACK(on_file_chooser_check_root),window); +} + +void yon_file_chooser_remove_root(filechooser_window *window, char *root_path){ + if (!yon_char_is_empty(window->root)) free(window->root); + window->root=NULL; + g_signal_handlers_disconnect_by_func(G_OBJECT(window->MainFileChooser),G_CALLBACK(on_file_chooser_check_root),window); + +} + filechooser_window *yon_file_chooser_window_new(GtkFileChooserAction action){ if (!__yon_filechooser_window){ filechooser_window *window = malloc(sizeof(filechooser_window)); @@ -84,6 +101,8 @@ filechooser_window *yon_file_chooser_window_new(GtkFileChooserAction action){ window->ChooseFolderCheck = yon_gtk_builder_get_widget(builder,"ChooseFolderCheck"); window->last_any_selection=NULL; window->last_success_selection=NULL; + window->root=NULL; + g_signal_connect(G_OBJECT(window->ChooseFolderCheck),"toggled",G_CALLBACK(on_file_chooser_selected),window); 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); diff --git a/source/libublsettingsui-gtk3.h b/source/libublsettingsui-gtk3.h index 98c9faa..f422d7b 100644 --- a/source/libublsettingsui-gtk3.h +++ b/source/libublsettingsui-gtk3.h @@ -173,11 +173,14 @@ typedef struct { char *last_success_selection; char *last_any_selection; GtkResponseType responce; + char *root; } filechooser_window; filechooser_window *yon_file_chooser_window_new(GtkFileChooserAction action); GtkResponseType yon_file_chooser_start(filechooser_window *window); void yon_file_chooser_set_button_label(char *label); +void yon_file_chooser_set_root(filechooser_window *window, char *root_path); +void yon_file_chooser_remove_root(filechooser_window *window, char *root_path); dialog_confirmation_data *yon_confirmation_dialog_data_new();