Editors: Create a EditorArea class

That manages its own context. Only the first step in supporting/fixing
things like window titles, and getting rid of the editor manager
placeholder.

Change-Id: I90e681d8470728f9fab4a04dd4d1e91d37c993f3
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
Eike Ziller
2014-07-22 12:49:45 +02:00
parent 9738422f6d
commit 04ad136022
6 changed files with 232 additions and 134 deletions

View File

@@ -28,6 +28,7 @@ SOURCES += mainwindow.cpp \
vcsmanager.cpp \ vcsmanager.cpp \
statusbarmanager.cpp \ statusbarmanager.cpp \
versiondialog.cpp \ versiondialog.cpp \
editormanager/editorarea.cpp \
editormanager/editormanager.cpp \ editormanager/editormanager.cpp \
editormanager/editorview.cpp \ editormanager/editorview.cpp \
editormanager/documentmodel.cpp \ editormanager/documentmodel.cpp \
@@ -117,6 +118,7 @@ HEADERS += mainwindow.h \
outputwindow.h \ outputwindow.h \
vcsmanager.h \ vcsmanager.h \
statusbarmanager.h \ statusbarmanager.h \
editormanager/editorarea.h \
editormanager/editormanager.h \ editormanager/editormanager.h \
editormanager/editormanager_p.h \ editormanager/editormanager_p.h \
editormanager/editorview.h \ editormanager/editorview.h \

View File

