aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/todo/todoplugin.cpp
blob: 3df1df3fa5afb5f8de64783ee57d49aef6e62bee (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright (C) 2016 Dmitry Savchenko
// Copyright (C) 2016 Vasiliy Sorokin
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#include "todoplugin.h"

#include "optionsdialog.h"
#include "todooutputpane.h"
#include "todoitemsprovider.h"
#include "todoprojectsettingswidget.h"
#include "todotr.h"

#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>

#include <projectexplorer/projectpanelfactory.h>
#include <utils/link.h>

#include <QSettings>

namespace Todo {
namespace Internal {

class TodoPluginPrivate : public QObject
{
public:
    TodoPluginPrivate();

    void settingsChanged(const Settings &settings);
    void scanningScopeChanged(ScanningScope scanningScope);
    void todoItemClicked(const TodoItem &item);
    void createItemsProvider();
    void createTodoOutputPane();

    Settings m_settings;
    TodoOutputPane *m_todoOutputPane = nullptr;
    TodoOptionsPage m_optionsPage{&m_settings, [this] { settingsChanged(m_settings); }};
    TodoItemsProvider *m_todoItemsProvider = nullptr;
};

TodoPluginPrivate::TodoPluginPrivate()
{
    m_settings.load(Core::ICore::settings());

    createItemsProvider();
    createTodoOutputPane();

    auto panelFactory = new ProjectExplorer::ProjectPanelFactory;
    panelFactory->setPriority(100);
    panelFactory->setDisplayName(Tr::tr("To-Do"));
    panelFactory->setCreateWidgetFunction([this](ProjectExplorer::Project *project) {
        auto widget = new TodoProjectSettingsWidget(project);
        connect(widget, &TodoProjectSettingsWidget::projectSettingsChanged,
                m_todoItemsProvider, [this, project] { m_todoItemsProvider->projectSettingsChanged(project); });
        return widget;
    });
    ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
    connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested,
            this, [this] { m_settings.save(Core::ICore::settings()); });
}

void TodoPluginPrivate::settingsChanged(const Settings &settings)
{
    settings.save(Core::ICore::settings());
    m_settings = settings;

    m_todoItemsProvider->settingsChanged(m_settings);
    m_todoOutputPane->setScanningScope(m_settings.scanningScope);
}

void TodoPluginPrivate::scanningScopeChanged(ScanningScope scanningScope)
{
    Settings newSettings = m_settings;
    newSettings.scanningScope = scanningScope;
    settingsChanged(newSettings);
}

void TodoPluginPrivate::todoItemClicked(const TodoItem &item)
{
    if (item.file.exists())
        Core::EditorManager::openEditorAt(Utils::Link(item.file, item.line));
}

void TodoPluginPrivate::createItemsProvider()
{
    m_todoItemsProvider = new TodoItemsProvider(m_settings, this);
}

void TodoPluginPrivate::createTodoOutputPane()
{
    m_todoOutputPane = new TodoOutputPane(m_todoItemsProvider->todoItemsModel(), &m_settings, this);
    m_todoOutputPane->setScanningScope(m_settings.scanningScope);
    connect(m_todoOutputPane, &TodoOutputPane::scanningScopeChanged,
            this, &TodoPluginPrivate::scanningScopeChanged);
    connect(m_todoOutputPane, &TodoOutputPane::todoItemClicked,
            this, &TodoPluginPrivate::todoItemClicked);
}

TodoPlugin::TodoPlugin()
{
    qRegisterMetaType<TodoItem>("TodoItem");
}

TodoPlugin::~TodoPlugin()
{
    delete d;
}

bool TodoPlugin::initialize(const QStringList& args, QString *errMsg)
{
    Q_UNUSED(args)
    Q_UNUSED(errMsg)

    d = new TodoPluginPrivate;

    return true;
}

} // namespace Internal
} // namespace Todo