[gnote] Move popover button creation to popoverwidgets



commit 8b12baa41bb5ea5cf3b7a949b3b0d72ba05a7ac2
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Thu Apr 11 23:18:26 2019 +0300

    Move popover button creation to popoverwidgets

 src/popoverwidgets.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/popoverwidgets.hpp | 26 +++++++++++++++++
 src/recentchanges.cpp  |  2 +-
 src/utils.cpp          | 71 +----------------------------------------------
 src/utils.hpp          | 21 --------------
 5 files changed, 103 insertions(+), 92 deletions(-)
---
diff --git a/src/popoverwidgets.cpp b/src/popoverwidgets.cpp
index 9d3cda9f..0dba9cc8 100644
--- a/src/popoverwidgets.cpp
+++ b/src/popoverwidgets.cpp
@@ -17,10 +17,41 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <gtkmm/label.h>
+#include <gtkmm/modelbutton.h>
+
 #include "iactionmanager.hpp"
 #include "popoverwidgets.hpp"
 
 namespace gnote {
+  namespace {
+    class PopoverSubmenuBox
+      : public Gtk::Box
+      , public PopoverSubmenu
+    {
+    public:
+      PopoverSubmenuBox(const Glib::ustring & submenu)
+        : Gtk::Box(Gtk::ORIENTATION_VERTICAL)
+        , PopoverSubmenu(submenu)
+      {
+        utils::set_common_popover_widget_props(*this);
+      }
+    };
+
+
+    void set_common_popover_button_props(Gtk::ModelButton & button)
+    {
+      button.set_use_underline(true);
+      button.property_margin_top() = 3;
+      button.property_margin_bottom() = 3;
+      auto lbl = dynamic_cast<Gtk::Label*>(button.get_child());
+      if(lbl) {
+        lbl->set_xalign(0.0f);
+      }
+      utils::set_common_popover_widget_props(button);
+    }
+  }
+
 
 const int APP_SECTION_NEW = 1;
 const int APP_SECTION_MANAGE = 2;
@@ -48,5 +79,49 @@ PopoverWidget PopoverWidget::create_custom_section(Gtk::Widget *w)
   return PopoverWidget(APP_CUSTOM_SECTION, 0, w);
 }
 
+namespace utils {
+
+  Gtk::Widget * create_popover_button(const Glib::ustring & action, const Glib::ustring & label)
+  {
+    Gtk::ModelButton *item = new Gtk::ModelButton;
+    gtk_actionable_set_action_name(GTK_ACTIONABLE(item->gobj()), action.c_str());
+    item->set_label(label);
+    set_common_popover_button_props(*item);
+    return item;
+  }
+
+
+  Gtk::Widget * create_popover_submenu_button(const Glib::ustring & submenu, const Glib::ustring & label)
+  {
+    Gtk::ModelButton *button = new Gtk::ModelButton;
+    button->property_menu_name() = submenu;
+    button->set_label(label);
+    set_common_popover_button_props(*button);
+    return button;
+  }
+
+
+  Gtk::Box * create_popover_submenu(const Glib::ustring & name)
+  {
+    return new PopoverSubmenuBox(name);
+  }
+
+
+  void set_common_popover_widget_props(Gtk::Widget & widget)
+  {
+    widget.property_hexpand() = true;
+  }
+
+  void set_common_popover_widget_props(Gtk::Box & widget)
+  {
+    widget.property_margin_top() = 9;
+    widget.property_margin_bottom() = 9;
+    widget.property_margin_left() = 12;
+    widget.property_margin_right() = 12;
+    set_common_popover_widget_props(static_cast<Gtk::Widget&>(widget));
+  }
+
+}
+
 }
 
diff --git a/src/popoverwidgets.hpp b/src/popoverwidgets.hpp
index 5025b2f8..82910356 100644
--- a/src/popoverwidgets.hpp
+++ b/src/popoverwidgets.hpp
@@ -20,6 +20,8 @@
 #ifndef _POPOVERWIDGETS_HPP_
 #define _POPOVERWIDGETS_HPP_
 
+#include <gtkmm/box.h>
+
 namespace gnote {
 
 extern const int APP_SECTION_NEW;
@@ -78,6 +80,30 @@ struct PopoverWidget
     }
 };
 
