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@560
|
8 Copyright (c) 2012 Chris Cannam
|
Chris@560
|
9 Copyright (c) 2012 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
|
sam@624
|
80 connect(m_fileStatusWidget, SIGNAL(showIn(QStringList)),
|
sam@624
|
81 this, SIGNAL(showIn(QStringList)));
|
sam@624
|
82
|
Chris@116
|
83 addTab(m_fileStatusWidget, tr("My work"));
|
Chris@88
|
84
|
Chris@326
|
85 // History graph tab
|
Chris@116
|
86 m_historyWidget = new HistoryWidget;
|
Chris@116
|
87 addTab(m_historyWidget, tr("History"));
|
Chris@141
|
88
|
Chris@141
|
89 connect(m_historyWidget, SIGNAL(commit()),
|
Chris@141
|
90 this, SIGNAL(commit()));
|
Chris@141
|
91
|
Chris@141
|
92 connect(m_historyWidget, SIGNAL(revert()),
|
Chris@141
|
93 this, SIGNAL(revert()));
|
Chris@141
|
94
|
Chris@168
|
95 connect(m_historyWidget, SIGNAL(showSummary()),
|
Chris@168
|
96 this, SIGNAL(showSummary()));
|
Chris@168
|
97
|
Chris@311
|
98 connect(m_historyWidget, SIGNAL(newBranch()),
|
Chris@311
|
99 this, SIGNAL(newBranch()));
|
Chris@311
|
100
|
Chris@311
|
101 connect(m_historyWidget, SIGNAL(noBranch()),
|
Chris@311
|
102 this, SIGNAL(noBranch()));
|
Chris@311
|
103
|
Chris@141
|
104 connect(m_historyWidget, SIGNAL(diffWorkingFolder()),
|
Chris@141
|
105 this, SIGNAL(diffWorkingFolder()));
|
Chris@141
|
106
|
Chris@153
|
107 connect(m_historyWidget, SIGNAL(showWork()),
|
Chris@153
|
108 this, SLOT(showWorkTab()));
|
Chris@153
|
109
|
Chris@141
|
110 connect(m_historyWidget, SIGNAL(updateTo(QString)),
|
Chris@141
|
111 this, SIGNAL(updateTo(QString)));
|
Chris@141
|
112
|
Chris@141
|
113 connect(m_historyWidget, SIGNAL(diffToCurrent(QString)),
|
Chris@141
|
114 this, SIGNAL(diffToCurrent(QString)));
|
Chris@141
|
115
|
Chris@148
|
116 connect(m_historyWidget, SIGNAL(diffToParent(QString, QString)),
|
Chris@148
|
117 this, SIGNAL(diffToParent(QString, QString)));
|
Chris@141
|
118
|
Chris@289
|
119 connect(m_historyWidget, SIGNAL(showSummary(Changeset *)),
|
Chris@289
|
120 this, SIGNAL(showSummary(Changeset *)));
|
Chris@288
|
121
|
Chris@141
|
122 connect(m_historyWidget, SIGNAL(mergeFrom(QString)),
|
Chris@141
|
123 this, SIGNAL(mergeFrom(QString)));
|
Chris@141
|
124
|
Chris@278
|
125 connect(m_historyWidget, SIGNAL(newBranch(QString)),
|
Chris@278
|
126 this, SIGNAL(newBranch(QString)));
|
Chris@278
|
127
|
Chris@514
|
128 connect(m_historyWidget, SIGNAL(closeBranch(QString)),
|
Chris@514
|
129 this, SIGNAL(closeBranch(QString)));
|
Chris@514
|
130
|
Chris@141
|
131 connect(m_historyWidget, SIGNAL(tag(QString)),
|
Chris@141
|
132 this, SIGNAL(tag(QString)));
|
jtkorhonen@32
|
133 }
|
jtkorhonen@32
|
134
|
Chris@96
|
135 void HgTabWidget::clearSelections()
|
Chris@94
|
136 {
|
Chris@116
|
137 m_fileStatusWidget->clearSelections();
|
Chris@94
|
138 }
|
Chris@94
|
139
|
Chris@153
|
140 void HgTabWidget::setCurrent(QStringList ids, QString branch)
|
Chris@128
|
141 {
|
Chris@505
|
142 m_historyWidget->setCurrent(ids, branch, haveChangesToCommit());
|
Chris@129
|
143 }
|
Chris@129
|
144
|
Chris@506
|
145 void HgTabWidget::setClosedHeadIds(QSet<QString> closed)
|
Chris@506
|
146 {
|
Chris@506
|
147 m_historyWidget->setClosedHeadIds(closed);
|
Chris@506
|
148 }
|
Chris@506
|
149
|
Chris@608
|
150 void HgTabWidget::clearAll()
|
Chris@608
|
151 {
|
Chris@608
|
152 m_fileStatusWidget->clearWidgets();
|
Chris@608
|
153 m_historyWidget->clear();
|
Chris@608
|
154 }
|
Chris@608
|
155
|
Chris@230
|
156 void HgTabWidget::updateFileStates()
|
Chris@230
|
157 {
|
Chris@230
|
158 m_fileStatusWidget->updateWidgets();
|
Chris@230
|
159 }
|
Chris@230
|
160
|
Chris@154
|
161 void HgTabWidget::updateHistory()
|
Chris@154
|
162 {
|
Chris@154
|
163 m_historyWidget->update();
|
Chris@154
|
164 }
|
Chris@154
|
165
|
Chris@555
|
166 void HgTabWidget::setSearchText(QString text)
|
Chris@555
|
167 {
|
Chris@555
|
168 m_fileStatusWidget->setSearchText(text);
|
Chris@555
|
169 m_historyWidget->setSearchText(text);
|
Chris@555
|
170 }
|
Chris@555
|
171
|
Chris@163
|
172 bool HgTabWidget::canDiff() const
|
Chris@163
|
173 {
|
Chris@237
|
174 return canRevert();
|
Chris@163
|
175 }
|
Chris@163
|
176
|
Chris@96
|
177 bool HgTabWidget::canCommit() const
|
Chris@90
|
178 {
|
Chris@505
|
179 if (!haveChangesToCommit()) return false;
|
Chris@505
|
180 if (!getAllUnresolvedFiles().empty()) return false;
|
Chris@326
|
181 return true;
|
Chris@90
|
182 }
|
jtkorhonen@0
|
183
|
Chris@109
|
184 bool HgTabWidget::canRevert() const
|
Chris@109
|
185 {
|
Chris@237
|
186 // Not the same as canCommit() -- we can revert (and diff)
|
Chris@237
|
187 // unresolved files, but we can't commit them
|
Chris@505
|
188 if (!haveChangesToCommit() &&
|
Chris@505
|
189 getAllUnresolvedFiles().empty()) return false;
|
Chris@326
|
190 return true;
|
Chris@109
|
191 }
|
Chris@109
|
192
|
Chris@96
|
193 bool HgTabWidget::canAdd() const
|
Chris@95
|
194 {
|
Chris@327
|
195 // Permit this only when work tab is visible
|
Chris@327
|
196 if (currentIndex() != 0) return false;
|
Chris@327
|
197
|
Chris@505
|
198 QStringList addable = getSelectedAddableFiles();
|
Chris@204
|
199 if (addable.empty()) return false;
|
Chris@204
|
200
|
Chris@505
|
201 QStringList removable = getSelectedRemovableFiles();
|
Chris@204
|
202 if (!removable.empty()) return false;
|
Chris@204
|
203
|
Chris@326
|
204 return true;
|
Chris@95
|
205 }
|
Chris@95
|
206
|
Chris@96
|
207 bool HgTabWidget::canRemove() const
|
Chris@95
|
208 {
|
Chris@327
|
209 // Permit this only when work tab is visible
|
Chris@327
|
210 if (currentIndex() != 0) return false;
|
Chris@327
|
211
|
Chris@505
|
212 if (getSelectedRemovableFiles().empty()) return false;
|
Chris@505
|
213 if (!getSelectedAddableFiles().empty()) return false;
|
Chris@95
|
214 return true;
|
Chris@95
|
215 }
|
Chris@95
|
216
|
Chris@163
|
217 bool HgTabWidget::canResolve() const
|
Chris@95
|
218 {
|
Chris@505
|
219 return !getAllUnresolvedFiles().empty();
|
Chris@95
|
220 }
|
Chris@95
|
221
|
Chris@425
|
222 bool HgTabWidget::canIgnore() const
|
Chris@425
|
223 {
|
Chris@425
|
224 return canAdd();
|
Chris@425
|
225 }
|
Chris@425
|
226
|
Chris@172
|
227 bool HgTabWidget::haveChangesToCommit() const
|
Chris@172
|
228 {
|
Chris@505
|
229 return m_haveMerge || m_fileStatusWidget->haveChangesToCommit();
|
Chris@172
|
230 }
|
Chris@172
|
231
|
Chris@109
|
232 QStringList HgTabWidget::getAllCommittableFiles() const
|
Chris@109
|
233 {
|
Chris@116
|
234 return m_fileStatusWidget->getAllCommittableFiles();
|
Chris@109
|
235 }
|
Chris@109
|
236
|
Chris@109
|
237 QStringList HgTabWidget::getAllRevertableFiles() const
|
Chris@109
|
238 {
|
Chris@116
|
239 return m_fileStatusWidget->getAllRevertableFiles();
|
Chris@109
|
240 }
|
Chris@109
|
241
|
Chris@96
|
242 QStringList HgTabWidget::getSelectedAddableFiles() const
|
Chris@95
|
243 {
|
Chris@116
|
244 return m_fileStatusWidget->getSelectedAddableFiles();
|
Chris@95
|
245 }
|
Chris@95
|
246
|
Chris@96
|
247 QStringList HgTabWidget::getSelectedRemovableFiles() const
|
Chris@95
|
248 {
|
Chris@116
|
249 return m_fileStatusWidget->getSelectedRemovableFiles();
|
Chris@95
|
250 }
|
Chris@95
|
251
|
Chris@163
|
252 QStringList HgTabWidget::getAllUnresolvedFiles() const
|
Chris@163
|
253 {
|
Chris@163
|
254 return m_fileStatusWidget->getAllUnresolvedFiles();
|
Chris@163
|
255 }
|
Chris@163
|
256
|
Chris@96
|
257 void HgTabWidget::updateWorkFolderFileList(QString fileList)
|
jtkorhonen@0
|
258 {
|
Chris@116
|
259 m_fileStates.parseStates(fileList);
|
Chris@116
|
260 m_fileStatusWidget->setFileStates(m_fileStates);
|
jtkorhonen@0
|
261 }
|
jtkorhonen@0
|
262
|
Chris@505
|
263 void HgTabWidget::setHaveMerge(bool haveMerge)
|
Chris@505
|
264 {
|
Chris@505
|
265 if (m_haveMerge != haveMerge) {
|
Chris@505
|
266 m_haveMerge = haveMerge;
|
Chris@505
|
267 m_historyWidget->setShowUncommitted(haveChangesToCommit());
|
Chris@505
|
268 updateHistory();
|
Chris@505
|
269 }
|
Chris@505
|
270 }
|
Chris@505
|
271
|
Chris@120
|
272 void HgTabWidget::setNewLog(QString hgLogList)
|
jtkorhonen@0
|
273 {
|
Chris@120
|
274 m_historyWidget->parseNewLog(hgLogList);
|
Chris@134
|
275 if (m_historyWidget->haveNewItems()) {
|
Chris@153
|
276 showHistoryTab();
|
Chris@134
|
277 }
|
Chris@120
|
278 }
|
Chris@120
|
279
|
Chris@120
|
280 void HgTabWidget::addIncrementalLog(QString hgLogList)
|
Chris@120
|
281 {
|
Chris@120
|
282 m_historyWidget->parseIncrementalLog(hgLogList);
|
Chris@134
|
283 if (m_historyWidget->haveNewItems()) {
|
Chris@153
|
284 showHistoryTab();
|
Chris@134
|
285 }
|
jtkorhonen@0
|
286 }
|
jtkorhonen@0
|
287
|
Chris@287
|
288 void HgTabWidget::setLocalPath(QString workFolderPath)
|
jtkorhonen@0
|
289 {
|
Chris@116
|
290 m_fileStatusWidget->setLocalPath(workFolderPath);
|
Chris@106
|
291 }
|
Chris@153
|
292
|
Chris@153
|
293 void HgTabWidget::showWorkTab()
|
Chris@153
|
294 {
|
Chris@153
|
295 setCurrentWidget(m_fileStatusWidget);
|
Chris@153
|
296 }
|
Chris@153
|
297
|
Chris@153
|
298 void HgTabWidget::showHistoryTab()
|
Chris@153
|
299 {
|
Chris@153
|
300 setCurrentWidget(m_historyWidget);
|
Chris@153
|
301 }
|
Chris@153
|
302
|
Chris@484
|
303 bool HgTabWidget::shouldShowAll() const
|
Chris@484
|
304 {
|
Chris@484
|
305 return m_fileStatusWidget->shouldShowAll();
|
Chris@484
|
306 }
|
Chris@484
|
307
|