Fix default selection of image

This commit is contained in:
daleclack 2024-02-06 10:46:21 +08:00
parent 74aa1188b2
commit 5fad44a721
3 changed files with 51 additions and 37 deletions

1
Gtk4_Reset/my_gtkui.json Normal file
View File

@ -0,0 +1 @@
{"background_folders":[],"folder_index":2,"height":576,"image_index":2,"panel_mode":1,"position":0,"width":1024}

View File

@ -133,6 +133,8 @@ static void btnset_clicked(GtkWidget *widget, MyDock *dock)
gtk_window_set_transient_for(GTK_WINDOW(dock->prefs_win), dock->parent_win);
gtk_window_present(GTK_WINDOW(dock->prefs_win));
}
my_prefs_first_load(dock->prefs_win);
my_prefs_start_scan(dock->prefs_win);
gtk_image_set_from_icon_name(GTK_IMAGE(dock->image_set), "my_prefs_running");
}
@ -315,9 +317,6 @@ static void my_dock_init(MyDock *self)
gtk_widget_set_valign(self->apps_grid, GTK_ALIGN_FILL);
gtk_grid_attach(GTK_GRID(child), self->apps_switcher, 1, 2, 1, 1);
my_prefs_first_load(self->prefs_win);
my_prefs_start_scan(self->prefs_win);
// Add Style to launchpad page
gtk_widget_add_css_class(self->launchpad_page, "dock_style");
gtk_style_context_add_provider_for_display(gtk_widget_get_display(self->launchpad_page),

View File

@ -626,45 +626,51 @@ void my_prefs_first_load(MyPrefs *self)
else
{
// Update image list by the folder selection
self->file = g_file_new_for_path(folder_name);
gtk_directory_list_set_file(self->file_list, self->file);
update_images_list(self);
g_object_unref(self->file);
do
{
g_print("%s", folder_name);
self->file = g_file_new_for_path(folder_name);
GtkDirectoryList *dir_list = gtk_directory_list_new("", self->file);
gtk_directory_list_set_file(self->file_list, self->file);
update_images_list(self);
g_object_unref(self->file);
}while (g_list_model_get_n_items(G_LIST_MODEL(self->images_list)) == 0);
}
// Get the selected image item
gtk_single_selection_set_selected(
self->image_select, self->current_image_index);
auto item = gtk_single_selection_get_selected_item(self->image_select);
// auto item = gtk_single_selection_get_selected_item(self->image_select);
// File name and properties
if (item != NULL)
{
const char *file_name = my_item_get_path(MY_ITEM(item));
is_internal = my_item_get_internal(MY_ITEM(item));
// Update image
if (is_internal)
{
// For image which is internal
switch (file_name[1])
{
case '1':
update_resource_image(self, "/org/gtk/daleclack/final_approach.png");
break;
case '2':
update_internal_image(self, img7);
break;
case '3':
update_internal_image(self, winpe);
break;
}
}
else
{
// For image which is outside
update_external_image(self, file_name);
}
}
// // File name and properties
// if (item != NULL)
// {
// const char *file_name = my_item_get_path(MY_ITEM(item));
// is_internal = my_item_get_internal(MY_ITEM(item));
// // Update image
// if (is_internal)
// {
// // For image which is internal
// switch (file_name[1])
// {
// case '1':
// update_resource_image(self, "/org/gtk/daleclack/final_approach.png");
// break;
// case '2':
// update_internal_image(self, img7);
// break;
// case '3':
// update_internal_image(self, winpe);
// break;
// }
// }
// else
// {
// // For image which is outside
// update_external_image(self, file_name);
// }
// }
}
// static void my_prefs_close_request(GtkWindow *self, gpointer user_data)
@ -749,8 +755,16 @@ static void my_prefs_init(MyPrefs *self)
gtk_box_append(GTK_BOX(self->btns_box), self->btn_remove);
gtk_box_append(GTK_BOX(self->back_page), self->btns_box);
// The model and item of folders view
gtk_single_selection_set_selected(
self->folders_select, self->current_folder_index);
auto folder_item = gtk_single_selection_get_selected_item(self->folders_select);
// File name and properties
const char *folder_name = my_item_get_path(MY_ITEM(folder_item));
// Create file list
self->file = g_file_new_for_path(g_get_home_dir());
self->file = g_file_new_for_path(folder_name);
self->file_list = gtk_directory_list_new(
"standard::name,standard::display-name,standard::icon,standard::size,standard::content-type", self->file);
g_object_unref(self->file);