Skip to content
Snippets Groups Projects
Commit b8b8f167 authored by Daniel Teske's avatar Daniel Teske Committed by Eike Ziller
Browse files

Add "Find in directory" to project tree context menu

And also to the filesystem view.

Task-Nr: QTCREATORBUG-5879
Change-Id: I27bfe05808182f56deafd6ceab474894631f0a26
Reviewed-on: http://codereview.qt.nokia.com/4185


Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent b09f527f
No related branches found
No related tags found
No related merge requests found
...@@ -186,6 +186,16 @@ void FindPlugin::openFindFilter() ...@@ -186,6 +186,16 @@ void FindPlugin::openFindFilter()
d->m_findDialog->open(filter); 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() void FindPlugin::setupMenu()
{ {
Core::ActionManager *am = Core::ICore::instance()->actionManager(); Core::ActionManager *am = Core::ICore::instance()->actionManager();
......
...@@ -79,6 +79,7 @@ public: ...@@ -79,6 +79,7 @@ public:
QStringListModel *replaceCompletionModel() const; QStringListModel *replaceCompletionModel() const;
void setUseFakeVim(bool on); void setUseFakeVim(bool on);
void openFindToolBar(FindDirection direction); void openFindToolBar(FindDirection direction);
void openFindDialog(IFindFilter *filter);
public slots: public slots:
void setCaseSensitive(bool sensitive); void setCaseSensitive(bool sensitive);
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include "projectexplorer.h" #include "projectexplorer.h"
#include "projectexplorerconstants.h" #include "projectexplorerconstants.h"
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/fileiconprovider.h> #include <coreplugin/fileiconprovider.h>
#include <coreplugin/filemanager.h> #include <coreplugin/filemanager.h>
...@@ -41,6 +43,10 @@ ...@@ -41,6 +43,10 @@
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/fileutils.h> #include <coreplugin/fileutils.h>
#include <find/findplugin.h>
#include <texteditor/findinfiles.h>
#include <utils/environment.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
...@@ -312,6 +318,8 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) ...@@ -312,6 +318,8 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
QAction *actionTerminal = menu.addAction(Core::FileUtils::msgTerminalAction()); QAction *actionTerminal = menu.addAction(Core::FileUtils::msgTerminalAction());
actionTerminal->setEnabled(hasCurrentItem); actionTerminal->setEnabled(hasCurrentItem);
QAction *actionFind = menu.addAction(msgFindOnFileSystem());
actionFind->setEnabled(hasCurrentItem);
// open with... // open with...
if (!m_fileSystemModel->isDir(current)) { if (!m_fileSystemModel->isDir(current)) {
QMenu *openWith = menu.addMenu(tr("Open with")); QMenu *openWith = menu.addMenu(tr("Open with"));
...@@ -345,10 +353,38 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) ...@@ -345,10 +353,38 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
Core::FileUtils::showInGraphicalShell(this, m_fileSystemModel->filePath(current)); Core::FileUtils::showInGraphicalShell(this, m_fileSystemModel->filePath(current));
return; 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, ProjectExplorerPlugin::openEditorFromAction(action,
m_fileSystemModel->filePath(current)); 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::FolderNavigationWidgetFactory() FolderNavigationWidgetFactory::FolderNavigationWidgetFactory()
{ {
......
...@@ -64,6 +64,8 @@ public: ...@@ -64,6 +64,8 @@ public:
bool autoSynchronization() const; bool autoSynchronization() const;
static void findOnFileSystem(const QString &pathIn);
static QString msgFindOnFileSystem();
public slots: public slots:
void setAutoSynchronization(bool sync); void setAutoSynchronization(bool sync);
void toggleAutoSynchronization(); void toggleAutoSynchronization();
......
...@@ -206,6 +206,7 @@ struct ProjectExplorerPluginPrivate { ...@@ -206,6 +206,7 @@ struct ProjectExplorerPluginPrivate {
QAction *m_renameFileAction; QAction *m_renameFileAction;
QAction *m_openFileAction; QAction *m_openFileAction;
QAction *m_projectTreeCollapseAllAction; QAction *m_projectTreeCollapseAllAction;
QAction *m_searchOnFileSystem;
QAction *m_showInGraphicalShell; QAction *m_showInGraphicalShell;
QAction *m_openTerminalHere; QAction *m_openTerminalHere;
QAction *m_setStartupProjectAction; QAction *m_setStartupProjectAction;
...@@ -585,6 +586,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er ...@@ -585,6 +586,12 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
projecTreeContext); projecTreeContext);
mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN); 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); d->m_showInGraphicalShell = new QAction(Core::FileUtils::msgGraphicalShellAction(), this);
cmd = am->registerAction(d->m_showInGraphicalShell, ProjectExplorer::Constants::SHOWINGRAPHICALSHELL, cmd = am->registerAction(d->m_showInGraphicalShell, ProjectExplorer::Constants::SHOWINGRAPHICALSHELL,
projecTreeContext); projecTreeContext);
...@@ -959,6 +966,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er ...@@ -959,6 +966,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
connect(d->m_addNewSubprojectAction, SIGNAL(triggered()), this, SLOT(addNewSubproject())); connect(d->m_addNewSubprojectAction, SIGNAL(triggered()), this, SLOT(addNewSubproject()));
connect(d->m_removeProjectAction, SIGNAL(triggered()), this, SLOT(removeProject())); connect(d->m_removeProjectAction, SIGNAL(triggered()), this, SLOT(removeProject()));
connect(d->m_openFileAction, SIGNAL(triggered()), this, SLOT(openFile())); 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_showInGraphicalShell, SIGNAL(triggered()), this, SLOT(showInGraphicalShell()));
connect(d->m_openTerminalHere, SIGNAL(triggered()), this, SLOT(openTerminalHere())); connect(d->m_openTerminalHere, SIGNAL(triggered()), this, SLOT(openTerminalHere()));
connect(d->m_removeFileAction, SIGNAL(triggered()), this, SLOT(removeFile())); connect(d->m_removeFileAction, SIGNAL(triggered()), this, SLOT(removeFile()));
...@@ -2523,6 +2531,12 @@ void ProjectExplorerPlugin::openFile() ...@@ -2523,6 +2531,12 @@ void ProjectExplorerPlugin::openFile()
em->openEditor(d->m_currentNode->path(), QString(), Core::EditorManager::ModeSwitch); 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() void ProjectExplorerPlugin::showInGraphicalShell()
{ {
QTC_ASSERT(d->m_currentNode, return) QTC_ASSERT(d->m_currentNode, return)
......
...@@ -188,6 +188,7 @@ private slots: ...@@ -188,6 +188,7 @@ private slots:
void addNewSubproject(); void addNewSubproject();
void removeProject(); void removeProject();
void openFile(); void openFile();
void searchOnFileSystem();
void showInGraphicalShell(); void showInGraphicalShell();
void removeFile(); void removeFile();
void deleteFile(); void deleteFile();
......
...@@ -74,6 +74,7 @@ const char * const ADDEXISTINGFILES = "ProjectExplorer.AddExistingFiles"; ...@@ -74,6 +74,7 @@ const char * const ADDEXISTINGFILES = "ProjectExplorer.AddExistingFiles";
const char * const ADDNEWSUBPROJECT = "ProjectExplorer.AddNewSubproject"; const char * const ADDNEWSUBPROJECT = "ProjectExplorer.AddNewSubproject";
const char * const REMOVEPROJECT = "ProjectExplorer.RemoveProject"; const char * const REMOVEPROJECT = "ProjectExplorer.RemoveProject";
const char * const OPENFILE = "ProjectExplorer.OpenFile"; const char * const OPENFILE = "ProjectExplorer.OpenFile";
const char * const SEARCHONFILESYSTEM = "ProjectExplorer.SearchOnFileSystem";
const char * const SHOWINGRAPHICALSHELL = "ProjectExplorer.ShowInGraphicalShell"; const char * const SHOWINGRAPHICALSHELL = "ProjectExplorer.ShowInGraphicalShell";
const char * const OPENTERMIANLHERE = "ProjectExplorer.OpenTerminalHere"; const char * const OPENTERMIANLHERE = "ProjectExplorer.OpenTerminalHere";
const char * const REMOVEFILE = "ProjectExplorer.RemoveFile"; const char * const REMOVEFILE = "ProjectExplorer.RemoveFile";
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
using namespace Find; using namespace Find;
using namespace TextEditor::Internal; using namespace TextEditor;
FindInFiles::FindInFiles(SearchResultWindow *resultWindow) FindInFiles::FindInFiles(SearchResultWindow *resultWindow)
: BaseFileFind(resultWindow), : BaseFileFind(resultWindow),
...@@ -145,3 +145,9 @@ void FindInFiles::readSettings(QSettings *settings) ...@@ -145,3 +145,9 @@ void FindInFiles::readSettings(QSettings *settings)
settings->endGroup(); settings->endGroup();
syncComboWithSettings(m_directory, m_directorySetting); syncComboWithSettings(m_directory, m_directorySetting);
} }
void FindInFiles::setDirectory(const QString &directory)
{
syncComboWithSettings(m_directory, directory);
}
...@@ -45,9 +45,8 @@ ...@@ -45,9 +45,8 @@
namespace TextEditor { namespace TextEditor {
namespace Internal {
class FindInFiles : public BaseFileFind class TEXTEDITOR_EXPORT FindInFiles : public BaseFileFind
{ {
Q_OBJECT Q_OBJECT
...@@ -61,6 +60,8 @@ public: ...@@ -61,6 +60,8 @@ public:
void writeSettings(QSettings *settings); void writeSettings(QSettings *settings);
void readSettings(QSettings *settings); void readSettings(QSettings *settings);
void setDirectory(const QString &directory);
protected: protected:
Utils::FileIterator *files() const; Utils::FileIterator *files() const;
...@@ -74,7 +75,6 @@ private: ...@@ -74,7 +75,6 @@ private:
QPointer<QComboBox> m_directory; QPointer<QComboBox> m_directory;
}; };
} // namespace Internal
} // namespace TextEditor } // namespace TextEditor
#endif // FINDINFILES_H #endif // FINDINFILES_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment