Commit 45b7451a authored by Eike Ziller's avatar Eike Ziller

Fix that names of custom locator filters are ignored.

We need to set the display name on the interface, and give the filters a
unique id (simply numbered).

Task-number: QTCREATORBUG-11051
Change-Id: I8fdbf52fb538f071a9257ac57d2151f58f8d2157
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 6b8b60ce
......@@ -35,13 +35,12 @@
using namespace Core;
using namespace Core::Internal;
DirectoryFilter::DirectoryFilter()
: m_name(tr("Generic Directory Filter")),
m_dialog(0)
DirectoryFilter::DirectoryFilter(Id id)
: m_dialog(0)
{
setId(Core::Id::fromString(m_name));
setId(id);
setIncludedByDefault(true);
setDisplayName(m_name);
setDisplayName(tr("Generic Directory Filter"));
m_filters.append(QLatin1String("*.h"));
m_filters.append(QLatin1String("*.cpp"));
......@@ -54,7 +53,7 @@ QByteArray DirectoryFilter::saveState() const
QMutexLocker locker(&m_lock);
QByteArray value;
QDataStream out(&value, QIODevice::WriteOnly);
out << m_name;
out << displayName();
out << m_directories;
out << m_filters;
out << shortcutString();
......@@ -67,17 +66,19 @@ bool DirectoryFilter::restoreState(const QByteArray &state)
{
QMutexLocker locker(&m_lock);
QString name;
QString shortcut;
bool defaultFilter;
QDataStream in(state);
in >> m_name;
in >> name;
in >> m_directories;
in >> m_filters;
in >> shortcut;
in >> defaultFilter;
in >> files();
setDisplayName(name);
setShortcutString(shortcut);
setIncludedByDefault(defaultFilter);
......@@ -100,7 +101,7 @@ bool DirectoryFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
this, SLOT(removeDirectory()), Qt::DirectConnection);
connect(m_ui.directoryList, SIGNAL(itemSelectionChanged()),
this, SLOT(updateOptionButtons()), Qt::DirectConnection);
m_ui.nameEdit->setText(m_name);
m_ui.nameEdit->setText(displayName());
m_ui.nameEdit->selectAll();
m_ui.directoryList->clear();
m_ui.directoryList->addItems(m_directories);
......@@ -113,7 +114,7 @@ bool DirectoryFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
bool directoriesChanged = false;
QStringList oldDirectories = m_directories;
QStringList oldFilters = m_filters;
m_name = m_ui.nameEdit->text().trimmed();
setDisplayName(m_ui.nameEdit->text().trimmed());
m_directories.clear();
int oldCount = oldDirectories.count();
int newCount = m_ui.directoryList->count();
......@@ -176,7 +177,7 @@ void DirectoryFilter::refresh(QFutureInterface<void> &future)
files().clear();
generateFileNames();
future.setProgressRange(0, 1);
future.setProgressValueAndText(1, tr("%1 filter update: 0 files").arg(m_name));
future.setProgressValueAndText(1, tr("%1 filter update: 0 files").arg(displayName()));
return;
}
directories = m_directories;
......@@ -189,7 +190,7 @@ void DirectoryFilter::refresh(QFutureInterface<void> &future)
if (future.isProgressUpdateNeeded()
|| future.progressValue() == 0 /*workaround for regression in Qt*/) {
future.setProgressValueAndText(it.currentProgress(),
tr("%1 filter update: %n files", 0, filesFound.size()).arg(m_name));
tr("%1 filter update: %n files", 0, filesFound.size()).arg(displayName()));
}
}
......@@ -199,6 +200,6 @@ void DirectoryFilter::refresh(QFutureInterface<void> &future)
generateFileNames();
future.setProgressValue(it.maxProgress());
} else {
future.setProgressValueAndText(it.currentProgress(), tr("%1 filter update: canceled").arg(m_name));
future.setProgressValueAndText(it.currentProgress(), tr("%1 filter update: canceled").arg(displayName()));
}
}
......@@ -46,7 +46,7 @@ class DirectoryFilter : public BaseFileFilter
Q_OBJECT
public:
DirectoryFilter();
DirectoryFilter(Core::Id id);
QByteArray saveState() const;
bool restoreState(const QByteArray &state);
bool openConfigDialog(QWidget *parent, bool &needsRefresh);
......@@ -59,7 +59,6 @@ private slots:
void updateOptionButtons();
private:
QString m_name;
QStringList m_directories;
QStringList m_filters;
// Our config dialog, uses in addDirectory and editDirectory
......
......@@ -33,6 +33,7 @@
#include "ilocatorfilter.h"
#include "directoryfilter.h"
#include "executefilter.h"
#include "locatorconstants.h"
#include <extensionsystem/iplugin.h>
#include <coreplugin/actionmanager/command.h>
......@@ -117,8 +118,10 @@ void Locator::loadSettingsHelper(S *settings)
settings->beginGroup(QLatin1String("CustomFilters"));
QList<ILocatorFilter *> customFilters;
const QStringList keys = settings->childKeys();
int count = 0;
Core::Id baseId(Constants::CUSTOM_FILTER_BASEID);
foreach (const QString &key, keys) {
ILocatorFilter *filter = new DirectoryFilter;
ILocatorFilter *filter = new DirectoryFilter(baseId.withSuffix(++count));
filter->restoreState(settings->value(key).toByteArray());
m_filters.append(filter);
customFilters.append(filter);
......
......@@ -36,6 +36,7 @@ namespace Core {
namespace Constants {
const char FILTER_OPTIONS_PAGE[] = QT_TRANSLATE_NOOP("Locator", "Locator");
const char CUSTOM_FILTER_BASEID[] = "Locator.CustomFilter";
const char TASK_INDEX[] = "Locator.Task.Index";
} // namespace Constants
......
......@@ -180,7 +180,8 @@ void SettingsPage::configureFilter(QListWidgetItem *item)
void SettingsPage::addCustomFilter()
{
ILocatorFilter *filter = new DirectoryFilter;
ILocatorFilter *filter = new DirectoryFilter(
Core::Id(Constants::CUSTOM_FILTER_BASEID).withSuffix(m_customFilters.size() + 1));
bool needsRefresh = false;
if (filter->openConfigDialog(m_widget, needsRefresh)) {
m_filters.append(filter);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment