Commit 2faf32c7 authored by mae's avatar mae
Browse files

new editor split system seems to be working now

parent 1f47895b
......@@ -569,16 +569,19 @@ void EditorManager::closeView(Core::Internal::EditorView *view)
return;
if (view == m_d->m_view) {
closeEditors(QList<IEditor *>() << view->currentEditor());
if (IEditor *e = view->currentEditor())
closeEditors(QList<IEditor *>() << e);
return;
}
emptyView(view);
SplitterOrView *splitterOrView = m_d->m_splitter->findView(view);
Q_ASSERT(splitterOrView);
Q_ASSERT(splitterOrView->view() == view);
SplitterOrView *splitter = m_d->m_splitter->findSplitter(splitterOrView);
Q_ASSERT(splitterOrView->hasEditors() == false);
splitterOrView->hide();
delete splitterOrView;
splitter->unsplit();
......@@ -590,6 +593,7 @@ void EditorManager::closeView(Core::Internal::EditorView *view)
else
setCurrentView(newCurrent);
}
updateEditorHistory();
}
void EditorManager::closeEditor(Core::IEditor *editor)
......@@ -726,8 +730,11 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA
delete editor;
}
if (currentView)
activateEditor(currentView, currentView->currentEditor());
if (currentView) {
setCurrentView(m_d->m_splitter->findView(currentView));
if (IEditor *e = currentView->currentEditor())
activateEditor(currentView, e);
}
return !closingFailed;
}
......@@ -744,27 +751,29 @@ IEditor *EditorManager::pickUnusedEditor() const
void EditorManager::activateEditor(IEditor *editor, OpenEditorFlags flags)
{
SplitterOrView *splitterOrView = m_d->m_currentView;
setCurrentView(0);
qDebug() << "currentView" << splitterOrView;
if (editor && (flags & ActivateInPlace)) {
SplitterOrView *place = m_d->m_splitter->findView(editor);
if (place && !place->isSplitter()) {
splitterOrView = place;
}
}
if (!splitterOrView)
splitterOrView = m_d->m_splitter->findEmptyView();
qDebug() << "empty" << splitterOrView;
if (!splitterOrView && m_d->m_currentEditor)
splitterOrView = m_d->m_splitter->findView(m_d->m_currentEditor);
qDebug() << "current editor" << splitterOrView;
if (!splitterOrView)
splitterOrView = m_d->m_splitter->findFirstView();
qDebug() << "first" << splitterOrView;
if (!splitterOrView) {
splitterOrView = m_d->m_splitter;
}
qDebug() << "origin" << splitterOrView;
activateEditor(splitterOrView->view(), editor, flags);
}
......@@ -805,6 +814,7 @@ void EditorManager::activateEditor(Core::Internal::EditorView *view, Core::IEdit
}
bool hasCurrent = (view->currentEditor() != 0);
editor = placeEditor(view, editor);
if (!(flags & NoActivate) || !hasCurrent)
view->setCurrentEditor(editor);
......@@ -1310,6 +1320,10 @@ void EditorManager::updateActions()
m_d->m_goBackAction->setEnabled(m_d->currentNavigationHistoryPosition > 0);
m_d->m_goForwardAction->setEnabled(m_d->currentNavigationHistoryPosition < m_d->m_navigationHistory.size()-1);
bool hasSplitter = m_d->m_splitter->isSplitter();
m_d->m_unsplitAction->setEnabled(hasSplitter);
m_d->m_gotoOtherWindowAction->setEnabled(hasSplitter);
m_d->m_openInExternalEditorAction->setEnabled(curEditor != 0);
}
......@@ -1434,7 +1448,6 @@ QByteArray EditorManager::saveState() const
QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly);
qDebug() << "saveState";
stream << QByteArray("EditorManagerV1");
stream << m_d->m_editorStates;
......@@ -1447,7 +1460,6 @@ QByteArray EditorManager::saveState() const
editors.prepend(m_d->m_currentEditor);
}
qDebug() << "save editors:" << editorCount;
stream << editorCount;
foreach (IEditor *editor, editors) {
......@@ -1674,8 +1686,11 @@ void EditorManager::split(Qt::Orientation orientation)
if (!view)
view = m_d->m_currentEditor ? m_d->m_splitter->findView(m_d->m_currentEditor)
: m_d->m_splitter->findFirstView();
if (view)
if (view) {
view->split(orientation);
updateEditorHistory();
}
updateActions();
}
void EditorManager::split()
......@@ -1698,6 +1713,7 @@ void EditorManager::unsplit()
return;
closeView(viewToClose->view());
updateActions();
}
void EditorManager::gotoOtherWindow()
......
......@@ -104,7 +104,9 @@ public:
enum OpenEditorFlag {
NoActivate = 1,
IgnoreNavigationHistory = 2
IgnoreNavigationHistory = 2,
ActivateInPlace = 4
};
Q_DECLARE_FLAGS(OpenEditorFlags, OpenEditorFlag)
......
......@@ -34,6 +34,7 @@
#include "editorview.h"
#include "editormanager.h"
#include "coreimpl.h"
#include "minisplitter.h"
#include <utils/qtcassert.h>
......@@ -199,8 +200,6 @@ void EditorModel::itemChanged()
emitDataChanged(qobject_cast<IEditor*>(sender()));
}
//================EditorView====================
EditorView::EditorView(EditorModel *model, QWidget *parent) :
......@@ -354,8 +353,6 @@ bool EditorView::hasEditor(IEditor *editor) const
void EditorView::closeView()
{
if (editorCount() == 0)
return;
EditorManager *em = CoreImpl::instance()->editorManager();
em->closeView(this);
}
......@@ -397,8 +394,6 @@ void EditorView::setCurrentEditor(IEditor *editor)
if (!editor || m_container->count() <= 0
|| m_container->indexOf(editor->widget()) == -1)
return;
if (editor)
qDebug() << "EditorView::setCurrentEditor" << editor << editor->file()->fileName();
const int idx = m_container->indexOf(editor->widget());
QTC_ASSERT(idx >= 0, return);
......@@ -664,7 +659,7 @@ SplitterOrView *SplitterOrView::findNextView_helper(SplitterOrView *view, bool *
void SplitterOrView::split(Qt::Orientation orientation)
{
Q_ASSERT(m_view && m_splitter == 0);
m_splitter = new QSplitter(this);
m_splitter = new MiniSplitter(this);
m_splitter->setOrientation(orientation);
m_layout->addWidget(m_splitter);
EditorManager *em = CoreImpl::instance()->editorManager();
......@@ -674,7 +669,6 @@ void SplitterOrView::split(Qt::Orientation orientation)
m_view->removeEditor(e);
m_splitter->addWidget(new SplitterOrView(e));
m_view = 0;
if (e->duplicateSupported()) {
Core::IEditor *duplicate = em->duplicateEditor(e);
......@@ -695,10 +689,9 @@ void SplitterOrView::split(Qt::Orientation orientation)
m_view = 0;
}
em->setCurrentView(findFirstView());
if (e)
em->activateEditor(e);
else
em->setCurrentView(findFirstView());
}
void SplitterOrView::close()
......@@ -728,37 +721,35 @@ void SplitterOrView::unsplit()
if (!m_splitter)
return;
qDebug() << "unsplit" << this << m_splitter;
#if 0
SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(0));
Q_ASSERT(splitterOrView != 0);
Q_ASSERT(m_splitter->count() == 1);
EditorManager *em = CoreImpl::instance()->editorManager();
SplitterOrView *childSplitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(0));
qDebug() << "splitter or view is" << splitterOrView;
QSplitter *oldSplitter = m_splitter;
m_splitter = 0;
if (editor) { // pick the other side
if (SplitterOrView *view = findView(editor)) {
qDebug() << "view to close is" << view;
view->close();
delete view;
if (childSplitterOrView->isSplitter()) {
Q_ASSERT(childSplitterOrView->view() == 0);
m_splitter = childSplitterOrView->splitter();
m_layout->addWidget(m_splitter);
m_layout->setCurrentWidget(m_splitter);
} else {
EditorView *childView = childSplitterOrView->view();
Q_ASSERT(childView);
if (m_view) {
if (IEditor *e = childView->currentEditor()) {
childView->removeEditor(e);
m_view->addEditor(e);
m_view->setCurrentEditor(e);
}
em->emptyView(childView);
} else {
m_view = childView;
childSplitterOrView->m_layout->removeWidget(m_view);
m_layout->addWidget(m_view);
}
splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(0));
qDebug() << "other splitter or view is" << splitterOrView;
m_layout->setCurrentWidget(m_view);
}
QSplitter *old_splitter = m_splitter;
EditorView *old_view = m_view;
m_splitter = splitterOrView->splitter();
m_view = splitterOrView->view();
qDebug() << "new splitter/view" << m_splitter << m_view;
if (m_splitter)
m_layout->addWidget(m_splitter);
if (m_view)
m_layout->addWidget(m_view);
// delete old_view;
// delete old_splitter;
#endif
delete oldSplitter;
em->setCurrentView(findFirstView());
}
......@@ -46,15 +46,6 @@ const int OpenEditorsWindow::WIDTH = 300;
const int OpenEditorsWindow::HEIGHT = 200;
const int OpenEditorsWindow::MARGIN = 4;
bool OpenEditorsWindow::isSameFile(IEditor *editorA, IEditor *editorB) const
{
if (editorA == editorB)
return true;
if (!editorA || !editorB)
return false;
return editorA->file()->fileName() == editorB->file()->fileName();
}
OpenEditorsWindow::OpenEditorsWindow(QWidget *parent) :
QWidget(parent, Qt::Popup),
m_editorList(new QTreeWidget(this)),
......@@ -209,7 +200,16 @@ void OpenEditorsWindow::setEditors(const QList<IEditor *>&editors, IEditor *curr
m_editorList->clear();
QList<IEditor *> doneList;
QList<IFile *>doneFileList;
foreach (IEditor *editor, editors) {
if (doneList.contains(editor))
continue;
doneList += editor;
if (!editor->widget()->isVisible() && doneFileList.contains(editor->file()))
continue;
doneFileList += editor->file();
QTreeWidgetItem *item = new QTreeWidgetItem();
QString title = editor->displayName();
......@@ -219,7 +219,7 @@ void OpenEditorsWindow::setEditors(const QList<IEditor *>&editors, IEditor *curr
item->setText(0, title);
item->setToolTip(0, editor->file()->fileName());
item->setData(0, Qt::UserRole, QVariant::fromValue(editor));
item->setFlags(Qt::ItemIsSelectable);
//item->setFlags(Qt::ItemIsSelectable);
item->setTextAlignment(0, Qt::AlignLeft);
......@@ -236,7 +236,7 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item)
if (item)
editor = item->data(0, Qt::UserRole).value<IEditor*>();
if (editor)
EditorManager::instance()->activateEditor(editor);
EditorManager::instance()->activateEditor(editor, EditorManager::ActivateInPlace);
}
void OpenEditorsWindow::editorClicked(QTreeWidgetItem *item)
......
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