[gnote] Warn and do not lock when closing note with duplicate title



commit 833aaeea056741c947e7ee6d78cfb7007e0b6cdc
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Tue Aug 20 22:44:22 2013 +0300

    Warn and do not lock when closing note with duplicate title
    
    Fixes Bug 705879.

 src/watchers.cpp |   21 +++++++++++++++------
 src/watchers.hpp |    5 +++--
 2 files changed, 18 insertions(+), 8 deletions(-)
---
diff --git a/src/watchers.cpp b/src/watchers.cpp
index fb67325..45a28f2 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -92,6 +92,8 @@ namespace gnote {
 
     get_window()->editor()->signal_focus_out_event().connect(
       sigc::mem_fun(*this, &NoteRenameWatcher::on_editor_focus_out));
+    get_window()->signal_backgrounded.connect(
+      sigc::mem_fun(*this, &NoteRenameWatcher::on_window_backgrounded));
 
     // FIXME: Needed because we hide on delete event, and
     // just hide on accelerator key, so we can't use delete
@@ -109,7 +111,7 @@ namespace gnote {
     // TODO: Duplicated from Update(); refactor instead
     if (m_editing_title) {
       changed ();
-      update_note_title ();
+      update_note_title(false);
       m_editing_title = false;
     }
     return false;
@@ -163,7 +165,7 @@ namespace gnote {
     else {
       if (m_editing_title) {
         changed ();
-        update_note_title ();
+        update_note_title(false);
         m_editing_title = false;
       }
     }
@@ -203,13 +205,13 @@ namespace gnote {
   }
 
 
-  bool NoteRenameWatcher::update_note_title()
+  bool NoteRenameWatcher::update_note_title(bool only_warn)
   {
     std::string title = get_window()->get_name();
 
     Note::Ptr existing = manager().find (title);
     if (existing && (existing != get_note())) {
-      show_name_clash_error (title);
+      show_name_clash_error (title, only_warn);
       return false;
     }
 
@@ -218,7 +220,7 @@ namespace gnote {
     return true;
   }
 
-  void NoteRenameWatcher::show_name_clash_error(const std::string & title)
+  void NoteRenameWatcher::show_name_clash_error(const std::string & title, bool only_warn)
   {
     // Select text from TitleStart to TitleEnd
     get_buffer()->move_mark (get_buffer()->get_selection_bound(), get_title_start());
@@ -234,8 +236,9 @@ namespace gnote {
     /// Only pop open a warning dialog when one isn't already present
     /// Had to add this check because this method is being called twice.
     if (m_title_taken_dialog == NULL) {
+      Gtk::Window *parent = only_warn ? NULL : get_host_window();
       m_title_taken_dialog =
-        new utils::HIGMessageDialog (get_host_window(),
+        new utils::HIGMessageDialog (parent,
                                      GTK_DIALOG_DESTROY_WITH_PARENT,
                                      Gtk::MESSAGE_WARNING,
                                      Gtk::BUTTONS_OK,
@@ -256,6 +259,12 @@ namespace gnote {
     get_window()->editor()->set_editable(true);
   }
 
+  void NoteRenameWatcher::on_window_backgrounded()
+  {
+    update_note_title(true);
+    m_editing_title = false;
+  }
+
 
   ////////////////////////////////////////////////////////////////////////
 
diff --git a/src/watchers.hpp b/src/watchers.hpp
index d96aaeb..2a14f06 100644
--- a/src/watchers.hpp
+++ b/src/watchers.hpp
@@ -74,9 +74,10 @@ namespace gnote {
     void update();
     void changed();
     std::string get_unique_untitled();
-    bool update_note_title();
-    void show_name_clash_error(const std::string &);
+    bool update_note_title(bool only_warn);
+    void show_name_clash_error(const std::string &, bool);
     void on_dialog_response(int);
+    void on_window_backgrounded();
 
     bool                       m_editing_title;
     Glib::RefPtr<Gtk::TextTag> m_title_tag;


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