forked from qt-creator/qt-creator
EditorManager: Do not be a widget.
There is no reason for the editor manager itself to be a widget. This makes even less sense in the presence of multiple windows. Change-Id: I384f8945fdd5632d64643e473e6637e05abbce7e Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -118,6 +118,7 @@ HEADERS += mainwindow.h \
|
||||
vcsmanager.h \
|
||||
statusbarmanager.h \
|
||||
editormanager/editormanager.h \
|
||||
editormanager/editormanager_p.h \
|
||||
editormanager/editorview.h \
|
||||
editormanager/documentmodel.h \
|
||||
editormanager/openeditorsview.h \
|
||||
|
@@ -140,7 +140,7 @@ QtcPlugin {
|
||||
files: [
|
||||
"BinFiles.mimetypes.xml",
|
||||
"documentmodel.cpp", "documentmodel.h",
|
||||
"editormanager.cpp", "editormanager.h",
|
||||
"editormanager.cpp", "editormanager.h", "editormanager_p.h",
|
||||
"editorview.cpp", "editorview.h",
|
||||
"ieditor.cpp", "ieditor.h",
|
||||
"ieditorfactory.cpp", "ieditorfactory.h",
|
||||
|
@@ -60,7 +60,8 @@ EditMode::EditMode() :
|
||||
m_rightSplitWidgetLayout->setMargin(0);
|
||||
QWidget *rightSplitWidget = new QWidget;
|
||||
rightSplitWidget->setLayout(m_rightSplitWidgetLayout);
|
||||
m_rightSplitWidgetLayout->insertWidget(0, new Core::EditorManagerPlaceHolder(this));
|
||||
auto editorPlaceHolder = new EditorManagerPlaceHolder(this);
|
||||
m_rightSplitWidgetLayout->insertWidget(0, editorPlaceHolder);
|
||||
|
||||
MiniSplitter *rightPaneSplitter = new MiniSplitter;
|
||||
rightPaneSplitter->insertWidget(0, rightSplitWidget);
|
||||
@@ -84,7 +85,7 @@ EditMode::EditMode() :
|
||||
|
||||
connect(ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)),
|
||||
this, SLOT(grabEditorManager(Core::IMode*)));
|
||||
m_splitter->setFocusProxy(EditorManager::instance());
|
||||
m_splitter->setFocusProxy(editorPlaceHolder);
|
||||
|
||||
IContext *modeContextObject = new IContext(this);
|
||||
modeContextObject->setContext(Context(Constants::C_EDITORMANAGER));
|
||||
|
@@ -28,6 +28,8 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "editormanager.h"
|
||||
#include "editormanager_p.h"
|
||||
|
||||
#include "editorview.h"
|
||||
#include "openeditorswindow.h"
|
||||
#include "openeditorsview.h"
|
||||
@@ -119,6 +121,7 @@ EditorManagerPlaceHolder::EditorManagerPlaceHolder(Core::IMode *mode, QWidget *p
|
||||
{
|
||||
setLayout(new QVBoxLayout);
|
||||
layout()->setMargin(0);
|
||||
setFocusProxy(EditorManagerPrivate::rootWidget());
|
||||
connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)),
|
||||
this, SLOT(currentModeChanged(Core::IMode*)));
|
||||
|
||||
@@ -128,7 +131,7 @@ EditorManagerPlaceHolder::EditorManagerPlaceHolder(Core::IMode *mode, QWidget *p
|
||||
EditorManagerPlaceHolder::~EditorManagerPlaceHolder()
|
||||
{
|
||||
// EditorManager will be deleted in ~MainWindow()
|
||||
EditorManager *em = EditorManager::instance();
|
||||
QWidget *em = EditorManagerPrivate::rootWidget();
|
||||
if (em && em->parent() == this) {
|
||||
em->hide();
|
||||
em->setParent(0);
|
||||
@@ -139,10 +142,11 @@ void EditorManagerPlaceHolder::currentModeChanged(Core::IMode *mode)
|
||||
{
|
||||
if (m_mode == mode) {
|
||||
QWidget *previousFocus = 0;
|
||||
if (EditorManager::instance()->focusWidget() && EditorManager::instance()->focusWidget()->hasFocus())
|
||||
previousFocus = EditorManager::instance()->focusWidget();
|
||||
layout()->addWidget(EditorManager::instance());
|
||||
EditorManager::instance()->show();
|
||||
QWidget *em = EditorManagerPrivate::rootWidget();
|
||||
if (em->focusWidget() && em->focusWidget()->hasFocus())
|
||||
previousFocus = em->focusWidget();
|
||||
layout()->addWidget(em);
|
||||
em->show();
|
||||
if (previousFocus)
|
||||
previousFocus->setFocus();
|
||||
}
|
||||
@@ -150,71 +154,10 @@ void EditorManagerPlaceHolder::currentModeChanged(Core::IMode *mode)
|
||||
|
||||
// ---------------- EditorManager
|
||||
|
||||
namespace Core {
|
||||
static EditorManager *m_instance = 0;
|
||||
static EditorManagerPrivate *d;
|
||||
|
||||
|
||||
class EditorManagerPrivate
|
||||
{
|
||||
public:
|
||||
explicit EditorManagerPrivate(QWidget *parent);
|
||||
~EditorManagerPrivate();
|
||||
QList<EditLocation> m_globalHistory;
|
||||
QList<Internal::SplitterOrView *> m_root;
|
||||
QList<IContext *> m_rootContext;
|
||||
QPointer<IEditor> m_currentEditor;
|
||||
QPointer<IEditor> m_scheduledCurrentEditor;
|
||||
QPointer<EditorView> m_currentView;
|
||||
QTimer *m_autoSaveTimer;
|
||||
|
||||
// actions
|
||||
QAction *m_revertToSavedAction;
|
||||
QAction *m_saveAction;
|
||||
QAction *m_saveAsAction;
|
||||
QAction *m_closeCurrentEditorAction;
|
||||
QAction *m_closeAllEditorsAction;
|
||||
QAction *m_closeOtherEditorsAction;
|
||||
QAction *m_closeAllEditorsExceptVisibleAction;
|
||||
QAction *m_gotoNextDocHistoryAction;
|
||||
QAction *m_gotoPreviousDocHistoryAction;
|
||||
QAction *m_goBackAction;
|
||||
QAction *m_goForwardAction;
|
||||
QAction *m_splitAction;
|
||||
QAction *m_splitSideBySideAction;
|
||||
QAction *m_splitNewWindowAction;
|
||||
QAction *m_removeCurrentSplitAction;
|
||||
QAction *m_removeAllSplitsAction;
|
||||
QAction *m_gotoNextSplitAction;
|
||||
|
||||
QAction *m_saveCurrentEditorContextAction;
|
||||
QAction *m_saveAsCurrentEditorContextAction;
|
||||
QAction *m_revertToSavedCurrentEditorContextAction;
|
||||
|
||||
QAction *m_closeCurrentEditorContextAction;
|
||||
QAction *m_closeAllEditorsContextAction;
|
||||
QAction *m_closeOtherEditorsContextAction;
|
||||
QAction *m_closeAllEditorsExceptVisibleContextAction;
|
||||
QAction *m_openGraphicalShellAction;
|
||||
QAction *m_openTerminalAction;
|
||||
QAction *m_findInDirectoryAction;
|
||||
DocumentModel::Entry *m_contextMenuEntry;
|
||||
|
||||
Internal::OpenEditorsWindow *m_windowPopup;
|
||||
Internal::EditorClosingCoreListener *m_coreListener;
|
||||
|
||||
QMap<QString, QVariant> m_editorStates;
|
||||
Internal::OpenEditorsViewFactory *m_openEditorsFactory;
|
||||
|
||||
IDocument::ReloadSetting m_reloadSetting;
|
||||
|
||||
QString m_titleAddition;
|
||||
QString m_titleVcsTopic;
|
||||
|
||||
bool m_autoSaveEnabled;
|
||||
int m_autoSaveInterval;
|
||||
};
|
||||
}
|
||||
|
||||
EditorManagerPrivate::EditorManagerPrivate(QWidget *parent) :
|
||||
EditorManagerPrivate::EditorManagerPrivate(QObject *parent) :
|
||||
m_autoSaveTimer(0),
|
||||
m_revertToSavedAction(new QAction(EditorManager::tr("Revert to Saved"), parent)),
|
||||
m_saveAction(new QAction(parent)),
|
||||
@@ -252,13 +195,15 @@ EditorManagerPrivate::~EditorManagerPrivate()
|
||||
DocumentModel::destroy();
|
||||
}
|
||||
|
||||
static EditorManager *m_instance = 0;
|
||||
static EditorManagerPrivate *d;
|
||||
QWidget *EditorManagerPrivate::rootWidget()
|
||||
{
|
||||
return d->m_root.at(0);
|
||||
}
|
||||
|
||||
EditorManager *EditorManager::instance() { return m_instance; }
|
||||
|
||||
EditorManager::EditorManager(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
EditorManager::EditorManager(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
d = new EditorManagerPrivate(parent);
|
||||
m_instance = this;
|
||||
@@ -425,18 +370,16 @@ EditorManager::EditorManager(QWidget *parent) :
|
||||
|
||||
// other setup
|
||||
SplitterOrView *firstRoot = new SplitterOrView();
|
||||
firstRoot->hide();
|
||||
connect(firstRoot, SIGNAL(destroyed(QObject*)), m_instance, SLOT(rootDestroyed(QObject*)));
|
||||
d->m_root.append(firstRoot);
|
||||
d->m_rootContext.append(0);
|
||||
d->m_currentView = firstRoot->view();
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
layout->setMargin(0);
|
||||
layout->setSpacing(0);
|
||||
layout->addWidget(firstRoot);
|
||||
|
||||
updateActions();
|
||||
|
||||
d->m_windowPopup = new OpenEditorsWindow(this);
|
||||
d->m_windowPopup = new OpenEditorsWindow;
|
||||
d->m_windowPopup->hide();
|
||||
|
||||
d->m_autoSaveTimer = new QTimer(this);
|
||||
connect(d->m_autoSaveTimer, SIGNAL(timeout()), SLOT(autoSave()));
|
||||
@@ -456,16 +399,19 @@ EditorManager::~EditorManager()
|
||||
}
|
||||
|
||||
// close all extra windows
|
||||
for (int i = 1; i < d->m_root.size(); ++i) {
|
||||
for (int i = 0; i < d->m_root.size(); ++i) {
|
||||
SplitterOrView *root = d->m_root.at(i);
|
||||
disconnect(root, SIGNAL(destroyed(QObject*)), this, SLOT(rootDestroyed(QObject*)));
|
||||
IContext *rootContext = d->m_rootContext.at(i);
|
||||
ICore::removeContextObject(rootContext);
|
||||
if (rootContext) {
|
||||
ICore::removeContextObject(rootContext);
|
||||
delete rootContext;
|
||||
}
|
||||
delete root;
|
||||
delete rootContext;
|
||||
}
|
||||
d->m_root.clear();
|
||||
d->m_rootContext.clear();
|
||||
delete d->m_windowPopup;
|
||||
|
||||
delete d;
|
||||
}
|
||||
@@ -2051,10 +1997,10 @@ void EditorManager::updateActions()
|
||||
|
||||
if (curDocument) {
|
||||
if (HostOsInfo::isMacHost())
|
||||
m_instance->window()->setWindowModified(curDocument->isModified());
|
||||
d->rootWidget()->window()->setWindowModified(curDocument->isModified());
|
||||
updateMakeWritableWarning();
|
||||
} else /* curEditor */ if (HostOsInfo::isMacHost()) {
|
||||
m_instance->window()->setWindowModified(false);
|
||||
d->rootWidget()->window()->setWindowModified(false);
|
||||
}
|
||||
|
||||
foreach (SplitterOrView *root, d->m_root)
|
||||
|
@@ -85,7 +85,7 @@ private:
|
||||
Core::IMode *m_mode;
|
||||
};
|
||||
|
||||
class CORE_EXPORT EditorManager : public QWidget
|
||||
class CORE_EXPORT EditorManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -251,7 +251,7 @@ public slots:
|
||||
static void gotoOtherSplit();
|
||||
|
||||
private:
|
||||
explicit EditorManager(QWidget *parent);
|
||||
explicit EditorManager(QObject *parent);
|
||||
~EditorManager();
|
||||
static void init();
|
||||
|
||||
|
121
src/plugins/coreplugin/editormanager/editormanager_p.h
Normal file
121
src/plugins/coreplugin/editormanager/editormanager_p.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** 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
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef EDITORMANAGER_P_H
|
||||
#define EDITORMANAGER_P_H
|
||||
|
||||
#include "idocument.h"
|
||||
#include "documentmodel.h"
|
||||
#include "editorview.h"
|
||||
#include "ieditor.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
class QTimer;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
namespace Internal {
|
||||
|
||||
class EditorClosingCoreListener;
|
||||
class OpenEditorsViewFactory;
|
||||
class OpenEditorsWindow;
|
||||
|
||||
class EditorManagerPrivate
|
||||
{
|
||||
public:
|
||||
explicit EditorManagerPrivate(QObject *parent);
|
||||
~EditorManagerPrivate();
|
||||
|
||||
static QWidget *rootWidget();
|
||||
|
||||
QList<EditLocation> m_globalHistory;
|
||||
QList<SplitterOrView *> m_root;
|
||||
QList<IContext *> m_rootContext;
|
||||
QPointer<IEditor> m_currentEditor;
|
||||
QPointer<IEditor> m_scheduledCurrentEditor;
|
||||
QPointer<EditorView> m_currentView;
|
||||
QTimer *m_autoSaveTimer;
|
||||
|
||||
// actions
|
||||
QAction *m_revertToSavedAction;
|
||||
QAction *m_saveAction;
|
||||
QAction *m_saveAsAction;
|
||||
QAction *m_closeCurrentEditorAction;
|
||||
QAction *m_closeAllEditorsAction;
|
||||
QAction *m_closeOtherEditorsAction;
|
||||
QAction *m_closeAllEditorsExceptVisibleAction;
|
||||
QAction *m_gotoNextDocHistoryAction;
|
||||
QAction *m_gotoPreviousDocHistoryAction;
|
||||
QAction *m_goBackAction;
|
||||
QAction *m_goForwardAction;
|
||||
QAction *m_splitAction;
|
||||
QAction *m_splitSideBySideAction;
|
||||
QAction *m_splitNewWindowAction;
|
||||
QAction *m_removeCurrentSplitAction;
|
||||
QAction *m_removeAllSplitsAction;
|
||||
QAction *m_gotoNextSplitAction;
|
||||
|
||||
QAction *m_saveCurrentEditorContextAction;
|
||||
QAction *m_saveAsCurrentEditorContextAction;
|
||||
QAction *m_revertToSavedCurrentEditorContextAction;
|
||||
|
||||
QAction *m_closeCurrentEditorContextAction;
|
||||
QAction *m_closeAllEditorsContextAction;
|
||||
QAction *m_closeOtherEditorsContextAction;
|
||||
QAction *m_closeAllEditorsExceptVisibleContextAction;
|
||||
QAction *m_openGraphicalShellAction;
|
||||
QAction *m_openTerminalAction;
|
||||
QAction *m_findInDirectoryAction;
|
||||
DocumentModel::Entry *m_contextMenuEntry;
|
||||
|
||||
OpenEditorsWindow *m_windowPopup;
|
||||
EditorClosingCoreListener *m_coreListener;
|
||||
|
||||
QMap<QString, QVariant> m_editorStates;
|
||||
OpenEditorsViewFactory *m_openEditorsFactory;
|
||||
|
||||
IDocument::ReloadSetting m_reloadSetting;
|
||||
|
||||
QString m_titleAddition;
|
||||
QString m_titleVcsTopic;
|
||||
|
||||
bool m_autoSaveEnabled;
|
||||
int m_autoSaveInterval;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
} // Core
|
||||
|
||||
#endif // EDITORMANAGER_P_H
|
@@ -278,7 +278,7 @@ void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
|
||||
{
|
||||
d->m_isStandalone = flags & FlagsStandalone;
|
||||
if (d->m_isStandalone) {
|
||||
QWidget *em = EditorManager::instance();
|
||||
EditorManager *em = EditorManager::instance();
|
||||
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)), SLOT(updateEditorListSelection(Core::IEditor*)));
|
||||
|
||||
disconnect(d->m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int)));
|
||||
|
@@ -189,7 +189,6 @@ MainWindow::MainWindow() :
|
||||
m_statusBarManager = new StatusBarManager(this);
|
||||
m_messageManager = new MessageManager;
|
||||
m_editorManager = new EditorManager(this);
|
||||
m_editorManager->hide();
|
||||
m_externalToolManager = new ExternalToolManager();
|
||||
setCentralWidget(m_modeStack);
|
||||
|
||||
|
@@ -443,7 +443,8 @@ QWidget *DebuggerMainWindow::createContents(IMode *mode)
|
||||
|
||||
QWidget *editorAndFindWidget = new QWidget;
|
||||
editorAndFindWidget->setLayout(editorHolderLayout);
|
||||
editorHolderLayout->addWidget(new EditorManagerPlaceHolder(mode));
|
||||
auto editorManagerPlaceHolder = new EditorManagerPlaceHolder(mode);
|
||||
editorHolderLayout->addWidget(editorManagerPlaceHolder);
|
||||
editorHolderLayout->addWidget(new FindToolBarPlaceHolder(editorAndFindWidget));
|
||||
|
||||
MiniSplitter *documentAndRightPane = new MiniSplitter;
|
||||
@@ -502,6 +503,7 @@ QWidget *DebuggerMainWindow::createContents(IMode *mode)
|
||||
|
||||
// Navigation and right-side window.
|
||||
MiniSplitter *splitter = new MiniSplitter;
|
||||
splitter->setFocusProxy(editorManagerPlaceHolder);
|
||||
splitter->addWidget(new NavigationWidgetPlaceHolder(mode));
|
||||
splitter->addWidget(mainWindowSplitter);
|
||||
splitter->setStretchFactor(0, 0);
|
||||
|
@@ -3292,7 +3292,6 @@ void DebuggerPluginPrivate::extensionsInitialized()
|
||||
modeContextObject->setContext(Core::Context(CC::C_EDITORMANAGER));
|
||||
modeContextObject->setWidget(widget);
|
||||
Core::ICore::addContextObject(modeContextObject);
|
||||
widget->setFocusProxy(EditorManager::instance());
|
||||
debugMode->setWidget(widget);
|
||||
|
||||
m_plugin->addAutoReleasedObject(debugMode);
|
||||
|
@@ -39,6 +39,7 @@
|
||||
#include "addlibrarywizard.h"
|
||||
#include "wizards/qtquickapp.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/buildmanager.h>
|
||||
#include <projectexplorer/session.h>
|
||||
@@ -146,7 +147,7 @@ void QmakeManager::addLibraryContextMenu()
|
||||
|
||||
void QmakeManager::addLibrary(const QString &fileName, ProFileEditor *editor)
|
||||
{
|
||||
AddLibraryWizard wizard(fileName, Core::EditorManager::instance());
|
||||
AddLibraryWizard wizard(fileName, Core::ICore::dialogParent());
|
||||
if (wizard.exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
|
Reference in New Issue
Block a user