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

dynamic view space lookup

parent 6b7207a9
......@@ -1502,6 +1502,6 @@ void KateMainWindow::showWelcomeViewIfNeeded()
QTimer::singleShot(0, this, [this]() {
if (activeView())
return;
addWidget(new KateWelcomeView(m_viewManager->activeViewSpace(), nullptr));
addWidget(new KateWelcomeView());
});
}
......@@ -12,22 +12,19 @@
#include <QPushButton>
#include <QTimer>
KateWelcomeView::KateWelcomeView(KateViewSpace *viewSpace, QWidget *parent)
: QWidget(parent)
, m_viewSpace(viewSpace)
KateWelcomeView::KateWelcomeView()
{
// setup ui & ensure proper title for tab & co.
m_ui.setupUi(this);
// ensure proper title for tab & co.
setWindowTitle(i18n("Welcome"));
// new file action, closes welcome after creating a new document
m_ui.fileNew->setText(i18n("New File"));
m_ui.fileNew->setIcon(QIcon::fromTheme(QStringLiteral("file-new")));
connect(m_ui.fileNew, &QPushButton::clicked, this, [this]() {
m_viewSpace->viewManager()->slotDocumentNew();
viewSpace()->viewManager()->slotDocumentNew();
QTimer::singleShot(0, this, [this]() {
m_viewSpace->viewManager()->mainWindow()->removeWidget(this);
viewSpace()->viewManager()->mainWindow()->removeWidget(this);
});
});
......@@ -35,9 +32,23 @@ KateWelcomeView::KateWelcomeView(KateViewSpace *viewSpace, QWidget *parent)
m_ui.fileOpen->setText(i18n("Open File..."));
m_ui.fileOpen->setIcon(QIcon::fromTheme(QStringLiteral("file-open")));
connect(m_ui.fileOpen, &QPushButton::clicked, this, [this]() {
m_viewSpace->viewManager()->slotDocumentOpen();
viewSpace()->viewManager()->slotDocumentOpen();
QTimer::singleShot(0, this, [this]() {
m_viewSpace->viewManager()->mainWindow()->removeWidget(this);
viewSpace()->viewManager()->mainWindow()->removeWidget(this);
});
});
}
KateViewSpace *KateWelcomeView::viewSpace()
{
// this view can be re-parented, search upwards the current view space
auto p = parent();
while (p) {
if (auto vs = qobject_cast<KateViewSpace *>(p)) {
return vs;
}
p = p->parent();
}
Q_ASSERT(false);
return nullptr;
}
......@@ -21,14 +21,13 @@ class KateWelcomeView : public QWidget
public:
/**
* Construct new output, we do that once per main window
* @param viewSpace parent view space
* @param parent parent widget
*/
KateWelcomeView(KateViewSpace *viewSpace, QWidget *parent);
KateWelcomeView();
public Q_SLOTS:
/**
* Welcome view can always be closed.
* @return can always be closed
*/
bool shouldClose()
{
......@@ -36,9 +35,14 @@ public Q_SLOTS:
}
private:
// our viewspace we belong to
KateViewSpace *const m_viewSpace = nullptr;
/**
* Get the view space we belong to.
* As we can in principle be dragged around.
* @return view space we belong to
*/
KateViewSpace *viewSpace();
private:
// designer UI for this widget
Ui::WelcomeViewWidget m_ui;
};
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