[gnote] Fix note disabling



commit 4c855d00a3af81c3e6b27e31b05f5b827ecc3a3c
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Sep 7 22:13:33 2013 +0300

    Fix note disabling
    
    Take into account toolbar and note actions.

 src/note.cpp       |    2 +-
 src/notewindow.cpp |   37 +++++++++++++++++++++++++++++++++++++
 src/notewindow.hpp |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 1 deletions(-)
---
diff --git a/src/note.cpp b/src/note.cpp
index 733f299..9f810d4 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -1121,7 +1121,7 @@ namespace gnote {
         if(!m_enabled) {
           m_focus_widget = window->get_focus();
         }
-        window->set_sensitive(m_enabled);
+        m_window->enabled(m_enabled);
         if(m_enabled) {
           window->set_focus(*m_focus_widget);
         }
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index b05d85b..fbf7995 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -57,6 +57,24 @@ namespace gnote {
   }
 
 
+  NoteWindow::NonModifyingAction::NonModifyingAction()
+  {}
+
+  NoteWindow::NonModifyingAction::NonModifyingAction(const Glib::ustring & name,
+                                                     const Gtk::StockID & stock_id,
+                                                     const Glib::ustring & label,
+                                                     const Glib::ustring & tooltip)
+    : Gtk::Action(name, stock_id, label, tooltip)
+  {}
+
+  NoteWindow::NonModifyingAction::NonModifyingAction(const Glib::ustring & name,
+                                                     const Glib::ustring & icon_name,
+                                                     const Glib::ustring & label,
+                                                     const Glib::ustring & tooltip)
+    : Gtk::Action(name, icon_name, label, tooltip)
+  {}
+
+
 
   NoteWindow::NoteWindow(Note & note)
     : m_note(note)
@@ -65,6 +83,7 @@ namespace gnote {
     , m_width(450)
     , m_find_handler(note)
     , m_global_keys(NULL)
+    , m_enabled(true)
   {
     m_template_tag = ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SYSTEM_TAG);
     m_template_save_size_tag = 
ITagManager::obj().get_or_create_system_tag(ITagManager::TEMPLATE_NOTE_SAVE_SIZE_SYSTEM_TAG);
@@ -212,6 +231,7 @@ namespace gnote {
         m_global_keys->add_accelerator(sigc::mem_fun(*this, &NoteWindow::change_depth_left_handler),
                                       GDK_KEY_Left, Gdk::MOD1_MASK,
                                       Gtk::ACCEL_VISIBLE);
+        m_global_keys->enabled(m_enabled);
       }
     }
     else {
@@ -274,6 +294,9 @@ namespace gnote {
     }
     m_widget_actions[order] = action;
     m_signal_actions_changed();
+    if(Glib::RefPtr<NonModifyingAction>::cast_dynamic(action) == 0) {
+      action->set_sensitive(m_enabled);
+    }
   }
 
   void NoteWindow::remove_widget_action(const std::string & name)
@@ -593,6 +616,20 @@ namespace gnote {
     m_note.set_pinned(!m_note.is_pinned());
   }
 
+  void NoteWindow::enabled(bool enable)
+  {
+    m_enabled = enable;
+    m_editor->set_editable(m_enabled);
+    embeddable_toolbar()->set_sensitive(m_enabled);
+    if(m_global_keys)
+      m_global_keys->enabled(m_enabled);
+    FOREACH(Glib::RefPtr<Gtk::Action> & action, get_widget_actions()) {
+      if(Glib::RefPtr<NonModifyingAction>::cast_dynamic(action) == 0) {
+        action->set_sensitive(enable);
+      }
+    }
+  }
+
 
   NoteFindHandler::NoteFindHandler(Note & note)
     : m_note(note)
diff --git a/src/notewindow.hpp b/src/notewindow.hpp
index 24c523f..2b1a293 100644
--- a/src/notewindow.hpp
+++ b/src/notewindow.hpp
@@ -155,6 +155,36 @@ public:
   // use co-variant return
   virtual Gtk::Grid *embeddable_toolbar() override;
 
+  class NonModifyingAction
+    : public Gtk::Action
+  {
+  public:
+    static Glib::RefPtr<NonModifyingAction> create()
+      {
+        return Glib::RefPtr<NonModifyingAction>(new NonModifyingAction);
+      }
+    static Glib::RefPtr<NonModifyingAction> create(const Glib::ustring & name,
+                                                   const Gtk::StockID & stock_id = Gtk::StockID(),
+                                                   const Glib::ustring & label = Glib::ustring(),
+                                                   const Glib::ustring & tooltip = Glib::ustring())
+      {
+        return Glib::RefPtr<NonModifyingAction>(new NonModifyingAction(name, stock_id, label, tooltip));
+      }
+    static Glib::RefPtr<NonModifyingAction> create(const Glib::ustring & name,
+                                                   const Glib::ustring & icon_name,
+                                                   const Glib::ustring & label = Glib::ustring(),
+                                                   const Glib::ustring & tooltip = Glib::ustring())
+      {
+        return Glib::RefPtr<NonModifyingAction>(new NonModifyingAction(name, icon_name, label, tooltip));
+      }
+    NonModifyingAction();
+    explicit NonModifyingAction(const Glib::ustring & name, const Gtk::StockID & stock_id = Gtk::StockID(),
+                                const Glib::ustring & label = Glib::ustring(),
+                                const Glib::ustring & tooltip = Glib::ustring());
+    NonModifyingAction(const Glib::ustring & name, const Glib::ustring & icon_name,
+                       const Glib::ustring & label = Glib::ustring(),
+                       const Glib::ustring & tooltip = Glib::ustring());
+  };
   virtual std::vector<Glib::RefPtr<Gtk::Action> > get_widget_actions() override;
   virtual sigc::signal<void> & signal_actions_changed() override;
   void add_widget_action(const Glib::RefPtr<Gtk::Action> & action, int order);
@@ -185,6 +215,11 @@ public:
     {
       return m_find_handler;
     }
+  void enabled(bool enable);
+  bool enabled() const
+    {
+      return m_enabled;
+    }
 private:
   static Glib::RefPtr<Gio::Icon> get_icon_pin_active();
   static Glib::RefPtr<Gio::Icon> get_icon_pin_down();
@@ -231,6 +266,7 @@ private:
 
   utils::GlobalKeybinder       *m_global_keys;
   utils::InterruptableTimeout  *m_mark_set_timeout;
+  bool                         m_enabled;
 
   std::map<int, Glib::RefPtr<Gtk::Action> > m_widget_actions;
   sigc::signal<void> m_signal_actions_changed;


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