QtSupport: Use setup functions for linguist and designer factories

Change-Id: I5083544dd7e8e16e8b5ed349d23fdcfc0d022330
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-01-18 13:14:00 +01:00
parent 5772a85751
commit 670116f2c3
3 changed files with 84 additions and 79 deletions

View File

@@ -4,6 +4,7 @@
#include "externaleditors.h" #include "externaleditors.h"
#include <coreplugin/coreplugintr.h> #include <coreplugin/coreplugintr.h>
#include <coreplugin/editormanager/ieditorfactory.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
@@ -234,7 +235,7 @@ static bool startEditorProcess(const LaunchData &data, QString *errorMessage)
return true; return true;
} }
// DesignerExternalEditor with Designer Tcp remote control. // ExternalDesignerEditorFactory with Designer Tcp remote control.
// A per-binary entry containing the socket // A per-binary entry containing the socket
using ProcessCache = QMap<QString, QTcpSocket*>; using ProcessCache = QMap<QString, QTcpSocket*>;
@@ -256,13 +257,16 @@ static void processTerminated(const QString &binary)
socket->deleteLater(); socket->deleteLater();
} }
DesignerExternalEditor::DesignerExternalEditor() class ExternalDesignerFactory final : public Core::IEditorFactory
{ {
public:
explicit ExternalDesignerFactory(QObject *guard)
{
setId("Qt.Designer"); setId("Qt.Designer");
setDisplayName(::Core::Tr::tr("Qt Designer")); setDisplayName(::Core::Tr::tr("Qt Designer"));
setMimeTypes({Utils::Constants::FORM_MIMETYPE}); setMimeTypes({Utils::Constants::FORM_MIMETYPE});
setEditorStarter([this](const FilePath &filePath, QString *errorMessage) { setEditorStarter([guard](const FilePath &filePath, QString *errorMessage) {
LaunchData data; LaunchData data;
// Find the editor binary // Find the editor binary
@@ -308,15 +312,21 @@ DesignerExternalEditor::DesignerExternalEditor()
// Insert into cache if socket is created, else try again next time // Insert into cache if socket is created, else try again next time
if (server.waitForNewConnection(3000)) { if (server.waitForNewConnection(3000)) {
QTcpSocket *socket = server.nextPendingConnection(); QTcpSocket *socket = server.nextPendingConnection();
socket->setParent(&m_guard); socket->setParent(guard);
const QString binary = data.binary; const QString binary = data.binary;
m_processCache.insert(binary, socket); m_processCache.insert(binary, socket);
auto mapSlot = [binary] { processTerminated(binary); }; auto mapSlot = [binary] { processTerminated(binary); };
QObject::connect(socket, &QAbstractSocket::disconnected, &m_guard, mapSlot); QObject::connect(socket, &QAbstractSocket::disconnected, guard, mapSlot);
QObject::connect(socket, &QAbstractSocket::errorOccurred, &m_guard, mapSlot); QObject::connect(socket, &QAbstractSocket::errorOccurred, guard, mapSlot);
} }
return true; return true;
}); });
}
};
void setupExternalDesigner(QObject *guard)
{
static ExternalDesignerFactory theExternalDesignerFactory(guard);
} }
// Linguist // Linguist
@@ -328,8 +338,11 @@ static QString linguistBinary(const QtSupport::QtVersion *qtVersion)
return QLatin1String(HostOsInfo::isMacHost() ? "Linguist" : "linguist"); return QLatin1String(HostOsInfo::isMacHost() ? "Linguist" : "linguist");
} }
LinguistEditor::LinguistEditor() class ExternalLinguistFactory : public Core::IEditorFactory
{ {
public:
ExternalLinguistFactory()
{
setId("Qt.Linguist"); setId("Qt.Linguist");
setDisplayName(::Core::Tr::tr("Qt Linguist")); setDisplayName(::Core::Tr::tr("Qt Linguist"));
setMimeTypes({Utils::Constants::LINGUIST_MIMETYPE}); setMimeTypes({Utils::Constants::LINGUIST_MIMETYPE});
@@ -338,6 +351,12 @@ LinguistEditor::LinguistEditor()
return getEditorLaunchData(linguistBinary, filePath, &data, errorMessage) return getEditorLaunchData(linguistBinary, filePath, &data, errorMessage)
&& startEditorProcess(data, errorMessage); && startEditorProcess(data, errorMessage);
}); });
}
};
void setupExternalLinguist()
{
static ExternalLinguistFactory theExternalDesignerFactory;
} }
} // QtSupport::Internal } // QtSupport::Internal

View File

@@ -3,25 +3,11 @@
#pragma once #pragma once
#include <coreplugin/editormanager/ieditorfactory.h>
#include <QObject> #include <QObject>
namespace QtSupport::Internal { namespace QtSupport::Internal {
class DesignerExternalEditor : public Core::IEditorFactory void setupExternalDesigner(QObject *guard);
{ void setupExternalLinguist();
public:
DesignerExternalEditor();
private:
QObject m_guard;
};
class LinguistEditor : public Core::IEditorFactory
{
public:
LinguistEditor();
};
} // QtSupport::Internal } // QtSupport::Internal

View File

@@ -48,9 +48,6 @@ namespace QtSupport::Internal {
class QtSupportPluginPrivate class QtSupportPluginPrivate
{ {
public: public:
DesignerExternalEditor designerEditor;
LinguistEditor linguistEditor;
TranslationWizardPageFactory translationWizardPageFactory; TranslationWizardPageFactory translationWizardPageFactory;
}; };
@@ -109,6 +106,9 @@ void QtSupportPlugin::initialize()
setupUicGenerator(); setupUicGenerator();
setupQScxmlcGenerator(); setupQScxmlcGenerator();
setupExternalDesigner(this);
setupExternalLinguist();
theProcessRunner() = processRunnerCallback; theProcessRunner() = processRunnerCallback;
thePrompter() = [this](const QString &msg, const QStringList &context) -> std::optional<QString> { thePrompter() = [this](const QString &msg, const QStringList &context) -> std::optional<QString> {