Browse Source

Improved replaceInPlace().
Focus FileSelector file list initially.

Lasse Öörni 15 years ago
parent
commit
d02e959f9a
2 changed files with 7 additions and 5 deletions
  1. 4 5
      Engine/Common/StringUtils.cpp
  2. 3 0
      Engine/UI/FileSelector.cpp

+ 4 - 5
Engine/Common/StringUtils.cpp

@@ -130,17 +130,16 @@ void replaceInPlace(std::string& str, char replaceThis, char replaceWith)
 
 
 void replaceInPlace(std::string& str, const std::string& replaceThis, const std::string& replaceWith)
 void replaceInPlace(std::string& str, const std::string& replaceThis, const std::string& replaceWith)
 {
 {
-    // Check for possibility of infinite loop and terminate in that case
-    if (replaceWith.find(replaceThis) != std::string::npos)
-        return;
+    size_t nextIndex = 0;
     
     
-    for (;;)
+    while (nextIndex < str.length())
     {
     {
-        size_t index = str.find(replaceThis);
+        size_t index = str.find(replaceThis, nextIndex);
         if (index == std::string::npos)
         if (index == std::string::npos)
             break;
             break;
         
         
         str.replace(index, replaceThis.length(), replaceWith);
         str.replace(index, replaceThis.length(), replaceWith);
+        nextIndex = index + replaceWith.length();
     }
     }
 }
 }
 
 

+ 3 - 0
Engine/UI/FileSelector.cpp

@@ -113,6 +113,9 @@ FileSelector::FileSelector(UI* ui) :
     subscribeToEvent(mFileList, EVENT_ITEMDOUBLECLICKED, EVENT_HANDLER(FileSelector, handleFileDoubleClicked));
     subscribeToEvent(mFileList, EVENT_ITEMDOUBLECLICKED, EVENT_HANDLER(FileSelector, handleFileDoubleClicked));
     subscribeToEvent(mOKButton, EVENT_PRESSED, EVENT_HANDLER(FileSelector, handleOKPressed));
     subscribeToEvent(mOKButton, EVENT_PRESSED, EVENT_HANDLER(FileSelector, handleOKPressed));
     subscribeToEvent(mCancelButton, EVENT_PRESSED, EVENT_HANDLER(FileSelector, handleCancelPressed));
     subscribeToEvent(mCancelButton, EVENT_PRESSED, EVENT_HANDLER(FileSelector, handleCancelPressed));
+    
+    // Focus the file list initially
+    mUI->setFocusElement(mFileList);
 }
 }
 
 
 FileSelector::~FileSelector()
 FileSelector::~FileSelector()