annotate src/filestatuswidget.cpp @ 624:38c84c66ad7a

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