QtSupport: Remove {Designer,Linguist}ExternalEditorFactory classes

... again, use the editors themselves, which are singletons.

Change-Id: I8ec7bce58414a23169831956c00bbdd73c6bfec3
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2023-01-26 11:24:06 +01:00
parent 66e932d284
commit bc6fc26951
3 changed files with 33 additions and 60 deletions

View File

@@ -3,8 +3,6 @@
#include "externaleditors.h"
#include <coreplugin/editormanager/iexternaleditor.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
@@ -37,14 +35,10 @@ enum { debug = 0 };
namespace QtSupport::Internal {
struct Tr
{
struct Tr {
Q_DECLARE_TR_FUNCTIONS(::QmakeProjectManager)
};
const char designerDisplayName[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "Qt Designer");
const char linguistDisplayName[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "Qt Linguist");
static QString msgStartFailed(const QString &binary, QStringList arguments)
{
arguments.push_front(binary);
@@ -160,28 +154,12 @@ static bool startEditorProcess(const LaunchData &data, QString *errorMessage)
// DesignerExternalEditor with Designer Tcp remote control.
class DesignerExternalEditor : public Core::IExternalEditor
{
public:
DesignerExternalEditor()
{
setId("Qt.Designer");
setDisplayName(designerDisplayName);
setMimeTypes({ProjectExplorer::Constants::FORM_MIMETYPE});
}
// A per-binary entry containing the socket
using ProcessCache = QMap<QString, QTcpSocket*>;
bool startEditor(const FilePath &filePath, QString *errorMessage) override;
static ProcessCache m_processCache;
private:
void processTerminated(const QString &binary);
// A per-binary entry containing the socket
using ProcessCache = QMap<QString, QTcpSocket*>;
ProcessCache m_processCache;
};
void DesignerExternalEditor::processTerminated(const QString &binary)
static void processTerminated(const QString &binary)
{
const ProcessCache::iterator it = m_processCache.find(binary);
if (it == m_processCache.end())
@@ -196,6 +174,13 @@ void DesignerExternalEditor::processTerminated(const QString &binary)
socket->deleteLater();
}
DesignerExternalEditor::DesignerExternalEditor()
{
setId("Qt.Designer");
setDisplayName(QT_TRANSLATE_NOOP("OpenWith::Editors", "Qt Designer"));
setMimeTypes({ProjectExplorer::Constants::FORM_MIMETYPE});
}
bool DesignerExternalEditor::startEditor(const FilePath &filePath, QString *errorMessage)
{
LaunchData data;
@@ -246,19 +231,13 @@ bool DesignerExternalEditor::startEditor(const FilePath &filePath, QString *erro
socket->setParent(this);
const QString binary = data.binary;
m_processCache.insert(binary, socket);
auto mapSlot = [this, binary] { processTerminated(binary); };
auto mapSlot = [binary] { processTerminated(binary); };
connect(socket, &QAbstractSocket::disconnected, this, mapSlot);
connect(socket, &QAbstractSocket::errorOccurred, this, mapSlot);
}
return true;
}
DesignerEditorFactory::DesignerEditorFactory()
{
auto editor = new DesignerExternalEditor;
editor->setParent(this);
}
// Linguist
static QString linguistBinary(const QtSupport::QtVersion *qtVersion)
@@ -268,28 +247,18 @@ static QString linguistBinary(const QtSupport::QtVersion *qtVersion)
return QLatin1String(HostOsInfo::isMacHost() ? "Linguist" : "linguist");
}
class LinguistEditor : public Core::IExternalEditor
LinguistEditor::LinguistEditor()
{
public:
LinguistEditor()
{
setId("Qt.Linguist");
setDisplayName(linguistDisplayName);
setMimeTypes({ProjectExplorer::Constants::LINGUIST_MIMETYPE});
}
setId("Qt.Linguist");
setDisplayName(QT_TRANSLATE_NOOP("OpenWith::Editors", "Qt Linguist"));
setMimeTypes({ProjectExplorer::Constants::LINGUIST_MIMETYPE});
}
bool startEditor(const FilePath &filePath, QString *errorMessage) override
{
LaunchData data;
return getEditorLaunchData(linguistBinary, filePath, &data, errorMessage)
&& startEditorProcess(data, errorMessage);
}
};
LinguistEditorFactory::LinguistEditorFactory()
bool LinguistEditor::startEditor(const Utils::FilePath &filePath, QString *errorMessage)
{
auto editor = new LinguistEditor;
editor->setParent(this);
LaunchData data;
return getEditorLaunchData(linguistBinary, filePath, &data, errorMessage)
&& startEditorProcess(data, errorMessage);
}
} // QtSupport::Internal

View File

@@ -3,20 +3,24 @@
#pragma once
#include <QObject>
#include <coreplugin/editormanager/iexternaleditor.h>
namespace QtSupport::Internal {
class DesignerEditorFactory : public QObject
class DesignerExternalEditor : public Core::IExternalEditor
{
public:
DesignerEditorFactory();
DesignerExternalEditor();
bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) final;
};
class LinguistEditorFactory : public QObject
class LinguistEditor : public Core::IExternalEditor
{
public:
LinguistEditorFactory();
LinguistEditor();
bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) final;
};
} // QtSupport::Internal

View File

@@ -63,8 +63,8 @@ public:
UicGeneratorFactory uicGeneratorFactory;
QScxmlcGeneratorFactory qscxmlcGeneratorFactory;
DesignerEditorFactory designerEditorFactory;
LinguistEditorFactory linguistEditorFactory;
DesignerExternalEditor designerEditor;
LinguistEditor linguistEditor;
};
QtSupportPlugin::~QtSupportPlugin()