forked from qt-creator/qt-creator
TextEditor: Use new setup pattern for the finders
The FindInFiles definition cannot go yet to the .cpp yet as there are some exported functions. Change-Id: I2d2f02ae80b560e3147f461fcbee0fa62b8085a3 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "findincurrentfile.h"
|
||||
|
||||
#include "basefilefind.h"
|
||||
#include "textdocument.h"
|
||||
#include "texteditortr.h"
|
||||
|
||||
@@ -11,10 +12,33 @@
|
||||
|
||||
#include <utils/qtcsettings.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace TextEditor::Internal {
|
||||
|
||||
class FindInCurrentFile final : public BaseFileFind
|
||||
{
|
||||
public:
|
||||
FindInCurrentFile();
|
||||
|
||||
private:
|
||||
QString id() const final;
|
||||
QString displayName() const final;
|
||||
bool isEnabled() const final;
|
||||
void writeSettings(Utils::QtcSettings *settings) final;
|
||||
void readSettings(Utils::QtcSettings *settings) final;
|
||||
|
||||
QString label() const final;
|
||||
QString toolTip() const final;
|
||||
|
||||
FileContainerProvider fileContainerProvider() const final;
|
||||
void handleFileChange(Core::IEditor *editor);
|
||||
|
||||
QPointer<Core::IDocument> m_currentDocument;
|
||||
};
|
||||
|
||||
FindInCurrentFile::FindInCurrentFile()
|
||||
{
|
||||
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
||||
@@ -87,4 +111,9 @@ void FindInCurrentFile::readSettings(QtcSettings *settings)
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
void setupFindInCurrentFile()
|
||||
{
|
||||
static FindInCurrentFile theFindInCurrentFile;
|
||||
}
|
||||
|
||||
} // TextEditor::Internal
|
||||
|
||||
@@ -3,41 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "basefilefind.h"
|
||||
namespace TextEditor::Internal {
|
||||
|
||||
#include <QPointer>
|
||||
void setupFindInCurrentFile();
|
||||
|
||||
namespace Core {
|
||||
class IEditor;
|
||||
class IDocument;
|
||||
} // namespace Core
|
||||
|
||||
namespace TextEditor {
|
||||
namespace Internal {
|
||||
|
||||
class FindInCurrentFile final : public BaseFileFind
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FindInCurrentFile();
|
||||
|
||||
QString id() const override;
|
||||
QString displayName() const override;
|
||||
bool isEnabled() const override;
|
||||
void writeSettings(Utils::QtcSettings *settings) override;
|
||||
void readSettings(Utils::QtcSettings *settings) override;
|
||||
|
||||
protected:
|
||||
QString label() const override;
|
||||
QString toolTip() const override;
|
||||
|
||||
private:
|
||||
FileContainerProvider fileContainerProvider() const override;
|
||||
void handleFileChange(Core::IEditor *editor);
|
||||
|
||||
QPointer<Core::IDocument> m_currentDocument;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace TextEditor
|
||||
} // TextEditor::Internal
|
||||
|
||||
@@ -23,12 +23,10 @@ using namespace Utils;
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
static FindInFiles *m_instance = nullptr;
|
||||
static const char HistoryKey[] = "FindInFiles.Directories.History";
|
||||
|
||||
FindInFiles::FindInFiles()
|
||||
{
|
||||
m_instance = this;
|
||||
connect(EditorManager::instance(), &EditorManager::findOnFileSystemRequest,
|
||||
this, &FindInFiles::findOnFileSystem);
|
||||
}
|
||||
@@ -209,18 +207,30 @@ void FindInFiles::setBaseDirectory(const FilePath &directory)
|
||||
m_directory->setBaseDirectory(directory);
|
||||
}
|
||||
|
||||
static FindInFiles *s_instance;
|
||||
|
||||
FindInFiles &findInFiles()
|
||||
{
|
||||
return *s_instance;
|
||||
}
|
||||
|
||||
void FindInFiles::findOnFileSystem(const QString &path)
|
||||
{
|
||||
QTC_ASSERT(m_instance, return);
|
||||
const QFileInfo fi(path);
|
||||
const QString folder = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath();
|
||||
m_instance->setSearchDir(FilePath::fromString(folder));
|
||||
Find::openFindDialog(m_instance);
|
||||
findInFiles().setSearchDir(FilePath::fromString(folder));
|
||||
Find::openFindDialog(&findInFiles());
|
||||
}
|
||||
|
||||
FindInFiles *FindInFiles::instance()
|
||||
{
|
||||
return m_instance;
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void Internal::setupFindInFiles(QObject *guard)
|
||||
{
|
||||
s_instance = new FindInFiles;
|
||||
s_instance->setParent(guard);
|
||||
}
|
||||
|
||||
} // TextEditor
|
||||
|
||||
@@ -58,4 +58,6 @@ private:
|
||||
bool m_isValid = false;
|
||||
};
|
||||
|
||||
namespace Internal { void setupFindInFiles(QObject *guard); }
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "findinopenfiles.h"
|
||||
|
||||
#include "basefilefind.h"
|
||||
#include "textdocument.h"
|
||||
#include "texteditortr.h"
|
||||
|
||||
@@ -15,6 +16,25 @@ using namespace Utils;
|
||||
|
||||
namespace TextEditor::Internal {
|
||||
|
||||
class FindInOpenFiles : public BaseFileFind
|
||||
{
|
||||
public:
|
||||
FindInOpenFiles();
|
||||
|
||||
private:
|
||||
QString id() const final;
|
||||
QString displayName() const final;
|
||||
bool isEnabled() const final;
|
||||
void writeSettings(Utils::QtcSettings *settings) final;
|
||||
void readSettings(Utils::QtcSettings *settings) final;
|
||||
|
||||
QString label() const final;
|
||||
QString toolTip() const final;
|
||||
|
||||
FileContainerProvider fileContainerProvider() const final;
|
||||
void updateEnabledState() { emit enabledChanged(isEnabled()); }
|
||||
};
|
||||
|
||||
FindInOpenFiles::FindInOpenFiles()
|
||||
{
|
||||
connect(Core::EditorManager::instance(), &Core::EditorManager::editorOpened,
|
||||
@@ -84,9 +104,11 @@ void FindInOpenFiles::readSettings(QtcSettings *settings)
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
void FindInOpenFiles::updateEnabledState()
|
||||
|
||||
|
||||
void setupFindInOpenFiles()
|
||||
{
|
||||
emit enabledChanged(isEnabled());
|
||||
static FindInOpenFiles theFindInOpenFiles;
|
||||
}
|
||||
|
||||
} // TextEditor::Internal
|
||||
|
||||
@@ -3,32 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "basefilefind.h"
|
||||
namespace TextEditor::Internal {
|
||||
|
||||
namespace TextEditor {
|
||||
namespace Internal {
|
||||
void setupFindInOpenFiles();
|
||||
|
||||
class FindInOpenFiles : public BaseFileFind
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FindInOpenFiles();
|
||||
|
||||
QString id() const override;
|
||||
QString displayName() const override;
|
||||
bool isEnabled() const override;
|
||||
void writeSettings(Utils::QtcSettings *settings) override;
|
||||
void readSettings(Utils::QtcSettings *settings) override;
|
||||
|
||||
protected:
|
||||
QString label() const override;
|
||||
QString toolTip() const override;
|
||||
|
||||
private:
|
||||
FileContainerProvider fileContainerProvider() const override;
|
||||
void updateEnabledState();
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace TextEditor
|
||||
} // TextEditor::Internal
|
||||
|
||||
@@ -67,10 +67,6 @@ const char kCurrentDocumentWordUnderCursor[] = "CurrentDocument:WordUnderCursor"
|
||||
class TextEditorPluginPrivate : public QObject
|
||||
{
|
||||
public:
|
||||
FindInFiles findInFilesFilter;
|
||||
FindInCurrentFile findInCurrentFileFilter;
|
||||
FindInOpenFiles findInOpenFilesFilter;
|
||||
|
||||
MarkdownEditorFactory markdownEditorFactory;
|
||||
JsonEditorFactory jsonEditorFactory;
|
||||
};
|
||||
@@ -122,6 +118,10 @@ void TextEditorPlugin::initialize()
|
||||
setupBookmarkView();
|
||||
setupBookmarkFilter();
|
||||
|
||||
setupFindInFiles(this);
|
||||
setupFindInCurrentFile();
|
||||
setupFindInOpenFiles();
|
||||
|
||||
d = new TextEditorPluginPrivate;
|
||||
|
||||
Context context(TextEditor::Constants::C_TEXTEDITOR);
|
||||
|
||||
Reference in New Issue
Block a user