File 2000-project-plugin.patch of Package kate
diff --git a/apps/lib/katemainwindow.cpp b/apps/lib/katemainwindow.cpp
index 9585d77bdde25f617134ebce703ed56e672b605a..db6acc3dc308931efe53080407ff48439779b843 100644
--- a/apps/lib/katemainwindow.cpp
+++ b/apps/lib/katemainwindow.cpp
@@ -1447,14 +1447,50 @@ bool KateMainWindow::event(QEvent *e)
return KateMDI::MainWindow::event(e);
}
-QObject *KateMainWindow::pluginView(const QString &name)
+QObject *KateMainWindow::pluginView(const QString &name, bool askToActivate)
{
- KTextEditor::Plugin *plugin = KateApp::self()->pluginManager()->plugin(name);
- if (!plugin) {
+ if (KTextEditor::Plugin *plugin = KateApp::self()->pluginManager()->plugin(name)) {
+ return m_pluginViews.value(plugin);
+ }
+
+ if (!askToActivate) {
+ return nullptr;
+ }
+
+ // try to find and activate the plugin
+ KatePluginList &pluginList = KateApp::self()->pluginManager()->pluginList();
+ KatePluginList::iterator i = std::find_if(pluginList.begin(), pluginList.end(), [&name](const KatePluginInfo &pluginInfo) {
+ return pluginInfo.metaData.pluginId() == name;
+ });
+
+ QString text;
+ if (i == pluginList.end()) {
+ text = i18n("The required plugin was not found");
+ KMessageBox::error(this, text);
return nullptr;
}
- return m_pluginViews.contains(plugin) ? m_pluginViews.value(plugin) : nullptr;
+ KatePluginInfo &pluginInfo = *i;
+ text = i18n("In order to continue, the <b>%1</b> plugin must be enabled. Enable it?", pluginInfo.metaData.name());
+ if (KMessageBox::questionTwoActions(this,
+ text,
+ i18nc("@title:window", "Enable Plugin"),
+ KGuiItem(i18nc("@action:button", "Enable"),
+ QStringLiteral("dialog-ok")),
+ KStandardGuiItem::cancel())
+ == KMessageBox::SecondaryAction) {
+ return nullptr;
+ }
+
+ if (!KateApp::self()->pluginManager()->loadPlugin(&pluginInfo)) {
+ text = i18n("Failed to enable the <b>%1</b> plugin", pluginInfo.metaData.name());
+ KMessageBox::error(this, text);
+ return nullptr;
+ }
+
+ KateApp::self()->pluginManager()->enablePluginGUI(&pluginInfo);
+
+ return m_pluginViews.value(pluginInfo.plugin);
}
bool KateMainWindow::addWidget(QWidget *widget)
diff --git a/apps/lib/katemainwindow.h b/apps/lib/katemainwindow.h
index 8ae6c9afeb563e7f14f5bae4b98405fad901ced6..0ae44c72c7b9e5d930331548bbf3ef061bde2c38 100644
--- a/apps/lib/katemainwindow.h
+++ b/apps/lib/katemainwindow.h
@@ -567,7 +567,7 @@ public Q_SLOTS:
* \return pointer to the plugin view if a plugin with \p name is loaded and has a view for this mainwindow,
* otherwise NULL
*/
- QObject *pluginView(const QString &name);
+ QObject *pluginView(const QString &name, bool askToActivate = false);
/**
* Add a widget to the main window.
diff --git a/apps/lib/kateviewmanager.cpp b/apps/lib/kateviewmanager.cpp
index 9629239c7a9e8394369b9a49b5fd16c415f07129..9f7f0b0a2ceb14138d8b24dcbf7d0f870a8a4294 100644
--- a/apps/lib/kateviewmanager.cpp
+++ b/apps/lib/kateviewmanager.cpp
@@ -528,6 +528,19 @@ void KateViewManager::openUrl(const QUrl &url)
openUrl(url, QString());
}
+void KateViewManager::openProject()
+{
+ if (KateApp::isKWrite()) {
+ const QString text = i18n("%1 cannot open folders", KAboutData::applicationData().displayName());
+ KMessageBox::error(mainWindow(), text);
+ return;
+ }
+
+ if (QObject *pluginView = mainWindow()->pluginView(QStringLiteral("kateprojectplugin"), true)) {
+ QMetaObject::invokeMethod(pluginView, "openDirectoryOrProject");
+ }
+}
+
void KateViewManager::openUrlOrProject(const QUrl &url)
{
if (!url.isLocalFile()) {
@@ -548,46 +561,9 @@ void KateViewManager::openUrlOrProject(const QUrl &url)
return;
}
- // try to open the folder
- static const QString projectPluginId = QStringLiteral("kateprojectplugin");
- QObject *projectPluginView = mainWindow()->pluginView(projectPluginId);
- if (!projectPluginView) {
- // try to find and enable the Projects plugin
- KatePluginList &pluginList = KateApp::self()->pluginManager()->pluginList();
- KatePluginList::iterator i = std::find_if(pluginList.begin(), pluginList.end(), [](const KatePluginInfo &pluginInfo) {
- return pluginInfo.metaData.pluginId() == projectPluginId;
- });
-
- QString text;
- if (i == pluginList.end()) {
- text = i18n("The plugin required to open folders was not found");
- KMessageBox::error(mainWindow(), text);
- return;
- }
-
- KatePluginInfo &projectPluginInfo = *i;
- text = i18n("In order to open folders, the <b>%1</b> plugin must be enabled. Enable it?", projectPluginInfo.metaData.name());
- if (KMessageBox::questionTwoActions(mainWindow(),
- text,
- i18nc("@title:window", "Open Folder"),
- KGuiItem(i18nc("@action:button", "Enable"), QStringLiteral("dialog-ok")),
- KStandardGuiItem::cancel())
- == KMessageBox::SecondaryAction) {
- return;
- }
-
- if (!KateApp::self()->pluginManager()->loadPlugin(&projectPluginInfo)) {
- text = i18n("Failed to enable <b>%1</b> plugin", projectPluginInfo.metaData.name());
- KMessageBox::error(mainWindow(), text);
- return;
- }
-
- KateApp::self()->pluginManager()->enablePluginGUI(&projectPluginInfo);
- projectPluginView = mainWindow()->pluginView(projectPluginId);
+ if (QObject *pluginView = mainWindow()->pluginView(QStringLiteral("kateprojectplugin"), true)) {
+ QMetaObject::invokeMethod(pluginView, "openDirectoryOrProject", Q_ARG(const QDir &, dir));
}
-
- Q_ASSERT(projectPluginView);
- QMetaObject::invokeMethod(projectPluginView, "openDirectoryOrProject", Q_ARG(const QDir &, dir));
}
KTextEditor::View *KateViewManager::openViewForDoc(KTextEditor::Document *doc)
diff --git a/apps/lib/kateviewmanager.h b/apps/lib/kateviewmanager.h
index ac5c1d29fae253730937270498ac98dfad50100a..ce0122deefb0c561b8672b59a1787b7e4c5f16bd 100644
--- a/apps/lib/kateviewmanager.h
+++ b/apps/lib/kateviewmanager.h
@@ -78,6 +78,7 @@ public:
public:
void openUrl(const QUrl &url);
+ void openProject();
void openUrlOrProject(const QUrl &url);
void addPositionToHistory(const QUrl &url, KTextEditor::Cursor pos);
diff --git a/apps/lib/welcomeview/welcomeview.cpp b/apps/lib/welcomeview/welcomeview.cpp
index bd270baaae88a375bb7a2590cf8bc83017ddcdef..aceb8ef1282dd5b836f310c9e9c5ccf4c738bd6f 100644
--- a/apps/lib/welcomeview/welcomeview.cpp
+++ b/apps/lib/welcomeview/welcomeview.cpp
@@ -89,9 +89,9 @@ WelcomeView::WelcomeView(KateViewManager *viewManager, QWidget *parent)
connect(buttonNewFile, &QPushButton::clicked, m_viewManager, &KateViewManager::slotDocumentNew);
connect(buttonOpenFile, &QPushButton::clicked, m_viewManager, &KateViewManager::slotDocumentOpen);
- connect(buttonClearRecentItems, &QPushButton::clicked, this, [recentFilesAction]() {
- recentFilesAction->clear();
- });
+ connect(buttonOpenFolder, &QPushButton::clicked, m_viewManager, &KateViewManager::openProject);
+ connect(buttonClearRecentItems, &QPushButton::clicked,
+ recentFilesAction, &KRecentFilesAction::clear);
connect(labelHomepage, qOverload<>(&KUrlLabel::leftClickedUrl), this, [aboutData]() {
QDesktopServices::openUrl(QUrl(aboutData.homepage()));
@@ -99,17 +99,11 @@ WelcomeView::WelcomeView(KateViewManager *viewManager, QWidget *parent)
connect(labelContribute, qOverload<>(&KUrlLabel::leftClickedUrl), this, []() {
QDesktopServices::openUrl(QUrl(QStringLiteral("https://kate-editor.org/join-us")));
});
- connect(labelHandbook, qOverload<>(&KUrlLabel::leftClickedUrl), this, [this]() {
- m_viewManager->mainWindow()->appHelpActivated();
- });
-
- onPluginViewChanged();
-
- const KTextEditor::MainWindow *mainWindow = m_viewManager->mainWindow()->wrapper();
- connect(mainWindow, &KTextEditor::MainWindow::pluginViewCreated, this, &WelcomeView::onPluginViewChanged);
- connect(mainWindow, &KTextEditor::MainWindow::pluginViewDeleted, this, &WelcomeView::onPluginViewChanged);
+ connect(labelHandbook, qOverload<>(&KUrlLabel::leftClickedUrl),
+ m_viewManager->mainWindow(), &KateMainWindow::appHelpActivated);
if (KateApp::isKWrite()) {
+ buttonOpenFolder->hide();
widgetSavedSessions->hide();
} else {
m_placeholderSavedSessions = new Placeholder;
@@ -209,20 +203,6 @@ bool WelcomeView::eventFilter(QObject *watched, QEvent *event)
return QScrollArea::eventFilter(watched, event);
}
-void WelcomeView::onPluginViewChanged(const QString &pluginName)
-{
- static const QString projectPluginName = QStringLiteral("kateprojectplugin");
- if (pluginName.isEmpty() || pluginName == projectPluginName) {
- QObject *projectPluginView = m_viewManager->mainWindow()->pluginView(projectPluginName);
- if (projectPluginView) {
- connect(buttonOpenFolder, SIGNAL(clicked()), projectPluginView, SLOT(openDirectoryOrProject()));
- buttonOpenFolder->show();
- } else {
- buttonOpenFolder->hide();
- }
- }
-}
-
void WelcomeView::onRecentItemsContextMenuRequested(const QPoint &pos)
{
const QModelIndex index = listViewRecentItems->indexAt(pos);
diff --git a/apps/lib/welcomeview/welcomeview.h b/apps/lib/welcomeview/welcomeview.h
index 23a2b0afc2478558569368478e43b27fc96cd3ee..267260b6eae0f5b84d381ec3a95277b3ed7b8f58 100644
--- a/apps/lib/welcomeview/welcomeview.h
+++ b/apps/lib/welcomeview/welcomeview.h
@@ -28,7 +28,6 @@ protected:
bool eventFilter(QObject *watched, QEvent *event) override;
private Q_SLOTS:
- void onPluginViewChanged(const QString &pluginName = QString());
void onRecentItemsContextMenuRequested(const QPoint &pos);
bool shouldClose()
{