Chris@57
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@57
|
2
|
Chris@57
|
3 /*
|
Chris@57
|
4 EasyMercurial
|
Chris@57
|
5
|
Chris@57
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@57
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@244
|
8 Copyright (c) 2011 Chris Cannam
|
Chris@244
|
9 Copyright (c) 2011 Queen Mary, University of London
|
Chris@57
|
10
|
Chris@57
|
11 This program is free software; you can redistribute it and/or
|
Chris@57
|
12 modify it under the terms of the GNU General Public License as
|
Chris@57
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@57
|
14 License, or (at your option) any later version. See the file
|
Chris@57
|
15 COPYING included with this distribution for more information.
|
Chris@57
|
16 */
|
jtkorhonen@0
|
17
|
Chris@96
|
18 #include "hgtabwidget.h"
|
jtkorhonen@0
|
19 #include "common.h"
|
Chris@88
|
20 #include "filestatuswidget.h"
|
Chris@116
|
21 #include "historywidget.h"
|
Chris@44
|
22
|
Chris@50
|
23 #include <QClipboard>
|
Chris@50
|
24 #include <QContextMenuEvent>
|
Chris@50
|
25 #include <QApplication>
|
Chris@50
|
26
|
Chris@44
|
27 #include <iostream>
|
jtkorhonen@0
|
28
|
Chris@96
|
29 HgTabWidget::HgTabWidget(QWidget *parent,
|
Chris@95
|
30 QString workFolderPath) :
|
Chris@505
|
31 QTabWidget(parent),
|
Chris@505
|
32 m_haveMerge(false)
|
jtkorhonen@0
|
33 {
|
Chris@326
|
34 // Work tab
|
Chris@116
|
35 m_fileStatusWidget = new FileStatusWidget;
|
Chris@116
|
36 m_fileStatusWidget->setLocalPath(workFolderPath);
|
Chris@326
|
37
|
Chris@116
|
38 connect(m_fileStatusWidget, SIGNAL(selectionChanged()),
|
Chris@95
|
39 this, SIGNAL(selectionChanged()));
|
Chris@326
|
40
|
Chris@484
|
41 connect(m_fileStatusWidget, SIGNAL(showAllChanged()),
|
Chris@484
|
42 this, SIGNAL(showAllChanged()));
|
Chris@326
|
43
|
Chris@326
|
44 connect(m_fileStatusWidget, SIGNAL(annotateFiles(QStringList)),
|
Chris@326
|
45 this, SIGNAL(annotateFiles(QStringList)));
|
Chris@326
|
46
|
Chris@326
|
47 connect(m_fileStatusWidget, SIGNAL(diffFiles(QStringList)),
|
Chris@326
|
48 this, SIGNAL(diffFiles(QStringList)));
|
Chris@326
|
49
|
Chris@326
|
50 connect(m_fileStatusWidget, SIGNAL(commitFiles(QStringList)),
|
Chris@326
|
51 this, SIGNAL(commitFiles(QStringList)));
|
Chris@326
|
52
|
Chris@326
|
53 connect(m_fileStatusWidget, SIGNAL(revertFiles(QStringList)),
|
Chris@326
|
54 this, SIGNAL(revertFiles(QStringList)));
|
Chris@326
|
55
|
Chris@361
|
56 connect(m_fileStatusWidget, SIGNAL(renameFiles(QStringList)),
|
Chris@361
|
57 this, SIGNAL(renameFiles(QStringList)));
|
Chris@361
|
58
|
Chris@361
|
59 connect(m_fileStatusWidget, SIGNAL(copyFiles(QStringList)),
|
Chris@361
|
60 this, SIGNAL(copyFiles(QStringList)));
|
Chris@361
|
61
|
Chris@326
|
62 connect(m_fileStatusWidget, SIGNAL(addFiles(QStringList)),
|
Chris@326
|
63 this, SIGNAL(addFiles(QStringList)));
|
Chris@326
|
64
|
Chris@326
|
65 connect(m_fileStatusWidget, SIGNAL(removeFiles(QStringList)),
|
Chris@326
|
66 this, SIGNAL(removeFiles(QStringList)));
|
Chris@326
|
67
|
Chris@326
|
68 connect(m_fileStatusWidget, SIGNAL(redoFileMerges(QStringList)),
|
Chris@326
|
69 this, SIGNAL(redoFileMerges(QStringList)));
|
Chris@326
|
70
|
Chris@326
|
71 connect(m_fileStatusWidget, SIGNAL(markFilesResolved(QStringList)),
|
Chris@326
|
72 this, SIGNAL(markFilesResolved(QStringList)));
|
Chris@326
|
73
|
Chris@326
|
74 connect(m_fileStatusWidget, SIGNAL(ignoreFiles(QStringList)),
|
Chris@326
|
75 this, SIGNAL(ignoreFiles(QStringList)));
|
Chris@326
|
76
|
Chris@326
|
77 connect(m_fileStatusWidget, SIGNAL(unIgnoreFiles(QStringList)),
|
Chris@326
|
78 this, SIGNAL(unIgnoreFiles(QStringList)));
|
Chris@326
|
79
|
Chris@116
|
80 addTab(m_fileStatusWidget, tr("My work"));
|
Chris@88
|
81
|
Chris@326
|
82 // History graph tab
|
Chris@116
|
83 m_historyWidget = new HistoryWidget;
|
Chris@116
|
84 addTab(m_historyWidget, tr("History"));
|
Chris@141
|
85
|
Chris@141
|
86 connect(m_historyWidget, SIGNAL(commit()),
|
Chris@141
|
87 this, SIGNAL(commit()));
|
Chris@141
|
88
|
Chris@141
|
89 connect(m_historyWidget, SIGNAL(revert()),
|
Chris@141
|
90 this, SIGNAL(revert()));
|
Chris@141
|
91
|
Chris@168
|
92 connect(m_historyWidget, SIGNAL(showSummary()),
|
Chris@168
|
93 this, SIGNAL(showSummary()));
|
Chris@168
|
94
|
Chris@311
|
95 connect(m_historyWidget, SIGNAL(newBranch()),
|
Chris@311
|
96 this, SIGNAL(newBranch()));
|
Chris@311
|
97
|
Chris@311
|
98 connect(m_historyWidget, SIGNAL(noBranch()),
|
Chris@311
|
99 this, SIGNAL(noBranch()));
|
Chris@311
|
100
|
Chris@141
|
101 connect(m_historyWidget, SIGNAL(diffWorkingFolder()),
|
Chris@141
|
102 this, SIGNAL(diffWorkingFolder()));
|
Chris@141
|
103
|
Chris@153
|
104 connect(m_historyWidget, SIGNAL(showWork()),
|
Chris@153
|
105 this, SLOT(showWorkTab()));
|
Chris@153
|
106
|
Chris@141
|
107 connect(m_historyWidget, SIGNAL(updateTo(QString)),
|
Chris@141
|
108 this, SIGNAL(updateTo(QString)));
|
Chris@141
|
109
|
Chris@141
|
110 connect(m_historyWidget, SIGNAL(diffToCurrent(QString)),
|
Chris@141
|
111 this, SIGNAL(diffToCurrent(QString)));
|
Chris@141
|
112
|
Chris@148
|
113 connect(m_historyWidget, SIGNAL(diffToParent(QString, QString)),
|
Chris@148
|
114 this, SIGNAL(diffToParent(QString, QString)));
|
Chris@141
|
115
|
Chris@289
|
116 connect(m_historyWidget, SIGNAL(showSummary(Changeset *)),
|
Chris@289
|
117 this, SIGNAL(showSummary(Changeset *)));
|
Chris@288
|
118
|
Chris@141
|
119 connect(m_historyWidget, SIGNAL(mergeFrom(QString)),
|
Chris@141
|
120 this, SIGNAL(mergeFrom(QString)));
|
Chris@141
|
121
|
Chris@278
|
122 connect(m_historyWidget, SIGNAL(newBranch(QString)),
|
Chris@278
|
123 this, SIGNAL(newBranch(QString)));
|
Chris@278
|
124
|
Chris@514
|
125 connect(m_historyWidget, SIGNAL(closeBranch(QString)),
|
Chris@514
|
126 this, SIGNAL(closeBranch(QString)));
|
Chris@514
|
127
|
Chris@141
|
128 connect(m_historyWidget, SIGNAL(tag(QString)),
|
Chris@141
|
129 this, SIGNAL(tag(QString)));
|
jtkorhonen@32
|
130 }
|
jtkorhonen@32
|
131
|
Chris@96
|
132 void HgTabWidget::clearSelections()
|
Chris@94
|
133 {
|
Chris@116
|
134 m_fileStatusWidget->clearSelections();
|
Chris@94
|
135 }
|
Chris@94
|
136
|
Chris@153
|
137 void HgTabWidget::setCurrent(QStringList ids, QString branch)
|
Chris@128
|
138 {
|
Chris@505
|
139 m_historyWidget->setCurrent(ids, branch, haveChangesToCommit());
|
Chris@129
|
140 }
|
Chris@129
|
141
|
Chris@506
|
142 void HgTabWidget::setClosedHeadIds(QSet<QString> closed)
|
Chris@506
|
143 {
|
Chris@506
|
144 m_historyWidget->setClosedHeadIds(closed);
|
Chris@506
|
145 }
|
Chris@506
|
146
|
Chris@230
|
147 void HgTabWidget::updateFileStates()
|
Chris@230
|
148 {
|
Chris@230
|
149 m_fileStatusWidget->updateWidgets();
|
Chris@230
|
150 }
|
Chris@230
|
151
|
Chris@154
|
152 void HgTabWidget::updateHistory()
|
Chris@154
|
153 {
|
Chris@154
|
154 m_historyWidget->update();
|
Chris@154
|
155 }
|
Chris@154
|
156
|
Chris@163
|
157 bool HgTabWidget::canDiff() const
|
Chris@163
|
158 {
|
Chris@237
|
159 return canRevert();
|
Chris@163
|
160 }
|
Chris@163
|
161
|
Chris@96
|
162 bool HgTabWidget::canCommit() const
|
Chris@90
|
163 {
|
Chris@505
|
164 if (!haveChangesToCommit()) return false;
|
Chris@505
|
165 if (!getAllUnresolvedFiles().empty()) return false;
|
Chris@326
|
166 return true;
|
Chris@90
|
167 }
|
jtkorhonen@0
|
168
|
Chris@109
|
169 bool HgTabWidget::canRevert() const
|
Chris@109
|
170 {
|
Chris@237
|
171 // Not the same as canCommit() -- we can revert (and diff)
|
Chris@237
|
172 // unresolved files, but we can't commit them
|
Chris@505
|
173 if (!haveChangesToCommit() &&
|
Chris@505
|
174 getAllUnresolvedFiles().empty()) return false;
|
Chris@326
|
175 return true;
|
Chris@109
|
176 }
|
Chris@109
|
177
|
Chris@96
|
178 bool HgTabWidget::canAdd() const
|
Chris@95
|
179 {
|
Chris@327
|
180 // Permit this only when work tab is visible
|
Chris@327
|
181 if (currentIndex() != 0) return false;
|
Chris@327
|
182
|
Chris@505
|
183 QStringList addable = getSelectedAddableFiles();
|
Chris@204
|
184 if (addable.empty()) return false;
|
Chris@204
|
185
|
Chris@505
|
186 QStringList removable = getSelectedRemovableFiles();
|
Chris@204
|
187 if (!removable.empty()) return false;
|
Chris@204
|
188
|
Chris@326
|
189 return true;
|
Chris@95
|
190 }
|
Chris@95
|
191
|
Chris@96
|
192 bool HgTabWidget::canRemove() const
|
Chris@95
|
193 {
|
Chris@327
|
194 // Permit this only when work tab is visible
|
Chris@327
|
195 if (currentIndex() != 0) return false;
|
Chris@327
|
196
|
Chris@505
|
197 if (getSelectedRemovableFiles().empty()) return false;
|
Chris@505
|
198 if (!getSelectedAddableFiles().empty()) return false;
|
Chris@95
|
199 return true;
|
Chris@95
|
200 }
|
Chris@95
|
201
|
Chris@163
|
202 bool HgTabWidget::canResolve() const
|
Chris@95
|
203 {
|
Chris@505
|
204 return !getAllUnresolvedFiles().empty();
|
Chris@95
|
205 }
|
Chris@95
|
206
|
Chris@425
|
207 bool HgTabWidget::canIgnore() const
|
Chris@425
|
208 {
|
Chris@425
|
209 return canAdd();
|
Chris@425
|
210 }
|
Chris@425
|
211
|
Chris@172
|
212 bool HgTabWidget::haveChangesToCommit() const
|
Chris@172
|
213 {
|
Chris@505
|
214 return m_haveMerge || m_fileStatusWidget->haveChangesToCommit();
|
Chris@172
|
215 }
|
Chris@172
|
216
|
Chris@109
|
217 QStringList HgTabWidget::getAllCommittableFiles() const
|
Chris@109
|
218 {
|
Chris@116
|
219 return m_fileStatusWidget->getAllCommittableFiles();
|
Chris@109
|
220 }
|
Chris@109
|
221
|
Chris@109
|
222 QStringList HgTabWidget::getAllRevertableFiles() const
|
Chris@109
|
223 {
|
Chris@116
|
224 return m_fileStatusWidget->getAllRevertableFiles();
|
Chris@109
|
225 }
|
Chris@109
|
226
|
Chris@96
|
227 QStringList HgTabWidget::getSelectedAddableFiles() const
|
Chris@95
|
228 {
|
Chris@116
|
229 return m_fileStatusWidget->getSelectedAddableFiles();
|
Chris@95
|
230 }
|
Chris@95
|
231
|
Chris@96
|
232 QStringList HgTabWidget::getSelectedRemovableFiles() const
|
Chris@95
|
233 {
|
Chris@116
|
234 return m_fileStatusWidget->getSelectedRemovableFiles();
|
Chris@95
|
235 }
|
Chris@95
|
236
|
Chris@163
|
237 QStringList HgTabWidget::getAllUnresolvedFiles() const
|
Chris@163
|
238 {
|
Chris@163
|
239 return m_fileStatusWidget->getAllUnresolvedFiles();
|
Chris@163
|
240 }
|
Chris@163
|
241
|
Chris@96
|
242 void HgTabWidget::updateWorkFolderFileList(QString fileList)
|
jtkorhonen@0
|
243 {
|
Chris@116
|
244 m_fileStates.parseStates(fileList);
|
Chris@116
|
245 m_fileStatusWidget->setFileStates(m_fileStates);
|
jtkorhonen@0
|
246 }
|
jtkorhonen@0
|
247
|
Chris@505
|
248 void HgTabWidget::setHaveMerge(bool haveMerge)
|
Chris@505
|
249 {
|
Chris@505
|
250 if (m_haveMerge != haveMerge) {
|
Chris@505
|
251 m_haveMerge = haveMerge;
|
Chris@505
|
252 m_historyWidget->setShowUncommitted(haveChangesToCommit());
|
Chris@505
|
253 updateHistory();
|
Chris@505
|
254 }
|
Chris@505
|
255 }
|
Chris@505
|
256
|
Chris@120
|
257 void HgTabWidget::setNewLog(QString hgLogList)
|
jtkorhonen@0
|
258 {
|
Chris@120
|
259 m_historyWidget->parseNewLog(hgLogList);
|
Chris@134
|
260 if (m_historyWidget->haveNewItems()) {
|
Chris@153
|
261 showHistoryTab();
|
Chris@134
|
262 }
|
Chris@120
|
263 }
|
Chris@120
|
264
|
Chris@120
|
265 void HgTabWidget::addIncrementalLog(QString hgLogList)
|
Chris@120
|
266 {
|
Chris@120
|
267 m_historyWidget->parseIncrementalLog(hgLogList);
|
Chris@134
|
268 if (m_historyWidget->haveNewItems()) {
|
Chris@153
|
269 showHistoryTab();
|
Chris@134
|
270 }
|
jtkorhonen@0
|
271 }
|
jtkorhonen@0
|
272
|
Chris@287
|
273 void HgTabWidget::setLocalPath(QString workFolderPath)
|
jtkorhonen@0
|
274 {
|
Chris@116
|
275 m_fileStatusWidget->setLocalPath(workFolderPath);
|
Chris@106
|
276 }
|
Chris@153
|
277
|
Chris@153
|
278 void HgTabWidget::showWorkTab()
|
Chris@153
|
279 {
|
Chris@153
|
280 setCurrentWidget(m_fileStatusWidget);
|
Chris@153
|
281 }
|
Chris@153
|
282
|
Chris@153
|
283 void HgTabWidget::showHistoryTab()
|
Chris@153
|
284 {
|
Chris@153
|
285 setCurrentWidget(m_historyWidget);
|
Chris@153
|
286 }
|
Chris@153
|
287
|
Chris@484
|
288 bool HgTabWidget::shouldShowAll() const
|
Chris@484
|
289 {
|
Chris@484
|
290 return m_fileStatusWidget->shouldShowAll();
|
Chris@484
|
291 }
|
Chris@484
|
292
|