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@88
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@88
|
9 Copyright (c) 2010 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@186
|
21 #include "clickablelabel.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@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@88
|
40 setLayout(layout);
|
Chris@88
|
41
|
Chris@88
|
42 int row = 0;
|
Chris@88
|
43
|
Chris@115
|
44 layout->addItem(new QSpacerItem(1, 1), row, 0);
|
Chris@115
|
45
|
Chris@115
|
46 ++row;
|
Chris@88
|
47 layout->addWidget(new QLabel(tr("Local:")), row, 0);
|
Chris@186
|
48
|
Chris@186
|
49 m_openButton = new ClickableLabel;
|
Chris@186
|
50 QFont f(m_openButton->font());
|
Chris@89
|
51 f.setBold(true);
|
Chris@186
|
52 m_openButton->setFont(f);
|
Chris@186
|
53 m_openButton->setMouseUnderline(true);
|
Chris@186
|
54 connect(m_openButton, SIGNAL(clicked()), this, SLOT(openButtonClicked()));
|
Chris@187
|
55 layout->addWidget(m_openButton, row, 1, 1, 2, Qt::AlignLeft);
|
Chris@88
|
56
|
Chris@88
|
57 ++row;
|
Chris@88
|
58 layout->addWidget(new QLabel(tr("Remote:")), row, 0);
|
Chris@88
|
59 m_remoteURLLabel = new QLabel;
|
Chris@186
|
60 layout->addWidget(m_remoteURLLabel, row, 1, 1, 2);
|
Chris@88
|
61
|
Chris@106
|
62 ++row;
|
Chris@115
|
63 layout->addWidget(new QLabel(tr("State:")), row, 0);
|
Chris@115
|
64 m_stateLabel = new QLabel;
|
Chris@115
|
65 layout->addWidget(m_stateLabel, row, 1, 1, 2);
|
Chris@106
|
66
|
Chris@89
|
67 layout->setColumnStretch(1, 20);
|
Chris@88
|
68
|
Chris@115
|
69 layout->addWidget(new QLabel("<qt><hr></qt>"), ++row, 0, 1, 3);
|
Chris@115
|
70
|
Chris@115
|
71 ++row;
|
Chris@115
|
72 m_noModificationsLabel = new QLabel
|
Chris@162
|
73 (tr("You have no uncommitted changes."));
|
Chris@115
|
74 layout->addWidget(m_noModificationsLabel, row, 1, 1, 2);
|
Chris@106
|
75
|
Chris@100
|
76 m_simpleLabels[FileStates::Clean] = tr("Unmodified:");
|
Chris@100
|
77 m_simpleLabels[FileStates::Modified] = tr("Modified:");
|
Chris@100
|
78 m_simpleLabels[FileStates::Added] = tr("Added:");
|
Chris@100
|
79 m_simpleLabels[FileStates::Removed] = tr("Removed:");
|
Chris@100
|
80 m_simpleLabels[FileStates::Missing] = tr("Missing:");
|
Chris@163
|
81 m_simpleLabels[FileStates::InConflict] = tr("In Conflict:");
|
Chris@100
|
82 m_simpleLabels[FileStates::Unknown] = tr("Untracked:");
|
Chris@199
|
83 m_simpleLabels[FileStates::Ignored] = tr("Ignored:");
|
Chris@99
|
84
|
Chris@100
|
85 m_descriptions[FileStates::Clean] = tr("You have not changed these files.");
|
Chris@100
|
86 m_descriptions[FileStates::Modified] = tr("You have changed these files since you last committed them.");
|
Chris@100
|
87 m_descriptions[FileStates::Added] = tr("These files will be added to version control next time you commit.");
|
Chris@100
|
88 m_descriptions[FileStates::Removed] = tr("These files will be removed from version control next time you commit.<br>"
|
Chris@100
|
89 "They will not be deleted from the local folder.");
|
Chris@109
|
90 m_descriptions[FileStates::Missing] = tr("These files are recorded in the version control, but absent from your working folder.<br>"
|
Chris@153
|
91 "If you intended to delete them, select them and use Remove to tell the version control system about it.<br>"
|
Chris@153
|
92 "If you deleted them by accident, select them and use Revert to restore their previous contents.");
|
Chris@163
|
93 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
|
94 m_descriptions[FileStates::Unknown] = tr("These files are in your working folder but are not under version control.<br>"
|
Chris@186
|
95 // "Select a file and use Add to place it under version control or Ignore to remove it from this list.");
|
Chris@186
|
96 "Select a file and use Add to place it under version control.");
|
Chris@199
|
97 m_descriptions[FileStates::Ignored] = tr("These files have names that match entries in the working folder's .hgignore file,<br>"
|
Chris@199
|
98 "and so will be ignored by the version control system.");
|
Chris@100
|
99
|
Chris@118
|
100 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> "
|
Chris@100
|
101 "have appeared since your most recent commit or update.");
|
Chris@89
|
102
|
Chris@94
|
103 for (int i = int(FileStates::FirstState);
|
Chris@163
|
104 i <= int(FileStates::LastState); ++i) {
|
Chris@89
|
105
|
Chris@94
|
106 FileStates::State s = FileStates::State(i);
|
Chris@89
|
107
|
Chris@89
|
108 QWidget *box = new QWidget;
|
Chris@89
|
109 QGridLayout *boxlayout = new QGridLayout;
|
Chris@99
|
110 boxlayout->setMargin(0);
|
Chris@89
|
111 box->setLayout(boxlayout);
|
Chris@89
|
112
|
Chris@106
|
113 boxlayout->addItem(new QSpacerItem(5, 5), 0, 0);
|
Chris@101
|
114
|
Chris@101
|
115 boxlayout->addWidget(new QLabel(labelFor(s)), 1, 0);
|
Chris@89
|
116
|
Chris@94
|
117 QListWidget *w = new QListWidget;
|
Chris@94
|
118 m_stateListMap[s] = w;
|
Chris@94
|
119 w->setSelectionMode(QListWidget::ExtendedSelection);
|
Chris@101
|
120 boxlayout->addWidget(w, 2, 0);
|
Chris@89
|
121
|
Chris@95
|
122 connect(w, SIGNAL(itemSelectionChanged()),
|
Chris@95
|
123 this, SLOT(itemSelectionChanged()));
|
Chris@95
|
124
|
Chris@115
|
125 layout->addWidget(box, ++row, 0, 1, 3);
|
Chris@89
|
126 box->hide();
|
Chris@89
|
127 }
|
Chris@89
|
128
|
Chris@89
|
129 layout->setRowStretch(++row, 20);
|
Chris@186
|
130
|
Chris@199
|
131 layout->addItem(new QSpacerItem(1, 1), ++row, 0);
|
Chris@199
|
132
|
Chris@199
|
133 m_showAllFiles = new QCheckBox(tr("Show all files"), this);
|
Chris@199
|
134 layout->addWidget(m_showAllFiles, ++row, 0, 1, 3, Qt::AlignLeft);
|
Chris@199
|
135 connect(m_showAllFiles, SIGNAL(toggled(bool)),
|
Chris@199
|
136 this, SIGNAL(showAllChanged(bool)));
|
Chris@88
|
137 }
|
Chris@88
|
138
|
Chris@93
|
139 FileStatusWidget::~FileStatusWidget()
|
Chris@93
|
140 {
|
Chris@93
|
141 delete m_dateReference;
|
Chris@93
|
142 }
|
Chris@93
|
143
|
Chris@186
|
144 void FileStatusWidget::openButtonClicked()
|
Chris@186
|
145 {
|
Chris@186
|
146 QDir d(m_localPath);
|
Chris@186
|
147 if (d.exists()) {
|
Chris@186
|
148 QStringList args;
|
Chris@201
|
149 QString path = d.canonicalPath();
|
Chris@201
|
150 #if defined Q_OS_WIN32
|
Chris@201
|
151 // Although the Win32 API is quite happy to have
|
Chris@201
|
152 // forward slashes as directory separators, Windows
|
Chris@201
|
153 // Explorer is not
|
Chris@201
|
154 path = path.replace('/', '\\');
|
Chris@201
|
155 args << path;
|
Chris@201
|
156 QProcess::execute("c:/windows/explorer.exe", args);
|
Chris@201
|
157 #else
|
Chris@201
|
158 args << path;
|
Chris@186
|
159 QProcess::execute(
|
Chris@201
|
160 #if defined Q_OS_MAC
|
Chris@186
|
161 "/usr/bin/open",
|
Chris@186
|
162 #else
|
Chris@186
|
163 "/usr/bin/xdg-open",
|
Chris@186
|
164 #endif
|
Chris@186
|
165 args);
|
Chris@201
|
166 #endif
|
Chris@186
|
167 }
|
Chris@186
|
168 }
|
Chris@186
|
169
|
Chris@100
|
170 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation)
|
Chris@100
|
171 {
|
Chris@100
|
172 if (addHighlightExplanation) {
|
Chris@100
|
173 return QString("<qt><b>%1</b><br>%2<br>%3</qt>")
|
Chris@100
|
174 .arg(m_simpleLabels[s])
|
Chris@100
|
175 .arg(m_descriptions[s])
|
Chris@100
|
176 .arg(m_highlightExplanation);
|
Chris@100
|
177 } else {
|
Chris@100
|
178 return QString("<qt><b>%1</b><br>%2</qt>")
|
Chris@100
|
179 .arg(m_simpleLabels[s])
|
Chris@100
|
180 .arg(m_descriptions[s]);
|
Chris@100
|
181 }
|
Chris@100
|
182 }
|
Chris@100
|
183
|
Chris@95
|
184 void FileStatusWidget::itemSelectionChanged()
|
Chris@95
|
185 {
|
Chris@135
|
186 DEBUG << "FileStatusWidget::itemSelectionChanged" << endl;
|
Chris@135
|
187
|
Chris@135
|
188 QListWidget *list = qobject_cast<QListWidget *>(sender());
|
Chris@135
|
189
|
Chris@135
|
190 if (list) {
|
Chris@135
|
191 foreach (QListWidget *w, m_stateListMap) {
|
Chris@135
|
192 if (w != list) {
|
Chris@135
|
193 w->blockSignals(true);
|
Chris@135
|
194 w->clearSelection();
|
Chris@135
|
195 w->blockSignals(false);
|
Chris@135
|
196 }
|
Chris@135
|
197 }
|
Chris@135
|
198 }
|
Chris@135
|
199
|
Chris@95
|
200 m_selectedFiles.clear();
|
Chris@95
|
201
|
Chris@95
|
202 foreach (QListWidget *w, m_stateListMap) {
|
Chris@95
|
203 QList<QListWidgetItem *> sel = w->selectedItems();
|
Chris@95
|
204 foreach (QListWidgetItem *i, sel) {
|
Chris@95
|
205 m_selectedFiles.push_back(i->text());
|
Chris@95
|
206 DEBUG << "file " << i->text() << " is selected" << endl;
|
Chris@95
|
207 }
|
Chris@95
|
208 }
|
Chris@95
|
209
|
Chris@95
|
210 emit selectionChanged();
|
Chris@95
|
211 }
|
Chris@95
|
212
|
Chris@94
|
213 void FileStatusWidget::clearSelections()
|
Chris@94
|
214 {
|
Chris@95
|
215 m_selectedFiles.clear();
|
Chris@94
|
216 foreach (QListWidget *w, m_stateListMap) {
|
Chris@94
|
217 w->clearSelection();
|
Chris@94
|
218 }
|
Chris@94
|
219 }
|
Chris@94
|
220
|
Chris@95
|
221 bool FileStatusWidget::haveChangesToCommit() const
|
Chris@95
|
222 {
|
Chris@95
|
223 return !m_fileStates.added().empty() ||
|
Chris@95
|
224 !m_fileStates.removed().empty() ||
|
Chris@95
|
225 !m_fileStates.modified().empty();
|
Chris@95
|
226 }
|
Chris@95
|
227
|
Chris@95
|
228 bool FileStatusWidget::haveSelection() const
|
Chris@95
|
229 {
|
Chris@95
|
230 return !m_selectedFiles.empty();
|
Chris@95
|
231 }
|
Chris@95
|
232
|
Chris@95
|
233 QStringList FileStatusWidget::getAllSelectedFiles() const
|
Chris@95
|
234 {
|
Chris@95
|
235 return m_selectedFiles;
|
Chris@95
|
236 }
|
Chris@95
|
237
|
Chris@95
|
238 QStringList FileStatusWidget::getSelectedCommittableFiles() const
|
Chris@95
|
239 {
|
Chris@95
|
240 QStringList files;
|
Chris@95
|
241 foreach (QString f, m_selectedFiles) {
|
Chris@95
|
242 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@95
|
243 case FileStates::Added:
|
Chris@95
|
244 case FileStates::Modified:
|
Chris@95
|
245 case FileStates::Removed:
|
Chris@95
|
246 files.push_back(f);
|
Chris@95
|
247 break;
|
Chris@95
|
248 default: break;
|
Chris@95
|
249 }
|
Chris@95
|
250 }
|
Chris@95
|
251 return files;
|
Chris@95
|
252 }
|
Chris@95
|
253
|
Chris@103
|
254 QStringList FileStatusWidget::getAllCommittableFiles() const
|
Chris@103
|
255 {
|
Chris@103
|
256 QStringList files;
|
Chris@103
|
257 files << m_fileStates.getFilesInState(FileStates::Modified);
|
Chris@103
|
258 files << m_fileStates.getFilesInState(FileStates::Added);
|
Chris@103
|
259 files << m_fileStates.getFilesInState(FileStates::Removed);
|
Chris@103
|
260 return files;
|
Chris@103
|
261 }
|
Chris@103
|
262
|
Chris@109
|
263 QStringList FileStatusWidget::getSelectedRevertableFiles() const
|
Chris@109
|
264 {
|
Chris@109
|
265 QStringList files;
|
Chris@109
|
266 foreach (QString f, m_selectedFiles) {
|
Chris@109
|
267 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@109
|
268 case FileStates::Added:
|
Chris@109
|
269 case FileStates::Modified:
|
Chris@109
|
270 case FileStates::Removed:
|
Chris@109
|
271 case FileStates::Missing:
|
Chris@163
|
272 case FileStates::InConflict:
|
Chris@109
|
273 files.push_back(f);
|
Chris@109
|
274 break;
|
Chris@109
|
275 default: break;
|
Chris@109
|
276 }
|
Chris@109
|
277 }
|
Chris@109
|
278 return files;
|
Chris@109
|
279 }
|
Chris@109
|
280
|
Chris@109
|
281 QStringList FileStatusWidget::getAllRevertableFiles() const
|
Chris@109
|
282 {
|
Chris@109
|
283 QStringList files;
|
Chris@109
|
284 files << m_fileStates.getFilesInState(FileStates::Modified);
|
Chris@109
|
285 files << m_fileStates.getFilesInState(FileStates::Added);
|
Chris@109
|
286 files << m_fileStates.getFilesInState(FileStates::Removed);
|
Chris@109
|
287 files << m_fileStates.getFilesInState(FileStates::Missing);
|
Chris@163
|
288 files << m_fileStates.getFilesInState(FileStates::InConflict);
|
Chris@163
|
289 return files;
|
Chris@163
|
290 }
|
Chris@163
|
291
|
Chris@163
|
292 QStringList FileStatusWidget::getSelectedUnresolvedFiles() const
|
Chris@163
|
293 {
|
Chris@163
|
294 QStringList files;
|
Chris@163
|
295 foreach (QString f, m_selectedFiles) {
|
Chris@163
|
296 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@163
|
297 case FileStates::InConflict:
|
Chris@163
|
298 files.push_back(f);
|
Chris@163
|
299 break;
|
Chris@163
|
300 default: break;
|
Chris@163
|
301 }
|
Chris@163
|
302 }
|
Chris@163
|
303 return files;
|
Chris@163
|
304 }
|
Chris@163
|
305
|
Chris@163
|
306 QStringList FileStatusWidget::getAllUnresolvedFiles() const
|
Chris@163
|
307 {
|
Chris@163
|
308 QStringList files;
|
Chris@163
|
309 files << m_fileStates.getFilesInState(FileStates::InConflict);
|
Chris@109
|
310 return files;
|
Chris@109
|
311 }
|
Chris@109
|
312
|
Chris@95
|
313 QStringList FileStatusWidget::getSelectedAddableFiles() const
|
Chris@95
|
314 {
|
Chris@95
|
315 QStringList files;
|
Chris@95
|
316 foreach (QString f, m_selectedFiles) {
|
Chris@95
|
317 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@95
|
318 case FileStates::Unknown:
|
Chris@95
|
319 case FileStates::Removed:
|
Chris@95
|
320 files.push_back(f);
|
Chris@95
|
321 break;
|
Chris@95
|
322 default: break;
|
Chris@95
|
323 }
|
Chris@95
|
324 }
|
Chris@95
|
325 return files;
|
Chris@95
|
326 }
|
Chris@95
|
327
|
Chris@103
|
328 QStringList FileStatusWidget::getAllAddableFiles() const
|
Chris@103
|
329 {
|
Chris@103
|
330 QStringList files;
|
Chris@103
|
331 files << m_fileStates.getFilesInState(FileStates::Removed);
|
Chris@103
|
332 files << m_fileStates.getFilesInState(FileStates::Unknown);
|
Chris@103
|
333 return files;
|
Chris@103
|
334 }
|
Chris@103
|
335
|
Chris@95
|
336 QStringList FileStatusWidget::getSelectedRemovableFiles() const
|
Chris@95
|
337 {
|
Chris@95
|
338 QStringList files;
|
Chris@95
|
339 foreach (QString f, m_selectedFiles) {
|
Chris@95
|
340 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@95
|
341 case FileStates::Clean:
|
Chris@95
|
342 case FileStates::Added:
|
Chris@95
|
343 case FileStates::Modified:
|
Chris@95
|
344 case FileStates::Missing:
|
Chris@163
|
345 case FileStates::InConflict:
|
Chris@95
|
346 files.push_back(f);
|
Chris@95
|
347 break;
|
Chris@95
|
348 default: break;
|
Chris@95
|
349 }
|
Chris@95
|
350 }
|
Chris@95
|
351 return files;
|
Chris@95
|
352 }
|
Chris@95
|
353
|
Chris@103
|
354 QStringList FileStatusWidget::getAllRemovableFiles() const
|
Chris@103
|
355 {
|
Chris@103
|
356 QStringList files;
|
Chris@103
|
357 files << m_fileStates.getFilesInState(FileStates::Clean);
|
Chris@103
|
358 files << m_fileStates.getFilesInState(FileStates::Added);
|
Chris@103
|
359 files << m_fileStates.getFilesInState(FileStates::Modified);
|
Chris@103
|
360 files << m_fileStates.getFilesInState(FileStates::Missing);
|
Chris@163
|
361 files << m_fileStates.getFilesInState(FileStates::InConflict);
|
Chris@103
|
362 return files;
|
Chris@103
|
363 }
|
Chris@103
|
364
|
Chris@88
|
365 void
|
Chris@88
|
366 FileStatusWidget::setLocalPath(QString p)
|
Chris@88
|
367 {
|
Chris@88
|
368 m_localPath = p;
|
Chris@186
|
369 m_openButton->setText(p);
|
Chris@93
|
370 delete m_dateReference;
|
Chris@93
|
371 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
|
Chris@93
|
372 if (!m_dateReference->exists() ||
|
Chris@93
|
373 !m_dateReference->isFile() ||
|
Chris@93
|
374 !m_dateReference->isReadable()) {
|
Chris@93
|
375 DEBUG << "FileStatusWidget::setLocalPath: date reference file "
|
Chris@93
|
376 << m_dateReference->absoluteFilePath()
|
Chris@93
|
377 << " does not exist, is not a file, or cannot be read"
|
Chris@93
|
378 << endl;
|
Chris@93
|
379 delete m_dateReference;
|
Chris@93
|
380 m_dateReference = 0;
|
Chris@93
|
381 }
|
Chris@186
|
382 m_openButton->setEnabled(QDir(m_localPath).exists());
|
Chris@88
|
383 }
|
Chris@88
|
384
|
Chris@88
|
385 void
|
Chris@88
|
386 FileStatusWidget::setRemoteURL(QString r)
|
Chris@88
|
387 {
|
Chris@88
|
388 m_remoteURL = r;
|
Chris@88
|
389 m_remoteURLLabel->setText(r);
|
Chris@88
|
390 }
|
Chris@88
|
391
|
Chris@88
|
392 void
|
Chris@92
|
393 FileStatusWidget::setFileStates(FileStates p)
|
Chris@88
|
394 {
|
Chris@92
|
395 m_fileStates = p;
|
Chris@88
|
396 updateWidgets();
|
Chris@88
|
397 }
|
Chris@88
|
398
|
Chris@88
|
399 void
|
Chris@115
|
400 FileStatusWidget::setState(QString b)
|
Chris@106
|
401 {
|
Chris@115
|
402 m_state = b;
|
Chris@115
|
403 updateStateLabel();
|
Chris@106
|
404 }
|
Chris@106
|
405
|
Chris@106
|
406 void
|
Chris@88
|
407 FileStatusWidget::updateWidgets()
|
Chris@88
|
408 {
|
Chris@95
|
409 QDateTime lastInteractionTime;
|
Chris@95
|
410 if (m_dateReference) {
|
Chris@95
|
411 lastInteractionTime = m_dateReference->lastModified();
|
Chris@95
|
412 DEBUG << "reference time: " << lastInteractionTime << endl;
|
Chris@95
|
413 }
|
Chris@95
|
414
|
Chris@95
|
415 QSet<QString> selectedFiles;
|
Chris@95
|
416 foreach (QString f, m_selectedFiles) selectedFiles.insert(f);
|
Chris@95
|
417
|
Chris@115
|
418 bool haveAnything = false;
|
Chris@115
|
419
|
Chris@94
|
420 foreach (FileStates::State s, m_stateListMap.keys()) {
|
Chris@95
|
421
|
Chris@94
|
422 QListWidget *w = m_stateListMap[s];
|
Chris@94
|
423 w->clear();
|
Chris@95
|
424 QStringList files = m_fileStates.getFilesInState(s);
|
Chris@93
|
425
|
Chris@95
|
426 QStringList highPriority, lowPriority;
|
Chris@95
|
427
|
Chris@95
|
428 foreach (QString file, files) {
|
Chris@95
|
429
|
Chris@95
|
430 bool highlighted = false;
|
Chris@95
|
431
|
Chris@95
|
432 if (s == FileStates::Unknown) {
|
Chris@95
|
433 // We want to highlight untracked files that have appeared
|
Chris@95
|
434 // since the last interaction with the repo
|
Chris@95
|
435 QString fn(m_localPath + "/" + file);
|
Chris@95
|
436 DEBUG << "comparing with " << fn << endl;
|
Chris@95
|
437 QFileInfo fi(fn);
|
Chris@100
|
438 if (fi.exists() && fi.created() > lastInteractionTime) {
|
Chris@95
|
439 DEBUG << "file " << fn << " is newer (" << fi.lastModified()
|
Chris@95
|
440 << ") than reference" << endl;
|
Chris@95
|
441 highlighted = true;
|
Chris@95
|
442 }
|
Chris@95
|
443 }
|
Chris@95
|
444
|
Chris@95
|
445 if (highlighted) {
|
Chris@95
|
446 highPriority.push_back(file);
|
Chris@95
|
447 } else {
|
Chris@95
|
448 lowPriority.push_back(file);
|
Chris@93
|
449 }
|
Chris@93
|
450 }
|
Chris@95
|
451
|
Chris@95
|
452 foreach (QString file, highPriority) {
|
Chris@95
|
453 QListWidgetItem *item = new QListWidgetItem(file);
|
Chris@95
|
454 w->addItem(item);
|
Chris@118
|
455 item->setForeground(QColor("#d40000")); //!!! and a nice gold star
|
Chris@95
|
456 item->setSelected(selectedFiles.contains(file));
|
Chris@95
|
457 }
|
Chris@95
|
458
|
Chris@95
|
459 foreach (QString file, lowPriority) {
|
Chris@95
|
460 QListWidgetItem *item = new QListWidgetItem(file);
|
Chris@95
|
461 w->addItem(item);
|
Chris@95
|
462 item->setSelected(selectedFiles.contains(file));
|
Chris@95
|
463 }
|
Chris@95
|
464
|
Chris@100
|
465 setLabelFor(w, s, !highPriority.empty());
|
Chris@100
|
466
|
Chris@115
|
467 if (files.empty()) {
|
Chris@115
|
468 w->parentWidget()->hide();
|
Chris@115
|
469 } else {
|
Chris@115
|
470 w->parentWidget()->show();
|
Chris@115
|
471 haveAnything = true;
|
Chris@115
|
472 }
|
Chris@93
|
473 }
|
Chris@115
|
474
|
Chris@115
|
475 m_noModificationsLabel->setVisible(!haveAnything);
|
Chris@115
|
476
|
Chris@115
|
477 updateStateLabel();
|
Chris@88
|
478 }
|
Chris@88
|
479
|
Chris@100
|
480 void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight)
|
Chris@100
|
481 {
|
Chris@100
|
482 QString text = labelFor(s, addHighlight);
|
Chris@100
|
483 QWidget *p = w->parentWidget();
|
Chris@100
|
484 QList<QLabel *> ql = p->findChildren<QLabel *>();
|
Chris@100
|
485 if (!ql.empty()) ql[0]->setText(text);
|
Chris@100
|
486 }
|
Chris@115
|
487
|
Chris@115
|
488 void FileStatusWidget::updateStateLabel()
|
Chris@115
|
489 {
|
Chris@115
|
490 m_stateLabel->setText(m_state);
|
Chris@115
|
491 }
|