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
......@@ -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();
......
......@@ -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);
......
......@@ -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()
{
......
......@@ -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();
......
......@@ -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)
......
......@@ -188,6 +188,7 @@ private slots:
void addNewSubproject();
void removeProject();
void openFile();
void searchOnFileSystem();
void showInGraphicalShell();
void removeFile();
void deleteFile();
......
......@@ -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";
......
......@@ -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);
}
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment