From be736eddf2fab11e1a4ca41685177849b8faecff Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Fri, 3 Apr 2009 15:12:28 +0200
Subject: [PATCH] Make emacs-like splitting more emacs like. Introduction of
 Ctrl+E,1 for delete-other-windows

---
 src/plugins/coreplugin/coreconstants.h        |  3 +-
 .../editormanager/editormanager.cpp           | 35 ++++++++++++----
 .../coreplugin/editormanager/editormanager.h  |  3 +-
 .../coreplugin/editormanager/editorview.cpp   | 41 ++++++++++++-------
 .../coreplugin/editormanager/editorview.h     |  6 ++-
 5 files changed, 62 insertions(+), 26 deletions(-)

diff --git a/src/plugins/coreplugin/coreconstants.h b/src/plugins/coreplugin/coreconstants.h
index 7afdde43663..a93027ae98e 100644
--- a/src/plugins/coreplugin/coreconstants.h
+++ b/src/plugins/coreplugin/coreconstants.h
@@ -123,7 +123,8 @@ const char * const ZOOM_WINDOW           = "QtCreator.ZoomWindow";
 
 const char * const SPLIT                 = "QtCreator.Split";
 const char * const SPLIT_SIDE_BY_SIDE    = "QtCreator.SplitSideBySide";
-const char * const UNSPLIT               = "QtCreator.Unsplit";
+const char * const DELETE_WINDOW         = "QtCreator.DeleteWindow";
+const char * const DELETE_OTHER_WINDOWS  = "QtCreator.DeleteOtherWindows";
 const char * const GOTO_OTHER_WINDOW     = "QtCreator.GotoOtherWindow";
 const char * const SAVEASDEFAULT         = "QtCreator.SaveAsDefaultLayout";
 const char * const RESTOREDEFAULT        = "QtCreator.RestoreDefaultLayout";
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 972de1582aa..00453003e43 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -154,7 +154,8 @@ struct EditorManagerPrivate {
     QAction *m_openInExternalEditorAction;
     QAction *m_splitAction;
     QAction *m_splitSideBySideAction;
-    QAction *m_unsplitAction;
+    QAction *m_deleteWindowAction;
+    QAction *m_deleteOtherWindowsAction;
     QAction *m_gotoOtherWindowAction;
 
     QList<IEditor *> m_editorHistory;
@@ -331,21 +332,27 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) :
 
     m_d->m_splitAction = new QAction(tr("Split"), this);
     cmd = am->registerAction(m_d->m_splitAction, Constants::SPLIT, editManagerContext);
-    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+E,1")));
+    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+E,2")));
     mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
     connect(m_d->m_splitAction, SIGNAL(triggered()), this, SLOT(split()));
 
     m_d->m_splitSideBySideAction = new QAction(tr("Split Side by Side"), this);
     cmd = am->registerAction(m_d->m_splitSideBySideAction, Constants::SPLIT_SIDE_BY_SIDE, editManagerContext);
-    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+E,2")));
+    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+E,3")));
     mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
     connect(m_d->m_splitSideBySideAction, SIGNAL(triggered()), this, SLOT(splitSideBySide()));
 
-    m_d->m_unsplitAction = new QAction(tr("Unsplit"), this);
-    cmd = am->registerAction(m_d->m_unsplitAction, Constants::UNSPLIT, editManagerContext);
+    m_d->m_deleteWindowAction = new QAction(tr("Delete Window"), this);
+    cmd = am->registerAction(m_d->m_deleteWindowAction, Constants::DELETE_WINDOW, editManagerContext);
     cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+E,0")));
     mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
-    connect(m_d->m_unsplitAction, SIGNAL(triggered()), this, SLOT(unsplit()));
+    connect(m_d->m_deleteWindowAction, SIGNAL(triggered()), this, SLOT(deleteWindow()));
+
+    m_d->m_deleteOtherWindowsAction = new QAction(tr("Delete Other Windows"), this);
+    cmd = am->registerAction(m_d->m_deleteOtherWindowsAction, Constants::DELETE_OTHER_WINDOWS, editManagerContext);
+    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+E,1")));
+    mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
+    connect(m_d->m_deleteOtherWindowsAction, SIGNAL(triggered()), this, SLOT(deleteOtherWindows()));
 
     m_d->m_gotoOtherWindowAction = new QAction(tr("Goto other window"), this);
     cmd = am->registerAction(m_d->m_gotoOtherWindowAction, Constants::GOTO_OTHER_WINDOW, editManagerContext);
@@ -1344,7 +1351,8 @@ void EditorManager::updateActions()
     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_deleteWindowAction->setEnabled(hasSplitter);
+    m_d->m_deleteOtherWindowsAction->setEnabled(hasSplitter);
     m_d->m_gotoOtherWindowAction->setEnabled(hasSplitter);
 
     m_d->m_openInExternalEditorAction->setEnabled(curEditor != 0);
