[gnote] Refactor PropertyEditor to use getter/setter



commit e90eacb86e44c9a08678d0e864a2ec8660dae097
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Thu Dec 31 15:32:21 2020 +0200

    Refactor PropertyEditor to use getter/setter

 src/sharp/propertyeditor.cpp | 16 +++++++++-------
 src/sharp/propertyeditor.hpp |  8 ++++----
 2 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/src/sharp/propertyeditor.cpp b/src/sharp/propertyeditor.cpp
index 92262686..136f924d 100644
--- a/src/sharp/propertyeditor.cpp
+++ b/src/sharp/propertyeditor.cpp
@@ -33,8 +33,8 @@
 namespace sharp {
 
 
-  PropertyEditorBase::PropertyEditorBase(const Glib::RefPtr<Gio::Settings> & settings, const char *key, 
Gtk::Widget &w)
-    : m_key(key), m_widget(w), m_settings(settings)
+  PropertyEditorBase::PropertyEditorBase(Gtk::Widget &w)
+    : m_widget(w)
   {
     w.set_data(Glib::Quark("sharp::property-editor"), (gpointer)this,
                &PropertyEditorBase::destroy_notify);
@@ -51,8 +51,10 @@ namespace sharp {
   }
 
 
-  PropertyEditor::PropertyEditor(Glib::RefPtr<Gio::Settings> & settings, const char * key, Gtk::Entry &entry)
-    : PropertyEditorBase(settings, key, entry)
+  PropertyEditor::PropertyEditor(std::function<Glib::ustring()> getter, std::function<void(const 
Glib::ustring&)> setter, Gtk::Entry &entry)
+    : PropertyEditorBase(entry)
+    , m_getter(getter)
+    , m_setter(setter)
   {
     m_connection = entry.property_text().signal_changed().connect(
       sigc::mem_fun(*this, &PropertyEditor::on_changed));
@@ -61,19 +63,19 @@ namespace sharp {
   void PropertyEditor::setup()
   {
     m_connection.block();
-    static_cast<Gtk::Entry &>(m_widget).set_text(m_settings->get_string(m_key));
+    static_cast<Gtk::Entry &>(m_widget).set_text(m_getter());
     m_connection.unblock();        
   }
 
   void PropertyEditor::on_changed()
   {
     Glib::ustring txt = static_cast<Gtk::Entry &>(m_widget).get_text();
-    m_settings->set_string(m_key, txt);
+    m_setter(txt);
   }
 
 
   PropertyEditorBool::PropertyEditorBool(std::function<bool()> getter, std::function<void(bool)> setter, 
Gtk::ToggleButton &button)
-    : PropertyEditorBase(Glib::RefPtr<Gio::Settings>(), "", button)
+    : PropertyEditorBase(button)
     , m_getter(getter)
     , m_setter(setter)
   {
diff --git a/src/sharp/propertyeditor.hpp b/src/sharp/propertyeditor.hpp
index 065a50c7..e36ae193 100644
--- a/src/sharp/propertyeditor.hpp
+++ b/src/sharp/propertyeditor.hpp
@@ -45,12 +45,10 @@ namespace sharp {
     virtual void setup() = 0;
 
   protected:
-    PropertyEditorBase(const Glib::RefPtr<Gio::Settings> & settings, const char *key, Gtk::Widget &w);
+    explicit PropertyEditorBase(Gtk::Widget & w);
 
-    Glib::ustring m_key;
     Gtk::Widget &m_widget;
     sigc::connection m_connection;
-    Glib::RefPtr<Gio::Settings> m_settings;
   private:
     void static destroy_notify(gpointer data);
   };
@@ -59,12 +57,14 @@ namespace sharp {
       : public PropertyEditorBase
   {
   public:
-    PropertyEditor(Glib::RefPtr<Gio::Settings> & settings, const char * key, Gtk::Entry &entry);
+    PropertyEditor(std::function<Glib::ustring()> getter, std::function<void(const Glib::ustring&)> setter, 
Gtk::Entry &entry);
 
     virtual void setup() override;
 
   private:
     void on_changed();
+    std::function<Glib::ustring()> m_getter;
+    std::function<void(const Glib::ustring&)> m_setter;
   };
 
   class PropertyEditorBool


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