diff --git a/src/plugins/find/findplugin.cpp b/src/plugins/find/findplugin.cpp index 4ebd37fcb47cef8c8e6e73048e06bbb2353e6f15..6ed68e9bf5e75b743bc788e34a4bd5a6e76b462b 100644 --- a/src/plugins/find/findplugin.cpp +++ b/src/plugins/find/findplugin.cpp @@ -186,6 +186,16 @@ void FindPlugin::openFindFilter() d->m_findDialog->open(filter); } +void FindPlugin::openFindDialog(IFindFilter *filter) +{ + if (d->m_currentDocumentFind->candidateIsEnabled()) + d->m_currentDocumentFind->acceptCandidate(); + QString currentFindString = (d->m_currentDocumentFind->isEnabled() ? d->m_currentDocumentFind->currentFindString() : ""); + if (!currentFindString.isEmpty()) + d->m_findDialog->setFindText(currentFindString); + d->m_findDialog->open(filter); +} + void FindPlugin::setupMenu() { Core::ActionManager *am = Core::ICore::instance()->actionManager(); diff --git a/src/plugins/find/findplugin.h b/src/plugins/find/findplugin.h index 4cc936a3d1046fd37affcfe075529c37e792c4e7..3834872ecb0dbcf270ad096d1b765bda996eed46 100644 --- a/src/plugins/find/findplugin.h +++ b/src/plugins/find/findplugin.h @@ -79,6 +79,7 @@ public: QStringListModel *replaceCompletionModel() const; void setUseFakeVim(bool on); void openFindToolBar(FindDirection direction); + void openFindDialog(IFindFilter *filter); public slots: void setCaseSensitive(bool sensitive); diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp index 374bf17a526aab889acfb4506e81cb66a1b06786..4e3d9bcc93f9bf1e7f899eba697e4de58acd972d 100644 --- a/src/plugins/projectexplorer/foldernavigationwidget.cpp +++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp @@ -34,6 +34,8 @@ #include "projectexplorer.h" #include "projectexplorerconstants.h" +#include <extensionsystem/pluginmanager.h> + #include <coreplugin/icore.h> #include <coreplugin/fileiconprovider.h> #include <coreplugin/filemanager.h> @@ -41,6 +43,10 @@ #include <coreplugin/coreconstants.h> #include <coreplugin/fileutils.h> +#include <find/findplugin.h> +#include <texteditor/findinfiles.h> + +#include <utils/environment.h> #include <utils/pathchooser.h> #include <utils/qtcassert.h> @@ -312,6 +318,8 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) QAction *actionTerminal = menu.addAction(Core::FileUtils::msgTerminalAction()); actionTerminal->setEnabled(hasCurrentItem); + QAction *actionFind = menu.addAction(msgFindOnFileSystem()); + actionFind->setEnabled(hasCurrentItem); // open with... if (!m_fileSystemModel->isDir(current)) { QMenu *openWith = menu.addMenu(tr("Open with")); @@ -345,10 +353,38 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) Core::FileUtils::showInGraphicalShell(this, m_fileSystemModel->filePath(current)); return; } + if (action == actionFind) { + QFileInfo info = m_fileSystemModel->fileInfo(current); + if (m_fileSystemModel->isDir(current)) + findOnFileSystem(info.absoluteFilePath()); + else + findOnFileSystem(info.absolutePath()); + return; + } ProjectExplorerPlugin::openEditorFromAction(action, m_fileSystemModel->filePath(current)); } +QString FolderNavigationWidget::msgFindOnFileSystem() +{ + return tr("Find in this directory..."); +} + +void FolderNavigationWidget::findOnFileSystem(const QString &pathIn) +{ + const QFileInfo fileInfo(pathIn); + const QString folder = fileInfo.isDir() ? fileInfo.absoluteFilePath() : fileInfo.absolutePath(); + + TextEditor::FindInFiles *fif = ExtensionSystem::PluginManager::instance()->getObject<TextEditor::FindInFiles>(); + if (!fif) + return; + Find::FindPlugin *plugin = Find::FindPlugin::instance(); + if (!plugin) + return; + fif->setDirectory(folder); + Find::FindPlugin::instance()->openFindDialog(fif); +} + // --------------------FolderNavigationWidgetFactory FolderNavigationWidgetFactory::FolderNavigationWidgetFactory() { diff --git a/src/plugins/projectexplorer/foldernavigationwidget.h b/src/plugins/projectexplorer/foldernavigationwidget.h index 07c956686f73a1912be2dbf6d4d3c6dd1f2089c0..279e6923319e0522d592b5e5fc5cbede41102f7e 100644 --- a/src/plugins/projectexplorer/foldernavigationwidget.h +++ b/src/plugins/projectexplorer/foldernavigationwidget.h @@ -64,6 +64,8 @@ public: bool autoSynchronization() const; + static void findOnFileSystem(const QString &pathIn); + static QString msgFindOnFileSystem(); public slots: void setAutoSynchronization(bool sync); void toggleAutoSynchronization(); diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 864bbccbe44b593e866fd76dd7f8637ca042f78d..f779b98d1c5951cde9c3684d60fe3339ca7d4bb4 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -206,6 +206,7 @@ struct ProjectExplorerPluginPrivate { QAction *m_renameFileAction; QAction *m_openFileAction; QAction *m_projectTreeCollapseAllAction; + QAction *m_searchOnFileSystem; QAction *m_showInGraphicalShell; QAction *m_openTerminalHere; QAction *m_setStartupProjectAction; @@ -585,6 +586,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er projecTreeContext); mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN); + d->m_searchOnFileSystem = new QAction(FolderNavigationWidget::msgFindOnFileSystem(), this); + cmd = am->registerAction(d->m_searchOnFileSystem, ProjectExplorer::Constants::SEARCHONFILESYSTEM, projecTreeContext); + mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_CONFIG); + msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST); + mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST); + d->m_showInGraphicalShell = new QAction(Core::FileUtils::msgGraphicalShellAction(), this); cmd = am->registerAction(d->m_showInGraphicalShell, ProjectExplorer::Constants::SHOWINGRAPHICALSHELL, projecTreeContext); @@ -959,6 +966,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er connect(d->m_addNewSubprojectAction, SIGNAL(triggered()), this, SLOT(addNewSubproject())); connect(d->m_removeProjectAction, SIGNAL(triggered()), this, SLOT(removeProject())); connect(d->m_openFileAction, SIGNAL(triggered()), this, SLOT(openFile())); + connect(d->m_searchOnFileSystem, SIGNAL(triggered()), this, SLOT(searchOnFileSystem())); connect(d->m_showInGraphicalShell, SIGNAL(triggered()), this, SLOT(showInGraphicalShell())); connect(d->m_openTerminalHere, SIGNAL(triggered()), this, SLOT(openTerminalHere())); connect(d->m_removeFileAction, SIGNAL(triggered()), this, SLOT(removeFile())); @@ -2523,6 +2531,12 @@ void ProjectExplorerPlugin::openFile() em->openEditor(d->m_currentNode->path(), QString(), Core::EditorManager::ModeSwitch); } +void ProjectExplorerPlugin::searchOnFileSystem() +{ + QTC_ASSERT(d->m_currentNode, return) + FolderNavigationWidget::findOnFileSystem(pathFor(d->m_currentNode)); +} + void ProjectExplorerPlugin::showInGraphicalShell() { QTC_ASSERT(d->m_currentNode, return) diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index 06044ca197cf760360706685b52b213ab2ee2a1f..d10958936b9f0dc0d6233c41ee84b17292249c7b 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -188,6 +188,7 @@ private slots: void addNewSubproject(); void removeProject(); void openFile(); + void searchOnFileSystem(); void showInGraphicalShell(); void removeFile(); void deleteFile(); diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h index 1273aea719ba883c66047c7c93c77e43ca842a4b..7dc512c84e09b5847773937069c4e43e07ee1590 100644 --- a/src/plugins/projectexplorer/projectexplorerconstants.h +++ b/src/plugins/projectexplorer/projectexplorerconstants.h @@ -74,6 +74,7 @@ const char * const ADDEXISTINGFILES = "ProjectExplorer.AddExistingFiles"; const char * const ADDNEWSUBPROJECT = "ProjectExplorer.AddNewSubproject"; const char * const REMOVEPROJECT = "ProjectExplorer.RemoveProject"; const char * const OPENFILE = "ProjectExplorer.OpenFile"; +const char * const SEARCHONFILESYSTEM = "ProjectExplorer.SearchOnFileSystem"; const char * const SHOWINGRAPHICALSHELL = "ProjectExplorer.ShowInGraphicalShell"; const char * const OPENTERMIANLHERE = "ProjectExplorer.OpenTerminalHere"; const char * const REMOVEFILE = "ProjectExplorer.RemoveFile"; diff --git a/src/plugins/texteditor/findinfiles.cpp b/src/plugins/texteditor/findinfiles.cpp index 1aa3d70dc036b030e02d351f683d03d107ffde5c..bb258ee4e7b65fbba188dc4d95074254ed2b22ec 100644 --- a/src/plugins/texteditor/findinfiles.cpp +++ b/src/plugins/texteditor/findinfiles.cpp @@ -43,7 +43,7 @@ #include <QtGui/QVBoxLayout> using namespace Find; -using namespace TextEditor::Internal; +using namespace TextEditor; FindInFiles::FindInFiles(SearchResultWindow *resultWindow) : BaseFileFind(resultWindow), @@ -145,3 +145,9 @@ void FindInFiles::readSettings(QSettings *settings) settings->endGroup(); syncComboWithSettings(m_directory, m_directorySetting); } + +void FindInFiles::setDirectory(const QString &directory) +{ + syncComboWithSettings(m_directory, directory); +} + diff --git a/src/plugins/texteditor/findinfiles.h b/src/plugins/texteditor/findinfiles.h index 4b6970bd1400c68fcdf1b424e32818b15a354916..7cf15e5cedb25c5f3f929df049f5c2243016a4d2 100644 --- a/src/plugins/texteditor/findinfiles.h +++ b/src/plugins/texteditor/findinfiles.h @@ -45,9 +45,8 @@ namespace TextEditor { -namespace Internal { -class FindInFiles : public BaseFileFind +class TEXTEDITOR_EXPORT FindInFiles : public BaseFileFind { Q_OBJECT @@ -61,6 +60,8 @@ public: void writeSettings(QSettings *settings); void readSettings(QSettings *settings); + void setDirectory(const QString &directory); + protected: Utils::FileIterator *files() const; @@ -74,7 +75,6 @@ private: QPointer<QComboBox> m_directory; }; -} // namespace Internal } // namespace TextEditor #endif // FINDINFILES_H