| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-01-11 16:28:15 +01:00
										 |  |  | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-11-02 15:59:12 +01:00
										 |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** 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.
 | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** In addition, as a special exception, Nokia gives you certain additional | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** rights. These rights are described in the Nokia Qt LGPL Exception | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** Other Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Alternatively, this file may be used in accordance with the terms and | 
					
						
							|  |  |  | ** conditions contained in a signed written agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** If you have questions regarding the use of this file, please contact | 
					
						
							| 
									
										
										
										
											2011-11-02 15:59:12 +01:00
										 |  |  | ** Nokia at qt-info@nokia.com. | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "findincurrentfile.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-11 11:34:17 +02:00
										 |  |  | #include "itexteditor.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <coreplugin/icore.h>
 | 
					
						
							|  |  |  | #include <coreplugin/editormanager/editormanager.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-01 16:38:08 +02:00
										 |  |  | #include <QtCore/QtDebug>
 | 
					
						
							|  |  |  | #include <QtCore/QSettings>
 | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | #include <QtCore/QDirIterator>
 | 
					
						
							|  |  |  | #include <QtGui/QPushButton>
 | 
					
						
							|  |  |  | #include <QtGui/QFileDialog>
 | 
					
						
							|  |  |  | #include <QtGui/QVBoxLayout>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace Find; | 
					
						
							| 
									
										
										
										
											2010-10-11 11:34:17 +02:00
										 |  |  | using namespace TextEditor; | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | using namespace TextEditor::Internal; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-02 11:51:31 +02:00
										 |  |  | FindInCurrentFile::FindInCurrentFile() | 
					
						
							|  |  |  |   : m_configWidget(0), | 
					
						
							| 
									
										
										
										
											2009-08-25 12:30:47 +02:00
										 |  |  |     m_currentFile(0) | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-08-25 12:30:47 +02:00
										 |  |  |     connect(Core::ICore::instance()->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)), | 
					
						
							|  |  |  |             this, SLOT(handleFileChange(Core::IEditor*))); | 
					
						
							|  |  |  |     handleFileChange(Core::ICore::instance()->editorManager()->currentEditor()); | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString FindInCurrentFile::id() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return "Current File"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-12 12:06:15 +02:00
										 |  |  | QString FindInCurrentFile::displayName() const | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return tr("Current File"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-13 10:50:57 +01:00
										 |  |  | Utils::FileIterator *FindInCurrentFile::files(const QStringList &nameFilters, | 
					
						
							|  |  |  |                                               const QVariant &additionalParameters) const | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-13 10:50:57 +01:00
										 |  |  |     Q_UNUSED(nameFilters) | 
					
						
							|  |  |  |     QString fileName = additionalParameters.toString(); | 
					
						
							| 
									
										
										
										
											2010-10-11 11:34:17 +02:00
										 |  |  |     QMap<QString, QTextCodec *> openEditorEncodings = ITextEditor::openedTextEditorsEncodings(); | 
					
						
							|  |  |  |     QTextCodec *codec = openEditorEncodings.value(fileName); | 
					
						
							|  |  |  |     if (!codec) | 
					
						
							| 
									
										
										
										
											2011-02-01 14:13:54 +01:00
										 |  |  |         codec = Core::EditorManager::instance()->defaultTextCodec(); | 
					
						
							| 
									
										
										
										
											2010-10-11 11:34:17 +02:00
										 |  |  |     return new Utils::FileIterator(QStringList() << fileName, QList<QTextCodec *>() << codec); | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-13 10:50:57 +01:00
										 |  |  | QVariant FindInCurrentFile::additionalParameters() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return qVariantFromValue(m_currentFile->fileName()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-07 20:28:04 +02:00
										 |  |  | QString FindInCurrentFile::label() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return tr("File '%1':").arg(QFileInfo(m_currentFile->fileName()).fileName()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString FindInCurrentFile::toolTip() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-16 09:28:20 +02:00
										 |  |  |     // %2 is filled by BaseFileFind::runNewSearch
 | 
					
						
							| 
									
										
										
										
											2011-09-07 20:28:04 +02:00
										 |  |  |     return tr("File path: %1\n%2").arg(QDir::toNativeSeparators(m_currentFile->fileName())); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | bool FindInCurrentFile::isEnabled() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-08-25 12:30:47 +02:00
										 |  |  |     return m_currentFile && !m_currentFile->fileName().isEmpty(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FindInCurrentFile::handleFileChange(Core::IEditor *editor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!editor) { | 
					
						
							|  |  |  |         if (m_currentFile) { | 
					
						
							|  |  |  |             m_currentFile = 0; | 
					
						
							|  |  |  |             emit changed(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         Core::IFile *file = editor->file(); | 
					
						
							|  |  |  |         if (file != m_currentFile) { | 
					
						
							|  |  |  |             m_currentFile = file; | 
					
						
							|  |  |  |             emit changed(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-25 12:30:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-29 14:14:08 +02:00
										 |  |  | QWidget *FindInCurrentFile::createConfigWidget() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!m_configWidget) { | 
					
						
							|  |  |  |         m_configWidget = new QWidget; | 
					
						
							|  |  |  |         QGridLayout * const gridLayout = new QGridLayout(m_configWidget); | 
					
						
							|  |  |  |         gridLayout->setMargin(0); | 
					
						
							|  |  |  |         m_configWidget->setLayout(gridLayout); | 
					
						
							|  |  |  |         // 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(); | 
					
						
							|  |  |  | } |