Commit 0fbd7f32 authored by hjk's avatar hjk
Browse files

Core: make ICore interface static



This mainly serves two purposes:
(a) it saves a function call in ICore::instance()->foo() vs ICore::foo() at runtime
(b) it saves typing and reduces line noise when reading

It's also (mostly) source compatible, as ICore::instance()->foo() remains compilable.

Change-Id: Icf7be0bce17fefe3560473534a8991ff79cbecc3
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 951b1120
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "coreimpl.h"
#include "mainwindow.h"
#include <QtCore/QDir>
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtGui/QStatusBar>
namespace Core {
namespace Internal {
// The Core Singleton
static CoreImpl *m_instance = 0;
} // namespace Internal
} // namespace Core
using namespace Core;
using namespace Core::Internal;
ICore* ICore::instance()
{
return m_instance;
}
CoreImpl::CoreImpl(MainWindow *mainwindow)
{
m_instance = this;
m_mainwindow = mainwindow;
}
CoreImpl::~CoreImpl()
{
m_instance = 0;
}
void CoreImpl::showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QString &defaultLocation)
{
m_mainwindow->showNewItemDialog(title, wizards, defaultLocation);
}
bool CoreImpl::showOptionsDialog(const QString &group, const QString &page, QWidget *parent)
{
return m_mainwindow->showOptionsDialog(group, page, parent);
}
bool CoreImpl::showWarningWithOptions(const QString &title, const QString &text,
const QString &details,
const QString &settingsCategory,
const QString &settingsId,
QWidget *parent)
{
return m_mainwindow->showWarningWithOptions(title, text,
details, settingsCategory,
settingsId, parent);
}
ActionManager *CoreImpl::actionManager() const
{
return m_mainwindow->actionManager();
}
FileManager *CoreImpl::fileManager() const
{
return m_mainwindow->fileManager();
}
MessageManager *CoreImpl::messageManager() const
{
return m_mainwindow->messageManager();
}
EditorManager *CoreImpl::editorManager() const
{
return m_mainwindow->editorManager();
}
ProgressManager *CoreImpl::progressManager() const
{
return m_mainwindow->progressManager();
}
ScriptManager *CoreImpl::scriptManager() const
{
return m_mainwindow->scriptManager();
}
VariableManager *CoreImpl::variableManager() const
{
return m_mainwindow->variableManager();
}
VcsManager *CoreImpl::vcsManager() const
{
return m_mainwindow->vcsManager();
}
ModeManager *CoreImpl::modeManager() const
{
return m_mainwindow->modeManager();
}
MimeDatabase *CoreImpl::mimeDatabase() const
{
return m_mainwindow->mimeDatabase();
}
HelpManager *CoreImpl::helpManager() const
{
return m_mainwindow->helpManager();
}
QSettings *CoreImpl::settings(QSettings::Scope scope) const
{
return m_mainwindow->settings(scope);
}
SettingsDatabase *CoreImpl::settingsDatabase() const
{
return m_mainwindow->settingsDatabase();
}
QPrinter *CoreImpl::printer() const
{
return m_mainwindow->printer();
}
QString CoreImpl::userInterfaceLanguage() const
{
return qApp->property("qtc_locale").toString();
}
#ifdef Q_OS_MAC
# define SHARE_PATH "/../Resources"
#else
# define SHARE_PATH "/../share/qtcreator"
#endif
QString CoreImpl::resourcePath() const
{
return QDir::cleanPath(QCoreApplication::applicationDirPath() + QLatin1String(SHARE_PATH));
}
QString CoreImpl::userResourcePath() const
{
// Create qtcreator dir if it doesn't yet exist
const QString configDir = QFileInfo(settings(QSettings::UserScope)->fileName()).path();
const QString urp = configDir + QLatin1String("/qtcreator");
QFileInfo fi(urp + QLatin1Char('/'));
if (!fi.exists()) {
QDir dir;
if (!dir.mkpath(urp))
qWarning() << "could not create" << urp;
}
return urp;
}
IContext *CoreImpl::currentContextObject() const
{
return m_mainwindow->currentContextObject();
}
QMainWindow *CoreImpl::mainWindow() const
{
return m_mainwindow;
}
QStatusBar *CoreImpl::statusBar() const
{
return m_mainwindow->statusBar();
}
void CoreImpl::updateAdditionalContexts(const Context &remove, const Context &add)
{
m_mainwindow->updateAdditionalContexts(remove, add);
}
bool CoreImpl::hasContext(int context) const
{
return m_mainwindow->hasContext(context);
}
void CoreImpl::addContextObject(IContext *context)
{
m_mainwindow->addContextObject(context);
}
void CoreImpl::removeContextObject(IContext *context)
{
m_mainwindow->removeContextObject(context);
}
void CoreImpl::openFiles(const QStringList &arguments, ICore::OpenFilesFlags flags)
{
m_mainwindow->openFiles(arguments, flags);
}
void CoreImpl::emitNewItemsDialogRequested()
{
emit newItemsDialogRequested();
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef COREIMPL_H
#define COREIMPL_H
#include "icore.h"
namespace Core {
namespace Internal {
class MainWindow;
class CoreImpl : public ICore
{
Q_OBJECT
public:
CoreImpl(MainWindow *mainwindow);
~CoreImpl();
void showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QString &defaultLocation = QString());
bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(),
QWidget *parent = 0);
bool showWarningWithOptions(const QString &title, const QString &text,
const QString &details = QString(),
const QString &settingsCategory = QString(),
const QString &settingsId = QString(),
QWidget *parent = 0);
ActionManager *actionManager() const;
FileManager *fileManager() const ;
MessageManager *messageManager() const;
EditorManager *editorManager() const;
ProgressManager *progressManager() const;
ScriptManager *scriptManager() const;
VariableManager *variableManager() const;
VcsManager *vcsManager() const;
ModeManager *modeManager() const;
MimeDatabase *mimeDatabase() const;
HelpManager *helpManager() const;
QSettings *settings(QSettings::Scope scope = QSettings::UserScope) const;
SettingsDatabase *settingsDatabase() const;
QPrinter *printer() const;
QString userInterfaceLanguage() const;
QString resourcePath() const;
QString userResourcePath() const;
IContext *currentContextObject() const;
QMainWindow *mainWindow() const;
QStatusBar *statusBar() const;
// Adds and removes additional active contexts, these contexts are appended
// to the currently active contexts.
void updateAdditionalContexts(const Context &remove, const Context &add);
bool hasContext(int context) const;
void addContextObject(IContext *context);
void removeContextObject(IContext *context);
void openFiles(const QStringList &fileNames, ICore::OpenFilesFlags flags);
void emitNewItemsDialogRequested();
private:
MainWindow *m_mainwindow;
friend class MainWindow;
};
} // namespace Internal
} // namespace Core
#endif // COREIMPL_H
...@@ -57,7 +57,6 @@ SOURCES += mainwindow.cpp \ ...@@ -57,7 +57,6 @@ SOURCES += mainwindow.cpp \
coreplugin.cpp \ coreplugin.cpp \
variablemanager.cpp \ variablemanager.cpp \
modemanager.cpp \ modemanager.cpp \
coreimpl.cpp \
basefilewizard.cpp \ basefilewizard.cpp \
generatedfile.cpp \ generatedfile.cpp \
plugindialog.cpp \ plugindialog.cpp \
...@@ -160,7 +159,6 @@ HEADERS += mainwindow.h \ ...@@ -160,7 +159,6 @@ HEADERS += mainwindow.h \
coreplugin.h \ coreplugin.h \
variablemanager.h \ variablemanager.h \
modemanager.h \ modemanager.h \
coreimpl.h \
basefilewizard.h \ basefilewizard.h \
generatedfile.h \ generatedfile.h \
plugindialog.h \ plugindialog.h \
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
**************************************************************************/ **************************************************************************/
#include "iwizard.h" #include "iwizard.h"
#include "coreimpl.h" #include "icore.h"
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
...@@ -145,8 +145,7 @@ template <class Predicate> ...@@ -145,8 +145,7 @@ template <class Predicate>
QList<IWizard*> findWizards(Predicate predicate) QList<IWizard*> findWizards(Predicate predicate)
{ {
// Hack: Trigger delayed creation of wizards // Hack: Trigger delayed creation of wizards
if (Core::Internal::CoreImpl *ci = qobject_cast<Core::Internal::CoreImpl*>(ICore::instance())) ICore::emitNewItemsDialogRequested();
ci->emitNewItemsDialogRequested();
// Filter all wizards // Filter all wizards
const QList<IWizard*> allWizards = IWizard::allWizards(); const QList<IWizard*> allWizards = IWizard::allWizards();
QList<IWizard*> rc; QList<IWizard*> rc;
...@@ -160,8 +159,7 @@ template <class Predicate> ...@@ -160,8 +159,7 @@ template <class Predicate>
QList<IWizard*> IWizard::allWizards() QList<IWizard*> IWizard::allWizards()
{ {
// Hack: Trigger delayed creation of wizards // Hack: Trigger delayed creation of wizards
if (Core::Internal::CoreImpl *ci = qobject_cast<Core::Internal::CoreImpl*>(ICore::instance())) ICore::emitNewItemsDialogRequested();
ci->emitNewItemsDialogRequested();
return ExtensionSystem::PluginManager::instance()->getObjects<IWizard>(); return ExtensionSystem::PluginManager::instance()->getObjects<IWizard>();
} }
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "editorview.h" #include "editorview.h"
#include "editormanager.h" #include "editormanager.h"
#include "coreimpl.h" #include "icore.h"
#include "minisplitter.h" #include "minisplitter.h"
#include "openeditorsmodel.h" #include "openeditorsmodel.h"
...@@ -139,7 +139,7 @@ EditorView::~EditorView() ...@@ -139,7 +139,7 @@ EditorView::~EditorView()
void EditorView::closeView() void EditorView::closeView()
{ {
EditorManager *em = CoreImpl::instance()->editorManager(); EditorManager *em = ICore::instance()->editorManager();
IEditor *editor = currentEditor(); IEditor *editor = currentEditor();
if (editor) if (editor)
em->closeEditor(editor); em->closeEditor(editor);
...@@ -406,7 +406,7 @@ void EditorView::updateCurrentPositionInNavigationHistory() ...@@ -406,7 +406,7 @@ void EditorView::updateCurrentPositionInNavigationHistory()
void EditorView::goBackInNavigationHistory() void EditorView::goBackInNavigationHistory()
{ {
EditorManager *em = CoreImpl::instance()->editorManager(); EditorManager *em = ICore::instance()->editorManager();
updateCurrentPositionInNavigationHistory(); updateCurrentPositionInNavigationHistory();
while (m_currentNavigationHistoryPosition > 0) { while (m_currentNavigationHistoryPosition > 0) {
--m_currentNavigationHistoryPosition; --m_currentNavigationHistoryPosition;
...@@ -431,7 +431,7 @@ void EditorView::goBackInNavigationHistory() ...@@ -431,7 +431,7 @@ void EditorView::goBackInNavigationHistory()
void EditorView::goForwardInNavigationHistory() void EditorView::goForwardInNavigationHistory()
{ {
EditorManager *em = CoreImpl::instance()->editorManager(); EditorManager *em = ICore::instance()->editorManager();
updateCurrentPositionInNavigationHistory(); updateCurrentPositionInNavigationHistory();
if (m_currentNavigationHistoryPosition >= m_navigationHistory.size()-1) if (m_currentNavigationHistoryPosition >= m_navigationHistory.size()-1)
return; return;
...@@ -490,12 +490,12 @@ void SplitterOrView::mousePressEvent(QMouseEvent *e) ...@@ -490,12 +490,12 @@ void SplitterOrView::mousePressEvent(QMouseEvent *e)
if (e->button() != Qt::LeftButton) if (e->button() != Qt::LeftButton)
return; return;
setFocus(Qt::MouseFocusReason); setFocus(Qt::MouseFocusReason);
CoreImpl::instance()->editorManager()->setCurrentView(this); ICore::instance()->editorManager()->setCurrentView(this);
} }
void SplitterOrView::paintEvent(QPaintEvent *) void SplitterOrView::paintEvent(QPaintEvent *)
{ {
if (CoreImpl::instance()->editorManager()->currentSplitterOrView() != this) if (ICore::instance()->editorManager()->currentSplitterOrView() != this)
return; return;
if (!m_view || hasEditors()) if (!m_view || hasEditors())
...@@ -657,7 +657,7 @@ void SplitterOrView::split(Qt::Orientation orientation) ...@@ -657,7 +657,7 @@ void SplitterOrView::split(Qt::Orientation orientation)
m_splitter = new MiniSplitter(this); m_splitter = new MiniSplitter(this);
m_splitter->setOrientation(orientation); m_splitter->setOrientation(orientation);
m_layout->addWidget(m_splitter); m_layout->addWidget(m_splitter);
EditorManager *em = CoreImpl::instance()->editorManager(); EditorManager *em = ICore::instance()->editorManager();
Core::IEditor *e = m_view->currentEditor(); Core::IEditor *e = m_view->currentEditor();
SplitterOrView *view = 0; SplitterOrView *view = 0;
...@@ -710,7 +710,7 @@ void SplitterOrView::unsplitAll() ...@@ -710,7 +710,7 @@ void SplitterOrView::unsplitAll()
void SplitterOrView::unsplitAll_helper() void SplitterOrView::unsplitAll_helper()
{ {
if (!m_isRoot && m_view) if (!m_isRoot && m_view)
CoreImpl::instance()->editorManager()->emptyView(m_view); ICore::instance()->editorManager()->emptyView(m_view);
if (m_splitter) { if (m_splitter) {
for (int i = 0; i < m_splitter->count(); ++i) { for (int i = 0; i < m_splitter->count(); ++i) {
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) { if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) {
...@@ -726,7 +726,7 @@ void SplitterOrView::unsplit() ...@@ -726,7 +726,7 @@ void SplitterOrView::unsplit()
return; return;
Q_ASSERT(m_splitter->count() == 1); Q_ASSERT(m_splitter->count() == 1);
EditorManager *em = CoreImpl::instance()->editorManager(); EditorManager *em = ICore::instance()->editorManager();
SplitterOrView *childSplitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(0)); SplitterOrView *childSplitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(0));
QSplitter *oldSplitter = m_splitter; QSplitter *oldSplitter = m_splitter;
m_splitter = 0; m_splitter = 0;
...@@ -771,7 +771,7 @@ QByteArray SplitterOrView::saveState() const ...@@ -771,7 +771,7 @@ QByteArray SplitterOrView::saveState() const
<< static_cast<SplitterOrView*>(m_splitter->widget(1))->saveState(); << static_cast<SplitterOrView*>(m_splitter->widget(1))->saveState();
} else { } else {
IEditor* e = editor(); IEditor* e = editor();
EditorManager *em = CoreImpl::instance()->editorManager(); EditorManager *em = ICore::instance()->editorManager();
// don't save state of temporary or ad-hoc editors // don't save state of temporary or ad-hoc editors
if (e && (e->isTemporary() || e->file()->fileName().isEmpty())) { if (e && (e->isTemporary() || e->file()->fileName().isEmpty())) {
...@@ -812,7 +812,7 @@ void SplitterOrView::restoreState(const QByteArray &state) ...@@ -812,7 +812,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
static_cast<SplitterOrView*>(m_splitter->widget(0))->restoreState(first); static_cast<SplitterOrView*>(m_splitter->widget(0))->restoreState(first);
static_cast<SplitterOrView*>(m_splitter->widget(1))->restoreState(second); static_cast<SplitterOrView*>(m_splitter->widget(1))->restoreState(second);
} else if (mode == "editor" || mode == "currenteditor") { } else if (mode == "editor" || mode == "currenteditor") {
EditorManager *em = CoreImpl::instance()->editorManager(); EditorManager *em = ICore::instance()->editorManager();
QString fileName; QString fileName;
QString id; QString id;
QByteArray editorState; QByteArray editorState;
......
...@@ -343,3 +343,213 @@ ...@@ -343,3 +343,213 @@
\brief Sent just after a new \a context became the current context \brief Sent just after a new \a context became the current context
(meaning that its widget got focus), or if the additional context ids changed. (meaning that its widget got focus), or if the additional context ids changed.
*/ */
#include "icore.h"
#include "mainwindow.h"
#include <QtCore/QDir>
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtGui/QStatusBar>
namespace Core {
// The Core Singleton
static ICore *m_instance = 0;
namespace Internal {
static MainWindow *m_mainwindow;
} // namespace Internal
using namespace Core::Internal;
ICore *ICore::instance()
{
return m_instance;
}
ICore::ICore(MainWindow *mainwindow)
{
m_instance = this;
m_mainwindow = mainwindow;
}
ICore::~ICore()
{
m_instance = 0;
}
void ICore::showNewItemDialog(const QString &title,
const QList<IWizard *> &wizards,
const QString &defaultLocation)
{
m_mainwindow->showNewItemDialog(title, wizards, defaultLocation);
}
bool ICore::showOptionsDialog(const QString &group, const QString &page, QWidget *parent)