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@560
|
8 Copyright (c) 2012 Chris Cannam
|
Chris@560
|
9 Copyright (c) 2012 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@558
|
21 #include "findwidget.h"
|
Chris@88
|
22
|
Chris@88
|
23 #include <QLabel>
|
Chris@88
|
24 #include <QListWidget>
|
Chris@88
|
25 #include <QGridLayout>
|
Chris@93
|
26 #include <QFileInfo>
|
Chris@93
|
27 #include <QApplication>
|
Chris@93
|
28 #include <QDateTime>
|
Chris@115
|
29 #include <QPushButton>
|
Chris@186
|
30 #include <QToolButton>
|
Chris@186
|
31 #include <QDir>
|
Chris@186
|
32 #include <QProcess>
|
Chris@199
|
33 #include <QCheckBox>
|
Chris@230
|
34 #include <QSettings>
|
Chris@323
|
35 #include <QAction>
|
Chris@88
|
36
|
Chris@88
|
37 FileStatusWidget::FileStatusWidget(QWidget *parent) :
|
Chris@93
|
38 QWidget(parent),
|
Chris@93
|
39 m_dateReference(0)
|
Chris@88
|
40 {
|
Chris@88
|
41 QGridLayout *layout = new QGridLayout;
|
Chris@215
|
42 layout->setMargin(10);
|
Chris@88
|
43 setLayout(layout);
|
Chris@88
|
44
|
Chris@88
|
45 int row = 0;
|
Chris@211
|
46
|
Chris@230
|
47 m_noModificationsLabel = new QLabel;
|
Chris@230
|
48 setNoModificationsLabelText();
|
Chris@297
|
49 layout->addWidget(m_noModificationsLabel, row, 0);
|
Chris@202
|
50 m_noModificationsLabel->hide();
|
Chris@106
|
51
|
Chris@100
|
52 m_simpleLabels[FileStates::Clean] = tr("Unmodified:");
|
Chris@100
|
53 m_simpleLabels[FileStates::Modified] = tr("Modified:");
|
Chris@100
|
54 m_simpleLabels[FileStates::Added] = tr("Added:");
|
Chris@100
|
55 m_simpleLabels[FileStates::Removed] = tr("Removed:");
|
Chris@100
|
56 m_simpleLabels[FileStates::Missing] = tr("Missing:");
|
Chris@163
|
57 m_simpleLabels[FileStates::InConflict] = tr("In Conflict:");
|
Chris@100
|
58 m_simpleLabels[FileStates::Unknown] = tr("Untracked:");
|
Chris@199
|
59 m_simpleLabels[FileStates::Ignored] = tr("Ignored:");
|
Chris@99
|
60
|
Chris@326
|
61 m_actionLabels[FileStates::Annotate] = tr("Show annotated version");
|
Chris@326
|
62 m_actionLabels[FileStates::Diff] = tr("Diff to parent");
|
Chris@325
|
63 m_actionLabels[FileStates::Commit] = tr("Commit...");
|
Chris@328
|
64 m_actionLabels[FileStates::Revert] = tr("Revert to last committed state");
|
Chris@361
|
65 m_actionLabels[FileStates::Rename] = tr("Rename...");
|
Chris@361
|
66 m_actionLabels[FileStates::Copy] = tr("Copy...");
|
Chris@326
|
67 m_actionLabels[FileStates::Add] = tr("Add to version control");
|
Chris@326
|
68 m_actionLabels[FileStates::Remove] = tr("Remove from version control");
|
Chris@326
|
69 m_actionLabels[FileStates::RedoMerge] = tr("Redo merge");
|
Chris@328
|
70 m_actionLabels[FileStates::MarkResolved] = tr("Mark conflict as resolved");
|
Chris@413
|
71 m_actionLabels[FileStates::Ignore] = tr("Ignore...");
|
Chris@421
|
72 // Unignore is too difficult in fact, so we just offer to edit the hgignore
|
Chris@421
|
73 m_actionLabels[FileStates::UnIgnore] = tr("Edit .hgignore File");
|
Chris@325
|
74
|
sam@624
|
75 // No "show in" under Unix at the moment.
|
sam@624
|
76 #if defined Q_OS_MAC
|
sam@624
|
77 m_actionLabels[FileStates::ShowIn] = tr("Show in Finder");
|
sam@624
|
78 #elif defined Q_OS_WIN32
|
sam@624
|
79 m_actionLabels[FileStates::ShowIn] = tr("Show in Windows Explorer");
|
sam@624
|
80 #endif
|
sam@624
|
81
|
sam@624
|
82 m_shortcuts[FileStates::ShowIn] = tr("Ctrl+Shift+S");
|
sam@627
|
83 m_shortcuts[FileStates::Diff] = tr("Ctrl+Shift+D");
|
sam@629
|
84 m_shortcuts[FileStates::Commit] = tr("Ctrl+Shift+C");
|
sam@624
|
85
|
Chris@100
|
86 m_descriptions[FileStates::Clean] = tr("You have not changed these files.");
|
Chris@100
|
87 m_descriptions[FileStates::Modified] = tr("You have changed these files since you last committed them.");
|
Chris@225
|
88 m_descriptions[FileStates::Added] = tr("These files will be added to version control next time you commit them.");
|
Chris@225
|
89 m_descriptions[FileStates::Removed] = tr("These files will be removed from version control next time you commit them.<br>"
|
Chris@100
|
90 "They will not be deleted from the local folder.");
|
Chris@109
|
91 m_descriptions[FileStates::Missing] = tr("These files are recorded in the version control, but absent from your working folder.<br>"
|
Chris@153
|
92 "If you intended to delete them, select them and use Remove to tell the version control system about it.<br>"
|
Chris@596
|
93 "If you deleted them by accident, right-click them and use Revert to restore their previous contents.");
|
Chris@482
|
94 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
|
95 m_descriptions[FileStates::Unknown] = tr("These files are in your working folder but are not under version control.<br>"
|
Chris@186
|
96 // "Select a file and use Add to place it under version control or Ignore to remove it from this list.");
|
Chris@186
|
97 "Select a file and use Add to place it under version control.");
|
Chris@199
|
98 m_descriptions[FileStates::Ignored] = tr("These files have names that match entries in the working folder's .hgignore file,<br>"
|
Chris@199
|
99 "and so will be ignored by the version control system.");
|
Chris@100
|
100
|
Chris@118
|
101 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> "
|
Chris@100
|
102 "have appeared since your most recent commit or update.");
|
Chris@89
|
103
|
Chris@230
|
104 m_boxesParent = new QWidget(this);
|
Chris@297
|
105 layout->addWidget(m_boxesParent, ++row, 0);
|
Chris@230
|
106
|
Chris@230
|
107 QGridLayout *boxesLayout = new QGridLayout;
|
Chris@230
|
108 boxesLayout->setMargin(0);
|
Chris@230
|
109 m_boxesParent->setLayout(boxesLayout);
|
Chris@230
|
110 int boxRow = 0;
|
Chris@230
|
111
|
Chris@94
|
112 for (int i = int(FileStates::FirstState);
|
Chris@163
|
113 i <= int(FileStates::LastState); ++i) {
|
Chris@89
|
114
|
Chris@94
|
115 FileStates::State s = FileStates::State(i);
|
Chris@89
|
116
|
Chris@230
|
117 QWidget *box = new QWidget(m_boxesParent);
|
Chris@89
|
118 QGridLayout *boxlayout = new QGridLayout;
|
Chris@99
|
119 boxlayout->setMargin(0);
|
Chris@89
|
120 box->setLayout(boxlayout);
|
Chris@89
|
121
|
Chris@211
|
122 boxlayout->addItem(new QSpacerItem(3, 3), 0, 0);
|
Chris@101
|
123
|
Chris@230
|
124 QLabel *label = new QLabel(labelFor(s));
|
Chris@230
|
125 label->setWordWrap(true);
|
Chris@230
|
126 boxlayout->addWidget(label, 1, 0);
|
Chris@89
|
127
|
Chris@94
|
128 QListWidget *w = new QListWidget;
|
Chris@94
|
129 m_stateListMap[s] = w;
|
Chris@94
|
130 w->setSelectionMode(QListWidget::ExtendedSelection);
|
Chris@101
|
131 boxlayout->addWidget(w, 2, 0);
|
Chris@89
|
132
|
Chris@95
|
133 connect(w, SIGNAL(itemSelectionChanged()),
|
Chris@95
|
134 this, SLOT(itemSelectionChanged()));
|
Chris@331
|
135 connect(w, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
|
Chris@331
|
136 this, SLOT(itemDoubleClicked(QListWidgetItem *)));
|
Chris@95
|
137
|
Chris@325
|
138 FileStates::Activities activities = m_fileStates.activitiesSupportedBy(s);
|
Chris@325
|
139 int prevGroup = -1;
|
Chris@325
|
140 foreach (FileStates::Activity a, activities) {
|
sam@624
|
141 QString label = m_actionLabels[a];
|
sam@624
|
142 if (label.length() == 0) {
|
sam@624
|
143 // Skip empty labels.
|
sam@624
|
144 continue;
|
sam@624
|
145 }
|
Chris@325
|
146 int group = FileStates::activityGroup(a);
|
Chris@325
|
147 if (group != prevGroup && prevGroup != -1) {
|
Chris@325
|
148 QAction *sep = new QAction("", w);
|
Chris@325
|
149 sep->setSeparator(true);
|
Chris@325
|
150 w->insertAction(0, sep);
|
Chris@325
|
151 }
|
Chris@325
|
152 prevGroup = group;
|
sam@624
|
153 QAction *act = new QAction(label, w);
|
Chris@326
|
154 act->setProperty("state", s);
|
Chris@326
|
155 act->setProperty("activity", a);
|
sam@624
|
156 if (m_shortcuts.contains(a)) {
|
sam@624
|
157 QString shortcut = m_shortcuts[a];
|
sam@624
|
158 act->setShortcut(shortcut);
|
sam@630
|
159 act->setShortcutContext(Qt::WidgetShortcut);
|
sam@624
|
160 }
|
Chris@326
|
161 connect(act, SIGNAL(triggered()), this, SLOT(menuActionActivated()));
|
Chris@325
|
162 w->insertAction(0, act);
|
Chris@325
|
163 }
|
Chris@323
|
164 w->setContextMenuPolicy(Qt::ActionsContextMenu);
|
Chris@323
|
165
|
Chris@211
|
166 boxlayout->addItem(new QSpacerItem(2, 2), 3, 0);
|
Chris@211
|
167
|
Chris@230
|
168 boxesLayout->addWidget(box, ++boxRow, 0);
|
Chris@230
|
169 m_boxes.push_back(box);
|
Chris@89
|
170 box->hide();
|
Chris@89
|
171 }
|
Chris@89
|
172
|
Chris@230
|
173 m_gridlyLayout = false;
|
Chris@230
|
174
|
Chris@89
|
175 layout->setRowStretch(++row, 20);
|
Chris@186
|
176
|
Chris@211
|
177 layout->addItem(new QSpacerItem(8, 8), ++row, 0);
|
Chris@199
|
178
|
Chris@558
|
179 QWidget *opts = new QWidget;
|
Chris@558
|
180 QGridLayout *optLayout = new QGridLayout(opts);
|
Chris@558
|
181 optLayout->setMargin(0);
|
Chris@558
|
182 layout->addWidget(opts, ++row, 0);
|
Chris@558
|
183
|
Chris@558
|
184 m_findWidget = new FindWidget(this);
|
Chris@558
|
185 optLayout->addWidget(m_findWidget, 0, 0, Qt::AlignLeft);
|
Chris@558
|
186 connect(m_findWidget, SIGNAL(findTextChanged(QString)),
|
Chris@558
|
187 this, SLOT(setSearchText(QString)));
|
Chris@558
|
188
|
Chris@558
|
189 m_showAllFiles = new QCheckBox(tr("Show all file states"), this);
|
Chris@340
|
190 m_showAllFiles->setEnabled(false);
|
Chris@558
|
191 optLayout->addWidget(m_showAllFiles, 0, 1, Qt::AlignRight);
|
Chris@484
|
192
|
Chris@484
|
193 QSettings settings;
|
Chris@484
|
194 m_showAllFiles->setChecked(settings.value("showall", false).toBool());
|
Chris@484
|
195
|
Chris@199
|
196 connect(m_showAllFiles, SIGNAL(toggled(bool)),
|
Chris@484
|
197 this, SIGNAL(showAllChanged()));
|
Chris@88
|
198 }
|
Chris@88
|
199
|
Chris@93
|
200 FileStatusWidget::~FileStatusWidget()
|
Chris@93
|
201 {
|
Chris@484
|
202 QSettings settings;
|
Chris@484
|
203 settings.setValue("showall", m_showAllFiles->isChecked());
|
Chris@484
|
204
|
Chris@93
|
205 delete m_dateReference;
|
Chris@93
|
206 }
|
Chris@93
|
207
|
Chris@484
|
208 bool FileStatusWidget::shouldShowAll() const
|
Chris@484
|
209 {
|
Chris@484
|
210 return m_showAllFiles->isChecked();
|
Chris@484
|
211 }
|
Chris@484
|
212
|
Chris@542
|
213 bool FileStatusWidget::shouldShow(FileStates::State s) const
|
Chris@542
|
214 {
|
Chris@542
|
215 if (shouldShowAll()) return true;
|
Chris@542
|
216 else return (s != FileStates::Clean &&
|
Chris@542
|
217 s != FileStates::Ignored);
|
Chris@542
|
218 }
|
Chris@542
|
219
|
Chris@100
|
220 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation)
|
Chris@100
|
221 {
|
Chris@230
|
222 QSettings settings;
|
Chris@230
|
223 settings.beginGroup("Presentation");
|
Chris@230
|
224 if (settings.value("showhelpfultext", true).toBool()) {
|
Chris@230
|
225 if (addHighlightExplanation) {
|
Chris@230
|
226 return QString("<qt><b>%1</b><br>%2<br>%3</qt>")
|
Chris@230
|
227 .arg(m_simpleLabels[s])
|
Chris@230
|
228 .arg(m_descriptions[s])
|
Chris@230
|
229 .arg(m_highlightExplanation);
|
Chris@230
|
230 } else {
|
Chris@230
|
231 return QString("<qt><b>%1</b><br>%2</qt>")
|
Chris@230
|
232 .arg(m_simpleLabels[s])
|
Chris@230
|
233 .arg(m_descriptions[s]);
|
Chris@230
|
234 }
|
Chris@230
|
235 }
|
Chris@542
|
236 return QString("<qt><b>%1</b></qt>")
|
Chris@542
|
237 .arg(m_simpleLabels[s]);
|
Chris@230
|
238 }
|
Chris@230
|
239
|
Chris@230
|
240 void FileStatusWidget::setNoModificationsLabelText()
|
Chris@230
|
241 {
|
Chris@230
|
242 QSettings settings;
|
Chris@230
|
243 settings.beginGroup("Presentation");
|
Chris@558
|
244
|
Chris@558
|
245 if (m_searchText != "") {
|
Chris@558
|
246 if (!m_showAllFiles->isChecked()) {
|
Chris@558
|
247 m_noModificationsLabel->setText
|
Chris@558
|
248 (tr("<qt><b>Nothing found</b><br>None of the modified files have matching filenames.<br>Select <b>Show all file states</b> to find matches among unmodified and untracked files as well.</qt>"));
|
Chris@558
|
249 } else {
|
Chris@558
|
250 m_noModificationsLabel->setText
|
Chris@558
|
251 (tr("<qt><b>Nothing found</b><br>No files have matching filenames.</qt>"));
|
Chris@558
|
252 }
|
Chris@558
|
253 } else if (settings.value("showhelpfultext", true).toBool()) {
|
Chris@230
|
254 m_noModificationsLabel->setText
|
Chris@230
|
255 (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
|
256 #if defined Q_OS_MAC
|
Chris@230
|
257 .arg(tr("To open the working folder in Finder,<br>click on the “Local” folder path shown above."))
|
Chris@230
|
258 #elif defined Q_OS_WIN32
|
Chris@230
|
259 .arg(tr("To open the working folder in Windows Explorer,<br>click on the “Local” folder path shown above."))
|
Chris@230
|
260 #else
|
Chris@230
|
261 .arg(tr("To open the working folder in your system file manager,<br>click the “Local” folder path shown above."))
|
Chris@230
|
262 #endif
|
Chris@230
|
263 );
|
Chris@230
|
264 } else {
|
Chris@230
|
265 m_noModificationsLabel->setText
|
Chris@230
|
266 (tr("<qt>You have no uncommitted changes.</qt>"));
|
Chris@100
|
267 }
|
Chris@100
|
268 }
|
Chris@100
|
269
|
Chris@319
|
270
|
Chris@326
|
271 void FileStatusWidget::menuActionActivated()
|
Chris@326
|
272 {
|
Chris@326
|
273 QAction *act = qobject_cast<QAction *>(sender());
|
Chris@326
|
274 if (!act) return;
|
Chris@326
|
275
|
Chris@326
|
276 FileStates::State state = (FileStates::State)
|
Chris@326
|
277 act->property("state").toUInt();
|
Chris@326
|
278 FileStates::Activity activity = (FileStates::Activity)
|
Chris@326
|
279 act->property("activity").toUInt();
|
Chris@319
|
280
|
Chris@326
|
281 DEBUG << "menuActionActivated: state = " << state << ", activity = "
|
Chris@326
|
282 << activity << endl;
|
Chris@319
|
283
|
Chris@326
|
284 if (!FileStates::supportsActivity(state, activity)) {
|
Chris@326
|
285 std::cerr << "WARNING: FileStatusWidget::menuActionActivated: "
|
Chris@326
|
286 << "Action state " << state << " does not support activity "
|
Chris@326
|
287 << activity << std::endl;
|
Chris@326
|
288 return;
|
Chris@326
|
289 }
|
Chris@326
|
290
|
Chris@326
|
291 QStringList files = getSelectedFilesInState(state);
|
Chris@326
|
292
|
Chris@326
|
293 switch (activity) {
|
Chris@326
|
294 case FileStates::Annotate: emit annotateFiles(files); break;
|
Chris@326
|
295 case FileStates::Diff: emit diffFiles(files); break;
|
Chris@326
|
296 case FileStates::Commit: emit commitFiles(files); break;
|
Chris@326
|
297 case FileStates::Revert: emit revertFiles(files); break;
|
Chris@361
|
298 case FileStates::Rename: emit renameFiles(files); break;
|
Chris@361
|
299 case FileStates::Copy: emit copyFiles(files); break;
|
Chris@326
|
300 case FileStates::Add: emit addFiles(files); break;
|
Chris@326
|
301 case FileStates::Remove: emit removeFiles(files); break;
|
Chris@326
|
302 case FileStates::RedoMerge: emit redoFileMerges(files); break;
|
Chris@326
|
303 case FileStates::MarkResolved: emit markFilesResolved(files); break;
|
Chris@326
|
304 case FileStates::Ignore: emit ignoreFiles(files); break;
|
Chris@326
|
305 case FileStates::UnIgnore: emit unIgnoreFiles(files); break;
|
sam@624
|
306 case FileStates::ShowIn: emit showIn(files); break;
|
Chris@326
|
307 }
|
Chris@326
|
308 }
|
Chris@319
|
309
|
Chris@331
|
310 void FileStatusWidget::itemDoubleClicked(QListWidgetItem *item)
|
Chris@331
|
311 {
|
Chris@331
|
312 QStringList files;
|
Chris@350
|
313 QString file = item->text();
|
Chris@350
|
314 files << file;
|
Chris@350
|
315
|
Chris@350
|
316 switch (m_fileStates.stateOf(file)) {
|
Chris@350
|
317
|
Chris@350
|
318 case FileStates::Modified:
|
Chris@350
|
319 case FileStates::InConflict:
|
Chris@350
|
320 emit diffFiles(files);
|
Chris@350
|
321 break;
|
Chris@350
|
322
|
Chris@350
|
323 case FileStates::Clean:
|
Chris@350
|
324 case FileStates::Missing:
|
Chris@350
|
325 emit annotateFiles(files);
|
Chris@350
|
326 break;
|
Chris@373
|
327
|
Chris@373
|
328 default:
|
Chris@373
|
329 break;
|
Chris@350
|
330 }
|
Chris@331
|
331 }
|
Chris@319
|
332
|
Chris@95
|
333 void FileStatusWidget::itemSelectionChanged()
|
Chris@95
|
334 {
|
Chris@135
|
335 DEBUG << "FileStatusWidget::itemSelectionChanged" << endl;
|
Chris@135
|
336
|
Chris@135
|
337 QListWidget *list = qobject_cast<QListWidget *>(sender());
|
Chris@135
|
338
|
Chris@135
|
339 if (list) {
|
Chris@135
|
340 foreach (QListWidget *w, m_stateListMap) {
|
Chris@135
|
341 if (w != list) {
|
Chris@135
|
342 w->blockSignals(true);
|
Chris@135
|
343 w->clearSelection();
|
Chris@135
|
344 w->blockSignals(false);
|
Chris@135
|
345 }
|
Chris@135
|
346 }
|
Chris@135
|
347 }
|
Chris@135
|
348
|
Chris@95
|
349 m_selectedFiles.clear();
|
Chris@95
|
350
|
Chris@95
|
351 foreach (QListWidget *w, m_stateListMap) {
|
Chris@95
|
352 QList<QListWidgetItem *> sel = w->selectedItems();
|
Chris@95
|
353 foreach (QListWidgetItem *i, sel) {
|
Chris@95
|
354 m_selectedFiles.push_back(i->text());
|
Chris@95
|
355 DEBUG << "file " << i->text() << " is selected" << endl;
|
Chris@95
|
356 }
|
Chris@95
|
357 }
|
Chris@95
|
358
|
Chris@95
|
359 emit selectionChanged();
|
Chris@95
|
360 }
|
Chris@95
|
361
|
Chris@94
|
362 void FileStatusWidget::clearSelections()
|
Chris@94
|
363 {
|
Chris@95
|
364 m_selectedFiles.clear();
|
Chris@94
|
365 foreach (QListWidget *w, m_stateListMap) {
|
Chris@94
|
366 w->clearSelection();
|
Chris@94
|
367 }
|
Chris@94
|
368 }
|
Chris@94
|
369
|
Chris@95
|
370 bool FileStatusWidget::haveChangesToCommit() const
|
Chris@95
|
371 {
|
Chris@326
|
372 return !getAllCommittableFiles().empty();
|
Chris@95
|
373 }
|
Chris@95
|
374
|
Chris@95
|
375 bool FileStatusWidget::haveSelection() const
|
Chris@95
|
376 {
|
Chris@95
|
377 return !m_selectedFiles.empty();
|
Chris@95
|
378 }
|
Chris@95
|
379
|
Chris@326
|
380 QStringList FileStatusWidget::getSelectedFilesInState(FileStates::State s) const
|
Chris@95
|
381 {
|
Chris@95
|
382 QStringList files;
|
Chris@95
|
383 foreach (QString f, m_selectedFiles) {
|
Chris@326
|
384 if (m_fileStates.stateOf(f) == s) files.push_back(f);
|
Chris@95
|
385 }
|
Chris@95
|
386 return files;
|
Chris@326
|
387 }
|
Chris@326
|
388
|
Chris@326
|
389 QStringList FileStatusWidget::getSelectedFilesSupportingActivity(FileStates::Activity a) const
|
Chris@326
|
390 {
|
Chris@326
|
391 QStringList files;
|
Chris@326
|
392 foreach (QString f, m_selectedFiles) {
|
Chris@326
|
393 if (m_fileStates.supportsActivity(f, a)) files.push_back(f);
|
Chris@326
|
394 }
|
Chris@326
|
395 return files;
|
Chris@326
|
396 }
|
Chris@95
|
397
|
Chris@103
|
398 QStringList FileStatusWidget::getAllCommittableFiles() const
|
Chris@103
|
399 {
|
Chris@326
|
400 return m_fileStates.filesSupportingActivity(FileStates::Commit);
|
Chris@109
|
401 }
|
Chris@109
|
402
|
Chris@109
|
403 QStringList FileStatusWidget::getAllRevertableFiles() const
|
Chris@109
|
404 {
|
Chris@326
|
405 return m_fileStates.filesSupportingActivity(FileStates::Revert);
|
Chris@163
|
406 }
|
Chris@163
|
407
|
Chris@163
|
408 QStringList FileStatusWidget::getAllUnresolvedFiles() const
|
Chris@163
|
409 {
|
Chris@326
|
410 return m_fileStates.filesInState(FileStates::InConflict);
|
Chris@109
|
411 }
|
Chris@109
|
412
|
Chris@95
|
413 QStringList FileStatusWidget::getSelectedAddableFiles() const
|
Chris@95
|
414 {
|
Chris@326
|
415 return getSelectedFilesSupportingActivity(FileStates::Add);
|
Chris@103
|
416 }
|
Chris@103
|
417
|
Chris@95
|
418 QStringList FileStatusWidget::getSelectedRemovableFiles() const
|
Chris@95
|
419 {
|
Chris@326
|
420 return getSelectedFilesSupportingActivity(FileStates::Remove);
|
Chris@103
|
421 }
|
Chris@103
|
422
|
Chris@283
|
423 QString
|
Chris@283
|
424 FileStatusWidget::localPath() const
|
Chris@283
|
425 {
|
Chris@287
|
426 return m_localPath;
|
Chris@283
|
427 }
|
Chris@283
|
428
|
Chris@88
|
429 void
|
Chris@88
|
430 FileStatusWidget::setLocalPath(QString p)
|
Chris@88
|
431 {
|
Chris@287
|
432 m_localPath = p;
|
Chris@93
|
433 delete m_dateReference;
|
Chris@93
|
434 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
|
Chris@93
|
435 if (!m_dateReference->exists() ||
|
Chris@93
|
436 !m_dateReference->isFile() ||
|
Chris@93
|
437 !m_dateReference->isReadable()) {
|
Chris@93
|
438 DEBUG << "FileStatusWidget::setLocalPath: date reference file "
|
Chris@93
|
439 << m_dateReference->absoluteFilePath()
|
Chris@93
|
440 << " does not exist, is not a file, or cannot be read"
|
Chris@93
|
441 << endl;
|
Chris@93
|
442 delete m_dateReference;
|
Chris@93
|
443 m_dateReference = 0;
|
Chris@340
|
444 m_showAllFiles->setEnabled(false);
|
Chris@340
|
445 } else {
|
Chris@340
|
446 m_showAllFiles->setEnabled(true);
|
Chris@93
|
447 }
|
Chris@283
|
448 }
|
Chris@283
|
449
|
Chris@88
|
450 void
|
Chris@92
|
451 FileStatusWidget::setFileStates(FileStates p)
|
Chris@88
|
452 {
|
Chris@92
|
453 m_fileStates = p;
|
Chris@88
|
454 updateWidgets();
|
Chris@88
|
455 }
|
Chris@88
|
456
|
Chris@88
|
457 void
|
Chris@555
|
458 FileStatusWidget::setSearchText(QString text)
|
Chris@555
|
459 {
|
Chris@555
|
460 if (m_searchText == text) return;
|
Chris@555
|
461 m_searchText = text;
|
Chris@555
|
462 updateWidgets();
|
Chris@555
|
463 }
|
Chris@555
|
464
|
Chris@555
|
465 void
|
Chris@608
|
466 FileStatusWidget::clearWidgets()
|
Chris@608
|
467 {
|
Chris@608
|
468 foreach (FileStates::State s, m_stateListMap.keys()) {
|
Chris@608
|
469 QListWidget *w = m_stateListMap[s];
|
Chris@608
|
470 w->clear();
|
Chris@608
|
471 w->parentWidget()->hide();
|
Chris@608
|
472 }
|
Chris@608
|
473 }
|
Chris@608
|
474
|
Chris@608
|
475 void
|
Chris@88
|
476 FileStatusWidget::updateWidgets()
|
Chris@88
|
477 {
|
Chris@95
|
478 QDateTime lastInteractionTime;
|
Chris@95
|
479 if (m_dateReference) {
|
Chris@95
|
480 lastInteractionTime = m_dateReference->lastModified();
|
Chris@95
|
481 DEBUG << "reference time: " << lastInteractionTime << endl;
|
Chris@95
|
482 }
|
Chris@95
|
483
|
Chris@95
|
484 QSet<QString> selectedFiles;
|
Chris@95
|
485 foreach (QString f, m_selectedFiles) selectedFiles.insert(f);
|
Chris@95
|
486
|
Chris@230
|
487 int visibleCount = 0;
|
Chris@555
|
488 bool finding = (m_searchText != "");
|
Chris@115
|
489
|
Chris@94
|
490 foreach (FileStates::State s, m_stateListMap.keys()) {
|
Chris@95
|
491
|
Chris@94
|
492 QListWidget *w = m_stateListMap[s];
|
Chris@94
|
493 w->clear();
|
Chris@542
|
494
|
Chris@542
|
495 if (!shouldShow(s)) {
|
Chris@542
|
496 w->parentWidget()->hide();
|
Chris@542
|
497 continue;
|
Chris@542
|
498 }
|
Chris@542
|
499
|
Chris@324
|
500 QStringList files = m_fileStates.filesInState(s);
|
Chris@557
|
501 bool foundSomething = false;
|
Chris@93
|
502
|
Chris@95
|
503 QStringList highPriority, lowPriority;
|
Chris@95
|
504
|
Chris@95
|
505 foreach (QString file, files) {
|
Chris@95
|
506
|
Chris@555
|
507 if (finding) {
|
Chris@555
|
508 if (file.contains(m_searchText, Qt::CaseInsensitive)) {
|
Chris@555
|
509 highPriority.push_back(file);
|
Chris@557
|
510 foundSomething = true;
|
Chris@555
|
511 }
|
Chris@555
|
512 continue;
|
Chris@557
|
513 } else {
|
Chris@557
|
514 foundSomething = true;
|
Chris@555
|
515 }
|
Chris@555
|
516
|
Chris@95
|
517 bool highlighted = false;
|
Chris@95
|
518
|
Chris@95
|
519 if (s == FileStates::Unknown) {
|
Chris@95
|
520 // We want to highlight untracked files that have appeared
|
Chris@95
|
521 // since the last interaction with the repo
|
Chris@287
|
522 QString fn(m_localPath + "/" + file);
|
Chris@95
|
523 DEBUG << "comparing with " << fn << endl;
|
Chris@95
|
524 QFileInfo fi(fn);
|
Chris@100
|
525 if (fi.exists() && fi.created() > lastInteractionTime) {
|
Chris@95
|
526 DEBUG << "file " << fn << " is newer (" << fi.lastModified()
|
Chris@95
|
527 << ") than reference" << endl;
|
Chris@95
|
528 highlighted = true;
|
Chris@95
|
529 }
|
Chris@95
|
530 }
|
Chris@95
|
531
|
Chris@95
|
532 if (highlighted) {
|
Chris@95
|
533 highPriority.push_back(file);
|
Chris@95
|
534 } else {
|
Chris@95
|
535 lowPriority.push_back(file);
|
Chris@93
|
536 }
|
Chris@93
|
537 }
|
Chris@95
|
538
|
Chris@95
|
539 foreach (QString file, highPriority) {
|
Chris@95
|
540 QListWidgetItem *item = new QListWidgetItem(file);
|
Chris@95
|
541 w->addItem(item);
|
Chris@555
|
542 if (finding) {
|
Chris@555
|
543 item->setForeground(QColor("#008400"));
|
Chris@555
|
544 } else {
|
Chris@555
|
545 item->setForeground(QColor("#d40000"));
|
Chris@555
|
546 }
|
Chris@95
|
547 item->setSelected(selectedFiles.contains(file));
|
Chris@95
|
548 }
|
Chris@95
|
549
|
Chris@95
|
550 foreach (QString file, lowPriority) {
|
Chris@95
|
551 QListWidgetItem *item = new QListWidgetItem(file);
|
Chris@95
|
552 w->addItem(item);
|
Chris@95
|
553 item->setSelected(selectedFiles.contains(file));
|
Chris@95
|
554 }
|
Chris@95
|
555
|
Chris@592
|
556 setLabelFor(w, s, !finding && !highPriority.empty());
|
Chris@100
|
557
|
Chris@557
|
558 if (!foundSomething) {
|
Chris@115
|
559 w->parentWidget()->hide();
|
Chris@115
|
560 } else {
|
Chris@115
|
561 w->parentWidget()->show();
|
Chris@230
|
562 ++visibleCount;
|
Chris@115
|
563 }
|
Chris@93
|
564 }
|
Chris@115
|
565
|
Chris@230
|
566 m_noModificationsLabel->setVisible(visibleCount == 0);
|
Chris@230
|
567
|
Chris@230
|
568 if (visibleCount > 3) {
|
Chris@230
|
569 layoutBoxesGridly(visibleCount);
|
Chris@230
|
570 } else {
|
Chris@230
|
571 layoutBoxesLinearly();
|
Chris@230
|
572 }
|
Chris@115
|
573
|
Chris@230
|
574 setNoModificationsLabelText();
|
Chris@230
|
575 }
|
Chris@230
|
576
|
Chris@230
|
577 void FileStatusWidget::layoutBoxesGridly(int visibleCount)
|
Chris@230
|
578 {
|
Chris@230
|
579 if (m_gridlyLayout && m_lastGridlyCount == visibleCount) return;
|
Chris@230
|
580
|
Chris@230
|
581 delete m_boxesParent->layout();
|
Chris@230
|
582
|
Chris@230
|
583 QGridLayout *layout = new QGridLayout;
|
Chris@230
|
584 layout->setMargin(0);
|
Chris@230
|
585 m_boxesParent->setLayout(layout);
|
Chris@230
|
586
|
Chris@230
|
587 int row = 0;
|
Chris@230
|
588 int col = 0;
|
Chris@230
|
589
|
Chris@230
|
590 DEBUG << "FileStatusWidget::layoutBoxesGridly: visibleCount = "
|
Chris@230
|
591 << visibleCount << endl;
|
Chris@230
|
592
|
Chris@230
|
593 for (int i = 0; i < m_boxes.size(); ++i) {
|
Chris@230
|
594
|
Chris@230
|
595 if (!m_boxes[i]->isVisible()) continue;
|
Chris@230
|
596
|
Chris@230
|
597 if (col == 0 && row >= (visibleCount+1)/2) {
|
Chris@230
|
598 layout->addItem(new QSpacerItem(10, 5), 0, 1);
|
Chris@230
|
599 col = 2;
|
Chris@230
|
600 row = 0;
|
Chris@230
|
601 }
|
Chris@230
|
602
|
Chris@230
|
603 layout->addWidget(m_boxes[i], row, col);
|
Chris@230
|
604
|
Chris@230
|
605 ++row;
|
Chris@230
|
606 }
|
Chris@230
|
607
|
Chris@230
|
608 m_gridlyLayout = true;
|
Chris@230
|
609 m_lastGridlyCount = visibleCount;
|
Chris@230
|
610 }
|
Chris@230
|
611
|
Chris@230
|
612 void FileStatusWidget::layoutBoxesLinearly()
|
Chris@230
|
613 {
|
Chris@230
|
614 if (!m_gridlyLayout) return;
|
Chris@230
|
615
|
Chris@230
|
616 delete m_boxesParent->layout();
|
Chris@230
|
617
|
Chris@230
|
618 QGridLayout *layout = new QGridLayout;
|
Chris@230
|
619 layout->setMargin(0);
|
Chris@230
|
620 m_boxesParent->setLayout(layout);
|
Chris@230
|
621
|
Chris@230
|
622 for (int i = 0; i < m_boxes.size(); ++i) {
|
Chris@230
|
623 layout->addWidget(m_boxes[i], i, 0);
|
Chris@230
|
624 }
|
Chris@230
|
625
|
Chris@230
|
626 m_gridlyLayout = false;
|
Chris@88
|
627 }
|
Chris@88
|
628
|
Chris@100
|
629 void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight)
|
Chris@100
|
630 {
|
Chris@100
|
631 QString text = labelFor(s, addHighlight);
|
Chris@100
|
632 QWidget *p = w->parentWidget();
|
Chris@100
|
633 QList<QLabel *> ql = p->findChildren<QLabel *>();
|
Chris@100
|
634 if (!ql.empty()) ql[0]->setText(text);
|
Chris@100
|
635 }
|
Chris@115
|
636
|