forked from qt-creator/qt-creator
getting closer to working split
This commit is contained in:
@@ -137,7 +137,7 @@ struct EditorManagerPrivate {
|
|||||||
explicit EditorManagerPrivate(ICore *core, QWidget *parent);
|
explicit EditorManagerPrivate(ICore *core, QWidget *parent);
|
||||||
~EditorManagerPrivate();
|
~EditorManagerPrivate();
|
||||||
Internal::EditorView *m_view;
|
Internal::EditorView *m_view;
|
||||||
QSplitter *m_splitter;
|
Internal::SplitterOrView *m_splitter;
|
||||||
QStackedLayout *m_stackedLayout;
|
QStackedLayout *m_stackedLayout;
|
||||||
|
|
||||||
ICore *m_core;
|
ICore *m_core;
|
||||||
@@ -382,11 +382,12 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) :
|
|||||||
connect(this, SIGNAL(currentEditorChanged(Core::IEditor*)),
|
connect(this, SIGNAL(currentEditorChanged(Core::IEditor*)),
|
||||||
this, SLOT(updateEditorHistory()));
|
this, SLOT(updateEditorHistory()));
|
||||||
m_d->m_view = new EditorView(m_d->m_editorModel, this);
|
m_d->m_view = new EditorView(m_d->m_editorModel, this);
|
||||||
|
m_d->m_splitter = new SplitterOrView(m_d->m_view);
|
||||||
connect(m_d->m_view, SIGNAL(closeRequested(Core::IEditor *)),
|
connect(m_d->m_view, SIGNAL(closeRequested(Core::IEditor *)),
|
||||||
this, SLOT(closeEditor(Core::IEditor *)));
|
this, SLOT(closeEditor(Core::IEditor *)));
|
||||||
|
|
||||||
m_d->m_stackedLayout = new QStackedLayout(this);
|
m_d->m_stackedLayout = new QStackedLayout(this);
|
||||||
m_d->m_stackedLayout->addWidget(m_d->m_view);
|
m_d->m_stackedLayout->addWidget(m_d->m_splitter);
|
||||||
|
|
||||||
updateActions();
|
updateActions();
|
||||||
|
|
||||||
@@ -554,7 +555,15 @@ void EditorManager::closeEditor(IEditor *editor)
|
|||||||
editor = currentEditor();
|
editor = currentEditor();
|
||||||
if (!editor)
|
if (!editor)
|
||||||
return;
|
return;
|
||||||
closeEditors(QList<IEditor *>() << editor);
|
|
||||||
|
if (m_d->m_view->hasEditor(editor)) {
|
||||||
|
unsplitAll();
|
||||||
|
closeEditors(QList<IEditor *>() << editor);
|
||||||
|
} else {
|
||||||
|
// ### TODO close duplicate editor
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IEditor*>
|
QList<IEditor*>
|
||||||
@@ -588,6 +597,7 @@ QList<IFile *>
|
|||||||
|
|
||||||
bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
|
bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
|
||||||
{
|
{
|
||||||
|
unsplitAll();
|
||||||
return closeEditors(openedEditors(), askAboutModifiedEditors);
|
return closeEditors(openedEditors(), askAboutModifiedEditors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,6 +682,12 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA
|
|||||||
return !closingFailed;
|
return !closingFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorManager::closeDuplicate(Core::IEditor *editor, bool doDelete)
|
||||||
|
{
|
||||||
|
emit editorAboutToClose(editor);
|
||||||
|
if (doDelete)
|
||||||
|
delete editor;
|
||||||
|
}
|
||||||
|
|
||||||
/* Find editors for a mimetype, best matching at the front
|
/* Find editors for a mimetype, best matching at the front
|
||||||
* of the list. Recurse over the parent classes of the mimetype to
|
* of the list. Recurse over the parent classes of the mimetype to
|
||||||
@@ -1162,11 +1178,6 @@ QList<IEditor*> EditorManager::openedEditors() const
|
|||||||
return m_d->m_view->editors();
|
return m_d->m_view->editors();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IEditor*> EditorManager::openedEditorsNoDuplicates() const
|
|
||||||
{
|
|
||||||
return m_d->m_view->editors();
|
|
||||||
}
|
|
||||||
|
|
||||||
Internal::EditorModel *EditorManager::openedEditorsModel() const
|
Internal::EditorModel *EditorManager::openedEditorsModel() const
|
||||||
{
|
{
|
||||||
return m_d->m_editorModel;
|
return m_d->m_editorModel;
|
||||||
@@ -1286,7 +1297,7 @@ QByteArray EditorManager::saveState() const
|
|||||||
|
|
||||||
stream << m_d->m_editorStates;
|
stream << m_d->m_editorStates;
|
||||||
|
|
||||||
QList<IEditor *> editors = openedEditorsNoDuplicates();
|
QList<IEditor *> editors = openedEditors();
|
||||||
int editorCount = editors.count();
|
int editorCount = editors.count();
|
||||||
|
|
||||||
qDebug() << "save editors:" << editorCount;
|
qDebug() << "save editors:" << editorCount;
|
||||||
@@ -1501,19 +1512,36 @@ QString EditorManager::externalEditor() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Core::IEditor *EditorManager::duplicateEditor(Core::IEditor *editor)
|
||||||
|
{
|
||||||
|
if (!editor->duplicateSupported())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
IEditor *duplicate = editor->duplicate(0);
|
||||||
|
// TODO ### emit signals
|
||||||
|
return duplicate;
|
||||||
|
}
|
||||||
|
|
||||||
void EditorManager::split()
|
void EditorManager::split()
|
||||||
{
|
{
|
||||||
qDebug() << "split";
|
m_d->m_splitter->split(Qt::Vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::splitSideBySide()
|
void EditorManager::splitSideBySide()
|
||||||
{
|
{
|
||||||
qDebug() << "splitSideBySide";
|
m_d->m_splitter->split(Qt::Horizontal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::unsplit()
|
void EditorManager::unsplit()
|
||||||
{
|
{
|
||||||
qDebug() << "unsplit";
|
unsplitAll(); // ### TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorManager::unsplitAll()
|
||||||
|
{
|
||||||
|
m_d->m_splitter->unsplit(0);
|
||||||
|
if (IEditor *e = m_d->m_splitter->editor())
|
||||||
|
setCurrentEditor(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===================EditorClosingCoreListener======================
|
//===================EditorClosingCoreListener======================
|
||||||
|
|||||||
@@ -69,11 +69,10 @@ struct EditorManagerPrivate;
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
class OpenEditorsWindow;
|
class OpenEditorsWindow;
|
||||||
class EditorModel;
|
class EditorModel;
|
||||||
//class EditorSplitter;
|
class SplitterOrView;
|
||||||
|
|
||||||
class EditorClosingCoreListener;
|
class EditorClosingCoreListener;
|
||||||
class OpenEditorsViewFactory;
|
class OpenEditorsViewFactory;
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
|
class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
|
||||||
@@ -121,7 +120,6 @@ public:
|
|||||||
// EditorGroup *currentEditorGroup() const;
|
// EditorGroup *currentEditorGroup() const;
|
||||||
|
|
||||||
QList<IEditor*> openedEditors() const;
|
QList<IEditor*> openedEditors() const;
|
||||||
QList<IEditor*> openedEditorsNoDuplicates() const;
|
|
||||||
|
|
||||||
Internal::EditorModel *openedEditorsModel() const;
|
Internal::EditorModel *openedEditorsModel() const;
|
||||||
|
|
||||||
@@ -191,6 +189,7 @@ private slots:
|
|||||||
bool saveFileAs(Core::IEditor *editor = 0);
|
bool saveFileAs(Core::IEditor *editor = 0);
|
||||||
void closeEditor();
|
void closeEditor();
|
||||||
void closeEditor(Core::IEditor *editor);
|
void closeEditor(Core::IEditor *editor);
|
||||||
|
|
||||||
void gotoNextDocHistory();
|
void gotoNextDocHistory();
|
||||||
void gotoPreviousDocHistory();
|
void gotoPreviousDocHistory();
|
||||||
void updateCurrentEditorAndGroup(Core::IContext *context);
|
void updateCurrentEditorAndGroup(Core::IContext *context);
|
||||||
@@ -203,6 +202,7 @@ private slots:
|
|||||||
void split();
|
void split();
|
||||||
void splitSideBySide();
|
void splitSideBySide();
|
||||||
void unsplit();
|
void unsplit();
|
||||||
|
void unsplitAll();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<IFile *> filesForEditors(QList<IEditor *> editors) const;
|
QList<IFile *> filesForEditors(QList<IEditor *> editors) const;
|
||||||
@@ -215,8 +215,13 @@ private:
|
|||||||
|
|
||||||
void restoreEditorState(IEditor *editor);
|
void restoreEditorState(IEditor *editor);
|
||||||
|
|
||||||
|
Core::IEditor *duplicateEditor(IEditor *editor);
|
||||||
|
void closeDuplicate(Core::IEditor *editor, bool doDelete);
|
||||||
|
|
||||||
static EditorManager *m_instance;
|
static EditorManager *m_instance;
|
||||||
EditorManagerPrivate *m_d;
|
EditorManagerPrivate *m_d;
|
||||||
|
|
||||||
|
friend class Core::Internal::SplitterOrView;
|
||||||
};
|
};
|
||||||
|
|
||||||
//===================EditorClosingCoreListener======================
|
//===================EditorClosingCoreListener======================
|
||||||
|
|||||||
@@ -333,8 +333,6 @@ void EditorView::insertEditor(int index, IEditor *editor)
|
|||||||
m_toolBar->layout()->addWidget(toolBar);
|
m_toolBar->layout()->addWidget(toolBar);
|
||||||
}
|
}
|
||||||
connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
|
connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
|
||||||
|
|
||||||
// emit editorAdded(editor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorView::hasEditor(IEditor *editor) const
|
bool EditorView::hasEditor(IEditor *editor) const
|
||||||
@@ -464,3 +462,115 @@ void EditorView::listSelectionChanged(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SplitterOrView::SplitterOrView(EditorView *view, QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
{
|
||||||
|
m_isRoot = true;
|
||||||
|
m_layout = new QStackedLayout(this);
|
||||||
|
m_view = view;
|
||||||
|
m_splitter = 0;
|
||||||
|
m_layout->addWidget(m_view);
|
||||||
|
}
|
||||||
|
|
||||||
|
SplitterOrView::SplitterOrView(Core::IEditor *editor, QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
{
|
||||||
|
m_isRoot = false;
|
||||||
|
m_layout = new QStackedLayout(this);
|
||||||
|
m_view = new EditorView(CoreImpl::instance()->editorManager()->openedEditorsModel());
|
||||||
|
m_view->addEditor(editor);
|
||||||
|
m_splitter = 0;
|
||||||
|
m_layout->addWidget(editor->widget());
|
||||||
|
}
|
||||||
|
|
||||||
|
SplitterOrView *SplitterOrView::findView(Core::IEditor *editor)
|
||||||
|
{
|
||||||
|
if (hasEditor(editor))
|
||||||
|
return this;
|
||||||
|
if (m_splitter) {
|
||||||
|
for (int i = 0; i < m_splitter->count(); ++i) {
|
||||||
|
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i)))
|
||||||
|
if (SplitterOrView *result = splitterOrView->findView(editor))
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SplitterOrView *SplitterOrView::findSplitter(Core::IEditor *editor)
|
||||||
|
{
|
||||||
|
if (m_splitter) {
|
||||||
|
for (int i = 0; i < m_splitter->count(); ++i) {
|
||||||
|
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) {
|
||||||
|
if (splitterOrView->hasEditor(editor))
|
||||||
|
return this;
|
||||||
|
if (SplitterOrView *result = splitterOrView->findSplitter(editor))
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplitterOrView::split(Qt::Orientation orientation)
|
||||||
|
{
|
||||||
|
Q_ASSERT(m_view && m_splitter == 0);
|
||||||
|
m_splitter = new QSplitter(this);
|
||||||
|
m_splitter->setOrientation(orientation);
|
||||||
|
Core::IEditor *e = m_view->currentEditor();
|
||||||
|
|
||||||
|
Core::IEditor *focus = e;
|
||||||
|
if (m_isRoot) {
|
||||||
|
Core::IEditor *duplicateA = CoreImpl::instance()->editorManager()->duplicateEditor(e);
|
||||||
|
m_splitter->addWidget(new SplitterOrView(duplicateA));
|
||||||
|
focus = duplicateA;
|
||||||
|
} else {
|
||||||
|
m_splitter->addWidget(new SplitterOrView(e));
|
||||||
|
Q_ASSERT(m_view->currentEditor() == 0);
|
||||||
|
}
|
||||||
|
Core::IEditor *duplicate = CoreImpl::instance()->editorManager()->duplicateEditor(e);
|
||||||
|
m_splitter->addWidget(new SplitterOrView(duplicate));
|
||||||
|
m_layout->addWidget(m_splitter);
|
||||||
|
|
||||||
|
if (!m_isRoot) {
|
||||||
|
delete m_view;
|
||||||
|
m_view = 0;
|
||||||
|
} else {
|
||||||
|
m_layout->setCurrentWidget(m_splitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
focus->widget()->setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplitterOrView::close()
|
||||||
|
{
|
||||||
|
foreach(Core::IEditor *e, editors())
|
||||||
|
CoreImpl::instance()->editorManager()->closeDuplicate(e, false);
|
||||||
|
closeSplitterEditors();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplitterOrView::closeSplitterEditors()
|
||||||
|
{
|
||||||
|
if (!m_splitter)
|
||||||
|
return;
|
||||||
|
for (int i = 0; i < m_splitter->count(); ++i) {
|
||||||
|
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) {
|
||||||
|
splitterOrView->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SplitterOrView::unsplit(Core::IEditor *editor)
|
||||||
|
{
|
||||||
|
if (!m_splitter)
|
||||||
|
return;
|
||||||
|
Q_ASSERT(m_isRoot || (m_view == 0 && editor));
|
||||||
|
if (!m_isRoot) {
|
||||||
|
m_view = new EditorView(CoreImpl::instance()->editorManager()->openedEditorsModel());
|
||||||
|
m_view->addEditor(editor);
|
||||||
|
m_layout->addWidget(m_view);
|
||||||
|
}
|
||||||
|
closeSplitterEditors();
|
||||||
|
delete m_splitter;
|
||||||
|
m_splitter = 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -148,6 +148,36 @@ private:
|
|||||||
QMap<QWidget *, IEditor *> m_widgetEditorMap;
|
QMap<QWidget *, IEditor *> m_widgetEditorMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SplitterOrView : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
SplitterOrView(EditorView *view, QWidget *parent = 0); // creates a root splitter or view
|
||||||
|
SplitterOrView(Core::IEditor *editor, QWidget *parent = 0);
|
||||||
|
|
||||||
|
void split(Qt::Orientation orientation);
|
||||||
|
void unsplit(Core::IEditor *editor);
|
||||||
|
|
||||||
|
bool isView() const { return m_view != 0; }
|
||||||
|
Core::IEditor *editor() const { return m_view ? m_view->currentEditor() : 0; }
|
||||||
|
QList<Core::IEditor *> editors() const { return m_view ? m_view->editors() : QList<Core::IEditor*>(); }
|
||||||
|
bool hasEditor(Core::IEditor *editor) const { return m_view && m_view->hasEditor(editor); }
|
||||||
|
EditorView *view() const { return m_view; }
|
||||||
|
QSplitter *splitter() const { return m_splitter; }
|
||||||
|
|
||||||
|
SplitterOrView *findView(Core::IEditor *editor);
|
||||||
|
SplitterOrView *findSplitter(Core::IEditor *editor);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void close();
|
||||||
|
void closeSplitterEditors();
|
||||||
|
bool m_isRoot;
|
||||||
|
QStackedLayout *m_layout;
|
||||||
|
EditorView *m_view;
|
||||||
|
QSplitter *m_splitter;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ void OpenEditorsWindow::updateList()
|
|||||||
int curItem = 0;
|
int curItem = 0;
|
||||||
int selectedIndex = -1;
|
int selectedIndex = -1;
|
||||||
QTreeWidgetItem *item;
|
QTreeWidgetItem *item;
|
||||||
foreach (IEditor *editor, em->openedEditorsNoDuplicates()){
|
foreach (IEditor *editor, em->openedEditors()){
|
||||||
if (curItem < oldNum) {
|
if (curItem < oldNum) {
|
||||||
item = m_editorList->topLevelItem(curItem);
|
item = m_editorList->topLevelItem(curItem);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user