Commit 98cb4090 authored by Artem Chystikov's avatar Artem Chystikov

Implement go to previous split feature

These changes allows users to move between splits
using the hotkeys not only clockwise, but counterclockwise too

Change-Id: I2a30bc0cd869881c525674d7e40e622b4b3dc7f6
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 049ffa2c
......@@ -112,7 +112,8 @@ const char SPLIT_SIDE_BY_SIDE[] = "QtCreator.SplitSideBySide";
const char SPLIT_NEW_WINDOW[] = "QtCreator.SplitNewWindow";
const char REMOVE_CURRENT_SPLIT[] = "QtCreator.RemoveCurrentSplit";
const char REMOVE_ALL_SPLITS[] = "QtCreator.RemoveAllSplits";
const char GOTO_NEXT_SPLIT[] = "QtCreator.GotoOtherSplit";
const char GOTO_PREV_SPLIT[] = "QtCreator.GoToPreviousSplit";
const char GOTO_NEXT_SPLIT[] = "QtCreator.GoToNextSplit";
const char CLOSE[] = "QtCreator.Close";
const char CLOSE_ALTERNATIVE[] = "QtCreator.Close_Alternative"; // temporary, see QTCREATORBUG-72
const char CLOSEALL[] = "QtCreator.CloseAll";
......
......@@ -412,6 +412,12 @@ void EditorManagerPrivate::init()
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_removeAllSplitsAction, SIGNAL(triggered()), this, SLOT(removeAllSplits()));
m_gotoPreviousSplitAction = new QAction(tr("Go to Previous Split or Window"), this);
cmd = ActionManager::registerAction(m_gotoPreviousSplitAction, Constants::GOTO_PREV_SPLIT, editManagerContext);
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+E,i") : tr("Ctrl+E,i")));
mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
connect(m_gotoPreviousSplitAction, SIGNAL(triggered()), this, SLOT(gotoPreviousSplit()));
m_gotoNextSplitAction = new QAction(tr("Go to Next Split or Window"), this);
cmd = ActionManager::registerAction(m_gotoNextSplitAction, Constants::GOTO_NEXT_SPLIT, editManagerContext);
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+E,o") : tr("Ctrl+E,o")));
......@@ -1658,6 +1664,30 @@ void EditorManagerPrivate::gotoNextSplit()
activateView(nextView);
}
void EditorManagerPrivate::gotoPreviousSplit()
{
EditorView *view = currentEditorView();
if (!view)
return;
EditorView *prevView = view->findPreviousView();
if (!prevView) {
// we are in the "first" view in this editor area
int index = -1;
EditorArea *area = findEditorArea(view, &index);
QTC_ASSERT(area, return);
QTC_ASSERT(index >= 0 && index < d->m_editorAreas.size(), return);
// find previous editor area. this might be the same editor area if there's only one.
int nextIndex = index - 1;
if (nextIndex < 0)
nextIndex = d->m_editorAreas.count() - 1;
prevView = d->m_editorAreas.at(nextIndex)->findLastView();
QTC_CHECK(prevView);
}
if (prevView)
activateView(prevView);
}
void EditorManagerPrivate::makeCurrentEditorWritable()
{
if (IDocument* doc = EditorManager::currentDocument())
......
......@@ -137,6 +137,7 @@ public slots:
static void split(Qt::Orientation orientation);
static void removeAllSplits();
static void gotoPreviousSplit();
static void gotoNextSplit();
void handleDocumentStateChange();
......@@ -224,6 +225,7 @@ private:
QAction *m_splitNewWindowAction;
QAction *m_removeCurrentSplitAction;
QAction *m_removeAllSplitsAction;
QAction *m_gotoPreviousSplitAction;
QAction *m_gotoNextSplitAction;
QAction *m_copyFilePathContextAction;
......
......@@ -184,6 +184,29 @@ EditorView *EditorView::findNextView()
return 0;
}
EditorView *EditorView::findPreviousView()
{
SplitterOrView *current = parentSplitterOrView();
QTC_ASSERT(current, return 0);
SplitterOrView *parent = current->findParentSplitter();
while (parent) {
QSplitter *splitter = parent->splitter();
QTC_ASSERT(splitter, return 0);
QTC_ASSERT(splitter->count() == 2, return 0);
// is current the last child? then the previous view is the first child in current's sibling
if (splitter->widget(1) == current) {
SplitterOrView *first = qobject_cast<SplitterOrView *>(splitter->widget(0));
QTC_ASSERT(first, return 0);
return first->findFirstView();
}
// otherwise go up the hierarchy
current = parent;
parent = current->findParentSplitter();
}
// current has no parent, so we are at the top and there is no "previous" view
return 0;
}
void EditorView::closeCurrentEditor()
{
IEditor *editor = currentEditor();
......@@ -637,6 +660,19 @@ EditorView *SplitterOrView::findFirstView()
return m_view;
}
EditorView *SplitterOrView::findLastView()
{
if (m_splitter) {
for (int i = m_splitter->count() - 1; 0 < i; --i) {
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i)))
if (EditorView *result = splitterOrView->findLastView())
return result;
}
return 0;
}
return m_view;
}
SplitterOrView *SplitterOrView::findParentSplitter() const
{
QWidget *w = parentWidget();
......
......@@ -85,6 +85,7 @@ public:
SplitterOrView *parentSplitterOrView() const;
EditorView *findNextView();
EditorView *findPreviousView();
int editorCount() const;
void addEditor(IEditor *editor);
......@@ -197,6 +198,7 @@ public:
void restoreState(const QByteArray &);
EditorView *findFirstView();
EditorView *findLastView();
SplitterOrView *findParentSplitter() const;
QSize sizeHint() const { return minimumSizeHint(); }
......
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