genericprojectplugin.cpp 4.05 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Roberto Raggi's avatar
Roberto Raggi committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3
4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
Roberto Raggi's avatar
Roberto Raggi committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Roberto Raggi's avatar
Roberto Raggi committed
7
**
hjk's avatar
hjk committed
8
9
10
11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
12
13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
Roberto Raggi's avatar
Roberto Raggi committed
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25
26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
Roberto Raggi's avatar
Roberto Raggi committed
30
31

#include "genericprojectplugin.h"
Tobias Hunger's avatar
Tobias Hunger committed
32
33

#include "genericbuildconfiguration.h"
Roberto Raggi's avatar
Roberto Raggi committed
34
#include "genericprojectmanager.h"
Roberto Raggi's avatar
Roberto Raggi committed
35
#include "genericprojectwizard.h"
36
37
#include "genericprojectconstants.h"
#include "genericprojectfileseditor.h"
38
#include "genericmakestep.h"
39
#include "genericproject.h"
Roberto Raggi's avatar
Roberto Raggi committed
40
41

#include <coreplugin/icore.h>
42
43
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
44
#include <coreplugin/actionmanager/command.h>
45
46

#include <projectexplorer/projectexplorerconstants.h>
47
#include <projectexplorer/projecttree.h>
48
#include <projectexplorer/selectablefilesmodel.h>
Roberto Raggi's avatar
Roberto Raggi committed
49

Eike Ziller's avatar
Eike Ziller committed
50
51
#include <utils/mimetypes/mimedatabase.h>

52
53
#include <QtPlugin>
#include <QDebug>
Roberto Raggi's avatar
Roberto Raggi committed
54

55
56
57
using namespace Core;
using namespace ProjectExplorer;

hjk's avatar
hjk committed
58
59
namespace GenericProjectManager {
namespace Internal {
Roberto Raggi's avatar
Roberto Raggi committed
60
61

GenericProjectPlugin::GenericProjectPlugin()
62
    : m_contextMenuProject(0)
Roberto Raggi's avatar
Roberto Raggi committed
63
64
65
66
{ }

bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage)
{
Eike Ziller's avatar
Eike Ziller committed
67
68
    Q_UNUSED(errorMessage)
    Utils::MimeDatabase::addMimeTypes(QLatin1String(":genericproject/GenericProjectManager.mimetypes.xml"));
Roberto Raggi's avatar
Roberto Raggi committed
69

70
71
    addAutoReleasedObject(new Manager);
    addAutoReleasedObject(new ProjectFilesFactory);
72
    addAutoReleasedObject(new GenericMakeStepFactory);
Tobias Hunger's avatar
Tobias Hunger committed
73
    addAutoReleasedObject(new GenericBuildConfigurationFactory);
Roberto Raggi's avatar
Roberto Raggi committed
74

75
76
    IWizardFactory::registerFactoryCreator([]() { return QList<IWizardFactory *>() << new GenericProjectWizard; });

hjk's avatar
hjk committed
77
78
    ActionContainer *mproject =
            ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
hjk's avatar
hjk committed
79

80
81
82
    auto editFilesAction = new QAction(tr("Edit Files..."), this);
    Command *command = ActionManager::registerAction(editFilesAction,
        "GenericProjectManager.EditFiles", Context(Constants::PROJECTCONTEXT));
hjk's avatar
hjk committed
83
    command->setAttribute(Command::CA_Hide);
84
85
    mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);

Montel Laurent's avatar
Montel Laurent committed
86
    connect(editFilesAction, &QAction::triggered, this, &GenericProjectPlugin::editFiles);
87

88
    connect(ProjectTree::instance(), &ProjectTree::aboutToShowContextMenu,
89
            [this] (Project *project, Node *) { m_contextMenuProject = project; });
Roberto Raggi's avatar
Roberto Raggi committed
90

91
    return true;
92
93
94
95
96
}

void GenericProjectPlugin::editFiles()
{
    GenericProject *genericProject = static_cast<GenericProject *>(m_contextMenuProject);
97
98
    SelectableFilesDialogEditFiles sfd(genericProject->projectFilePath().toFileInfo().path(), genericProject->files(),
                              ICore::mainWindow());
99
    if (sfd.exec() == QDialog::Accepted)
100
101
102
        genericProject->setFiles(sfd.selectedFiles());
}

hjk's avatar
hjk committed
103
104
} // namespace Internal
} // namespace GenericProjectManager