[gnote] Make TagManager non-singleton
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Make TagManager non-singleton
- Date: Tue, 8 Oct 2019 20:04:26 +0000 (UTC)
commit 6c9a57730844ff8a0bcc1a9d6080b819a292cae3
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun Oct 6 21:45:00 2019 +0300
Make TagManager non-singleton
src/dbus/remotecontrol.cpp | 6 +++---
src/gnote.cpp | 1 -
src/itagmanager.hpp | 2 --
src/notebase.cpp | 4 ++--
src/notebooks/notebook.cpp | 11 +++++------
src/notebooks/notebook.hpp | 4 ++--
src/notebooks/notebookmanager.cpp | 3 +--
src/notebooks/notebooknoteaddin.cpp | 6 +++---
src/notebooks/notebooknoteaddin.hpp | 2 +-
src/notemanager.cpp | 4 ++--
src/notemanager.hpp | 10 ++++++++++
src/notemanagerbase.cpp | 9 ++++-----
src/notemanagerbase.hpp | 3 +++
src/notewindow.cpp | 10 +++++-----
src/search.cpp | 3 +--
src/watchers.cpp | 9 ++++-----
16 files changed, 46 insertions(+), 41 deletions(-)
---
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index 0db52ceb..c2deb1ea 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.cpp
@@ -62,7 +62,7 @@ namespace gnote {
if (!note) {
return false;
}
- Tag::Ptr tag = ITagManager::obj().get_or_create_tag(tag_name);
+ Tag::Ptr tag = m_manager.tag_manager().get_or_create_tag(tag_name);
note->add_tag (tag);
return true;
}
@@ -166,7 +166,7 @@ namespace gnote {
std::vector<Glib::ustring> RemoteControl::GetAllNotesWithTag(const Glib::ustring& tag_name)
{
- Tag::Ptr tag = ITagManager::obj().get_tag(tag_name);
+ Tag::Ptr tag = m_manager.tag_manager().get_tag(tag_name);
if (!tag)
return std::vector<Glib::ustring>();
@@ -290,7 +290,7 @@ bool RemoteControl::RemoveTagFromNote(const Glib::ustring& uri,
NoteBase::Ptr note = m_manager.find_by_uri(uri);
if (!note)
return false;
- Tag::Ptr tag = ITagManager::obj().get_tag(tag_name);
+ Tag::Ptr tag = m_manager.tag_manager().get_tag(tag_name);
if (tag) {
note->remove_tag (tag);
}
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 0a475bb9..3b6f71e8 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -141,7 +141,6 @@ namespace gnote {
Glib::ustring note_path = get_note_path(m_cmd_line.note_path());
//create singleton objects
- new TagManager;
new Preferences;
m_manager = new NoteManager(note_path);
new notebooks::NotebookManager(default_note_manager());
diff --git a/src/itagmanager.hpp b/src/itagmanager.hpp
index 607b3e0d..22f73b46 100644
--- a/src/itagmanager.hpp
+++ b/src/itagmanager.hpp
@@ -23,12 +23,10 @@
#include <glibmm/ustring.h>
#include "tag.hpp"
-#include "base/singleton.hpp"
namespace gnote {
class ITagManager
- : public base::Singleton<ITagManager>
{
public:
static const char * TEMPLATE_NOTE_SYSTEM_TAG;
diff --git a/src/notebase.cpp b/src/notebase.cpp
index dcebcca5..ab9df751 100644
--- a/src/notebase.cpp
+++ b/src/notebase.cpp
@@ -336,7 +336,7 @@ void NoteBase::load_foreign_note_xml(const Glib::ustring & foreignNoteXml, Chang
if(doc2) {
std::vector<Glib::ustring> tag_strings = parse_tags(doc2->children);
for(const Glib::ustring & tag_str : tag_strings) {
- Tag::Ptr tag = ITagManager::obj().get_or_create_tag(tag_str);
+ Tag::Ptr tag = m_manager.tag_manager().get_or_create_tag(tag_str);
new_tags.push_back(tag);
}
xmlFreeDoc(doc2);
@@ -486,7 +486,7 @@ void NoteArchiver::_read(sharp::XmlReader & xml, NoteData & data, Glib::ustring
if(doc2) {
std::vector<Glib::ustring> tag_strings = NoteBase::parse_tags(doc2->children);
for(const Glib::ustring & tag_str : tag_strings) {
- Tag::Ptr tag = ITagManager::obj().get_or_create_tag(tag_str);
+ Tag::Ptr tag = m_manager.tag_manager().get_or_create_tag(tag_str);
data.tags()[tag->normalized_name()] = tag;
}
xmlFreeDoc(doc2);
diff --git a/src/notebooks/notebook.cpp b/src/notebooks/notebook.cpp
index 9dd20a32..643585fe 100644
--- a/src/notebooks/notebook.cpp
+++ b/src/notebooks/notebook.cpp
@@ -26,7 +26,6 @@
#include "notemanager.hpp"
#include "notebooks/notebook.hpp"
#include "notebooks/notebookmanager.hpp"
-#include "itagmanager.hpp"
namespace gnote {
namespace notebooks {
@@ -35,10 +34,10 @@ namespace notebooks {
const char * Notebook::NOTEBOOK_TAG_PREFIX = "notebook:";
Tag::Ptr Notebook::s_template_tag;
- Tag::Ptr Notebook::template_tag()
+ Tag::Ptr Notebook::template_tag() const
{
if(s_template_tag == NULL) {
- s_template_tag = ITagManager::obj().get_or_create_system_tag(
+ s_template_tag = m_note_manager.tag_manager().get_or_create_system_tag(
ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
}
@@ -70,7 +69,7 @@ namespace notebooks {
}
else {
set_name(name);
- m_tag = ITagManager::obj().get_or_create_system_tag(
+ m_tag = manager.tag_manager().get_or_create_system_tag(
Glib::ustring(NOTEBOOK_TAG_PREFIX) + name);
}
}
@@ -127,7 +126,7 @@ namespace notebooks {
{
Note::Ptr note;
Tag::Ptr templ_tag = template_tag();
- Tag::Ptr notebook_tag = ITagManager::obj().get_system_tag(NOTEBOOK_TAG_PREFIX + get_name());
+ Tag::Ptr notebook_tag = m_note_manager.tag_manager().get_system_tag(NOTEBOOK_TAG_PREFIX + get_name());
if(!templ_tag || !notebook_tag) {
return note;
}
@@ -165,7 +164,7 @@ namespace notebooks {
// Add on the notebook system tag so Tomboy
// will persist the tag/notebook across sessions
// if no other notes are added to the notebook.
- Tag::Ptr notebook_tag = ITagManager::obj().get_or_create_system_tag(NOTEBOOK_TAG_PREFIX + get_name());
+ Tag::Ptr notebook_tag = m_note_manager.tag_manager().get_or_create_system_tag(NOTEBOOK_TAG_PREFIX +
get_name());
note->add_tag (notebook_tag);
note->queue_save (CONTENT_CHANGED);
diff --git a/src/notebooks/notebook.hpp b/src/notebooks/notebook.hpp
index 4ed2d06c..99bd26c7 100644
--- a/src/notebooks/notebook.hpp
+++ b/src/notebooks/notebook.hpp
@@ -56,8 +56,8 @@ public:
virtual ~Notebook()
{}
protected:
- static Tag::Ptr template_tag();
- static bool is_template_note(const Note::Ptr &);
+ Tag::Ptr template_tag() const;
+ bool is_template_note(const Note::Ptr &);
NoteManager & m_note_manager;
private:
diff --git a/src/notebooks/notebookmanager.cpp b/src/notebooks/notebookmanager.cpp
index 594fd792..a3469f66 100644
--- a/src/notebooks/notebookmanager.cpp
+++ b/src/notebooks/notebookmanager.cpp
@@ -32,7 +32,6 @@
#include "debug.hpp"
#include "ignote.hpp"
#include "notemanager.hpp"
-#include "itagmanager.hpp"
namespace gnote {
@@ -463,7 +462,7 @@ namespace gnote {
void NotebookManager::load_notebooks()
{
Gtk::TreeIter iter;
- auto tags = ITagManager::obj().all_tags();
+ auto tags = m_note_manager.tag_manager().all_tags();
for(const auto & tag : tags) {
// Skip over tags that aren't notebooks
if (!tag->is_system()
diff --git a/src/notebooks/notebooknoteaddin.cpp b/src/notebooks/notebooknoteaddin.cpp
index 5adc3f18..ada1aaa3 100644
--- a/src/notebooks/notebooknoteaddin.cpp
+++ b/src/notebooks/notebooknoteaddin.cpp
@@ -30,7 +30,7 @@
#include "iactionmanager.hpp"
#include "iconmanager.hpp"
#include "tag.hpp"
-#include "itagmanager.hpp"
+#include "notemanagerbase.hpp"
#include "notewindow.hpp"
@@ -39,10 +39,10 @@ namespace notebooks {
Tag::Ptr NotebookNoteAddin::s_templateTag;
- Tag::Ptr NotebookNoteAddin::get_template_tag()
+ Tag::Ptr NotebookNoteAddin::get_template_tag() const
{
if(!s_templateTag) {
- s_templateTag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+ s_templateTag =
manager().tag_manager().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
}
return s_templateTag;
}
diff --git a/src/notebooks/notebooknoteaddin.hpp b/src/notebooks/notebooknoteaddin.hpp
index be0f9061..b0e8c8c1 100644
--- a/src/notebooks/notebooknoteaddin.hpp
+++ b/src/notebooks/notebooknoteaddin.hpp
@@ -36,7 +36,7 @@ namespace notebooks {
{
public:
static NoteAddin * create();
- static Tag::Ptr get_template_tag();
+ Tag::Ptr get_template_tag() const;
virtual void initialize() override;
virtual void shutdown() override;
virtual void on_note_opened() override;
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index a9749d13..5ba93595 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -327,7 +327,7 @@ namespace gnote {
}
// Copy template note's properties
- Tag::Ptr template_save_size =
ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
+ Tag::Ptr template_save_size =
m_tag_manager.get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
if(template_note->data().has_extent() && template_note->contains_tag(template_save_size)) {
new_note->data().height() = template_note->data().height();
new_note->data().width() = template_note->data().width();
@@ -335,7 +335,7 @@ namespace gnote {
Glib::RefPtr<Gtk::TextBuffer> buffer = std::static_pointer_cast<Note>(new_note)->get_buffer();
Gtk::TextIter cursor, selection;
- Tag::Ptr template_save_selection =
ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG);
+ Tag::Ptr template_save_selection =
m_tag_manager.get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG);
if(template_note->contains_tag(template_save_selection)) {
Glib::ustring template_title = template_note->get_title();
int cursor_pos = template_note->data().cursor_position();
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index 0adc6bf8..7c5ae6f5 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -25,6 +25,7 @@
#include "notemanagerbase.hpp"
#include "note.hpp"
+#include "tagmanager.hpp"
namespace gnote {
@@ -44,6 +45,14 @@ namespace gnote {
{
return m_note_archiver;
}
+ virtual const ITagManager & tag_manager() const override
+ {
+ return m_tag_manager;
+ }
+ virtual ITagManager & tag_manager() override
+ {
+ return m_tag_manager;
+ }
void on_setting_changed(const Glib::ustring & key);
@@ -77,6 +86,7 @@ namespace gnote {
AddinManager *m_addin_mgr;
NoteArchiver m_note_archiver;
+ TagManager m_tag_manager;
};
diff --git a/src/notemanagerbase.cpp b/src/notemanagerbase.cpp
index c38b5d43..2c613d50 100644
--- a/src/notemanagerbase.cpp
+++ b/src/notemanagerbase.cpp
@@ -24,7 +24,6 @@
#include "debug.hpp"
#include "ignote.hpp"
-#include "itagmanager.hpp"
#include "notemanagerbase.hpp"
#include "utils.hpp"
#include "trie.hpp"
@@ -257,7 +256,7 @@ NoteBase::Ptr NoteManagerBase::create_note_from_template(const Glib::ustring & t
const Glib::ustring & guid)
{
Glib::ustring new_title(title);
- Tag::Ptr template_save_title =
ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG);
+ Tag::Ptr template_save_title =
tag_manager().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG);
if(template_note->contains_tag(template_save_title)) {
new_title = get_unique_name(template_note->get_title());
}
@@ -271,7 +270,7 @@ NoteBase::Ptr NoteManagerBase::create_note_from_template(const Glib::ustring & t
NoteBase::Ptr new_note = create_new_note(new_title, xml_content, guid);
// Copy template note's properties
- Tag::Ptr template_save_size =
ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
+ Tag::Ptr template_save_size =
tag_manager().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
if(template_note->data().has_extent() && template_note->contains_tag(template_save_size)) {
new_note->data().height() = template_note->data().height();
new_note->data().width() = template_note->data().width();
@@ -379,7 +378,7 @@ NoteBase::Ptr NoteManagerBase::get_or_create_template_note()
}
// Flag this as a template note
- Tag::Ptr template_tag =
ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+ Tag::Ptr template_tag = tag_manager().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
template_note->add_tag(template_tag);
template_note->queue_save(CONTENT_CHANGED);
@@ -428,7 +427,7 @@ Glib::ustring NoteManagerBase::make_new_file_name(const Glib::ustring & guid) co
NoteBase::Ptr NoteManagerBase::find_template_note() const
{
NoteBase::Ptr template_note;
- Tag::Ptr template_tag = ITagManager::obj().get_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+ Tag::Ptr template_tag = tag_manager().get_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
if(!template_tag) {
return template_note;
}
diff --git a/src/notemanagerbase.hpp b/src/notemanagerbase.hpp
index d378e7ea..e783f35a 100644
--- a/src/notemanagerbase.hpp
+++ b/src/notemanagerbase.hpp
@@ -22,6 +22,7 @@
#ifndef _NOTEMANAGERBASE_HPP_
#define _NOTEMANAGERBASE_HPP_
+#include "itagmanager.hpp"
#include "notebase.hpp"
#include "triehit.hpp"
@@ -46,6 +47,8 @@ public:
TrieHit<NoteBase::WeakPtr>::ListPtr find_trie_matches(const Glib::ustring &);
virtual NoteArchiver & note_archiver() = 0;
+ virtual const ITagManager & tag_manager() const = 0;
+ virtual ITagManager & tag_manager() = 0;
void read_only(bool ro)
{
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 2eb530d0..3c1d26c9 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -44,7 +44,6 @@
#include "utils.hpp"
#include "undo.hpp"
#include "search.hpp"
-#include "itagmanager.hpp"
#include "notebooks/notebookmanager.hpp"
#include "sharp/exception.hpp"
#include "mainwindowaction.hpp"
@@ -101,10 +100,11 @@ namespace gnote {
, m_global_keys(NULL)
, m_enabled(true)
{
- m_template_tag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
- m_template_save_size_tag =
ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
- m_template_save_selection_tag =
ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG);
- m_template_save_title_tag =
ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG);
+ ITagManager & tag_manager = note.manager().tag_manager();
+ m_template_tag = tag_manager.get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+ m_template_save_size_tag =
tag_manager.get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
+ m_template_save_selection_tag =
tag_manager.get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SELECTION_SYSTEM_TAG);
+ m_template_save_title_tag =
tag_manager.get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_TITLE_SYSTEM_TAG);
set_hexpand(true);
set_vexpand(true);
diff --git a/src/search.cpp b/src/search.cpp
index 8de06ed9..2017abb4 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -24,7 +24,6 @@
#include "sharp/string.hpp"
#include "notemanager.hpp"
#include "search.hpp"
-#include "itagmanager.hpp"
#include "utils.hpp"
namespace gnote {
@@ -53,7 +52,7 @@ namespace gnote {
ResultsPtr temp_matches(new Results);
// Skip over notes that are template notes
- Tag::Ptr template_tag =
ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
+ Tag::Ptr template_tag =
m_manager.tag_manager().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
for(const NoteBase::Ptr & iter : m_manager.get_notes()) {
Note::Ptr note(std::static_pointer_cast<Note>(iter));
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 74ef0000..d368c5e2 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -36,7 +36,6 @@
#include "notemanager.hpp"
#include "notewindow.hpp"
#include "preferences.hpp"
-#include "itagmanager.hpp"
#include "triehit.hpp"
#include "watchers.hpp"
@@ -445,7 +444,7 @@ namespace gnote {
if(tag && tag->name() != tag_name) {
get_note()->remove_tag(tag);
}
- tag = ITagManager::obj().get_or_create_tag(tag_name);
+ tag = manager().tag_manager().get_or_create_tag(tag_name);
get_note()->add_tag(tag);
DBG_OUT("Added language tag %s", tag_name.c_str());
}
@@ -489,7 +488,7 @@ namespace gnote {
else {
Glib::ustring tag_name = LANG_PREFIX;
tag_name += LANG_DISABLED;
- tag = ITagManager::obj().get_or_create_tag(tag_name);
+ tag = manager().tag_manager().get_or_create_tag(tag_name);
get_note()->add_tag(tag);
detach_checker();
}
@@ -1379,10 +1378,10 @@ namespace gnote {
void NoteTagsWatcher::on_tag_removed(const NoteBase::Ptr&, const Glib::ustring& tag_name)
{
- Tag::Ptr tag = ITagManager::obj().get_tag(tag_name);
+ Tag::Ptr tag = manager().tag_manager().get_tag(tag_name);
DBG_OUT ("Watchers.OnTagRemoved popularity count: %d", tag ? tag->popularity() : 0);
if (tag && tag->popularity() == 0) {
- ITagManager::obj().remove_tag(tag);
+ manager().tag_manager().remove_tag(tag);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]