Commit a942dbc5 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

set activeView to null when a non-KTE::View is active

This fixes the issue that we don't have the gui client for activeView
not merged into the MainWindow.

Lots of code is simplified, activeView now just returns m_guiMergedView
and doesn't try to do any other thing like it was doing before.

ViewData::active is removed, m_guiMergedView is the source of truth now.

Further improvements could be to _really ensure_ that viewspace itself
doesn't do **any** view activation by itself. That means no direct
showView etc from inside ViewSpaces.
parent 410b1fbc
......@@ -103,6 +103,12 @@ void KateViewManagementTests::testViewspaceClosesWhenThereIsWidget()
// Widget should be active
QVERIFY(vm->activeViewSpace()->currentWidget());
// activeView() should be nullptr
QVERIFY(!vm->activeView());
// Make the view active
vm->activateView(vm->m_views.begin()->first);
QVERIFY(vm->activeView() == vm->m_views.begin()->first);
// close active view
// active view still points to the last active view
......@@ -226,17 +232,22 @@ void KateViewManagementTests::testTabLRUWithWidgets()
// Add a widget
QWidget *widget = new QWidget;
widget->setObjectName(QStringLiteral("widget"));
Utils::addWidget(widget, app->activeMainWindow());
QCOMPARE(vs->currentWidget(), widget);
// There should be no activeView
QVERIFY(!vm->activeView());
QCOMPARE(vs->m_registeredDocuments.size(), 4);
// activate view1
vm->activateView(view1->document());
QVERIFY(vm->activeView());
// activate widget again
QCOMPARE(vs->currentWidget(), nullptr);
vm->activateWidget(widget);
QCOMPARE(vs->currentWidget(), widget);
QVERIFY(!vm->activeView());
// close "widget"
vm->slotDocumentClose();
......
......@@ -481,5 +481,4 @@ void KateTabBar::setCurrentWidget(QWidget *widget)
setTabIcon(idx, widget->windowIcon());
setTabData(idx, QVariant::fromValue(widget));
setCurrentIndex(idx);
Q_EMIT currentChanged(idx);
}
......@@ -46,7 +46,6 @@ KateViewManager::KateViewManager(QWidget *parentW, KateMainWindow *parent)
: KateSplitter(parentW)
, m_mainWindow(parent)
, m_blockViewCreationAndActivation(false)
, m_activeViewRunning(false)
, m_minAge(0)
, m_guiMergedView(nullptr)
{
......@@ -593,7 +592,7 @@ void KateViewManager::documentsDeleted(const QList<KTextEditor::Document *> &)
* this might be missed as above we had m_blockViewCreationAndActivation set to true
* see bug 426605, no view XMLGUI stuff merged after tab close
*/
reactivateActiveView();
replugActiveView();
// trigger action update
updateViewSpaceActions();
......@@ -635,7 +634,6 @@ KTextEditor::View *KateViewManager::createView(KTextEditor::Document *doc, KateV
* remember this view, active == false, min age set
* create activity resource
*/
m_views[view].active = false;
m_views[view].lruAge = m_minAge--;
#ifdef KF5Activities_FOUND
......@@ -759,41 +757,7 @@ bool KateViewManager::activateWidget(QWidget *w)
KTextEditor::View *KateViewManager::activeView()
{
if (m_activeViewRunning) {
return nullptr;
}
m_activeViewRunning = true;
for (const auto &[view, viewData] : m_views) {
if (viewData.active) {
m_activeViewRunning = false;
return view;
}
}
// if we get to here, no view isActive()
// first, try to get one from activeViewSpace()
KateViewSpace *vs = activeViewSpace();
if (vs && vs->currentView()) {
activateView(vs->currentView());
m_activeViewRunning = false;
return vs->currentView();
}
// last attempt: pick MRU view
if (auto sortedViews = views(); !sortedViews.empty()) {
KTextEditor::View *v = sortedViews.front();
activateView(v);
m_activeViewRunning = false;
return v;
}
m_activeViewRunning = false;
// no views exists!
return nullptr;
return m_guiMergedView;
}
void KateViewManager::setActiveSpace(KateViewSpace *vs)
......@@ -809,17 +773,6 @@ void KateViewManager::setActiveSpace(KateViewSpace *vs)
Q_EMIT historyForwardEnabled(vs->isHistoryForwardEnabled());
}
void KateViewManager::setActiveView(KTextEditor::View *view)
{
if (auto v = activeView()) {
m_views[v].active = false;
}
if (view) {
m_views[view].active = true;
}
}
void KateViewManager::activateSpace(KTextEditor::View *v)
{
if (!v) {
......@@ -836,20 +789,9 @@ void KateViewManager::activateSpace(KTextEditor::View *v)
void KateViewManager::replugActiveView()
{
if (auto view = activeView()) {
if (m_guiMergedView == view) {
mainWindow()->guiFactory()->removeClient(m_guiMergedView);
mainWindow()->guiFactory()->addClient(view);
}
}
}
void KateViewManager::reactivateActiveView()
{
KTextEditor::View *view = activeView();
if (view) {
m_views[view].active = false;
activateView(view);
if (m_guiMergedView) {
mainWindow()->guiFactory()->removeClient(m_guiMergedView);
mainWindow()->guiFactory()->addClient(m_guiMergedView);
}
}
......@@ -864,11 +806,7 @@ void KateViewManager::activateView(KTextEditor::View *view)
return;
}
auto it = m_views.find(view);
Q_ASSERT(it != m_views.end());
ViewData &viewData = it->second;
if (!viewData.active) {
if (!m_guiMergedView || m_guiMergedView != view) {
// avoid flicker
KateUpdateDisabler disableUpdates(mainWindow());
......@@ -878,8 +816,6 @@ void KateViewManager::activateView(KTextEditor::View *view)
return;
}
setActiveView(view);
bool toolbarVisible = mainWindow()->toolBar()->isVisible();
if (toolbarVisible) {
mainWindow()->toolBar()->hide(); // hide to avoid toolbar flickering
......@@ -899,6 +835,9 @@ void KateViewManager::activateView(KTextEditor::View *view)
mainWindow()->toolBar()->show();
}
auto it = m_views.find(view);
Q_ASSERT(it != m_views.end());
ViewData &viewData = it->second;
// remember age of this view
viewData.lruAge = m_minAge--;
......
......@@ -100,7 +100,6 @@ public Q_SLOTS:
void slotDocumentClose(KTextEditor::Document *document);
void setActiveSpace(KateViewSpace *vs);
void setActiveView(KTextEditor::View *view);
void activateNextView();
void activatePrevView();
......@@ -279,8 +278,6 @@ public Q_SLOTS:
void replugActiveView();
void reactivateActiveView();
/**
* Toogle the orientation of current split view
*/
......@@ -343,8 +340,6 @@ private:
bool m_blockViewCreationAndActivation;
bool m_activeViewRunning;
bool m_showUrlNavBar = false;
int m_splitterIndex = 0; // used during saving splitter config.
......@@ -355,11 +350,6 @@ private:
class ViewData
{
public:
/**
* view active?
*/
bool active = false;
/**
* lru age of the view
* important: smallest age ==> latest used view
......
......@@ -367,27 +367,16 @@ void KateViewSpace::removeView(KTextEditor::View *v)
// switch to most recently used rather than letting stack choose one
// (last element could well be v->document() being removed here)
bool shown = false;
for (auto rit = m_registeredDocuments.rbegin(); rit != m_registeredDocuments.rend(); ++rit) {
if (auto doc = rit->doc()) {
shown = showView(doc);
m_viewManager->activateView(doc);
break;
} else if (auto wid = rit->widget()) {
activateWidget(wid);
shown = true;
break;
}
}
// This can happen if no other tab has a view in this viewspace
if (!shown) {
// At this point our current index has already changed
int idx = m_tabBar->currentIndex();
if (idx != -1) {
m_viewManager->activateView(m_tabBar->tabDocument(idx));
}
}
// Did we just loose our last doc?
// Send a delayed signal. Delay is important as we want to kill
// the viewspace after the view transfer was done
......@@ -469,16 +458,8 @@ void KateViewSpace::changeView(int idx)
return;
}
auto currentActiveWidget = currentWidget();
// tell the view manager to show the view
m_viewManager->activateView(doc);
// If we had a non-KTE::View widget as active, emit the signal
// so that any listeners can tell that tab was changed
if (currentActiveWidget) {
Q_EMIT m_viewManager->viewChanged(m_viewManager->activeView());
}
}
KTextEditor::View *KateViewSpace::currentView()
......@@ -757,7 +738,7 @@ void KateViewSpace::closeTabRequest(int idx)
// switch to most recently used doc
for (auto rit = m_registeredDocuments.rbegin(); rit != m_registeredDocuments.rend(); ++rit) {
if (auto doc = rit->doc()) {
showView(doc);
m_viewManager->activateView(doc);
break;
} else if (auto wid = rit->widget()) {
activateWidget(wid);
......@@ -867,6 +848,7 @@ bool KateViewSpace::activateWidget(QWidget *widget)
m_registeredDocuments.removeOne(widget);
m_registeredDocuments.append(widget);
m_viewManager->activateView(static_cast<KTextEditor::Document *>(nullptr));
return true;
}
}
......
Supports Markdown
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