diff --git a/plugins/projectmanagerview/projectmanagerview.cpp b/plugins/projectmanagerview/projectmanagerview.cpp index 8e51ba8a01..35c8f3278e 100644 --- a/plugins/projectmanagerview/projectmanagerview.cpp +++ b/plugins/projectmanagerview/projectmanagerview.cpp @@ -1,202 +1,202 @@ /* This file is part of KDevelop Copyright 2005 Roberto Raggi Copyright 2007 Andreas Pakulat Copyright 2008 Aleix Pol This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "projectmanagerview.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "tests/modeltest.h" #include #include "projectmanagerviewplugin.h" #include "ui_projectmanagerview.h" using namespace KDevelop; ProjectManagerView::ProjectManagerView( ProjectManagerViewPlugin* plugin, QWidget *parent ) : QWidget( parent ), m_ui(new Ui::ProjectManagerView), m_plugin(plugin) { m_ui->setupUi( this ); setWindowIcon( SmallIcon( "project-development" ) ); m_syncAction = plugin->actionCollection()->action("locate_document"); Q_ASSERT(m_syncAction); m_syncAction->setShortcutContext(Qt::WidgetWithChildrenShortcut); m_syncAction->setText(i18n("Locate Current Document")); m_syncAction->setToolTip(i18n("Locates the current document in the project tree and selects it.")); m_syncAction->setIcon(KIcon("dirsync")); m_syncAction->setShortcut(Qt::ControlModifier + Qt::Key_Less); connect(m_syncAction, SIGNAL(triggered(bool)), this, SLOT(locateCurrentDocument())); addAction(m_syncAction); updateSyncAction(); addAction(plugin->actionCollection()->action("project_build")); addAction(plugin->actionCollection()->action("project_install")); addAction(plugin->actionCollection()->action("project_clean")); connect(m_ui->projectTreeView, SIGNAL(activateUrl(const KUrl&)), this, SLOT(openUrl(const KUrl&))); // m_filters = new KLineEdit(this); // m_filters->setClearButtonShown(true); // connect(d->m_filters, SIGNAL(returnPressed()), this, SLOT(filtersChanged())); // vbox->addWidget( m_filters ); m_ui->buildSetView->setProjectView( this ); m_modelFilter = new ProjectProxyModel( this ); m_modelFilter->setDynamicSortFilter( true ); m_modelFilter->setSourceModel(ICore::self()->projectController()->projectModel()); m_ui->projectTreeView->setModel( m_modelFilter ); connect(m_ui->fileNameFilterEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString))); connect( m_ui->projectTreeView->selectionModel(), SIGNAL(selectionChanged( const QItemSelection&, const QItemSelection&) ), this, SLOT(selectionChanged() ) ); connect( KDevelop::ICore::self()->documentController(), SIGNAL(documentClosed(KDevelop::IDocument*) ), SLOT(updateSyncAction())); connect( KDevelop::ICore::self()->documentController(), SIGNAL(documentActivated(KDevelop::IDocument*) ), SLOT(updateSyncAction())); connect( qobject_cast(KDevelop::ICore::self()->uiController()->activeMainWindow()), SIGNAL(areaChanged(Sublime::Area*)), SLOT(updateSyncAction())); selectionChanged(); //Update the "sync" button after the initialization has completed, to see whether there already is some open documents QMetaObject::invokeMethod(this, "updateSyncAction", Qt::QueuedConnection); // Need to set this to get horizontal scrollbar. Also needs to be done after // the setModel call m_ui->projectTreeView->header()->setResizeMode( QHeaderView::ResizeToContents ); } void ProjectManagerView::selectionChanged() { m_ui->buildSetView->selectionChanged(); QList selected; foreach( const QModelIndex& idx, m_ui->projectTreeView->selectionModel()->selectedRows() ) { selected << m_modelFilter->itemFromProxyIndex( idx ); } KDevelop::ICore::self()->selectionController()->updateSelection( new ProjectItemContext( selected ) ); } void ProjectManagerView::updateSyncAction() { m_syncAction->setEnabled( KDevelop::ICore::self()->documentController()->activeDocument() ); } ProjectManagerView::~ProjectManagerView() { } QList ProjectManagerView::selectedItems() const { QList items; foreach( const QModelIndex &idx, m_ui->projectTreeView->selectionModel()->selectedIndexes() ) { KDevelop::ProjectBaseItem* item = ICore::self()->projectController()->projectModel()->itemFromIndex( m_modelFilter->mapToSource(idx) ); if( item ) items << item; else kDebug(9511) << "adding an unknown item"; } return items; } void ProjectManagerView::locateCurrentDocument() { ICore::self()->uiController()->raiseToolView(this); KDevelop::IDocument *doc = ICore::self()->documentController()->activeDocument(); // We should _never_ get a null pointer for the document, as // the action is only enabled when there is an active document. Q_ASSERT(doc); QModelIndex bestMatch; foreach (IProject* proj, ICore::self()->projectController()->projects()) { foreach (KDevelop::ProjectFileItem* item, proj->filesForUrl(doc->url())) { QModelIndex index = m_modelFilter->proxyIndexFromItem(item); if (index.isValid()) { if (!bestMatch.isValid()) { bestMatch = index; } else if (KDevelop::ProjectBaseItem* parent = item->parent()) { // prefer files in their real folders over the 'copies' in the target folders if (!parent->target()) { bestMatch = index; break; } } } } } if (bestMatch.isValid()) { m_ui->projectTreeView->clearSelection(); m_ui->projectTreeView->setCurrentIndex(bestMatch); m_ui->projectTreeView->expand(bestMatch); m_ui->projectTreeView->scrollTo(bestMatch); } } void ProjectManagerView::openUrl( const KUrl& url ) { - ICore::self()->documentController()->openDocument( url ); + ICore::self()->documentController()->openDocument( url ); } void ProjectManagerView::filterChanged(const QString &text) { m_modelFilter->setFilterString(text); } #include "projectmanagerview.moc" diff --git a/project/projectproxymodel.cpp b/project/projectproxymodel.cpp index 86067f4d1c..c72ea48e32 100644 --- a/project/projectproxymodel.cpp +++ b/project/projectproxymodel.cpp @@ -1,126 +1,126 @@ /* This file is part of KDevelop Copyright 2008 Aleix Pol This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "projectproxymodel.h" #include #include #include #include #include ProjectProxyModel::ProjectProxyModel(QObject * parent) : QSortFilterProxyModel(parent) { setDynamicSortFilter(true); sort(0); //initiate sorting regardless of the view } KDevelop::ProjectModel * ProjectProxyModel::projectModel() const { return qobject_cast( sourceModel() ); } bool ProjectProxyModel::lessThan(const QModelIndex & left, const QModelIndex & right) const { KDevelop::ProjectBaseItem *iLeft=projectModel()->itemFromIndex(left), *iRight=projectModel()->itemFromIndex(right); if(!iLeft || !iRight) return false; return( iLeft->lessThan( iRight ) ); } QModelIndex ProjectProxyModel::proxyIndexFromItem(KDevelop::ProjectBaseItem* item) const { return mapFromSource(projectModel()->indexFromItem(item)); } KDevelop::ProjectBaseItem* ProjectProxyModel::itemFromProxyIndex( const QModelIndex& idx ) const { return static_cast( projectModel()->itemFromIndex( mapToSource( idx ) ) ); } QVariant ProjectProxyModel::data(const QModelIndex& index, int role) const { if( role == Qt::DecorationRole && index.isValid() ) { return KIcon( QSortFilterProxyModel::data(index, role).toString() ); } return QSortFilterProxyModel::data(index, role); } bool ProjectProxyModel::filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const { + if (mFilenameFilters.isEmpty()) { + return true; + } + bool retval = true; // Show all items by default - QModelIndex index0 = sourceModel()->index(source_row, 0, source_parent); + QModelIndex index = sourceModel()->index(source_row, 0, source_parent); - KDevelop::ProjectBaseItem *item(projectModel()->itemFromIndex(index0)); - - if (item) - { - if (!mFilenameFilters.empty() && - item->type() != KDevelop::ProjectBaseItem::Folder && + KDevelop::ProjectBaseItem *item = projectModel()->itemFromIndex(index); + + if (item) { + if (item->type() != KDevelop::ProjectBaseItem::Folder && item->type() != KDevelop::ProjectBaseItem::BuildFolder) { retval = false; // Do not show until it is matched to filter - + QSharedPointer filter; - + foreach(filter, mFilenameFilters) { - if (filter->exactMatch(item->text())) - { + if (filter->exactMatch(item->text())) { retval = true; break; } } } } return retval; } void ProjectProxyModel::setFilterString(const QString &filters) { QStringList patterns(filters.split(QRegExp("[; ]"), QString::SkipEmptyParts)); - + // Check for special case: single pattern without special chars -> force prefixed search (qwerty ->qwerty*) - if (patterns.size() == 1) - { + if (patterns.size() == 1) { QString pattern(patterns.front()); - + if (!pattern.contains('*') && !pattern.contains('?') && !pattern.contains('[') && !pattern.contains(']')) { // Filter has no specia symbols (?, *) so adjust it for prefixed search pattern += '*'; } - + patterns.clear(); patterns << pattern; } - + QString pattern; mFilenameFilters.clear(); - + foreach(pattern, patterns) { mFilenameFilters.push_back(QSharedPointer(new QRegExp(pattern, Qt::CaseInsensitive, QRegExp::Wildcard))); } - + invalidateFilter(); };