summaryrefslogtreecommitdiff
path: root/src/gui/chat.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2010-01-08 16:03:29 +0200
committerBlue <bluesansdouze@gmail.com>2010-01-08 23:05:32 +0100
commitc1ddf4c0840bb15016dc69af4a4751d09908393f (patch)
tree26b8f6a28a469a64208eb9f475fb5e26de13b29b /src/gui/chat.cpp
parent9b6e5a3189311d5704993d41a1fa195e006a57af (diff)
downloadmana-client-c1ddf4c0840bb15016dc69af4a4751d09908393f.tar.gz
mana-client-c1ddf4c0840bb15016dc69af4a4751d09908393f.tar.bz2
mana-client-c1ddf4c0840bb15016dc69af4a4751d09908393f.tar.xz
mana-client-c1ddf4c0840bb15016dc69af4a4751d09908393f.zip
Small refactoring in chat auto completing
Diffstat (limited to 'src/gui/chat.cpp')
-rw-r--r--src/gui/chat.cpp58
1 files changed, 42 insertions, 16 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index af0c3808..c9defe33 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -531,13 +531,16 @@ void ChatWindow::autoComplete()
ChatTab *cTab = static_cast<ChatTab*>(mChatTabs->getSelectedTab());
+ std::vector<std::string> nameList;
if (cTab && cTab->getType() == ChatTab::PARTY)
{
- newName = partyWindow->getAutoCompleteName(name);
+ partyWindow->getNames(nameList);
+ newName = autoComplete(nameList, name);
}
if (newName == "")
{
- newName = beingManager->getAutoCompletePlayerName(name);
+ beingManager->getPlayerNames(nameList, true);
+ newName = autoComplete(nameList, name);
}
if (newName == "")
{
@@ -556,10 +559,44 @@ void ChatWindow::autoComplete()
}
}
+std::string ChatWindow::autoComplete(std::vector<std::string> &names,
+ std::string partName) const
+{
+ std::vector<std::string>::iterator i = names.begin();
+ toLower(partName);
+ std::string newName("");
+
+ while (i != names.end())
+ {
+ if (!i->empty())
+ {
+ std::string name = *i;
+ toLower(name);
+
+ std::string::size_type pos = name.find(partName, 0);
+ if (pos == 0)
+ {
+ if (newName != "")
+ {
+ toLower(newName);
+ newName = findSameSubstring(name, newName);
+ }
+ else
+ {
+ newName = *i;
+ }
+ }
+ }
+ ++i;
+ }
+
+ return newName;
+}
+
std::string ChatWindow::autoCompleteHistory(std::string partName)
{
History::iterator i = mHistory.begin();
- std::string newName = "";
+ std::vector<std::string> nameList;
while (i != mHistory.end())
{
@@ -572,20 +609,9 @@ std::string ChatWindow::autoCompleteHistory(std::string partName)
line = line.substr(0, f);
if (line != "")
{
- std::string::size_type pos = line.find(partName, 0);
- if (pos == 0)
- {
- if (newName != "")
- {
- newName = findSameSubstring(line, newName);
- }
- else
- {
- newName = line;
- }
- }
+ nameList.push_back(line);
}
++i;
}
- return newName;
+ return autoComplete(nameList, partName);
}