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

allow that no document is open

this is an extension of allowing we have no views
parent c022bf99
......@@ -66,7 +66,7 @@ if (TARGET KUserFeedbackWidgets)
target_compile_definitions(kateprivate PUBLIC -DWITH_KUSERFEEDBACK)
endif()
ki18n_wrap_ui(kateprivate ui/sessionconfigwidget.ui session/katesessionmanagedialog.ui)
ki18n_wrap_ui(kateprivate ui/sessionconfigwidget.ui ui/welcome.ui session/katesessionmanagedialog.ui)
target_sources(
kateprivate
......@@ -97,6 +97,7 @@ target_sources(
katesplitter.cpp
kateviewmanager.cpp
kateviewspace.cpp
katewelcomeview.cpp
tabmimedata.cpp
kateoutputview.cpp
......
......@@ -39,9 +39,6 @@ KateDocManager::KateDocManager(QObject *parent)
{
// set our application wrapper
KTextEditor::Editor::instance()->setApplication(KateApp::self()->wrapper());
// create one doc, we always have at least one around!
createDoc();
}
KateDocManager::~KateDocManager()
......@@ -212,14 +209,6 @@ bool KateDocManager::closeDocuments(const QList<KTextEditor::Document *> documen
last++;
}
/**
* never ever empty the whole document list
* do this before documentsDeleted is emitted, to have no flicker
*/
if (m_docList.empty()) {
createDoc();
}
Q_EMIT documentsDeleted(QList<KTextEditor::Document *>{documents.begin() + last, documents.end()});
return success;
......@@ -409,13 +398,7 @@ void KateDocManager::restoreDocumentList(KConfig *config)
for (unsigned int i = 0; i < count; i++) {
KConfigGroup cg(config, QStringLiteral("Document %1").arg(i));
KTextEditor::Document *doc = nullptr;
if (i == 0) {
doc = m_docList.front();
} else {
doc = createDoc();
}
KTextEditor::Document *doc = createDoc();
connect(doc, SIGNAL(completed()), this, SLOT(documentOpened()));
connect(doc, &KParts::ReadOnlyPart::canceled, this, &KateDocManager::documentOpened);
......
......@@ -27,6 +27,7 @@
#include "katestashmanager.h"
#include "kateupdatedisabler.h"
#include "kateviewspace.h"
#include "katewelcomeview.h"
#include "ktexteditor_utils.h"
#include <KAboutData>
......@@ -177,6 +178,14 @@ 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
// delay this after initialisation
QTimer::singleShot(0, this, [this]() {
if (activeView())
return;
addWidget(new KateWelcomeView(m_viewManager->activeViewSpace(), nullptr));
});
}
KateMainWindow::~KateMainWindow()
......
......@@ -485,4 +485,5 @@ void KateTabBar::setCurrentWidget(QWidget *widget)
setTabIcon(idx, widget->windowIcon());
setTabData(idx, QVariant::fromValue(widget));
setCurrentIndex(idx);
Q_EMIT currentChanged(idx);
}
......@@ -1298,7 +1298,7 @@ void KateViewManager::restoreViewConfiguration(const KConfigGroup &config)
// activate correct view (wish #195435, #188764)
activateView(m_viewSpaceList.at(lastViewSpace)->currentView());
// give view the focus to avoid focus stealing by toolviews / plugins
m_viewSpaceList.at(lastViewSpace)->currentView()->setFocus();
m_viewSpaceList.at(lastViewSpace)->setFocus();
}
// emergency
......@@ -1312,14 +1312,6 @@ void KateViewManager::restoreViewConfiguration(const KConfigGroup &config)
addWidget(vs);
vs->setActive(true);
m_viewSpaceList.push_back(vs);
/**
* activate at least one document!
*/
activateView(KateApp::self()->documentManager()->documentList().back());
if (!vs->currentView()) {
createView(activeView()->document(), vs);
}
}
updateViewSpaceActions();
......
......@@ -448,7 +448,7 @@ void KateViewSpace::changeView(int idx)
if (!doc) {
auto w = m_tabBar->tabData(idx).value<QWidget *>();
if (!w) {
Q_ASSERT(false);
// can happen during widget creation if no view is there initially
return;
}
stack->setCurrentWidget(w);
......@@ -1122,26 +1122,8 @@ void KateViewSpace::restoreConfig(KateViewManager *viewMan, const KConfigBase *c
}
}
// avoid empty view space
if (m_docToView.empty()) {
auto *doc = KateApp::self()->documentManager()->documentList().first();
if (!fn.isEmpty()) {
QUrl url(fn);
auto *docInfo = KateApp::self()->documentManager()->documentInfo(doc);
if (KateApp::self()->hasCursorInArgs()) {
docInfo->startCursor = KateApp::self()->cursorFromArgs();
} else if (url.hasQuery()) {
docInfo->startCursor = KateApp::self()->cursorFromQueryString(url);
}
}
viewMan->createView(doc, this);
}
// there must be a view now
Q_ASSERT(currentView());
// ensure we update the urlbar at least once
m_urlBar->updateForDocument(currentView()->document());
m_urlBar->updateForDocument(currentView() ? currentView()->document() : nullptr);
m_group = groupname; // used for restroing view configs later
}
......
/*
SPDX-FileCopyrightText: 2022 Christoph Cullmann <cullmann@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "katewelcomeview.h"
KateWelcomeView::KateWelcomeView(KateViewSpace *viewSpace, QWidget *parent)
: QWidget(parent)
, m_viewSpace(viewSpace)
{
m_ui.setupUi(this);
}
/*
SPDX-FileCopyrightText: 2022 Christoph Cullmann <cullmann@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "ui_welcome.h"
class KateViewSpace;
/**
* Placeholder if a view space has no real views.
* Allows for a nice welcome experience :P
*/
class KateWelcomeView : public QWidget
{
Q_OBJECT
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);
private:
// our viewspace we belong to
KateViewSpace *const m_viewSpace = nullptr;
// designer UI for this widget
Ui::WelcomeViewWidget m_ui;
};
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WelcomeViewWidget</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>990</width>
<height>593</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Kate - KDE Advance Text Editor</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Start</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Recent</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</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