Mercurial > hg > easyhg
changeset 559:95877ad67d3e
Merge from branch "find"
author | Chris Cannam |
---|---|
date | Mon, 27 Feb 2012 17:08:47 +0000 |
parents | 9c8147c9f245 (current diff) d932ce55c364 (diff) |
children | 533519ebc0cb |
files | |
diffstat | 13 files changed, 274 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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()); }
--- 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<QAction *, QString> m_parentDiffActions; QMap<QAction *, QString> m_summaryActions;
--- 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 <QLabel> #include <QListWidget> @@ -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("<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>")); + } else { + m_noModificationsLabel->setText + (tr("<qt><b>Nothing found</b><br>No files have matching filenames.</qt>")); + } + } else if (settings.value("showhelpfultext", true).toBool()) { m_noModificationsLabel->setText (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>") #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();
--- 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<QWidget *> m_boxes; QWidget *m_boxesParent; + QString m_searchText; + void layoutBoxesGridly(int count); void layoutBoxesLinearly(); void setNoModificationsLabelText();
--- /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 <QGridLayout> +#include <QLabel> +#include <QLineEdit> +#include <QToolButton> + +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<QAbstractButton *>(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()); + } + } +} +
--- /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 <QWidget> + +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
--- 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();
--- 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;
--- 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 <iostream> @@ -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<QGraphicsItem *> items = scene->items(); + foreach (QGraphicsItem *it, items) { + + ChangesetItem *csit = dynamic_cast<ChangesetItem *>(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<ChangesetScene *>(m_panned->scene());
--- 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
--- 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;