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