# HG changeset patch # User Chris Cannam # Date 1330362527 0 # Node ID 95877ad67d3e48a2d38f4287d4e1802ee9d00a23 # Parent 9c8147c9f245e74569efa8c77984e76f88f2ac0e# Parent d932ce55c364b49393997bda1ffd1df7ad7518da Merge from branch "find" diff -r 9c8147c9f245 -r 95877ad67d3e easyhg.pro --- a/easyhg.pro Fri Feb 17 10:58:41 2012 +0000 +++ b/easyhg.pro Mon Feb 27 17:08:47 2012 +0000 @@ -65,7 +65,8 @@ src/hgignoredialog.h \ src/versiontester.h \ src/squeezedlabel.h \ - src/fswatcher.h + src/fswatcher.h \ + src/findwidget.h SOURCES = \ src/main.cpp \ src/mainwindow.cpp \ @@ -103,7 +104,8 @@ src/hgignoredialog.cpp \ src/versiontester.cpp \ src/squeezedlabel.cpp \ - src/fswatcher.cpp + src/fswatcher.cpp \ + src/findwidget.cpp macx-* { SOURCES += src/common_osx.mm diff -r 9c8147c9f245 -r 95877ad67d3e src/changesetitem.cpp --- a/src/changesetitem.cpp Fri Feb 17 10:58:41 2012 +0000 +++ b/src/changesetitem.cpp Mon Feb 27 17:08:47 2012 +0000 @@ -38,7 +38,7 @@ ChangesetItem::ChangesetItem(Changeset *cs) : m_changeset(cs), m_detail(0), m_showBranch(false), m_column(0), m_row(0), m_wide(false), - m_current(false), m_closing(false), m_new(false) + m_current(false), m_closing(false), m_new(false), m_searchMatches(false) { m_font = QFont(); m_font.setPixelSize(11); @@ -91,6 +91,15 @@ emit detailHidden(); } +bool +ChangesetItem::setSearchText(QString text) +{ + m_searchText = text; + m_searchMatches = (m_changeset->comment().contains + (text, Qt::CaseInsensitive)); + return m_searchMatches; +} + void ChangesetItem::mousePressEvent(QGraphicsSceneMouseEvent *e) { @@ -296,6 +305,17 @@ bool showText = (scale >= 0.2); bool showProperLines = (scale >= 0.1); + if (m_searchText != "") { + if (m_searchMatches) { + userColour = QColor("#008400"); + showProperLines = true; + showText = true; + } else { + branchColour = Qt::gray; + userColour = Qt::gray; + } + } + if (!showProperLines) { paint->setPen(QPen(branchColour, 0)); } else { @@ -452,6 +472,8 @@ paint->setFont(f); + if (m_searchMatches) paint->setPen(userColour); + for (int i = 0; i < lines.size(); ++i) { paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed()); } diff -r 9c8147c9f245 -r 95877ad67d3e src/changesetitem.h --- a/src/changesetitem.h Fri Feb 17 10:58:41 2012 +0000 +++ b/src/changesetitem.h Mon Feb 27 17:08:47 2012 +0000 @@ -65,6 +65,8 @@ bool showBranch() const { return m_showBranch; } void setShowBranch(bool s) { m_showBranch = s; } + bool setSearchText(QString text); // return true if it matches + signals: void detailShown(); void detailHidden(); @@ -110,6 +112,8 @@ bool m_current; bool m_closing; bool m_new; + QString m_searchText; + bool m_searchMatches; QMap m_parentDiffActions; QMap m_summaryActions; diff -r 9c8147c9f245 -r 95877ad67d3e src/filestatuswidget.cpp --- a/src/filestatuswidget.cpp Fri Feb 17 10:58:41 2012 +0000 +++ b/src/filestatuswidget.cpp Mon Feb 27 17:08:47 2012 +0000 @@ -18,6 +18,7 @@ #include "filestatuswidget.h" #include "debug.h" #include "multichoicedialog.h" +#include "findwidget.h" #include #include @@ -154,9 +155,19 @@ layout->addItem(new QSpacerItem(8, 8), ++row, 0); - m_showAllFiles = new QCheckBox(tr("Show all files"), this); + QWidget *opts = new QWidget; + QGridLayout *optLayout = new QGridLayout(opts); + optLayout->setMargin(0); + layout->addWidget(opts, ++row, 0); + + m_findWidget = new FindWidget(this); + optLayout->addWidget(m_findWidget, 0, 0, Qt::AlignLeft); + connect(m_findWidget, SIGNAL(findTextChanged(QString)), + this, SLOT(setSearchText(QString))); + + m_showAllFiles = new QCheckBox(tr("Show all file states"), this); m_showAllFiles->setEnabled(false); - layout->addWidget(m_showAllFiles, ++row, 0, Qt::AlignLeft); + optLayout->addWidget(m_showAllFiles, 0, 1, Qt::AlignRight); QSettings settings; m_showAllFiles->setChecked(settings.value("showall", false).toBool()); @@ -209,7 +220,16 @@ { QSettings settings; settings.beginGroup("Presentation"); - if (settings.value("showhelpfultext", true).toBool()) { + + if (m_searchText != "") { + if (!m_showAllFiles->isChecked()) { + m_noModificationsLabel->setText + (tr("Nothing found
None of the modified files have matching filenames.
Select Show all file states to find matches among unmodified and untracked files as well.
")); + } else { + m_noModificationsLabel->setText + (tr("Nothing found
No files have matching filenames.
")); + } + } else if (settings.value("showhelpfultext", true).toBool()) { m_noModificationsLabel->setText (tr("This area will list files in your working folder that you have changed.

