diff --git a/src/plugins/texteditor/basefilefind.cpp b/src/plugins/texteditor/basefilefind.cpp index 8565107c652708c014f7a9f49c21065e598e94c8..6c04645f8b7369ed86986ff1631b0f0f4f05029a 100644 --- a/src/plugins/texteditor/basefilefind.cpp +++ b/src/plugins/texteditor/basefilefind.cpp @@ -83,7 +83,8 @@ void BaseFileFind::findAll(const QString &txt, QTextDocument::FindFlags findFlag { m_isSearching = true; emit changed(); - updateComboEntries(m_filterCombo, false); + if (m_filterCombo) + updateComboEntries(m_filterCombo, false); m_watcher.setFuture(QFuture<FileSearchResult>()); m_resultWindow->clearContents(); m_resultWindow->popup(true); @@ -194,7 +195,8 @@ void BaseFileFind::readCommonSettings(QSettings *settings, const QString &defaul if (m_filterSetting.isEmpty()) m_filterSetting = filters.first(); 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) diff --git a/src/plugins/texteditor/findincurrentfile.cpp b/src/plugins/texteditor/findincurrentfile.cpp new file mode 100644 index 0000000000000000000000000000000000000000..97d3aa448363945b261beda61c274b99a3c60264 --- /dev/null +++ b/src/plugins/texteditor/findincurrentfile.cpp @@ -0,0 +1,110 @@ +/************************************************************************** +** +** 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(); +} diff --git a/src/plugins/texteditor/findincurrentfile.h b/src/plugins/texteditor/findincurrentfile.h new file mode 100644 index 0000000000000000000000000000000000000000..f3a56bbd79639631964d37c387aceeaefb5e56d0 --- /dev/null +++ b/src/plugins/texteditor/findincurrentfile.h @@ -0,0 +1,72 @@ +/************************************************************************** +** +** 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 diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro index be36fe0ef91e1f9db1fdd9e34b60780c4caeede4..639ac2acce36daeb1900e11f356d226060fb3ae0 100644 --- a/src/plugins/texteditor/texteditor.pro +++ b/src/plugins/texteditor/texteditor.pro @@ -25,7 +25,8 @@ SOURCES += texteditorplugin.cpp \ findinfiles.cpp \ basefilefind.cpp \ texteditorsettings.cpp \ - codecselector.cpp + codecselector.cpp \ + findincurrentfile.cpp HEADERS += texteditorplugin.h \ textfilewizard.h \ plaintexteditor.h \ @@ -54,10 +55,10 @@ HEADERS += texteditorplugin.h \ findinfiles.h \ basefilefind.h \ texteditorsettings.h \ - codecselector.h + codecselector.h \ + findincurrentfile.h FORMS += behaviorsettingspage.ui \ displaysettingspage.ui \ fontsettingspage.ui RESOURCES += texteditor.qrc - OTHER_FILES += TextEditor.pluginspec diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index 393e887dd107540694c3945c7033dc17400ac506..049d3a3978061fa52ea78c7aeb173b0384e075a7 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -30,6 +30,7 @@ #include "texteditorplugin.h" #include "findinfiles.h" +#include "findincurrentfile.h" #include "fontsettings.h" #include "linenumberfilter.h" #include "texteditorconstants.h" @@ -147,7 +148,8 @@ void TextEditorPlugin::extensionsInitialized() addAutoReleasedObject(new FindInFiles( ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>())); - + addAutoReleasedObject(new FindInCurrentFile( + ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>())); } void TextEditorPlugin::initializeEditor(PlainTextEditor *editor)