summaryrefslogtreecommitdiff
path: root/src/plugins/coreplugin
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2019-05-10 15:32:55 +0200
committerEike Ziller <eike.ziller@qt.io>2019-05-15 05:14:45 +0000
commitfd1ca5e06f13ef079136617d5783566ea35ff814 (patch)
tree88092f5e84bb1c660efa6407fc9dc1f644c5246b /src/plugins/coreplugin
parentb810f6f1bad9c02a39bd94f3dbfeeee31e6c2f47 (diff)
downloadqt-creator-fd1ca5e06f13ef079136617d5783566ea35ff814.tar.gz
Add filter for all files in all project directories
Behaves like the custom directory filters, but with preset directories, updating whenever a project is loaded or closed. Loading or closing a project will trigger a refresh of the file cache, otherwise the filter refreshes with the refresh interval that the other custom directory filters use, or on manual request. Task-number: QTCREATORBUG-19122 Change-Id: Id4f65b5137284e63412390672fa8449030c9fed4 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/coreplugin')
-rw-r--r--src/plugins/coreplugin/locator/directoryfilter.cpp170
-rw-r--r--src/plugins/coreplugin/locator/directoryfilter.h29
-rw-r--r--src/plugins/coreplugin/locator/directoryfilter.ui37
-rw-r--r--src/plugins/coreplugin/locator/locator.cpp21
-rw-r--r--src/plugins/coreplugin/locator/locator.h3
5 files changed, 186 insertions, 74 deletions
diff --git a/src/plugins/coreplugin/locator/directoryfilter.cpp b/src/plugins/coreplugin/locator/directoryfilter.cpp
index 645bae42d3..02e7e59fe9 100644
--- a/src/plugins/coreplugin/locator/directoryfilter.cpp
+++ b/src/plugins/coreplugin/locator/directoryfilter.cpp
@@ -24,6 +24,9 @@
****************************************************************************/
#include "directoryfilter.h"
+#include "ui_directoryfilter.h"
+
+#include "locator.h"
#include <coreplugin/coreconstants.h>
#include <utils/algorithm.h>
@@ -32,8 +35,7 @@
#include <QFileDialog>
#include <QTimer>
-using namespace Core;
-using namespace Core::Internal;
+namespace Core {
DirectoryFilter::DirectoryFilter(Id id)
: m_filters({"*.h", "*.cpp", "*.ui", "*.qrc"}),
@@ -64,12 +66,13 @@ void DirectoryFilter::restoreState(const QByteArray &state)
QMutexLocker locker(&m_lock);
QString name;
+ QStringList directories;
QString shortcut;
bool defaultFilter;
QDataStream in(state);
in >> name;
- in >> m_directories;
+ in >> directories;
in >> m_filters;
in >> shortcut;
in >> defaultFilter;
@@ -79,6 +82,8 @@ void DirectoryFilter::restoreState(const QByteArray &state)
else
m_exclusionFilters.clear();
+ if (m_isCustomFilter)
+ m_directories = directories;
setDisplayName(name);
setShortcutString(shortcut);
setIncludedByDefault(defaultFilter);
@@ -88,60 +93,83 @@ void DirectoryFilter::restoreState(const QByteArray &state)
bool DirectoryFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
{
+ if (!m_ui) {
+ m_ui = new Internal::Ui::DirectoryFilterOptions;
+ }
bool success = false;
QDialog dialog(parent);
m_dialog = &dialog;
- m_ui.setupUi(&dialog);
+ m_ui->setupUi(&dialog);
dialog.setWindowTitle(ILocatorFilter::msgConfigureDialogTitle());
- m_ui.prefixLabel->setText(ILocatorFilter::msgPrefixLabel());
- m_ui.prefixLabel->setToolTip(ILocatorFilter::msgPrefixToolTip());
- m_ui.defaultFlag->setText(ILocatorFilter::msgIncludeByDefault());
- m_ui.defaultFlag->setToolTip(ILocatorFilter::msgIncludeByDefaultToolTip());
- connect(m_ui.addButton, &QPushButton::clicked,
- this, &DirectoryFilter::addDirectory, Qt::DirectConnection);
- connect(m_ui.editButton, &QPushButton::clicked,
- this, &DirectoryFilter::editDirectory, Qt::DirectConnection);
- connect(m_ui.removeButton, &QPushButton::clicked,
- this, &DirectoryFilter::removeDirectory, Qt::DirectConnection);
- connect(m_ui.directoryList, &QListWidget::itemSelectionChanged,
- this, &DirectoryFilter::updateOptionButtons, Qt::DirectConnection);
- m_ui.nameEdit->setText(displayName());
- m_ui.nameEdit->selectAll();
- m_ui.directoryList->clear();
- m_ui.directoryList->addItems(m_directories);
- m_ui.filePatternLabel->setText(Utils::msgFilePatternLabel());
- m_ui.filePatternLabel->setBuddy(m_ui.filePattern);
- m_ui.filePattern->setToolTip(Utils::msgFilePatternToolTip());
- m_ui.filePattern->setText(Utils::transform(m_filters, &QDir::toNativeSeparators).join(','));
- m_ui.exclusionPatternLabel->setText(Utils::msgExclusionPatternLabel());
- m_ui.exclusionPatternLabel->setBuddy(m_ui.exclusionPattern);
- m_ui.exclusionPattern->setToolTip(Utils::msgFilePatternToolTip());
- m_ui.exclusionPattern->setText(Utils::transform(m_exclusionFilters, &QDir::toNativeSeparators)
- .join(','));
- m_ui.shortcutEdit->setText(shortcutString());
- m_ui.defaultFlag->setChecked(isIncludedByDefault());
+ m_ui->prefixLabel->setText(ILocatorFilter::msgPrefixLabel());
+ m_ui->prefixLabel->setToolTip(ILocatorFilter::msgPrefixToolTip());
+ m_ui->defaultFlag->setText(ILocatorFilter::msgIncludeByDefault());
+ m_ui->defaultFlag->setToolTip(ILocatorFilter::msgIncludeByDefaultToolTip());
+ m_ui->nameEdit->setText(displayName());
+ m_ui->nameEdit->selectAll();
+ connect(m_ui->addButton,
+ &QPushButton::clicked,
+ this,
+ &DirectoryFilter::handleAddDirectory,
+ Qt::DirectConnection);
+ connect(m_ui->editButton,
+ &QPushButton::clicked,
+ this,
+ &DirectoryFilter::handleEditDirectory,
+ Qt::DirectConnection);
+ connect(m_ui->removeButton,
+ &QPushButton::clicked,
+ this,
+ &DirectoryFilter::handleRemoveDirectory,
+ Qt::DirectConnection);
+ connect(m_ui->directoryList,
+ &QListWidget::itemSelectionChanged,
+ this,
+ &DirectoryFilter::updateOptionButtons,
+ Qt::DirectConnection);
+ m_ui->directoryList->clear();
+ m_ui->directoryList->addItems(m_directories);
+ m_ui->nameLabel->setVisible(m_isCustomFilter);
+ m_ui->nameEdit->setVisible(m_isCustomFilter);
+ m_ui->directoryLabel->setVisible(m_isCustomFilter);
+ m_ui->directoryList->setVisible(m_isCustomFilter);
+ m_ui->addButton->setVisible(m_isCustomFilter);
+ m_ui->editButton->setVisible(m_isCustomFilter);
+ m_ui->removeButton->setVisible(m_isCustomFilter);
+ m_ui->filePatternLabel->setText(Utils::msgFilePatternLabel());
+ m_ui->filePatternLabel->setBuddy(m_ui->filePattern);
+ m_ui->filePattern->setToolTip(Utils::msgFilePatternToolTip());
+ m_ui->filePattern->setText(Utils::transform(m_filters, &QDir::toNativeSeparators).join(','));
+ m_ui->exclusionPatternLabel->setText(Utils::msgExclusionPatternLabel());
+ m_ui->exclusionPatternLabel->setBuddy(m_ui->exclusionPattern);
+ m_ui->exclusionPattern->setToolTip(Utils::msgFilePatternToolTip());
+ m_ui->exclusionPattern->setText(
+ Utils::transform(m_exclusionFilters, &QDir::toNativeSeparators).join(','));
+ m_ui->shortcutEdit->setText(shortcutString());
+ m_ui->defaultFlag->setChecked(isIncludedByDefault());
updateOptionButtons();
+ dialog.adjustSize();
if (dialog.exec() == QDialog::Accepted) {
QMutexLocker locker(&m_lock);
bool directoriesChanged = false;
const QStringList oldDirectories = m_directories;
const QStringList oldFilters = m_filters;
const QStringList oldExclusionFilters = m_exclusionFilters;
- setDisplayName(m_ui.nameEdit->text().trimmed());
+ setDisplayName(m_ui->nameEdit->text().trimmed());
m_directories.clear();
const int oldCount = oldDirectories.count();
- const int newCount = m_ui.directoryList->count();
+ const int newCount = m_ui->directoryList->count();
if (oldCount != newCount)
directoriesChanged = true;
for (int i = 0; i < newCount; ++i) {
- m_directories.append(m_ui.directoryList->item(i)->text());
+ m_directories.append(m_ui->directoryList->item(i)->text());
if (!directoriesChanged && m_directories.at(i) != oldDirectories.at(i))
directoriesChanged = true;
}
- m_filters = Utils::splitFilterUiText(m_ui.filePattern->text());
- m_exclusionFilters = Utils::splitFilterUiText(m_ui.exclusionPattern->text());
- setShortcutString(m_ui.shortcutEdit->text().trimmed());
- setIncludedByDefault(m_ui.defaultFlag->isChecked());
+ m_filters = Utils::splitFilterUiText(m_ui->filePattern->text());
+ m_exclusionFilters = Utils::splitFilterUiText(m_ui->exclusionPattern->text());
+ setShortcutString(m_ui->shortcutEdit->text().trimmed());
+ setIncludedByDefault(m_ui->defaultFlag->isChecked());
needsRefresh = directoriesChanged || oldFilters != m_filters
|| oldExclusionFilters != m_exclusionFilters;
success = true;
@@ -149,37 +177,37 @@ bool DirectoryFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
return success;
}
-void DirectoryFilter::addDirectory()
+void DirectoryFilter::handleAddDirectory()
{
QString dir = QFileDialog::getExistingDirectory(m_dialog, tr("Select Directory"));
if (!dir.isEmpty())
- m_ui.directoryList->addItem(dir);
+ m_ui->directoryList->addItem(dir);
}
-void DirectoryFilter::editDirectory()
+void DirectoryFilter::handleEditDirectory()
{
- if (m_ui.directoryList->selectedItems().count() < 1)
+ if (m_ui->directoryList->selectedItems().count() < 1)
return;
- QListWidgetItem *currentItem = m_ui.directoryList->selectedItems().at(0);
+ QListWidgetItem *currentItem = m_ui->directoryList->selectedItems().at(0);
QString dir = QFileDialog::getExistingDirectory(m_dialog, tr("Select Directory"),
currentItem->text());
if (!dir.isEmpty())
currentItem->setText(dir);
}
-void DirectoryFilter::removeDirectory()
+void DirectoryFilter::handleRemoveDirectory()
{
- if (m_ui.directoryList->selectedItems().count() < 1)
+ if (m_ui->directoryList->selectedItems().count() < 1)
return;
- QListWidgetItem *currentItem = m_ui.directoryList->selectedItems().at(0);
- delete m_ui.directoryList->takeItem(m_ui.directoryList->row(currentItem));
+ QListWidgetItem *currentItem = m_ui->directoryList->selectedItems().at(0);
+ delete m_ui->directoryList->takeItem(m_ui->directoryList->row(currentItem));
}
void DirectoryFilter::updateOptionButtons()
{
- bool haveSelectedItem = (m_ui.directoryList->selectedItems().count() > 0);
- m_ui.editButton->setEnabled(haveSelectedItem);
- m_ui.removeButton->setEnabled(haveSelectedItem);
+ bool haveSelectedItem = (m_ui->directoryList->selectedItems().count() > 0);
+ m_ui->editButton->setEnabled(haveSelectedItem);
+ m_ui->removeButton->setEnabled(haveSelectedItem);
}
void DirectoryFilter::updateFileIterator()
@@ -225,3 +253,45 @@ void DirectoryFilter::refresh(QFutureInterface<void> &future)
future.setProgressValueAndText(subDirIterator.currentProgress(), tr("%1 filter update: canceled").arg(displayName()));
}
}
+
+void DirectoryFilter::setIsCustomFilter(bool value)
+{
+ m_isCustomFilter = value;
+}
+
+void DirectoryFilter::setDirectories(const QStringList &directories)
+{
+ if (directories == m_directories)
+ return;
+ m_directories = directories;
+ Internal::Locator::instance()->refresh({this});
+}
+
+void DirectoryFilter::addDirectory(const QString &directory)
+{
+ setDirectories(m_directories + QStringList(directory));
+}
+
+void DirectoryFilter::removeDirectory(const QString &directory)
+{
+ QStringList directories = m_directories;
+ directories.removeOne(directory);
+ setDirectories(directories);
+}
+
+QStringList DirectoryFilter::directories() const
+{
+ return m_directories;
+}
+
+void DirectoryFilter::setFilters(const QStringList &filters)
+{
+ m_filters = filters;
+}
+
+void DirectoryFilter::setExclusionFilters(const QStringList &exclusionFilters)
+{
+ m_exclusionFilters = exclusionFilters;
+}
+
+} // namespace Core
diff --git a/src/plugins/coreplugin/locator/directoryfilter.h b/src/plugins/coreplugin/locator/directoryfilter.h
index 06ef1f37e3..803141afdb 100644
--- a/src/plugins/coreplugin/locator/directoryfilter.h
+++ b/src/plugins/coreplugin/locator/directoryfilter.h
@@ -25,9 +25,10 @@
#pragma once
-#include "ui_directoryfilter.h"
#include "basefilefilter.h"
+#include <coreplugin/core_global.h>
+
#include <QString>
#include <QByteArray>
#include <QFutureInterface>
@@ -35,8 +36,12 @@
namespace Core {
namespace Internal {
+namespace Ui {
+class DirectoryFilterOptions;
+} // namespace Ui
+} // namespace Internal
-class DirectoryFilter : public BaseFileFilter
+class CORE_EXPORT DirectoryFilter : public BaseFileFilter
{
Q_OBJECT
@@ -47,10 +52,20 @@ public:
bool openConfigDialog(QWidget *parent, bool &needsRefresh) override;
void refresh(QFutureInterface<void> &future) override;
+ void setIsCustomFilter(bool value);
+ void setDirectories(const QStringList &directories);
+ void addDirectory(const QString &directory);
+ void removeDirectory(const QString &directory);
+ QStringList directories() const;
+ void setFilters(const QStringList &filters);
+ void setExclusionFilters(const QStringList &exclusionFilters);
+
+ using ILocatorFilter::setDisplayName;
+
private:
- void addDirectory();
- void editDirectory();
- void removeDirectory();
+ void handleAddDirectory();
+ void handleEditDirectory();
+ void handleRemoveDirectory();
void updateOptionButtons();
void updateFileIterator();
@@ -60,10 +75,10 @@ private:
// Our config dialog, uses in addDirectory and editDirectory
// to give their dialogs the right parent
QDialog *m_dialog = nullptr;
- Ui::DirectoryFilterOptions m_ui;
+ Internal::Ui::DirectoryFilterOptions *m_ui = nullptr;
mutable QMutex m_lock;
QStringList m_files;
+ bool m_isCustomFilter = true;
};
-} // namespace Internal
} // namespace Core
diff --git a/src/plugins/coreplugin/locator/directoryfilter.ui b/src/plugins/coreplugin/locator/directoryfilter.ui
index 37d26e4ed7..5889a82750 100644
--- a/src/plugins/coreplugin/locator/directoryfilter.ui
+++ b/src/plugins/coreplugin/locator/directoryfilter.ui
@@ -10,11 +10,11 @@
<height>300</height>
</rect>
</property>
- <layout class="QGridLayout">
- <item row="0" column="0">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
<layout class="QGridLayout">
<item row="0" column="0">
- <widget class="QLabel" name="label">
+ <widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
@@ -81,7 +81,7 @@ To do this, you type this shortcut and a space in the Locator entry field, and t
</widget>
</item>
<item row="1" column="3">
- <layout class="QVBoxLayout" name="verticalLayout">
+ <layout class="QVBoxLayout" name="directoryButtonLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
@@ -110,8 +110,8 @@ To do this, you type this shortcut and a space in the Locator entry field, and t
</property>
<property name="sizeHint" stdset="0">
<size>
- <width>20</width>
- <height>40</height>
+ <width>0</width>
+ <height>0</height>
</size>
</property>
</spacer>
@@ -119,23 +119,23 @@ To do this, you type this shortcut and a space in the Locator entry field, and t
</layout>
</item>
<item row="1" column="0">
- <layout class="QVBoxLayout" name="verticalLayout_2">
+ <layout class="QVBoxLayout" name="directoryLabelLayout">
<item>
- <widget class="QLabel" name="label_2">
+ <widget class="QLabel" name="directoryLabel">
<property name="text">
<string>Directories:</string>
</property>
</widget>
</item>
<item>
- <spacer name="verticalSpacer">
+ <spacer name="directoryLabelSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
- <width>20</width>
- <height>40</height>
+ <width>0</width>
+ <height>0</height>
</size>
</property>
</spacer>
@@ -154,7 +154,20 @@ To do this, you type this shortcut and a space in the Locator entry field, and t
</item>
</layout>
</item>
- <item row="1" column="0">
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
diff --git a/src/plugins/coreplugin/locator/locator.cpp b/src/plugins/coreplugin/locator/locator.cpp
index d3de093e17..48749cce3e 100644
--- a/src/plugins/coreplugin/locator/locator.cpp
+++ b/src/plugins/coreplugin/locator/locator.cpp
@@ -56,7 +56,6 @@
#include <utils/utilsicons.h>
#include <QAction>
-#include <QFuture>
#include <QSettings>
#include <QtPlugin>
@@ -339,10 +338,22 @@ void Locator::setRefreshInterval(int interval)
void Locator::refresh(QList<ILocatorFilter *> filters)
{
- QFuture<void> task = Utils::map(filters, &ILocatorFilter::refresh, Utils::MapReduceOption::Unordered);
- FutureProgress *progress =
- ProgressManager::addTask(task, tr("Updating Locator Caches"), Constants::TASK_INDEX);
- connect(progress, &FutureProgress::finished, this, &Locator::saveSettings);
+ if (m_refreshTask.isRunning()) {
+ m_refreshTask.cancel();
+ // this is not ideal because some of the previous filters might have finished, but we
+ // currently cannot find out which part of a map-reduce has finished
+ filters = Utils::filteredUnique(m_refreshingFilters + filters);
+ }
+ m_refreshingFilters = filters;
+ m_refreshTask = Utils::map(filters, &ILocatorFilter::refresh, Utils::MapReduceOption::Unordered);
+ ProgressManager::addTask(m_refreshTask, tr("Updating Locator Caches"), Constants::TASK_INDEX);
+ Utils::onFinished(m_refreshTask, this, [this](const QFuture<void> &future) {
+ if (!future.isCanceled()) {
+ saveSettings();
+ m_refreshingFilters.clear();
+ m_refreshTask = QFuture<void>();
+ }
+ });
}
} // namespace Internal
diff --git a/src/plugins/coreplugin/locator/locator.h b/src/plugins/coreplugin/locator/locator.h
index bb68c4a336..d7c62c44ba 100644
--- a/src/plugins/coreplugin/locator/locator.h
+++ b/src/plugins/coreplugin/locator/locator.h
@@ -30,6 +30,7 @@
#include <coreplugin/actionmanager/command.h>
+#include <QFuture>
#include <QObject>
#include <QTimer>
@@ -80,6 +81,8 @@ private:
QList<ILocatorFilter *> m_customFilters;
QMap<Id, QAction *> m_filterActionMap;
QTimer m_refreshTimer;
+ QFuture<void> m_refreshTask;
+ QList<ILocatorFilter *> m_refreshingFilters;
};
} // namespace Internal