[gnote/gnome-3-20] Make --search always show main window in search mode



commit d66a166df8f1576bf730828095197b34069892b5
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Wed Aug 17 22:51:06 2016 +0300

    Make --search always show main window in search mode
    
    Fixes Bug 769906.

 src/dbus/remotecontrol.cpp |    4 ++--
 src/gnote.cpp              |   43 +++++++++++++++++++++++++++++++++++++++----
 src/gnote.hpp              |    2 +-
 src/ignote.hpp             |    4 ++--
 4 files changed, 44 insertions(+), 9 deletions(-)
---
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index 995df82..0464381 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2014 Aurimas Cernius
+ * Copyright (C) 2011-2014,2016 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -137,7 +137,7 @@ namespace gnote {
 
   void RemoteControl::DisplaySearch()
   {
-    IGnote::obj().open_search_all();
+    IGnote::obj().open_search_all().present();
   }
 
 
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 52d90d1..473533b 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -365,11 +365,46 @@ namespace gnote {
     return new_main_window();
   }
 
-  void Gnote::open_search_all()
+  MainWindow & Gnote::open_search_all()
   {
-    MainWindow & main_window = get_main_window();
-    main_window.present_search();
-    main_window.present();
+    // if active window is search, just show it
+    MainWindow *rc = get_active_window();
+    if(rc) {
+      if(rc->is_search()) {
+        return *rc;
+      }
+    }
+
+    // present already open search window, if there is one
+    std::vector<Gtk::Window*> windows = Gtk::Window::list_toplevels();
+    int main_windows = 0;
+    for(std::vector<Gtk::Window*>::iterator iter = windows.begin();
+        iter != windows.end(); ++iter) {
+      auto win = dynamic_cast<MainWindow*>(*iter);
+      if(win) {
+        ++main_windows;
+        if(win->is_search()) {
+          return *win;
+        }
+        else if(rc == NULL) {
+          rc = win;
+        }
+      }
+    }
+
+    // if notes are opened in new window by default, then open new window for search
+    // otherwise switch the only window to search
+    // if there is more than one window open, open new for search, since we can't decide which one to switch
+    bool new_window = Preferences::obj()
+      .get_schema_settings(Preferences::SCHEMA_GNOTE)->get_boolean(Preferences::OPEN_NOTES_IN_NEW_WINDOW);
+    if(main_windows > 1 || new_window) {
+      MainWindow & main_window = new_main_window();
+      main_window.present_search();
+      return main_window;
+    }
+
+    rc->present_search();
+    return *rc;
   }
 
   void Gnote::open_note_sync_window(const Glib::VariantBase&)
diff --git a/src/gnote.hpp b/src/gnote.hpp
index fd3a8b5..64f836c 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -126,7 +126,7 @@ public:
   virtual MainWindow & new_main_window() override;
   virtual MainWindow & get_main_window() override;
   virtual MainWindow & get_window_for_note() override;
-  virtual void open_search_all() override;
+  virtual MainWindow & open_search_all() override;
   void open_note_sync_window(const Glib::VariantBase&);
 
   bool is_background() const
diff --git a/src/ignote.hpp b/src/ignote.hpp
index 989d0ea..ee36dc4 100644
--- a/src/ignote.hpp
+++ b/src/ignote.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (C) 2013,2016 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -39,7 +39,7 @@ public:
   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;
+  virtual MainWindow & open_search_all() = 0;
 
   sigc::signal<void> signal_quit;
 };


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