OSDN Git Service

Add "Find in directory" to project tree context menu
authorDaniel Teske <daniel.teske@nokia.com>
Mon, 5 Sep 2011 08:19:49 +0000 (10:19 +0200)
committerEike Ziller <eike.ziller@nokia.com>
Mon, 5 Sep 2011 12:37:10 +0000 (14:37 +0200)
And also to the filesystem view.

Task-Nr: QTCREATORBUG-5879
Change-Id: I27bfe05808182f56deafd6ceab474894631f0a26
Reviewed-on: http://codereview.qt.nokia.com/4185
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
src/plugins/find/findplugin.cpp
src/plugins/find/findplugin.h
src/plugins/projectexplorer/foldernavigationwidget.cpp
src/plugins/projectexplorer/foldernavigationwidget.h
src/plugins/projectexplorer/projectexplorer.cpp
src/plugins/projectexplorer/projectexplorer.h
src/plugins/projectexplorer/projectexplorerconstants.h
src/plugins/texteditor/findinfiles.cpp
src/plugins/texteditor/findinfiles.h

index 4ebd37f..6ed68e9 100644 (file)
@@ -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();
index 4cc936a..3834872 100644 (file)
@@ -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);
index 374bf17..4e3d9bc 100644 (file)
@@ -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>
 #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()
 {
index 07c9566..279e692 100644 (file)
@@ -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();
index 864bbcc..f779b98 100644 (file)
@@ -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)
index 06044ca..d109589 100644 (file)
@@ -188,6 +188,7 @@ private slots:
     void addNewSubproject();
     void removeProject();
     void openFile();
+    void searchOnFileSystem();
     void showInGraphicalShell();
     void removeFile();
     void deleteFile();
index 1273aea..7dc512c 100644 (file)
@@ -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";
index 1aa3d70..bb258ee 100644 (file)
@@ -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);
+}
+
index 4b6970b..7cf15e5 100644 (file)
@@ -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