@@ -140,6 +140,7 @@ QtcPlugin {
files: [ files: [
"BinFiles.mimetypes.xml", "BinFiles.mimetypes.xml",
"documentmodel.cpp", "documentmodel.h", "documentmodel.cpp", "documentmodel.h",
"editorarea.cpp", "editorarea.h",
"editormanager.cpp", "editormanager.h", "editormanager_p.h", "editormanager.cpp", "editormanager.h", "editormanager_p.h",
"editorview.cpp", "editorview.h", "editorview.cpp", "editorview.h",
"ieditor.cpp", "ieditor.h", "ieditor.cpp", "ieditor.h",

View File

@@ -0,0 +1,54 @@
/****************************************************************************
**
** 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.
**
****************************************************************************/
#include "editorarea.h"
#include "coreconstants.h"
#include "icontext.h"
#include "icore.h"
namespace Core {
namespace Internal {
EditorArea::EditorArea()
{
m_context = new IContext;
m_context->setContext(Context(Constants::C_EDITORMANAGER));
m_context->setWidget(this);
ICore::addContextObject(m_context);
}
EditorArea::~EditorArea()
{
ICore::removeContextObject(m_context);
delete m_context;
}
} // Internal
} // Core

View File

@@ -0,0 +1,56 @@
/****************************************************************************
**
** 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 EDITORAREA_H
#define EDITORAREA_H
#include "editorview.h"
namespace Core {
class IContext;
namespace Internal {
class EditorArea : public SplitterOrView
{
Q_OBJECT
public:
EditorArea();
~EditorArea();
private:
IContext *m_context;
};
} // Internal
} // Core
#endif // EDITORAREA_H

View File

@@ -126,7 +126,7 @@ EditorManagerPlaceHolder::EditorManagerPlaceHolder(Core::IMode *mode, QWidget *p
{ {
setLayout(new QVBoxLayout); setLayout(new QVBoxLayout);
layout()->setMargin(0); layout()->setMargin(0);
setFocusProxy(EditorManagerPrivate::rootWidget()); setFocusProxy(EditorManagerPrivate::mainEditorArea());
connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)), connect(Core::ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)),
this, SLOT(currentModeChanged(Core::IMode*))); this, SLOT(currentModeChanged(Core::IMode*)));
@@ -136,7 +136,7 @@ EditorManagerPlaceHolder::EditorManagerPlaceHolder(Core::IMode *mode, QWidget *p
EditorManagerPlaceHolder::~EditorManagerPlaceHolder() EditorManagerPlaceHolder::~EditorManagerPlaceHolder()
{ {
// EditorManager will be deleted in ~MainWindow() // EditorManager will be deleted in ~MainWindow()
QWidget *em = EditorManagerPrivate::rootWidget(); QWidget *em = EditorManagerPrivate::mainEditorArea();
if (em && em->parent() == this) { if (em && em->parent() == this) {
em->hide(); em->hide();
em->setParent(0); em->setParent(0);
@@ -147,7 +147,7 @@ void EditorManagerPlaceHolder::currentModeChanged(Core::IMode *mode)
{ {
if (m_mode == mode) { if (m_mode == mode) {
QWidget *previousFocus = 0; QWidget *previousFocus = 0;
QWidget *em = EditorManagerPrivate::rootWidget(); QWidget *em = EditorManagerPrivate::mainEditorArea();
if (em->focusWidget() && em->focusWidget()->hasFocus()) if (em->focusWidget() && em->focusWidget()->hasFocus())
previousFocus = em->focusWidget(); previousFocus = em->focusWidget();
layout()->addWidget(em); layout()->addWidget(em);
@@ -263,18 +263,12 @@ EditorManagerPrivate::~EditorManagerPrivate()
} }
// close all extra windows // close all extra windows
for (int i = 0; i < m_root.size(); ++i) { for (int i = 0; i < m_editorAreas.size(); ++i) {
SplitterOrView *root = m_root.at(i); EditorArea *area = m_editorAreas.at(i);
disconnect(root, SIGNAL(destroyed(QObject*)), this, SLOT(rootDestroyed(QObject*))); disconnect(area, SIGNAL(destroyed(QObject*)), this, SLOT(editorAreaDestroyed(QObject*)));
IContext *rootContext = m_rootContext.at(i); delete area;
if (rootContext) {
ICore::removeContextObject(rootContext);
delete rootContext;
} }
delete root; m_editorAreas.clear();
}
m_root.clear();
m_rootContext.clear();
delete m_windowPopup; delete m_windowPopup;
DocumentModel::destroy(); DocumentModel::destroy();
@@ -454,12 +448,11 @@ void EditorManagerPrivate::init()
advancedMenu->addSeparator(editManagerContext, Constants::G_EDIT_EDITOR); advancedMenu->addSeparator(editManagerContext, Constants::G_EDIT_EDITOR);
// other setup // other setup
SplitterOrView *firstRoot = new SplitterOrView(); auto mainEditorArea = new EditorArea();
firstRoot->hide(); mainEditorArea->hide();
connect(firstRoot, SIGNAL(destroyed(QObject*)), this, SLOT(rootDestroyed(QObject*))); connect(mainEditorArea, SIGNAL(destroyed(QObject*)), this, SLOT(editorAreaDestroyed(QObject*)));
m_root.append(firstRoot); d->m_editorAreas.append(mainEditorArea);
m_rootContext.append(0); d->m_currentView = mainEditorArea->view();
m_currentView = firstRoot->view();
updateActions(); updateActions();
@@ -497,9 +490,9 @@ void EditorManagerPrivate::init()
}); });
} }
QWidget *EditorManagerPrivate::rootWidget() QWidget *EditorManagerPrivate::mainEditorArea()
{ {
return d->m_root.at(0); return d->m_editorAreas.at(0);
} }
IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileName, Id editorId, IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileName, Id editorId,
@@ -707,22 +700,22 @@ void EditorManagerPrivate::showPopupOrSelectDocument()
} else { } else {
QWidget *activeWindow = qApp->activeWindow(); QWidget *activeWindow = qApp->activeWindow();
// decide where to show the popup // decide where to show the popup
// if the active window has editors, we want that root as a reference // if the active window has editors, we want that editor area as a reference
// TODO: this does not work correctly with multiple roots in the same window // TODO: this does not work correctly with multiple editor areas in the same window
SplitterOrView *activeRoot = 0; EditorArea *activeEditorArea = 0;
foreach (SplitterOrView *root, d->m_root) { foreach (EditorArea *area, d->m_editorAreas) {
if (root->window() == activeWindow) { if (area->window() == activeWindow) {
activeRoot = root; activeEditorArea = area;
break; break;
} }
} }
// otherwise we take the "current" root // otherwise we take the "current" editor area
if (!activeRoot) if (!activeEditorArea)
activeRoot = findRoot(EditorManagerPrivate::currentEditorView()); activeEditorArea = findEditorArea(EditorManagerPrivate::currentEditorView());
QTC_ASSERT(activeRoot, activeRoot = d->m_root.first()); QTC_ASSERT(activeEditorArea, activeEditorArea = d->m_editorAreas.first());
// root in main window is invisible when invoked from Design Mode. // editor area in main window is invisible when invoked from Design Mode.
QWidget *referenceWidget = activeRoot->isVisible() ? activeRoot : activeRoot->window(); QWidget *referenceWidget = activeEditorArea->isVisible() ? activeEditorArea : activeEditorArea->window();
QTC_CHECK(referenceWidget->isVisible()); QTC_CHECK(referenceWidget->isVisible());
const QPoint p = referenceWidget->mapToGlobal(QPoint(0, 0)); const QPoint p = referenceWidget->mapToGlobal(QPoint(0, 0));
OpenEditorsWindow *popup = windowPopup(); OpenEditorsWindow *popup = windowPopup();
@@ -985,9 +978,9 @@ IEditor *EditorManagerPrivate::activateEditor(EditorView *view, IEditor *editor,
ModeManager::activateMode(Core::Constants::MODE_DESIGN); ModeManager::activateMode(Core::Constants::MODE_DESIGN);
ModeManager::setFocusToCurrentMode(); ModeManager::setFocusToCurrentMode();
} else { } else {
int rootIndex; int index;
findRoot(view, &rootIndex); findEditorArea(view, &index);
if (rootIndex == 0) // main window --> we might need to switch mode if (index == 0) // main window --> we might need to switch mode
if (!editor->widget()->isVisible()) if (!editor->widget()->isVisible())
ModeManager::activateMode(Core::Constants::MODE_EDIT); ModeManager::activateMode(Core::Constants::MODE_EDIT);
editor->widget()->setFocus(); editor->widget()->setFocus();
@@ -1094,19 +1087,20 @@ void EditorManagerPrivate::setCurrentView(EditorView *view)
} }
} }
SplitterOrView *EditorManagerPrivate::findRoot(const EditorView *view, int *rootIndex) EditorArea *EditorManagerPrivate::findEditorArea(const EditorView *view, int *areaIndex)
{ {
SplitterOrView *current = view->parentSplitterOrView(); SplitterOrView *current = view->parentSplitterOrView();
while (current) { while (current) {
int index = d->m_root.indexOf(current); if (EditorArea *area = qobject_cast<EditorArea *>(current)) {
if (index >= 0) { int index = d->m_editorAreas.indexOf(area);
if (rootIndex) QTC_ASSERT(index >= 0, return 0);
*rootIndex = index; if (areaIndex)
return current; *areaIndex = index;
return area;
} }
current = current->findParentSplitter(); current = current->findParentSplitter();
} }
QTC_CHECK(false); // we should never have views without a root QTC_CHECK(false); // we should never have views without a editor area
return 0; return 0;
} }
@@ -1169,39 +1163,33 @@ void EditorManagerPrivate::emptyView(EditorView *view)
void EditorManagerPrivate::splitNewWindow(EditorView *view) void EditorManagerPrivate::splitNewWindow(EditorView *view)
{ {
SplitterOrView *splitter;
IEditor *editor = view->currentEditor(); IEditor *editor = view->currentEditor();
IEditor *newEditor = 0; IEditor *newEditor = 0;
if (editor && editor->duplicateSupported()) if (editor && editor->duplicateSupported())
newEditor = EditorManagerPrivate::duplicateEditor(editor); newEditor = EditorManagerPrivate::duplicateEditor(editor);
else else
newEditor = editor; // move to the new view newEditor = editor; // move to the new view
splitter = new SplitterOrView; auto area = new EditorArea;
QWidget *win = new QWidget; QWidget *win = new QWidget;
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0); layout->setMargin(0);
layout->setSpacing(0); layout->setSpacing(0);
win->setLayout(layout); win->setLayout(layout);
layout->addWidget(splitter); layout->addWidget(area);
win->setFocusProxy(splitter); win->setFocusProxy(area);
win->setAttribute(Qt::WA_DeleteOnClose); win->setAttribute(Qt::WA_DeleteOnClose);
win->setAttribute(Qt::WA_QuitOnClose, false); // don't prevent Qt Creator from closing win->setAttribute(Qt::WA_QuitOnClose, false); // don't prevent Qt Creator from closing
win->resize(QSize(800, 600)); win->resize(QSize(800, 600));
static int windowId = 0; static int windowId = 0;
ICore::registerWindow(win, Context(Id("EditorManager.ExternalWindow.").withSuffix(++windowId))); ICore::registerWindow(win, Context(Id("EditorManager.ExternalWindow.").withSuffix(++windowId)));
IContext *context = new IContext; d->m_editorAreas.append(area);
context->setContext(Context(Constants::C_EDITORMANAGER)); connect(area, SIGNAL(destroyed(QObject*)), d, SLOT(editorAreaDestroyed(QObject*)));
context->setWidget(splitter);
ICore::addContextObject(context);
d->m_root.append(splitter);
d->m_rootContext.append(context);
connect(splitter, SIGNAL(destroyed(QObject*)), d, SLOT(rootDestroyed(QObject*)));
win->show(); win->show();
ICore::raiseWindow(win); ICore::raiseWindow(win);
if (newEditor) if (newEditor)
activateEditor(splitter->view(), newEditor, EditorManager::IgnoreNavigationHistory); activateEditor(area->view(), newEditor, EditorManager::IgnoreNavigationHistory);
else else
splitter->view()->setFocus(); area->view()->setFocus();
updateActions(); updateActions();
} }
@@ -1320,14 +1308,14 @@ void EditorManagerPrivate::updateActions()
if (curDocument) { if (curDocument) {
if (HostOsInfo::isMacHost()) if (HostOsInfo::isMacHost())
rootWidget()->window()->setWindowModified(curDocument->isModified()); mainEditorArea()->window()->setWindowModified(curDocument->isModified());
updateMakeWritableWarning(); updateMakeWritableWarning();
} else /* curEditor */ if (HostOsInfo::isMacHost()) { } else /* curEditor */ if (HostOsInfo::isMacHost()) {
rootWidget()->window()->setWindowModified(false); mainEditorArea()->window()->setWindowModified(false);
} }
foreach (SplitterOrView *root, d->m_root) foreach (EditorArea *area, d->m_editorAreas)
setCloseSplitEnabled(root, root->isSplitter()); setCloseSplitEnabled(area, area->isSplitter());
QString quotedName; QString quotedName;
if (curDocument) if (curDocument)
@@ -1353,7 +1341,7 @@ void EditorManagerPrivate::updateActions()
bool hasSplitter = parentSplitter && parentSplitter->isSplitter(); bool hasSplitter = parentSplitter && parentSplitter->isSplitter();
d->m_removeCurrentSplitAction->setEnabled(hasSplitter); d->m_removeCurrentSplitAction->setEnabled(hasSplitter);
d->m_removeAllSplitsAction->setEnabled(hasSplitter); d->m_removeAllSplitsAction->setEnabled(hasSplitter);
d->m_gotoNextSplitAction->setEnabled(hasSplitter || d->m_root.size() > 1); d->m_gotoNextSplitAction->setEnabled(hasSplitter || d->m_editorAreas.size() > 1);
} }
void EditorManagerPrivate::updateWindowTitle() void EditorManagerPrivate::updateWindowTitle()
@@ -1417,16 +1405,16 @@ void EditorManagerPrivate::gotoNextSplit()
return; return;
EditorView *nextView = view->findNextView(); EditorView *nextView = view->findNextView();
if (!nextView) { if (!nextView) {
// we are in the "last" view in this root // we are in the "last" view in this editor area
int rootIndex = -1; int index = -1;
SplitterOrView *root = findRoot(view, &rootIndex); EditorArea *area = findEditorArea(view, &index);
QTC_ASSERT(root, return); QTC_ASSERT(area, return);
QTC_ASSERT(rootIndex >= 0 && rootIndex < d->m_root.size(), return); QTC_ASSERT(index >= 0 && index < d->m_editorAreas.size(), return);
// find next root. this might be the same root if there's only one. // find next editor area. this might be the same editor area if there's only one.
int nextRootIndex = rootIndex + 1; int nextIndex = index + 1;
if (nextRootIndex >= d->m_root.size()) if (nextIndex >= d->m_editorAreas.size())
nextRootIndex = 0; nextIndex = 0;
nextView = d->m_root.at(nextRootIndex)->findFirstView(); nextView = d->m_editorAreas.at(nextIndex)->findFirstView();
QTC_CHECK(nextView); QTC_CHECK(nextView);
} }
@@ -1470,46 +1458,43 @@ void EditorManagerPrivate::handleDocumentStateChange()
} }
} }
void EditorManagerPrivate::rootDestroyed(QObject *root) void EditorManagerPrivate::editorAreaDestroyed(QObject *area)
{ {
QWidget *activeWin = qApp->activeWindow(); QWidget *activeWin = qApp->activeWindow();
SplitterOrView *newActiveRoot = 0; EditorArea *newActiveArea = 0;
for (int i = 0; i < d->m_root.size(); ++i) { for (int i = 0; i < d->m_editorAreas.size(); ++i) {
SplitterOrView *r = d->m_root.at(i); EditorArea *r = d->m_editorAreas.at(i);
if (r == root) { if (r == area) {
d->m_root.removeAt(i); d->m_editorAreas.removeAt(i);
IContext *context = d->m_rootContext.takeAt(i);
ICore::removeContextObject(context);
delete context;
--i; // we removed the current one --i; // we removed the current one
} else if (r->window() == activeWin) { } else if (r->window() == activeWin) {
newActiveRoot = r; newActiveArea = r;
} }
} }
// check if the destroyed root had the current view or current editor // check if the destroyed editor area had the current view or current editor
if (d->m_currentEditor || (d->m_currentView && d->m_currentView->parentSplitterOrView() != root)) if (d->m_currentEditor || (d->m_currentView && d->m_currentView->parentSplitterOrView() != area))
return; return;
// we need to set a new current editor or view // we need to set a new current editor or view
if (!newActiveRoot) { if (!newActiveArea) {
// some window managers behave weird and don't activate another window // some window managers behave weird and don't activate another window
// or there might be a Qt Creator toplevel activated that doesn't have editor windows // or there might be a Qt Creator toplevel activated that doesn't have editor windows
newActiveRoot = d->m_root.first(); newActiveArea = d->m_editorAreas.first();
} }
// check if the focusWidget points to some view // check if the focusWidget points to some view
SplitterOrView *focusSplitterOrView = 0; SplitterOrView *focusSplitterOrView = 0;
QWidget *candidate = newActiveRoot->focusWidget(); QWidget *candidate = newActiveArea->focusWidget();
while (candidate && candidate != newActiveRoot) { while (candidate && candidate != newActiveArea) {
if ((focusSplitterOrView = qobject_cast<SplitterOrView *>(candidate))) if ((focusSplitterOrView = qobject_cast<SplitterOrView *>(candidate)))
break; break;
candidate = candidate->parentWidget(); candidate = candidate->parentWidget();
} }
// focusWidget might have been 0 // focusWidget might have been 0
if (!focusSplitterOrView) if (!focusSplitterOrView)
focusSplitterOrView = newActiveRoot->findFirstView()->parentSplitterOrView(); focusSplitterOrView = newActiveArea->findFirstView()->parentSplitterOrView();
QTC_ASSERT(focusSplitterOrView, focusSplitterOrView = newActiveRoot); QTC_ASSERT(focusSplitterOrView, focusSplitterOrView = newActiveArea);
EditorView *focusView = focusSplitterOrView->findFirstView(); // can be just focusSplitterOrView EditorView *focusView = focusSplitterOrView->findFirstView(); // can be just focusSplitterOrView
QTC_ASSERT(focusView, focusView = newActiveRoot->findFirstView()); QTC_ASSERT(focusView, focusView = newActiveArea->findFirstView());
QTC_ASSERT(focusView, return); QTC_ASSERT(focusView, return);
if (focusView->currentEditor()) if (focusView->currentEditor())
setCurrentEditor(focusView->currentEditor()); setCurrentEditor(focusView->currentEditor());
@@ -1746,7 +1731,7 @@ void EditorManagerPrivate::removeCurrentSplit()
EditorView *viewToClose = currentEditorView(); EditorView *viewToClose = currentEditorView();
QTC_ASSERT(viewToClose, return); QTC_ASSERT(viewToClose, return);
QTC_ASSERT(!d->m_root.contains(viewToClose->parentSplitterOrView()), return); QTC_ASSERT(!qobject_cast<EditorArea *>(viewToClose->parentSplitterOrView()), return);
closeView(viewToClose); closeView(viewToClose);
updateActions(); updateActions();
@@ -1756,9 +1741,9 @@ void EditorManagerPrivate::removeAllSplits()
{ {
EditorView *view = currentEditorView(); EditorView *view = currentEditorView();
QTC_ASSERT(view, return); QTC_ASSERT(view, return);
SplitterOrView *root = findRoot(view); EditorArea *currentArea = findEditorArea(view);
QTC_ASSERT(root, return); QTC_ASSERT(currentArea, return);
root->unsplitAll(); currentArea->unsplitAll();
} }
void EditorManagerPrivate::setCurrentEditorFromContextChange() void EditorManagerPrivate::setCurrentEditorFromContextChange()
@@ -1779,17 +1764,17 @@ EditorView *EditorManagerPrivate::currentEditorView()
if (!view) { if (!view) {
if (d->m_currentEditor) { if (d->m_currentEditor) {
view = EditorManagerPrivate::viewForEditor(d->m_currentEditor); view = EditorManagerPrivate::viewForEditor(d->m_currentEditor);
QTC_ASSERT(view, view = d->m_root.first()->findFirstView()); QTC_ASSERT(view, view = d->m_editorAreas.first()->findFirstView());
} }
QTC_CHECK(view); QTC_CHECK(view);
if (!view) { // should not happen, we should always have either currentview or currentdocument if (!view) { // should not happen, we should always have either currentview or currentdocument
foreach (SplitterOrView *root, d->m_root) { foreach (EditorArea *area, d->m_editorAreas) {
if (root->window()->isActiveWindow()) { if (area->window()->isActiveWindow()) {
view = root->findFirstView(); view = area->findFirstView();
break; break;
} }
} }
QTC_ASSERT(view, view = d->m_root.first()->findFirstView()); QTC_ASSERT(view, view = d->m_editorAreas.first()->findFirstView());
} }
} }
return view; return view;
@@ -2306,17 +2291,17 @@ bool EditorManager::hasSplitter()
{ {
EditorView *view = EditorManagerPrivate::currentEditorView(); EditorView *view = EditorManagerPrivate::currentEditorView();
QTC_ASSERT(view, return false); QTC_ASSERT(view, return false);
SplitterOrView *root = EditorManagerPrivate::findRoot(view); EditorArea *area = EditorManagerPrivate::findEditorArea(view);
QTC_ASSERT(root, return false); QTC_ASSERT(area, return false);
return root->isSplitter(); return area->isSplitter();
} }
QList<IEditor*> EditorManager::visibleEditors() QList<IEditor*> EditorManager::visibleEditors()
{ {
QList<IEditor *> editors; QList<IEditor *> editors;
foreach (SplitterOrView *root, d->m_root) { foreach (EditorArea *area, d->m_editorAreas) {
if (root->isSplitter()) { if (area->isSplitter()) {
EditorView *firstView = root->findFirstView(); EditorView *firstView = area->findFirstView();
EditorView *view = firstView; EditorView *view = firstView;
if (view) { if (view) {
do { do {
@@ -2327,8 +2312,8 @@ QList<IEditor*> EditorManager::visibleEditors()
} while (view); } while (view);
} }
} else { } else {
if (root->editor()) if (area->editor())
editors.append(root->editor()); editors.append(area->editor());
} }
} }
return editors; return editors;
@@ -2400,7 +2385,7 @@ QByteArray EditorManager::saveState()
stream << entry->fileName() << entry->displayName() << entry->id(); stream << entry->fileName() << entry->displayName() << entry->id();
} }
stream << d->m_root.first()->saveState(); // TODO stream << d->m_editorAreas.first()->saveState(); // TODO
return bytes; return bytes;
} }
@@ -2409,9 +2394,9 @@ bool EditorManager::restoreState(const QByteArray &state)
{ {
closeAllEditors(true); closeAllEditors(true);
// remove extra windows // remove extra windows
for (int i = d->m_root.count() - 1; i > 0 /* keep first alive */; --i) for (int i = d->m_editorAreas.count() - 1; i > 0 /* keep first alive */; --i)
delete d->m_root.at(i); // automatically removes it from list delete d->m_editorAreas.at(i); // automatically removes it from list
if (d->m_root.first()->isSplitter()) if (d->m_editorAreas.first()->isSplitter())
EditorManagerPrivate::removeAllSplits(); EditorManagerPrivate::removeAllSplits();
QDataStream stream(state); QDataStream stream(state);
@@ -2449,7 +2434,7 @@ bool EditorManager::restoreState(const QByteArray &state)
QByteArray splitterstates; QByteArray splitterstates;
stream >> splitterstates; stream >> splitterstates;
d->m_root.first()->restoreState(splitterstates); // TODO d->m_editorAreas.first()->restoreState(splitterstates); // TODO
// splitting and stuff results in focus trouble, that's why we set the focus again after restoration // splitting and stuff results in focus trouble, that's why we set the focus again after restoration
if (d->m_currentEditor) { if (d->m_currentEditor) {
@@ -2510,28 +2495,28 @@ void EditorManager::gotoOtherSplit()
return; return;
EditorView *nextView = view->findNextView(); EditorView *nextView = view->findNextView();
if (!nextView) { if (!nextView) {
// we are in the "last" view in this root // we are in the "last" view in this editor area
int rootIndex = -1; int index = -1;
SplitterOrView *root = EditorManagerPrivate::findRoot(view, &rootIndex); EditorArea *area = EditorManagerPrivate::findEditorArea(view, &index);
QTC_ASSERT(root, return); QTC_ASSERT(area, return);
QTC_ASSERT(rootIndex >= 0 && rootIndex < d->m_root.size(), return); QTC_ASSERT(index >= 0 && index < d->m_editorAreas.size(), return);
// stay in same window if it is split // stay in same window if it is split
if (root->isSplitter()) { if (area->isSplitter()) {
nextView = root->findFirstView(); nextView = area->findFirstView();
QTC_CHECK(nextView != view); QTC_CHECK(nextView != view);
} else { } else {
// find next root. this might be the same root if there's only one. // find next editor area. this might be the same editor area if there's only one.
int nextRootIndex = rootIndex + 1; int nextIndex = index + 1;
if (nextRootIndex >= d->m_root.size()) if (nextIndex >= d->m_editorAreas.size())
nextRootIndex = 0; nextIndex = 0;
nextView = d->m_root.at(nextRootIndex)->findFirstView(); nextView = d->m_editorAreas.at(nextIndex)->findFirstView();
QTC_CHECK(nextView); QTC_CHECK(nextView);
// if we had only one root with only one view, we end up at the startpoint // if we had only one editor area with only one view, we end up at the startpoint
// in that case we need to split // in that case we need to split
if (nextView == view) { if (nextView == view) {
QTC_CHECK(!root->isSplitter()); QTC_CHECK(!area->isSplitter());
splitSideBySide(); // that deletes 'view' splitSideBySide(); // that deletes 'view'
view = root->findFirstView(); view = area->findFirstView();
nextView = view->findNextView(); nextView = view->findNextView();
QTC_CHECK(nextView != view); QTC_CHECK(nextView != view);
QTC_CHECK(nextView); QTC_CHECK(nextView);

View File

@@ -30,10 +30,11 @@
#ifndef EDITORMANAGER_P_H #ifndef EDITORMANAGER_P_H
#define EDITORMANAGER_P_H #define EDITORMANAGER_P_H
#include "idocument.h"
#include "documentmodel.h" #include "documentmodel.h"
#include "editorarea.h"
#include "editormanager.h" #include "editormanager.h"
#include "editorview.h" #include "editorview.h"
#include "idocument.h"
#include "ieditor.h" #include "ieditor.h"
#include <QList> #include <QList>
@@ -65,7 +66,7 @@ class EditorManagerPrivate : public QObject
friend class Core::EditorManager; friend class Core::EditorManager;
public: public:
static QWidget *rootWidget(); static QWidget *mainEditorArea();
static EditorView *currentEditorView(); static EditorView *currentEditorView();
static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false); static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
static IEditor *openEditor(EditorView *view, static IEditor *openEditor(EditorView *view,
@@ -114,7 +115,7 @@ public slots:
static void gotoNextSplit(); static void gotoNextSplit();
void handleDocumentStateChange(); void handleDocumentStateChange();
static void rootDestroyed(QObject *root); static void editorAreaDestroyed(QObject *area);
private slots: private slots:
static void gotoNextDocHistory(); static void gotoNextDocHistory();
@@ -153,7 +154,7 @@ private:
static void activateView(EditorView *view); static void activateView(EditorView *view);
static void restoreEditorState(IEditor *editor); static void restoreEditorState(IEditor *editor);
static int visibleDocumentsCount(); static int visibleDocumentsCount();
static SplitterOrView *findRoot(const EditorView *view, int *rootIndex = 0); static EditorArea *findEditorArea(const EditorView *view, int *areaIndex = 0);
static IEditor *pickUnusedEditor(Internal::EditorView **foundView = 0); static IEditor *pickUnusedEditor(Internal::EditorView **foundView = 0);
static void addDocumentToRecentFiles(IDocument *document); static void addDocumentToRecentFiles(IDocument *document);
static void updateAutoSave(); static void updateAutoSave();
@@ -169,8 +170,7 @@ private:
void init(); void init();
QList<EditLocation> m_globalHistory; QList<EditLocation> m_globalHistory;
QList<SplitterOrView *> m_root; QList<EditorArea *> m_editorAreas;
QList<IContext *> m_rootContext;
QPointer<IEditor> m_currentEditor; QPointer<IEditor> m_currentEditor;
QPointer<IEditor> m_scheduledCurrentEditor; QPointer<IEditor> m_scheduledCurrentEditor;
QPointer<EditorView> m_currentView; QPointer<EditorView> m_currentView;