summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-04-05 04:38:10 +0300
committerAndrei Karas <akaras@inbox.ru>2011-04-05 04:38:10 +0300
commit81fd600ac9a941b1ee06e41d322399d19fc4dcaa (patch)
tree27a2075c419057d5445c7a33b652aa1b4fbde12c
parentc758ce6cde782ff8866b4624c1ba28f1e0db1e35 (diff)
downloadmanaplus-81fd600ac9a941b1ee06e41d322399d19fc4dcaa.tar.gz
manaplus-81fd600ac9a941b1ee06e41d322399d19fc4dcaa.tar.bz2
manaplus-81fd600ac9a941b1ee06e41d322399d19fc4dcaa.tar.xz
manaplus-81fd600ac9a941b1ee06e41d322399d19fc4dcaa.zip
Add custom autocomplate list from file customwords.txt
-rw-r--r--src/gui/chatwindow.cpp36
-rw-r--r--src/gui/chatwindow.h8
2 files changed, 38 insertions, 6 deletions
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index 1e530ecba..0b9945370 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -190,6 +190,7 @@ ChatWindow::ChatWindow():
fillCommands();
initTradeFilter();
+ loadCustomList();
}
ChatWindow::~ChatWindow()
@@ -1093,12 +1094,14 @@ void ChatWindow::autoComplete()
if (newName == "" && spellManager)
newName = spellManager->autoComplete(name);
if (newName == "")
- newName = autoCompleteCommands(name);
+ newName = autoComplete(name, &mCommands);
if (newName == "" && actorSpriteManager)
{
actorSpriteManager->getMobNames(nameList);
newName = autoComplete(nameList, name);
}
+ if (newName == "")
+ newName = autoComplete(name, &mCustomWords);
if (newName != "")
{
@@ -1149,12 +1152,15 @@ std::string ChatWindow::autoComplete(std::vector<std::string> &names,
return newName;
}
-std::string ChatWindow::autoCompleteCommands(std::string partName)
+std::string ChatWindow::autoComplete(std::string partName, History *words)
{
- Commands::iterator i = mCommands.begin();
+ if (!words)
+ return "";
+
+ Commands::iterator i = words->begin();
std::vector<std::string> nameList;
- while (i != mCommands.end())
+ while (i != words->end())
{
std::string line = *i;
std::string::size_type pos = line.find(partName, 0);
@@ -1414,3 +1420,25 @@ std::string ChatWindow::doReplace(const std::string &msg)
replaceSpecialChars(str);
return str;
}
+
+void ChatWindow::loadCustomList()
+{
+ std::ifstream listFile;
+ struct stat statbuf;
+
+ std::string listName = Client::getServerConfigDirectory()
+ + "/customwords.txt";
+
+ if (!stat(listName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode))
+ {
+ listFile.open(listName.c_str(), std::ios::in);
+ char line[101];
+ while (listFile.getline(line, 100))
+ {
+ std::string str = line;
+ if (!str.empty())
+ mCustomWords.push_back(str);
+ }
+ listFile.close();
+ }
+}
diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h
index 97f586442..1b10405d4 100644
--- a/src/gui/chatwindow.h
+++ b/src/gui/chatwindow.h
@@ -242,6 +242,8 @@ class ChatWindow : public Window,
void saveState();
+ void loadCustomList();
+
std::string doReplace(const std::string &msg);
protected:
@@ -249,6 +251,8 @@ class ChatWindow : public Window,
friend class WhisperTab;
friend class PopupMenu;
+ typedef std::list<std::string> History;
+
/** Remove the given tab from the window */
void removeTab(ChatTab *tab);
@@ -265,7 +269,7 @@ class ChatWindow : public Window,
std::string autoCompleteHistory(std::string partName);
- std::string autoCompleteCommands(std::string partName);
+ std::string autoComplete(std::string partName, History *words);
std::string autoComplete(std::vector<std::string> &names,
std::string partName) const;
@@ -294,7 +298,6 @@ class ChatWindow : public Window,
/** Manage whisper tabs */
TabMap mWhispers;
- typedef std::list<std::string> History;
typedef History::iterator HistoryIterator;
History mHistory; /**< Command history. */
HistoryIterator mCurHist; /**< History iterator. */
@@ -302,6 +305,7 @@ class ChatWindow : public Window,
typedef std::list<std::string> Commands;
typedef Commands::iterator CommandsIterator;
History mCommands; /**< Command list. */
+ History mCustomWords;
bool mReturnToggles; /**< Marks whether <Return> toggles the chat log
or not */