Commit be736edd authored by mae's avatar mae
Browse files

Make emacs-like splitting more emacs like. Introduction of Ctrl+E,1 for

delete-other-windows
parent 62d5b16a
......@@ -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";
......
......@@ -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()) {
......
......@@ -211,7 +211,8 @@ private slots:
void split(Qt::Orientation orientation);
void split();
void splitSideBySide();
void unsplit();
void deleteWindow();
void deleteOtherWindows();
void gotoOtherWindow();
private:
......
......@@ -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();
}
}
}
}
......
......@@ -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;
......
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