Index: src/UIElements/TextUI/TextWindow.cpp
===================================================================
--- src/UIElements/TextUI/TextWindow.cpp	(revision 112b090c14e4507fb9dde0a3a340b9a3d61823ba)
+++ src/UIElements/TextUI/TextWindow.cpp	(revision 0c5eeb409cae578bdec87b091364dde4c8b6940e)
@@ -12,25 +12,4 @@
 #include <boost/bind.hpp>
 
-
-// TODO: When done with refactoring most of these wont be needed anymore
-#include "analysis_correlation.hpp"
-#include "atom.hpp"
-#include "bond.hpp"
-#include "bondgraph.hpp"
-#include "boundary.hpp"
-#include "config.hpp"
-#include "element.hpp"
-#include "ellipsoid.hpp"
-#include "helpers.hpp"
-#include "leastsquaremin.hpp"
-#include "linkedcell.hpp"
-#include "log.hpp"
-#include "memoryusageobserver.hpp"
-#include "molecule.hpp"
-#include "periodentafel.hpp"
-#include "World.hpp"
-
-#include "Legacy/oldmenu.hpp"
-
 #include "Menu/Menu.hpp"
 #include "Menu/TextMenu.hpp"
@@ -40,6 +19,6 @@
 #include "Menu/SubMenuItem.hpp"
 #include "TextUI/TextStatusIndicator.hpp"
+#include "Actions/MapOfActions.hpp"
 #include "Actions/MethodAction.hpp"
-#include "Actions/MoleculeAction/ChangeNameAction.hpp"
 #include "Actions/ErrorAction.hpp"
 #include "Actions/ActionRegistry.hpp"
@@ -47,5 +26,17 @@
 #include "Views/MethodStringView.hpp"
 
+#include "defs.hpp"
+#include "log.hpp"
+#include "verbose.hpp"
+
+// all needed due to config::SaveAll()
+#include "config.hpp"
+#include "periodentafel.hpp"
+
+// config::SaveAll() and enumerate()
+#include "molecule.hpp"
+
 #include <iostream>
+#include <map>
 
 using namespace std;
@@ -54,14 +45,14 @@
 TextWindow::TextWindow()
 {
-  MoleculeListClass *molecules = World::getInstance().getMolecules();
-  config *configuration = World::getInstance().getConfig();
-  periodentafel *periode = World::getInstance().getPeriode();
-  char *ConfigFileName = NULL;
-  old_menu = new oldmenu;
+  char ConfigFileName[MAXSTRINGSIZE];
+  map <std::string, TextMenu *> NametoTextMenuMap;
+
+  // populate all actions
+  MapOfActions::getInstance().populateActions();
 
   // build the main menu
   main_menu = new TextMenu(Log() << Verbose(0), "Main Menu");
 
-  moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,molecules,_1));
+  moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,World::getInstance().getMolecules(),_1));
   new DisplayMenuItem(main_menu,moleculeView,"Molecule List");
 
@@ -76,43 +67,52 @@
   new SeperatorItem(main_menu);
 
-  Action *setMoleculeAction = new MethodAction("setMoleculeAction",boost::bind(&MoleculeListClass::flipChosen,molecules));
+  Action *setMoleculeAction = new MethodAction("setMoleculeAction",boost::bind(&MoleculeListClass::flipChosen,World::getInstance().getMolecules()));
   new ActionMenuItem('a',"set molecule (in)active",main_menu,setMoleculeAction);
 
-  TextMenu *editMoleculesMenu = new TextMenu(Log() << Verbose(0), "Edit Molecules");
-  new SubMenuItem('e',"edit molecules (load, parse, save)",main_menu,editMoleculesMenu);
+  TextMenu *AnalysisMenu = new TextMenu(Log() << Verbose(0), "Analysis");
+  NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("analysis", AnalysisMenu) );
+  new SubMenuItem('A',"Analysis (pair correlation, volume)",main_menu,AnalysisMenu);
 
