[niepce/gtk4] gtk4: Fix import directory
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce/gtk4] gtk4: Fix import directory
- Date: Sat, 14 May 2022 02:46:25 +0000 (UTC)
commit bb67c67a4cb5d7b6194b5833695e61af777926a1
Author: Hubert Figuière <hub figuiere net>
Date: Tue May 10 23:05:58 2022 -0400
gtk4: Fix import directory
- the file dialog will call the callback directly
.../ui/dialogs/importers/directoryimporterui.cpp | 49 +++++++++-------------
.../ui/dialogs/importers/directoryimporterui.hpp | 3 +-
2 files changed, 21 insertions(+), 31 deletions(-)
---
diff --git a/src/niepce/ui/dialogs/importers/directoryimporterui.cpp
b/src/niepce/ui/dialogs/importers/directoryimporterui.cpp
index e11e43c..58bb355 100644
--- a/src/niepce/ui/dialogs/importers/directoryimporterui.cpp
+++ b/src/niepce/ui/dialogs/importers/directoryimporterui.cpp
@@ -50,46 +50,37 @@ Gtk::Widget* DirectoryImporterUI::setup_widget(const fwk::Frame::Ptr& frame)
}
void DirectoryImporterUI::do_select_directories()
-{
- auto source = select_source();
- if (!source.empty() && m_source_selected_cb) {
- m_source_selected_cb(source, fwk::path_basename(source));
- }
-}
-
-std::string DirectoryImporterUI::select_source()
{
fwk::Configuration & cfg = fwk::Application::app()->config();
- Glib::ustring filename;
- {
- auto frame = m_frame.lock();
- Gtk::FileChooserDialog dialog(frame->gtkWindow(), _("Import picture folder"),
- Gtk::FileChooser::Action::SELECT_FOLDER);
+ auto frame = m_frame.lock();
+ auto dialog = new Gtk::FileChooserDialog(frame->gtkWindow(), _("Import picture folder"),
+ Gtk::FileChooser::Action::SELECT_FOLDER);
- dialog.add_button(_("Cancel"), Gtk::ResponseType::CANCEL);
- dialog.add_button(_("Select"), Gtk::ResponseType::OK);
- dialog.set_select_multiple(false);
+ dialog->add_button(_("Cancel"), Gtk::ResponseType::CANCEL);
+ dialog->add_button(_("Select"), Gtk::ResponseType::OK);
+ dialog->set_select_multiple(false);
- std::string last_import_location = cfg.getValue("last_import_location", "");
- if (!last_import_location.empty()) {
- dialog.set_current_name(last_import_location);
- }
-
- dialog.show();
- // XXX fix this Gtk4
- int result = 0;
- switch(result)
+ std::string last_import_location = cfg.getValue("last_import_location", "");
+ if (!last_import_location.empty()) {
+ auto file = Gio::File::create_for_path(last_import_location);
+ dialog->set_current_folder(file);
+ }
+ dialog->signal_response().connect([this, dialog] (int result) {
+ std::string source;
+ switch (result)
{
case Gtk::ResponseType::OK:
- filename = dialog.get_current_name();
+ source = dialog->get_file()->get_path();
+ m_source_selected_cb(source, fwk::path_basename(source));
break;
default:
break;
}
- }
- m_directory_name->set_text(filename);
- return filename.raw();
+ m_directory_name->set_text(source);
+ delete dialog;
+ });
+ dialog->show();
}
}
diff --git a/src/niepce/ui/dialogs/importers/directoryimporterui.hpp
b/src/niepce/ui/dialogs/importers/directoryimporterui.hpp
index c4a8a75..1dff05b 100644
--- a/src/niepce/ui/dialogs/importers/directoryimporterui.hpp
+++ b/src/niepce/ui/dialogs/importers/directoryimporterui.hpp
@@ -2,7 +2,7 @@
/*
* niepce - ui/dialogs/importer/directoryimporterui.hpp
*
- * Copyright (C) 2017 Hubert Figuière
+ * Copyright (C) 2017-2022 Hubert Figuière
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -41,7 +41,6 @@ public:
Gtk::Widget* setup_widget(const fwk::Frame::Ptr&) override;
private:
- std::string select_source();
void do_select_directories();
Gtk::Label *m_directory_name;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]