From 8a068ecd9dd6d41ba49f258107b09b98a8ea1a6d Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Sat, 16 Jul 2011 00:45:25 +0300
Subject: Add hotkey to close selected chat tab.

---
 src/game.cpp           |  5 +++++
 src/gui/chatwindow.cpp | 16 ++++++++++++++++
 src/gui/chatwindow.h   |  5 +++++
 src/keyboardconfig.cpp |  3 +++
 src/keyboardconfig.h   |  1 +
 5 files changed, 30 insertions(+)

(limited to 'src')

diff --git a/src/game.cpp b/src/game.cpp
index 259317545..623d2a069 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -716,6 +716,11 @@ void Game::handleInput()
                     socialWindow->nextTab();
                     return;
                 }
+                else if (keyboard.isKeyActive(keyboard.KEY_CLOSE_CHAT_TAB))
+                {
+                    chatWindow->closeTab();
+                    return;
+                }
             }
 
             const int tKey = keyboard.getKeyIndex(event.key.keysym.sym);
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index 29ce3bace..c266374ef 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -396,6 +396,22 @@ void ChatWindow::nextTab()
     mChatTabs->setSelectedTab(tab);
 }
 
+void ChatWindow::closeTab()
+{
+    if (!mChatTabs)
+        return;
+
+    int idx = mChatTabs->getSelectedTabIndex();
+    Tab *tab = mChatTabs->getTabByIndex(idx);
+    if (!tab)
+        return;
+    WhisperTab *whisper = dynamic_cast<WhisperTab*>(tab);
+    if (!whisper)
+        return;
+
+    whisper->handleCommand("close", "");
+}
+
 void ChatWindow::defaultTab()
 {
     if (mChatTabs)
diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h
index 05e039c60..b6a37ef79 100644
--- a/src/gui/chatwindow.h
+++ b/src/gui/chatwindow.h
@@ -129,6 +129,11 @@ class ChatWindow : public Window,
          */
         void nextTab();
 
+        /**
+         * Close current chat tab
+         */
+        void closeTab();
+
         /**
          * Switch to the default tab
          */
diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp
index ff504ca2d..8ad38ab76 100644
--- a/src/keyboardconfig.cpp
+++ b/src/keyboardconfig.cpp
@@ -274,6 +274,9 @@ static KeyData const keyData[KeyboardConfig::KEY_TOTAL] = {
         KeyboardConfig::GRP_DEFAULT | KeyboardConfig::GRP_GUI},
     {"keyChatNextTab", SDLK_KP9, N_("Next Chat Tab"),
         KeyboardConfig::GRP_DEFAULT | KeyboardConfig::GRP_GUI},
+    {"keyChatCloseTab", KeyboardConfig::KEY_NO_VALUE,
+        N_("Close current Chat Tab"), KeyboardConfig::GRP_DEFAULT
+        | KeyboardConfig::GRP_GUI},
     {"keyChatPrevHistory", SDLK_KP7, N_("Previous chat line"),
         KeyboardConfig::GRP_CHAT},
     {"keyChatNextHistory", SDLK_KP9, N_("Next chat line"),
diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h
index 1d264b039..43bb1c17f 100644
--- a/src/keyboardconfig.h
+++ b/src/keyboardconfig.h
@@ -276,6 +276,7 @@ class KeyboardConfig
             KEY_SCROLL_CHAT_DOWN,
             KEY_PREV_CHAT_TAB,
             KEY_NEXT_CHAT_TAB,
+            KEY_CLOSE_CHAT_TAB,
             KEY_CHAT_PREV_HISTORY,
             KEY_CHAT_NEXT_HISTORY,
             KEY_AUTOCOMPLETE_CHAT,
-- 
cgit v1.2.3-70-g09d2