genericprojectplugin.cpp 4.02 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Roberto Raggi's avatar
Roberto Raggi committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
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 12 13 14
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
Roberto Raggi's avatar
Roberto Raggi committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
Roberto Raggi's avatar
Roberto Raggi committed
29 30

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

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

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

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

49 50
#include <QtPlugin>
#include <QDebug>
Roberto Raggi's avatar
Roberto Raggi committed
51

52 53 54
using namespace Core;
using namespace ProjectExplorer;

hjk's avatar
hjk committed
55 56
namespace GenericProjectManager {
namespace Internal {
Roberto Raggi's avatar
Roberto Raggi committed
57 58

GenericProjectPlugin::GenericProjectPlugin()
59
    : m_contextMenuProject(0)
Roberto Raggi's avatar
Roberto Raggi committed
60 61 62 63
{ }

bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage)
{
Orgad Shaneh's avatar
Orgad Shaneh committed
64
    const QLatin1String mimetypesXml(":genericproject/GenericProjectManager.mimetypes.xml");
Roberto Raggi's avatar
Roberto Raggi committed
65

hjk's avatar
hjk committed
66
    if (!MimeDatabase::addMimeTypes(mimetypesXml, errorMessage))
Roberto Raggi's avatar
Roberto Raggi committed
67 68
        return false;

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

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

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

84 85
    connect(editFilesAction, &QAction::triggered,
            this, &GenericProjectPlugin::editFiles);
86

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

90
    return true;
91 92 93 94 95
}

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

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

Q_EXPORT_PLUGIN(GenericProjectManager::Internal::GenericProjectPlugin)