[niepce] ui: move the import file command to the workspace



commit fb6f04da4e5db79a9d159f83b92b62037f7b89be
Author: Hubert Figuière <hub figuiere net>
Date:   Fri Nov 17 00:17:08 2017 -0500

    ui: move the import file command to the workspace

 src/niepce/ui/niepcewindow.cpp        |   55 +----------------------------
 src/niepce/ui/niepcewindow.hpp        |    2 -
 src/niepce/ui/workspacecontroller.cpp |   62 +++++++++++++++++++++++++++++++-
 src/niepce/ui/workspacecontroller.hpp |    2 +
 4 files changed, 63 insertions(+), 58 deletions(-)
---
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index f508f7b..d6848e5 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -38,12 +38,11 @@
 #include "fwk/toolkit/notificationcenter.hpp"
 #include "fwk/toolkit/configdatabinder.hpp"
 #include "fwk/toolkit/undo.hpp"
-#include "engine/importer/iimporter.hpp"
+#include "fwk/toolkit/gtkutils.hpp"
 #include "libraryclient/uidataprovider.hpp"
 
 #include "thumbstripview.hpp"
 #include "niepcewindow.hpp"
-#include "dialogs/importdialog.hpp"
 #include "dialogs/editlabels.hpp"
 #include "selectioncontroller.hpp"
 
@@ -54,8 +53,6 @@ using libraryclient::LibraryClientPtr;
 using fwk::Application;
 using fwk::Configuration;
 using fwk::UndoHistory;
-using eng::Managed;
-using eng::IImporter;
 
 namespace ui {
 
@@ -195,10 +192,6 @@ void NiepceWindow::init_actions()
     section = Gio::Menu::create();
     submenu->append_section(section);
     section->append(_("New Project..."), "action");
-    fwk::add_action(m_action_group, "Import",
-                    sigc::mem_fun(*this,
-                                  &NiepceWindow::on_action_file_import),
-                    section, _("_Import..."), "win");
 
     section = Gio::Menu::create();
     submenu->append_section(section);
@@ -250,52 +243,6 @@ void NiepceWindow::init_actions()
                           nullptr);
 }
 
