Skip to content

Commit 02a125c

Browse files
authored
Merge pull request #899 from horde3d/enhancementDoubleClickDiff
External diff by double clicking the file. Addresses issue #688
2 parents d18e556 + e5d4dc4 commit 02a125c

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

src/ui/DoubleTreeWidget.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ DoubleTreeWidget::DoubleTreeWidget(const git::Repository &repo, QWidget *parent)
158158
});
159159

160160
stagedFiles->setModel(new TreeProxy(true, mDiffTreeModel, this));
161+
connect(stagedFiles, &QAbstractItemView::doubleClicked,
162+
[this, repoView](const QModelIndex &index) {
163+
openExternalDiffTool(index, repoView, true);
164+
});
161165

162166
QHBoxLayout *hBoxLayout = new QHBoxLayout();
163167
QLabel *label = new QLabel(kStagedFiles);
@@ -184,6 +188,10 @@ DoubleTreeWidget::DoubleTreeWidget(const git::Repository &repo, QWidget *parent)
184188
});
185189

186190
unstagedFiles->setModel(new TreeProxy(false, mDiffTreeModel, this));
191+
connect(unstagedFiles, &QAbstractItemView::doubleClicked,
192+
[this, repoView](const QModelIndex &index) {
193+
openExternalDiffTool(index, repoView, false);
194+
});
187195

188196
hBoxLayout = new QHBoxLayout();
189197
mUnstagedCommitedFiles = new QLabel(kUnstagedFiles);
@@ -347,6 +355,25 @@ void DoubleTreeWidget::showFileContextMenu(const QPoint &pos, RepoView *view,
347355
menu->popup(tree->mapToGlobal(pos));
348356
}
349357

358+
void DoubleTreeWidget::openExternalDiffTool(const QModelIndex &index,
359+
RepoView *view, bool staged) {
360+
const auto diff = view->diff();
361+
if (!diff.isValid())
362+
return;
363+
364+
const bool statusDiff = diff.isStatusDiff();
365+
QStringList files;
366+
auto node = index.data(Qt::UserRole).value<Node *>();
367+
addNodeToMenu(view->repo().index(), files, node, staged, statusDiff);
368+
if (files.isEmpty())
369+
return;
370+
371+
FileContextMenu fileMenu(view, files, git::Index(), nullptr);
372+
auto doubleClickAction = fileMenu.doubleClickAction();
373+
if (doubleClickAction)
374+
doubleClickAction->trigger();
375+
}
376+
350377
QList<QModelIndex> DoubleTreeWidget::selectedIndices() const {
351378
QList<QModelIndex> list;
352379

src/ui/DoubleTreeWidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ private slots:
5454
void collapseCountChanged(int count);
5555
static void showFileContextMenu(const QPoint &pos, RepoView *view,
5656
QTreeView *tree, bool staged);
57+
static void openExternalDiffTool(const QModelIndex &index, RepoView *view,
58+
bool staged);
5759

5860
private:
5961
enum View {

src/ui/FileContextMenu.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ FileContextMenu::FileContextMenu(RepoView *view, const QStringList &files,
168168
addExternalToolsAction(showTools);
169169
addExternalToolsAction(editTools);
170170
addExternalToolsAction(diffTools);
171-
addExternalToolsAction(diffToLocalTools);
171+
mDoubleClickAction = addExternalToolsAction(diffToLocalTools);
172172
addExternalToolsAction(mergeTools);
173173

174174
if (!isEmpty())
@@ -527,10 +527,10 @@ bool FileContextMenu::exportFile(const RepoView *view, const QString &folder,
527527
return true;
528528
}
529529

530-
void FileContextMenu::addExternalToolsAction(
531-
const QList<ExternalTool *> &tools) {
530+
QAction *
531+
FileContextMenu::addExternalToolsAction(const QList<ExternalTool *> &tools) {
532532
if (tools.isEmpty())
533-
return;
533+
return nullptr;
534534

535535
// Add action.
536536
QAction *action = addAction(tools.first()->name(), [this, tools] {
@@ -570,4 +570,5 @@ void FileContextMenu::addExternalToolsAction(
570570
break;
571571
}
572572
}
573+
return action->isEnabled() ? action : nullptr;
573574
}

src/ui/FileContextMenu.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ class FileContextMenu : public QMenu {
2525
FileContextMenu(RepoView *view, const QStringList &files,
2626
const git::Index &index = git::Index(),
2727
QWidget *parent = nullptr);
28+
29+
QAction *doubleClickAction() { return mDoubleClickAction; }
30+
2831
private slots:
2932
void ignoreFile();
3033

3134
private:
32-
void addExternalToolsAction(const QList<ExternalTool *> &tools);
35+
QAction *addExternalToolsAction(const QList<ExternalTool *> &tools);
3336
bool exportFile(const RepoView *view, const QString &folder,
3437
const QString &file);
3538
void handleUncommittedChanges(const git::Index &index,
@@ -39,6 +42,7 @@ private slots:
3942

4043
RepoView *mView;
4144
QStringList mFiles;
45+
QAction *mDoubleClickAction;
4246

4347
friend class TestTreeView;
4448
};

0 commit comments

Comments
 (0)