From c94456763cb17205529e6620d4c7c955f905c742 Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Thu, 30 Apr 2009 19:30:14 +0200
Subject: [PATCH] experiment with splitted views based on karsten's input. The
 goal is to support both the emacs usecase and the usecase with fixed views
 for certain sets of files. The changes gives the user more control where the
 files are. Effectively it should be easy now to put your cpp files in the
 left pane, and the header files in the right pane, and use F4 to toggle
 between them.

Also make the 'x' in the toolbar close the document, and not the view.
---
 .../editormanager/editormanager.cpp           | 12 +++++++-
 .../coreplugin/editormanager/editorview.cpp   | 30 +++++++++++++++++--
 .../coreplugin/editormanager/editorview.h     |  1 +
 3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index ff16068c7f6..f084f20080e 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -516,6 +516,9 @@ void EditorManager::setCurrentView(Core::Internal::SplitterOrView *view)
         old->update();
     if (view)
         view->update();
+
+    if (view && !view->editor())
+        view->setFocus();
 }
 
 Core::Internal::SplitterOrView *EditorManager::currentView() const
@@ -715,6 +718,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA
 
     foreach (EditorView *view, currentViews) {
         IEditor *newCurrent = view->currentEditor();
+#if 0
         if (!newCurrent)
             newCurrent = pickUnusedEditor();
         if (!newCurrent) {
@@ -726,7 +730,10 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA
                 }
             }
         }
-
+#else
+    if (!newCurrent && view == m_d->m_view)
+        newCurrent = pickUnusedEditor();
+#endif
         if (newCurrent) {
             activateEditor(view, newCurrent, NoActivate);
         } else {
@@ -833,15 +840,18 @@ Core::IEditor *EditorManager::placeEditor(Core::Internal::EditorView *view, Core
                 sourceView->view()->removeEditor(editor);
                 view->addEditor(editor);
                 view->setCurrentEditor(editor);
+#if 0
                 if (!sourceView->editor()) {
                     if (IEditor *replacement = pickUnusedEditor()) {
                         sourceView->view()->addEditor(replacement);
                     }
                 }
+#endif
                 return editor;
             } else if (duplicateSupported) {
                 editor = duplicateEditor(editor);
                 Q_ASSERT(editor);
+                m_d->m_editorModel->makeOriginal(editor);
             }
         }
         view->addEditor(editor);
diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp
index 48edfc1a009..b9838a8b595 100644
--- a/src/plugins/coreplugin/editormanager/editorview.cpp
+++ b/src/plugins/coreplugin/editormanager/editorview.cpp
@@ -229,6 +229,17 @@ QList<IEditor *> EditorModel::duplicatesFor(IEditor *editor) const
     return result;
 }
 
+void EditorModel::makeOriginal(IEditor *duplicate)
+{
+    Q_ASSERT(isDuplicate(duplicate));
+    IEditor *original = originalForDuplicate(duplicate);
+    Q_ASSERT(original);
+    int i = findEditor(original);
+    m_editors[i].editor = duplicate;
+    m_duplicateEditors.removeOne(duplicate);
+    m_duplicateEditors.append(original);
+}
+
 void EditorModel::emitDataChanged(IEditor *editor)
 {
     int idx = findEditor(editor);
@@ -504,7 +515,12 @@ bool EditorView::hasEditor(IEditor *editor) const
 void EditorView::closeView()
 {
     EditorManager *em = CoreImpl::instance()->editorManager();
+#if 1
+    if (IEditor *editor = currentEditor())
+        em->closeEditor(editor);
+#else
     em->closeView(this);
+#endif
 }
 
 void EditorView::removeEditor(IEditor *editor)
@@ -547,7 +563,9 @@ void EditorView::setCurrentEditor(IEditor *editor)
 {
     if (!editor || m_container->count() <= 0
         || m_container->indexOf(editor->widget()) == -1)
+        // ### TODO the combo box m_editorList should show an empty item
         return;
+
     m_editors.removeAll(editor);
     m_editors.append(editor);
 
@@ -862,20 +880,24 @@ void SplitterOrView::split(Qt::Orientation orientation)
     EditorManager *em = CoreImpl::instance()->editorManager();
     Core::IEditor *e = m_view->currentEditor();
 
+    SplitterOrView *view = 0;
     if (e) {
 
         m_view->removeEditor(e);
         m_splitter->addWidget(new SplitterOrView(e));
-
+#if 0
         if (e->duplicateSupported()) {
             Core::IEditor *duplicate = em->duplicateEditor(e);
             m_splitter->addWidget(new SplitterOrView(duplicate));
         } else {
             m_splitter->addWidget(new SplitterOrView());
         }
+#else
+        m_splitter->addWidget((view = new SplitterOrView()));
+#endif
     } else {
         m_splitter->addWidget(new SplitterOrView());
-        m_splitter->addWidget(new SplitterOrView());
+        m_splitter->addWidget((view = new SplitterOrView()));
     }
 
     m_layout->setCurrentWidget(m_splitter);
@@ -886,9 +908,11 @@ void SplitterOrView::split(Qt::Orientation orientation)
         m_view = 0;
     }
 
-    em->setCurrentView(findFirstView());
+    em->setCurrentView(view);
+#if 0
     if (e)
         em->activateEditor(e);
+#endif
 }
 
 void SplitterOrView::unsplitAll()
diff --git a/src/plugins/coreplugin/editormanager/editorview.h b/src/plugins/coreplugin/editormanager/editorview.h
index 13eb957b299..b62645baaaf 100644
--- a/src/plugins/coreplugin/editormanager/editorview.h
+++ b/src/plugins/coreplugin/editormanager/editorview.h
@@ -95,6 +95,7 @@ public:
     bool isDuplicate(IEditor *editor) const;
     QList<IEditor *> duplicatesFor(IEditor *editor) const;
     IEditor *originalForDuplicate(IEditor *duplicate) const;
+    void makeOriginal(IEditor *duplicate);
     QModelIndex indexOf(IEditor *editor) const;
     QModelIndex indexOf(const QString &filename) const;
 
-- 
GitLab