Commit 7caed268 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Create filebrowser on demand

We spend a lot of time during startup creating the filebrowser while it
may not be needed immediately. Delay creating it until the user wants to
see it.
parent 602386d3
Pipeline #132944 passed with stage
in 4 minutes and 50 seconds
......@@ -114,6 +114,8 @@ KateFileBrowser::KateFileBrowser(KTextEditor::MainWindow *mainWindow, QWidget *p
connect(m_mainWindow, &KTextEditor::MainWindow::viewChanged, this, &KateFileBrowser::autoSyncFolder);
connect(m_dirOperator, &KDirOperator::contextMenuAboutToShow, this, &KateFileBrowser::contextMenuAboutToShow);
autoSyncFolder();
}
KateFileBrowser::~KateFileBrowser()
......
......@@ -52,7 +52,10 @@ KTextEditor::ConfigPage *KateFileBrowserPlugin::configPage(int number, QWidget *
if (number != 0) {
return nullptr;
}
return new KateFileBrowserConfigPage(parent, m_views[0]->m_fileBrowser);
if (!m_views[0]->m_fileBrowser) {
m_views[0]->createFileBrowser(true);
}
return new KateFileBrowserConfigPage(parent, m_views[0]->m_fileBrowser.get());
}
// END KateFileBrowserPlugin
......@@ -64,34 +67,50 @@ KateFileBrowserPluginView::KateFileBrowserPluginView(KTextEditor::Plugin *plugin
KTextEditor::MainWindow::Left,
QIcon::fromTheme(QStringLiteral("document-open")),
i18n("Filesystem Browser")))
, m_fileBrowser(new KateFileBrowser(mainWindow, m_toolView))
, m_mainWindow(mainWindow)
{
m_toolView->installEventFilter(this);
connect(m_toolView.get(), SIGNAL(toolVisibleChanged(bool)), this, SLOT(createFileBrowser(bool)));
}
KateFileBrowserPluginView::~KateFileBrowserPluginView()
void KateFileBrowserPluginView::readSessionConfig(const KConfigGroup &config)
{
// cleanup, kill toolview + console
delete m_fileBrowser->parentWidget();
if (m_fileBrowser) {
m_fileBrowser->readSessionConfig(config);
} else {
cg.reset(new KConfigGroup(config));
}
}
void KateFileBrowserPluginView::readSessionConfig(const KConfigGroup &config)
void KateFileBrowserPluginView::writeSessionConfig(KConfigGroup &config)
{
m_fileBrowser->readSessionConfig(config);
if (m_fileBrowser) {
m_fileBrowser->writeSessionConfig(config);
}
}
void KateFileBrowserPluginView::writeSessionConfig(KConfigGroup &config)
void KateFileBrowserPluginView::createFileBrowser(bool visible)
{
m_fileBrowser->writeSessionConfig(config);
if (!visible) {
return;
}
// we must not have a filebrowser
Q_ASSERT(!m_fileBrowser);
disconnect(m_toolView.get(), SIGNAL(toolVisibleChanged(bool)), this, SLOT(createFileBrowser(bool)));
m_fileBrowser = std::make_unique<KateFileBrowser>(m_mainWindow, m_toolView.get());
m_fileBrowser->readSessionConfig(*cg);
// delete the config now
cg.reset();
}
bool KateFileBrowserPluginView::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
if ((obj == m_toolView) && (ke->key() == Qt::Key_Escape)) {
m_mainWindow->hideToolView(m_toolView);
if ((obj == m_toolView.get()) && (ke->key() == Qt::Key_Escape)) {
m_mainWindow->hideToolView(m_toolView.get());
event->accept();
return true;
}
......
......@@ -11,12 +11,15 @@
#ifndef KATE_FILEBROWSER_PLUGIN_H
#define KATE_FILEBROWSER_PLUGIN_H
#include <KConfigGroup>
#include <KTextEditor/SessionConfigInterface>
#include <ktexteditor/configpage.h>
#include <ktexteditor/document.h>
#include <ktexteditor/mainwindow.h>
#include <ktexteditor/plugin.h>
#include <memory>
class KateFileBrowser;
class KateFileBrowserPluginView;
......@@ -53,19 +56,16 @@ public:
*/
KateFileBrowserPluginView(KTextEditor::Plugin *plugin, KTextEditor::MainWindow *mainWindow);
/**
* Virtual destructor.
*/
~KateFileBrowserPluginView() override;
void readSessionConfig(const KConfigGroup &config) override;
void writeSessionConfig(KConfigGroup &config) override;
private:
bool eventFilter(QObject *, QEvent *) override;
Q_SLOT void createFileBrowser(bool visible);
QWidget *m_toolView;
KateFileBrowser *m_fileBrowser;
std::unique_ptr<QWidget> m_toolView;
std::unique_ptr<KateFileBrowser> m_fileBrowser = nullptr;
std::unique_ptr<KConfigGroup> cg;
KTextEditor::MainWindow *m_mainWindow;
friend class KateFileBrowserPlugin;
};
......
Markdown is supported
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