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