[gnote] Add close_on_escape support for main window



commit bcd267e1c86da32df80d82c1a8de635ec652bb7d
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Thu Jun 20 16:20:24 2013 +0300

    Add close_on_escape support for main window
    
    Use it when opening all notes in new window.
    Part of Bug 700458.

 src/mainwindow.cpp    |    1 +
 src/mainwindow.hpp    |   11 +++++++++++
 src/note.cpp          |    6 ++++++
 src/recentchanges.cpp |   12 ++++++++++--
 src/recentchanges.hpp |    1 +
 src/watchers.cpp      |    1 +
 6 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 2db59f6..7fd78d0 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -41,6 +41,7 @@ MainWindow *MainWindow::get_owning(Gtk::Widget & widget)
 
 MainWindow::MainWindow(const std::string & title)
   : utils::ForcedPresentWindow(title)
+  , m_close_on_esc(false)
 {
 }
 
diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp
index a273146..45dbd01 100644
--- a/src/mainwindow.hpp
+++ b/src/mainwindow.hpp
@@ -43,6 +43,17 @@ public:
   virtual void present_search() = 0;
   virtual void new_note() = 0;
   virtual void close_window() = 0;
+
+  void close_on_escape(bool close)
+    {
+      m_close_on_esc = close;
+    }
+  bool close_on_escape() const
+    {
+      return m_close_on_esc;
+    }
+private:
+  bool m_close_on_esc;
 };
 
 }
diff --git a/src/note.cpp b/src/note.cpp
index f323e7e..479f98d 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -37,6 +37,7 @@
 #include <gtkmm/button.h>
 #include <gtkmm/stock.h>
 
+#include "mainwindow.hpp"
 #include "note.hpp"
 #include "notemanager.hpp"
 #include "noterenamedialog.hpp"
@@ -378,7 +379,12 @@ namespace gnote {
 
     if (m_window) {
       if(m_window->host()) {
+        MainWindow *win = dynamic_cast<MainWindow*>(m_window->host());
+        bool close_host = win ? win->close_on_escape() : false;
         m_window->host()->unembed_widget(*m_window);
+        if(close_host) {
+          win->close_window();
+        }
       }
       delete m_window; 
       m_window = NULL;
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 49763a3..05a3e1b 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -139,7 +139,7 @@ namespace gnote {
     image->property_margin() = icon_margin;
     m_all_notes_button->set_image(*image);
     m_all_notes_button->set_tooltip_text(_("All Notes"));
-    m_all_notes_button->signal_clicked().connect(sigc::mem_fun(*this, &NoteRecentChanges::present_search));
+    m_all_notes_button->signal_clicked().connect(sigc::mem_fun(*this, 
&NoteRecentChanges::on_all_notes_button_clicked));
     m_all_notes_button->show_all();
     left_box->attach(*m_all_notes_button, 0, 0, 1, 1);
 
@@ -327,6 +327,7 @@ namespace gnote {
     MainWindow & window = IGnote::obj().new_main_window();
     window.present();
     window.present_note(note);
+    window.close_on_escape(true);
   }
 
   void NoteRecentChanges::on_delete_note()
@@ -373,7 +374,8 @@ namespace gnote {
         m_search_button.set_active(false);
       }
       // Allow Escape to close the window
-      else if(&m_search_notes_widget == dynamic_cast<SearchNotesWidget*>(currently_embedded())) {
+      else if(close_on_escape()
+              || &m_search_notes_widget == dynamic_cast<SearchNotesWidget*>(currently_embedded())) {
         close_window();
       }
       else {
@@ -658,6 +660,12 @@ namespace gnote {
     }
   }
 
+  void NoteRecentChanges::on_all_notes_button_clicked()
+  {
+    close_on_escape(false);  // intentional switch to search, user probably want to work more with this 
window
+    present_search();
+  }
+
   void NoteRecentChanges::on_show_window_menu()
   {
     HasActions *embed_with_actions = dynamic_cast<HasActions*>(currently_embedded());
diff --git a/src/recentchanges.hpp b/src/recentchanges.hpp
index cbd54c2..bd1f8fd 100644
--- a/src/recentchanges.hpp
+++ b/src/recentchanges.hpp
@@ -77,6 +77,7 @@ private:
   void entry_changed_timeout();
   std::string get_search_text();
   void update_toolbar(EmbeddableWidget & widget);
+  void on_all_notes_button_clicked();
   void on_show_window_menu();
   void on_search_button_toggled();
   void on_find_next_button_clicked();
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 29aca14..d8f2ddc 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -917,6 +917,7 @@ namespace gnote {
       }
       if(!window) {
         window = &IGnote::obj().new_main_window();
+        window->close_on_escape(true);
       }
       window->present_note(link);
       window->present();


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