aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/vcpkg/vcpkgmanifesteditor.cpp
blob: 40e4837cf7779a77c6a9a10062754a9773ca74a6 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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 "vcpkgmanifesteditor.h"

#include "vcpkgconstants.h"
#include "vcpkgsearch.h"
#include "vcpkgsettings.h"
#include "vcpkgtr.h"

#include <coreplugin/icore.h>

#include <utils/utilsicons.h>

#include <texteditor/textdocument.h>

#include <QToolBar>

namespace Vcpkg::Internal {

class VcpkgManifestEditorWidget : public TextEditor::TextEditorWidget
{
public:
    VcpkgManifestEditorWidget()
    {
        m_searchPkgAction = toolBar()->addAction(Utils::Icons::ZOOM_TOOLBAR.icon(),
                                                        Tr::tr("Search package..."));
        connect(m_searchPkgAction, &QAction::triggered, this, [this] {
            const Search::VcpkgManifest package = Search::showVcpkgPackageSearchDialog();
            if (!package.name.isEmpty())
                textCursor().insertText(package.name);
        });
        updateToolBar();

        QAction *optionsAction = toolBar()->addAction(Utils::Icons::SETTINGS_TOOLBAR.icon(),
                                                      Core::ICore::msgShowOptionsDialog());
        connect(optionsAction, &QAction::triggered, [] {
            Core::ICore::showOptionsDialog(Constants::TOOLSSETTINGSPAGE_ID);
        });

        connect(&settings().vcpkgRoot, &Utils::BaseAspect::changed,
                this, &VcpkgManifestEditorWidget::updateToolBar);
    }

    void updateToolBar()
    {
        Utils::FilePath vcpkg = settings().vcpkgRoot().pathAppended("vcpkg").withExecutableSuffix();
        m_searchPkgAction->setEnabled(vcpkg.isExecutableFile());
    }

private:
    QAction *m_searchPkgAction;
};

static TextEditor::TextDocument *createVcpkgManifestDocument()
{
    auto doc = new TextEditor::TextDocument;
    doc->setId(Constants::VCPKGMANIFEST_EDITOR_ID);
    return doc;
}

VcpkgManifestEditorFactory::VcpkgManifestEditorFactory()
{
    setId(Constants::VCPKGMANIFEST_EDITOR_ID);
    setDisplayName(Tr::tr("Vcpkg Manifest Editor"));
    addMimeType(Constants::VCPKGMANIFEST_MIMETYPE);
    setDocumentCreator(createVcpkgManifestDocument);
    setEditorWidgetCreator([] { return new VcpkgManifestEditorWidget; });
    setUseGenericHighlighter(true);
}

} // namespace Vcpkg::Internal