[gnote] Refactor window creation code
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Refactor window creation code
- Date: Tue, 8 Sep 2015 18:18:58 +0000 (UTC)
commit 38d34a2a4fa6f430493c5e05a4e183430524100e
Author: Aurimas Černius <aurisc4 gmail com>
Date: Tue Sep 8 15:04:21 2015 +0300
Refactor window creation code
To allow note window destruction in the future.
src/mainwindow.cpp | 6 ++++--
src/note.cpp | 4 ++--
src/note.hpp | 8 ++++++--
src/noteaddin.cpp | 4 ++--
src/notewindow.cpp | 6 ++++--
src/recentchanges.cpp | 2 +-
6 files changed, 19 insertions(+), 11 deletions(-)
---
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 32b5298..22bec6e 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -53,7 +53,7 @@ void MainWindow::present_in(MainWindow & win, const Note::Ptr & note)
MainWindow *MainWindow::present_active(const Note::Ptr & note)
{
- if(note && note->get_window()->host()
+ if(note && note->has_window() && note->get_window()->host()
&& note->get_window()->host()->is_foreground(*note->get_window())) {
MainWindow *win = dynamic_cast<MainWindow*>(note->get_window()->host());
win->present();
@@ -90,7 +90,9 @@ MainWindow *MainWindow::present_default(const Note::Ptr & note)
}
Glib::RefPtr<Gio::Settings> settings = Preferences::obj().get_schema_settings(Preferences::SCHEMA_GNOTE);
if(false == settings->get_boolean(Preferences::OPEN_NOTES_IN_NEW_WINDOW)) {
- win = dynamic_cast<MainWindow*>(note->get_window()->host());
+ if (note->has_window()) {
+ win = dynamic_cast<MainWindow*>(note->get_window()->host());
+ }
}
if(!win) {
win = &IGnote::obj().new_main_window();
diff --git a/src/note.cpp b/src/note.cpp
index 737e3fd..0c4aee7 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010-2014 Aurimas Cernius
+ * Copyright (C) 2010-2015 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -733,7 +733,7 @@ namespace gnote {
}
- NoteWindow * Note::get_window()
+ NoteWindow * Note::create_window()
{
if(!m_window) {
m_window = new NoteWindow(*this);
diff --git a/src/note.hpp b/src/note.hpp
index 616c5f8..fc960c1 100644
--- a/src/note.hpp
+++ b/src/note.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011-2014 Aurimas Cernius
+ * Copyright (C) 2011-2015 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -131,7 +131,11 @@ public:
{
return (m_window != NULL);
}
- NoteWindow * get_window();
+ NoteWindow * get_window()
+ {
+ return m_window;
+ }
+ NoteWindow * create_window();
bool is_special() const;
bool is_loaded() const
{
diff --git a/src/noteaddin.cpp b/src/noteaddin.cpp
index a34ffde..c820464 100644
--- a/src/noteaddin.cpp
+++ b/src/noteaddin.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2012-2014 Aurimas Cernius
+ * Copyright (C) 2012-2015 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -135,7 +135,7 @@ namespace gnote {
throw sharp::Exception(_("Plugin is disposing already"));
}
NoteWindow *note_window = m_note->get_window();
- if(!note_window->host()) {
+ if(note_window == NULL || !note_window->host()) {
throw std::runtime_error(_("Window is not embedded"));
}
return dynamic_cast<Gtk::Window*>(note_window->host());
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 94880a1..f18b7cf 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -33,6 +33,7 @@
#include "debug.hpp"
#include "iconmanager.hpp"
+#include "mainwindow.hpp"
#include "note.hpp"
#include "notewindow.hpp"
#include "notemanager.hpp"
@@ -571,7 +572,7 @@ namespace gnote {
m_note.get_buffer()->apply_tag(m_note.get_tag_table()->get_link_tag(), start, end);
}
- host()->embed_widget(*static_pointer_cast<Note>(match)->get_window());
+ MainWindow::present_in(*dynamic_cast<MainWindow*>(host()), static_pointer_cast<Note>(match));
}
void NoteWindow::open_help_activate()
@@ -1094,7 +1095,8 @@ namespace gnote {
m_buffer->apply_tag(m_buffer->note().get_tag_table()->get_link_tag(), start, end);
}
- m_buffer->note().get_window()->host()->embed_widget(*static_pointer_cast<Note>(match)->get_window());
+ MainWindow::present_in(*dynamic_cast<MainWindow*>(m_buffer->note().get_window()->host()),
+ static_pointer_cast<Note>(match));
}
//
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index f087e2e..dd7940a 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -301,7 +301,7 @@ namespace gnote {
void NoteRecentChanges::present_note(const Note::Ptr & note)
{
- embed_widget(*note->get_window());
+ embed_widget(*note->create_window());
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]