From 4642291e19a5a98d07c067baddf1b5fafbab943a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 12 Oct 2014 22:14:50 +0300 Subject: Fix popup menu for channel chat tab. --- src/gui/popups/popupmenu.cpp | 6 ++++-- src/gui/widgets/tabs/chat/channeltab.cpp | 24 ++++++++++++++++++++++++ src/gui/widgets/tabs/chat/channeltab.h | 3 +++ src/gui/widgets/tabs/chat/chattab.h | 2 +- src/gui/windows/chatwindow.cpp | 29 ++++++++++++++++++----------- src/gui/windows/chatwindow.h | 3 +++ 6 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index 57dd21fca..2670b5384 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -685,7 +685,8 @@ void PopupMenu::showChatPopup(const int x, const int y, ChatTab *const tab) mBrowserBox->clearRows(); - if (tab->getType() == static_cast(ChatTabType::WHISPER)) + const ChatTabType::Type &type = tab->getType(); + if (type == ChatTabType::WHISPER || type == ChatTabType::CHANNEL) { // TRANSLATORS: popup menu item // TRANSLATORS: close chat tab @@ -746,7 +747,7 @@ void PopupMenu::showChatPopup(const int x, const int y, ChatTab *const tab) mBrowserBox->addRow("chat clipboard", _("Copy to clipboard")); mBrowserBox->addRow("##3---"); - if (tab->getType() == static_cast(ChatTabType::WHISPER)) + if (type == ChatTabType::WHISPER) { const WhisperTab *const wTab = static_cast(tab); std::string name = wTab->getNick(); @@ -847,6 +848,7 @@ void PopupMenu::showChatPopup(const int x, const int y, ChatTab *const tab) mBrowserBox->addRow("##3---"); } } + addWindowMenu(chatWindow); // TRANSLATORS: popup menu item // TRANSLATORS: close menu diff --git a/src/gui/widgets/tabs/chat/channeltab.cpp b/src/gui/widgets/tabs/chat/channeltab.cpp index f4b26f4bc..43ba86acf 100644 --- a/src/gui/widgets/tabs/chat/channeltab.cpp +++ b/src/gui/widgets/tabs/chat/channeltab.cpp @@ -25,6 +25,8 @@ #include "chatlogger.h" #include "configuration.h" +#include "gui/widgets/windowcontainer.h" + #include "gui/windows/chatwindow.h" #include "net/chathandler.h" @@ -40,6 +42,8 @@ ChannelTab::ChannelTab(const Widget2 *const widget, ChannelTab::~ChannelTab() { + if (chatWindow) + chatWindow->removeChannel(mChannelName); } void ChannelTab::handleInput(const std::string &msg) @@ -48,3 +52,23 @@ void ChannelTab::handleInput(const std::string &msg) newMsg = ChatWindow::doReplace(msg); chatHandler->privateMessage(mChannelName, newMsg); } + +bool ChannelTab::handleCommand(const std::string &restrict type, + const std::string &restrict args A_UNUSED) +{ + if (type == "close") + { + if (windowContainer) + windowContainer->scheduleDelete(this); + else + delete this; + if (chatWindow) + chatWindow->defaultTab(); + } + else + { + return false; + } + + return true; +} diff --git a/src/gui/widgets/tabs/chat/channeltab.h b/src/gui/widgets/tabs/chat/channeltab.h index 4ca3d9379..33ed49987 100644 --- a/src/gui/widgets/tabs/chat/channeltab.h +++ b/src/gui/widgets/tabs/chat/channeltab.h @@ -41,6 +41,9 @@ class ChannelTab final : public ChatTab protected: void handleInput(const std::string &msg) override final; + + bool handleCommand(const std::string &restrict type, + const std::string &restrict args) override final; }; #endif // GUI_WIDGETS_TABS_CHAT_CHANNELTAB_H diff --git a/src/gui/widgets/tabs/chat/chattab.h b/src/gui/widgets/tabs/chat/chattab.h index 41a02030e..f60a5bc85 100644 --- a/src/gui/widgets/tabs/chat/chattab.h +++ b/src/gui/widgets/tabs/chat/chattab.h @@ -134,7 +134,7 @@ class ChatTab notfinal : public Tab /** * Returns type of the being. */ - int getType() const A_WARN_UNUSED + ChatTabType::Type getType() const A_WARN_UNUSED { return mType; } void saveToLogFile(std::string msg) const; diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index 3a59279cc..357c76911 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -64,6 +64,8 @@ #include "gui/widgets/tabs/chat/tradetab.h" #include "gui/widgets/tabs/chat/whispertab.h" +#include "input/inputmanager.h" + #include "render/opengldebug.h" #include "net/chathandler.h" @@ -378,15 +380,13 @@ void ChatWindow::closeTab() const if (!mChatTabs) return; - Tab *const tab = mChatTabs->getTabByIndex( - mChatTabs->getSelectedTabIndex()); + ChatTab *const tab = dynamic_cast(mChatTabs->getTabByIndex( + mChatTabs->getSelectedTabIndex())); if (!tab) return; - WhisperTab *const whisper = dynamic_cast(tab); - if (!whisper) - return; - - whisper->handleCommand("close", ""); + const ChatTabType::Type &type = tab->getType(); + if (type == ChatTabType::WHISPER || type == ChatTabType::CHANNEL) + tab->handleCommand("close", ""); } void ChatWindow::defaultTab() @@ -546,6 +546,13 @@ void ChatWindow::removeWhisper(const std::string &nick) mWhispers.erase(tempNick); } +void ChatWindow::removeChannel(const std::string &name) +{ + std::string tempName = name; + toLower(tempName); + mChannels.erase(tempName); +} + void ChatWindow::removeAllWhispers() { std::list tabs; @@ -681,16 +688,16 @@ void ChatWindow::mousePressed(MouseEvent &event) if (tab) { event.consume(); + ChatTab *const cTab = dynamic_cast(tab); if (inputManager.isActionActive(static_cast( InputAction::CHAT_MOD))) { - ChatTab *const wTab = dynamic_cast(tab); - if (wTab) - wTab->handleCommand("close", ""); + inputManager.executeChatCommand( + InputAction::CLOSE_CHAT_TAB, + std::string(), cTab); } else { - ChatTab *const cTab = dynamic_cast(tab); if (cTab) { popupMenu->showChatPopup(viewport->mMouseX, diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h index 313a65803..acecdcaf2 100644 --- a/src/gui/windows/chatwindow.h +++ b/src/gui/windows/chatwindow.h @@ -294,6 +294,7 @@ class ChatWindow final : public Window, #endif protected: + friend class ChannelTab; friend class ChatTab; friend class WhisperTab; friend class PopupMenu; @@ -308,6 +309,8 @@ class ChatWindow final : public Window, void removeWhisper(const std::string &nick); + void removeChannel(const std::string &nick); + void autoComplete(); std::string addColors(std::string &msg); -- cgit v1.2.3-70-g09d2