[gnote] Make IGnote return references to main window



commit 6063c2a47cedd4e6c9d5467bf34377d15ef6a733
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Sun Feb 10 22:30:58 2013 +0200

    Make IGnote return references to main window

 src/addins/backlinks/backlinkmenuitem.cpp |    2 +-
 src/dbus/remotecontrol.cpp                |   12 ++++----
 src/gnote.cpp                             |   44 ++++++++++++++--------------
 src/gnote.hpp                             |    6 ++--
 src/ignote.hpp                            |    6 ++--
 src/noterenamedialog.cpp                  |    2 +-
 src/recentchanges.cpp                     |    6 ++--
 src/synchronization/syncdialog.cpp        |    6 ++--
 src/tray.cpp                              |    6 ++--
 src/watchers.cpp                          |    2 +-
 10 files changed, 46 insertions(+), 46 deletions(-)
---
diff --git a/src/addins/backlinks/backlinkmenuitem.cpp b/src/addins/backlinks/backlinkmenuitem.cpp
index e3aee08..596042b 100644
--- a/src/addins/backlinks/backlinkmenuitem.cpp
+++ b/src/addins/backlinks/backlinkmenuitem.cpp
@@ -58,7 +58,7 @@ void BacklinkMenuItem::on_activate()
   
   gnote::MainWindow *window = gnote::MainWindow::get_owning(*this);
   if(!window) {
-    window = gnote::IGnote::obj().new_main_window();
+    window = &gnote::IGnote::obj().new_main_window();
   }
 
   window->present_note(m_note);
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index ca2481b..efdb5c5 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.cpp
@@ -153,9 +153,9 @@ namespace gnote {
 
   void RemoteControl::DisplaySearchWithText(const std::string& search_text)
   {
-    MainWindow *recent_changes = IGnote::obj().get_main_window();
-    recent_changes->set_search_text(search_text);
-    recent_changes->present();
+    MainWindow & recent_changes = IGnote::obj().get_main_window();
+    recent_changes.set_search_text(search_text);
+    recent_changes.present();
   }
 
 
@@ -408,9 +408,9 @@ void RemoteControl::on_note_saved(const Note::Ptr & note)
 
 void RemoteControl::present_note(const Note::Ptr & note)
 {
-    MainWindow *window = IGnote::obj().get_window_for_note();
-    window->present_note(note);
-    window->present();
+    MainWindow & window = IGnote::obj().get_window_for_note();
+    window.present_note(note);
+    window.present();
 }
 
 
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 8a7b972..7917eda 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -126,7 +126,7 @@ namespace gnote {
       cmd_line.execute();
     }
     else {
-      new_main_window()->present();
+      new_main_window().present();
     }
 
     return 0;
@@ -389,30 +389,30 @@ namespace gnote {
     about.set_documenters(documenters);
     about.set_translator_credits(translators);
 //      about.set_icon_name("gnote");
-    MainWindow *recent_changes = get_main_window();
-    if(recent_changes && recent_changes->get_visible()) {
-      about.set_transient_for(*recent_changes);
-      recent_changes->present();
+    MainWindow & recent_changes = get_main_window();
+    if(recent_changes.get_visible()) {
+      about.set_transient_for(recent_changes);
+      recent_changes.present();
     }
     about.run();
   }
 
-  MainWindow *Gnote::new_main_window()
+  MainWindow & Gnote::new_main_window()
   {
     NoteRecentChanges *win = new NoteRecentChanges(default_note_manager());
     win->signal_hide().connect(sigc::mem_fun(*this, &Gnote::on_main_window_closed));
     add_window(*win);
-    return win;
+    return *win;
   }
 
-  MainWindow *Gnote::get_main_window()
+  MainWindow & Gnote::get_main_window()
   {
     std::vector<Gtk::Window*> windows = Gtk::Window::list_toplevels();
     for(std::vector<Gtk::Window*>::iterator iter = windows.begin();
         iter != windows.end(); ++iter) {
       MainWindow *rc = dynamic_cast<MainWindow*>(*iter);
       if(rc) {
-        return rc;
+        return *rc;
       }
     }
 
@@ -427,7 +427,7 @@ namespace gnote {
     }
   }
 
-  MainWindow *Gnote::get_window_for_note()
+  MainWindow & Gnote::get_window_for_note()
   {
     std::vector<Gtk::Window*> windows = Gtk::Window::list_toplevels();
     MainWindow *window = NULL;
@@ -436,13 +436,13 @@ namespace gnote {
       if(rc) {
         window = rc;
         if(rc->get_visible()) {
-          return rc;
+          return *rc;
         }
       }
     }
 
     if(window) {
-      return window;
+      return *window;
     }
 
     return new_main_window();
@@ -450,9 +450,9 @@ namespace gnote {
 
   void Gnote::open_search_all()
   {
-    MainWindow *main_window = get_main_window();
-    main_window->present_search();
-    main_window->present();
+    MainWindow & main_window = get_main_window();
+    main_window.present_search();
+    main_window.present();
   }
 
   void Gnote::open_note_sync_window(const Glib::VariantBase&)
@@ -500,7 +500,7 @@ namespace gnote {
 
   void Gnote::on_new_window_action(const Glib::VariantBase&)
   {
-    new_main_window()->present();
+    new_main_window().present();
   }
 
 
@@ -524,18 +524,18 @@ namespace gnote {
       rc->new_note();
     }
     else {
-      MainWindow *recent_changes = get_main_window();
-      recent_changes->new_note();
-      recent_changes->present();
+      MainWindow & recent_changes = get_main_window();
+      recent_changes.new_note();
+      recent_changes.present();
     }
   }
 
 
   void Gnote::open_note(const Note::Ptr & note)
   {
-    MainWindow *main_window = get_window_for_note();
-    main_window->present_note(note);
-    main_window->present();
+    MainWindow & main_window = get_window_for_note();
+    main_window.present_note(note);
+    main_window.present();
   }
 
 
diff --git a/src/gnote.hpp b/src/gnote.hpp
index 2273ed4..5751590 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -126,9 +126,9 @@ public:
   void on_show_preferences_action(const Glib::VariantBase&);
   void on_show_help_action(const Glib::VariantBase&);
   void on_show_about_action(const Glib::VariantBase&);
-  virtual MainWindow *new_main_window();
-  virtual MainWindow *get_main_window();
-  virtual MainWindow *get_window_for_note();
+  virtual MainWindow & new_main_window();
+  virtual MainWindow & get_main_window();
+  virtual MainWindow & get_window_for_note();
   virtual void open_search_all();
   void open_note_sync_window(const Glib::VariantBase&);
 
diff --git a/src/ignote.hpp b/src/ignote.hpp
index 417ff22..989d0ea 100644
--- a/src/ignote.hpp
+++ b/src/ignote.hpp
@@ -35,9 +35,9 @@ public:
   static std::string old_note_dir();
 
   virtual ~IGnote();
-  virtual MainWindow *get_main_window() = 0;
-  virtual MainWindow *get_window_for_note() = 0; //TODO change to return reference
-  virtual MainWindow *new_main_window() = 0; //TODO change to return reference
+  virtual MainWindow & get_main_window() = 0;
+  virtual MainWindow & get_window_for_note() = 0;
+  virtual MainWindow & new_main_window() = 0;
   virtual void open_note(const Note::Ptr & note) = 0;
   virtual void open_search_all() = 0;
 
diff --git a/src/noterenamedialog.cpp b/src/noterenamedialog.cpp
index 8df2c26..cd1bff2 100644
--- a/src/noterenamedialog.cpp
+++ b/src/noterenamedialog.cpp
@@ -366,7 +366,7 @@ void NoteRenameDialog::on_notes_view_row_activated(
     window = MainWindow::get_owning(*parent);
   }
   if(!window) {
-    window = IGnote::obj().new_main_window();
+    window = &IGnote::obj().new_main_window();
   }
 
   window->present_note(note);
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 6fb69de..933b0c7 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -145,9 +145,9 @@ namespace gnote {
 
   void NoteRecentChanges::on_open_note_new_window(const Note::Ptr & note)
   {
-    MainWindow *window = IGnote::obj().new_main_window();
-    window->present();
-    window->present_note(note);
+    MainWindow & window = IGnote::obj().new_main_window();
+    window.present();
+    window.present_note(note);
   }
 
   void NoteRecentChanges::on_delete_note()
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index 43cf820..faa1535 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -733,9 +733,9 @@ void SyncDialog::rename_note(const Note::Ptr & note, const std::string & newTitl
 
 void SyncDialog::present_note(const Note::Ptr & note)
 {
-  MainWindow *window = IGnote::obj().get_window_for_note();
-  window->present_note(note);
-  window->present();
+  MainWindow & window = IGnote::obj().get_window_for_note();
+  window.present_note(note);
+  window.present();
 }
 
 }
diff --git a/src/tray.cpp b/src/tray.cpp
index f25f28c..8346b4a 100644
--- a/src/tray.cpp
+++ b/src/tray.cpp
@@ -93,9 +93,9 @@ namespace gnote {
   {
     if(!m_inhibit_activate) {
       if(m_note) {
-        MainWindow *window = IGnote::obj().get_window_for_note();
-        window->present_note(m_note);
-        window->present();
+        MainWindow & window = IGnote::obj().get_window_for_note();
+        window.present_note(m_note);
+        window.present();
       }
     }
   }
diff --git a/src/watchers.cpp b/src/watchers.cpp
index d1b6929..2a6e0fd 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -913,7 +913,7 @@ namespace gnote {
       DBG_OUT ("Opening note '%s' on click...", link_name.c_str());
       MainWindow *window = MainWindow::get_owning(const_cast<NoteEditor&>(editor));
       if(!window) {
-        window = IGnote::obj().new_main_window();
+        window = &IGnote::obj().new_main_window();
       }
       window->present_note(link);
       window->present();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]