Skip to content

Commit 2bbb770

Browse files
authored
Merge pull request #391 from Murmele/FileContextMenu
FileContextMenu: Show context menu when a commit is selected && show correct context menu entries when commit is selected
2 parents 8569757 + 5bb85e9 commit 2bbb770

File tree

3 files changed

+257
-234
lines changed

3 files changed

+257
-234
lines changed

src/ui/DoubleTreeWidget.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,12 @@ QModelIndex DoubleTreeWidget::selectedIndex() const {
300300
}
301301

302302
static void addNodeToMenu(const git::Index &index, QStringList &files,
303-
const Node *node, bool staged) {
303+
const Node *node, bool staged, bool statusDiff) {
304304
qDebug() << "DoubleTreeWidgetr addNodeToMenu()" << node->name();
305305

306306
if (node->hasChildren()) {
307307
for (auto child : node->children()) {
308-
addNodeToMenu(index, files, child, staged);
308+
addNodeToMenu(index, files, child, staged, statusDiff);
309309
}
310310

311311
} else {
@@ -314,7 +314,7 @@ static void addNodeToMenu(const git::Index &index, QStringList &files,
314314
auto stageState = index.isStaged(path);
315315

316316
if ((staged && stageState != git::Index::Unstaged) ||
317-
!staged && stageState != git::Index::Staged) {
317+
(!staged && stageState != git::Index::Staged) || !statusDiff) {
318318
files.append(path);
319319
}
320320
}
@@ -324,10 +324,15 @@ void DoubleTreeWidget::showFileContextMenu(const QPoint &pos, RepoView *view,
324324
QTreeView *tree, bool staged) {
325325
QStringList files;
326326
QModelIndexList indexes = tree->selectionModel()->selectedIndexes();
327+
const auto diff = view->diff();
328+
if (!diff.isValid())
329+
return;
330+
331+
const bool statusDiff = diff.isStatusDiff();
327332
foreach (const QModelIndex &index, indexes) {
328333
auto node = index.data(Qt::UserRole).value<Node *>();
329334

330-
addNodeToMenu(view->repo().index(), files, node, staged);
335+
addNodeToMenu(view->repo().index(), files, node, staged, statusDiff);
331336
}
332337

333338
if (files.isEmpty())

0 commit comments

Comments
 (0)