Add context menu to status tree: View Diff(s), Open File(s)
This commit is contained in:
parent
63bc6680c4
commit
dcc5218ad7
|
|
@ -200,6 +200,7 @@ GitPlusPlusView::GitPlusPlusView(GitPlusPlusPlugin *plugin, KTextEditor::MainWin
|
||||||
m_treeView->setSelectionMode(QTreeView::ExtendedSelection);
|
m_treeView->setSelectionMode(QTreeView::ExtendedSelection);
|
||||||
m_treeView->setRootIsDecorated(true);
|
m_treeView->setRootIsDecorated(true);
|
||||||
m_treeView->setUniformRowHeights(true);
|
m_treeView->setUniformRowHeights(true);
|
||||||
|
m_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
treeLayout->addWidget(m_treeView);
|
treeLayout->addWidget(m_treeView);
|
||||||
|
|
||||||
// Commit area
|
// Commit area
|
||||||
|
|
@ -519,6 +520,41 @@ GitPlusPlusView::GitPlusPlusView(GitPlusPlusPlugin *plugin, KTextEditor::MainWin
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Right-click context menu on status tree
|
||||||
|
connect(m_treeView, &QTreeView::customContextMenuRequested, this, [this](const QPoint &pos) {
|
||||||
|
const auto indexes = m_treeView->selectionModel()->selectedIndexes();
|
||||||
|
QStringList files;
|
||||||
|
for (const auto &proxyIdx : indexes) {
|
||||||
|
QModelIndex idx = m_proxy->mapToSource(proxyIdx);
|
||||||
|
if (idx.internalId() == 0xFFFFFFFF)
|
||||||
|
continue;
|
||||||
|
QString file = idx.data(GitStatusModel::FilePathRole).toString();
|
||||||
|
if (!file.isEmpty())
|
||||||
|
files.append(file);
|
||||||
|
}
|
||||||
|
if (files.isEmpty()) return;
|
||||||
|
|
||||||
|
QMenu menu;
|
||||||
|
QString diffLabel = files.size() == 1
|
||||||
|
? QStringLiteral("View Diff")
|
||||||
|
: QStringLiteral("View Diff(s)");
|
||||||
|
QString openLabel = files.size() == 1
|
||||||
|
? QStringLiteral("Open File")
|
||||||
|
: QStringLiteral("Open File(s)");
|
||||||
|
auto *diffAction = menu.addAction(QIcon::fromTheme(QStringLiteral("vcs-diff")), diffLabel);
|
||||||
|
auto *openAction = menu.addAction(QIcon::fromTheme(QStringLiteral("document-open")), openLabel);
|
||||||
|
|
||||||
|
auto *chosen = menu.exec(m_treeView->viewport()->mapToGlobal(pos));
|
||||||
|
if (chosen == diffAction) {
|
||||||
|
diffSelected();
|
||||||
|
} else if (chosen == openAction) {
|
||||||
|
for (const auto &file : qAsConst(files)) {
|
||||||
|
QString absPath = m_gitDir + QLatin1Char('/') + file;
|
||||||
|
m_mainWindow->openUrl(QUrl::fromLocalFile(absPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Amend checkbox: load last commit message when checked
|
// Amend checkbox: load last commit message when checked
|
||||||
connect(m_amendCheck, &QCheckBox::toggled, this, [this](bool checked) {
|
connect(m_amendCheck, &QCheckBox::toggled, this, [this](bool checked) {
|
||||||
if (checked && m_commitMsgEdit->toPlainText().trimmed().isEmpty()) {
|
if (checked && m_commitMsgEdit->toPlainText().trimmed().isEmpty()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue