[niepce] Implement move file to folder Implement move to Trash in the UI
- From: Hubert FiguiÃre <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] Implement move file to folder Implement move to Trash in the UI
- Date: Thu, 17 Nov 2011 02:23:34 +0000 (UTC)
commit 6f1fc7b5f70cfc3d6a65108395a3dc43a682093b
Author: Hub Figuiere <hub figuiere net>
Date: Tue Nov 15 08:21:37 2011 -0800
Implement move file to folder
Implement move to Trash in the UI
src/engine/db/library.hpp | 1 +
src/engine/library/commands.cpp | 9 ++++++---
src/engine/library/commands.hpp | 3 ++-
src/libraryclient/clientimpl.cpp | 5 +++--
src/libraryclient/clientimpl.hpp | 3 ++-
src/libraryclient/libraryclient.cpp | 8 +++++---
src/libraryclient/libraryclient.hpp | 3 ++-
src/niepce/ui/gridviewmodule.cpp | 16 +++++++++++++++-
src/niepce/ui/moduleshell.cpp | 5 +++++
src/niepce/ui/moduleshell.hpp | 2 ++
src/niepce/ui/niepcewindow.cpp | 9 ++++++++-
src/niepce/ui/niepcewindow.hpp | 1 +
src/niepce/ui/selectioncontroller.cpp | 21 +++++++++++++++++++++
src/niepce/ui/selectioncontroller.hpp | 2 ++
src/niepce/ui/workspacecontroller.cpp | 26 ++++++++++++++++++++++++++
src/niepce/ui/workspacecontroller.hpp | 2 ++
16 files changed, 103 insertions(+), 13 deletions(-)
---
diff --git a/src/engine/db/library.hpp b/src/engine/db/library.hpp
index eaad5bf..3d41b4e 100644
--- a/src/engine/db/library.hpp
+++ b/src/engine/db/library.hpp
@@ -69,6 +69,7 @@ public:
NOTIFY_LABEL_DELETED,
NOTIFY_XMP_NEEDS_UPDATE,
NOTIFY_FOLDER_COUNTED,
+ NOTIFY_FOLDER_COUNT_CHANGE,
NOTIFY_FILE_MOVED
} NotifyType;
diff --git a/src/engine/library/commands.cpp b/src/engine/library/commands.cpp
index 6034d60..82419ec 100644
--- a/src/engine/library/commands.cpp
+++ b/src/engine/library/commands.cpp
@@ -127,13 +127,16 @@ void Commands::cmdSetMetadata(const Library::Ptr & lib,
}
void Commands::cmdMoveFileToFolder(const Library::Ptr & lib,
- library_id_t file_id, library_id_t folder_id)
+ library_id_t file_id, library_id_t from_folder_id,
+ library_id_t to_folder_id)
{
- if(lib->moveFileToFolder(file_id, folder_id)) {
+ if(lib->moveFileToFolder(file_id, to_folder_id)) {
std::pair<library_id_t, library_id_t> move;
move.first = file_id;
- move.second = folder_id;
+ move.second = to_folder_id;
lib->notify(Library::NOTIFY_FILE_MOVED, boost::any(move));
+ lib->notify(Library::NOTIFY_FOLDER_COUNT_CHANGE, boost::any(std::make_pair(from_folder_id, -1)));
+ lib->notify(Library::NOTIFY_FOLDER_COUNT_CHANGE, boost::any(std::make_pair(to_folder_id, 1)));
}
}
diff --git a/src/engine/library/commands.hpp b/src/engine/library/commands.hpp
index fc676a6..527cf51 100644
--- a/src/engine/library/commands.hpp
+++ b/src/engine/library/commands.hpp
@@ -55,7 +55,8 @@ public:
library_id_t file_id, fwk::PropertyIndex meta,
const fwk::PropertyValue & value);
static void cmdMoveFileToFolder(const Library::Ptr & lib,
- library_id_t file_id, library_id_t folder_id);
+ library_id_t file_id, library_id_t from_folder_id,
+ library_id_t to_folder_id);
static void cmdListAllLabels(const Library::Ptr & lib);
static void cmdCreateLabel(const Library::Ptr & lib, const std::string & s,
const std::string & color);
diff --git a/src/libraryclient/clientimpl.cpp b/src/libraryclient/clientimpl.cpp
index cd0a9a9..ea4cfb4 100644
--- a/src/libraryclient/clientimpl.cpp
+++ b/src/libraryclient/clientimpl.cpp
@@ -120,11 +120,12 @@ tid_t ClientImpl::setMetadata(eng::library_id_t file_id, int meta, const fwk::Pr
return id;
}
-tid_t ClientImpl::moveFileToFolder(eng::library_id_t file_id, eng::library_id_t folder_id)
+tid_t ClientImpl::moveFileToFolder(eng::library_id_t file_id, eng::library_id_t from_folder_id,
+ eng::library_id_t to_folder_id)
{
tid_t id = LibraryClient::newTid();
Op::Ptr op(new Op(id, boost::bind(&Commands::cmdMoveFileToFolder, _1,
- file_id, folder_id)));
+ file_id, from_folder_id, to_folder_id)));
m_localLibrary->schedule(op);
return id;
}
diff --git a/src/libraryclient/clientimpl.hpp b/src/libraryclient/clientimpl.hpp
index 811a5bc..887878b 100644
--- a/src/libraryclient/clientimpl.hpp
+++ b/src/libraryclient/clientimpl.hpp
@@ -47,7 +47,8 @@ public:
eng::tid_t countFolder(eng::library_id_t id);
eng::tid_t requestMetadata(eng::library_id_t id);
eng::tid_t setMetadata(eng::library_id_t id, int meta, const fwk::PropertyValue & value);
- eng::tid_t moveFileToFolder(eng::library_id_t file_id, eng::library_id_t folder_id);
+ eng::tid_t moveFileToFolder(eng::library_id_t file_id, eng::library_id_t from_folder_id,
+ eng::library_id_t to_folder_id);
eng::tid_t getAllLabels();
eng::tid_t createLabel(const std::string & s, const std::string & color);
diff --git a/src/libraryclient/libraryclient.cpp b/src/libraryclient/libraryclient.cpp
index a3541fe..54f6a71 100644
--- a/src/libraryclient/libraryclient.cpp
+++ b/src/libraryclient/libraryclient.cpp
@@ -85,14 +85,16 @@ eng::tid_t LibraryClient::requestMetadata(eng::library_id_t id)
}
/** set the metadata */
-eng::tid_t LibraryClient::setMetadata(library_id_t id, fwk::PropertyIndex meta, const fwk::PropertyValue & value)
+eng::tid_t LibraryClient::setMetadata(library_id_t id, fwk::PropertyIndex meta,
+ const fwk::PropertyValue & value)
{
return m_pImpl->setMetadata(id, meta, value);
}
-eng::tid_t LibraryClient::moveFileToFolder(eng::library_id_t file_id, eng::library_id_t folder_id)
+eng::tid_t LibraryClient::moveFileToFolder(eng::library_id_t file_id, eng::library_id_t from_folder,
+ eng::library_id_t to_folder)
{
- return m_pImpl->moveFileToFolder(file_id, folder_id);
+ return m_pImpl->moveFileToFolder(file_id, from_folder, to_folder);
}
eng::tid_t LibraryClient::getAllLabels()
diff --git a/src/libraryclient/libraryclient.hpp b/src/libraryclient/libraryclient.hpp
index 289d442..f33dd3a 100644
--- a/src/libraryclient/libraryclient.hpp
+++ b/src/libraryclient/libraryclient.hpp
@@ -66,7 +66,8 @@ namespace libraryclient {
/** set the metadata */
eng::tid_t setMetadata(eng::library_id_t id, fwk::PropertyIndex meta, const fwk::PropertyValue & value);
- eng::tid_t moveFileToFolder(eng::library_id_t file_id, eng::library_id_t folder_id);
+ eng::tid_t moveFileToFolder(eng::library_id_t file_id, eng::library_id_t from_folder,
+ eng::library_id_t to_folder);
/** get all the labels */
eng::tid_t getAllLabels();
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index 6a18379..841b170 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -52,6 +52,8 @@ GridViewModule::on_lib_notification(const eng::LibNotification &ln)
switch(ln.type) {
case eng::Library::NOTIFY_METADATA_QUERIED:
{
+ DBG_ASSERT(ln.param.type() == typeid(eng::LibMetadata::Ptr),
+ "incorrect data type for the notification");
eng::LibMetadata::Ptr lm
= boost::any_cast<eng::LibMetadata::Ptr>(ln.param);
DBG_OUT("received metadata");
@@ -61,13 +63,25 @@ GridViewModule::on_lib_notification(const eng::LibNotification &ln)
case eng::Library::NOTIFY_METADATA_CHANGED:
{
DBG_OUT("metadata changed");
- eng::metadata_desc_t m = boost::any_cast<eng::metadata_desc_t>(ln.param);
+ DBG_ASSERT(ln.param.type() == typeid(eng::metadata_desc_t),
+ "incorrect data type for the notification");
+ eng::metadata_desc_t m = boost::any_cast<eng::metadata_desc_t>(ln.param);
if(m.id == m_metapanecontroller->displayed_file()) {
// FIXME: actually just update the metadata
m_shell.getLibraryClient()->requestMetadata(m.id);
}
break;
}
+ case eng::Library::NOTIFY_FILE_MOVED:
+ {
+ DBG_ASSERT(ln.param.type() == typeid(std::pair<eng::library_id_t,eng::library_id_t>),
+ "incorrect data type for the notification");
+ std::pair<eng::library_id_t,eng::library_id_t> moved(boost::any_cast<std::pair<eng::library_id_t,eng::library_id_t> >(ln.param));
+
+// check that the file that was moved still match the content
+
+ break;
+ }
default:
break;
}
diff --git a/src/niepce/ui/moduleshell.cpp b/src/niepce/ui/moduleshell.cpp
index edbdf81..ce6e6fb 100644
--- a/src/niepce/ui/moduleshell.cpp
+++ b/src/niepce/ui/moduleshell.cpp
@@ -210,6 +210,11 @@ Gtk::Widget * ModuleShell::buildWidget(const Glib::RefPtr<Gtk::UIManager> & mana
return m_widget;
}
+void ModuleShell::action_edit_delete()
+{
+ DBG_OUT("shell - delete");
+ m_selection_controller->move_to_trash();
+}
void ModuleShell::add_library_module(const ILibraryModule::Ptr & module,
const std::string & label)
diff --git a/src/niepce/ui/moduleshell.hpp b/src/niepce/ui/moduleshell.hpp
index de1162a..ed70c34 100644
--- a/src/niepce/ui/moduleshell.hpp
+++ b/src/niepce/ui/moduleshell.hpp
@@ -75,6 +75,8 @@ public:
void on_image_activated(eng::library_id_t id);
virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager);
+
+ void action_edit_delete();
protected:
virtual void add_library_module(const ILibraryModule::Ptr & module,
const std::string & label);
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index 195e62a..5d1a32b 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -253,7 +253,8 @@ void NiepceWindow::init_actions(const Glib::RefPtr<Gtk::UIManager> & manager)
m_refActionGroup->add(Gtk::Action::create("Cut", Gtk::Stock::CUT));
m_refActionGroup->add(Gtk::Action::create("Copy", Gtk::Stock::COPY));
m_refActionGroup->add(Gtk::Action::create("Paste", Gtk::Stock::PASTE));
- m_refActionGroup->add(Gtk::Action::create("Delete", Gtk::Stock::DELETE));
+ m_refActionGroup->add(Gtk::Action::create("Delete", Gtk::Stock::DELETE),
+ sigc::mem_fun(*this, &NiepceWindow::on_action_edit_delete));
m_refActionGroup->add(Gtk::Action::create("Preferences",
Gtk::Stock::PREFERENCES),
@@ -448,6 +449,12 @@ void NiepceWindow::on_action_edit_labels()
dlg->run_modal(shared_frame_ptr());
}
+void NiepceWindow::on_action_edit_delete()
+{
+ // find the responder. And pass it.
+ m_moduleshell->action_edit_delete();
+}
+
void NiepceWindow::set_title(const std::string & title)
{
Frame::set_title(_("Niepce Digital - ") + title);
diff --git a/src/niepce/ui/niepcewindow.hpp b/src/niepce/ui/niepcewindow.hpp
index 6325dfa..f2025d6 100644
--- a/src/niepce/ui/niepcewindow.hpp
+++ b/src/niepce/ui/niepcewindow.hpp
@@ -62,6 +62,7 @@ private:
void on_action_file_open();
void on_open_library();
void on_action_edit_labels();
+ void on_action_edit_delete();
void preference_dialog_setup(const Glib::RefPtr<Gtk::Builder> &,
Gtk::Dialog *);
diff --git a/src/niepce/ui/selectioncontroller.cpp b/src/niepce/ui/selectioncontroller.cpp
index bb66e3d..5b638ff 100644
--- a/src/niepce/ui/selectioncontroller.cpp
+++ b/src/niepce/ui/selectioncontroller.cpp
@@ -278,6 +278,27 @@ void SelectionController::set_properties(const fwk::PropertyBag & props,
}
}
+void SelectionController::move_to_trash()
+{
+ eng::library_id_t trash_folder = 1; // FIXME get the actual ID.
+ eng::library_id_t selection = get_selection();
+ if(selection >= 0) {
+ Gtk::TreeIter iter = m_imageliststore->get_iter_from_id(selection);
+ if(iter) {
+ eng::LibFile::Ptr file = (*iter)[m_imageliststore->columns().m_libfile];
+ eng::library_id_t from_folder = file->folderId();
+ fwk::UndoTransaction *undo = fwk::Application::app()->begin_undo(_("Move to Trash"));
+ undo->new_command<void>(
+ boost::bind(&libraryclient::LibraryClient::moveFileToFolder,
+ getLibraryClient(), selection, from_folder, trash_folder),
+ boost::bind(&libraryclient::LibraryClient::moveFileToFolder,
+ getLibraryClient(), selection, trash_folder, from_folder )
+ );
+ undo->execute();
+ }
+ }
+}
+
}
diff --git a/src/niepce/ui/selectioncontroller.hpp b/src/niepce/ui/selectioncontroller.hpp
index 32a5050..7e7fbd3 100644
--- a/src/niepce/ui/selectioncontroller.hpp
+++ b/src/niepce/ui/selectioncontroller.hpp
@@ -96,6 +96,8 @@ public:
void set_properties(const fwk::PropertyBag & props,
const fwk::PropertyBag & old);
+ void move_to_trash();
+
/** get the current selection
* todo: change it to support multiple
*/
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index b670b13..c18a033 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -115,11 +115,37 @@ void WorkspaceController::on_lib_notification(const eng::LibNotification &ln)
= m_folderidmap.find( count.first );
if(iter != m_folderidmap.end()) {
Gtk::TreeRow row = *(iter->second);
+ row[m_librarycolumns.m_count_n] = count.second;
row[m_librarycolumns.m_count] = boost::lexical_cast<Glib::ustring>(count.second);
}
break;
}
+ case eng::Library::NOTIFY_FOLDER_COUNT_CHANGE:
+ {
+ std::pair<eng::library_id_t,int> count(boost::any_cast<std::pair<eng::library_id_t,int> >(ln.param));
+ DBG_OUT("count change for folder %Ld is %d", count.first, count.second);
+ std::map<int, Gtk::TreeIter>::iterator iter
+ = m_folderidmap.find( count.first );
+ if(iter != m_folderidmap.end()) {
+ Gtk::TreeRow row = *(iter->second);
+ int new_count = row[m_librarycolumns.m_count_n] + count.second;
+ row[m_librarycolumns.m_count_n] = new_count;
+ row[m_librarycolumns.m_count] = boost::lexical_cast<Glib::ustring>(new_count);
+ }
+
+ break;
+ }
+ case eng::Library::NOTIFY_FILE_MOVED:
+ {
+ DBG_ASSERT(ln.param.type() == typeid(std::pair<eng::library_id_t,eng::library_id_t>),
+ "incorrect data type for the notification");
+
+ std::pair<eng::library_id_t,eng::library_id_t> moved(boost::any_cast<std::pair<eng::library_id_t,eng::library_id_t> >(ln.param));
+
+
+ break;
+ }
default:
break;
}
diff --git a/src/niepce/ui/workspacecontroller.hpp b/src/niepce/ui/workspacecontroller.hpp
index b00fdb1..08879e4 100644
--- a/src/niepce/ui/workspacecontroller.hpp
+++ b/src/niepce/ui/workspacecontroller.hpp
@@ -68,12 +68,14 @@ namespace ui {
add(m_label);
add(m_type);
add(m_count);
+ add(m_count_n);
}
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> > m_icon;
Gtk::TreeModelColumn<int> m_id;
Gtk::TreeModelColumn<Glib::ustring> m_label;
Gtk::TreeModelColumn<int> m_type;
Gtk::TreeModelColumn<Glib::ustring> m_count;
+ Gtk::TreeModelColumn<int> m_count_n;
};
virtual void on_ready();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]