[niepce] Implement undo for properties.
- From: Hubert FiguiÃre <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] Implement undo for properties.
- Date: Sun, 13 Nov 2011 06:50:28 +0000 (UTC)
commit 6ac140089e69e83b26fe68078dc13bc29b42da3e
Author: Hub Figuiere <hub figuiere net>
Date: Sat Nov 12 16:44:44 2011 -0800
Implement undo for properties.
src/fwk/toolkit/metadatawidget.cpp | 22 ++++++++++++++++------
src/fwk/toolkit/metadatawidget.hpp | 4 +++-
src/niepce/ui/gridviewmodule.cpp | 4 ++--
src/niepce/ui/gridviewmodule.hpp | 2 +-
src/niepce/ui/metadatapanecontroller.cpp | 5 +++--
src/niepce/ui/metadatapanecontroller.hpp | 5 +++--
src/niepce/ui/selectioncontroller.cpp | 16 +++++++++++-----
src/niepce/ui/selectioncontroller.hpp | 6 ++++--
8 files changed, 43 insertions(+), 21 deletions(-)
---
diff --git a/src/fwk/toolkit/metadatawidget.cpp b/src/fwk/toolkit/metadatawidget.cpp
index a9e8671..5fb0c48 100644
--- a/src/fwk/toolkit/metadatawidget.cpp
+++ b/src/fwk/toolkit/metadatawidget.cpp
@@ -79,6 +79,7 @@ void MetaDataWidget::clear_widget(std::pair<const PropertyIndex, Gtk::Widget *>
void MetaDataWidget::set_data_source(const fwk::PropertyBag & properties)
{
DBG_OUT("set data source");
+ m_current_data = properties;
if(!m_data_map.empty()) {
std::for_each(m_data_map.begin(), m_data_map.end(),
boost::bind(&MetaDataWidget::clear_widget, this, _1));
@@ -209,14 +210,13 @@ void MetaDataWidget::add_data(const MetaDataFormat * current,
m_table.show_all();
}
-bool MetaDataWidget::on_str_changed(GdkEventFocus*, Gtk::Entry *e, fwk::PropertyIndex prop)
+bool MetaDataWidget::on_str_changed(GdkEventFocus*, Gtk::Entry *e,
+ fwk::PropertyIndex prop)
{
if(m_update) {
return true;
}
- fwk::PropertyBag props;
- props.set_value_for_property(prop, fwk::PropertyValue(e->get_text()));
- signal_metadata_changed.emit(props);
+ emit_metadata_changed(prop, fwk::PropertyValue(e->get_text()));
return true;
}
@@ -225,9 +225,19 @@ void MetaDataWidget::on_int_changed(int value, fwk::PropertyIndex prop)
if(m_update) {
return;
}
- fwk::PropertyBag props;
+ emit_metadata_changed(prop, fwk::PropertyValue(value));
+}
+
+void MetaDataWidget::emit_metadata_changed(fwk::PropertyIndex prop,
+ const fwk::PropertyValue & value)
+{
+ fwk::PropertyBag props, old_props;
props.set_value_for_property(prop, fwk::PropertyValue(value));
- signal_metadata_changed.emit(props);
+ fwk::PropertyValue old_value;
+ if(m_current_data.get_value_for_property(prop, old_value)) {
+ old_props.set_value_for_property(prop, old_value);
+ }
+ signal_metadata_changed.emit(props, old_props);
}
}
diff --git a/src/fwk/toolkit/metadatawidget.hpp b/src/fwk/toolkit/metadatawidget.hpp
index 9064f96..b73ac23 100644
--- a/src/fwk/toolkit/metadatawidget.hpp
+++ b/src/fwk/toolkit/metadatawidget.hpp
@@ -72,15 +72,17 @@ public:
void set_data_format(const MetaDataSectionFormat * fmt);
void set_data_source(const fwk::PropertyBag & properties);
- sigc::signal<void, const fwk::PropertyBag &> signal_metadata_changed;
+ sigc::signal<void, const fwk::PropertyBag &, const fwk::PropertyBag &> signal_metadata_changed;
protected:
bool on_str_changed(GdkEventFocus*, Gtk::Entry *, fwk::PropertyIndex prop);
void on_int_changed(int, fwk::PropertyIndex prop);
private:
void clear_widget(std::pair<const PropertyIndex, Gtk::Widget *> & p);
+ void emit_metadata_changed(fwk::PropertyIndex prop, const fwk::PropertyValue & value);
Gtk::Table m_table;
std::map<const PropertyIndex, Gtk::Widget *> m_data_map;
+ fwk::PropertyBag m_current_data;
const MetaDataSectionFormat * m_fmt;
bool m_update;
};
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index ae28307..37d720f 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -176,11 +176,11 @@ void GridViewModule::select_image(eng::library_id_t id)
}
-void GridViewModule::on_metadata_changed(const fwk::PropertyBag & props)
+void GridViewModule::on_metadata_changed(const fwk::PropertyBag & props, const fwk::PropertyBag & old)
{
// TODO this MUST be more generic
DBG_OUT("on_metadata_changed()");
- m_shell.get_selection_controller()->set_properties(props);
+ m_shell.get_selection_controller()->set_properties(props, old);
}
void GridViewModule::on_rating_changed(int /*id*/, int rating)
diff --git a/src/niepce/ui/gridviewmodule.hpp b/src/niepce/ui/gridviewmodule.hpp
index b95e5c7..fd415c3 100644
--- a/src/niepce/ui/gridviewmodule.hpp
+++ b/src/niepce/ui/gridviewmodule.hpp
@@ -75,7 +75,7 @@ protected:
private:
- void on_metadata_changed(const fwk::PropertyBag &);
+ void on_metadata_changed(const fwk::PropertyBag &, const fwk::PropertyBag & old);
void on_rating_changed(int id, int rating);
const IModuleShell & m_shell;
diff --git a/src/niepce/ui/metadatapanecontroller.cpp b/src/niepce/ui/metadatapanecontroller.cpp
index b721fa5..3daf7c5 100644
--- a/src/niepce/ui/metadatapanecontroller.cpp
+++ b/src/niepce/ui/metadatapanecontroller.cpp
@@ -139,9 +139,10 @@ MetaDataPaneController::buildWidget(const Glib::RefPtr<Gtk::UIManager> & )
return m_widget;
}
-void MetaDataPaneController::on_metadata_changed(const fwk::PropertyBag & props)
+void MetaDataPaneController::on_metadata_changed(const fwk::PropertyBag & props,
+ const fwk::PropertyBag & old)
{
- signal_metadata_changed.emit(props);
+ signal_metadata_changed.emit(props, old);
}
diff --git a/src/niepce/ui/metadatapanecontroller.hpp b/src/niepce/ui/metadatapanecontroller.hpp
index 8f20291..3e58548 100644
--- a/src/niepce/ui/metadatapanecontroller.hpp
+++ b/src/niepce/ui/metadatapanecontroller.hpp
@@ -47,9 +47,10 @@ public:
eng::library_id_t displayed_file() const
{ return m_fileid; }
- sigc::signal<void, const fwk::PropertyBag &> signal_metadata_changed;
+ sigc::signal<void, const fwk::PropertyBag &, const fwk::PropertyBag &> signal_metadata_changed;
private:
- void on_metadata_changed(const fwk::PropertyBag &);
+ void on_metadata_changed(const fwk::PropertyBag &,
+ const fwk::PropertyBag & old);
std::vector<fwk::MetaDataWidget *> m_widgets;
diff --git a/src/niepce/ui/selectioncontroller.cpp b/src/niepce/ui/selectioncontroller.cpp
index fbcb2fb..bb66e3d 100644
--- a/src/niepce/ui/selectioncontroller.cpp
+++ b/src/niepce/ui/selectioncontroller.cpp
@@ -193,18 +193,23 @@ bool SelectionController::_set_metadata(const std::string & undo_label,
bool SelectionController::_set_metadata(const std::string & undo_label,
const eng::LibFile::Ptr & file,
- const fwk::PropertyBag & props)
+ const fwk::PropertyBag & props,
+ const fwk::PropertyBag & old)
{
fwk::UndoTransaction *undo = fwk::Application::app()->begin_undo(undo_label);
for(fwk::PropertyBag::const_iterator iter = props.begin();
iter != props.end(); ++iter) {
+ fwk::PropertyValue value;
+ old.get_value_for_property(iter->first, value);
+
+ DBG_ASSERT(value.type() == iter->second.type(), "Value type mismatch");
+
undo->new_command<void>(
boost::bind(&libraryclient::LibraryClient::setMetadata,
getLibraryClient(), file->id(), iter->first, iter->second),
- // FIXME. This make undo now work
boost::bind(&libraryclient::LibraryClient::setMetadata,
- getLibraryClient(), file->id(), iter->first, iter->second)
+ getLibraryClient(), file->id(), iter->first, value)
);
}
undo->execute();
@@ -260,14 +265,15 @@ void SelectionController::set_property(fwk::PropertyIndex idx, int value)
}
}
-void SelectionController::set_properties(const fwk::PropertyBag & props)
+void SelectionController::set_properties(const fwk::PropertyBag & props,
+ const fwk::PropertyBag & old)
{
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];
- _set_metadata(_("Set Properties"), file, props);
+ _set_metadata(_("Set Properties"), file, props, old);
}
}
}
diff --git a/src/niepce/ui/selectioncontroller.hpp b/src/niepce/ui/selectioncontroller.hpp
index 64bbfdd..32a5050 100644
--- a/src/niepce/ui/selectioncontroller.hpp
+++ b/src/niepce/ui/selectioncontroller.hpp
@@ -93,7 +93,8 @@ public:
void set_property(fwk::PropertyIndex idx, int value);
- void set_properties(const fwk::PropertyBag & props);
+ void set_properties(const fwk::PropertyBag & props,
+ const fwk::PropertyBag & old);
/** get the current selection
* todo: change it to support multiple
@@ -111,7 +112,8 @@ private:
int old_value, int new_value);
bool _set_metadata(const std::string & undo_label,
const eng::LibFile::Ptr & file,
- const fwk::PropertyBag & props);
+ const fwk::PropertyBag & props,
+ const fwk::PropertyBag & old);
/** move the selection and emit the signal
* @param backwards true if the move is backwards.
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]