1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "templatemanager.h" |
6 | #include "wizard/maindialog.h" |
7 | |
8 | #include "services/window/windowservice.h" |
9 | #include "base/abstractaction.h" |
10 | #include "common/actionmanager/actionmanager.h" |
11 | |
12 | using namespace dpfservice; |
13 | |
14 | class TemplateManagerPrivate |
15 | { |
16 | friend class TemplateManager; |
17 | |
18 | QSharedPointer<QAction> newAction; |
19 | }; |
20 | |
21 | TemplateManager *TemplateManager::instance() |
22 | { |
23 | static TemplateManager ins; |
24 | return &ins; |
25 | } |
26 | |
27 | TemplateManager::TemplateManager(QObject *parent) |
28 | : QObject(parent) |
29 | , d(new TemplateManagerPrivate()) |
30 | { |
31 | |
32 | } |
33 | |
34 | TemplateManager::~TemplateManager() |
35 | { |
36 | if (d) { |
37 | delete d; |
38 | } |
39 | } |
40 | |
41 | void TemplateManager::initialize() |
42 | { |
43 | addMenu(); |
44 | } |
45 | |
46 | void TemplateManager::() |
47 | { |
48 | auto &ctx = dpfInstance.serviceContext(); |
49 | auto windowService = ctx.service<WindowService>(WindowService::name()); |
50 | if (!windowService) |
51 | return; |
52 | |
53 | auto actionInit = [&](QAction *action, QString actionID, QKeySequence key, QString iconFileName){ |
54 | ActionManager::getInstance()->registerAction(action, actionID, action->text(), key, iconFileName); |
55 | AbstractAction *actionImpl = new AbstractAction(action); |
56 | windowService->addAction(dpfservice::MWM_FILE, actionImpl); |
57 | }; |
58 | |
59 | d->newAction.reset(new QAction(MWMFA_NEW_FILE_OR_PROJECT)); |
60 | actionInit(d->newAction.get(), |
61 | "Fiel.New.FileOrProject" , |
62 | QKeySequence(Qt::Modifier::CTRL | Qt::Modifier::SHIFT | Qt::Key::Key_O), ":/template/images/new_project.png" ); |
63 | QObject::connect(d->newAction.get(), &QAction::triggered, |
64 | this, &TemplateManager::newWizard, Qt::DirectConnection); |
65 | } |
66 | |
67 | void TemplateManager::newWizard() |
68 | { |
69 | MainDialog *mainDlg = new MainDialog(); |
70 | mainDlg->exec(); |
71 | } |
72 | |