From 0e21b478636fac986a5e2276662da6a6e1692f9e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 18 Feb 2013 15:34:03 +0300 Subject: Add support for help seach links. To add link to search text: /url ?text Also add support for links in format: help://topic --- src/gui/widgets/itemlinkhandler.cpp | 59 ++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 21 deletions(-) (limited to 'src/gui/widgets/itemlinkhandler.cpp') diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp index 24b487f53..e708eb507 100644 --- a/src/gui/widgets/itemlinkhandler.cpp +++ b/src/gui/widgets/itemlinkhandler.cpp @@ -25,6 +25,7 @@ #include "item.h" #include "gui/confirmdialog.h" +#include "gui/helpwindow.h" #include "gui/itempopup.h" #include "gui/viewport.h" @@ -64,7 +65,43 @@ ItemLinkHandler::~ItemLinkHandler() void ItemLinkHandler::handleLink(const std::string &link, gcn::MouseEvent *event) { - if (!strStartWith(link, "http://") && !strStartWith(link, "https://")) + if (strStartWith(link, "http://") || strStartWith(link, "https://")) + { + if (!event) + return; + std::string url = link; + replaceAll(url, " ", ""); + listener.url = url; + 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); + } + } + else if (!link.empty() && link[0] == '?') + { + if (helpWindow) + { + helpWindow->search(link.substr(1)); + helpWindow->requestMoveToTop(); + } + } + else if (strStartWith(link, "help://")) + { + if (helpWindow) + { + helpWindow->loadHelp(link.substr(7)); + helpWindow->requestMoveToTop(); + } + } + else { if (!mItemPopup) return; @@ -91,24 +128,4 @@ void ItemLinkHandler::handleLink(const std::string &link, } } } - else - { - if (!event) - return; - std::string url = link; - replaceAll(url, " ", ""); - listener.url = url; - 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