diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmFactory.h b/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmFactory.h index 06c2d99e773de45c0c6a9264d644e61618da3514..e4dad97580ddaa1d31c2a63add10fecba1f79cdc 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmFactory.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmFactory.h @@ -18,6 +18,7 @@ namespace API { /// version. struct Algorithm_descriptor { std::string name; ///< name + std::string alias; ///< alias std::string category; ///< category int version; ///< version }; diff --git a/Code/Mantid/Framework/API/src/AlgorithmFactory.cpp b/Code/Mantid/Framework/API/src/AlgorithmFactory.cpp index 2148a8b52d6e6dd855383a7ea8d64c3eabdc5b0b..d2dda0b8c35f4007940444c9a964223f88d4584e 100644 --- a/Code/Mantid/Framework/API/src/AlgorithmFactory.cpp +++ b/Code/Mantid/Framework/API/src/AlgorithmFactory.cpp @@ -350,6 +350,7 @@ AlgorithmFactoryImpl::getDescriptors(bool includeHidden) const { boost::shared_ptr<IAlgorithm> alg = create(desc.name, desc.version); std::vector<std::string> categories = alg->categories(); + desc.alias = alg->alias(); // For each category auto itCategoriesEnd = categories.end(); diff --git a/Code/Mantid/Framework/API/test/AlgorithmFactoryTest.h b/Code/Mantid/Framework/API/test/AlgorithmFactoryTest.h index 1314ee8fc8fa2eedb5f9f9a769910e90499f4d62..540c2555904325212c2d7ade23e28d4ee1860f72 100644 --- a/Code/Mantid/Framework/API/test/AlgorithmFactoryTest.h +++ b/Code/Mantid/Framework/API/test/AlgorithmFactoryTest.h @@ -25,7 +25,7 @@ public: { Mantid::Kernel::Instantiator<ToyAlgorithmTwo, Algorithm>* newTwo = new Mantid::Kernel::Instantiator<ToyAlgorithmTwo, Algorithm>; - //get the nubmer of algorithms it already has + //get the number of algorithms it already has std::vector<std::string> keys = AlgorithmFactory::Instance().getKeys(); size_t noOfAlgs = keys.size(); @@ -34,7 +34,7 @@ public: TS_ASSERT_THROWS_ANYTHING(AlgorithmFactory::Instance().subscribe<ToyAlgorithm>()); - //get the nubmer of algorithms it has now + //get the number of algorithms it has now keys = AlgorithmFactory::Instance().getKeys(); size_t noOfAlgsAfter = keys.size(); TS_ASSERT_EQUALS(noOfAlgsAfter, noOfAlgs + 2); @@ -160,7 +160,10 @@ public: bool foundAlg = false; while (descItr != descriptors.end() && !foundAlg) { - foundAlg = ("Cat" == descItr->category)&&("ToyAlgorithm" == descItr->name)&&(1 == descItr->version); + foundAlg = ("Cat" == descItr->category) && + ("ToyAlgorithm" == descItr->name) && + ("Dog" == descItr->alias) && + (1 == descItr->version); descItr++; } TS_ASSERT(foundAlg); @@ -170,7 +173,7 @@ public: TS_ASSERT_THROWS_NOTHING(descriptors = AlgorithmFactory::Instance().getDescriptors(true)); TS_ASSERT_EQUALS(noOfAlgs - 1, descriptors.size()); - } + } void testGetCategories() { diff --git a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/AlgorithmSelectorWidget.h b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/AlgorithmSelectorWidget.h index 63f1567b5ba24e962fd42e1242bf42bd58a00972..be9200fa657c4f31ab225c513be5efd7bd5afff8 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/AlgorithmSelectorWidget.h +++ b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/AlgorithmSelectorWidget.h @@ -5,13 +5,20 @@ #include "MantidAPI/AlgorithmFactory.h" #include "WidgetDllOption.h" +#include <vector> #include <Poco/NObserver.h> #include <QtGui> - //------------------------------------------------------------------------------ // Forward declaration //------------------------------------------------------------------------------ +namespace Mantid +{ +namespace API +{ + struct Algorithm_descriptor; +} +} namespace MantidQt { namespace MantidWidgets @@ -113,6 +120,10 @@ signals: protected: void keyPressEvent(QKeyEvent *e); + private: + typedef std::vector<Mantid::API::Algorithm_descriptor> AlgNamesType; + void addAliases(AlgNamesType& algNamesList); + QString stripAlias(const QString& text) const; }; diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/AlgorithmSelectorWidget.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/AlgorithmSelectorWidget.cpp index c618119c4925111a5303e0bb5a15378a3023ecc4..3f48ee2a809db624236740eafe4b5499b512875a 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/src/AlgorithmSelectorWidget.cpp +++ b/Code/Mantid/MantidQt/MantidWidgets/src/AlgorithmSelectorWidget.cpp @@ -2,6 +2,8 @@ #include "MantidKernel/System.h" #include "MantidAPI/AlgorithmManager.h" +#include "boost/algorithm/string.hpp" + using namespace Mantid::Kernel; using namespace Mantid::API; @@ -55,7 +57,7 @@ namespace MantidWidgets layout->addLayout(buttonLayout); layout->addWidget(m_tree); - // The poco notification will be dispacted from the callers thread but we need to + // The poco notification will be dispatched from the callers thread but we need to // make sure the updates to the widgets happen on the GUI thread. Dispatching // through a Qt signal will make sure it is in the correct thread. AlgorithmFactory::Instance().notificationCenter.addObserver(m_updateObserver); @@ -322,7 +324,7 @@ namespace MantidWidgets else { QString cn = subCats[0]; - QTreeWidgetItem *catItem = 0; + QTreeWidgetItem *catItem = NULL; int n = subCats.size(); for(int j=0;j<n;j++) { @@ -377,13 +379,13 @@ namespace MantidWidgets QComboBox::keyPressEvent(e); } - //--------------------------------------------------------------------------- + //--------------------------------------------------------------------------- /** Update the list of algos in the combo box */ void FindAlgComboBox::update() { - typedef std::vector<Algorithm_descriptor> AlgNamesType; //include hidden categories in the combo list box AlgNamesType names = AlgorithmFactory::Instance().getDescriptors(true); + addAliases(names); // sort by algorithm names only to fill this combobox sort(names.begin(),names.end(),Algorithm_descriptor_name_less); @@ -399,6 +401,38 @@ namespace MantidWidgets this->setCurrentIndex(-1); } + + /** Adds alias entries to the list of algorithms */ + void FindAlgComboBox::addAliases(AlgNamesType& algNamesList) + { + AlgNamesType aliasList; + for(AlgNamesType::const_iterator i=algNamesList.begin();i!=algNamesList.end();++i) + { + //the alias is not empty and is not just different by case from the name + if ((!i->alias.empty()) && (!boost::iequals(i->alias,i->name))) + { + Algorithm_descriptor newAlias(*i); + newAlias.name = i->alias + " [" + i->name + "]"; + aliasList.push_back(newAlias); + } + } + //add them to the list - unsorted + algNamesList.reserve( algNamesList.size() + aliasList.size() ); + algNamesList.insert( algNamesList.end(), aliasList.begin(), aliasList.end() ); + } + + /** if a string is for an alias convert it to the algorithm name */ + QString FindAlgComboBox::stripAlias(const QString& text) const + { + QString retVal = text; + int foundOpen = text.indexOf("["); + if (foundOpen!=-1){ + int foundClose=text.lastIndexOf("]"); + if (foundClose!=-1) + retVal = text.mid(foundOpen+1, foundClose-foundOpen-1); + } + return retVal; + } //--------------------------------------------------------------------------- /** Return the selected algorithm */ @@ -413,6 +447,7 @@ namespace MantidWidgets if (matchedIndex > -1) { typedText = this->itemText(matchedIndex); //text in the combobox at the matched index + typedText = stripAlias(typedText); } } //set return values