[gnote] Change boolean property editor to use setter/getter
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Change boolean property editor to use setter/getter
- Date: Mon, 14 Dec 2020 21:07:12 +0000 (UTC)
commit 190a09ca8f139f87e6154e4e1cb9171c0698d855
Author: Aurimas Černius <aurisc4 gmail com>
Date: Mon Dec 14 23:05:59 2020 +0200
Change boolean property editor to use setter/getter
src/preferencesdialog.cpp | 19 ++++++++++---------
src/sharp/propertyeditor.cpp | 14 ++++++++------
src/sharp/propertyeditor.hpp | 8 +++++---
3 files changed, 23 insertions(+), 18 deletions(-)
---
diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp
index 9a1bb7f7..5bf88485 100644
--- a/src/preferencesdialog.cpp
+++ b/src/preferencesdialog.cpp
@@ -57,6 +57,9 @@
#define DEFAULT_SYNC_CONFIGURED_CONFLICT_BEHAVIOR 0
+#define NEW_PROPERTY_EDITOR_BOOL(property, check) new sharp::PropertyEditorBool([this]()->bool { return
m_gnote.preferences().property(); }, \
+ [this](bool v) { m_gnote.preferences().property(v); }, check);
+
namespace gnote {
struct CompareSyncAddinsByName
@@ -250,7 +253,7 @@ namespace gnote {
// Open in new window
check = manage(make_check_button(_("Always _open notes in new window")));
options_list->attach(*check, 0, options_list_row++, 1, 1);
- peditor = new sharp::PropertyEditorBool(settings, Preferences::OPEN_NOTES_IN_NEW_WINDOW, *check);
+ peditor = NEW_PROPERTY_EDITOR_BOOL(open_notes_in_new_window, *check);
peditor->setup();
@@ -265,7 +268,7 @@ namespace gnote {
set_widget_tooltip(*check, _("Misspellings will be underlined in red, with correct spelling "
"suggestions shown in the context menu."));
options_list->attach(*check, 0, options_list_row++, 1, 1);
- peditor = new sharp::PropertyEditorBool(settings, Preferences::ENABLE_SPELLCHECKING, *check);
+ peditor = NEW_PROPERTY_EDITOR_BOOL(enable_spellchecking, *check);
peditor->setup();
}
#endif
@@ -275,8 +278,7 @@ namespace gnote {
check = manage(make_check_button (_("Enable auto-_bulleted lists")));
set_widget_tooltip(*check, _("Start new bulleted list by starting new line with character \"-\"."));
options_list->attach(*check, 0, options_list_row++, 1, 1);
- bullet_peditor = new sharp::PropertyEditorBool(settings, Preferences::ENABLE_AUTO_BULLETED_LISTS,
- *check);
+ bullet_peditor = NEW_PROPERTY_EDITOR_BOOL(enable_auto_bulleted_lists, *check);
bullet_peditor->setup();
// Custom font...
@@ -285,8 +287,7 @@ namespace gnote {
check = manage(make_check_button (_("Use custom _font")));
check->set_hexpand(true);
font_box->attach(*check, 0, 0, 1, 1);
- font_peditor = new sharp::PropertyEditorBool(settings, Preferences::ENABLE_CUSTOM_FONT,
- *check);
+ font_peditor = NEW_PROPERTY_EDITOR_BOOL(enable_custom_font, *check);
font_peditor->setup();
font_button = manage(make_font_button());
@@ -391,7 +392,7 @@ namespace gnote {
check = manage(make_check_button(_("_Automatically link to notes")));
set_widget_tooltip(*check, _("Enable this option to create a link when text matches note title."));
vbox->attach(*check, 0, vbox_row++, 1, 1);
- peditor = new sharp::PropertyEditorBool(settings, Preferences::ENABLE_AUTO_LINKS, *check);
+ peditor = NEW_PROPERTY_EDITOR_BOOL(enable_auto_links, *check);
peditor->setup();
// URLs
@@ -399,7 +400,7 @@ namespace gnote {
set_widget_tooltip(*check, _("Enable this option to create links for URLs. "
"Clicking will open URL with appropriate program."));
vbox->attach(*check, 0, vbox_row++, 1, 1);
- peditor = new sharp::PropertyEditorBool(settings, Preferences::ENABLE_URL_LINKS, *check);
+ peditor = NEW_PROPERTY_EDITOR_BOOL(enable_url_links, *check);
peditor->setup();
// WikiWords...
@@ -407,7 +408,7 @@ namespace gnote {
set_widget_tooltip(*check, _("Enable this option to highlight words <b>ThatLookLikeThis</b>. "
"Clicking the word will create a note with that name."));
vbox->attach(*check, 0, vbox_row++, 1, 1);
- peditor = new sharp::PropertyEditorBool(settings, Preferences::ENABLE_WIKIWORDS, *check);
+ peditor = NEW_PROPERTY_EDITOR_BOOL(enable_wikiwords, *check);
peditor->setup();
return vbox;
diff --git a/src/sharp/propertyeditor.cpp b/src/sharp/propertyeditor.cpp
index 3c720fd5..92262686 100644
--- a/src/sharp/propertyeditor.cpp
+++ b/src/sharp/propertyeditor.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011,2017 Aurimas Cernius
+ * Copyright (C) 2011,2017,2020 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -33,7 +33,7 @@
namespace sharp {
- PropertyEditorBase::PropertyEditorBase(Glib::RefPtr<Gio::Settings> & settings, const char *key,
Gtk::Widget &w)
+ PropertyEditorBase::PropertyEditorBase(const Glib::RefPtr<Gio::Settings> & settings, const char *key,
Gtk::Widget &w)
: m_key(key), m_widget(w), m_settings(settings)
{
w.set_data(Glib::Quark("sharp::property-editor"), (gpointer)this,
@@ -72,8 +72,10 @@ namespace sharp {
}
- PropertyEditorBool::PropertyEditorBool(Glib::RefPtr<Gio::Settings> & settings, const char * key,
Gtk::ToggleButton &button)
- : PropertyEditorBase(settings, key, button)
+ PropertyEditorBool::PropertyEditorBool(std::function<bool()> getter, std::function<void(bool)> setter,
Gtk::ToggleButton &button)
+ : PropertyEditorBase(Glib::RefPtr<Gio::Settings>(), "", button)
+ , m_getter(getter)
+ , m_setter(setter)
{
m_connection = button.property_active().signal_changed().connect(
sigc::mem_fun(*this, &PropertyEditorBool::on_changed));
@@ -91,14 +93,14 @@ namespace sharp {
void PropertyEditorBool::setup()
{
m_connection.block();
- static_cast<Gtk::ToggleButton &>(m_widget).set_active(m_settings->get_boolean(m_key));
+ static_cast<Gtk::ToggleButton &>(m_widget).set_active(m_getter());
m_connection.unblock();
}
void PropertyEditorBool::on_changed()
{
bool active = static_cast<Gtk::ToggleButton &>(m_widget).get_active();
- m_settings->set_boolean(m_key, active);
+ m_setter(active);
guard(active);
}
diff --git a/src/sharp/propertyeditor.hpp b/src/sharp/propertyeditor.hpp
index 73600677..065a50c7 100644
--- a/src/sharp/propertyeditor.hpp
+++ b/src/sharp/propertyeditor.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011,2013,2017,2019 Aurimas Cernius
+ * Copyright (C) 2011,2013,2017,2019-2020 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -45,7 +45,7 @@ namespace sharp {
virtual void setup() = 0;
protected:
- PropertyEditorBase(Glib::RefPtr<Gio::Settings> & settings, const char *key, Gtk::Widget &w);
+ PropertyEditorBase(const Glib::RefPtr<Gio::Settings> & settings, const char *key, Gtk::Widget &w);
Glib::ustring m_key;
Gtk::Widget &m_widget;
@@ -71,7 +71,7 @@ namespace sharp {
: public PropertyEditorBase
{
public:
- PropertyEditorBool(Glib::RefPtr<Gio::Settings> & settings, const char * key, Gtk::ToggleButton &button);
+ PropertyEditorBool(std::function<bool()> getter, std::function<void(bool)> setter, Gtk::ToggleButton
&button);
void add_guard(Gtk::Widget* w)
{
m_guarded.push_back(w);
@@ -83,6 +83,8 @@ namespace sharp {
void guard(bool v);
void on_changed();
std::vector<Gtk::Widget*> m_guarded;
+ std::function<bool()> m_getter;
+ std::function<void(bool)> m_setter;
};
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]