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