-  Action *manipulateMoleculeAction = new MethodAction("manipulateMoleculeAction",boost::bind(&oldmenu::ManipulateMolecules,old_menu,periode, molecules, configuration));
-  new ActionMenuItem('g',"globally manipulate atoms in molecule",main_menu,manipulateMoleculeAction);
+  TextMenu *CommandMenu = new TextMenu(Log() << Verbose(0), "Configuration");
+  NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("command", CommandMenu) );
+  new SubMenuItem('c',"configuration",main_menu,CommandMenu);
 
-  Action *mergeMoleculeAction = new MethodAction("mergeMoleculeAction",boost::bind(&oldmenu::MergeMolecules,old_menu,periode, molecules));
-  new ActionMenuItem('M',"Merge molecules",main_menu,mergeMoleculeAction);
+  TextMenu *AtomMenu = new TextMenu(Log() << Verbose(0), "Atoms");
+  NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("atom", AtomMenu) );
+  new SubMenuItem('e',"edit atoms",main_menu,AtomMenu);
 
-  Action *manipulateAtomsAction = new MethodAction("manipulateAtomsAction",boost::bind(&oldmenu::ManipulateAtoms,old_menu,periode, molecules, configuration));
-  new ActionMenuItem('m',"manipulate atoms",main_menu,manipulateAtomsAction);
+  TextMenu *FragmentationMenu = new TextMenu(Log() << Verbose(0), "Fragmentation");
+  NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("fragmentation", FragmentationMenu) );
+  new SubMenuItem('f',"fragmentation",main_menu,FragmentationMenu);
+
+  TextMenu *ParserMenu = new TextMenu(Log() << Verbose(0), "Parse files");
+  NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("parser", ParserMenu) );
+  new SubMenuItem('p',"parse files into system",main_menu,ParserMenu);
+
+  TextMenu *MoleculesMenu = new TextMenu(Log() << Verbose(0), "Edit Molecules");
+  NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("analysis", AnalysisMenu) );
+  new SubMenuItem('m',"edit molecules (load, parse, save)",main_menu,MoleculesMenu);
+
+  TextMenu *TesselationMenu = new TextMenu(Log() << Verbose(0), "Tesselate Molecules");
+  NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("tesselation", TesselationMenu) );
+  new SubMenuItem('t',"tesselate molecules",main_menu,TesselationMenu);
+
+  TextMenu *WorldMenu = new TextMenu(Log() << Verbose(0), "World");
+  NametoTextMenuMap.insert( pair <std::string, TextMenu *> ("world", WorldMenu) );
+  new SubMenuItem('w',"edit world",main_menu,WorldMenu);
 
   new SeperatorItem(main_menu);
 
-  Action *editConfigAction = new MethodAction("editConfigAction",boost::bind(&config::Edit,configuration));
-  new ActionMenuItem('c',"edit the current configuration",main_menu,editConfigAction);
-
-  new SeperatorItem(main_menu);
-
-  Action *saveConfigAction = new MethodAction("saveConfigAction",boost::bind(&config::SaveAll,configuration, ConfigFileName, periode, molecules));
+  Action *saveConfigAction = new MethodAction("saveConfigAction",boost::bind(&config::SaveAll,World::getInstance().getConfig(), ConfigFileName, World::getInstance().getPeriode(), World::getInstance().getMolecules()));
   new ActionMenuItem('s',"save current setup to config file",main_menu,saveConfigAction);
-
-  Action *doTestAction = new MethodAction("doTestAction",boost::bind(&oldmenu::testroutine,old_menu,molecules));
-  new ActionMenuItem('T',"call the current test routine",main_menu,doTestAction);
 
   quitAction = new MethodAction("quitAction",boost::bind(&TextMenu::doQuit,main_menu),false);
   new ActionMenuItem('q',"quit",main_menu,quitAction);
 
