Skip to content

Commit 0ff01ab

Browse files
committed
ability to swap source and destination when comparing files or directories
1 parent 15fca24 commit 0ff01ab

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

Diff for: TODO.txt

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ alpha (initial prelease phase)
88

99
later
1010
--------------
11-
- Swap source and destination
1211
- Create a plugin for KDevelop
1312
- intraline diffs are wrong at some cases. Need to fix libkomparediff2
1413
- Account for Intraline diffs when changing cursor positions

Diff for: kdiffui.rc

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Action name="open_diff" />
99
<Action name="blend_diff" />
1010
<Merge />
11+
<Action name="swap" />
1112
</Menu>
1213
<Merge />
1314
<Menu name="settings"><text>&amp;Settings</text>

Diff for: mainwindow.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ void KDiffMainWindow::setupActions() {
101101
a = actionCollection()->addAction(KStandardAction::KeyBindings, m_viewPart, SLOT(editKeys()));
102102
a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
103103

104+
swapAction = new QAction(this);
105+
swapAction->setEnabled(false);
106+
swapAction->setText(i18n("&Swap Source and Destination"));
107+
actionCollection()->addAction("swap", swapAction);
108+
connect(swapAction, SIGNAL(triggered(bool)), this, SLOT(swap()));
109+
104110
}
105111

106112
void KDiffMainWindow::openFiles() {
@@ -115,6 +121,7 @@ void KDiffMainWindow::openFiles() {
115121
QUrl destination = QUrl(settings->recentDestinationUrls().at(0));
116122

117123
viewPart()->openFiles(source, destination);
124+
swapAction->setEnabled(true);
118125
}
119126
}
120127

@@ -127,6 +134,7 @@ void KDiffMainWindow::openDiff() {
127134
QUrl diffUrl = QUrl(settings->recentPatchUrls().at(0));
128135

129136
viewPart()->openDiff(diffUrl);
137+
swapAction->setEnabled(false);
130138
}
131139

132140
}
@@ -143,6 +151,7 @@ void KDiffMainWindow::openDiffAndFiles() {
143151
QUrl destination = QUrl(settings->recentDestinationUrls().at(0));
144152

145153
viewPart()->openDiffAndFiles(diffUrl, destination);
154+
swapAction->setEnabled(false);
146155
}
147156

148157
}
@@ -198,3 +207,9 @@ KDiffInterface* KDiffMainWindow::viewPart() const
198207
{
199208
return qobject_cast<KDiffInterface *>(m_viewPart);
200209
}
210+
211+
void KDiffMainWindow::swap() {
212+
QUrl source = QUrl(settings->recentSourceUrls().at(0));
213+
QUrl destination = QUrl(settings->recentDestinationUrls().at(0));
214+
viewPart()->openFiles(destination, source);
215+
}

Diff for: mainwindow.h

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private slots:
3333
void editToolbars();
3434
void aboutEditor();
3535
void toggleMenuBar();
36+
void swap();
3637

3738
protected:
3839
void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
@@ -43,6 +44,7 @@ private slots:
4344
KParts::ReadWritePart* m_viewPart;
4445
KDiffInterface* viewPart() const;
4546
void setupActions();
47+
QAction* swapAction;
4648
};
4749

4850
#endif //KDIFF_MAINWINDOW_H

0 commit comments

Comments
 (0)