1 from PyQt4
import QtGui
2 from PyQt4
import QtCore
3 from PyQt4
.QtCore
import SIGNAL
6 from cola
import qtutils
7 from cola
import gitcmds
11 """Launches 'git difftool' with args"""
12 difftool_args
= ['git', 'difftool', '--no-prompt']
13 difftool_args
.extend(args
)
14 utils
.fork(difftool_args
)
17 def diff_commits(parent
, a
, b
):
18 dlg
= FileDiffDialog(parent
, a
, b
)
21 return dlg
.exec_() == QtGui
.QDialog
.Accepted
24 class FileDiffDialog(QtGui
.QDialog
):
25 def __init__(self
, parent
, a
, b
):
26 QtGui
.QDialog
.__init
__(self
, parent
)
30 self
.setWindowTitle('Select File(s)')
31 self
._tree
= QtGui
.QTreeWidget(self
)
32 self
._tree
.setAlternatingRowColors(True)
33 self
._tree
.setRootIsDecorated(False)
34 self
._tree
.setSelectionMode(self
._tree
.ExtendedSelection
)
35 self
._tree
.setUniformRowHeights(True)
36 self
._tree
.setAllColumnsShowFocus(True)
37 self
._tree
.setHeaderHidden(True)
39 self
._diff
_btn
= QtGui
.QPushButton('Compare')
40 self
._diff
_btn
.setIcon(qtutils
.ok_icon())
41 self
._diff
_btn
.setEnabled(False)
43 self
._close
_btn
= QtGui
.QPushButton('Close')
44 self
._close
_btn
.setIcon(qtutils
.close_icon())
46 self
._button
_layt
= QtGui
.QHBoxLayout()
47 self
._button
_layt
.setMargin(0)
48 self
._button
_layt
.addStretch()
49 self
._button
_layt
.addWidget(self
._diff
_btn
)
50 self
._button
_layt
.addWidget(self
._close
_btn
)
52 self
._layt
= QtGui
.QVBoxLayout()
53 self
._layt
.setMargin(4)
54 self
._layt
.addWidget(self
._tree
)
55 self
._layt
.addLayout(self
._button
_layt
)
56 self
.setLayout(self
._layt
)
58 qtutils
.add_close_action(self
)
60 self
.connect(self
._tree
, SIGNAL('itemSelectionChanged()'),
61 self
._tree
_selection
_changed
)
63 self
.connect(self
._tree
,
64 SIGNAL('itemDoubleClicked(QTreeWidgetItem*,int)'),
65 self
._tree
_double
_clicked
)
67 self
.connect(self
._diff
_btn
, SIGNAL('clicked()'), self
.diff
)
68 self
.connect(self
._close
_btn
, SIGNAL('clicked()'), self
.close
)
70 self
.diff_arg
= '%s..%s' % (self
.a
, self
.b
)
76 filenames
= gitcmds
.diff_filenames(self
.diff_arg
)
78 details
= ('"git diff --name-only %s" returned an empty list' %
81 qtutils
.information('git cola',
82 message
='No changes to diff',
88 icon
= qtutils
.file_icon()
90 for filename
in filenames
:
91 item
= QtGui
.QTreeWidgetItem()
93 item
.setText(0, filename
)
94 item
.setData(0, QtCore
.Qt
.UserRole
, QtCore
.QVariant(filename
))
96 self
._tree
.addTopLevelItems(items
)
98 return QtGui
.QDialog
.exec_(self
)
100 def _tree_selection_changed(self
):
101 self
._diff
_btn
.setEnabled(bool(self
._tree
.selectedItems()))
103 def _tree_double_clicked(self
, item
, column
):
104 path
= item
.data(0, QtCore
.Qt
.UserRole
).toPyObject()
105 launch([self
.diff_arg
, '--', unicode(path
)])
108 items
= self
._tree
.selectedItems()
111 paths
= [i
.data(0, QtCore
.Qt
.UserRole
).toPyObject() for i
in items
]
113 launch([self
.diff_arg
, '--', unicode(path
)])