Chris@88
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@88
|
2
|
Chris@88
|
3 /*
|
Chris@88
|
4 EasyMercurial
|
Chris@88
|
5
|
Chris@88
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@88
|
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@88
|
10
|
Chris@88
|
11 This program is free software; you can redistribute it and/or
|
Chris@88
|
12 modify it under the terms of the GNU General Public License as
|
Chris@88
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@88
|
14 License, or (at your option) any later version. See the file
|
Chris@88
|
15 COPYING included with this distribution for more information.
|
Chris@88
|
16 */
|
Chris@88
|
17
|
Chris@88
|
18 #include "filestatuswidget.h"
|
Chris@115
|
19 #include "debug.h"
|
Chris@115
|
20 #include "multichoicedialog.h"
|
Chris@283
|
21 #include "workstatuswidget.h"
|
Chris@88
|
22
|
Chris@88
|
23 #include <QLabel>
|
Chris@88
|
24 #include <QListWidget>
|
Chris@88
|
25 #include <QGridLayout>
|
Chris@93
|
26 #include <QFileInfo>
|
Chris@93
|
27 #include <QApplication>
|
Chris@93
|
28 #include <QDateTime>
|
Chris@115
|
29 #include <QPushButton>
|
Chris@186
|
30 #include <QToolButton>
|
Chris@186
|
31 #include <QDir>
|
Chris@186
|
32 #include <QProcess>
|
Chris@199
|
33 #include <QCheckBox>
|
Chris@230
|
34 #include <QSettings>
|
Chris@88
|
35
|
Chris@88
|
36 FileStatusWidget::FileStatusWidget(QWidget *parent) :
|
Chris@93
|
37 QWidget(parent),
|
Chris@93
|
38 m_dateReference(0)
|
Chris@88
|
39 {
|
Chris@88
|
40 QGridLayout *layout = new QGridLayout;
|
Chris@215
|
41 layout->setMargin(10);
|
Chris@88
|
42 setLayout(layout);
|
Chris@88
|
43
|
Chris@88
|
44 int row = 0;
|
Chris@211
|
45
|
Chris@283
|
46 m_workStatus = new WorkStatusWidget(this);
|
Chris@283
|
47 layout->addWidget(m_workStatus, row, 0, 1, 3);
|
Chris@115
|
48 ++row;
|
Chris@230
|
49
|
Chris@230
|
50 m_noModificationsLabel = new QLabel;
|
Chris@230
|
51 setNoModificationsLabelText();
|
Chris@115
|
52 layout->addWidget(m_noModificationsLabel, row, 1, 1, 2);
|
Chris@202
|
53 m_noModificationsLabel->hide();
|
Chris@106
|
54
|
Chris@100
|
55 m_simpleLabels[FileStates::Clean] = tr("Unmodified:");
|
Chris@100
|
56 m_simpleLabels[FileStates::Modified] = tr("Modified:");
|
Chris@100
|
57 m_simpleLabels[FileStates::Added] = tr("Added:");
|
Chris@100
|
58 m_simpleLabels[FileStates::Removed] = tr("Removed:");
|
Chris@100
|
59 m_simpleLabels[FileStates::Missing] = tr("Missing:");
|
Chris@163
|
60 m_simpleLabels[FileStates::InConflict] = tr("In Conflict:");
|
Chris@100
|
61 m_simpleLabels[FileStates::Unknown] = tr("Untracked:");
|
Chris@199
|
62 m_simpleLabels[FileStates::Ignored] = tr("Ignored:");
|
Chris@99
|
63
|
Chris@100
|
64 m_descriptions[FileStates::Clean] = tr("You have not changed these files.");
|
Chris@100
|
65 m_descriptions[FileStates::Modified] = tr("You have changed these files since you last committed them.");
|
Chris@225
|
66 m_descriptions[FileStates::Added] = tr("These files will be added to version control next time you commit them.");
|
Chris@225
|
67 m_descriptions[FileStates::Removed] = tr("These files will be removed from version control next time you commit them.<br>"
|
Chris@100
|
68 "They will not be deleted from the local folder.");
|
Chris@109
|
69 m_descriptions[FileStates::Missing] = tr("These files are recorded in the version control, but absent from your working folder.<br>"
|
Chris@153
|
70 "If you intended to delete them, select them and use Remove to tell the version control system about it.<br>"
|
Chris@153
|
71 "If you deleted them by accident, select them and use Revert to restore their previous contents.");
|
Chris@163
|
72 m_descriptions[FileStates::InConflict] = tr("These files are unresolved following an incomplete merge.<br>Select a file and use Merge to try to resolve the merge again.");
|
Chris@100
|
73 m_descriptions[FileStates::Unknown] = tr("These files are in your working folder but are not under version control.<br>"
|
Chris@186
|
74 // "Select a file and use Add to place it under version control or Ignore to remove it from this list.");
|
Chris@186
|
75 "Select a file and use Add to place it under version control.");
|
Chris@199
|
76 m_descriptions[FileStates::Ignored] = tr("These files have names that match entries in the working folder's .hgignore file,<br>"
|
Chris@199
|
77 "and so will be ignored by the version control system.");
|
Chris@100
|
78
|
Chris@118
|
79 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> "
|
Chris@100
|
80 "have appeared since your most recent commit or update.");
|
Chris@89
|
81
|
Chris@230
|
82 m_boxesParent = new QWidget(this);
|
Chris@230
|
83 layout->addWidget(m_boxesParent, ++row, 0, 1, 3);
|
Chris@230
|
84
|
Chris@230
|
85 QGridLayout *boxesLayout = new QGridLayout;
|
Chris@230
|
86 boxesLayout->setMargin(0);
|
Chris@230
|
87 m_boxesParent->setLayout(boxesLayout);
|
Chris@230
|
88 int boxRow = 0;
|
Chris@230
|
89
|
Chris@94
|
90 for (int i = int(FileStates::FirstState);
|
Chris@163
|
91 i <= int(FileStates::LastState); ++i) {
|
Chris@89
|
92
|
Chris@94
|
93 FileStates::State s = FileStates::State(i);
|
Chris@89
|
94
|
Chris@230
|
95 QWidget *box = new QWidget(m_boxesParent);
|
Chris@89
|
96 QGridLayout *boxlayout = new QGridLayout;
|
Chris@99
|
97 boxlayout->setMargin(0);
|
Chris@89
|
98 box->setLayout(boxlayout);
|
Chris@89
|
99
|
Chris@211
|
100 boxlayout->addItem(new QSpacerItem(3, 3), 0, 0);
|
Chris@101
|
101
|
Chris@230
|
102 QLabel *label = new QLabel(labelFor(s));
|
Chris@230
|
103 label->setWordWrap(true);
|
Chris@230
|
104 boxlayout->addWidget(label, 1, 0);
|
Chris@89
|
105
|
Chris@94
|
106 QListWidget *w = new QListWidget;
|
Chris@94
|
107 m_stateListMap[s] = w;
|
Chris@94
|
108 w->setSelectionMode(QListWidget::ExtendedSelection);
|
Chris@101
|
109 boxlayout->addWidget(w, 2, 0);
|
Chris@89
|
110
|
Chris@95
|
111 connect(w, SIGNAL(itemSelectionChanged()),
|
Chris@95
|
112 this, SLOT(itemSelectionChanged()));
|
Chris@95
|
113
|
Chris@211
|
114 boxlayout->addItem(new QSpacerItem(2, 2), 3, 0);
|
Chris@211
|
115
|
Chris@230
|
116 boxesLayout->addWidget(box, ++boxRow, 0);
|
Chris@230
|
117 m_boxes.push_back(box);
|
Chris@89
|
118 box->hide();
|
Chris@89
|
119 }
|
Chris@89
|
120
|
Chris@230
|
121 m_gridlyLayout = false;
|
Chris@230
|
122
|
Chris@89
|
123 layout->setRowStretch(++row, 20);
|
Chris@186
|
124
|
Chris@211
|
125 layout->addItem(new QSpacerItem(8, 8), ++row, 0);
|
Chris@199
|
126
|
Chris@199
|
127 m_showAllFiles = new QCheckBox(tr("Show all files"), this);
|
Chris@199
|
128 layout->addWidget(m_showAllFiles, ++row, 0, 1, 3, Qt::AlignLeft);
|
Chris@199
|
129 connect(m_showAllFiles, SIGNAL(toggled(bool)),
|
Chris@199
|
130 this, SIGNAL(showAllChanged(bool)));
|
Chris@88
|
131 }
|
Chris@88
|
132
|
Chris@93
|
133 FileStatusWidget::~FileStatusWidget()
|
Chris@93
|
134 {
|
Chris@93
|
135 delete m_dateReference;
|
Chris@93
|
136 }
|
Chris@93
|
137
|
Chris@100
|
138 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation)
|
Chris@100
|
139 {
|
Chris@230
|
140 QSettings settings;
|
Chris@230
|
141 settings.beginGroup("Presentation");
|
Chris@230
|
142 if (settings.value("showhelpfultext", true).toBool()) {
|
Chris@230
|
143 if (addHighlightExplanation) {
|
Chris@230
|
144 return QString("<qt><b>%1</b><br>%2<br>%3</qt>")
|
Chris@230
|
145 .arg(m_simpleLabels[s])
|
Chris@230
|
146 .arg(m_descriptions[s])
|
Chris@230
|
147 .arg(m_highlightExplanation);
|
Chris@230
|
148 } else {
|
Chris@230
|
149 return QString("<qt><b>%1</b><br>%2</qt>")
|
Chris@230
|
150 .arg(m_simpleLabels[s])
|
Chris@230
|
151 .arg(m_descriptions[s]);
|
Chris@230
|
152 }
|
Chris@100
|
153 } else {
|
Chris@230
|
154 return QString("<qt><b>%1</b></qt>")
|
Chris@230
|
155 .arg(m_simpleLabels[s]);
|
Chris@230
|
156 }
|
Chris@230
|
157 settings.endGroup();
|
Chris@230
|
158 }
|
Chris@230
|
159
|
Chris@230
|
160 void FileStatusWidget::setNoModificationsLabelText()
|
Chris@230
|
161 {
|
Chris@230
|
162 QSettings settings;
|
Chris@230
|
163 settings.beginGroup("Presentation");
|
Chris@230
|
164 if (settings.value("showhelpfultext", true).toBool()) {
|
Chris@230
|
165 m_noModificationsLabel->setText
|
Chris@230
|
166 (tr("<qt>This area will list files in your working folder that you have changed.<br><br>At the moment you have no uncommitted changes.<br><br>To see changes previously made to the repository,<br>switch to the History tab.<br><br>%1</qt>")
|
Chris@230
|
167 #if defined Q_OS_MAC
|
Chris@230
|
168 .arg(tr("To open the working folder in Finder,<br>click on the “Local” folder path shown above."))
|
Chris@230
|
169 #elif defined Q_OS_WIN32
|
Chris@230
|
170 .arg(tr("To open the working folder in Windows Explorer,<br>click on the “Local” folder path shown above."))
|
Chris@230
|
171 #else
|
Chris@230
|
172 .arg(tr("To open the working folder in your system file manager,<br>click the “Local” folder path shown above."))
|
Chris@230
|
173 #endif
|
Chris@230
|
174 );
|
Chris@230
|
175 } else {
|
Chris@230
|
176 m_noModificationsLabel->setText
|
Chris@230
|
177 (tr("<qt>You have no uncommitted changes.</qt>"));
|
Chris@100
|
178 }
|
Chris@100
|
179 }
|
Chris@100
|
180
|
Chris@95
|
181 void FileStatusWidget::itemSelectionChanged()
|
Chris@95
|
182 {
|
Chris@135
|
183 DEBUG << "FileStatusWidget::itemSelectionChanged" << endl;
|
Chris@135
|
184
|
Chris@135
|
185 QListWidget *list = qobject_cast<QListWidget *>(sender());
|
Chris@135
|
186
|
Chris@135
|
187 if (list) {
|
Chris@135
|
188 foreach (QListWidget *w, m_stateListMap) {
|
Chris@135
|
189 if (w != list) {
|
Chris@135
|
190 w->blockSignals(true);
|
Chris@135
|
191 w->clearSelection();
|
Chris@135
|
192 w->blockSignals(false);
|
Chris@135
|
193 }
|
Chris@135
|
194 }
|
Chris@135
|
195 }
|
Chris@135
|
196
|
Chris@95
|
197 m_selectedFiles.clear();
|
Chris@95
|
198
|
Chris@95
|
199 foreach (QListWidget *w, m_stateListMap) {
|
Chris@95
|
200 QList<QListWidgetItem *> sel = w->selectedItems();
|
Chris@95
|
201 foreach (QListWidgetItem *i, sel) {
|
Chris@95
|
202 m_selectedFiles.push_back(i->text());
|
Chris@95
|
203 DEBUG << "file " << i->text() << " is selected" << endl;
|
Chris@95
|
204 }
|
Chris@95
|
205 }
|
Chris@95
|
206
|
Chris@95
|
207 emit selectionChanged();
|
Chris@95
|
208 }
|
Chris@95
|
209
|
Chris@94
|
210 void FileStatusWidget::clearSelections()
|
Chris@94
|
211 {
|
Chris@95
|
212 m_selectedFiles.clear();
|
Chris@94
|
213 foreach (QListWidget *w, m_stateListMap) {
|
Chris@94
|
214 w->clearSelection();
|
Chris@94
|
215 }
|
Chris@94
|
216 }
|
Chris@94
|
217
|
Chris@95
|
218 bool FileStatusWidget::haveChangesToCommit() const
|
Chris@95
|
219 {
|
Chris@95
|
220 return !m_fileStates.added().empty() ||
|
Chris@95
|
221 !m_fileStates.removed().empty() ||
|
Chris@95
|
222 !m_fileStates.modified().empty();
|
Chris@95
|
223 }
|
Chris@95
|
224
|
Chris@95
|
225 bool FileStatusWidget::haveSelection() const
|
Chris@95
|
226 {
|
Chris@95
|
227 return !m_selectedFiles.empty();
|
Chris@95
|
228 }
|
Chris@95
|
229
|
Chris@95
|
230 QStringList FileStatusWidget::getAllSelectedFiles() const
|
Chris@95
|
231 {
|
Chris@95
|
232 return m_selectedFiles;
|
Chris@95
|
233 }
|
Chris@95
|
234
|
Chris@95
|
235 QStringList FileStatusWidget::getSelectedCommittableFiles() const
|
Chris@95
|
236 {
|
Chris@95
|
237 QStringList files;
|
Chris@95
|
238 foreach (QString f, m_selectedFiles) {
|
Chris@95
|
239 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@95
|
240 case FileStates::Added:
|
Chris@95
|
241 case FileStates::Modified:
|
Chris@95
|
242 case FileStates::Removed:
|
Chris@95
|
243 files.push_back(f);
|
Chris@95
|
244 break;
|
Chris@95
|
245 default: break;
|
Chris@95
|
246 }
|
Chris@95
|
247 }
|
Chris@95
|
248 return files;
|
Chris@95
|
249 }
|
Chris@95
|
250
|
Chris@103
|
251 QStringList FileStatusWidget::getAllCommittableFiles() const
|
Chris@103
|
252 {
|
Chris@103
|
253 QStringList files;
|
Chris@103
|
254 files << m_fileStates.getFilesInState(FileStates::Modified);
|
Chris@103
|
255 files << m_fileStates.getFilesInState(FileStates::Added);
|
Chris@103
|
256 files << m_fileStates.getFilesInState(FileStates::Removed);
|
Chris@103
|
257 return files;
|
Chris@103
|
258 }
|
Chris@103
|
259
|
Chris@109
|
260 QStringList FileStatusWidget::getSelectedRevertableFiles() const
|
Chris@109
|
261 {
|
Chris@109
|
262 QStringList files;
|
Chris@109
|
263 foreach (QString f, m_selectedFiles) {
|
Chris@109
|
264 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@109
|
265 case FileStates::Added:
|
Chris@109
|
266 case FileStates::Modified:
|
Chris@109
|
267 case FileStates::Removed:
|
Chris@109
|
268 case FileStates::Missing:
|
Chris@163
|
269 case FileStates::InConflict:
|
Chris@109
|
270 files.push_back(f);
|
Chris@109
|
271 break;
|
Chris@109
|
272 default: break;
|
Chris@109
|
273 }
|
Chris@109
|
274 }
|
Chris@109
|
275 return files;
|
Chris@109
|
276 }
|
Chris@109
|
277
|
Chris@109
|
278 QStringList FileStatusWidget::getAllRevertableFiles() const
|
Chris@109
|
279 {
|
Chris@109
|
280 QStringList files;
|
Chris@109
|
281 files << m_fileStates.getFilesInState(FileStates::Modified);
|
Chris@109
|
282 files << m_fileStates.getFilesInState(FileStates::Added);
|
Chris@109
|
283 files << m_fileStates.getFilesInState(FileStates::Removed);
|
Chris@109
|
284 files << m_fileStates.getFilesInState(FileStates::Missing);
|
Chris@163
|
285 files << m_fileStates.getFilesInState(FileStates::InConflict);
|
Chris@163
|
286 return files;
|
Chris@163
|
287 }
|
Chris@163
|
288
|
Chris@163
|
289 QStringList FileStatusWidget::getSelectedUnresolvedFiles() const
|
Chris@163
|
290 {
|
Chris@163
|
291 QStringList files;
|
Chris@163
|
292 foreach (QString f, m_selectedFiles) {
|
Chris@163
|
293 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@163
|
294 case FileStates::InConflict:
|
Chris@163
|
295 files.push_back(f);
|
Chris@163
|
296 break;
|
Chris@163
|
297 default: break;
|
Chris@163
|
298 }
|
Chris@163
|
299 }
|
Chris@163
|
300 return files;
|
Chris@163
|
301 }
|
Chris@163
|
302
|
Chris@163
|
303 QStringList FileStatusWidget::getAllUnresolvedFiles() const
|
Chris@163
|
304 {
|
Chris@163
|
305 QStringList files;
|
Chris@163
|
306 files << m_fileStates.getFilesInState(FileStates::InConflict);
|
Chris@109
|
307 return files;
|
Chris@109
|
308 }
|
Chris@109
|
309
|
Chris@95
|
310 QStringList FileStatusWidget::getSelectedAddableFiles() const
|
Chris@95
|
311 {
|
Chris@95
|
312 QStringList files;
|
Chris@95
|
313 foreach (QString f, m_selectedFiles) {
|
Chris@95
|
314 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@95
|
315 case FileStates::Unknown:
|
Chris@95
|
316 case FileStates::Removed:
|
Chris@95
|
317 files.push_back(f);
|
Chris@95
|
318 break;
|
Chris@95
|
319 default: break;
|
Chris@95
|
320 }
|
Chris@95
|
321 }
|
Chris@95
|
322 return files;
|
Chris@95
|
323 }
|
Chris@95
|
324
|
Chris@103
|
325 QStringList FileStatusWidget::getAllAddableFiles() const
|
Chris@103
|
326 {
|
Chris@103
|
327 QStringList files;
|
Chris@103
|
328 files << m_fileStates.getFilesInState(FileStates::Removed);
|
Chris@103
|
329 files << m_fileStates.getFilesInState(FileStates::Unknown);
|
Chris@103
|
330 return files;
|
Chris@103
|
331 }
|
Chris@103
|
332
|
Chris@95
|
333 QStringList FileStatusWidget::getSelectedRemovableFiles() const
|
Chris@95
|
334 {
|
Chris@95
|
335 QStringList files;
|
Chris@95
|
336 foreach (QString f, m_selectedFiles) {
|
Chris@95
|
337 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@95
|
338 case FileStates::Clean:
|
Chris@95
|
339 case FileStates::Added:
|
Chris@95
|
340 case FileStates::Modified:
|
Chris@95
|
341 case FileStates::Missing:
|
Chris@163
|
342 case FileStates::InConflict:
|
Chris@95
|
343 files.push_back(f);
|
Chris@95
|
344 break;
|
Chris@95
|
345 default: break;
|
Chris@95
|
346 }
|
Chris@95
|
347 }
|
Chris@95
|
348 return files;
|
Chris@95
|
349 }
|
Chris@95
|
350
|
Chris@103
|
351 QStringList FileStatusWidget::getAllRemovableFiles() const
|
Chris@103
|
352 {
|
Chris@103
|
353 QStringList files;
|
Chris@103
|
354 files << m_fileStates.getFilesInState(FileStates::Clean);
|
Chris@103
|
355 files << m_fileStates.getFilesInState(FileStates::Added);
|
Chris@103
|
356 files << m_fileStates.getFilesInState(FileStates::Modified);
|
Chris@103
|
357 files << m_fileStates.getFilesInState(FileStates::Missing);
|
Chris@163
|
358 files << m_fileStates.getFilesInState(FileStates::InConflict);
|
Chris@103
|
359 return files;
|
Chris@103
|
360 }
|
Chris@103
|
361
|
Chris@283
|
362 QString
|
Chris@283
|
363 FileStatusWidget::localPath() const
|
Chris@283
|
364 {
|
Chris@283
|
365 return m_workStatus->localPath();
|
Chris@283
|
366 }
|
Chris@283
|
367
|
Chris@88
|
368 void
|
Chris@88
|
369 FileStatusWidget::setLocalPath(QString p)
|
Chris@88
|
370 {
|
Chris@283
|
371 m_workStatus->setLocalPath(p);
|
Chris@93
|
372 delete m_dateReference;
|
Chris@93
|
373 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
|
Chris@93
|
374 if (!m_dateReference->exists() ||
|
Chris@93
|
375 !m_dateReference->isFile() ||
|
Chris@93
|
376 !m_dateReference->isReadable()) {
|
Chris@93
|
377 DEBUG << "FileStatusWidget::setLocalPath: date reference file "
|
Chris@93
|
378 << m_dateReference->absoluteFilePath()
|
Chris@93
|
379 << " does not exist, is not a file, or cannot be read"
|
Chris@93
|
380 << endl;
|
Chris@93
|
381 delete m_dateReference;
|
Chris@93
|
382 m_dateReference = 0;
|
Chris@93
|
383 }
|
Chris@283
|
384 }
|
Chris@283
|
385
|
Chris@283
|
386 QString
|
Chris@283
|
387 FileStatusWidget::remoteURL() const
|
Chris@283
|
388 {
|
Chris@283
|
389 return m_workStatus->remoteURL();
|
Chris@88
|
390 }
|
Chris@88
|
391
|
Chris@88
|
392 void
|
Chris@88
|
393 FileStatusWidget::setRemoteURL(QString r)
|
Chris@88
|
394 {
|
Chris@283
|
395 m_workStatus->setRemoteURL(r);
|
Chris@283
|
396 }
|
Chris@283
|
397
|
Chris@283
|
398 QString
|
Chris@283
|
399 FileStatusWidget::state() const
|
Chris@283
|
400 {
|
Chris@283
|
401 return m_workStatus->state();
|
Chris@283
|
402 }
|
Chris@283
|
403
|
Chris@283
|
404 void
|
Chris@283
|
405 FileStatusWidget::setState(QString b)
|
Chris@283
|
406 {
|
Chris@283
|
407 m_workStatus->setState(b);
|
Chris@88
|
408 }
|
Chris@88
|
409
|
Chris@88
|
410 void
|
Chris@92
|
411 FileStatusWidget::setFileStates(FileStates p)
|
Chris@88
|
412 {
|
Chris@92
|
413 m_fileStates = p;
|
Chris@88
|
414 updateWidgets();
|
Chris@88
|
415 }
|
Chris@88
|
416
|
Chris@88
|
417 void
|
Chris@88
|
418 FileStatusWidget::updateWidgets()
|
Chris@88
|
419 {
|
Chris@95
|
420 QDateTime lastInteractionTime;
|
Chris@95
|
421 if (m_dateReference) {
|
Chris@95
|
422 lastInteractionTime = m_dateReference->lastModified();
|
Chris@95
|
423 DEBUG << "reference time: " << lastInteractionTime << endl;
|
Chris@95
|
424 }
|
Chris@95
|
425
|
Chris@95
|
426 QSet<QString> selectedFiles;
|
Chris@95
|
427 foreach (QString f, m_selectedFiles) selectedFiles.insert(f);
|
Chris@95
|
428
|
Chris@230
|
429 int visibleCount = 0;
|
Chris@115
|
430
|
Chris@94
|
431 foreach (FileStates::State s, m_stateListMap.keys()) {
|
Chris@95
|
432
|
Chris@94
|
433 QListWidget *w = m_stateListMap[s];
|
Chris@94
|
434 w->clear();
|
Chris@95
|
435 QStringList files = m_fileStates.getFilesInState(s);
|
Chris@93
|
436
|
Chris@95
|
437 QStringList highPriority, lowPriority;
|
Chris@95
|
438
|
Chris@95
|
439 foreach (QString file, files) {
|
Chris@95
|
440
|
Chris@95
|
441 bool highlighted = false;
|
Chris@95
|
442
|
Chris@95
|
443 if (s == FileStates::Unknown) {
|
Chris@95
|
444 // We want to highlight untracked files that have appeared
|
Chris@95
|
445 // since the last interaction with the repo
|
Chris@283
|
446 QString fn(m_workStatus->localPath() + "/" + file);
|
Chris@95
|
447 DEBUG << "comparing with " << fn << endl;
|
Chris@95
|
448 QFileInfo fi(fn);
|
Chris@100
|
449 if (fi.exists() && fi.created() > lastInteractionTime) {
|
Chris@95
|
450 DEBUG << "file " << fn << " is newer (" << fi.lastModified()
|
Chris@95
|
451 << ") than reference" << endl;
|
Chris@95
|
452 highlighted = true;
|
Chris@95
|
453 }
|
Chris@95
|
454 }
|
Chris@95
|
455
|
Chris@95
|
456 if (highlighted) {
|
Chris@95
|
457 highPriority.push_back(file);
|
Chris@95
|
458 } else {
|
Chris@95
|
459 lowPriority.push_back(file);
|
Chris@93
|
460 }
|
Chris@93
|
461 }
|
Chris@95
|
462
|
Chris@95
|
463 foreach (QString file, highPriority) {
|
Chris@95
|
464 QListWidgetItem *item = new QListWidgetItem(file);
|
Chris@95
|
465 w->addItem(item);
|
Chris@118
|
466 item->setForeground(QColor("#d40000")); //!!! and a nice gold star
|
Chris@95
|
467 item->setSelected(selectedFiles.contains(file));
|
Chris@95
|
468 }
|
Chris@95
|
469
|
Chris@95
|
470 foreach (QString file, lowPriority) {
|
Chris@95
|
471 QListWidgetItem *item = new QListWidgetItem(file);
|
Chris@95
|
472 w->addItem(item);
|
Chris@95
|
473 item->setSelected(selectedFiles.contains(file));
|
Chris@95
|
474 }
|
Chris@95
|
475
|
Chris@100
|
476 setLabelFor(w, s, !highPriority.empty());
|
Chris@100
|
477
|
Chris@115
|
478 if (files.empty()) {
|
Chris@115
|
479 w->parentWidget()->hide();
|
Chris@115
|
480 } else {
|
Chris@115
|
481 w->parentWidget()->show();
|
Chris@230
|
482 ++visibleCount;
|
Chris@115
|
483 }
|
Chris@93
|
484 }
|
Chris@115
|
485
|
Chris@230
|
486 m_noModificationsLabel->setVisible(visibleCount == 0);
|
Chris@230
|
487
|
Chris@230
|
488 if (visibleCount > 3) {
|
Chris@230
|
489 layoutBoxesGridly(visibleCount);
|
Chris@230
|
490 } else {
|
Chris@230
|
491 layoutBoxesLinearly();
|
Chris@230
|
492 }
|
Chris@115
|
493
|
Chris@230
|
494 setNoModificationsLabelText();
|
Chris@230
|
495 }
|
Chris@230
|
496
|
Chris@230
|
497 void FileStatusWidget::layoutBoxesGridly(int visibleCount)
|
Chris@230
|
498 {
|
Chris@230
|
499 if (m_gridlyLayout && m_lastGridlyCount == visibleCount) return;
|
Chris@230
|
500
|
Chris@230
|
501 delete m_boxesParent->layout();
|
Chris@230
|
502
|
Chris@230
|
503 QGridLayout *layout = new QGridLayout;
|
Chris@230
|
504 layout->setMargin(0);
|
Chris@230
|
505 m_boxesParent->setLayout(layout);
|
Chris@230
|
506
|
Chris@230
|
507 int row = 0;
|
Chris@230
|
508 int col = 0;
|
Chris@230
|
509
|
Chris@230
|
510 DEBUG << "FileStatusWidget::layoutBoxesGridly: visibleCount = "
|
Chris@230
|
511 << visibleCount << endl;
|
Chris@230
|
512
|
Chris@230
|
513 for (int i = 0; i < m_boxes.size(); ++i) {
|
Chris@230
|
514
|
Chris@230
|
515 if (!m_boxes[i]->isVisible()) continue;
|
Chris@230
|
516
|
Chris@230
|
517 if (col == 0 && row >= (visibleCount+1)/2) {
|
Chris@230
|
518 layout->addItem(new QSpacerItem(10, 5), 0, 1);
|
Chris@230
|
519 col = 2;
|
Chris@230
|
520 row = 0;
|
Chris@230
|
521 }
|
Chris@230
|
522
|
Chris@230
|
523 layout->addWidget(m_boxes[i], row, col);
|
Chris@230
|
524
|
Chris@230
|
525 ++row;
|
Chris@230
|
526 }
|
Chris@230
|
527
|
Chris@230
|
528 m_gridlyLayout = true;
|
Chris@230
|
529 m_lastGridlyCount = visibleCount;
|
Chris@230
|
530 }
|
Chris@230
|
531
|
Chris@230
|
532 void FileStatusWidget::layoutBoxesLinearly()
|
Chris@230
|
533 {
|
Chris@230
|
534 if (!m_gridlyLayout) return;
|
Chris@230
|
535
|
Chris@230
|
536 delete m_boxesParent->layout();
|
Chris@230
|
537
|
Chris@230
|
538 QGridLayout *layout = new QGridLayout;
|
Chris@230
|
539 layout->setMargin(0);
|
Chris@230
|
540 m_boxesParent->setLayout(layout);
|
Chris@230
|
541
|
Chris@230
|
542 for (int i = 0; i < m_boxes.size(); ++i) {
|
Chris@230
|
543 layout->addWidget(m_boxes[i], i, 0);
|
Chris@230
|
544 }
|
Chris@230
|
545
|
Chris@230
|
546 m_gridlyLayout = false;
|
Chris@88
|
547 }
|
Chris@88
|
548
|
Chris@100
|
549 void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight)
|
Chris@100
|
550 {
|
Chris@100
|
551 QString text = labelFor(s, addHighlight);
|
Chris@100
|
552 QWidget *p = w->parentWidget();
|
Chris@100
|
553 QList<QLabel *> ql = p->findChildren<QLabel *>();
|
Chris@100
|
554 if (!ql.empty()) ql[0]->setText(text);
|
Chris@100
|
555 }
|
Chris@115
|
556
|