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