summaryrefslogtreecommitdiff
path: root/src/plugins/terminal/terminalcommands.h
blob: 71bc7ffe0f8b3b2679b98a09d7a44877f16697a6 (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
73
74
75
76
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include <utils/id.h>

#include <coreplugin/icontext.h>

#include <QAction>
#include <QCoreApplication>
#include <QKeyEvent>

namespace Core {
class Command;
class Context;
} // namespace Core

namespace Terminal {

struct WidgetActions
{
    QAction copy;
    QAction paste;
    QAction copyLink;
    QAction clearSelection;
    QAction clearTerminal;
    QAction moveCursorWordLeft;
    QAction moveCursorWordRight;
    QAction findNext;
    QAction findPrevious;
};

struct PaneActions
{
    QAction newTerminal;
    QAction closeTerminal;
    QAction nextTerminal;
    QAction prevTerminal;
    QAction minMax;
};

class TerminalCommands
{
public:
    TerminalCommands();

    void init(const Core::Context &context);
    static TerminalCommands &instance();
    static WidgetActions &widgetActions() { return instance().m_widgetActions; }
    static PaneActions &paneActions() { return instance().m_paneActions; }

    static QList<QKeySequence> shortcutsFor(QAction *action);

    static bool triggerAction(QKeyEvent *event);

    static QAction *openSettingsAction();

    void lazyInitCommands();

protected:
    void initWidgetActions();
    void initPaneActions();
    void initGlobalCommands();

    void lazyInitCommand(const Utils::Id &id);
    void registerAction(QAction &action, const Utils::Id &id, QList<QKeySequence> shortcuts = {});

private:
    WidgetActions m_widgetActions;
    PaneActions m_paneActions;
    QList<Core::Command *> m_commands;
    Core::Context m_context;
};

} // namespace Terminal