At the moment you have no uncommitted changes.

To see changes previously made to the repository,
switch to the History tab.

%1
") #if defined Q_OS_MAC @@ -413,6 +433,14 @@ } void +FileStatusWidget::setSearchText(QString text) +{ + if (m_searchText == text) return; + m_searchText = text; + updateWidgets(); +} + +void FileStatusWidget::updateWidgets() { QDateTime lastInteractionTime; @@ -425,6 +453,7 @@ foreach (QString f, m_selectedFiles) selectedFiles.insert(f); int visibleCount = 0; + bool finding = (m_searchText != ""); foreach (FileStates::State s, m_stateListMap.keys()) { @@ -437,11 +466,22 @@ } QStringList files = m_fileStates.filesInState(s); + bool foundSomething = false; QStringList highPriority, lowPriority; foreach (QString file, files) { + if (finding) { + if (file.contains(m_searchText, Qt::CaseInsensitive)) { + highPriority.push_back(file); + foundSomething = true; + } + continue; + } else { + foundSomething = true; + } + bool highlighted = false; if (s == FileStates::Unknown) { @@ -467,7 +507,11 @@ foreach (QString file, highPriority) { QListWidgetItem *item = new QListWidgetItem(file); w->addItem(item); - item->setForeground(QColor("#d40000")); + if (finding) { + item->setForeground(QColor("#008400")); + } else { + item->setForeground(QColor("#d40000")); + } item->setSelected(selectedFiles.contains(file)); } @@ -479,7 +523,7 @@ setLabelFor(w, s, !highPriority.empty()); - if (files.empty()) { + if (!foundSomething) { w->parentWidget()->hide(); } else { w->parentWidget()->show(); diff -r 9c8147c9f245 -r 95877ad67d3e src/filestatuswidget.h --- a/src/filestatuswidget.h Fri Feb 17 10:58:41 2012 +0000 +++ b/src/filestatuswidget.h Mon Feb 27 17:08:47 2012 +0000 @@ -29,6 +29,7 @@ class QPushButton; class QFileInfo; class QCheckBox; +class FindWidget; class FileStatusWidget : public QWidget { @@ -78,6 +79,8 @@ void clearSelections(); void updateWidgets(); + void setSearchText(QString text); + private slots: void menuActionActivated(); void itemSelectionChanged(); @@ -87,6 +90,7 @@ QString m_localPath; QLabel *m_noModificationsLabel; + FindWidget *m_findWidget; QCheckBox *m_showAllFiles; FileStates m_fileStates; @@ -104,6 +108,8 @@ QList m_boxes; QWidget *m_boxesParent; + QString m_searchText; + void layoutBoxesGridly(int count); void layoutBoxesLinearly(); void setNoModificationsLabelText(); diff -r 9c8147c9f245 -r 95877ad67d3e src/findwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/findwidget.cpp Mon Feb 27 17:08:47 2012 +0000 @@ -0,0 +1,77 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + EasyMercurial + + Based on HgExplorer by Jari Korhonen + Copyright (c) 2010 Jari Korhonen + Copyright (c) 2011 Chris Cannam + Copyright (c) 2011 Queen Mary, University of London + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "findwidget.h" + +#include +#include +#include +#include + +FindWidget::FindWidget(QWidget *parent) : + QWidget(parent) +{ + QGridLayout *layout = new QGridLayout; + layout->setMargin(0); + setLayout(layout); + + QToolButton *button = new QToolButton(); + layout->addWidget(button, 0, 0); + button->setText(tr("Find...")); + button->setToolButtonStyle(Qt::ToolButtonTextOnly); +// button->setAutoRaise(true); + connect(button, SIGNAL(clicked()), this, SLOT(buttonPressed())); + + m_lineEdit = new QLineEdit(); + layout->addWidget(m_lineEdit, 0, 1); + + m_lineEdit->setFixedWidth(100); + m_lineEdit->hide(); + + int h = m_lineEdit->sizeHint().height(); + int h0 = button->sizeHint().height(); + if (h > h0) button->setFixedHeight(h); + + connect(m_lineEdit, SIGNAL(textChanged(const QString &)), + this, SIGNAL(findTextChanged(QString))); +} + +FindWidget::~FindWidget() +{ +} + +void +FindWidget::buttonPressed() +{ + QAbstractButton *button = qobject_cast(sender()); + if (!button) return; + if (m_lineEdit->isVisible()) { + m_lineEdit->hide(); + button->setText(tr("Find...")); + if (m_lineEdit->text() != "") { + emit findTextChanged(""); + } + } else { + m_lineEdit->show(); + m_lineEdit->setFocus(Qt::OtherFocusReason); + button->setText(tr("Find:")); + if (m_lineEdit->text() != "") { + emit findTextChanged(m_lineEdit->text()); + } + } +} + diff -r 9c8147c9f245 -r 95877ad67d3e src/findwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/findwidget.h Mon Feb 27 17:08:47 2012 +0000 @@ -0,0 +1,43 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + EasyMercurial + + Based on HgExplorer by Jari Korhonen + Copyright (c) 2010 Jari Korhonen + Copyright (c) 2011 Chris Cannam + Copyright (c) 2011 Queen Mary, University of London + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef FINDWIDGET_H +#define FINDWIDGET_H + +#include + +class QLineEdit; + +class FindWidget : public QWidget +{ + Q_OBJECT + +public: + FindWidget(QWidget *parent = 0); + ~FindWidget(); + +signals: + void findTextChanged(QString); + +private slots: + void buttonPressed(); + +private: + QLineEdit *m_lineEdit; +}; + +#endif diff -r 9c8147c9f245 -r 95877ad67d3e src/hgtabwidget.cpp --- a/src/hgtabwidget.cpp Fri Feb 17 10:58:41 2012 +0000 +++ b/src/hgtabwidget.cpp Mon Feb 27 17:08:47 2012 +0000 @@ -154,6 +154,12 @@ m_historyWidget->update(); } +void HgTabWidget::setSearchText(QString text) +{ + m_fileStatusWidget->setSearchText(text); + m_historyWidget->setSearchText(text); +} + bool HgTabWidget::canDiff() const { return canRevert(); diff -r 9c8147c9f245 -r 95877ad67d3e src/hgtabwidget.h --- a/src/hgtabwidget.h Fri Feb 17 10:58:41 2012 +0000 +++ b/src/hgtabwidget.h Mon Feb 27 17:08:47 2012 +0000 @@ -113,6 +113,8 @@ void showWorkTab(); void showHistoryTab(); + void setSearchText(QString text); + private: FileStatusWidget *m_fileStatusWidget; HistoryWidget *m_historyWidget; diff -r 9c8147c9f245 -r 95877ad67d3e src/historywidget.cpp --- a/src/historywidget.cpp Fri Feb 17 10:58:41 2012 +0000 +++ b/src/historywidget.cpp Mon Feb 27 17:08:47 2012 +0000 @@ -23,6 +23,7 @@ #include "grapher.h" #include "debug.h" #include "uncommitteditem.h" +#include "findwidget.h" #include @@ -55,11 +56,21 @@ settings.beginGroup("Presentation"); bool showClosed = (settings.value("showclosedbranches", false).toBool()); + QWidget *opts = new QWidget; + QGridLayout *optLayout = new QGridLayout(opts); + optLayout->setMargin(0); + layout->addWidget(opts, ++row, 0, 1, 2); + + m_findWidget = new FindWidget(this); + optLayout->addWidget(m_findWidget, 0, 0, Qt::AlignLeft); + connect(m_findWidget, SIGNAL(findTextChanged(QString)), + this, SLOT(setSearchText(QString))); + m_showClosedBranches = new QCheckBox(tr("Show closed branches"), this); m_showClosedBranches->setChecked(showClosed); connect(m_showClosedBranches, SIGNAL(toggled(bool)), this, SLOT(showClosedChanged(bool))); - layout->addWidget(m_showClosedBranches, ++row, 0, Qt::AlignLeft); + optLayout->addWidget(m_showClosedBranches, 0, 1, Qt::AlignRight); m_showClosedBranches->hide(); setLayout(layout); @@ -241,6 +252,7 @@ toFocus->ensureVisible(); } + updateSearchStatus(); connectSceneSignals(); } @@ -294,6 +306,38 @@ } } +void HistoryWidget::setSearchText(QString text) +{ + if (m_searchText == text) return; + m_searchText = text; + updateSearchStatus(); +} + +void HistoryWidget::updateSearchStatus() +{ + QGraphicsScene *scene = m_panned->scene(); + if (!scene) return; + + ChangesetItem *toFocus = 0; + + QList items = scene->items(); + foreach (QGraphicsItem *it, items) { + + ChangesetItem *csit = dynamic_cast(it); + if (!csit) continue; + + bool matched = csit->setSearchText(m_searchText); + if (matched && (!toFocus || csit->row() < toFocus->row())) { + toFocus = csit; + } + csit->update(); + } + + if (toFocus) { + toFocus->ensureVisible(); + } +} + void HistoryWidget::connectSceneSignals() { ChangesetScene *scene = qobject_cast(m_panned->scene()); diff -r 9c8147c9f245 -r 95877ad67d3e src/historywidget.h --- a/src/historywidget.h Fri Feb 17 10:58:41 2012 +0000 +++ b/src/historywidget.h Mon Feb 27 17:08:47 2012 +0000 @@ -28,6 +28,7 @@ class Panner; class UncommittedItem; class QGraphicsScene; +class FindWidget; class HistoryWidget : public QWidget { @@ -68,6 +69,9 @@ private slots: void showClosedChanged(bool); + +public slots: + void setSearchText(QString); private: Changesets m_changesets; @@ -78,10 +82,13 @@ bool m_showUncommitted; bool m_refreshNeeded; + FindWidget *m_findWidget; Panned *m_panned; Panner *m_panner; QCheckBox *m_showClosedBranches; + QString m_searchText; + QGraphicsScene *scene(); void clearChangesets(); void replaceChangesets(Changesets); @@ -90,6 +97,7 @@ void setChangesetParents(); void updateNewAndCurrentItems(); void connectSceneSignals(); + void updateSearchStatus(); }; #endif diff -r 9c8147c9f245 -r 95877ad67d3e src/mainwindow.cpp --- a/src/mainwindow.cpp Fri Feb 17 10:58:41 2012 +0000 +++ b/src/mainwindow.cpp Mon Feb 27 17:08:47 2012 +0000 @@ -112,7 +112,7 @@ m_hgTabs = new HgTabWidget(central, m_workFolderPath); connectTabsSignals(); - cl->addWidget(m_hgTabs, row++, 0); + cl->addWidget(m_hgTabs, row++, 0, 1, 2); connect(m_hgTabs, SIGNAL(selectionChanged()), this, SLOT(enableDisableActions())); @@ -153,6 +153,11 @@ } +void MainWindow::resizeEvent(QResizeEvent *) +{ +} + + QString MainWindow::getUserInfo() const { QSettings settings; diff -r 9c8147c9f245 -r 95877ad67d3e src/mainwindow.h --- a/src/mainwindow.h Fri Feb 17 10:58:41 2012 +0000 +++ b/src/mainwindow.h Mon Feb 27 17:08:47 2012 +0000 @@ -46,6 +46,7 @@ protected: void closeEvent(QCloseEvent *event); + void resizeEvent(QResizeEvent *event); public slots: void open(QString local);