| 88 | } |
| 89 | |
| 90 | void DiffViewsCtrl::setupDiffActions(KTextEditor::View* view, const RepoStatusModel::Areas diffType) const |
| 91 | { |
| 92 | // Context Menu Setup |
| 93 | QMenu* ret = new QMenu; |
| 94 | if (diffType == RepoStatusModel::Index || diffType == RepoStatusModel::IndexRoot) { |
| 95 | ret->addAction(m_unstageSelectedAct); |
| 96 | } else if (diffType == RepoStatusModel::WorkTree || diffType == RepoStatusModel::WorkTreeRoot) { |
| 97 | ret->addAction(m_stageSelectedAct); |
| 98 | ret->addAction(m_revertSelectedAct); |
| 99 | } |
| 100 | ret->addAction(m_gotoSrcLineAct); |
| 101 | view->setContextMenu(ret); |
| 102 | |
| 103 | // Set the text of the actions based on whether some lines |
| 104 | // are selected or not |
| 105 | connect(view, &KTextEditor::View::contextMenuAboutToShow, this, [=] { |
| 106 | auto haveSelection = !view->selectionRange().isEmpty(); |
| 107 | if (haveSelection) { |
| 108 | m_unstageSelectedAct->setText(i18n("Unstage selected lines")); |
| 109 | m_stageSelectedAct->setText(i18n("Stage selected lines")); |
| 110 | m_revertSelectedAct->setText(i18n("Revert selected lines")); |
| 111 | } else { |
| 112 | m_unstageSelectedAct->setText(i18n("Unstage selected hunk")); |
| 113 | m_stageSelectedAct->setText(i18n("Stage selected hunk")); |
| 114 | m_revertSelectedAct->setText(i18n("Revert selected hunk")); |
| 115 | } |
| 116 | }); |
| 117 | |
| 118 | // Add the actions to the view action collection, so that |
| 119 | // shortcuts work and can be edited |
| 120 | auto actCollection = view->actionCollection(); |
| 121 | if (diffType == RepoStatusModel::Index || diffType == RepoStatusModel::IndexRoot) { |
| 122 | actCollection->addAction(QStringLiteral("git_unstage_selected"), m_unstageSelectedAct); |
| 123 | actCollection->addAction(QStringLiteral("git_goto_source"), m_gotoSrcLineAct); |
| 124 | actCollection->setDefaultShortcut(m_unstageSelectedAct, i18n("S")); |
| 125 | actCollection->setDefaultShortcut(m_gotoSrcLineAct, i18n("G")); |
| 126 | } else if (diffType == RepoStatusModel::WorkTree || diffType == RepoStatusModel::WorkTreeRoot) { |
| 127 | actCollection->addAction(QStringLiteral("git_stage_selected"), m_stageSelectedAct); |
| 128 | actCollection->addAction(QStringLiteral("git_revert_selected"), m_revertSelectedAct); |
| 129 | actCollection->addAction(QStringLiteral("git_goto_source"), m_gotoSrcLineAct); |
| 130 | actCollection->setDefaultShortcut(m_stageSelectedAct, i18n("S")); |
| 131 | actCollection->setDefaultShortcut(m_gotoSrcLineAct, i18n("G")); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | const QString DiffViewsCtrl::viewKey(const QUrl& url, RepoStatusModel::Areas area) |
| 136 | { |
nothing calls this directly
no test coverage detected