From 8fb33900ecd068fff96ec0f424e0360e87cdb9a0 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sat, 28 Sep 2019 00:15:37 +0200 Subject: [PATCH] [GTK3] Implement boot ROM search path preference --- gtk3/main.c | 15 ++++++++++++--- gtk3/settings.c | 4 +++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/gtk3/main.c b/gtk3/main.c index da6e110..61d597d 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -30,6 +30,7 @@ static GtkBuilder *builder; static GtkGLArea *gl_area; static GtkApplicationWindow *main_window; +static GtkWindow *preferences; static GtkWindow *vram_viewer; static GtkWindow *memory_viewer; static GtkWindow *console; @@ -406,10 +407,18 @@ G_MODULE_EXPORT void on_rewind_duration_changed(GtkWidget *w, gpointer user_data G_MODULE_EXPORT void on_boot_rom_location_changed(GtkWidget *w, gpointer user_data_gptr) { GtkComboBox *box = GTK_COMBO_BOX(w); const gchar *id = gtk_combo_box_get_active_id(box); + if (id == NULL) return; if (g_strcmp0(id, "other") == 0) { - g_print("TODO: Open path picker\n"); - update_boot_rom_selector(builder); + GtkFileChooserNative *native = gtk_file_chooser_native_new("Select Folder", preferences, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "_Select", "_Cancel"); + gint res = gtk_native_dialog_run(GTK_NATIVE_DIALOG(native)); + + if (res == GTK_RESPONSE_ACCEPT) { + config.boot_rom_path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(native)); + update_boot_rom_selector(builder); + } + + g_object_unref(native); } else { config.boot_rom_path = (gchar *)id; @@ -439,7 +448,7 @@ static void startup(GApplication *app, gpointer user_data_gptr) { gtk_widget_destroy(gtkget(GTK_WIDGET, "menubar_override_selector")); #endif - GtkWindow *preferences = GTK_WINDOW(get_object("preferences")); + preferences = GTK_WINDOW(get_object("preferences")); g_signal_connect(preferences, "realize", G_CALLBACK(on_preferences_realize), (gpointer) builder); init_settings(user_data->config_path, preferences); diff --git a/gtk3/settings.c b/gtk3/settings.c index e5e9ac0..1fda9c5 100644 --- a/gtk3/settings.c +++ b/gtk3/settings.c @@ -182,11 +182,13 @@ void update_boot_rom_selector(GtkBuilder *builder) { GtkComboBoxText *combo_box = gtkget(GTK_COMBO_BOX_TEXT, "boot_rom_selector"); gtk_combo_box_text_remove_all(combo_box); gtk_combo_box_text_append(combo_box, "auto", "Use Built-in Boot ROMs"); - gtk_combo_box_set_active_id(GTK_COMBO_BOX(combo_box), "auto"); if (config.boot_rom_path != NULL && !g_str_equal(config.boot_rom_path, "auto") && !g_str_equal(config.boot_rom_path, "other")) { gtk_combo_box_text_append(combo_box, config.boot_rom_path, config.boot_rom_path); gtk_combo_box_set_active_id(GTK_COMBO_BOX(combo_box), config.boot_rom_path); } + else { + gtk_combo_box_set_active_id(GTK_COMBO_BOX(combo_box), "auto"); + } gtk_combo_box_text_append_text(combo_box, ""); gtk_combo_box_text_append(combo_box, "other", "Other"); }