int CWizEditorToolBar::buildMenu(QMenu* pMenu, int indx)
{
    int index = indx;
    bool bSkip = false;
    WizEditorContextMenuItem* arrayData = contextMenuData();

    WizEditorContextMenuItem& curItem = arrayData[index];
    if (curItem.command != "+") {
        int value = m_editor->editorCommandQueryCommandState(curItem.command);
        if (value == -1) {
            bSkip = true;
        }
    }

    QMenu* pSubMenu = new QMenu(curItem.label, pMenu);

    if (!bSkip) {
        pMenu->addMenu(pSubMenu);
    }

    while(1) {
        index++;

        WizEditorContextMenuItem& item = arrayData[index];
        if (item.label == "+") {
            break;

        } else if (item.label == "-") {
            pSubMenu->addSeparator();

        } else if (item.command != "+" && !item.execute.isEmpty()) {

            // special case
            if (m_editor->editorCommandQueryLink()
                    && item.label == WIZEDITOR_ACTION_LINK_INSERT) {
                continue;
            } else if (!m_editor->editorCommandQueryLink()
                       && item.label == WIZEDITOR_ACTION_LINK_EDIT) {
                continue;
            }

            if (!item.command.isEmpty()) {
                int value = m_editor->editorCommandQueryCommandState(item.command);
                if (value == -1) {
                    continue;
                }
            }

            QString strSlot = "1" + item.execute + "()";
            m_actions[item.label] = pSubMenu->addAction(item.label, m_editor, strSlot.toUtf8());

        } else if (item.command.isEmpty() && item.execute.isEmpty()) {
            continue;
        } else {
            Q_ASSERT(0);
        }
    }

    return index;
}
void CWizEditorToolBar::buildMenu()
{
    if (!m_menuContext) {
        m_menuContext = new QMenu(this);
    }

    m_menuContext->clear();

    int index = 0;
    WizEditorContextMenuItem* arrayData = contextMenuData();
    MainWindow* mainWindow = qobject_cast<MainWindow *>(m_app.mainWindow());
    while (1) {
        WizEditorContextMenuItem& item = arrayData[index];
        if (item.label.isEmpty() && item.command.isEmpty() && item.execute.isEmpty()) {
            break;

        } else if (item.label == "-") {
            m_menuContext->addSeparator();

        } else if (item.execute == "+") {
            index = buildMenu(m_menuContext, index);

        } else if (item.command != "+" && !item.execute.isEmpty()) {
            if (!item.command.isEmpty()) {
                int value = mainWindow->web()->editorCommandQueryCommandState(item.command);
                if (value == -1) {
                    index++;
                    continue;
                }
            }

            QString strSlot = "1" + item.execute + "()";
            m_menuContext->addAction(item.label, mainWindow->web(), strSlot.toUtf8());
        } else if (item.command.isEmpty() && item.execute.isEmpty()) {
            index++;
            continue;
        } else {
            Q_ASSERT(0);
        }

        index++;
    }
}
Beispiel #3
0
void WebContentsViewQt::ShowContextMenu(content::RenderFrameHost *, const content::ContextMenuParams &params)
{
    WebEngineContextMenuData contextMenuData(fromParams(params));
    m_client->contextMenuRequested(contextMenuData);
}