From 568068d0890b0f71bda539620a47b6351e96e0be Mon Sep 17 00:00:00 2001
From: Martyn Gigg <martyn.gigg@stfc.ac.uk>
Date: Thu, 17 Feb 2011 12:36:32 +0000
Subject: [PATCH] Fix problem with saving certain paths after the default save
 directory had been appended to it. Fixes #2445 Also improve python simple
 algorithm functions help documentation with a few new lines to make them
 clearer. Fixes #2459

---
 .../Kernel/inc/MantidKernel/ConfigService.h   |  2 +-
 .../Framework/Kernel/src/ConfigService.cpp    | 26 +++++++++----------
 .../PythonAPI/src/FrameworkManagerProxy.cpp   | 10 ++++---
 3 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h
index 3d351eb6cbe..36906341b92 100644
--- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ConfigService.h
@@ -200,7 +200,7 @@ namespace Mantid
       /// Create the storage of the user search directories
       void cacheUserSearchPaths();
       /// Returns true if the path is in the data search list
-      bool isADataSearchDir(const std::string & path) const;
+      bool isInDataSearchList(const std::string & path) const;
 
       // Forward declaration of inner class
       template <class T>
diff --git a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
index 348313792a5..9e2cb0a6b00 100644
--- a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
+++ b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
@@ -24,6 +24,8 @@
 #include <Poco/Notification.h>
 #include <Poco/Environment.h>
 
+#include <boost/algorithm/string/replace.hpp>
+
 #include <fstream>
 #include <sstream>
 #include <iostream>
@@ -336,7 +338,6 @@ void ConfigServiceImpl::convertRelativeToAbsolute()
 std::string ConfigServiceImpl::makeAbsolute(const std::string & dir, const std::string & key) const
 {
   std::string converted;
-  const std::string propFileDir(getPropertiesDir());
   // If we have a list, chop it up and convert each one
   if (dir.find_first_of(";,") != std::string::npos)
   {
@@ -379,6 +380,7 @@ std::string ConfigServiceImpl::makeAbsolute(const std::string & dir, const std::
   }
   if (is_relative)
   {
+    const std::string propFileDir(getPropertiesDir());
     converted = Poco::Path(propFileDir).resolve(dir).toString();
   }
   else
@@ -400,6 +402,10 @@ std::string ConfigServiceImpl::makeAbsolute(const std::string & dir, const std::
         << "\" variable does not exist.\n";
     converted = "";
   }
+  // Backward slashes cannot be allowed to go into our properties file
+  // Note this is a temporary fix for ticket #2445. 
+  // Ticket #2460 prompts a review of our path handling in the config service.
+  boost::replace_all(converted,"\\","/");
   return converted;
 }
 
@@ -451,17 +457,11 @@ void ConfigServiceImpl::cacheUserSearchPaths()
  *  @param path :: the absolute path name to search for
  *  @return true if the path was found
  */
-bool ConfigServiceImpl::isADataSearchDir(const std::string & path) const
+bool ConfigServiceImpl::isInDataSearchList(const std::string & path) const
 {
-  std::vector<std::string>::const_iterator it = m_DataSearchDirs.begin();
-  for( ; it != m_DataSearchDirs.end(); ++it)
-  {
-    if ( path == *it )
-    {
-      return true;
-    }
-  }
-  return false;
+  std::vector<std::string>::const_iterator it = 
+    std::find_if(m_DataSearchDirs.begin(), m_DataSearchDirs.end(), std::bind2nd(std::equal_to<std::string>(),path));
+  return (it != m_DataSearchDirs.end());
 }
 
 /**
@@ -471,7 +471,7 @@ bool ConfigServiceImpl::isADataSearchDir(const std::string & path) const
  */
 void ConfigServiceImpl::appendDataSearchDir(const std::string & path)
 {
-  if ( ! isADataSearchDir(path) )
+  if ( ! isInDataSearchList(path) )
   {
     std::string newSearchString;
     std::vector<std::string>::const_iterator it = m_DataSearchDirs.begin();
@@ -877,7 +877,7 @@ std::string ConfigServiceImpl::getPropertiesDir() const
  */
 std::string ConfigServiceImpl::getUserPropertiesDir() const
 {
-#ifdef _WIN32 
+#ifdef _WIN32
   return m_strBaseDir;
 #else
   Poco::Path datadir(m_pSysConfig->getString("system.homeDir"));
diff --git a/Code/Mantid/Framework/PythonAPI/src/FrameworkManagerProxy.cpp b/Code/Mantid/Framework/PythonAPI/src/FrameworkManagerProxy.cpp
index 0772e1d0021..57b62542bc5 100644
--- a/Code/Mantid/Framework/PythonAPI/src/FrameworkManagerProxy.cpp
+++ b/Code/Mantid/Framework/PythonAPI/src/FrameworkManagerProxy.cpp
@@ -185,15 +185,16 @@ std::string FrameworkManagerProxy::createAlgorithmDocs(const std::string& algNam
     names[i] = SimplePythonAPI::removeCharacters(properties[i]->name(), "");
   }
 
-  // write the actual properties
+  buffer << "Property descriptions: " << EOL << EOL;
+  // write the actual propertie descriptions
   Mantid::Kernel::Property *prop;
   for ( size_t i = 0; i < numProps; ++i) {
     prop = properties[i];
-    buffer << "  " << names[i] << "("
+    buffer << names[i] << "("
            << Mantid::Kernel::Direction::asText(prop->direction());
     if (!prop->isValid().empty())
       buffer << ":req";
-    buffer << ") *" << prop->type() << "* "<< "\n";
+    buffer << ") *" << prop->type() << "* "<< EOL;
     std::set<std::string> allowed = prop->allowedValues();
     if (!prop->documentation().empty() || !allowed.empty())
     {
@@ -211,7 +212,8 @@ std::string FrameworkManagerProxy::createAlgorithmDocs(const std::string& algNam
         }
         buffer << "]";
       }
-//      buffer << EOL; // TODO REMOVE
+      buffer << EOL;
+      if( i < numProps - 1 ) buffer << EOL;
     }
   }
 
-- 
GitLab