[gnote] Add method get_active_window to Gnote



commit 7ed23a044fc70b25b4498870864ce10eb0b79470
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Fri Oct 19 23:52:35 2012 +0300

    Add method get_active_window to Gnote
    
    Reuse it in on_new_note_app_action.

 src/gnote.cpp |   20 +++++++++++++++-----
 src/gnote.hpp |    1 +
 2 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/src/gnote.cpp b/src/gnote.cpp
index dc98548..d2907a7 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -503,18 +503,28 @@ namespace gnote {
   }
 
 
-  void Gnote::on_new_note_app_action(const Glib::VariantBase&)
+  NoteRecentChanges *Gnote::get_active_window()
   {
     std::vector<Gtk::Window*> windows = Gtk::Window::list_toplevels();
     for(std::vector<Gtk::Window*>::iterator iter = windows.begin(); iter != windows.end(); ++iter) {
       if((*iter)->property_is_active()) {
-        NoteRecentChanges *rc = dynamic_cast<NoteRecentChanges*>(*iter);
-        rc->new_note();
-        return;
+        return dynamic_cast<NoteRecentChanges*>(*iter);
       }
     }
 
-    get_main_window()->new_note();
+    return NULL;
+  }
+
+
+  void Gnote::on_new_note_app_action(const Glib::VariantBase&)
+  {
+    NoteRecentChanges *rc = get_active_window();
+    if(rc) {
+      rc->new_note();
+    }
+    else {
+      get_main_window()->new_note();
+    }
   }
 
 
diff --git a/src/gnote.hpp b/src/gnote.hpp
index 2d205c6..00bc18e 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -186,6 +186,7 @@ private:
   void make_app_menu();
   void on_new_window_action(const Glib::VariantBase&);
   void on_new_note_app_action(const Glib::VariantBase&);
+  NoteRecentChanges *get_active_window();
 
   NoteManager *m_manager;
   IKeybinder  *m_keybinder;



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