[gnote] Change NoteAddin to use PopoverWidget for popover buttons



commit f00fddc04b6eeb24ee2dc2db9bf44c80fd908963
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Mar 31 17:54:15 2019 +0300

    Change NoteAddin to use PopoverWidget for popover buttons

 src/noteaddin.cpp                   |  6 +++---
 src/noteaddin.hpp                   |  5 +++--
 src/notebooks/notebooknoteaddin.cpp |  8 ++++----
 src/notebooks/notebooknoteaddin.hpp |  4 ++--
 src/notewindow.cpp                  | 19 +++++++++++--------
 src/popoverwidgets.cpp              | 10 ++++++++++
 src/popoverwidgets.hpp              |  2 ++
 src/watchers.cpp                    | 10 +++++-----
 src/watchers.hpp                    |  4 ++--
 9 files changed, 42 insertions(+), 26 deletions(-)
---
diff --git a/src/noteaddin.cpp b/src/noteaddin.cpp
index b2223180..39fd4377 100644
--- a/src/noteaddin.cpp
+++ b/src/noteaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2016 Aurimas Cernius
+ * Copyright (C) 2012-2016,2019 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -163,9 +163,9 @@ namespace gnote {
     return dynamic_cast<Gtk::Window*>(note_window->host());
   }
 
-  std::map<int, Gtk::Widget*> NoteAddin::get_actions_popover_widgets() const
+  std::vector<gnote::PopoverWidget> NoteAddin::get_actions_popover_widgets() const
   {
-    return std::map<int, Gtk::Widget*>();
+    return std::vector<gnote::PopoverWidget>();
   }
 
   void NoteAddin::register_main_window_action_callback(const Glib::ustring & action, sigc::slot<void, const 
Glib::VariantBase&> callback)
diff --git a/src/noteaddin.hpp b/src/noteaddin.hpp
index 25535222..e21f1afd 100644
--- a/src/noteaddin.hpp
+++ b/src/noteaddin.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2016 Aurimas Cernius
+ * Copyright (C) 2012-2016,2019 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -37,6 +37,7 @@
 #include "abstractaddin.hpp"
 #include "note.hpp"
 #include "notebuffer.hpp"
