forked from qt-creator/qt-creator
Core: Add option to exclude binary files from search
Fixes: QTCREATORBUG-1756 Change-Id: I4675981f21b65c638ad64ac36668e5474337e283 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -378,6 +378,11 @@ void Find::setWholeWord(bool wholeOnly)
|
||||
d->setFindFlag(FindWholeWords, wholeOnly);
|
||||
}
|
||||
|
||||
void Find::setIgnoreBinaryFiles(bool ignoreBinaryFiles)
|
||||
{
|
||||
d->setFindFlag(DontFindBinaryFiles, ignoreBinaryFiles);
|
||||
}
|
||||
|
||||
void Find::setBackward(bool backward)
|
||||
{
|
||||
d->setFindFlag(FindBackward, backward);
|
||||
@@ -420,6 +425,8 @@ void FindPrivate::writeSettings()
|
||||
settings->setValueWithDefault("Backward", bool(m_findFlags & FindBackward), false);
|
||||
settings->setValueWithDefault("CaseSensitively", bool(m_findFlags & FindCaseSensitively), false);
|
||||
settings->setValueWithDefault("WholeWords", bool(m_findFlags & FindWholeWords), false);
|
||||
settings
|
||||
->setValueWithDefault("IgnoreBinaryFiles", bool(m_findFlags & DontFindBinaryFiles), false);
|
||||
settings->setValueWithDefault("RegularExpression",
|
||||
bool(m_findFlags & FindRegularExpression),
|
||||
false);
|
||||
@@ -437,6 +444,8 @@ void FindPrivate::writeSettings()
|
||||
s.insert("Backward", true);
|
||||
if (m_findFlags & FindCaseSensitively)
|
||||
s.insert("CaseSensitively", true);
|
||||
if (m_findFlags & DontFindBinaryFiles)
|
||||
s.insert("IgnoreBinaryFiles", true);
|
||||
if (m_findFlags & FindWholeWords)
|
||||
s.insert("WholeWords", true);
|
||||
if (m_findFlags & FindRegularExpression)
|
||||
@@ -472,6 +481,7 @@ void FindPrivate::readSettings()
|
||||
Find::setWholeWord(settings->value("WholeWords", false).toBool());
|
||||
Find::setRegularExpression(settings->value("RegularExpression", false).toBool());
|
||||
Find::setPreserveCase(settings->value("PreserveCase", false).toBool());
|
||||
Find::setIgnoreBinaryFiles(settings->value("IgnoreBinaryFiles", false).toBool());
|
||||
}
|
||||
m_findCompletionModel.readSettings(settings);
|
||||
m_replaceCompletions = settings->value("ReplaceStrings").toStringList();
|
||||
@@ -487,6 +497,7 @@ void FindPrivate::readSettings()
|
||||
Find::setWholeWord(s.value("WholeWords", false).toBool());
|
||||
Find::setRegularExpression(s.value("RegularExpression", false).toBool());
|
||||
Find::setPreserveCase(s.value("PreserveCase", false).toBool());
|
||||
Find::setIgnoreBinaryFiles(s.value("IgnoreBinaryFiles", false).toBool());
|
||||
}
|
||||
m_findCompletionModel.restore(storeFromVariant(s.value("FindCompletions")));
|
||||
m_replaceCompletions = s.value("ReplaceStrings").toStringList();
|
||||
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
|
||||
static void setCaseSensitive(bool sensitive);
|
||||
static void setWholeWord(bool wholeOnly);
|
||||
static void setIgnoreBinaryFiles(bool ignoreBinaryFiles);
|
||||
static void setBackward(bool backward);
|
||||
static void setRegularExpression(bool regExp);
|
||||
static void setPreserveCase(bool preserveCase);
|
||||
|
||||
@@ -83,6 +83,9 @@ FindToolWindow::FindToolWindow(QWidget *parent)
|
||||
m_wholeWords = new QCheckBox(m_optionsWidget);
|
||||
m_wholeWords->setText(Tr::tr("Whole words o&nly", nullptr));
|
||||
|
||||
m_ignoreBinaryFiles = new QCheckBox(m_optionsWidget);
|
||||
m_ignoreBinaryFiles->setText(Tr::tr("Ignore binary files", nullptr));
|
||||
|
||||
m_regExp = new QCheckBox(m_optionsWidget);
|
||||
m_regExp->setText(Tr::tr("Use re&gular expressions", nullptr));
|
||||
|
||||
@@ -108,6 +111,7 @@ FindToolWindow::FindToolWindow(QWidget *parent)
|
||||
m_matchCase,
|
||||
m_wholeWords,
|
||||
m_regExp,
|
||||
m_ignoreBinaryFiles,
|
||||
st,
|
||||
noMargin
|
||||
}.attachTo(m_optionsWidget);
|
||||
@@ -126,6 +130,7 @@ FindToolWindow::FindToolWindow(QWidget *parent)
|
||||
connect(m_replaceButton, &QAbstractButton::clicked, this, &FindToolWindow::replace);
|
||||
connect(m_matchCase, &QAbstractButton::toggled, Find::instance(), &Find::setCaseSensitive);
|
||||
connect(m_wholeWords, &QAbstractButton::toggled, Find::instance(), &Find::setWholeWord);
|
||||
connect(m_ignoreBinaryFiles, &QAbstractButton::toggled, Find::instance(), &Find::setIgnoreBinaryFiles);
|
||||
connect(m_regExp, &QAbstractButton::toggled, Find::instance(), &Find::setRegularExpression);
|
||||
connect(m_filterList, &QComboBox::activated, this, &FindToolWindow::setCurrentFilterIndex);
|
||||
|
||||
@@ -199,19 +204,22 @@ void FindToolWindow::updateButtonStates()
|
||||
if (m_configWidget)
|
||||
m_configWidget->setEnabled(filterEnabled);
|
||||
|
||||
Utils::FindFlags supportedFlags = m_currentFilter ? m_currentFilter->supportedFindFlags()
|
||||
: Utils::FindFlags();
|
||||
|
||||
if (m_currentFilter) {
|
||||
m_searchTerm->setVisible(m_currentFilter->showSearchTermInput());
|
||||
m_searchLabel->setVisible(m_currentFilter->showSearchTermInput());
|
||||
m_optionsWidget->setVisible(m_currentFilter->supportedFindFlags()
|
||||
& (FindCaseSensitively | FindWholeWords | FindRegularExpression));
|
||||
m_optionsWidget->setVisible(
|
||||
supportedFlags
|
||||
& (FindCaseSensitively | FindWholeWords | FindRegularExpression | DontFindBinaryFiles));
|
||||
}
|
||||
|
||||
m_matchCase->setEnabled(filterEnabled
|
||||
&& (m_currentFilter->supportedFindFlags() & FindCaseSensitively));
|
||||
m_wholeWords->setEnabled(filterEnabled
|
||||
&& (m_currentFilter->supportedFindFlags() & FindWholeWords));
|
||||
m_regExp->setEnabled(filterEnabled
|
||||
&& (m_currentFilter->supportedFindFlags() & FindRegularExpression));
|
||||
m_matchCase->setEnabled(filterEnabled && (supportedFlags & FindCaseSensitively));
|
||||
m_wholeWords->setEnabled(filterEnabled && (supportedFlags & FindWholeWords));
|
||||
m_ignoreBinaryFiles->setEnabled(filterEnabled && (supportedFlags & DontFindBinaryFiles));
|
||||
|
||||
m_regExp->setEnabled(filterEnabled && (supportedFlags & FindRegularExpression));
|
||||
m_searchTerm->setEnabled(filterEnabled);
|
||||
}
|
||||
|
||||
@@ -220,6 +228,7 @@ void FindToolWindow::updateFindFlags()
|
||||
m_matchCase->setChecked(Find::hasFindFlag(FindCaseSensitively));
|
||||
m_wholeWords->setChecked(Find::hasFindFlag(FindWholeWords));
|
||||
m_regExp->setChecked(Find::hasFindFlag(FindRegularExpression));
|
||||
m_ignoreBinaryFiles->setChecked(Find::hasFindFlag(DontFindBinaryFiles));
|
||||
}
|
||||
|
||||
|
||||
@@ -284,12 +293,16 @@ void FindToolWindow::setCurrentFilterIndex(int index)
|
||||
this, &FindToolWindow::updateButtonStates);
|
||||
disconnect(m_currentFilter, &IFindFilter::validChanged,
|
||||
this, &FindToolWindow::updateButtonStates);
|
||||
disconnect(m_currentFilter, &IFindFilter::supportedFlagsChanged,
|
||||
this, &FindToolWindow::updateButtonStates);
|
||||
}
|
||||
m_currentFilter = m_filters.at(i);
|
||||
connect(m_currentFilter, &IFindFilter::enabledChanged,
|
||||
this, &FindToolWindow::updateButtonStates);
|
||||
connect(m_currentFilter, &IFindFilter::validChanged,
|
||||
this, &FindToolWindow::updateButtonStates);
|
||||
connect(m_currentFilter, &IFindFilter::supportedFlagsChanged,
|
||||
this, &FindToolWindow::updateButtonStates);
|
||||
updateButtonStates();
|
||||
if (m_configWidget)
|
||||
m_uiConfigWidget->layout()->addWidget(m_configWidget);
|
||||
|
||||
@@ -72,6 +72,7 @@ private:
|
||||
QWidget *m_optionsWidget;
|
||||
QCheckBox *m_matchCase;
|
||||
QCheckBox *m_wholeWords;
|
||||
QCheckBox *m_ignoreBinaryFiles;
|
||||
QCheckBox *m_regExp;
|
||||
Utils::FancyLineEdit *m_searchTerm;
|
||||
};
|
||||
|
||||
@@ -57,6 +57,7 @@ signals:
|
||||
void enabledChanged(bool enabled);
|
||||
void validChanged(bool valid);
|
||||
void displayNameChanged();
|
||||
void supportedFlagsChanged();
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
||||
@@ -149,6 +149,11 @@ public:
|
||||
};
|
||||
}
|
||||
|
||||
Utils::FindFlags supportedFindFlags() const override
|
||||
{
|
||||
return FindCaseSensitively | FindWholeWords | FindRegularExpression | DontFindBinaryFiles;
|
||||
}
|
||||
|
||||
private:
|
||||
QWidget *m_widget;
|
||||
};
|
||||
@@ -285,6 +290,7 @@ void BaseFileFind::setCurrentSearchEngine(int index)
|
||||
return;
|
||||
d->m_currentSearchEngineIndex = index;
|
||||
emit currentSearchEngineChanged();
|
||||
emit supportedFlagsChanged();
|
||||
}
|
||||
|
||||
void BaseFileFind::runNewSearch(const QString &txt, FindFlags findFlags,
|
||||
|
||||
@@ -76,6 +76,11 @@ public:
|
||||
bool isEnabled() const;
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
virtual Utils::FindFlags supportedFindFlags() const
|
||||
{
|
||||
return Utils::FindCaseSensitively | Utils::FindRegularExpression | Utils::FindWholeWords;
|
||||
}
|
||||
|
||||
signals:
|
||||
void enabledChanged(bool enabled);
|
||||
|
||||
@@ -101,6 +106,11 @@ public:
|
||||
static Utils::FilePaths replaceAll(const QString &txt, const Utils::SearchResultItems &items,
|
||||
bool preserveCase = false);
|
||||
|
||||
Utils::FindFlags supportedFindFlags() const override
|
||||
{
|
||||
return currentSearchEngine()->supportedFindFlags();
|
||||
}
|
||||
|
||||
protected:
|
||||
void setSearchDir(const Utils::FilePath &dir);
|
||||
Utils::FilePath searchDir() const;
|
||||
|
||||
@@ -38,6 +38,11 @@ private:
|
||||
|
||||
QPointer<Core::IDocument> m_currentDocument;
|
||||
|
||||
Utils::FindFlags supportedFindFlags() const override
|
||||
{
|
||||
return FindCaseSensitively | FindRegularExpression | FindWholeWords;
|
||||
}
|
||||
|
||||
// deprecated
|
||||
QByteArray settingsKey() const final;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user