Esempio n. 1
0
void ItemLinkHandler::handleLink(const std::string &link, MouseEvent *event)
{
    if (strStartWith(link, "http://") || strStartWith(link, "https://"))
    {
        if (!event)
            return;
        std::string url = link;
        replaceAll(url, " ", "");
        listener.url = url;
        const MouseButton::Type button = event->getButton();
        if (button == MouseButton::LEFT)
        {
            ConfirmDialog *const confirmDlg = new ConfirmDialog(
                // TRANSLATORS: dialog message
                _("Open url"), url, SOUND_REQUEST, false, Modal_true);
            confirmDlg->postInit();
            confirmDlg->addActionListener(&listener);
        }
        else if (button == MouseButton::RIGHT)
        {
            if (popupMenu)
                popupMenu->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 (!itemPopup || link.empty())
            return;

        const char ch = link[0];
        if (ch < '0' || ch > '9')
            return;

        std::vector<int> str;
        splitToIntVector(str, link, ',');
        if (str.empty())
            return;
        unsigned char color = 1;
        if (str.size() > 1)
            color = static_cast<unsigned char>(str[1]);
        const int id = str[0];
        if (id > 0)
        {
            const ItemInfo &itemInfo = ItemDB::get(id);
            itemPopup->setItem(itemInfo, color, true);
            if (itemPopup->isPopupVisible())
            {
                itemPopup->setVisible(false);
            }
            else if (viewport)
            {
                itemPopup->position(viewport->mMouseX,
                    viewport->mMouseY);
            }
        }
    }
}
Esempio n. 2
0
void Setup_Input::action(const ActionEvent &event)
{
    const std::string &id = event.getId();
    const int selectedData = mKeyListModel->getSelectedData();

    if (event.getSource() == mKeyList)
    {
        if (!mKeySetting)
        {
            const int i(mKeyList->getSelected());
            if (i >= 0 && i < mActionDataSize[selectedData])
            {
                if (setupActionData[selectedData][i].actionId
                    == InputAction::NO_VALUE)
                {
                    mAssignKeyButton->setEnabled(false);
                    mUnassignKeyButton->setEnabled(false);
                }
                else
                {
                    mAssignKeyButton->setEnabled(true);
                    mUnassignKeyButton->setEnabled(true);
                }
            }
        }
    }
    else if (id == "assign")
    {
        mKeySetting = true;
        mAssignKeyButton->setEnabled(false);
        keyboard.setEnabled(false);
        const int i(mKeyList->getSelected());
        if (i >= 0 && i < mActionDataSize[selectedData])
        {
            const SetupActionData &key = setupActionData[selectedData][i];
            const InputActionT ik = key.actionId;
            inputManager.setNewKeyIndex(ik);
            mKeyListModel->setElementAt(i, std::string(
                gettext(key.name.c_str())).append(": ?"));
        }
    }
    else if (id == "unassign")
    {
        const int i(mKeyList->getSelected());
        if (i >= 0 && i < mActionDataSize[selectedData])
        {
            const SetupActionData &key = setupActionData[selectedData][i];
            const InputActionT ik = key.actionId;
            inputManager.setNewKeyIndex(ik);
            refreshAssignedKey(mKeyList->getSelected());
            inputManager.unassignKey();
            inputManager.setNewKeyIndex(InputAction::NO_VALUE);
        }
        mAssignKeyButton->setEnabled(true);
    }
    else if (id == "resetkeys")
    {
        inputManager.resetKeys();
        InputManager::update();
        refreshKeys();
    }
    else if (id == "default")
    {
        const int i(mKeyList->getSelected());
        if (i >= 0 && i < mActionDataSize[selectedData])
        {
            const SetupActionData &key = setupActionData[selectedData][i];
            const InputActionT ik = key.actionId;
            inputManager.makeDefault(ik);
            refreshKeys();
        }
    }
    else if (strStartWith(id, "tabs_"))
    {
        int k = 0;
        std::string str("tabs_");
        while (pages[k] != nullptr)
        {
            if (str + pages[k] == id)
                break;
            k ++;
        }
        if ((pages[k] != nullptr) && str + pages[k] == id)
        {
            mKeyListModel->setSelectedData(k);
            mKeyListModel->setSize(mActionDataSize[k]);
            refreshKeys();
            mKeyList->setSelected(0);
        }
    }
}