Skip to content
Snippets Groups Projects
Commit 592b0d7c authored by con's avatar con
Browse files

Add a "current file" find filter.

Which nicely adds the occurrances to the search output window for
navigation.
parent 4db79f2c
No related branches found
No related tags found
No related merge requests found
...@@ -83,7 +83,8 @@ void BaseFileFind::findAll(const QString &txt, QTextDocument::FindFlags findFlag ...@@ -83,7 +83,8 @@ void BaseFileFind::findAll(const QString &txt, QTextDocument::FindFlags findFlag
{ {
m_isSearching = true; m_isSearching = true;
emit changed(); emit changed();
updateComboEntries(m_filterCombo, false); if (m_filterCombo)
updateComboEntries(m_filterCombo, false);
m_watcher.setFuture(QFuture<FileSearchResult>()); m_watcher.setFuture(QFuture<FileSearchResult>());
m_resultWindow->clearContents(); m_resultWindow->clearContents();
m_resultWindow->popup(true); m_resultWindow->popup(true);
...@@ -194,7 +195,8 @@ void BaseFileFind::readCommonSettings(QSettings *settings, const QString &defaul ...@@ -194,7 +195,8 @@ void BaseFileFind::readCommonSettings(QSettings *settings, const QString &defaul
if (m_filterSetting.isEmpty()) if (m_filterSetting.isEmpty())
m_filterSetting = filters.first(); m_filterSetting = filters.first();
m_filterStrings.setStringList(filters); m_filterStrings.setStringList(filters);
syncComboWithSettings(m_filterCombo, m_filterSetting); if (m_filterCombo)
syncComboWithSettings(m_filterCombo, m_filterSetting);
} }
void BaseFileFind::syncComboWithSettings(QComboBox *combo, const QString &setting) void BaseFileFind::syncComboWithSettings(QComboBox *combo, const QString &setting)
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#include "findincurrentfile.h"
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <QtDebug>
#include <QtCore/QDirIterator>
#include <QtGui/QPushButton>
#include <QtGui/QFileDialog>
#include <QtGui/QVBoxLayout>
using namespace Find;
using namespace TextEditor::Internal;
FindInCurrentFile::FindInCurrentFile(SearchResultWindow *resultWindow)
: BaseFileFind(resultWindow),
m_configWidget(0)
{
}
QString FindInCurrentFile::id() const
{
return "Current File";
}
QString FindInCurrentFile::name() const
{
return tr("Current File");
}
QKeySequence FindInCurrentFile::defaultShortcut() const
{
return QKeySequence();
}
QStringList FindInCurrentFile::files()
{
QStringList fileList;
if (Core::IEditor *editor = Core::ICore::instance()->editorManager()->currentEditor()) {
if (editor->file() && !editor->file()->fileName().isEmpty())
fileList << editor->file()->fileName();
}
return fileList;
}
bool FindInCurrentFile::isEnabled() const
{
Core::IEditor *editor = Core::ICore::instance()->editorManager()->currentEditor();
return editor && editor->file() && !editor->file()->fileName().isEmpty();
}
QWidget *FindInCurrentFile::createConfigWidget()
{
if (!m_configWidget) {
m_configWidget = new QWidget;
QGridLayout * const gridLayout = new QGridLayout(m_configWidget);
gridLayout->setMargin(0);
m_configWidget->setLayout(gridLayout);
gridLayout->addWidget(createRegExpWidget(), 0, 1, 1, 2);
// just for the layout HACK
QLabel * const filePatternLabel = new QLabel;
filePatternLabel->setMinimumWidth(80);
filePatternLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
gridLayout->addWidget(filePatternLabel, 0, 0);
}
return m_configWidget;
}
void FindInCurrentFile::writeSettings(QSettings *settings)
{
settings->beginGroup("FindInCurrentFile");
writeCommonSettings(settings);
settings->endGroup();
}
void FindInCurrentFile::readSettings(QSettings *settings)
{
settings->beginGroup("FindInCurrentFile");
readCommonSettings(settings, "*.cpp,*.h");
settings->endGroup();
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#ifndef FINDINCURRENTFILE_H
#define FINDINCURRENTFILE_H
#include "basefilefind.h"
#include <find/ifindfilter.h>
#include <find/searchresultwindow.h>
#include <QtCore/QPointer>
#include <QtGui/QLabel>
#include <QtGui/QComboBox>
#include <QtGui/QStringListModel>
namespace TextEditor {
namespace Internal {
class FindInCurrentFile : public BaseFileFind
{
Q_OBJECT
public:
explicit FindInCurrentFile(Find::SearchResultWindow *resultWindow);
QString id() const;
QString name() const;
QKeySequence defaultShortcut() const;
bool isEnabled() const;
QWidget *createConfigWidget();
void writeSettings(QSettings *settings);
void readSettings(QSettings *settings);
protected:
QStringList files();
private:
QPointer<QWidget> m_configWidget;
};
} // namespace Internal
} // namespace TextEditor
#endif // FINDINCURRENTFILE_H
...@@ -25,7 +25,8 @@ SOURCES += texteditorplugin.cpp \ ...@@ -25,7 +25,8 @@ SOURCES += texteditorplugin.cpp \
findinfiles.cpp \ findinfiles.cpp \
basefilefind.cpp \ basefilefind.cpp \
texteditorsettings.cpp \ texteditorsettings.cpp \
codecselector.cpp codecselector.cpp \
findincurrentfile.cpp
HEADERS += texteditorplugin.h \ HEADERS += texteditorplugin.h \
textfilewizard.h \ textfilewizard.h \
plaintexteditor.h \ plaintexteditor.h \
...@@ -54,10 +55,10 @@ HEADERS += texteditorplugin.h \ ...@@ -54,10 +55,10 @@ HEADERS += texteditorplugin.h \
findinfiles.h \ findinfiles.h \
basefilefind.h \ basefilefind.h \
texteditorsettings.h \ texteditorsettings.h \
codecselector.h codecselector.h \
findincurrentfile.h
FORMS += behaviorsettingspage.ui \ FORMS += behaviorsettingspage.ui \
displaysettingspage.ui \ displaysettingspage.ui \
fontsettingspage.ui fontsettingspage.ui
RESOURCES += texteditor.qrc RESOURCES += texteditor.qrc
OTHER_FILES += TextEditor.pluginspec OTHER_FILES += TextEditor.pluginspec
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "texteditorplugin.h" #include "texteditorplugin.h"
#include "findinfiles.h" #include "findinfiles.h"
#include "findincurrentfile.h"
#include "fontsettings.h" #include "fontsettings.h"
#include "linenumberfilter.h" #include "linenumberfilter.h"
#include "texteditorconstants.h" #include "texteditorconstants.h"
...@@ -147,7 +148,8 @@ void TextEditorPlugin::extensionsInitialized() ...@@ -147,7 +148,8 @@ void TextEditorPlugin::extensionsInitialized()
addAutoReleasedObject(new FindInFiles( addAutoReleasedObject(new FindInFiles(
ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>())); ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>()));
addAutoReleasedObject(new FindInCurrentFile(
ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>()));
} }
void TextEditorPlugin::initializeEditor(PlainTextEditor *editor) void TextEditorPlugin::initializeEditor(PlainTextEditor *editor)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment