[ekiga/ds-gtk-application] GActorMenu: Added option to enable/disable section labels in menus.



commit 0da725b27de2db47dae0ad19a25589c7d771cf3d
Author: Damien Sandras <dsandras seconix com>
Date:   Sat Nov 29 12:17:41 2014 +0100

    GActorMenu: Added option to enable/disable section labels in menus.

 lib/engine/gui/gtk-core/gactor-menu.cpp |   28 ++++++++++++++++------------
 lib/engine/gui/gtk-core/gactor-menu.h   |    6 ++++--
 2 files changed, 20 insertions(+), 14 deletions(-)
---
diff --git a/lib/engine/gui/gtk-core/gactor-menu.cpp b/lib/engine/gui/gtk-core/gactor-menu.cpp
index 7bd5ed6..dafe719 100644
--- a/lib/engine/gui/gtk-core/gactor-menu.cpp
+++ b/lib/engine/gui/gtk-core/gactor-menu.cpp
@@ -80,12 +80,12 @@ Ekiga::GActorMenu::~GActorMenu ()
 
 
 void
-Ekiga::GActorMenu::activate (const std::string & name)
+Ekiga::GActorMenu::activate (const std::string & _name)
 {
   Actor::const_iterator it;
 
   for (it = obj.begin(); it != obj.end(); ++it) {
-    if (name.empty () || (*it)->get_name () == name) {
+    if (_name.empty () || (*it)->get_name () == _name) {
       (*it)->activate ();
       return;
     }
@@ -94,15 +94,16 @@ Ekiga::GActorMenu::activate (const std::string & name)
 
 
 GMenuModel *
-Ekiga::GActorMenu::get_model (const Ekiga::GActorMenuStore & store)
+Ekiga::GActorMenu::get_model (const Ekiga::GActorMenuStore & store,
+                              bool display_section_label)
 {
   int c = 0;
-  std::string content = as_xml ();
+  std::string content = as_xml (std::string (), display_section_label);
 
   for (Ekiga::GActorMenuStore::const_iterator it = store.begin ();
        it != store.end ();
        it++) {
-    content = content + (*it)->as_xml ();
+    content = content + (*it)->as_xml (std::string (), display_section_label);
     c += (*it)->size ();
   }
   content = "<?xml_content version=\"1.0\"?>"
@@ -118,7 +119,7 @@ Ekiga::GActorMenu::get_model (const Ekiga::GActorMenuStore & store)
 GtkWidget *
 Ekiga::GActorMenu::get_menu (const Ekiga::GActorMenuStore & store)
 {
-  GtkWidget *menu = gtk_menu_new_from_model (get_model (store));
+  GtkWidget *menu = gtk_menu_new_from_model (get_model (store, false));
   gtk_widget_insert_action_group (menu, "win", G_ACTION_GROUP (g_application_get_default ()));
   g_object_ref (menu);
 
@@ -148,12 +149,12 @@ Ekiga::GActorMenu::sync_gio_actions ()
 
 
 void
-Ekiga::GActorMenu::add_gio_action (const std::string & name)
+Ekiga::GActorMenu::add_gio_action (const std::string & _name)
 {
   Actor::const_iterator it;
 
   for (it = obj.begin(); it != obj.end(); ++it) {
-    if ((*it)->get_name () == name) {
+    if ((*it)->get_name () == _name) {
       add_gio_action (*it);
       return;
     }
@@ -188,15 +189,16 @@ Ekiga::GActorMenu::add_gio_action (Ekiga::ActionPtr a)
 
 
 void
-Ekiga::GActorMenu::remove_gio_action (const std::string & name)
+Ekiga::GActorMenu::remove_gio_action (const std::string & _name)
 {
   g_action_map_remove_action (G_ACTION_MAP (g_application_get_default ()),
-                              name.c_str ());
+                              _name.c_str ());
 }
 
 
 const std::string
-Ekiga::GActorMenu::as_xml (const std::string & id)
+Ekiga::GActorMenu::as_xml (const std::string & id,
+                           bool display_section_label)
 {
   Actor::const_iterator it;
   std::string xml_content;
@@ -207,17 +209,19 @@ Ekiga::GActorMenu::as_xml (const std::string & id)
   else
    xml_content += "    <section>";
 
-  if (!name.empty ())
+  if (display_section_label && !name.empty ())
    xml_content +=  "        <attribute name=\"label\" translatable=\"yes\">"+name+"</attribute>";
 
   for (it = obj.begin(); it != obj.end(); ++it) {
 
+    if ((*it)->is_enabled ()) {
       xml_content +=
         "      <item>"
         "        <attribute name=\"label\" translatable=\"yes\">"+(*it)->get_description ()+"</attribute>"
         "        <attribute name=\"action\">win."+(*it)->get_name ()+"</attribute>"
         "      </item>";
       n++;
+    }
   }
 
   xml_content +=
diff --git a/lib/engine/gui/gtk-core/gactor-menu.h b/lib/engine/gui/gtk-core/gactor-menu.h
index a9e1be4..679f963 100644
--- a/lib/engine/gui/gtk-core/gactor-menu.h
+++ b/lib/engine/gui/gtk-core/gactor-menu.h
@@ -91,7 +91,8 @@ namespace Ekiga {
      * @return a pointer to the GMenuModel, NULL if none (no action, or all actions
      *         are disabled).
      */
-    GMenuModel *get_model (const GActorMenuStore & store = GActorMenuStore ());
+    GMenuModel *get_model (const GActorMenuStore & store = GActorMenuStore (),
+                           bool display_section_label = true);
 
     /** Return a pointer to the GtkMenu corresponding to the current GActorMenu
      *  and the list of GActorMenus given as argument.
@@ -121,7 +122,8 @@ namespace Ekiga {
     virtual void remove_gio_action (const std::string & name);
 
     /** Return the XML representation of the enabled Actions */
-    virtual const std::string as_xml (const std::string & id = "");
+    virtual const std::string as_xml (const std::string & id = "",
+                                      bool display_section_label = true);
 
     /** Return the XML representation of the full menu with
      * enabled Actions.


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