+class PopoverSubmenu
+{
+public:
+  PopoverSubmenu(const Glib::ustring & name)
+    : m_name(name)
+  {}
+
+  const Glib::ustring & name() const
+    {
+      return m_name;
+    }
+private:
+  const Glib::ustring m_name;
+};
+
+
+namespace utils {
+  Gtk::Widget * create_popover_button(const Glib::ustring & action, const Glib::ustring & label);
+  Gtk::Widget * create_popover_submenu_button(const Glib::ustring & submenu, const Glib::ustring & label);
+  Gtk::Box * create_popover_submenu(const Glib::ustring & name);
+  void set_common_popover_widget_props(Gtk::Widget & widget);
+  void set_common_popover_widget_props(Gtk::Box & widget);
+}
+
 }
 
 #endif
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 30267435..cfc88355 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -790,7 +790,7 @@ namespace gnote {
 
       menu->add(*menu_box);
       for(; iter != items.end(); ++iter) {
-          utils::PopoverSubmenu *submenu = dynamic_cast<utils::PopoverSubmenu*>(iter->widget);
+          PopoverSubmenu *submenu = dynamic_cast<PopoverSubmenu*>(iter->widget);
           if(submenu) {
             menu->add(*manage(iter->widget));
             menu->child_property_submenu(*iter->widget) = submenu->name();
diff --git a/src/utils.cpp b/src/utils.cpp
index b7640909..ee32ff3d 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -34,8 +34,6 @@
 #include <gtkmm/checkmenuitem.h>
 #include <gtkmm/icontheme.h>
 #include <gtkmm/image.h>
-#include <gtkmm/label.h>
-#include <gtkmm/modelbutton.h>
 #include <gtkmm/stock.h>
 #include <gtkmm/textbuffer.h>
 
@@ -109,33 +107,7 @@ namespace gnote {
         cond->signal();
         mutex->unlock();
       }
-
-
-      class PopoverSubmenuBox
-        : public Gtk::Box
-        , public PopoverSubmenu
-      {
-      public:
-        PopoverSubmenuBox(const Glib::ustring & submenu)
-          : Gtk::Box(Gtk::ORIENTATION_VERTICAL)
-          , PopoverSubmenu(submenu)
-        {
-          utils::set_common_popover_widget_props(*this);
-        }
-      };
-
-      void set_common_popover_widget_props(Gtk::ModelButton & button)
-      {
-        button.set_use_underline(true);
-        button.property_margin_top() = 3;
-        button.property_margin_bottom() = 3;
-        auto lbl = dynamic_cast<Gtk::Label*>(button.get_child());
-        if(lbl) {
-          lbl->set_xalign(0.0f);
-        }
-        utils::set_common_popover_widget_props(button);
-      }
-    }
+   }
 
 
     void popup_menu(Gtk::Menu &menu, const GdkEventButton * ev)
@@ -297,47 +269,6 @@ namespace gnote {
     }
 
 
-    Gtk::Widget * create_popover_button(const Glib::ustring & action, const Glib::ustring & label)
-    {
-      Gtk::ModelButton *item = new Gtk::ModelButton;
-      gtk_actionable_set_action_name(GTK_ACTIONABLE(item->gobj()), action.c_str());
-      item->set_label(label);
-      set_common_popover_widget_props(*item);
-      return item;
-    }
-
-
-    Gtk::Widget * create_popover_submenu_button(const Glib::ustring & submenu, const Glib::ustring & label)
-    {
-      Gtk::ModelButton *button = new Gtk::ModelButton;
-      button->property_menu_name() = submenu;
-      button->set_label(label);
-      set_common_popover_widget_props(*button);
-      return button;
-    }
-
-
-    Gtk::Box * create_popover_submenu(const Glib::ustring & name)
-    {
-      return new PopoverSubmenuBox(name);
-    }
-
-
-    void set_common_popover_widget_props(Gtk::Widget & widget)
-    {
-      widget.property_hexpand() = true;
-    }
-
-    void set_common_popover_widget_props(Gtk::Box & widget)
-    {
-      widget.property_margin_top() = 9;
-      widget.property_margin_bottom() = 9;
-      widget.property_margin_left() = 12;
-      widget.property_margin_right() = 12;
-      set_common_popover_widget_props(static_cast<Gtk::Widget&>(widget));
-    }
-
-
     void add_item_to_ordered_map(std::map<int, Gtk::Widget*> & dest, int order, Gtk::Widget *item)
     {
       for(; dest.find(order) != dest.end(); ++order);
diff --git a/src/utils.hpp b/src/utils.hpp
index c38cc4fd..8017558a 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -61,30 +61,9 @@ namespace gnote {
     void main_context_invoke(const sigc::slot<void> & slot);
     void main_context_call(const sigc::slot<void> & slot);
 
-    Gtk::Widget * create_popover_button(const Glib::ustring & action, const Glib::ustring & label);
-    Gtk::Widget * create_popover_submenu_button(const Glib::ustring & submenu, const Glib::ustring & label);
-    Gtk::Box * create_popover_submenu(const Glib::ustring & name);
-    void set_common_popover_widget_props(Gtk::Widget & widget);
-    void set_common_popover_widget_props(Gtk::Box & widget);
-
     void add_item_to_ordered_map(std::map<int, Gtk::Widget*> & dest, int order, Gtk::Widget *item);
     void merge_ordered_maps(std::map<int, Gtk::Widget*> & dest, const std::map<int, Gtk::Widget*> & adds);
 
-    class PopoverSubmenu
-    {
-    public:
-      PopoverSubmenu(const Glib::ustring & name)
-        : m_name(name)
-      {}
-
-      const Glib::ustring & name() const
-        {
-          return m_name;
-        }
-    private:
-      const Glib::ustring m_name;
-    };
-
     class GlobalKeybinder
     {
     public:


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