Commit 3b04ed31 authored by mae's avatar mae
Browse files

getting closer to working split

parent 145f9c24
......@@ -137,7 +137,7 @@ struct EditorManagerPrivate {
explicit EditorManagerPrivate(ICore *core, QWidget *parent);
~EditorManagerPrivate();
Internal::EditorView *m_view;
QSplitter *m_splitter;
Internal::SplitterOrView *m_splitter;
QStackedLayout *m_stackedLayout;
ICore *m_core;
......@@ -382,11 +382,12 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) :
connect(this, SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateEditorHistory()));
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 *)),
this, SLOT(closeEditor(Core::IEditor *)));
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();
......@@ -554,7 +555,15 @@ void EditorManager::closeEditor(IEditor *editor)
editor = currentEditor();
if (!editor)
return;
closeEditors(QList<IEditor *>() << editor);
if (m_d->m_view->hasEditor(editor)) {
unsplitAll();
closeEditors(QList<IEditor *>() << editor);
} else {
// ### TODO close duplicate editor
}
}
QList<IEditor*>
......@@ -588,6 +597,7 @@ QList<IFile *>
bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
{
unsplitAll();
return closeEditors(openedEditors(), askAboutModifiedEditors);
}
......@@ -672,6 +682,12 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA
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
* 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();
}
QList<IEditor*> EditorManager::openedEditorsNoDuplicates() const
{
return m_d->m_view->editors();
}
Internal::EditorModel *EditorManager::openedEditorsModel() const
{
return m_d->m_editorModel;
......@@ -1286,7 +1297,7 @@ QByteArray EditorManager::saveState() const
stream << m_d->m_editorStates;
QList<IEditor *> editors = openedEditorsNoDuplicates();
QList<IEditor *> editors = openedEditors();
int editorCount = editors.count();
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()
{
qDebug() << "split";
m_d->m_splitter->split(Qt::Vertical);
}
void EditorManager::splitSideBySide()
{
qDebug() << "splitSideBySide";
m_d->m_splitter->split(Qt::Horizontal);
}
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======================
......
......@@ -69,11 +69,10 @@ struct EditorManagerPrivate;
namespace Internal {
class OpenEditorsWindow;
class EditorModel;
//class EditorSplitter;
class SplitterOrView;
class EditorClosingCoreListener;
class OpenEditorsViewFactory;
} // namespace Internal
class CORE_EXPORT EditorManagerPlaceHolder : public QWidget
......@@ -121,7 +120,6 @@ public:
// EditorGroup *currentEditorGroup() const;
QList<IEditor*> openedEditors() const;
QList<IEditor*> openedEditorsNoDuplicates() const;
Internal::EditorModel *openedEditorsModel() const;
......@@ -191,6 +189,7 @@ private slots:
bool saveFileAs(Core::IEditor *editor = 0);
void closeEditor();
void closeEditor(Core::IEditor *editor);
void gotoNextDocHistory();
void gotoPreviousDocHistory();
void updateCurrentEditorAndGroup(Core::IContext *context);
......@@ -203,6 +202,7 @@ private slots:
void split();
void splitSideBySide();
void unsplit();
void unsplitAll();
private:
QList<IFile *> filesForEditors(QList<IEditor *> editors) const;
......@@ -215,8 +215,13 @@ private:
void restoreEditorState(IEditor *editor);
Core::IEditor *duplicateEditor(IEditor *editor);
void closeDuplicate(Core::IEditor *editor, bool doDelete);
static EditorManager *m_instance;
EditorManagerPrivate *m_d;
friend class Core::Internal::SplitterOrView;
};
//===================EditorClosingCoreListener======================
......
......@@ -333,8 +333,6 @@ void EditorView::insertEditor(int index, IEditor *editor)
m_toolBar->layout()->addWidget(toolBar);
}
connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
// emit editorAdded(editor);
}
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;
};
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 selectedIndex = -1;
QTreeWidgetItem *item;
foreach (IEditor *editor, em->openedEditorsNoDuplicates()){
foreach (IEditor *editor, em->openedEditors()){
if (curItem < oldNum) {
item = m_editorList->topLevelItem(curItem);
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment