]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/menubar.cxx
removal of yet more stuff, left over from development; further simplification;
[flightgear.git] / src / GUI / menubar.cxx
index a8a9e66121f9d56c0574cc558720c1695d6dc65c..fa3d69d56ba8f111eff7bd80a853de87a391b908 100644 (file)
 // user-configured dialogs and new commands where necessary.
 ////////////////////////////////////////////////////////////////////////
 
-extern void saveFlight (puObject *);
-static bool
-do_save_dialog (const SGPropertyNode * arg)
-{
-    saveFlight(0);
-    return true;
-}
-
-extern void loadFlight (puObject *);
-static bool
-do_load_dialog (const SGPropertyNode * arg)
-{
-    loadFlight(0);
-    return true;
-}
-
 extern void reInit (puObject *);
 static bool
 do_reinit_dialog (const SGPropertyNode * arg)
@@ -72,22 +56,6 @@ do_print_dialog (const SGPropertyNode * arg)
 }
 #endif
 
-extern void PilotOffsetAdjust (puObject *);
-static bool
-do_pilot_offset_dialog (const SGPropertyNode * arg)
-{
-    PilotOffsetAdjust(0);
-    return true;
-}
-
-extern void fgHUDalphaAdjust (puObject *);
-static bool
-do_hud_alpha_dialog (const SGPropertyNode * arg)
-{
-    fgHUDalphaAdjust(0);
-    return true;
-}
-
 extern void prop_pickerView (puObject *);
 static bool
 do_properties_dialog (const SGPropertyNode * arg)
@@ -150,8 +118,6 @@ static struct {
     const char * name;
     SGCommandMgr::command_t command;
 } deprecated_dialogs [] = {
-    { "old-save-dialog", do_save_dialog },
-    { "old-load-dialog", do_load_dialog },
     { "old-reinit-dialog", do_reinit_dialog },
 #if defined(TR_HIRES_SNAP)
     { "old-hires-snapshot-dialog", do_hires_snapshot_dialog },
@@ -159,8 +125,6 @@ static struct {
 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
     { "old-print-dialog", do_print_dialog },
 #endif
-    { "old-pilot-offset-dialog", do_pilot_offset_dialog },
-    { "old-hud-alpha-dialog", do_hud_alpha_dialog },
     { "old-properties-dialog", do_properties_dialog },
     { "old-ap-add-waypoint-dialog", do_ap_add_waypoint_dialog },
     { "old-ap-pop-waypoint-dialog", do_ap_pop_waypoint_dialog },
@@ -327,7 +291,7 @@ FGMenuBar::make_menubar ()
  * contents, whether they are representing a 'legal' menubar structure.
  */
 void
-FGMenuBar::make_menubar(const SGPropertyNode * props) 
+FGMenuBar::make_menubar(SGPropertyNode * props) 
 {    
     // Just in case.
     destroy_menubar();
@@ -338,6 +302,8 @@ FGMenuBar::make_menubar(const SGPropertyNode * props)
         make_menu(menu_nodes[i]);
 
     _menuBar->close();
+    make_map(props);
+
     if (_visible)
         _menuBar->reveal();
     else
@@ -385,6 +351,90 @@ FGMenuBar::destroy_menubar ()
     SG_LOG(SG_GENERAL, SG_INFO, "Done.");
 }
 
+struct EnabledListener : SGPropertyChangeListener {
+    void valueChanged(SGPropertyNode* node) {
+        NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
+        if (!gui)
+            return;
+        FGMenuBar *menubar = gui->getMenuBar();
+        if (menubar)
+            menubar->enable_item(node->getParent(), node->getBoolValue());
+    }
+};
+
+void
+FGMenuBar::add_enabled_listener(SGPropertyNode * node)
+{
+    if (!node->hasValue("enabled"))
+        node->setBoolValue("enabled", true);
+
+    enable_item(node, node->getBoolValue("enabled"));
+    node->getNode("enabled")->addChangeListener(new EnabledListener());
+}
+
+void
+FGMenuBar::make_map(SGPropertyNode * node)
+{
+    int menu_index = 0;
+    for (puObject *obj = ((puGroup *)_menuBar)->getFirstChild();
+            obj; obj = obj->getNextObject()) {
+
+        // skip puPopupMenus. They are also children of _menuBar,
+        // but we access them via getUserData()  (see below)
+        if (!(obj->getType() & PUCLASS_ONESHOT))
+            continue;
+
+        SGPropertyNode *menu = node->getNode("menu", menu_index, false);
+        if (!menu) {
+            SG_LOG(SG_GENERAL, SG_WARN, "<menu> without node: "
+                    << node->getPath() << "/menu[" << menu_index << ']');
+            continue;
+        }
+
+        _entries[menu->getPath()] = obj;
+        add_enabled_listener(menu);
+
+        puPopupMenu *popup = (puPopupMenu *)obj->getUserData();
+        if (!popup)
+            continue;
+
+        // the entries are for some reason reversed (last first), and we
+        // don't know yet how many will be usable; so we collect first
+        vector<puObject *> e;
+        for (puObject *me = ((puGroup *)popup)->getFirstChild();
+                me; me = me->getNextObject())
+            e.push_back(me);
+
+        for (unsigned int i = 0; i < e.size(); i++) {
+            SGPropertyNode *item = menu->getNode("item", e.size() - i - 1, false);
+            if (!item) {
+                SG_LOG(SG_GENERAL, SG_WARN, "menu <item> without node: "
+                        << menu->getPath() << "/item[" << i << ']');
+                continue;
+            }
+            _entries[item->getPath()] = e[i];
+            add_enabled_listener(item);
+        }
+        menu_index++;
+    }
+}
+
+bool
+FGMenuBar::enable_item(const SGPropertyNode * node, bool state)
+{
+    if (!node || _entries.find(node->getPath()) == _entries.end()) {
+        SG_LOG(SG_GENERAL, SG_WARN, "Trying to enable/disable "
+            "non-existent menu item");
+        return false;
+    }
+    puObject *object = _entries[node->getPath()];
+    if (state)
+        object->activate();
+    else
+        object->greyOut();
+
+    return true;
+}
 
 char **
 FGMenuBar::make_char_array (int size)