-
-void NiepceWindow::on_action_file_import()
-{
-    int result;
-    Configuration & cfg = Application::app()->config();
-
-    ImportDialog::Ptr import_dialog(new ImportDialog());
-
-    result = import_dialog->run_modal(shared_frame_ptr());
-    switch(result) {
-    case 0:
-    {
-        // import
-        // XXX change the API to provide more details.
-        std::string source = import_dialog->get_source();
-        if(source.empty()) {
-            return;
-        }
-        // XXX this should be a different config key
-        // specific to the importer.
-        cfg.setValue("last_import_location", source);
-
-        auto importer = import_dialog->get_importer();
-        DBG_ASSERT(!!importer, "Import can't be null if we clicked import");
-        if (importer) {
-            auto dest_dir = import_dialog->get_dest_dir();
-            importer->do_import(
-                source, dest_dir,
-                [this] (const std::string & path, IImporter::Import type, Managed manage) {
-                    if (type == IImporter::Import::SINGLE) {
-                        ffi::libraryclient_import_file(m_libClient->client(), path.c_str(), manage);
-                    } else {
-                        m_libClient->importFromDirectory(path, manage);
-                    }
-                });
-        }
-        break;
-    }
-    case 1:
-        // cancel
-        break;
-    default:
-        break;
-    }
-}
-
 void NiepceWindow::on_open_library()
 {
     Configuration & cfg = Application::app()->config();
diff --git a/src/niepce/ui/niepcewindow.hpp b/src/niepce/ui/niepcewindow.hpp
index fdd40df..21b0907 100644
--- a/src/niepce/ui/niepcewindow.hpp
+++ b/src/niepce/ui/niepcewindow.hpp
@@ -59,8 +59,6 @@ public:
 protected:
     virtual Gtk::Widget * buildWidget() override;
 private:
-    void on_action_file_import();
-
     void on_open_library();
     void on_action_edit_labels();
     void on_action_edit_delete();
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index c010704..b26009f 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -23,19 +23,26 @@
 
 #include <gtkmm/icontheme.h>
 #include <gtkmm/box.h>
+#include <gtkmm/iconview.h>
 
 #include "fwk/base/debug.hpp"
 #include "fwk/toolkit/application.hpp"
+#include "fwk/toolkit/configuration.hpp"
 #include "fwk/toolkit/gtkutils.hpp"
 #include "niepce/notifications.hpp"
+#include "engine/importer/iimporter.hpp"
 #include "engine/library/notification.hpp"
 #include "libraryclient/libraryclient.hpp"
+#include "dialogs/importdialog.hpp"
 #include "niepcewindow.hpp"
 #include "workspacecontroller.hpp"
 
 #include "rust_bindings.hpp"
 
 using fwk::Application;
+using fwk::Configuration;
+using eng::Managed;
+using eng::IImporter;
 
 namespace ui {
 
@@ -87,10 +94,56 @@ void WorkspaceController::action_new_folder()
 {
     auto& window = std::dynamic_pointer_cast<NiepceWindow>(m_parent.lock())->gtkWindow();
     ui::dialog_request_new_folder(getLibraryClient()->client(), window.gobj());
-    // XXX get a unique name
-    // select folder in tree
 }
 
+void WorkspaceController::action_file_import()
+{
+    int result;
+    auto& cfg = Application::app()->config(); // XXX change to getLibraryConfig()
+    // as the last import should be part of the library not the application.
+
+    ImportDialog::Ptr import_dialog(new ImportDialog());
+
+    result = import_dialog->run_modal(std::dynamic_pointer_cast<NiepceWindow>(m_parent.lock()));
+    switch(result) {
+    case 0:
+    {
+        // import
+        // XXX change the API to provide more details.
+        std::string source = import_dialog->get_source();
+        if(source.empty()) {
+            return;
+        }
+        // XXX this should be a different config key
+        // specific to the importer.
+        cfg.setValue("last_import_location", source);
+
+        auto importer = import_dialog->get_importer();
+        DBG_ASSERT(!!importer, "Import can't be null if we clicked import");
+        if (importer) {
+            auto dest_dir = import_dialog->get_dest_dir();
+            importer->do_import(
+                source, dest_dir,
+                [this] (const std::string & path, IImporter::Import type, Managed manage) {
+                    if (type == IImporter::Import::SINGLE) {
+                        ffi::libraryclient_import_file(getLibraryClient()->client(),
+                                                       path.c_str(), manage);
+                    } else {
+                        getLibraryClient()->importFromDirectory(path, manage);
+                    }
+                });
+        }
+        break;
+    }
+    case 1:
+        // cancel
+        break;
+    default:
+        break;
+    }
+}
+
+
 void WorkspaceController::on_lib_notification(const eng::LibNotification &ln)
 {
     DBG_OUT("notification for workspace");
@@ -315,6 +368,11 @@ Gtk::Widget * WorkspaceController::buildWidget()
                     sigc::mem_fun(*this,
                                   &WorkspaceController::action_new_folder),
                     section, _("New Folder..."), "workspace");
+    fwk::add_action(m_action_group, "Import",
+                    sigc::mem_fun(*this,
+                                  &WorkspaceController::action_file_import),
+                    section, _("_Import..."), "workspace");
+
     add_btn->set_menu_model(menu);
 
     header->pack_end(*add_btn, Gtk::PACK_SHRINK);
diff --git a/src/niepce/ui/workspacecontroller.hpp b/src/niepce/ui/workspacecontroller.hpp
index 04ee01e..aad58f4 100644
--- a/src/niepce/ui/workspacecontroller.hpp
+++ b/src/niepce/ui/workspacecontroller.hpp
@@ -87,6 +87,8 @@ private:
 
     /** action to create a new folder */
     void action_new_folder();
+    /** action to import images */
+    void action_file_import();
 
     void on_row_expanded_collapsed(const Gtk::TreeIter& iter,
                                    const Gtk::TreePath& path, bool expanded);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]