@@ -1788,7 +1796,7 @@ void EditorManager::splitSideBySide()
     split(Qt::Horizontal);
 }
 
-void EditorManager::unsplit()
+void EditorManager::deleteWindow()
 {
     SplitterOrView *viewToClose = m_d->m_currentView;
     if (!viewToClose && m_d->m_currentEditor)
@@ -1801,6 +1809,17 @@ void EditorManager::unsplit()
     updateActions();
 }
 
+void EditorManager::deleteOtherWindows()
+{
+    IEditor *editor = m_d->m_currentEditor;
+    if (editor && m_d->m_editorModel->isDuplicate(editor))
+        editor = m_d->m_editorModel->originalForDuplicate(editor);
+    m_d->m_splitter->unsplitAll();
+    if (!editor)
+        editor = pickUnusedEditor();
+    activateEditor(editor);
+}
+
 void EditorManager::gotoOtherWindow()
 {
     if (m_d->m_splitter->isSplitter()) {
diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h
index 44df9294cbd..d30390e593a 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.h
+++ b/src/plugins/coreplugin/editormanager/editormanager.h
@@ -211,7 +211,8 @@ private slots:
     void split(Qt::Orientation orientation);
     void split();
     void splitSideBySide();
-    void unsplit();
+    void deleteWindow();
+    void deleteOtherWindows();
     void gotoOtherWindow();
 
 private:
diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp
index 15d7f19fb13..d77fa22b041 100644
--- a/src/plugins/coreplugin/editormanager/editorview.cpp
+++ b/src/plugins/coreplugin/editormanager/editorview.cpp
@@ -520,6 +520,7 @@ void EditorView::removeEditor(IEditor *editor)
 
     m_container->removeWidget(editor->widget());
     m_widgetEditorMap.remove(editor->widget());
+    qDebug() << "EditorView::removeEditor" << editor << "  set 0 parent on widget" << editor->widget();
     editor->widget()->setParent(0);
     disconnect(editor, SIGNAL(changed()), this, SLOT(updateEditorStatus()));
     QToolBar *toolBar = editor->toolBar();
@@ -657,6 +658,18 @@ SplitterOrView::SplitterOrView(Core::IEditor *editor)
     setFocusPolicy(Qt::ClickFocus);
 }
 
+SplitterOrView::~SplitterOrView()
+{
+    delete m_layout;
+    m_layout = 0;
+    delete m_view;
+    m_view = 0;
+    delete m_splitter;
+    m_splitter = 0;
+}
+
+
+
 void SplitterOrView::focusInEvent(QFocusEvent *)
 {
     CoreImpl::instance()->editorManager()->setCurrentView(this);
@@ -861,24 +874,24 @@ void SplitterOrView::split(Qt::Orientation orientation)
         em->activateEditor(e);
 }
 
-void SplitterOrView::close()
+void SplitterOrView::unsplitAll()
 {
-    Q_ASSERT(!m_isRoot);
-    if (m_view) {
-        CoreImpl::instance()->editorManager()->emptyView(m_view);
-        delete m_view;
-        m_view = 0;
-    }
-    closeSplitterEditors();
+    m_splitter->hide();
+    m_layout->removeWidget(m_splitter); // workaround Qt bug
+    unsplitAll_helper();
+    delete m_splitter;
+    m_splitter = 0;
 }
 
-void SplitterOrView::closeSplitterEditors()
+void SplitterOrView::unsplitAll_helper()
 {
-    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();
+    if (!m_isRoot && m_view)
+        CoreImpl::instance()->editorManager()->emptyView(m_view);
+    if (m_splitter) {
+        for (int i = 0; i < m_splitter->count(); ++i) {
+            if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) {
+                splitterOrView->unsplitAll_helper();
+            }
         }
     }
 }
diff --git a/src/plugins/coreplugin/editormanager/editorview.h b/src/plugins/coreplugin/editormanager/editorview.h
index e0d900f37d4..d198155ca3d 100644
--- a/src/plugins/coreplugin/editormanager/editorview.h
+++ b/src/plugins/coreplugin/editormanager/editorview.h
@@ -181,6 +181,7 @@ class SplitterOrView  : public QWidget
 public:
     SplitterOrView(Internal::EditorModel *model = 0); // creates a splitter with an empty view
     SplitterOrView(Core::IEditor *editor);
+    ~SplitterOrView();
 
     void split(Qt::Orientation orientation);
     void unsplit();
@@ -210,14 +211,15 @@ public:
     QSize sizeHint() const { return minimumSizeHint(); }
     QSize minimumSizeHint() const;
 
+    void unsplitAll();
+
 protected:
     void focusInEvent(QFocusEvent *);
     void paintEvent(QPaintEvent *);
 
 
 private:
-    void close();
-    void closeSplitterEditors();
+    void unsplitAll_helper();
     SplitterOrView *findNextView_helper(SplitterOrView *view, bool *found);
     bool m_isRoot;
     QStackedLayout *m_layout;
-- 
GitLab