+#include "popoverwidgets.hpp"
 
 namespace gnote {
 
@@ -74,7 +75,7 @@ public:
   /// </summary>
   virtual void on_note_opened () = 0;
 
-  virtual std::map<int, Gtk::Widget*> get_actions_popover_widgets() const;
+  virtual std::vector<PopoverWidget> get_actions_popover_widgets() const;
   void register_main_window_action_callback(const Glib::ustring & action, sigc::slot<void, const 
Glib::VariantBase&> callback);
 
   const Note::Ptr & get_note() const
diff --git a/src/notebooks/notebooknoteaddin.cpp b/src/notebooks/notebooknoteaddin.cpp
index aa40a80a..7563d467 100644
--- a/src/notebooks/notebooknoteaddin.cpp
+++ b/src/notebooks/notebooknoteaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2016 Aurimas Cernius
+ * Copyright (C) 2010-2016,2019 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -103,16 +103,16 @@ namespace notebooks {
   }
 
 
-  std::map<int, Gtk::Widget*> NotebookNoteAddin::get_actions_popover_widgets() const
+  std::vector<gnote::PopoverWidget> NotebookNoteAddin::get_actions_popover_widgets() const
   {
     auto widgets = NoteAddin::get_actions_popover_widgets();
     if(!get_note()->contains_tag(get_template_tag())) {
       Gtk::Widget *notebook_button = utils::create_popover_submenu_button("notebooks-submenu", 
_("Notebook"));
-      utils::add_item_to_ordered_map(widgets, gnote::NOTEBOOK_ORDER, notebook_button);
+      widgets.push_back(gnote::PopoverWidget::create_for_note(gnote::NOTEBOOK_ORDER, notebook_button));
 
       auto submenu = utils::create_popover_submenu("notebooks-submenu");
       update_menu(submenu);
-      utils::add_item_to_ordered_map(widgets, 1000000, submenu);
+      widgets.push_back(gnote::PopoverWidget::create_custom_section(submenu));
     }
 
     return widgets;
diff --git a/src/notebooks/notebooknoteaddin.hpp b/src/notebooks/notebooknoteaddin.hpp
index 24733000..4bdf3f00 100644
--- a/src/notebooks/notebooknoteaddin.hpp
+++ b/src/notebooks/notebooknoteaddin.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2016 Aurimas Cernius
+ * Copyright (C) 2011-2016,2019 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -41,7 +41,7 @@ namespace notebooks {
     virtual void initialize() override;
     virtual void shutdown() override;
     virtual void on_note_opened() override;
-    virtual std::map<int, Gtk::Widget*> get_actions_popover_widgets() const override;
+    virtual std::vector<gnote::PopoverWidget> get_actions_popover_widgets() const override;
 
   protected:
     NotebookNoteAddin();
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index a5ae1ed4..3ab20a07 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2018 Aurimas Cernius
+ * Copyright (C) 2011-2019 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -308,6 +308,8 @@ namespace gnote {
   {
     std::vector<Gtk::Widget*> widgets;
     std::map<int, Gtk::Widget*> widget_map;
+    std::vector<PopoverWidget> popover_widgets;
+    popover_widgets.reserve(20);
 
     Gtk::Widget *new_note = manage(utils::create_popover_button("app.new-note", _("_New Note")));
     widgets.push_back(new_note);
@@ -321,23 +323,24 @@ namespace gnote {
     widgets.push_back(NULL);
 
     Gtk::Widget *link = manage(utils::create_popover_button("win.link", _("_Link to New Note")));
-    widget_map[2000] = link; // place under "note actions", see iactionmanger.hpp
+    popover_widgets.push_back(PopoverWidget::create_for_note(2000, link));
 
     NoteManager & manager = static_cast<NoteManager&>(m_note.manager());
     Note::Ptr note = std::dynamic_pointer_cast<Note>(m_note.shared_from_this());
     FOREACH(NoteAddin *addin, manager.get_addin_manager().get_note_addins(note)) {
-      utils::merge_ordered_maps(widget_map, addin->get_actions_popover_widgets());
+      auto addin_widgets = addin->get_actions_popover_widgets();
+      popover_widgets.insert(popover_widgets.end(), addin_widgets.begin(), addin_widgets.end());
     }
 
+    std::sort(popover_widgets.begin(), popover_widgets.end());
     int last_order = 0;
-    for(std::map<int, Gtk::Widget*>::iterator iter = widget_map.begin();
-        iter != widget_map.end(); ++iter) {
+    for(auto & w : popover_widgets) {
       // put separator between groups
-      if(iter->first < 10000 && (iter->first / 1000) > last_order && widgets.size() > 0 && widgets.back() != 
NULL) {
+      if(w.order < 10000 && (w.order / 1000) > last_order && widgets.size() > 0 && widgets.back() != NULL) {
         widgets.push_back(NULL);
       }
-      last_order = iter->first / 1000;
-      widgets.push_back(iter->second);
+      last_order = w.order / 1000;
+      widgets.push_back(w.widget);
     }
 
     widgets.push_back(utils::create_popover_button("win.important-note", _("_Important")));
diff --git a/src/popoverwidgets.cpp b/src/popoverwidgets.cpp
index 67dfcdf7..cd4f7a6b 100644
--- a/src/popoverwidgets.cpp
+++ b/src/popoverwidgets.cpp
@@ -27,5 +27,15 @@ PopoverWidget PopoverWidget::create_for_app(int ord, Gtk::Widget *w)
   return PopoverWidget(IActionManager::APP_ACTION_MANAGE, ord, w);
 }
 
+PopoverWidget PopoverWidget::create_for_note(int ord, Gtk::Widget *w)
+{
+  return PopoverWidget(0, ord, w);
+}
+
+PopoverWidget PopoverWidget::create_custom_section(Gtk::Widget *w)
+{
+  return PopoverWidget(IActionManager::APP_CUSTOM_SECTION, 0, w);
+}
+
 }
 
diff --git a/src/popoverwidgets.hpp b/src/popoverwidgets.hpp
index bcedb807..1c024522 100644
--- a/src/popoverwidgets.hpp
+++ b/src/popoverwidgets.hpp
@@ -30,6 +30,8 @@ struct PopoverWidget
   int secondary_order;
 
   static PopoverWidget create_for_app(int ord, Gtk::Widget *w);
+  static PopoverWidget create_for_note(int ord, Gtk::Widget *w);
+  static PopoverWidget create_custom_section(Gtk::Widget *w);
 
   PopoverWidget(int sec, int ord, Gtk::Widget *w)
     : widget(w)
diff --git a/src/watchers.cpp b/src/watchers.cpp
index df5db038..4ec32340 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2015,2017 Aurimas Cernius
+ * Copyright (C) 2010-2015,2017,2019 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -307,12 +307,12 @@ namespace gnote {
     window->signal_backgrounded.connect(sigc::mem_fun(*this, 
&NoteSpellChecker::on_note_window_backgrounded));
   }
 
-  std::map<int, Gtk::Widget*> NoteSpellChecker::get_actions_popover_widgets() const
+  std::vector<gnote::PopoverWidget> NoteSpellChecker::get_actions_popover_widgets() const
   {
-    std::map<int, Gtk::Widget*> widgets = NoteAddin::get_actions_popover_widgets();
+    auto widgets = NoteAddin::get_actions_popover_widgets();
     if(m_enabled) {
-      utils::add_item_to_ordered_map(widgets, SPELL_CHECK_ORDER,
-        utils::create_popover_button("win.enable-spell-check", _("Check spelling")));
+      auto button = utils::create_popover_button("win.enable-spell-check", _("Check spelling"));
+      widgets.push_back(gnote::PopoverWidget::create_for_note(SPELL_CHECK_ORDER, button));
     }
     return widgets;
   }
diff --git a/src/watchers.hpp b/src/watchers.hpp
index 81c8e8f8..182be3df 100644
--- a/src/watchers.hpp
+++ b/src/watchers.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2015,2017 Aurimas Cernius
+ * Copyright (C) 2010-2015,2017,2019 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -94,7 +94,7 @@ namespace gnote {
     virtual void initialize() override;
     virtual void shutdown() override;
     virtual void on_note_opened() override;
-    virtual std::map<int, Gtk::Widget*> get_actions_popover_widgets() const override;
+    virtual std::vector<gnote::PopoverWidget> get_actions_popover_widgets() const override;
 
     static bool gtk_spell_available()
       { return true; }


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