[gnote] Make NotebookManager not singleton
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Make NotebookManager not singleton
- Date: Mon, 21 Oct 2019 13:38:57 +0000 (UTC)
commit 9c23dfedf9ddd13538d50c74d21db40ae434fb71
Author: Aurimas Černius <aurisc4 gmail com>
Date: Mon Oct 21 16:36:30 2019 +0300
Make NotebookManager not singleton
src/gnote.cpp | 5 ++++-
src/gnote.hpp | 5 +++++
src/ignote.hpp | 4 ++++
src/note.cpp | 4 ++--
src/notebooks/createnotebookdialog.cpp | 2 +-
src/notebooks/notebook.cpp | 3 ++-
src/notebooks/notebookapplicationaddin.cpp | 17 ++++++++---------
src/notebooks/notebookmanager.cpp | 10 +++++-----
src/notebooks/notebookmanager.hpp | 4 +---
src/notebooks/notebookmenuitem.cpp | 5 +++--
src/notebooks/notebooknoteaddin.cpp | 14 +++++++-------
src/notebooks/specialnotebooks.cpp | 4 ++--
src/notemanagerbase.cpp | 2 +-
src/notewindow.cpp | 2 +-
src/searchnoteswidget.cpp | 24 +++++++++++-------------
15 files changed, 57 insertions(+), 48 deletions(-)
---
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 656df6c9..8d88f044 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -71,6 +71,9 @@ namespace gnote {
if (m_prefsdlg) {
delete m_prefsdlg;
}
+ if(m_notebook_manager) {
+ delete m_notebook_manager;
+ }
delete m_manager;
}
@@ -143,7 +146,7 @@ namespace gnote {
m_preferences.init();;
m_manager = new NoteManager(m_preferences);
m_manager->init(note_path);
- new notebooks::NotebookManager(default_note_manager());
+ m_notebook_manager = new notebooks::NotebookManager(default_note_manager());
m_action_manager.init();
sync::SyncManager::init(default_note_manager());
diff --git a/src/gnote.hpp b/src/gnote.hpp
index 37b321a3..4575390d 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -129,6 +129,10 @@ public:
{
return m_icon_manager;
}
+ virtual notebooks::NotebookManager & notebook_manager() override
+ {
+ return *m_notebook_manager;
+ }
virtual Preferences & preferences()
{
return m_preferences;
@@ -174,6 +178,7 @@ private:
NoteManager *m_manager;
IconManager m_icon_manager;
+ notebooks::NotebookManager *m_notebook_manager;
Preferences m_preferences;
ActionManager m_action_manager;
Glib::RefPtr<Gtk::IconTheme> m_icon_theme;
diff --git a/src/ignote.hpp b/src/ignote.hpp
index 911d00df..7c602936 100644
--- a/src/ignote.hpp
+++ b/src/ignote.hpp
@@ -28,6 +28,9 @@ namespace gnote {
class IActionManager;
class IconManager;
class Preferences;
+namespace notebooks {
+ class NotebookManager;
+}
class IGnote
@@ -43,6 +46,7 @@ public:
virtual IActionManager & action_manager() = 0;
virtual IconManager & icon_manager() = 0;
+ virtual notebooks::NotebookManager & notebook_manager() = 0;
virtual Preferences & preferences() = 0;
virtual MainWindow & get_main_window() = 0;
diff --git a/src/note.cpp b/src/note.cpp
index ddc76dee..d9a512aa 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -760,7 +760,7 @@ namespace gnote {
m_note_window_embedded = true;
}
-
notebooks::NotebookManager::obj().active_notes_notebook()->add_note(std::static_pointer_cast<Note>(shared_from_this()));
+
IGnote::obj().notebook_manager().active_notes_notebook()->add_note(std::static_pointer_cast<Note>(shared_from_this()));
}
void Note::on_note_window_foregrounded()
@@ -810,7 +810,7 @@ namespace gnote {
}
}
settings->set_string(Preferences::MENU_PINNED_NOTES, new_pinned);
- notebooks::NotebookManager::obj().signal_note_pin_status_changed(*this, pinned);
+ IGnote::obj().notebook_manager().signal_note_pin_status_changed(*this, pinned);
}
void Note::enabled(bool is_enabled)
diff --git a/src/notebooks/createnotebookdialog.cpp b/src/notebooks/createnotebookdialog.cpp
index b53395b2..c882a9df 100644
--- a/src/notebooks/createnotebookdialog.cpp
+++ b/src/notebooks/createnotebookdialog.cpp
@@ -92,7 +92,7 @@ namespace gnote {
void CreateNotebookDialog::on_name_entry_changed()
{
bool nameTaken = false;
- if(NotebookManager::obj().notebook_exists(get_notebook_name())) {
+ if(IGnote::obj().notebook_manager().notebook_exists(get_notebook_name())) {
m_errorLabel.show ();
nameTaken = true;
}
diff --git a/src/notebooks/notebook.cpp b/src/notebooks/notebook.cpp
index 643585fe..347818de 100644
--- a/src/notebooks/notebook.cpp
+++ b/src/notebooks/notebook.cpp
@@ -23,6 +23,7 @@
#include <glibmm/i18n.h>
#include "sharp/string.hpp"
+#include "ignote.hpp"
#include "notemanager.hpp"
#include "notebooks/notebook.hpp"
#include "notebooks/notebookmanager.hpp"
@@ -207,7 +208,7 @@ namespace notebooks {
bool Notebook::add_note(const Note::Ptr & note)
{
- NotebookManager::obj().move_note_to_notebook(note, shared_from_this());
+ IGnote::obj().notebook_manager().move_note_to_notebook(note, shared_from_this());
return true;
}
diff --git a/src/notebooks/notebookapplicationaddin.cpp b/src/notebooks/notebookapplicationaddin.cpp
index 23974682..29e7eed2 100644
--- a/src/notebooks/notebookapplicationaddin.cpp
+++ b/src/notebooks/notebookapplicationaddin.cpp
@@ -100,7 +100,8 @@ namespace gnote {
void NotebookApplicationAddin::on_tag_added(const NoteBase & note, const Tag::Ptr& tag)
{
- if (NotebookManager::obj().is_adding_notebook()) {
+ NotebookManager & manager = IGnote::obj().notebook_manager();
+ if (manager.is_adding_notebook()) {
return;
}
@@ -110,13 +111,11 @@ namespace gnote {
return;
}
- Glib::ustring notebookName =
- sharp::string_substring(tag->name(), megaPrefix.size());
+ Glib::ustring notebookName = sharp::string_substring(tag->name(), megaPrefix.size());
- Notebook::Ptr notebook =
- NotebookManager::obj().get_or_create_notebook (notebookName);
+ Notebook::Ptr notebook = manager.get_or_create_notebook(notebookName);
- NotebookManager::obj().signal_note_added_to_notebook() (static_cast<const Note&>(note), notebook);
+ manager.signal_note_added_to_notebook() (static_cast<const Note&>(note), notebook);
}
@@ -134,13 +133,13 @@ namespace gnote {
Glib::ustring normalizedNotebookName =
sharp::string_substring(normalizedTagName, megaPrefix.size());
- Notebook::Ptr notebook =
- NotebookManager::obj().get_notebook (normalizedNotebookName);
+ NotebookManager & manager = IGnote::obj().notebook_manager();
+ Notebook::Ptr notebook = manager.get_notebook(normalizedNotebookName);
if (!notebook) {
return;
}
- NotebookManager::obj().signal_note_removed_from_notebook() (*std::static_pointer_cast<Note>(note),
notebook);
+ manager.signal_note_removed_from_notebook() (*std::static_pointer_cast<Note>(note), notebook);
}
void NotebookApplicationAddin::on_note_added(const NoteBase::Ptr & note)
diff --git a/src/notebooks/notebookmanager.cpp b/src/notebooks/notebookmanager.cpp
index a3469f66..06e8cc7c 100644
--- a/src/notebooks/notebookmanager.cpp
+++ b/src/notebooks/notebookmanager.cpp
@@ -76,7 +76,7 @@ namespace gnote {
load_notebooks ();
- }
+ }
Notebook::Ptr NotebookManager::get_notebook(const Glib::ustring & notebookName) const
@@ -322,7 +322,7 @@ namespace gnote {
if (response != Gtk::RESPONSE_OK)
return Notebook::Ptr();
- Notebook::Ptr notebook = obj().get_or_create_notebook (notebookName);
+ Notebook::Ptr notebook = IGnote::obj().notebook_manager().get_or_create_notebook (notebookName);
if (!notebook) {
DBG_OUT ("Could not create notebook: %s", notebookName.c_str());
}
@@ -334,7 +334,7 @@ namespace gnote {
// Move all the specified notesToAdd into the new notebook
for(Note::List::const_iterator iter = notesToAdd.begin();
iter != notesToAdd.end(); ++iter) {
- obj().move_note_to_notebook (*iter, notebook);
+ IGnote::obj().notebook_manager().move_note_to_notebook (*iter, notebook);
}
}
}
@@ -372,11 +372,11 @@ namespace gnote {
// Grab the template note before removing all the notebook tags
Note::Ptr templateNote = notebook->get_template_note ();
- obj().delete_notebook (notebook);
+ IGnote::obj().notebook_manager().delete_notebook(notebook);
// Delete the template note
if (templateNote) {
- obj().note_manager().delete_note(templateNote);
+ IGnote::obj().notebook_manager().note_manager().delete_note(templateNote);
}
}
diff --git a/src/notebooks/notebookmanager.hpp b/src/notebooks/notebookmanager.hpp
index 96319ee2..8dd84a2b 100644
--- a/src/notebooks/notebookmanager.hpp
+++ b/src/notebooks/notebookmanager.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2012-2015,2017 Aurimas Cernius
+ * Copyright (C) 2012-2015,2017,2019 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -33,14 +33,12 @@
#include "notebooks/notebook.hpp"
#include "note.hpp"
#include "tag.hpp"
-#include "base/singleton.hpp"
namespace gnote {
namespace notebooks {
class NotebookManager
- : public base::Singleton<NotebookManager>
{
public:
typedef sigc::signal<void, const Note &, const Notebook::Ptr &> NotebookEventHandler;
diff --git a/src/notebooks/notebookmenuitem.cpp b/src/notebooks/notebookmenuitem.cpp
index bfbd89b2..9a645830 100644
--- a/src/notebooks/notebookmenuitem.cpp
+++ b/src/notebooks/notebookmenuitem.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010,2013,2015 Aurimas Cernius
+ * Copyright (C) 2010,2013,2015,2019 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -24,6 +24,7 @@
#include "notebooks/notebookmenuitem.hpp"
#include "notebooks/notebookmanager.hpp"
+#include "ignote.hpp"
@@ -45,7 +46,7 @@ namespace gnote {
return;
}
- NotebookManager::obj().move_note_to_notebook(m_note, m_notebook);
+ IGnote::obj().notebook_manager().move_note_to_notebook(m_note, m_notebook);
}
// the menu item is comparable.
diff --git a/src/notebooks/notebooknoteaddin.cpp b/src/notebooks/notebooknoteaddin.cpp
index ada1aaa3..83a315b1 100644
--- a/src/notebooks/notebooknoteaddin.cpp
+++ b/src/notebooks/notebooknoteaddin.cpp
@@ -29,6 +29,7 @@
#include "debug.hpp"
#include "iactionmanager.hpp"
#include "iconmanager.hpp"
+#include "ignote.hpp"
#include "tag.hpp"
#include "notemanagerbase.hpp"
#include "notewindow.hpp"
@@ -74,7 +75,7 @@ namespace notebooks {
auto note_win = get_window();
note_win->signal_foregrounded.connect(sigc::mem_fun(*this,
&NotebookNoteAddin::on_note_window_foregrounded));
note_win->signal_backgrounded.connect(sigc::mem_fun(*this,
&NotebookNoteAddin::on_note_window_backgrounded));
- NotebookManager::obj().signal_notebook_list_changed
+ IGnote::obj().notebook_manager().signal_notebook_list_changed
.connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_notebooks_changed));
}
@@ -84,7 +85,7 @@ namespace notebooks {
EmbeddableWidgetHost *host = get_window()->host();
m_new_notebook_cid = host->find_action("new-notebook")->signal_activate()
.connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_new_notebook_menu_item));
- Notebook::Ptr current_notebook = NotebookManager::obj().get_notebook_from_note(get_note());
+ Notebook::Ptr current_notebook = IGnote::obj().notebook_manager().get_notebook_from_note(get_note());
Glib::ustring name;
if(current_notebook) {
name = current_notebook->get_name();
@@ -123,8 +124,7 @@ namespace notebooks {
{
Note::List noteList;
noteList.push_back(get_note());
- NotebookManager::obj().prompt_create_new_notebook(
- dynamic_cast<Gtk::Window*>(get_window()->host()), noteList);
+ NotebookManager::prompt_create_new_notebook(dynamic_cast<Gtk::Window*>(get_window()->host()), noteList);
get_window()->signal_popover_widgets_changed();
}
@@ -135,9 +135,9 @@ namespace notebooks {
Glib::ustring name = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(state).get();
Notebook::Ptr notebook;
if(name.size()) {
- notebook = NotebookManager::obj().get_notebook(name);
+ notebook = IGnote::obj().notebook_manager().get_notebook(name);
}
- NotebookManager::obj().move_note_to_notebook(get_note(), notebook);
+ IGnote::obj().notebook_manager().move_note_to_notebook(get_note(), notebook);
}
@@ -173,7 +173,7 @@ namespace notebooks {
std::vector<Gtk::ModelButton*> NotebookNoteAddin::get_notebook_menu_items() const
{
std::vector<Gtk::ModelButton*> items;
- Glib::RefPtr<Gtk::TreeModel> model = NotebookManager::obj().get_notebooks();
+ Glib::RefPtr<Gtk::TreeModel> model = IGnote::obj().notebook_manager().get_notebooks();
Gtk::TreeIter iter;
iter = model->children().begin();
diff --git a/src/notebooks/specialnotebooks.cpp b/src/notebooks/specialnotebooks.cpp
index 8ffed7f0..c7934b7e 100644
--- a/src/notebooks/specialnotebooks.cpp
+++ b/src/notebooks/specialnotebooks.cpp
@@ -84,7 +84,7 @@ Glib::ustring UnfiledNotesNotebook::get_normalized_name() const
bool UnfiledNotesNotebook::contains_note(const Note::Ptr & note, bool include_system)
{
- bool contains = !notebooks::NotebookManager::obj().get_notebook_from_note(note);
+ bool contains = !IGnote::obj().notebook_manager().get_notebook_from_note(note);
if(!contains || include_system) {
return contains;
}
@@ -93,7 +93,7 @@ bool UnfiledNotesNotebook::contains_note(const Note::Ptr & note, bool include_sy
bool UnfiledNotesNotebook::add_note(const Note::Ptr & note)
{
- NotebookManager::obj().move_note_to_notebook(note, Notebook::Ptr());
+ IGnote::obj().notebook_manager().move_note_to_notebook(note, Notebook::Ptr());
return true;
}
diff --git a/src/notemanagerbase.cpp b/src/notemanagerbase.cpp
index d6f40282..be76fa92 100644
--- a/src/notemanagerbase.cpp
+++ b/src/notemanagerbase.cpp
@@ -434,7 +434,7 @@ NoteBase::Ptr NoteManagerBase::find_template_note() const
auto notes = template_tag->get_notes();
for(NoteBase *iter : notes) {
NoteBase::Ptr note = iter->shared_from_this();
- if(!notebooks::NotebookManager::obj().get_notebook_from_note(note)) {
+ if(!IGnote::obj().notebook_manager().get_notebook_from_note(note)) {
template_note = note;
break;
}
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 1658e983..abfc23b0 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -190,7 +190,7 @@ namespace gnote {
important_action->set_state(Glib::Variant<bool>::create(m_note.is_pinned()));
m_important_note_slot = important_action->signal_change_state()
.connect(sigc::mem_fun(*this, &NoteWindow::on_pin_button_clicked));
- notebooks::NotebookManager::obj().signal_note_pin_status_changed
+ IGnote::obj().notebook_manager().signal_note_pin_status_changed
.connect(sigc::mem_fun(*this, &NoteWindow::on_pin_status_changed));
}
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index 02860c9a..2c5f2589 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -97,11 +97,12 @@ SearchNotesWidget::SearchNotesWidget(NoteManager & m)
// Watch when notes are added to notebooks so the search
// results will be updated immediately instead of waiting
// until the note's queue_save () kicks in.
- notebooks::NotebookManager::obj().signal_note_added_to_notebook()
+ notebooks::NotebookManager & notebook_manager = IGnote::obj().notebook_manager();
+ notebook_manager.signal_note_added_to_notebook()
.connect(sigc::mem_fun(*this, &SearchNotesWidget::on_note_added_to_notebook));
- notebooks::NotebookManager::obj().signal_note_removed_from_notebook()
+ notebook_manager.signal_note_removed_from_notebook()
.connect(sigc::mem_fun(*this, &SearchNotesWidget::on_note_removed_from_notebook));
- notebooks::NotebookManager::obj().signal_note_pin_status_changed
+ notebook_manager.signal_note_pin_status_changed
.connect(sigc::mem_fun(*this, &SearchNotesWidget::on_note_pin_status_changed));
Glib::RefPtr<Gio::Settings> settings =
IGnote::obj().preferences().get_schema_settings(Preferences::SCHEMA_GNOTE);
@@ -213,10 +214,7 @@ void SearchNotesWidget::restore_matches_window()
Gtk::Widget *SearchNotesWidget::make_notebooks_pane()
{
- m_notebooksTree = Gtk::manage(
- new notebooks::NotebooksTreeView(m_manager,
- notebooks::NotebookManager::obj()
- .get_notebooks_with_special_items()));
+ m_notebooksTree = Gtk::manage(new notebooks::NotebooksTreeView(m_manager,
IGnote::obj().notebook_manager().get_notebooks_with_special_items()));
m_notebooksTree->get_selection()->set_mode(Gtk::SELECTION_SINGLE);
m_notebooksTree->set_headers_visible(true);
@@ -333,25 +331,25 @@ void SearchNotesWidget::notebook_text_cell_data_func(Gtk::CellRenderer * rendere
void SearchNotesWidget::on_notebook_row_edited(const Glib::ustring& /*tree_path*/,
const Glib::ustring& new_text)
{
- if(notebooks::NotebookManager::obj().notebook_exists(new_text) || new_text == "") {
+ notebooks::NotebookManager & notebook_manager = IGnote::obj().notebook_manager();
+ if(notebook_manager.notebook_exists(new_text) || new_text == "") {
return;
}
notebooks::Notebook::Ptr old_notebook = this->get_selected_notebook();
if(std::dynamic_pointer_cast<notebooks::SpecialNotebook>(old_notebook)) {
return;
}
- notebooks::Notebook::Ptr new_notebook = notebooks::NotebookManager::obj()
- .get_or_create_notebook(new_text);
+ notebooks::Notebook::Ptr new_notebook = notebook_manager.get_or_create_notebook(new_text);
DBG_OUT("Renaming notebook '{%s}' to '{%s}'", old_notebook->get_name().c_str(),
new_text.c_str());
auto notes = old_notebook->get_tag()->get_notes();
for(NoteBase *note : notes) {
- notebooks::NotebookManager::obj().move_note_to_notebook(
+ notebook_manager.move_note_to_notebook(
std::static_pointer_cast<Note>(note->shared_from_this()), new_notebook);
}
- notebooks::NotebookManager::obj().delete_notebook(old_notebook);
+ notebook_manager.delete_notebook(old_notebook);
Gtk::TreeIter iter;
- if(notebooks::NotebookManager::obj().get_notebook_iter(new_notebook, iter)) {
+ if(notebook_manager.get_notebook_iter(new_notebook, iter)) {
m_notebooksTree->get_selection()->select(iter);
m_notebooksTree->set_cursor(m_notebooksTree->get_model()->get_path(iter));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]