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