Commit cc116313 authored by Christoph Cullmann's avatar Christoph Cullmann 🍨 Committed by Eric Armbruster
Browse files

ensure welcome view properly vanishes

now the welcome view always is removed when a new view
pops up in the same view space
parent 518f74da
......@@ -27,7 +27,6 @@
#include "katestashmanager.h"
#include "kateupdatedisabler.h"
#include "kateviewspace.h"
#include "katewelcomeview.h"
#include "ktexteditor_utils.h"
#include <KAboutData>
......@@ -178,9 +177,6 @@ KateMainWindow::KateMainWindow(KConfig *sconfig, const QString &sgroup)
if (KateApp::isKWrite()) {
setSidebarsVisibleInternal(false, true);
}
// ensure we have the welcome view if no active view is there
showWelcomeViewIfNeeded();
}
KateMainWindow::~KateMainWindow()
......@@ -1495,13 +1491,3 @@ void KateMainWindow::addRecentOpenedFile(const QUrl &url)
// to the global "Recent Document Menu", see bug 420504
// KRecentDocument::add(url);
}
void KateMainWindow::showWelcomeViewIfNeeded()
{
// delay the creation, e.g. used on startup
QTimer::singleShot(0, this, [this]() {
if (activeView())
return;
addWidget(new KateWelcomeView());
});
}
......@@ -138,12 +138,6 @@ public:
*/
void saveOptions();
/**
* Trigger creation of welcome view via timer.
* Will do nothing if we have some view around when the timer triggers.
*/
void showWelcomeViewIfNeeded();
private:
/**
* Setup actions which pointers are needed already in setupMainWindow
......
......@@ -13,6 +13,7 @@
#include "katemainwindow.h"
#include "kateupdatedisabler.h"
#include "kateviewspace.h"
#include "katewelcomeview.h"
#include <KTextEditor/Attribute>
#include <KTextEditor/Document>
......@@ -72,6 +73,9 @@ KateViewManager::KateViewManager(QWidget *parentW, KateMainWindow *parent)
*/
connect(KateApp::self()->documentManager(), &KateDocManager::aboutToDeleteDocuments, this, &KateViewManager::aboutToDeleteDocuments);
connect(KateApp::self()->documentManager(), &KateDocManager::documentsDeleted, this, &KateViewManager::documentsDeleted);
// ensure we have the welcome view if no active view is there
showWelcomeViewIfNeeded();
}
KateViewManager::~KateViewManager()
......@@ -492,6 +496,16 @@ KTextEditor::View *KateViewManager::createView(KTextEditor::Document *doc, KateV
doc = KateApp::self()->documentManager()->createDoc();
}
/**
* ensure the initial welcome view vanishes as soon as we have some real view!
*/
if (auto welcomeView = qobject_cast<KateWelcomeView *>((vs ? vs : activeViewSpace())->currentWidget())) {
// delay the deletion, we might be in event handling of some action from the welcome view itself!
QTimer::singleShot(0, welcomeView, [this, welcomeView]() {
mainWindow()->removeWidget(welcomeView);
});
}
/**
* create view, registers its XML gui itself
* pass the view the correct main window
......@@ -1081,7 +1095,7 @@ void KateViewManager::onViewSpaceEmptied(KateViewSpace *vs)
}
// else we want to trigger showing of the welcome view
m_mainWindow->showWelcomeViewIfNeeded();
showWelcomeViewIfNeeded();
}
void KateViewManager::setShowUrlNavBar(bool show)
......@@ -1495,3 +1509,13 @@ void KateViewManager::moveSplitter(Qt::Key key, int repeats)
currentSplitter = qobject_cast<KateSplitter *>(currentSplitter->parentWidget());
}
}
void KateViewManager::showWelcomeViewIfNeeded()
{
// delay the creation, e.g. used on startup
QTimer::singleShot(0, this, [this]() {
if (activeView())
return;
mainWindow()->addWidget(new KateWelcomeView());
});
}
......@@ -309,6 +309,12 @@ public Q_SLOTS:
void setShowUrlNavBar(bool show);
bool showUrlNavBar() const;
/**
* Trigger creation of welcome view via timer.
* Will do nothing if we have some view around when the timer triggers.
*/
void showWelcomeViewIfNeeded();
private:
KateMainWindow *m_mainWindow;
......
......@@ -18,24 +18,20 @@ KateWelcomeView::KateWelcomeView()
m_ui.setupUi(this);
setWindowTitle(i18n("Welcome"));
// new file action, closes welcome after creating a new document
// new file action, view manager will trigger close of the welcome view
m_ui.fileNew->setText(i18n("New File"));
m_ui.fileNew->setIcon(QIcon::fromTheme(QStringLiteral("file-new")));
connect(m_ui.fileNew, &QPushButton::clicked, this, [this]() {
// we ensure that we use the current view space
viewSpace()->viewManager()->slotDocumentNew();
QTimer::singleShot(0, this, [this]() {
viewSpace()->viewManager()->mainWindow()->removeWidget(this);
});
});
// open file action, closes welcome after creating a new document
// open file action, view manager will trigger close of the welcome view
m_ui.fileOpen->setText(i18n("Open File..."));
m_ui.fileOpen->setIcon(QIcon::fromTheme(QStringLiteral("file-open")));
connect(m_ui.fileOpen, &QPushButton::clicked, this, [this]() {
// we ensure that we use the current view space
viewSpace()->viewManager()->slotDocumentOpen();
QTimer::singleShot(0, this, [this]() {
viewSpace()->viewManager()->mainWindow()->removeWidget(this);
});
});
}
......
......@@ -13,6 +13,7 @@ class KateViewSpace;
/**
* Placeholder if a view space has no real views.
* Allows for a nice welcome experience :P
* The KateViewManager will ensure we instantiate the welcome view when needed and remove it later on.
*/
class KateWelcomeView : public QWidget
{
......
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