1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "findincurrentfile.h"
34 #include "itexteditor.h"
36 #include <coreplugin/icore.h>
37 #include <coreplugin/editormanager/editormanager.h>
39 #include <QtCore/QtDebug>
40 #include <QtCore/QSettings>
41 #include <QtCore/QDirIterator>
42 #include <QtGui/QPushButton>
43 #include <QtGui/QFileDialog>
44 #include <QtGui/QVBoxLayout>
47 using namespace TextEditor;
48 using namespace TextEditor::Internal;
50 FindInCurrentFile::FindInCurrentFile(SearchResultWindow *resultWindow)
51 : BaseFileFind(resultWindow),
55 connect(Core::ICore::instance()->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)),
56 this, SLOT(handleFileChange(Core::IEditor*)));
57 handleFileChange(Core::ICore::instance()->editorManager()->currentEditor());
60 QString FindInCurrentFile::id() const
62 return "Current File";
65 QString FindInCurrentFile::displayName() const
67 return tr("Current File");
70 Utils::FileIterator *FindInCurrentFile::files() const
72 Q_ASSERT(isEnabled());
73 QString fileName = m_currentFile->fileName();
74 QMap<QString, QTextCodec *> openEditorEncodings = ITextEditor::openedTextEditorsEncodings();
75 QTextCodec *codec = openEditorEncodings.value(fileName);
77 codec = Core::EditorManager::instance()->defaultTextCodec();
78 return new Utils::FileIterator(QStringList() << fileName, QList<QTextCodec *>() << codec);
81 bool FindInCurrentFile::isEnabled() const
83 return m_currentFile && !m_currentFile->fileName().isEmpty();
86 void FindInCurrentFile::handleFileChange(Core::IEditor *editor)
94 Core::IFile *file = editor->file();
95 if (file != m_currentFile) {
103 QWidget *FindInCurrentFile::createConfigWidget()
105 if (!m_configWidget) {
106 m_configWidget = new QWidget;
107 QGridLayout * const gridLayout = new QGridLayout(m_configWidget);
108 gridLayout->setMargin(0);
109 m_configWidget->setLayout(gridLayout);
110 // just for the layout HACK
111 QLabel * const filePatternLabel = new QLabel;
112 filePatternLabel->setMinimumWidth(80);
113 filePatternLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
114 gridLayout->addWidget(filePatternLabel, 0, 0);
116 return m_configWidget;
119 void FindInCurrentFile::writeSettings(QSettings *settings)
121 settings->beginGroup("FindInCurrentFile");
122 writeCommonSettings(settings);
123 settings->endGroup();
126 void FindInCurrentFile::readSettings(QSettings *settings)
128 settings->beginGroup("FindInCurrentFile");
129 readCommonSettings(settings, "*.cpp,*.h");
130 settings->endGroup();