forked from qt-creator/qt-creator
CompilerExplorer: Add Mimetype
Change-Id: Id267d6d164a4ce8b1527ccb9dc6d1e4b6b289833 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -15,5 +15,15 @@
|
|||||||
],
|
],
|
||||||
"Description" : "Integrates https://godbolt.org into Qt Creator.",
|
"Description" : "Integrates https://godbolt.org into Qt Creator.",
|
||||||
"Url" : "http://www.qt.io",
|
"Url" : "http://www.qt.io",
|
||||||
${IDE_PLUGIN_DEPENDENCIES}
|
${IDE_PLUGIN_DEPENDENCIES},
|
||||||
|
"Mimetypes" : [
|
||||||
|
"<?xml version='1.0'?>",
|
||||||
|
"<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>",
|
||||||
|
" <mime-type type='application/compiler-explorer'>",
|
||||||
|
" <sub-class-of type='application/json'/>",
|
||||||
|
" <comment>Compiler Explorer file</comment>",
|
||||||
|
" <glob pattern='*.qtce'/>",
|
||||||
|
" </mime-type>",
|
||||||
|
"</mime-info>"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,14 +84,15 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonSettingsDocument::JsonSettingsDocument(CompilerExplorerSettings *ceSettings)
|
JsonSettingsDocument::JsonSettingsDocument()
|
||||||
: m_ceSettings(ceSettings)
|
|
||||||
{
|
{
|
||||||
setId(Constants::CE_EDITOR_ID);
|
setId(Constants::CE_EDITOR_ID);
|
||||||
|
setMimeType("application/compiler-explorer");
|
||||||
connect(m_ceSettings, &CompilerExplorerSettings::changed, this, [this] { emit changed(); });
|
connect(&m_ceSettings, &CompilerExplorerSettings::changed, this, [this] { emit changed(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonSettingsDocument::~JsonSettingsDocument() {}
|
||||||
|
|
||||||
Core::IDocument::OpenResult JsonSettingsDocument::open(QString *errorString,
|
Core::IDocument::OpenResult JsonSettingsDocument::open(QString *errorString,
|
||||||
const Utils::FilePath &filePath,
|
const Utils::FilePath &filePath,
|
||||||
const Utils::FilePath &realFilePath)
|
const Utils::FilePath &realFilePath)
|
||||||
@@ -120,7 +121,7 @@ Core::IDocument::OpenResult JsonSettingsDocument::open(QString *errorString,
|
|||||||
return OpenResult::CannotHandle;
|
return OpenResult::CannotHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ceSettings->fromMap(doc.toVariant().toMap());
|
m_ceSettings.fromMap(doc.toVariant().toMap());
|
||||||
emit settingsChanged();
|
emit settingsChanged();
|
||||||
return OpenResult::Success;
|
return OpenResult::Success;
|
||||||
}
|
}
|
||||||
@@ -133,15 +134,15 @@ bool JsonSettingsDocument::saveImpl(QString *errorString,
|
|||||||
|
|
||||||
if (autoSave) {
|
if (autoSave) {
|
||||||
if (m_windowStateCallback)
|
if (m_windowStateCallback)
|
||||||
m_ceSettings->windowState.setVolatileValue(m_windowStateCallback());
|
m_ceSettings.windowState.setVolatileValue(m_windowStateCallback());
|
||||||
|
|
||||||
m_ceSettings->volatileToMap(map);
|
m_ceSettings.volatileToMap(map);
|
||||||
} else {
|
} else {
|
||||||
if (m_windowStateCallback)
|
if (m_windowStateCallback)
|
||||||
m_ceSettings->windowState.setValue(m_windowStateCallback());
|
m_ceSettings.windowState.setValue(m_windowStateCallback());
|
||||||
|
|
||||||
m_ceSettings->apply();
|
m_ceSettings.apply();
|
||||||
m_ceSettings->toMap(map);
|
m_ceSettings.toMap(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument doc = QJsonDocument::fromVariant(map);
|
QJsonDocument doc = QJsonDocument::fromVariant(map);
|
||||||
@@ -162,8 +163,7 @@ bool JsonSettingsDocument::saveImpl(QString *errorString,
|
|||||||
|
|
||||||
bool JsonSettingsDocument::isModified() const
|
bool JsonSettingsDocument::isModified() const
|
||||||
{
|
{
|
||||||
bool isDirty = m_ceSettings->isDirty();
|
return m_ceSettings.isDirty();
|
||||||
return isDirty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JsonSettingsDocument::setContents(const QByteArray &contents)
|
bool JsonSettingsDocument::setContents(const QByteArray &contents)
|
||||||
@@ -174,7 +174,7 @@ bool JsonSettingsDocument::setContents(const QByteArray &contents)
|
|||||||
|
|
||||||
QTC_ASSERT(doc.isObject(), return false);
|
QTC_ASSERT(doc.isObject(), return false);
|
||||||
|
|
||||||
m_ceSettings->fromMap(doc.toVariant().toMap());
|
m_ceSettings.fromMap(doc.toVariant().toMap());
|
||||||
|
|
||||||
emit settingsChanged();
|
emit settingsChanged();
|
||||||
return true;
|
return true;
|
||||||
@@ -455,7 +455,7 @@ void CompilerWidget::doCompile()
|
|||||||
m_compileWatcher->setFuture(f);
|
m_compileWatcher->setFuture(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorWidget::EditorWidget(QSharedPointer<JsonSettingsDocument> document, QWidget *parent)
|
EditorWidget::EditorWidget(const QSharedPointer<JsonSettingsDocument> &document, QWidget *parent)
|
||||||
: Utils::FancyMainWindow(parent)
|
: Utils::FancyMainWindow(parent)
|
||||||
, m_document(document)
|
, m_document(document)
|
||||||
{
|
{
|
||||||
@@ -494,7 +494,7 @@ EditorWidget::EditorWidget(QSharedPointer<JsonSettingsDocument> document, QWidge
|
|||||||
m_compilerWidgets.append(dockWidget);
|
m_compilerWidgets.append(dockWidget);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto addSourceEditor = [this, document, addCompiler](
|
auto addSourceEditor = [this, document = document.get(), addCompiler](
|
||||||
const std::shared_ptr<SourceSettings> &sourceSettings) {
|
const std::shared_ptr<SourceSettings> &sourceSettings) {
|
||||||
auto sourceEditor = new SourceEditorWidget(sourceSettings);
|
auto sourceEditor = new SourceEditorWidget(sourceSettings);
|
||||||
sourceEditor->setWindowTitle("Source Code #" + QString::number(m_sourceWidgets.size() + 1));
|
sourceEditor->setWindowTitle("Source Code #" + QString::number(m_sourceWidgets.size() + 1));
|
||||||
@@ -607,7 +607,7 @@ class Editor : public Core::IEditor
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Editor()
|
Editor()
|
||||||
: m_document(new JsonSettingsDocument(&m_settings))
|
: m_document(new JsonSettingsDocument())
|
||||||
{
|
{
|
||||||
setWidget(new EditorWidget(m_document));
|
setWidget(new EditorWidget(m_document));
|
||||||
}
|
}
|
||||||
@@ -617,7 +617,6 @@ public:
|
|||||||
Core::IDocument *document() const override { return m_document.data(); }
|
Core::IDocument *document() const override { return m_document.data(); }
|
||||||
QWidget *toolBar() override { return nullptr; }
|
QWidget *toolBar() override { return nullptr; }
|
||||||
|
|
||||||
CompilerExplorerSettings m_settings;
|
|
||||||
QSharedPointer<JsonSettingsDocument> m_document;
|
QSharedPointer<JsonSettingsDocument> m_document;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -631,6 +630,7 @@ EditorFactory::EditorFactory()
|
|||||||
{
|
{
|
||||||
setId(Constants::CE_EDITOR_ID);
|
setId(Constants::CE_EDITOR_ID);
|
||||||
setDisplayName(Tr::tr("Compiler Explorer Editor"));
|
setDisplayName(Tr::tr("Compiler Explorer Editor"));
|
||||||
|
setMimeTypes({"application/compiler-explorer"});
|
||||||
|
|
||||||
setEditorCreator([]() { return new Editor(); });
|
setEditorCreator([]() { return new Editor(); });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ class JsonSettingsDocument : public Core::IDocument
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
JsonSettingsDocument(CompilerExplorerSettings *ceSettings);
|
JsonSettingsDocument();
|
||||||
|
~JsonSettingsDocument() override;
|
||||||
|
|
||||||
OpenResult open(QString *errorString,
|
OpenResult open(QString *errorString,
|
||||||
const Utils::FilePath &filePath,
|
const Utils::FilePath &filePath,
|
||||||
const Utils::FilePath &realFilePath) override;
|
const Utils::FilePath &realFilePath) override;
|
||||||
@@ -50,7 +52,7 @@ public:
|
|||||||
bool isModified() const override;
|
bool isModified() const override;
|
||||||
bool isSaveAsAllowed() const override { return true; }
|
bool isSaveAsAllowed() const override { return true; }
|
||||||
|
|
||||||
CompilerExplorerSettings *settings() { return m_ceSettings; }
|
CompilerExplorerSettings *settings() { return &m_ceSettings; }
|
||||||
|
|
||||||
void setWindowStateCallback(std::function<QVariantMap()> callback)
|
void setWindowStateCallback(std::function<QVariantMap()> callback)
|
||||||
{
|
{
|
||||||
@@ -61,7 +63,7 @@ signals:
|
|||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CompilerExplorerSettings *m_ceSettings;
|
mutable CompilerExplorerSettings m_ceSettings;
|
||||||
std::function<QVariantMap()> m_windowStateCallback;
|
std::function<QVariantMap()> m_windowStateCallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -118,7 +120,7 @@ class EditorWidget : public Utils::FancyMainWindow
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
EditorWidget(QSharedPointer<JsonSettingsDocument> document = nullptr, QWidget *parent = nullptr);
|
EditorWidget(const QSharedPointer<JsonSettingsDocument> &document, QWidget *parent = nullptr);
|
||||||
~EditorWidget() override;
|
~EditorWidget() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
Reference in New Issue
Block a user