aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/compilerexplorer/compilerexplorerplugin.cpp
blob: 48920561b4af120f3466f2bfd5d76be0078ad182 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "compilerexplorerconstants.h"
#include "compilerexplorereditor.h"
#include "compilerexplorersettings.h"
#include "compilerexplorertr.h"

#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>

#include <cppeditor/cppeditorconstants.h>

#include <extensionsystem/iplugin.h>

#include <projectexplorer/jsonwizard/jsonwizardfactory.h>

#include <utils/fsengine/fileiconprovider.h>

using namespace Core;
using namespace Utils;

namespace CompilerExplorer::Internal {

class CompilerExplorerPlugin final : public ExtensionSystem::IPlugin
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CompilerExplorer.json")

public:
    void initialize() final
    {
        static CompilerExplorer::EditorFactory ceEditorFactory;

        FileIconProvider::registerIconForMimeType(QIcon(":/compilerexplorer/logos/ce.ico"),
                                                  "application/compiler-explorer");

        const Id menuId = "Tools.CompilerExplorer";
        MenuBuilder(menuId)
            .setTitle(Tr::tr("Compiler Explorer"))
            .addToContainer(Core::Constants::M_TOOLS);

        ActionBuilder(this, "CompilerExplorer.CompilerExplorerAction")
            .setText(Tr::tr("Open Compiler Explorer"))
            .addToContainer(menuId)
            .addOnTriggered(this, [] {
                QString name = "Compiler Explorer $";
                EditorManager::openEditorWithContents(Constants::CE_EDITOR_ID,
                                                      &name,
                                                      settings().defaultDocument().toUtf8());
            });
    }
};

} // namespace CompilerExplorer::Internal

#include "compilerexplorerplugin.moc"