forked from qt-creator/qt-creator
more splitting works, fewer crashes
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "editormanager.h"
|
||||
#include "editorview.h"
|
||||
#include "openeditorswindow.h"
|
||||
#include "openeditorsview.h"
|
||||
#include "openwithdialog.h"
|
||||
#include "filemanager.h"
|
||||
#include "icore.h"
|
||||
@@ -137,6 +138,7 @@ struct EditorManagerPrivate {
|
||||
~EditorManagerPrivate();
|
||||
Internal::EditorView *m_view;
|
||||
Internal::SplitterOrView *m_splitter;
|
||||
QPointer<IEditor> m_currentEditor;
|
||||
QStackedLayout *m_stackedLayout;
|
||||
|
||||
ICore *m_core;
|
||||
@@ -495,6 +497,7 @@ void EditorManager::setCurrentEditor(IEditor *editor, bool ignoreNavigationHisto
|
||||
<< "ignore history?" << ignoreNavigationHistory;
|
||||
if (m_d->m_suppressEditorChanges)
|
||||
return;
|
||||
m_d->m_currentEditor = editor;
|
||||
if (editor) {
|
||||
bool addToHistory = (!ignoreNavigationHistory && editor != currentEditor());
|
||||
if (debugEditorManager)
|
||||
@@ -528,7 +531,7 @@ QList<IEditor *> EditorManager::editorsForFileName(const QString &filename) cons
|
||||
|
||||
IEditor *EditorManager::currentEditor() const
|
||||
{
|
||||
return m_d->m_view->currentEditor();
|
||||
return m_d->m_currentEditor;
|
||||
}
|
||||
|
||||
|
||||
@@ -555,7 +558,9 @@ void EditorManager::closeEditor(IEditor *editor)
|
||||
if (!editor)
|
||||
return;
|
||||
|
||||
qDebug() << "EditorManager::closeEditor";
|
||||
if (m_d->m_view->hasEditor(editor)) {
|
||||
qDebug() << "it's a main editor, do unsplit";
|
||||
unsplitAll();
|
||||
closeEditors(QList<IEditor *>() << editor);
|
||||
} else {
|
||||
@@ -688,6 +693,32 @@ void EditorManager::closeDuplicate(Core::IEditor *editor, bool doDelete)
|
||||
delete editor;
|
||||
}
|
||||
|
||||
void EditorManager::activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor)
|
||||
{
|
||||
Q_ASSERT(view && editor);
|
||||
Q_ASSERT(m_d->m_view->hasEditor(editor));
|
||||
|
||||
if (!editor->duplicateSupported()) {
|
||||
unsplitAll();
|
||||
view = m_d->m_view;
|
||||
}
|
||||
|
||||
if (view == m_d->m_view || view->hasEditor(editor)) {
|
||||
view->setCurrentEditor(editor);
|
||||
return;
|
||||
}
|
||||
QList<IEditor*> editors = view->editors();
|
||||
IEditor *duplicate = duplicateEditor(editor);
|
||||
view->addEditor(duplicate);
|
||||
view->setCurrentEditor(duplicate);
|
||||
foreach(IEditor *e, editors) {
|
||||
view->removeEditor(e);
|
||||
closeDuplicate(e, true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Find editors for a mimetype, best matching at the front
|
||||
* of the list. Recurse over the parent classes of the mimetype to
|
||||
* find them. */
|
||||
@@ -1299,6 +1330,11 @@ QByteArray EditorManager::saveState() const
|
||||
QList<IEditor *> editors = openedEditors();
|
||||
int editorCount = editors.count();
|
||||
|
||||
if (editors.contains(m_d->m_currentEditor)) {
|
||||
editors.removeAll(m_d->m_currentEditor);
|
||||
editors.prepend(m_d->m_currentEditor);
|
||||
}
|
||||
|
||||
qDebug() << "save editors:" << editorCount;
|
||||
|
||||
stream << editorCount;
|
||||
@@ -1341,12 +1377,14 @@ bool EditorManager::restoreState(const QByteArray &state)
|
||||
stream >> fileName;
|
||||
QByteArray kind;
|
||||
stream >> kind;
|
||||
openEditor(fileName, kind, true);
|
||||
IEditor *editor = openEditor(fileName, kind, true);
|
||||
if (!m_d->m_currentEditor)
|
||||
m_d->m_currentEditor = editor;
|
||||
}
|
||||
|
||||
m_d->m_suppressEditorChanges = editorChangesSuppressed;
|
||||
if (currentEditor())
|
||||
setCurrentEditor(currentEditor());// looks like a null-op but is not
|
||||
setCurrentEditor(m_d->m_currentEditor);
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
@@ -1517,7 +1555,8 @@ Core::IEditor *EditorManager::duplicateEditor(Core::IEditor *editor)
|
||||
return 0;
|
||||
|
||||
IEditor *duplicate = editor->duplicate(0);
|
||||
// TODO ### emit signals
|
||||
emit editorCreated(duplicate, duplicate->file()->fileName());
|
||||
emit editorOpened(duplicate);
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ struct EditorManagerPrivate;
|
||||
namespace Internal {
|
||||
class OpenEditorsWindow;
|
||||
class EditorModel;
|
||||
class EditorView;
|
||||
class SplitterOrView;
|
||||
|
||||
class EditorClosingCoreListener;
|
||||
@@ -217,11 +218,13 @@ private:
|
||||
|
||||
Core::IEditor *duplicateEditor(IEditor *editor);
|
||||
void closeDuplicate(Core::IEditor *editor, bool doDelete);
|
||||
void activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor);
|
||||
|
||||
static EditorManager *m_instance;
|
||||
EditorManagerPrivate *m_d;
|
||||
|
||||
friend class Core::Internal::SplitterOrView;
|
||||
friend class Core::Internal::EditorView;
|
||||
};
|
||||
|
||||
//===================EditorClosingCoreListener======================
|
||||
|
||||
@@ -234,7 +234,7 @@ EditorView::EditorView(EditorModel *model, QWidget *parent) :
|
||||
vlayout->addLayout(toplayout);
|
||||
tl->addWidget(top);
|
||||
|
||||
connect(m_editorList, SIGNAL(currentIndexChanged(int)), this, SLOT(listSelectionChanged(int)));
|
||||
connect(m_editorList, SIGNAL(activated(int)), this, SLOT(listSelectionActivated(int)));
|
||||
connect(m_lockButton, SIGNAL(clicked()), this, SLOT(makeEditorWritable()));
|
||||
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(sendCloseRequest()));
|
||||
}
|
||||
@@ -333,6 +333,11 @@ void EditorView::insertEditor(int index, IEditor *editor)
|
||||
m_toolBar->layout()->addWidget(toolBar);
|
||||
}
|
||||
connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
|
||||
|
||||
if (m_container->count() == 1) {
|
||||
updateToolBar(editor);
|
||||
updateEditorStatus(editor);
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorView::hasEditor(IEditor *editor) const
|
||||
@@ -379,18 +384,19 @@ void EditorView::setCurrentEditor(IEditor *editor)
|
||||
if (!editor || m_container->count() <= 0
|
||||
|| m_container->indexOf(editor->widget()) == -1)
|
||||
return;
|
||||
if (editor)
|
||||
qDebug() << "EditorView::setCurrentEditor" << editor->file()->fileName();
|
||||
const int idx = m_container->indexOf(editor->widget());
|
||||
QTC_ASSERT(idx >= 0, return);
|
||||
if (m_container->currentIndex() != idx) {
|
||||
m_container->setCurrentIndex(idx);
|
||||
disconnect(m_editorList, SIGNAL(currentIndexChanged(int)), this, SLOT(listSelectionChanged(int)));
|
||||
m_editorList->setCurrentIndex(qobject_cast<EditorModel*>(m_editorList->model())->indexOf(editor->file()->fileName()).row());
|
||||
connect(m_editorList, SIGNAL(currentIndexChanged(int)), this, SLOT(listSelectionChanged(int)));
|
||||
}
|
||||
setEditorFocus(idx);
|
||||
|
||||
updateEditorStatus(editor);
|
||||
updateToolBar(editor);
|
||||
|
||||
|
||||
if (editor != m_editorForInfoWidget) {
|
||||
m_infoWidget->hide();
|
||||
m_editorForInfoWidget = 0;
|
||||
@@ -455,10 +461,11 @@ void EditorView::makeEditorWritable()
|
||||
CoreImpl::instance()->editorManager()->makeEditorWritable(currentEditor());
|
||||
}
|
||||
|
||||
void EditorView::listSelectionChanged(int index)
|
||||
void EditorView::listSelectionActivated(int index)
|
||||
{
|
||||
QAbstractItemModel *model = m_editorList->model();
|
||||
setCurrentEditor(model->data(model->index(index, 0), Qt::UserRole).value<IEditor*>());
|
||||
IEditor *editor = model->data(model->index(index, 0), Qt::UserRole).value<IEditor*>();
|
||||
CoreImpl::instance()->editorManager()->activateEditor(this, editor);
|
||||
}
|
||||
|
||||
|
||||
@@ -480,7 +487,7 @@ SplitterOrView::SplitterOrView(Core::IEditor *editor, QWidget *parent)
|
||||
m_view = new EditorView(CoreImpl::instance()->editorManager()->openedEditorsModel());
|
||||
m_view->addEditor(editor);
|
||||
m_splitter = 0;
|
||||
m_layout->addWidget(editor->widget());
|
||||
m_layout->addWidget(m_view);
|
||||
}
|
||||
|
||||
SplitterOrView *SplitterOrView::findView(Core::IEditor *editor)
|
||||
@@ -525,6 +532,7 @@ void SplitterOrView::split(Qt::Orientation orientation)
|
||||
m_splitter->addWidget(new SplitterOrView(duplicateA));
|
||||
focus = duplicateA;
|
||||
} else {
|
||||
m_view->removeEditor(e);
|
||||
m_splitter->addWidget(new SplitterOrView(e));
|
||||
Q_ASSERT(m_view->currentEditor() == 0);
|
||||
}
|
||||
@@ -568,6 +576,7 @@ void SplitterOrView::unsplit(Core::IEditor *editor)
|
||||
if (!m_isRoot) {
|
||||
m_view = new EditorView(CoreImpl::instance()->editorManager()->openedEditorsModel());
|
||||
m_view->addEditor(editor);
|
||||
m_view->setCurrentEditor(editor);
|
||||
m_layout->addWidget(m_view);
|
||||
}
|
||||
closeSplitterEditors();
|
||||
|
||||
@@ -126,7 +126,7 @@ private slots:
|
||||
void checkEditorStatus();
|
||||
void setEditorFocus(int index);
|
||||
void makeEditorWritable();
|
||||
void listSelectionChanged(int index);
|
||||
void listSelectionActivated(int index);
|
||||
|
||||
private:
|
||||
void updateToolBar(IEditor *editor);
|
||||
|
||||
Reference in New Issue
Block a user