summaryrefslogtreecommitdiff
path: root/src/gui/windows
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-31 13:13:47 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-31 13:13:47 +0300
commit1072eecf0e9e9140796d24f82d077199b2a1d9e6 (patch)
tree2c90f4f56a735cb184e90519650d7e2ac1db6eb9 /src/gui/windows
parentc0197404a15a3937ef3cd21f48a09e691a96518f (diff)
downloadmanaplus-1072eecf0e9e9140796d24f82d077199b2a1d9e6.tar.gz
manaplus-1072eecf0e9e9140796d24f82d077199b2a1d9e6.tar.bz2
manaplus-1072eecf0e9e9140796d24f82d077199b2a1d9e6.tar.xz
manaplus-1072eecf0e9e9140796d24f82d077199b2a1d9e6.zip
Add to chat history enteerd text if was pressed up or down key.
Diffstat (limited to 'src/gui/windows')
-rw-r--r--src/gui/windows/chatwindow.cpp18
-rw-r--r--src/gui/windows/chatwindow.h2
2 files changed, 20 insertions, 0 deletions
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index c6b3d0987..6c5219b01 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -728,6 +728,7 @@ void ChatWindow::keyPressed(KeyEvent &event)
{
// Move forward through the history
const HistoryIterator prevHist = mCurHist++;
+ addCurrentToHistory();
if (mCurHist != mHistory.end())
{
@@ -743,6 +744,8 @@ void ChatWindow::keyPressed(KeyEvent &event)
}
else if (!mChatInput->getText().empty())
{
+ if (addCurrentToHistory())
+ mCurHist = mHistory.end();
mChatInput->setText("");
}
}
@@ -751,6 +754,7 @@ void ChatWindow::keyPressed(KeyEvent &event)
{
// Move backward through the history
--mCurHist;
+ addCurrentToHistory();
mChatInput->setText(*mCurHist);
mChatInput->setCaretPosition(static_cast<unsigned>(
mChatInput->getText().length()));
@@ -890,6 +894,20 @@ void ChatWindow::keyPressed(KeyEvent &event)
#undef ifKey
+bool ChatWindow::addCurrentToHistory()
+{
+ const std::string str = mChatInput->getText();
+ if (str.empty())
+ return false;
+ FOR_EACH (HistoryIterator, it, mHistory)
+ {
+ if (*it == str)
+ return false;
+ }
+ mHistory.push_back(str);
+ return true;
+}
+
void ChatWindow::statChanged(const int id,
const int oldVal1,
const int oldVal2)
diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h
index b90b15b45..d6b89fbd1 100644
--- a/src/gui/windows/chatwindow.h
+++ b/src/gui/windows/chatwindow.h
@@ -329,6 +329,8 @@ class ChatWindow final : public Window,
void updateTabsMargin();
+ bool addCurrentToHistory();
+
typedef std::map<const std::string, WhisperTab*> TabMap;
/** Manage whisper tabs */
TabMap mWhispers;