From 70d4f24f38a4036f84c1f71803173199e95ad675 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 16 Jan 2013 14:41:11 +0300 Subject: Add context menu to browserbox http links. --- src/gui/chatwindow.cpp | 3 +++ src/gui/popupmenu.cpp | 27 +++++++++++++++++++++++++++ src/gui/popupmenu.h | 2 ++ src/gui/viewport.cpp | 5 +++++ src/gui/viewport.h | 2 ++ src/gui/widgets/browserbox.cpp | 1 + src/gui/widgets/itemlinkhandler.cpp | 20 ++++++++++++++++---- 7 files changed, 56 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index c9c061be2..f14002827 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -718,6 +718,9 @@ void ChatWindow::scroll(const int amount) const void ChatWindow::mousePressed(gcn::MouseEvent &event) { + if (event.isConsumed()) + return; + if (event.getButton() == gcn::MouseEvent::RIGHT) { if (viewport) diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 844fc4e3f..807f5413e 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -69,7 +69,9 @@ #include "resources/iteminfo.h" +#include "utils/copynpaste.h" #include "utils/gettext.h" +#include "utils/process.h" #include @@ -1549,6 +1551,14 @@ void PopupMenu::handleLink(const std::string &link, if (mTextField) mTextField->handlePaste(); } + else if (link == "open link" && !mNick.empty()) + { + openBrowser(mNick); + } + else if (link == "clipboard link" && !mNick.empty()) + { + sendBuffer(mNick); + } else if (!link.compare(0, 10, "guild-pos-")) { if (player_node) @@ -2079,6 +2089,23 @@ void PopupMenu::showTextFieldPopup(int x, int y, TextField *input) showPopup(x, y); } +void PopupMenu::showLinkPopup(const int x, const int y, + const std::string &link) +{ + mX = x; + mY = y; + mNick = link; + + mBrowserBox->clearRows(); + + mBrowserBox->addRow("open link", _("Open link")); + mBrowserBox->addRow("clipboard link", _("Copy to clipboard")); + mBrowserBox->addRow("##3---"); + mBrowserBox->addRow("cancel", _("Cancel")); + + showPopup(x, y); +} + void PopupMenu::showPopup(int x, int y) { const int pad2 = 2 * getPadding(); diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index e2397d7db..1f1229e40 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -171,6 +171,8 @@ class PopupMenu final : public Popup, public LinkHandler void showTextFieldPopup(int x, int y, TextField *input); + void showLinkPopup(const int x, const int y, const std::string &link); + /** * Handles link action. */ diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 4b7a86fe6..3d8490dc5 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -821,6 +821,11 @@ void Viewport::showTextFieldPopup(TextField *input) mPopupMenu->showTextFieldPopup(getMouseX(), getMouseY(), input); } +void Viewport::showLinkPopup(const std::string &link) +{ + mPopupMenu->showLinkPopup(getMouseX(), getMouseY(), link); +} + void Viewport::closePopupMenu() { if (mPopupMenu) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 6953a3827..a3d545b61 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -185,6 +185,8 @@ class Viewport final : public WindowContainer, void showTextFieldPopup(TextField *input); + void showLinkPopup(const std::string &link); + /** * Closes the popup menu. Needed for when the player dies or switching * maps. diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 26d446060..34dfb50bf 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -355,6 +355,7 @@ void BrowserBox::mousePressed(gcn::MouseEvent &event) if (i != mLinks.end()) mLinkHandler->handleLink(i->link, &event); + event.consume(); } void BrowserBox::mouseMoved(gcn::MouseEvent &event) diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp index 293eb5237..4c5baa8a5 100644 --- a/src/gui/widgets/itemlinkhandler.cpp +++ b/src/gui/widgets/itemlinkhandler.cpp @@ -35,6 +35,7 @@ #include #include +#include #include "debug.h" @@ -61,7 +62,7 @@ ItemLinkHandler::~ItemLinkHandler() } void ItemLinkHandler::handleLink(const std::string &link, - gcn::MouseEvent *event A_UNUSED) + gcn::MouseEvent *event) { if (!strStartWith(link, "http://")) { @@ -92,11 +93,22 @@ void ItemLinkHandler::handleLink(const std::string &link, } else { + if (!event) + return; std::string url = link; replaceAll(url, " ", ""); listener.url = url; - ConfirmDialog *const confirmDlg = new ConfirmDialog( - _("Open url"), url, false, true); - confirmDlg->addActionListener(&listener); + const int button = event->getButton(); + if (button == gcn::MouseInput::LEFT) + { + ConfirmDialog *const confirmDlg = new ConfirmDialog( + _("Open url"), url, false, true); + confirmDlg->addActionListener(&listener); + } + else if (button == gcn::MouseInput::RIGHT) + { + if (viewport) + viewport->showLinkPopup(url); + } } } -- cgit v1.2.3-70-g09d2