annotate src/filestatuswidget.cpp @ 629:080258d897db

* Added shortcut for commit
author Sam Izzo <sam@humbug.net>
date Sun, 26 Aug 2012 02:45:04 +1000
parents d39d236a0ce8
children bddd0924109f
rev   line source
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@624 159 }
Chris@326 160 connect(act, SIGNAL(triggered()), this, SLOT(menuActionActivated()));
Chris@325 161 w->insertAction(0, act);
Chris@325 162 }
Chris@323 163 w->setContextMenuPolicy(Qt::ActionsContextMenu);
Chris@323 164
Chris@211 165 boxlayout->addItem(new QSpacerItem(2, 2), 3, 0);
Chris@211 166
Chris@230 167 boxesLayout->addWidget(box, ++boxRow, 0);
Chris@230 168 m_boxes.push_back(box);
Chris@89 169 box->hide();
Chris@89 170 }
Chris@89 171
Chris@230 172 m_gridlyLayout = false;
Chris@230 173
Chris@89 174 layout->setRowStretch(++row, 20);
Chris@186 175
Chris@211 176 layout->addItem(new QSpacerItem(8, 8), ++row, 0);
Chris@199 177
Chris@558 178 QWidget *opts = new QWidget;
Chris@558 179 QGridLayout *optLayout = new QGridLayout(opts);
Chris@558 180 optLayout->setMargin(0);
Chris@558 181 layout->addWidget(opts, ++row, 0);
Chris@558 182
Chris@558 183 m_findWidget = new FindWidget(this);
Chris@558 184 optLayout->addWidget(m_findWidget, 0, 0, Qt::AlignLeft);
Chris@558 185 connect(m_findWidget, SIGNAL(findTextChanged(QString)),
Chris@558 186 this, SLOT(setSearchText(QString)));
Chris@558 187
Chris@558 188 m_showAllFiles = new QCheckBox(tr("Show all file states"), this);
Chris@340 189 m_showAllFiles->setEnabled(false);
Chris@558 190 optLayout->addWidget(m_showAllFiles, 0, 1, Qt::AlignRight);
Chris@484 191
Chris@484 192 QSettings settings;
Chris@484 193 m_showAllFiles->setChecked(settings.value("showall", false).toBool());
Chris@484 194
Chris@199 195 connect(m_showAllFiles, SIGNAL(toggled(bool)),
Chris@484 196 this, SIGNAL(showAllChanged()));
Chris@88 197 }
Chris@88 198
Chris@93 199 FileStatusWidget::~FileStatusWidget()
Chris@93 200 {
Chris@484 201 QSettings settings;
Chris@484 202 settings.setValue("showall", m_showAllFiles->isChecked());
Chris@484 203
Chris@93 204 delete m_dateReference;
Chris@93 205 }
Chris@93 206
Chris@484 207 bool FileStatusWidget::shouldShowAll() const
Chris@484 208 {
Chris@484 209 return m_showAllFiles->isChecked();
Chris@484 210 }
Chris@484 211
Chris@542 212 bool FileStatusWidget::shouldShow(FileStates::State s) const
Chris@542 213 {
Chris@542 214 if (shouldShowAll()) return true;
Chris@542 215 else return (s != FileStates::Clean &&
Chris@542 216 s != FileStates::Ignored);
Chris@542 217 }
Chris@542 218
Chris@100 219 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation)
Chris@100 220 {
Chris@230 221 QSettings settings;
Chris@230 222 settings.beginGroup("Presentation");
Chris@230 223 if (settings.value("showhelpfultext", true).toBool()) {
Chris@230 224 if (addHighlightExplanation) {
Chris@230 225 return QString("<qt><b>%1</b><br>%2<br>%3</qt>")
Chris@230 226 .arg(m_simpleLabels[s])
Chris@230 227 .arg(m_descriptions[s])
Chris@230 228 .arg(m_highlightExplanation);
Chris@230 229 } else {
Chris@230 230 return QString("<qt><b>%1</b><br>%2</qt>")
Chris@230 231 .arg(m_simpleLabels[s])
Chris@230 232 .arg(m_descriptions[s]);
Chris@230 233 }
Chris@230 234 }
Chris@542 235 return QString("<qt><b>%1</b></qt>")
Chris@542 236 .arg(m_simpleLabels[s]);
Chris@230 237 }
Chris@230 238
Chris@230 239 void FileStatusWidget::setNoModificationsLabelText()
Chris@230 240 {
Chris@230 241 QSettings settings;
Chris@230 242 settings.beginGroup("Presentation");
Chris@558 243
Chris@558 244 if (m_searchText != "") {
Chris@558 245 if (!m_showAllFiles->isChecked()) {
Chris@558 246 m_noModificationsLabel->setText
Chris@558 247 (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 248 } else {
Chris@558 249 m_noModificationsLabel->setText
Chris@558 250 (tr("<qt><b>Nothing found</b><br>No files have matching filenames.</qt>"));
Chris@558 251 }
Chris@558 252 } else if (settings.value("showhelpfultext", true).toBool()) {
Chris@230 253 m_noModificationsLabel->setText
Chris@230 254 (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 255 #if defined Q_OS_MAC
Chris@230 256 .arg(tr("To open the working folder in Finder,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
Chris@230 257 #elif defined Q_OS_WIN32
Chris@230 258 .arg(tr("To open the working folder in Windows Explorer,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
Chris@230 259 #else
Chris@230 260 .arg(tr("To open the working folder in your system file manager,<br>click the &ldquo;Local&rdquo; folder path shown above."))
Chris@230 261 #endif
Chris@230 262 );
Chris@230 263 } else {
Chris@230 264 m_noModificationsLabel->setText
Chris@230 265 (tr("<qt>You have no uncommitted changes.</qt>"));
Chris@100 266 }
Chris@100 267 }
Chris@100 268
Chris@319 269
Chris@326 270 void FileStatusWidget::menuActionActivated()
Chris@326 271 {
Chris@326 272 QAction *act = qobject_cast<QAction *>(sender());
Chris@326 273 if (!act) return;
Chris@326 274
Chris@326 275 FileStates::State state = (FileStates::State)
Chris@326 276 act->property("state").toUInt();
Chris@326 277 FileStates::Activity activity = (FileStates::Activity)
Chris@326 278 act->property("activity").toUInt();
Chris@319 279
Chris@326 280 DEBUG << "menuActionActivated: state = " << state << ", activity = "
Chris@326 281 << activity << endl;
Chris@319 282
Chris@326 283 if (!FileStates::supportsActivity(state, activity)) {
Chris@326 284 std::cerr << "WARNING: FileStatusWidget::menuActionActivated: "
Chris@326 285 << "Action state " << state << " does not support activity "
Chris@326 286 << activity << std::endl;
Chris@326 287 return;
Chris@326 288 }
Chris@326 289
Chris@326 290 QStringList files = getSelectedFilesInState(state);
Chris@326 291
Chris@326 292 switch (activity) {
Chris@326 293 case FileStates::Annotate: emit annotateFiles(files); break;
Chris@326 294 case FileStates::Diff: emit diffFiles(files); break;
Chris@326 295 case FileStates::Commit: emit commitFiles(files); break;
Chris@326 296 case FileStates::Revert: emit revertFiles(files); break;
Chris@361 297 case FileStates::Rename: emit renameFiles(files); break;
Chris@361 298 case FileStates::Copy: emit copyFiles(files); break;
Chris@326 299 case FileStates::Add: emit addFiles(files); break;
Chris@326 300 case FileStates::Remove: emit removeFiles(files); break;
Chris@326 301 case FileStates::RedoMerge: emit redoFileMerges(files); break;
Chris@326 302 case FileStates::MarkResolved: emit markFilesResolved(files); break;
Chris@326 303 case FileStates::Ignore: emit ignoreFiles(files); break;
Chris@326 304 case FileStates::UnIgnore: emit unIgnoreFiles(files); break;
sam@624 305 case FileStates::ShowIn: emit showIn(files); break;
Chris@326 306 }
Chris@326 307 }
Chris@319 308
Chris@331 309 void FileStatusWidget::itemDoubleClicked(QListWidgetItem *item)
Chris@331 310 {
Chris@331 311 QStringList files;
Chris@350 312 QString file = item->text();
Chris@350 313 files << file;
Chris@350 314
Chris@350 315 switch (m_fileStates.stateOf(file)) {
Chris@350 316
Chris@350 317 case FileStates::Modified:
Chris@350 318 case FileStates::InConflict:
Chris@350 319 emit diffFiles(files);
Chris@350 320 break;
Chris@350 321
Chris@350 322 case FileStates::Clean:
Chris@350 323 case FileStates::Missing:
Chris@350 324 emit annotateFiles(files);
Chris@350 325 break;
Chris@373 326
Chris@373 327 default:
Chris@373 328 break;
Chris@350 329 }
Chris@331 330 }
Chris@319 331
Chris@95 332 void FileStatusWidget::itemSelectionChanged()
Chris@95 333 {
Chris@135 334 DEBUG << "FileStatusWidget::itemSelectionChanged" << endl;
Chris@135 335
Chris@135 336 QListWidget *list = qobject_cast<QListWidget *>(sender());
Chris@135 337
Chris@135 338 if (list) {
Chris@135 339 foreach (QListWidget *w, m_stateListMap) {
Chris@135 340 if (w != list) {
Chris@135 341 w->blockSignals(true);
Chris@135 342 w->clearSelection();
Chris@135 343 w->blockSignals(false);
Chris@135 344 }
Chris@135 345 }
Chris@135 346 }
Chris@135 347
Chris@95 348 m_selectedFiles.clear();
Chris@95 349
Chris@95 350 foreach (QListWidget *w, m_stateListMap) {
Chris@95 351 QList<QListWidgetItem *> sel = w->selectedItems();
Chris@95 352 foreach (QListWidgetItem *i, sel) {
Chris@95 353 m_selectedFiles.push_back(i->text());
Chris@95 354 DEBUG << "file " << i->text() << " is selected" << endl;
Chris@95 355 }
Chris@95 356 }
Chris@95 357
Chris@95 358 emit selectionChanged();
Chris@95 359 }
Chris@95 360
Chris@94 361 void FileStatusWidget::clearSelections()
Chris@94 362 {
Chris@95 363 m_selectedFiles.clear();
Chris@94 364 foreach (QListWidget *w, m_stateListMap) {
Chris@94 365 w->clearSelection();
Chris@94 366 }
Chris@94 367 }
Chris@94 368
Chris@95 369 bool FileStatusWidget::haveChangesToCommit() const
Chris@95 370 {
Chris@326 371 return !getAllCommittableFiles().empty();
Chris@95 372 }
Chris@95 373
Chris@95 374 bool FileStatusWidget::haveSelection() const
Chris@95 375 {
Chris@95 376 return !m_selectedFiles.empty();
Chris@95 377 }
Chris@95 378
Chris@326 379 QStringList FileStatusWidget::getSelectedFilesInState(FileStates::State s) const
Chris@95 380 {
Chris@95 381 QStringList files;
Chris@95 382 foreach (QString f, m_selectedFiles) {
Chris@326 383 if (m_fileStates.stateOf(f) == s) files.push_back(f);
Chris@95 384 }
Chris@95 385 return files;
Chris@326 386 }
Chris@326 387
Chris@326 388 QStringList FileStatusWidget::getSelectedFilesSupportingActivity(FileStates::Activity a) const
Chris@326 389 {
Chris@326 390 QStringList files;
Chris@326 391 foreach (QString f, m_selectedFiles) {
Chris@326 392 if (m_fileStates.supportsActivity(f, a)) files.push_back(f);
Chris@326 393 }
Chris@326 394 return files;
Chris@326 395 }
Chris@95 396
Chris@103 397 QStringList FileStatusWidget::getAllCommittableFiles() const
Chris@103 398 {
Chris@326 399 return m_fileStates.filesSupportingActivity(FileStates::Commit);
Chris@109 400 }
Chris@109 401
Chris@109 402 QStringList FileStatusWidget::getAllRevertableFiles() const
Chris@109 403 {
Chris@326 404 return m_fileStates.filesSupportingActivity(FileStates::Revert);
Chris@163 405 }
Chris@163 406
Chris@163 407 QStringList FileStatusWidget::getAllUnresolvedFiles() const
Chris@163 408 {
Chris@326 409 return m_fileStates.filesInState(FileStates::InConflict);
Chris@109 410 }
Chris@109 411
Chris@95 412 QStringList FileStatusWidget::getSelectedAddableFiles() const
Chris@95 413 {
Chris@326 414 return getSelectedFilesSupportingActivity(FileStates::Add);
Chris@103 415 }
Chris@103 416
Chris@95 417 QStringList FileStatusWidget::getSelectedRemovableFiles() const
Chris@95 418 {
Chris@326 419 return getSelectedFilesSupportingActivity(FileStates::Remove);
Chris@103 420 }
Chris@103 421
Chris@283 422 QString
Chris@283 423 FileStatusWidget::localPath() const
Chris@283 424 {
Chris@287 425 return m_localPath;
Chris@283 426 }
Chris@283 427
Chris@88 428 void
Chris@88 429 FileStatusWidget::setLocalPath(QString p)
Chris@88 430 {
Chris@287 431 m_localPath = p;
Chris@93 432 delete m_dateReference;
Chris@93 433 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
Chris@93 434 if (!m_dateReference->exists() ||
Chris@93 435 !m_dateReference->isFile() ||
Chris@93 436 !m_dateReference->isReadable()) {
Chris@93 437 DEBUG << "FileStatusWidget::setLocalPath: date reference file "
Chris@93 438 << m_dateReference->absoluteFilePath()
Chris@93 439 << " does not exist, is not a file, or cannot be read"
Chris@93 440 << endl;
Chris@93 441 delete m_dateReference;
Chris@93 442 m_dateReference = 0;
Chris@340 443 m_showAllFiles->setEnabled(false);
Chris@340 444 } else {
Chris@340 445 m_showAllFiles->setEnabled(true);
Chris@93 446 }
Chris@283 447 }
Chris@283 448
Chris@88 449 void
Chris@92 450 FileStatusWidget::setFileStates(FileStates p)
Chris@88 451 {
Chris@92 452 m_fileStates = p;
Chris@88 453 updateWidgets();
Chris@88 454 }
Chris@88 455
Chris@88 456 void
Chris@555 457 FileStatusWidget::setSearchText(QString text)
Chris@555 458 {
Chris@555 459 if (m_searchText == text) return;
Chris@555 460 m_searchText = text;
Chris@555 461 updateWidgets();
Chris@555 462 }
Chris@555 463
Chris@555 464 void
Chris@608 465 FileStatusWidget::clearWidgets()
Chris@608 466 {
Chris@608 467 foreach (FileStates::State s, m_stateListMap.keys()) {
Chris@608 468 QListWidget *w = m_stateListMap[s];
Chris@608 469 w->clear();
Chris@608 470 w->parentWidget()->hide();
Chris@608 471 }
Chris@608 472 }
Chris@608 473
Chris@608 474 void
Chris@88 475 FileStatusWidget::updateWidgets()
Chris@88 476 {
Chris@95 477 QDateTime lastInteractionTime;
Chris@95 478 if (m_dateReference) {
Chris@95 479 lastInteractionTime = m_dateReference->lastModified();
Chris@95 480 DEBUG << "reference time: " << lastInteractionTime << endl;
Chris@95 481 }
Chris@95 482
Chris@95 483 QSet<QString> selectedFiles;
Chris@95 484 foreach (QString f, m_selectedFiles) selectedFiles.insert(f);
Chris@95 485
Chris@230 486 int visibleCount = 0;
Chris@555 487 bool finding = (m_searchText != "");
Chris@115 488
Chris@94 489 foreach (FileStates::State s, m_stateListMap.keys()) {
Chris@95 490
Chris@94 491 QListWidget *w = m_stateListMap[s];
Chris@94 492 w->clear();
Chris@542 493
Chris@542 494 if (!shouldShow(s)) {
Chris@542 495 w->parentWidget()->hide();
Chris@542 496 continue;
Chris@542 497 }
Chris@542 498
Chris@324 499 QStringList files = m_fileStates.filesInState(s);
Chris@557 500 bool foundSomething = false;
Chris@93 501
Chris@95 502 QStringList highPriority, lowPriority;
Chris@95 503
Chris@95 504 foreach (QString file, files) {
Chris@95 505
Chris@555 506 if (finding) {
Chris@555 507 if (file.contains(m_searchText, Qt::CaseInsensitive)) {
Chris@555 508 highPriority.push_back(file);
Chris@557 509 foundSomething = true;
Chris@555 510 }
Chris@555 511 continue;
Chris@557 512 } else {
Chris@557 513 foundSomething = true;
Chris@555 514 }
Chris@555 515
Chris@95 516 bool highlighted = false;
Chris@95 517
Chris@95 518 if (s == FileStates::Unknown) {
Chris@95 519 // We want to highlight untracked files that have appeared
Chris@95 520 // since the last interaction with the repo
Chris@287 521 QString fn(m_localPath + "/" + file);
Chris@95 522 DEBUG << "comparing with " << fn << endl;
Chris@95 523 QFileInfo fi(fn);
Chris@100 524 if (fi.exists() && fi.created() > lastInteractionTime) {
Chris@95 525 DEBUG << "file " << fn << " is newer (" << fi.lastModified()
Chris@95 526 << ") than reference" << endl;
Chris@95 527 highlighted = true;
Chris@95 528 }
Chris@95 529 }
Chris@95 530
Chris@95 531 if (highlighted) {
Chris@95 532 highPriority.push_back(file);
Chris@95 533 } else {
Chris@95 534 lowPriority.push_back(file);
Chris@93 535 }
Chris@93 536 }
Chris@95 537
Chris@95 538 foreach (QString file, highPriority) {
Chris@95 539 QListWidgetItem *item = new QListWidgetItem(file);
Chris@95 540 w->addItem(item);
Chris@555 541 if (finding) {
Chris@555 542 item->setForeground(QColor("#008400"));
Chris@555 543 } else {
Chris@555 544 item->setForeground(QColor("#d40000"));
Chris@555 545 }
Chris@95 546 item->setSelected(selectedFiles.contains(file));
Chris@95 547 }
Chris@95 548
Chris@95 549 foreach (QString file, lowPriority) {
Chris@95 550 QListWidgetItem *item = new QListWidgetItem(file);
Chris@95 551 w->addItem(item);
Chris@95 552 item->setSelected(selectedFiles.contains(file));
Chris@95 553 }
Chris@95 554
Chris@592 555 setLabelFor(w, s, !finding && !highPriority.empty());
Chris@100 556
Chris@557 557 if (!foundSomething) {
Chris@115 558 w->parentWidget()->hide();
Chris@115 559 } else {
Chris@115 560 w->parentWidget()->show();
Chris@230 561 ++visibleCount;
Chris@115 562 }
Chris@93 563 }
Chris@115 564
Chris@230 565 m_noModificationsLabel->setVisible(visibleCount == 0);
Chris@230 566
Chris@230 567 if (visibleCount > 3) {
Chris@230 568 layoutBoxesGridly(visibleCount);
Chris@230 569 } else {
Chris@230 570 layoutBoxesLinearly();
Chris@230 571 }
Chris@115 572
Chris@230 573 setNoModificationsLabelText();
Chris@230 574 }
Chris@230 575
Chris@230 576 void FileStatusWidget::layoutBoxesGridly(int visibleCount)
Chris@230 577 {
Chris@230 578 if (m_gridlyLayout && m_lastGridlyCount == visibleCount) return;
Chris@230 579
Chris@230 580 delete m_boxesParent->layout();
Chris@230 581
Chris@230 582 QGridLayout *layout = new QGridLayout;
Chris@230 583 layout->setMargin(0);
Chris@230 584 m_boxesParent->setLayout(layout);
Chris@230 585
Chris@230 586 int row = 0;
Chris@230 587 int col = 0;
Chris@230 588
Chris@230 589 DEBUG << "FileStatusWidget::layoutBoxesGridly: visibleCount = "
Chris@230 590 << visibleCount << endl;
Chris@230 591
Chris@230 592 for (int i = 0; i < m_boxes.size(); ++i) {
Chris@230 593
Chris@230 594 if (!m_boxes[i]->isVisible()) continue;
Chris@230 595
Chris@230 596 if (col == 0 && row >= (visibleCount+1)/2) {
Chris@230 597 layout->addItem(new QSpacerItem(10, 5), 0, 1);
Chris@230 598 col = 2;
Chris@230 599 row = 0;
Chris@230 600 }
Chris@230 601
Chris@230 602 layout->addWidget(m_boxes[i], row, col);
Chris@230 603
Chris@230 604 ++row;
Chris@230 605 }
Chris@230 606
Chris@230 607 m_gridlyLayout = true;
Chris@230 608 m_lastGridlyCount = visibleCount;
Chris@230 609 }
Chris@230 610
Chris@230 611 void FileStatusWidget::layoutBoxesLinearly()
Chris@230 612 {
Chris@230 613 if (!m_gridlyLayout) return;
Chris@230 614
Chris@230 615 delete m_boxesParent->layout();
Chris@230 616
Chris@230 617 QGridLayout *layout = new QGridLayout;
Chris@230 618 layout->setMargin(0);
Chris@230 619 m_boxesParent->setLayout(layout);
Chris@230 620
Chris@230 621 for (int i = 0; i < m_boxes.size(); ++i) {
Chris@230 622 layout->addWidget(m_boxes[i], i, 0);
Chris@230 623 }
Chris@230 624
Chris@230 625 m_gridlyLayout = false;
Chris@88 626 }
Chris@88 627
Chris@100 628 void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight)
Chris@100 629 {
Chris@100 630 QString text = labelFor(s, addHighlight);
Chris@100 631 QWidget *p = w->parentWidget();
Chris@100 632 QList<QLabel *> ql = p->findChildren<QLabel *>();
Chris@100 633 if (!ql.empty()) ql[0]->setText(text);
Chris@100 634 }
Chris@115 635