coreplugin.cpp 4.63 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con 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
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con 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.
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
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "coreplugin.h"
31
#include "designmode.h"
con's avatar
con committed
32
#include "editmode.h"
33 34
#include "helpmanager.h"
#include "mainwindow.h"
35
#include "mimedatabase.h"
36
#include "modemanager.h"
37
#include "infobar.h"
38

39 40
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/editormanager/editormanager.h>
41 42
#include <coreplugin/find/findplugin.h>
#include <coreplugin/locator/locatorplugin.h>
con's avatar
con committed
43

44
#include <utils/savefile.h>
45

46 47
#include <QtPlugin>
#include <QDebug>
48
#include <QDateTime>
con's avatar
con committed
49

Lasse Holmstedt's avatar
Lasse Holmstedt committed
50
using namespace Core;
con's avatar
con committed
51 52
using namespace Core::Internal;

53
CorePlugin::CorePlugin() : m_editMode(0), m_designMode(0)
con's avatar
con committed
54
{
55 56
    qRegisterMetaType<Core::Id>();
    m_mainWindow = new MainWindow;
57 58
    m_findPlugin = new FindPlugin;
    m_locatorPlugin = new LocatorPlugin;
con's avatar
con committed
59 60 61 62
}

CorePlugin::~CorePlugin()
{
63 64 65
    delete m_findPlugin;
    delete m_locatorPlugin;

con's avatar
con committed
66 67 68 69 70
    if (m_editMode) {
        removeObject(m_editMode);
        delete m_editMode;
    }

Lasse Holmstedt's avatar
Lasse Holmstedt committed
71
    if (m_designMode) {
72 73
        if (m_designMode->designModeIsRequired())
            removeObject(m_designMode);
Lasse Holmstedt's avatar
Lasse Holmstedt committed
74 75 76
        delete m_designMode;
    }

con's avatar
con committed
77 78 79
    delete m_mainWindow;
}

80 81
void CorePlugin::parseArguments(const QStringList &arguments)
{
Tobias Hunger's avatar
Tobias Hunger committed
82
    for (int i = 0; i < arguments.size(); ++i) {
83 84 85 86 87
        if (arguments.at(i) == QLatin1String("-color")) {
            const QString colorcode(arguments.at(i + 1));
            m_mainWindow->setOverrideColor(QColor(colorcode));
            i++; // skip the argument
        }
Tobias Hunger's avatar
Tobias Hunger committed
88
        if (arguments.at(i) == QLatin1String("-presentationMode"))
Eike Ziller's avatar
Eike Ziller committed
89
            ActionManager::setPresentationModeEnabled(true);
90 91 92
    }
}

93
bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
con's avatar
con committed
94
{
95
    qsrand(QDateTime::currentDateTime().toTime_t());
96
    parseArguments(arguments);
97
    const bool success = m_mainWindow->init(errorMessage);
con's avatar
con committed
98
    if (success) {
hjk's avatar
hjk committed
99
        m_editMode = new EditMode;
con's avatar
con committed
100
        addObject(m_editMode);
101
        ModeManager::activateMode(m_editMode->id());
hjk's avatar
hjk committed
102
        m_designMode = new DesignMode;
103
        InfoBar::initializeGloballySuppressed();
con's avatar
con committed
104
    }
105 106 107 108

    // Make sure we respect the process's umask when creating new files
    Utils::SaveFile::initializeUmask();

109 110 111
    m_findPlugin->initialize(arguments, errorMessage);
    m_locatorPlugin->initialize(this, arguments, errorMessage);

con's avatar
con committed
112 113 114 115 116
    return success;
}

void CorePlugin::extensionsInitialized()
{
117
    MimeDatabase::syncUserModifiedMimeTypes();
118 119
    if (m_designMode->designModeIsRequired())
        addObject(m_designMode);
con's avatar
con committed
120
    m_mainWindow->extensionsInitialized();
121 122
    m_findPlugin->extensionsInitialized();
    m_locatorPlugin->extensionsInitialized();
con's avatar
con committed
123 124
}

125 126
bool CorePlugin::delayedInitialize()
{
127
    HelpManager::setupHelpManager();
128
    m_locatorPlugin->delayedInitialize();
129 130 131
    return true;
}

132
QObject *CorePlugin::remoteCommand(const QStringList & /* options */, const QStringList &args)
con's avatar
con committed
133
{
134 135
    IDocument *res = m_mainWindow->openFiles(
                args, ICore::OpenFilesFlags(ICore::SwitchMode | ICore::CanContainLineNumbers));
136
    m_mainWindow->raiseWindow();
137
    return res;
138 139 140 141 142
}

void CorePlugin::fileOpenRequest(const QString &f)
{
    remoteCommand(QStringList(), QStringList(f));
con's avatar
con committed
143 144
}

145
ExtensionSystem::IPlugin::ShutdownFlag CorePlugin::aboutToShutdown()
146
{
147
    m_mainWindow->aboutToShutdown();
148
    return SynchronousShutdown;
149 150
}

con's avatar
con committed
151
Q_EXPORT_PLUGIN(CorePlugin)