aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/projectexplorer/taskhandlers.h
blob: 3449d3cf581649f8bc06680784e740ccf807306f (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
// 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 "projectexplorer_export.h"
#include "task.h"

#include <utils/id.h>

#include <QAction>
#include <QObject>
#include <QPointer>
#include <QString>

#include <functional>

QT_BEGIN_NAMESPACE
class QAction;
QT_END_NAMESPACE

namespace Core { class Context; }

namespace ProjectExplorer {
namespace Internal { void registerQueuedTaskHandlers(); }

class PROJECTEXPLORER_EXPORT ITaskHandler : public QObject
{
public:
    explicit ITaskHandler(QAction *action, const Utils::Id &actionId = {},
                          bool isMultiHandler = false);
    ~ITaskHandler() override;

    virtual bool isDefaultHandler() const { return false; }
    virtual bool canHandle(const Task &) const { return m_isMultiHandler; }
    virtual void handle(const Task &task);       // Non-multi-handlers should implement this.
    virtual void handle(const Tasks &tasks); // Multi-handlers should implement this.

    bool canHandle(const Tasks &tasks) const;
    QAction *action() const { return m_action; }

private:
    friend void Internal::registerQueuedTaskHandlers();

    void registerHandler();
    void deregisterHandler();

    const QPointer<QAction> m_action;
    const Utils::Id m_actionId;
    const bool m_isMultiHandler;
};

namespace Internal {
using RegisterHandlerAction = std::function<void(QAction *)>;
using GetHandlerTasks = std::function<Tasks()>;
void setupTaskHandlers(
    QObject *actionParent,
    const Core::Context &cmdContext,
    const RegisterHandlerAction &onCreateAction,
    const GetHandlerTasks &getTasks);

ITaskHandler *taskHandlerForAction(QAction *action);
ITaskHandler *defaultTaskHandler();
void updateTaskHandlerActionsState();

} // namespace Internal
} // namespace ProjectExplorer