-  // call all functions used to build the submenus
-
-  populateEditMoleculesMenu(editMoleculesMenu);
-
-  Action *returnFromEditMoleculeAction = new TextMenu::LeaveAction(editMoleculesMenu);
-  MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",editMoleculesMenu,returnFromEditMoleculeAction);
-
-  editMoleculesMenu->addDefault(returnItem);
+  // go through all menus and create them
+  for (map <std::string, TextMenu *>::iterator MenuRunner = NametoTextMenuMap.begin(); MenuRunner != NametoTextMenuMap.end(); ++MenuRunner) {
+    cout << "Creating Menu " << MenuRunner->first << "." << endl;
+    populateMenu(MenuRunner->second, MenuRunner->first);
+  }
 
   // Add status indicators etc...
@@ -123,5 +123,4 @@
 TextWindow::~TextWindow()
 {
-  delete old_menu;
   delete quitAction;
   delete moleculeView;
@@ -134,27 +133,28 @@
 }
 
-void TextWindow::populateEditMoleculesMenu(Menu* editMoleculesMenu)
+char TextWindow::getSuitableShortForm(set <char> &ShortcutList, const std::string name) const
 {
-  MoleculeListClass *molecules = World::getInstance().getMolecules();
-  periodentafel *periode = World::getInstance().getPeriode();
+  for (std::string::const_iterator CharRunner = name.begin(); CharRunner != name.end(); ++CharRunner) {
+    if (ShortcutList.find(*CharRunner) == ShortcutList.end())
+      return *CharRunner;
+  }
+  DoeLog(1) && (eLog() << Verbose(1) << "Could not find a suitable shortform for TextWindow::getSuitableShortForm()." << endl);
+  return ((char)(ShortcutList.size() % 10) + '0');
+}
 
-  // build the EditMoleculesMenu
-  Action *createMoleculeAction = new MethodAction("createMoleculeAction",boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));
-  new ActionMenuItem('c',"create new molecule",editMoleculesMenu,createMoleculeAction);
-
-  Action *loadMoleculeAction = new MethodAction("loadMoleculeAction",boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));
-  new ActionMenuItem('l',"load molecule from xyz file",editMoleculesMenu,loadMoleculeAction);
-
-  Action *changeFilenameAction = new MoleculeChangeNameAction();
-  new ActionMenuItem('n',"change molecule's name",editMoleculesMenu,changeFilenameAction);
-
-  Action *giveFilenameAction = new MethodAction("giveFilenameAction",boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));
-  new ActionMenuItem('N',"give molecules filename",editMoleculesMenu,giveFilenameAction);
-
-  Action *parseAtomsAction = new MethodAction("parseAtomsAction",boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));
-  new ActionMenuItem('p',"parse atoms in xyz file into molecule",editMoleculesMenu,parseAtomsAction);
-
-  Action *eraseMoleculeAction = new MethodAction("eraseMoleculeAction",boost::bind(&MoleculeListClass::eraseMolecule,molecules));
-  new ActionMenuItem('r',"remove a molecule",editMoleculesMenu,eraseMoleculeAction);
-
+void TextWindow::populateMenu(TextMenu* Menu, const  std::string &MenuName)
+{
+  Action *ActionItem = NULL;
+  set <char> ShortcutList;
+  // through all actions for this menu
+  pair < multimap <std::string, std::string>::iterator, multimap <std::string, std::string>::iterator > MenuActions = MapOfActions::getInstance().MenuContainsActionMap.equal_range(MenuName);
+  for (multimap <std::string, std::string>::const_iterator MenuRunner = MenuActions.first; MenuRunner != MenuActions.second; ++MenuRunner) {
+    cout << " Adding " << MenuRunner->second << " to submenu " << MenuName << endl;
+    ActionItem = ActionRegistry::getInstance().getActionByName(MenuRunner->second);
+    new ActionMenuItem(getSuitableShortForm(ShortcutList, MenuRunner->second),MapOfActions::getInstance().getDescription(MenuRunner->second).c_str(),Menu,ActionItem);
+  }
+  // finally add default quit item
+  Action *returnFromAction = new TextMenu::LeaveAction(Menu);
+  MenuItem *returnFromItem = new ActionMenuItem('q',"return to Main menu",Menu,returnFromAction);
+  Menu->addDefault(returnFromItem);
 }
