Commit 66a4c7ca authored by Eric Armbruster's avatar Eric Armbruster 🍁
Browse files

Move welcomeview code to viewmanager

parent b7a21fa1
......@@ -75,7 +75,6 @@
#include <QToolButton>
#include "diffwidget.h"
#include "welcomeview.h"
#include <ktexteditor/sessionconfiginterface.h>
......@@ -308,8 +307,6 @@ void KateMainWindow::setupActions()
m_fileOpenRecent->setMaxItems(KateConfigDialog::recentFilesMaxCount());
actionCollection()->addAction(m_fileOpenRecent->objectName(), m_fileOpenRecent);
m_fileOpenRecent->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
connect(m_fileOpenRecent, &KRecentFilesAction::recentListCleared, this, &KateMainWindow::refreshRecentsOnWelcomeView);
connect(m_welcomeView, &WelcomeView::forgetAllRecents, m_fileOpenRecent, &KRecentFilesAction::clear);
a = actionCollection()->addAction(QStringLiteral("file_save_all"));
a->setIcon(QIcon::fromTheme(QStringLiteral("document-save-all")));
......@@ -1494,57 +1491,3 @@ void KateMainWindow::addRecentOpenedFile(const QUrl &url)
// to the global "Recent Document Menu", see bug 420504
// KRecentDocument::add(url);
}
void KateMainWindow::hideWelcomeView()
{
if (auto welcomeView = qobject_cast<WelcomeView *>((viewManager()->activeViewSpace())->currentWidget())) {
QTimer::singleShot(0, welcomeView, [this, welcomeView]() {
removeWidget(welcomeView);
});
}
}
void KateMainWindow::showWelcomeView()
{
// delay the creation, e.g. used on startup
QTimer::singleShot(0, this, [this]() {
if (activeView())
return;
auto vs = viewManager()->activeViewSpace();
if (vs) {
m_welcomeView = new WelcomeView(this);
// todo m_welcomeView->installEventFilter(this);
connect(m_welcomeView, &WelcomeView::openClicked, this, [this]() {
viewManager()->slotDocumentOpen();
});
connect(m_welcomeView, &WelcomeView::recentItemClicked, this, [this](const QUrl &url) {
openUrl(url);
});
connect(m_welcomeView, &WelcomeView::forgetRecentItem, this, &KateMainWindow::forgetRecentItem);
addWidget(m_welcomeView);
refreshRecentsOnWelcomeView();
}
});
}
void KateMainWindow::refreshRecentsOnWelcomeView()
{
saveRecents();
m_welcomeView->loadRecents();
}
void KateMainWindow::forgetRecentItem(QUrl const &url)
{
if (m_fileOpenRecent != nullptr) {
m_fileOpenRecent->removeUrl(url);
saveRecents();
refreshRecentsOnWelcomeView();
}
}
void KateMainWindow::saveRecents()
{
m_fileOpenRecent->saveEntries(KSharedConfig::openConfig()->group("Recent Files"));
}
......@@ -44,7 +44,6 @@ class KRecentFilesAction;
class KateOutputView;
class KateViewManager;
class KateMwModOnHdDialog;
class WelcomeView;
// Helper layout class to always provide minimum size
class KateContainerStackedLayout : public QStackedLayout
......@@ -304,8 +303,10 @@ public:
*/
void addRecentOpenedFile(const QUrl &url);
// TODO
void saveRecents();
KRecentFilesAction *recentFilesAction()
{
return m_fileOpenRecent;
}
//
// KTextEditor::MainWindow interface, get called by invokeMethod from our wrapper object!
......@@ -562,13 +563,6 @@ public Q_SLOTS:
*/
void showMessage(const QVariantMap &map);
// TODO
public Q_SLOTS:
void hideWelcomeView();
void showWelcomeView();
void refreshRecentsOnWelcomeView();
void forgetRecentItem(QUrl const &url);
private Q_SLOTS:
void slotUpdateBottomViewBar();
......@@ -683,8 +677,6 @@ private:
*/
KateOutputView *m_outputView = nullptr;
WelcomeView *m_welcomeView = nullptr;
public:
/**
* The available actions for the mouse back button, used as indexing
......
......@@ -24,6 +24,7 @@
#include <KConfigGroup>
#include <KLocalizedString>
#include <KMessageBox>
#include <KSharedConfig>
#include <KToolBar>
#include <KXMLGUIFactory>
......@@ -75,7 +76,7 @@ KateViewManager::KateViewManager(QWidget *parentW, KateMainWindow *parent)
connect(KateApp::self()->documentManager(), &KateDocManager::documentsDeleted, this, &KateViewManager::documentsDeleted);
// ensure we have the welcome view if no active view is there
mainWindow()->showWelcomeView();
showWelcomeView();
}
KateViewManager::~KateViewManager()
......@@ -497,7 +498,7 @@ KTextEditor::View *KateViewManager::createView(KTextEditor::Document *doc, KateV
/**
* ensure the initial welcome view vanishes as soon as we have some real view!
*/
mainWindow()->hideWelcomeView();
hideWelcomeView(vs);
/**
* create view, registers its XML gui itself
......@@ -1093,7 +1094,7 @@ void KateViewManager::onViewSpaceEmptied(KateViewSpace *vs)
}
// else we want to trigger showing of the welcome view
mainWindow()->showWelcomeView();
showWelcomeView();
}
void KateViewManager::setShowUrlNavBar(bool show)
......@@ -1507,3 +1508,58 @@ void KateViewManager::moveSplitter(Qt::Key key, int repeats)
currentSplitter = qobject_cast<KateSplitter *>(currentSplitter->parentWidget());
}
}
void KateViewManager::hideWelcomeView(KateViewSpace *vs)
{
if (auto welcomeView = qobject_cast<WelcomeView *>(vs ? vs : activeViewSpace()->currentWidget())) {
QTimer::singleShot(0, welcomeView, [this, welcomeView]() {
mainWindow()->removeWidget(welcomeView);
});
}
}
void KateViewManager::showWelcomeView()
{
// delay the creation, e.g. used on startup
QTimer::singleShot(0, this, [this]() {
if (activeView())
return;
if (!m_welcomeView) {
m_welcomeView = new WelcomeView(this);
connect(m_welcomeView, &WelcomeView::openClicked, this, &KateViewManager::slotDocumentOpen);
connect(m_welcomeView, &WelcomeView::recentItemClicked, this, [this](const QUrl &url) {
openUrl(url);
});
connect(m_welcomeView, &WelcomeView::forgetRecentItem, this, &KateViewManager::forgetRecentItem);
auto recentFilesAction = mainWindow()->recentFilesAction();
connect(recentFilesAction, &KRecentFilesAction::recentListCleared, this, &KateViewManager::refreshRecentsOnWelcomeView);
connect(m_welcomeView, &WelcomeView::forgetAllRecents, recentFilesAction, &KRecentFilesAction::clear);
}
mainWindow()->addWidget(m_welcomeView);
refreshRecentsOnWelcomeView();
});
}
void KateViewManager::refreshRecentsOnWelcomeView()
{
saveRecents();
m_welcomeView->loadRecents();
}
void KateViewManager::forgetRecentItem(QUrl const &url)
{
auto recentFilesAction = mainWindow()->recentFilesAction();
if (recentFilesAction != nullptr) {
recentFilesAction->removeUrl(url);
saveRecents();
refreshRecentsOnWelcomeView();
}
}
void KateViewManager::saveRecents()
{
mainWindow()->recentFilesAction()->saveEntries(KSharedConfig::openConfig()->group("Recent Files"));
}
......@@ -36,6 +36,7 @@ class KConfigGroup;
class KConfigBase;
class KateMainWindow;
class KateViewSpace;
class WelcomeView;
class KATE_PRIVATE_EXPORT KateViewManager : public KateSplitter
{
......@@ -142,6 +143,8 @@ private:
void removeViewSpace(KateViewSpace *viewspace);
void saveRecents();
public:
KTextEditor::View *activeView();
KateViewSpace *activeViewSpace();
......@@ -309,6 +312,11 @@ public Q_SLOTS:
void setShowUrlNavBar(bool show);
bool showUrlNavBar() const;
void hideWelcomeView(KateViewSpace *vs);
void showWelcomeView();
void refreshRecentsOnWelcomeView();
void forgetRecentItem(QUrl const &url);
private:
KateMainWindow *m_mainWindow;
......@@ -380,6 +388,8 @@ private:
* last url of open file dialog, used if current document has no valid url
*/
QUrl m_lastOpenDialogUrl;
WelcomeView *m_welcomeView = nullptr;
};
#endif
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