MCPcopy Create free account
hub / github.com/KDE/kdevelop / setupDiffActions

Method setupDiffActions

plugins/git/diffviewsctrl.cpp:90–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90void 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
135const QString DiffViewsCtrl::viewKey(const QUrl& url, RepoStatusModel::Areas area)
136{

Callers

nothing calls this directly

Calls 4

addActionMethod · 0.45
isEmptyMethod · 0.45
setTextMethod · 0.45
actionCollectionMethod · 0.45

Tested by

no test coverage detected