[gnote] Update underline for popover



commit 4218f69b6a98b49df280b18c6ce7da9e72649535
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Mar 13 13:30:40 2016 +0200

    Update underline for popover

 src/addins/underline/Makefile.am             |    1 -
 src/addins/underline/underline.desktop.in.in |    4 +-
 src/addins/underline/underlinemenuitem.cpp   |   87 --------------------------
 src/addins/underline/underlinemenuitem.hpp   |   61 ------------------
 src/addins/underline/underlinenoteaddin.cpp  |   60 ++++++++++++++++--
 src/addins/underline/underlinenoteaddin.hpp  |   10 +++-
 6 files changed, 67 insertions(+), 156 deletions(-)
---
diff --git a/src/addins/underline/Makefile.am b/src/addins/underline/Makefile.am
index 0b6a731..620e9a3 100644
--- a/src/addins/underline/Makefile.am
+++ b/src/addins/underline/Makefile.am
@@ -13,7 +13,6 @@ addins_DATA = $(desktop_files)
 
 libunderline_la_SOURCES = underlinenoteaddin.hpp underlinenoteaddin.cpp \
        underlinetag.hpp \
-       underlinemenuitem.hpp underlinemenuitem.cpp \
        $(NULL)
 
 EXTRA_DIST = $(desktop_in_files)
diff --git a/src/addins/underline/underline.desktop.in.in b/src/addins/underline/underline.desktop.in.in
index bf6b87f..7be7002 100644
--- a/src/addins/underline/underline.desktop.in.in
+++ b/src/addins/underline/underline.desktop.in.in
@@ -4,8 +4,10 @@ _Name=Underline
 _Description=Adds ability to underline text.
 _Authors=Hubert Figuière and the Tomboy Project
 Category=Tools
-Version=0.2
+Version=0.3
 DefaultEnabled=true
 Module=libunderline
 LibgnoteRelease= LIBGNOTE_RELEASE@
 LibgnoteVersionInfo= LIBGNOTE_VERSION_INFO@
+[Actions]
+actions_bool=underline-enable
diff --git a/src/addins/underline/underlinenoteaddin.cpp b/src/addins/underline/underlinenoteaddin.cpp
index f12bc87..507fa02 100644
--- a/src/addins/underline/underlinenoteaddin.cpp
+++ b/src/addins/underline/underlinenoteaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010,2013 Aurimas Cernius
+ * Copyright (C) 2010,2013,2016 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  * Original C# file
  * (C) 2009 Mark Wakim <markwakim gmail com>
@@ -24,8 +24,10 @@
 // Translated from UnderlineNoteAddin.cs:
 
 
+#include <glibmm/i18n.h>
+
 #include "sharp/modulefactory.hpp"
-#include "underlinemenuitem.hpp"
+#include "notewindow.hpp"
 #include "underlinenoteaddin.hpp"
 #include "underlinetag.hpp"
 
@@ -48,6 +50,13 @@ namespace underline {
                                get_note()->get_tag_table()->add (m_tag);
                        }
 
+    Gtk::Widget *button = gnote::utils::create_popover_button("win.underline-enable", "");
+    auto label = dynamic_cast<Gtk::Label*>(dynamic_cast<Gtk::Bin*>(button)->get_child());
+    Glib::ustring lbl("<u>");
+    lbl += _("_Underline");
+    lbl += "</u>";
+    label->set_markup_with_mnemonic(lbl);
+    add_text_menu_item(button);
   }
 
 
@@ -62,11 +71,52 @@ namespace underline {
 
   void UnderlineNoteAddin::on_note_opened ()
   {
-    // Add here instead of in Initialize to avoid creating unopened
-    // notes' windows/buffers.
-    add_text_menu_item (new UnderlineMenuItem (this));
+    get_window()->text_menu()->signal_show().connect(
+      sigc::mem_fun(*this, &UnderlineNoteAddin::menu_shown));
+    dynamic_cast<gnote::NoteTextMenu*>(get_window()->text_menu())->signal_set_accels
+      .connect(sigc::mem_fun(*this, &UnderlineNoteAddin::set_accels));
+
+    gnote::NoteWindow *note_window = get_window();
+    note_window->signal_foregrounded.connect(
+      sigc::mem_fun(*this, &UnderlineNoteAddin::on_note_foregrounded));
+    note_window->signal_backgrounded.connect(
+      sigc::mem_fun(*this, &UnderlineNoteAddin::on_note_backgrounded));
+  }
+
+  void UnderlineNoteAddin::on_note_foregrounded()
+  {
+    m_on_underline_clicked_cid = get_window()->host()->find_action("underline-enable")->signal_change_state()
+      .connect(sigc::mem_fun(*this, &UnderlineNoteAddin::on_underline_clicked));
+  }
+
+  void UnderlineNoteAddin::on_note_backgrounded()
+  {
+    m_on_underline_clicked_cid.disconnect();
+  }
+
+  void UnderlineNoteAddin::on_underline_clicked(const Glib::VariantBase & state)
+  {
+    get_window()->host()->find_action("underline-enable")->set_state(state);
+    on_underline_pressed();
   }
 
+  void UnderlineNoteAddin::on_underline_pressed()
+  {
+    get_buffer()->toggle_active_tag("underline");
+  }
+
+  void UnderlineNoteAddin::menu_shown()
+  {
+    get_window()->host()->find_action("underline-enable")->set_state(
+      Glib::Variant<bool>::create(get_buffer()->is_active_tag("underline")));
+  }
+
+  void UnderlineNoteAddin::set_accels(const gnote::utils::GlobalKeybinder & keybinder)
+  {
+    const_cast<gnote::utils::GlobalKeybinder&>(keybinder).add_accelerator(
+      sigc::mem_fun(*this, &UnderlineNoteAddin::on_underline_pressed),
+      GDK_KEY_U, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE);
+  }
 
 
 }
diff --git a/src/addins/underline/underlinenoteaddin.hpp b/src/addins/underline/underlinenoteaddin.hpp
index 6b0aa49..bf2745c 100644
--- a/src/addins/underline/underlinenoteaddin.hpp
+++ b/src/addins/underline/underlinenoteaddin.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010,2013 Aurimas Cernius
+ * Copyright (C) 2010,2013,2016 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  * Original C# file
  * (C) 2009 Mark Wakim <markwakim gmail com>
@@ -57,7 +57,15 @@ namespace underline {
     virtual void shutdown() override;
     virtual void on_note_opened() override;
   private:
+    void on_note_foregrounded();
+    void on_note_backgrounded();
+    void on_underline_clicked(const Glib::VariantBase & state);
+    void on_underline_pressed();
+    void menu_shown();
+    void set_accels(const gnote::utils::GlobalKeybinder & keybinder);
+
     Glib::RefPtr<Gtk::TextTag> m_tag;
+    sigc::connection           m_on_underline_clicked_cid;
   };
 
 


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