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