[gnote] Do not use singleton IGnote in note and note windows
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Do not use singleton IGnote in note and note windows
- Date: Sun, 8 Dec 2019 21:03:50 +0000 (UTC)
commit 5624dd869cd44b0cccdb82f7d56afb2fa9c4b53f
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun Dec 8 18:49:34 2019 +0200
Do not use singleton IGnote in note and note windows
src/note.cpp | 51 +++++++++++++++++-------------------------------
src/note.hpp | 12 ++++++++----
src/notemanager.cpp | 6 +++---
src/noterenamedialog.cpp | 6 ++++--
src/noterenamedialog.hpp | 7 ++++++-
src/notewindow.cpp | 18 ++++++++---------
src/notewindow.hpp | 10 ++++++----
7 files changed, 54 insertions(+), 56 deletions(-)
---
diff --git a/src/note.cpp b/src/note.cpp
index e2ede68d..3f109f09 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -246,8 +246,9 @@ namespace gnote {
}
}
- Note::Note(NoteData * _data, const Glib::ustring & filepath, NoteManager & _manager)
+ Note::Note(NoteData * _data, const Glib::ustring & filepath, NoteManager & _manager, IGnote & g)
: NoteBase(_data, filepath, _manager)
+ , m_gnote(g)
, m_data(_data)
, m_save_needed(false)
, m_is_deleting(false)
@@ -270,24 +271,10 @@ namespace gnote {
delete m_window;
}
- /// <summary>
- /// Creates a New Note with the given values.
- /// </summary>
- /// <param name="title">
- /// A <see cref="System.String"/>
- /// </param>
- /// <param name="filepath">
- /// A <see cref="System.String"/>
- /// </param>
- /// <param name="manager">
- /// A <see cref="NoteManager"/>
- /// </param>
- /// <returns>
- /// A <see cref="Note"/>
- /// </returns>
Note::Ptr Note::create_new_note(const Glib::ustring & title,
const Glib::ustring & filename,
- NoteManager & manager)
+ NoteManager & manager,
+ IGnote & g)
{
NoteData * note_data = new NoteData(url_from_path(filename));
note_data->title() = title;
@@ -295,12 +282,10 @@ namespace gnote {
note_data->create_date() = date;
note_data->set_change_date(date);
- return Note::Ptr(new Note(note_data, filename, manager));
+ return Note::Ptr(new Note(note_data, filename, manager, g));
}
- Note::Ptr Note::create_existing_note(NoteData *data,
- Glib::ustring filepath,
- NoteManager & manager)
+ Note::Ptr Note::create_existing_note(NoteData *data, Glib::ustring filepath, NoteManager & manager, IGnote
& g)
{
if (!data->change_date().is_valid()) {
sharp::DateTime d(sharp::file_modification_time(filepath));
@@ -315,7 +300,7 @@ namespace gnote {
data->create_date() = d;
}
}
- return Note::Ptr(new Note(data, filepath, manager));
+ return Note::Ptr(new Note(data, filepath, manager, g));
}
void Note::delete_note()
@@ -347,11 +332,11 @@ namespace gnote {
}
- Note::Ptr Note::load(const Glib::ustring & read_file, NoteManager & manager)
+ Note::Ptr Note::load(const Glib::ustring & read_file, NoteManager & manager, IGnote & g)
{
NoteData *data = new NoteData(url_from_path(read_file));
manager.note_archiver().read_file(read_file, *data);
- return create_existing_note(data, read_file, manager);
+ return create_existing_note(data, read_file, manager, g);
}
@@ -552,12 +537,12 @@ namespace gnote {
const Note::Ptr self = std::static_pointer_cast<Note>(shared_from_this());
if (!linking_notes.empty()) {
- Glib::RefPtr<Gio::Settings> settings =
IGnote::obj().preferences().get_schema_settings(Preferences::SCHEMA_GNOTE);
+ Glib::RefPtr<Gio::Settings> settings =
m_gnote.preferences().get_schema_settings(Preferences::SCHEMA_GNOTE);
const NoteRenameBehavior behavior
= static_cast<NoteRenameBehavior>(settings->get_int(Preferences::NOTE_RENAME_BEHAVIOR));
if (NOTE_RENAME_ALWAYS_SHOW_DIALOG == behavior) {
- NoteRenameDialog *dlg = new NoteRenameDialog(linking_notes, old_title, self);
+ NoteRenameDialog *dlg = new NoteRenameDialog(linking_notes, old_title, self, m_gnote);
dlg->signal_response().connect([this, dlg, old_title, self](int response) {
process_rename_link_update_end(response, dlg, old_title, self);
});
@@ -586,7 +571,7 @@ namespace gnote {
NoteRenameDialog *dlg = static_cast<NoteRenameDialog*>(dialog);
const NoteRenameBehavior selected_behavior = dlg->get_selected_behavior();
if(Gtk::RESPONSE_CANCEL != response && NOTE_RENAME_ALWAYS_SHOW_DIALOG != selected_behavior) {
- Glib::RefPtr<Gio::Settings> settings =
IGnote::obj().preferences().get_schema_settings(Preferences::SCHEMA_GNOTE);
+ Glib::RefPtr<Gio::Settings> settings =
m_gnote.preferences().get_schema_settings(Preferences::SCHEMA_GNOTE);
settings->set_int(Preferences::NOTE_RENAME_BEHAVIOR, selected_behavior);
}
@@ -711,7 +696,7 @@ namespace gnote {
{
if(!m_buffer) {
DBG_OUT("Creating buffer for %s", m_data.data().title().c_str());
- m_buffer = NoteBuffer::create(get_tag_table(), *this, IGnote::obj().preferences());
+ m_buffer = NoteBuffer::create(get_tag_table(), *this, m_gnote.preferences());
m_data.set_buffer(m_buffer);
m_buffer->signal_changed().connect(
@@ -732,7 +717,7 @@ namespace gnote {
NoteWindow * Note::create_window()
{
if(!m_window) {
- m_window = new NoteWindow(*this);
+ m_window = new NoteWindow(*this, m_gnote);
m_window->signal_delete_event().connect(
sigc::mem_fun(*this, &Note::on_window_destroyed));
@@ -760,7 +745,7 @@ namespace gnote {
m_note_window_embedded = true;
}
-
IGnote::obj().notebook_manager().active_notes_notebook()->add_note(std::static_pointer_cast<Note>(shared_from_this()));
+
m_gnote.notebook_manager().active_notes_notebook()->add_note(std::static_pointer_cast<Note>(shared_from_this()));
}
void Note::on_note_window_foregrounded()
@@ -781,7 +766,7 @@ namespace gnote {
bool Note::is_pinned() const
{
- Glib::ustring pinned_uris = IGnote::obj().preferences()
+ Glib::ustring pinned_uris = m_gnote.preferences()
.get_schema_settings(Preferences::SCHEMA_GNOTE)->get_string(Preferences::MENU_PINNED_NOTES);
return pinned_uris.find(uri()) != Glib::ustring::npos;
}
@@ -790,7 +775,7 @@ namespace gnote {
void Note::set_pinned(bool pinned) const
{
Glib::ustring new_pinned;
- Glib::RefPtr<Gio::Settings> settings =
IGnote::obj().preferences().get_schema_settings(Preferences::SCHEMA_GNOTE);
+ Glib::RefPtr<Gio::Settings> settings =
m_gnote.preferences().get_schema_settings(Preferences::SCHEMA_GNOTE);
Glib::ustring old_pinned = settings->get_string(Preferences::MENU_PINNED_NOTES);
bool is_currently_pinned = old_pinned.find(uri()) != Glib::ustring::npos;
@@ -810,7 +795,7 @@ namespace gnote {
}
}
settings->set_string(Preferences::MENU_PINNED_NOTES, new_pinned);
- IGnote::obj().notebook_manager().signal_note_pin_status_changed(*this, pinned);
+ m_gnote.notebook_manager().signal_note_pin_status_changed(*this, pinned);
}
void Note::enabled(bool is_enabled)
diff --git a/src/note.hpp b/src/note.hpp
index 2ee3c2ae..548caa94 100644
--- a/src/note.hpp
+++ b/src/note.hpp
@@ -34,6 +34,7 @@
namespace gnote {
+class IGnote;
class NoteManager;
class NoteWindow;
@@ -98,13 +99,15 @@ public:
static Note::Ptr create_new_note(const Glib::ustring & title,
const Glib::ustring & filename,
- NoteManager & manager);
+ NoteManager & manager,
+ IGnote & g);
static Note::Ptr create_existing_note(NoteData *data,
Glib::ustring filepath,
- NoteManager & manager);
+ NoteManager & manager,
+ IGnote & g);
virtual void delete_note() override;
- static Note::Ptr load(const Glib::ustring &, NoteManager &);
+ static Note::Ptr load(const Glib::ustring &, NoteManager &, IGnote &);
virtual void save() override;
virtual void queue_save(ChangeType c) override;
using NoteBase::remove_tag;
@@ -182,7 +185,7 @@ private:
void on_note_window_embedded();
void on_note_window_foregrounded();
- Note(NoteData * data, const Glib::ustring & filepath, NoteManager & manager);
+ Note(NoteData * data, const Glib::ustring & filepath, NoteManager & manager, IGnote & g);
struct ChildWidgetData
{
@@ -196,6 +199,7 @@ private:
Gtk::Widget *widget;
};
+ IGnote & m_gnote;
NoteDataBufferSynchronizer m_data;
bool m_save_needed;
bool m_is_deleting;
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index cd8071ba..55838a35 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -182,7 +182,7 @@ namespace gnote {
for(auto file_path : files) {
try {
- Note::Ptr note = Note::load(file_path, *this);
+ Note::Ptr note = Note::load(file_path, *this, m_gnote);
add_note(note);
}
catch (const std::exception & e) {
@@ -269,7 +269,7 @@ namespace gnote {
NoteBase::Ptr NoteManager::note_load(const Glib::ustring & file_name)
{
- return Note::load(file_name, *this);
+ return Note::load(file_name, *this, m_gnote);
}
@@ -299,7 +299,7 @@ namespace gnote {
NoteBase::Ptr NoteManager::note_create_new(const Glib::ustring & title, const Glib::ustring & file_name)
{
- return Note::create_new_note(title, file_name, *this);
+ return Note::create_new_note(title, file_name, *this, m_gnote);
}
NoteBase::Ptr NoteManager::get_or_create_template_note()
diff --git a/src/noterenamedialog.cpp b/src/noterenamedialog.cpp
index 9e19b377..f60b7625 100644
--- a/src/noterenamedialog.cpp
+++ b/src/noterenamedialog.cpp
@@ -120,10 +120,12 @@ void ModelFiller::operator()(const NoteBase::Ptr & note)
NoteRenameDialog::NoteRenameDialog(const NoteBase::List & notes,
const Glib::ustring & old_title,
- const NoteBase::Ptr & renamed_note)
+ const NoteBase::Ptr & renamed_note,
+ IGnote & g)
: Gtk::Dialog(_("Rename Note Links?"),
*dynamic_cast<Gtk::Window*>(std::static_pointer_cast<Note>(renamed_note)->get_window()->host()),
false)
+ , m_gnote(g)
, m_notes_model(Gtk::ListStore::create(m_model_column_record))
, m_dont_rename_button(_("_Don't Rename Links"), true)
, m_rename_button(_("_Rename Links"), true)
@@ -362,7 +364,7 @@ void NoteRenameDialog::on_notes_view_row_activated(
if (!note)
return;
- MainWindow *window = MainWindow::present_default(IGnote::obj(), std::static_pointer_cast<Note>(note));
+ MainWindow *window = MainWindow::present_default(m_gnote, std::static_pointer_cast<Note>(note));
if(window) {
window->set_search_text(Glib::ustring::compose("\"%1\"", old_title));
window->show_search_bar();
diff --git a/src/noterenamedialog.hpp b/src/noterenamedialog.hpp
index 5f8d85ee..f098b66a 100644
--- a/src/noterenamedialog.hpp
+++ b/src/noterenamedialog.hpp
@@ -32,6 +32,9 @@
namespace gnote {
+class IGnote;
+
+
// Values should match with those in data/gnote.schemas.in
enum NoteRenameBehavior {
NOTE_RENAME_ALWAYS_SHOW_DIALOG = 0,
@@ -79,7 +82,8 @@ public:
NoteRenameDialog(const NoteBase::List & notes,
const Glib::ustring & old_title,
- const NoteBase::Ptr & renamed_note);
+ const NoteBase::Ptr & renamed_note,
+ IGnote & g);
MapPtr get_notes() const;
NoteRenameBehavior get_selected_behavior() const;
@@ -100,6 +104,7 @@ private:
void on_select_all_button_clicked(bool select);
void on_toggle_cell_toggled(const Glib::ustring & p);
+ IGnote & m_gnote;
ModelColumnRecord m_model_column_record;
Glib::RefPtr<Gtk::ListStore> m_notes_model;
Gtk::Button m_dont_rename_button;
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 4a1720ad..39314575 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -51,14 +51,14 @@
namespace gnote {
- Glib::RefPtr<Gio::Icon> NoteWindow::get_icon_pin_active()
+ Glib::RefPtr<Gio::Icon> NoteWindow::get_icon_pin_active(IconManager & icon_manager)
{
- return IGnote::obj().icon_manager().get_icon(IconManager::PIN_ACTIVE, 22);
+ return icon_manager.get_icon(IconManager::PIN_ACTIVE, 22);
}
- Glib::RefPtr<Gio::Icon> NoteWindow::get_icon_pin_down()
+ Glib::RefPtr<Gio::Icon> NoteWindow::get_icon_pin_down(IconManager & icon_manager)
{
- return IGnote::obj().icon_manager().get_icon(IconManager::PIN_DOWN, 22);
+ return icon_manager.get_icon(IconManager::PIN_DOWN, 22);
}
@@ -91,8 +91,9 @@ namespace gnote {
- NoteWindow::NoteWindow(Note & note)
+ NoteWindow::NoteWindow(Note & note, IGnote & g)
: m_note(note)
+ , m_gnote(g)
, m_name(note.get_title())
, m_height(450)
, m_width(600)
@@ -116,7 +117,7 @@ namespace gnote {
m_template_widget = make_template_bar();
// The main editor widget
- m_editor = manage(new NoteEditor(note.get_buffer(), IGnote::obj().preferences()));
+ m_editor = manage(new NoteEditor(note.get_buffer(), g.preferences()));
m_editor->signal_populate_popup().connect(sigc::mem_fun(*this, &NoteWindow::on_populate_popup));
m_editor->show();
@@ -190,7 +191,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));
- IGnote::obj().notebook_manager().signal_note_pin_status_changed
+ m_gnote.notebook_manager().signal_note_pin_status_changed
.connect(sigc::mem_fun(*this, &NoteWindow::on_pin_status_changed));
}
@@ -225,8 +226,7 @@ namespace gnote {
void NoteWindow::hint_size(int & width, int & height)
{
- if (IGnote::obj().preferences().get_schema_settings(Preferences::SCHEMA_GNOTE)->get_boolean(
- Preferences::AUTOSIZE_NOTE_WINDOW)) {
+
if(m_gnote.preferences().get_schema_settings(Preferences::SCHEMA_GNOTE)->get_boolean(Preferences::AUTOSIZE_NOTE_WINDOW))
{
width = m_width;
height = m_height;
}
diff --git a/src/notewindow.hpp b/src/notewindow.hpp
index cd1d73e8..df5f4f18 100644
--- a/src/notewindow.hpp
+++ b/src/notewindow.hpp
@@ -43,7 +43,8 @@
namespace gnote {
- class Note;
+class IconManager;
+
class NoteTextMenu
: public Gtk::PopoverMenu
@@ -132,7 +133,7 @@ class NoteWindow
, public HasActions
{
public:
- NoteWindow(Note &);
+ NoteWindow(Note &, IGnote &);
~NoteWindow();
virtual Glib::ustring get_name() const override;
@@ -222,8 +223,8 @@ public:
return m_enabled;
}
private:
- static Glib::RefPtr<Gio::Icon> get_icon_pin_active();
- static Glib::RefPtr<Gio::Icon> get_icon_pin_down();
+ static Glib::RefPtr<Gio::Icon> get_icon_pin_active(IconManager & icon_manager);
+ static Glib::RefPtr<Gio::Icon> get_icon_pin_down(IconManager & icon_manager);
void on_delete_button_clicked(const Glib::VariantBase&);
void on_selection_mark_set(const Gtk::TextIter&, const Glib::RefPtr<Gtk::TextMark>&);
@@ -247,6 +248,7 @@ private:
void on_text_button_clicked();
Note & m_note;
+ IGnote & m_gnote;
Glib::ustring m_name;
int m_height;
int m_width;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]