Core: Merge iexternaleditor.{h,cpp} into ieditorfactory.{h,cpp}

Naming is still inconsistent, these should be all some kind of
factories, but now is at least the 'distance' to the base class
('EditorType') the same for both siblings.

Also remove unneeded #include

Change-Id: I73aa0cbc2aab14605fe6a1101d388b10a9108b63
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2023-08-18 11:52:20 +02:00
parent 8346905a51
commit fd0a1a1922
10 changed files with 78 additions and 118 deletions

View File

@@ -86,8 +86,6 @@ add_qtc_plugin(Core
editormanager/ieditorfactory.cpp
editormanager/ieditorfactory.h
editormanager/ieditorfactory_p.h
editormanager/iexternaleditor.cpp
editormanager/iexternaleditor.h
editormanager/openeditorsview.cpp
editormanager/openeditorsview.h
editormanager/openeditorswindow.cpp

View File

@@ -232,7 +232,6 @@ Project {
"editorwindow.cpp", "editorwindow.h",
"ieditor.cpp", "ieditor.h",
"ieditorfactory.cpp", "ieditorfactory.h", "ieditorfactory_p.h",
"iexternaleditor.cpp", "iexternaleditor.h",
"openeditorsview.cpp", "openeditorsview.h",
"openeditorswindow.cpp", "openeditorswindow.h",
"systemeditor.cpp", "systemeditor.h",

View File

@@ -21,7 +21,6 @@
#include <coreplugin/editormanager/editorview.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/editormanager/ieditorfactory.h>
#include <coreplugin/editormanager/iexternaleditor.h>
#include <coreplugin/systemsettings.h>
#include <extensionsystem/pluginmanager.h>

View File

@@ -9,6 +9,8 @@
#include "editorview.h"
#include "editorwindow.h"
#include "ieditor.h"
#include "ieditorfactory.h"
#include "ieditorfactory_p.h"
#include "openeditorsview.h"
#include "openeditorswindow.h"
#include "../actionmanager/actioncontainer.h"
@@ -20,9 +22,6 @@
#include "../dialogs/readonlyfilesdialog.h"
#include "../diffservice.h"
#include "../documentmanager.h"
#include "../editormanager/ieditorfactory.h"
#include "../editormanager/ieditorfactory_p.h"
#include "../editormanager/iexternaleditor.h"
#include "../fileutils.h"
#include "../findplaceholder.h"
#include "../icore.h"

View File

@@ -298,4 +298,59 @@ void Internal::setUserPreferredEditorTypes(const QHash<Utils::MimeType, EditorTy
g_userPreferredEditorTypes = factories;
}
/*!
\class Core::IExternalEditor
\inheaderfile coreplugin/editormanager/ieditorfactory.h
\inmodule QtCreator
\ingroup mainclasses
\brief The IExternalEditor class enables registering an external
editor in the \uicontrol{Open With} dialog.
*/
/*!
\fn bool Core::IExternalEditor::startEditor(const Utils::FilePath &fileName, QString *errorMessage)
Opens the editor with \a fileName. Returns \c true on success or \c false
on failure along with the error in \a errorMessage.
*/
static QList<IExternalEditor *> g_externalEditors;
/*!
\internal
*/
IExternalEditor::IExternalEditor()
{
g_externalEditors.append(this);
}
/*!
\internal
*/
IExternalEditor::~IExternalEditor()
{
g_externalEditors.removeOne(this);
}
/*!
Returns all available external editors.
*/
const ExternalEditorList IExternalEditor::allExternalEditors()
{
return g_externalEditors;
}
/*!
Returns all external editors available for this \a mimeType in the default
order (editors ordered by MIME type hierarchy).
*/
const ExternalEditorList IExternalEditor::externalEditors(const Utils::MimeType &mimeType)
{
ExternalEditorList rc;
const ExternalEditorList allEditors = IExternalEditor::allExternalEditors();
Internal::mimeTypeFactoryLookup(mimeType, allEditors, &rc);
return rc;
}
} // Core

View File

@@ -7,7 +7,6 @@
#include <utils/id.h>
#include <QObject>
#include <QStringList>
#include <functional>
@@ -26,6 +25,7 @@ class EditorType;
using EditorFactoryList = QList<IEditorFactory *>;
using EditorTypeList = QList<EditorType *>;
using ExternalEditorList = QList<IExternalEditor *>;
class CORE_EXPORT EditorType
{
@@ -77,4 +77,18 @@ private:
std::function<IEditor *()> m_creator;
};
class CORE_EXPORT IExternalEditor : public EditorType
{
public:
explicit IExternalEditor();
~IExternalEditor() override;
static const ExternalEditorList allExternalEditors();
static const ExternalEditorList externalEditors(const Utils::MimeType &mimeType);
IExternalEditor *asExternalEditor() override { return this; }
virtual bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) = 0;
};
} // namespace Core

View File

@@ -1,65 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "iexternaleditor.h"
#include "ieditorfactory_p.h"
namespace Core {
/*!
\class Core::IExternalEditor
\inheaderfile coreplugin/editormanager/iexternaleditor.h
\inmodule QtCreator
\ingroup mainclasses
\brief The IExternalEditor class enables registering an external
editor in the \uicontrol{Open With} dialog.
*/
/*!
\fn bool Core::IExternalEditor::startEditor(const Utils::FilePath &fileName, QString *errorMessage)
Opens the editor with \a fileName. Returns \c true on success or \c false
on failure along with the error in \a errorMessage.
*/
static QList<IExternalEditor *> g_externalEditors;
/*!
\internal
*/
IExternalEditor::IExternalEditor()
{
g_externalEditors.append(this);
}
/*!
\internal
*/
IExternalEditor::~IExternalEditor()
{
g_externalEditors.removeOne(this);
}
/*!
Returns all available external editors.
*/
const ExternalEditorList IExternalEditor::allExternalEditors()
{
return g_externalEditors;
}
/*!
Returns all external editors available for this \a mimeType in the default
order (editors ordered by MIME type hierarchy).
*/
const ExternalEditorList IExternalEditor::externalEditors(const Utils::MimeType &mimeType)
{
ExternalEditorList rc;
const ExternalEditorList allEditors = IExternalEditor::allExternalEditors();
Internal::mimeTypeFactoryLookup(mimeType, allEditors, &rc);
return rc;
}
} // Core

View File

@@ -1,39 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "ieditorfactory.h"
#include <coreplugin/core_global.h>
#include <utils/id.h>
#include <QObject>
namespace Utils {
class FilePath;
class MimeType;
}
namespace Core {
class IExternalEditor;
using ExternalEditorList = QList<IExternalEditor *>;
class CORE_EXPORT IExternalEditor : public EditorType
{
public:
explicit IExternalEditor();
~IExternalEditor() override;
static const ExternalEditorList allExternalEditors();
static const ExternalEditorList externalEditors(const Utils::MimeType &mimeType);
IExternalEditor *asExternalEditor() override { return this; }
virtual bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) = 0;
};
} // namespace Core

View File

@@ -3,10 +3,9 @@
#pragma once
#include "iexternaleditor.h"
#include "ieditorfactory.h"
namespace Core {
namespace Internal {
namespace Core::Internal {
class SystemEditor : public IExternalEditor
{
@@ -16,5 +15,4 @@ public:
bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) override;
};
} // namespace Internal
} // namespace Core
} // namespace Core::Internal

View File

@@ -3,7 +3,9 @@
#pragma once
#include <coreplugin/editormanager/iexternaleditor.h>
#include <coreplugin/editormanager/ieditorfactory.h>
#include <QObject>
namespace QtSupport::Internal {