예제 #1
0
// Fetch VFileSessionInfo from @p_tabInfo.
VFileSessionInfo VFileSessionInfo::fromEditTabInfo(const VEditTabInfo *p_tabInfo)
{
    Q_ASSERT(p_tabInfo);
    VEditTab *tab = p_tabInfo->m_editTab;
    VFileSessionInfo info(tab->getFile()->fetchPath(),
                          tab->isEditMode() ? OpenFileMode::Edit : OpenFileMode::Read);
    info.m_headerIndex = p_tabInfo->m_headerIndex;
    info.m_cursorBlockNumber = p_tabInfo->m_cursorBlockNumber;
    info.m_cursorPositionInBlock = p_tabInfo->m_cursorPositionInBlock;

    return info;
}
예제 #2
0
파일: vmdeditor.cpp 프로젝트: vscanf/vnote
void VMdEditor::contextMenuEvent(QContextMenuEvent *p_event)
{
    QMenu *menu = createStandardContextMenu();
    menu->setToolTipsVisible(true);

    VEditTab *editTab = dynamic_cast<VEditTab *>(parent());
    Q_ASSERT(editTab);
    if (editTab->isEditMode()) {
        const QList<QAction *> actions = menu->actions();

        if (textCursor().hasSelection()) {
            initCopyAsMenu(actions.isEmpty() ? NULL : actions.last(), menu);
        } else {
            QAction *saveExitAct = new QAction(VIconUtils::menuIcon(":/resources/icons/save_exit.svg"),
                                               tr("&Save Changes And Read"),
                                               menu);
            saveExitAct->setToolTip(tr("Save changes and exit edit mode"));
            connect(saveExitAct, &QAction::triggered,
                    this, [this]() {
                        emit m_object->saveAndRead();
                    });

            QAction *discardExitAct = new QAction(VIconUtils::menuIcon(":/resources/icons/discard_exit.svg"),
                                                  tr("&Discard Changes And Read"),
                                                  menu);
            discardExitAct->setToolTip(tr("Discard changes and exit edit mode"));
            connect(discardExitAct, &QAction::triggered,
                    this, [this]() {
                        emit m_object->discardAndRead();
                    });

            menu->insertAction(actions.isEmpty() ? NULL : actions[0], discardExitAct);
            menu->insertAction(discardExitAct, saveExitAct);
        }

        if (!actions.isEmpty()) {
            menu->insertSeparator(actions[0]);
        }
    }

    menu->exec(p_event->globalPos());
    delete menu;
}