[rkward/work/kateintegration] rkward/windows: Some small rewrites, and start fixing up plugin UI.
Thomas Friedrichsmeier
null at kde.org
Sat Jan 11 13:07:55 GMT 2020
Git commit 2e688b91f2fe4adb333803c5fbdf949c591ae45f by Thomas Friedrichsmeier.
Committed on 11/01/2020 at 13:07.
Pushed by tfry into branch 'work/kateintegration'.
Some small rewrites, and start fixing up plugin UI.
M +48 -17 rkward/windows/katepluginintegration.cpp
M +10 -3 rkward/windows/katepluginintegration.h
M +3 -2 rkward/windows/rkmdiwindow.cpp
M +2 -1 rkward/windows/rkmdiwindow.h
M +8 -1 rkward/windows/rktoolwindowbar.cpp
M +2 -1 rkward/windows/rktoolwindowbar.h
https://commits.kde.org/rkward/2e688b91f2fe4adb333803c5fbdf949c591ae45f
diff --git a/rkward/windows/katepluginintegration.cpp b/rkward/windows/katepluginintegration.cpp
index f475696a..be7dd1a8 100644
--- a/rkward/windows/katepluginintegration.cpp
+++ b/rkward/windows/katepluginintegration.cpp
@@ -83,6 +83,13 @@ KTextEditor::View *KatePluginIntegrationApp::dummyView() {
return dummy_view;
}
+QString KatePluginIntegrationApp::idForPlugin(const KTextEditor::Plugin *plugin) const {
+ for (auto it = known_plugins.constBegin(); it != known_plugins.constEnd(); ++it) {
+ if (it.value().plugin == plugin) return it.key();
+ }
+ return QString();
+}
+
QString KatePluginIntegrationApp::idForPlugin(const KPluginMetaData &plugin) const {
return QFileInfo(plugin.fileName()).baseName();
}
@@ -266,12 +273,13 @@ KatePluginIntegrationWindow::KatePluginIntegrationWindow (KatePluginIntegrationA
main = new KTextEditor::MainWindow(this);
// While this one may be accessed from plugins via KTextEditor::Editor::instance()->application()
app = parent;
+ active_plugin = 0;
}
class KatePluginToolWindow : public RKMDIWindow {
Q_OBJECT
public:
- KatePluginToolWindow(QWidget *parent, RKMDIWindow::Type type) : RKMDIWindow(parent, type, true) {
+ KatePluginToolWindow(QWidget *parent) : RKMDIWindow(parent, RKMDIWindow::KatePluginWindow, true) {
RK_TRACE (APP);
QVBoxLayout *layout = new QVBoxLayout(this);
@@ -296,15 +304,17 @@ public:
}
};
-QWidget * KatePluginIntegrationWindow::createToolView (KTextEditor::Plugin *plugin, const QString &identifier, KTextEditor::MainWindow::ToolViewPosition pos, const QIcon &icon, const QString &text) {
+QWidget* KatePluginIntegrationWindow::createToolView (KTextEditor::Plugin *plugin, const QString &identifier, KTextEditor::MainWindow::ToolViewPosition pos, const QIcon &icon, const QString &text) {
RK_TRACE (APP);
+ RK_DEBUG(APP, DL_DEBUG, "createToolView for %p, %s, position %d, %s", plugin, qPrintable(identifier), pos, qPrintable(text));
// TODO: Set proper RKMDIWindow:type
- KatePluginToolWindow *window = new KatePluginToolWindow(RKWorkplace::mainWorkplace()->view(), RKMDIWindow::ConsoleWindow);
+ KatePluginToolWindow *window = new KatePluginToolWindow(RKWorkplace::mainWorkplace()->view());
window->setCaption(text);
window->setWindowIcon(icon);
RKWorkplace::mainWorkplace()->placeInToolWindowBar(window, pos);
- created_tool_views.append(window->getPart());
+ RKToolWindowList::registerToolWindow(window, identifier, (RKToolWindowList::Placement) pos, 0);
+ plugin_resources[plugin].windows.append(window);
return window;
}
@@ -389,7 +399,7 @@ KTextEditor::View *KatePluginIntegrationWindow::openUrl(const QUrl &url, const Q
QObject *KatePluginIntegrationWindow::pluginView(const QString &name) {
RK_TRACE (APP);
- return plugin_views.value(app->plugin(name));
+ return plugin_resources.value(app->plugin(name)).view;
}
bool KatePluginIntegrationWindow::closeSplitView(KTextEditor::View* view) {
@@ -451,6 +461,17 @@ bool KatePluginIntegrationWindow::viewsInSameSplitView(KTextEditor::View* view1,
return false;
}
+void fixupPluginUI(const QString &id, int num_of_client, KXMLGUIClient* client, RKMDIWindow* window) {
+ RK_TRACE (APP);
+
+ if (num_of_client == 0) {
+ if (id == QStringLiteral("katesearchplugin")) {
+ window->setCaption("Search in Scripts");
+ // TODO
+ }
+ }
+}
+
QObject* KatePluginIntegrationWindow::createPluginView(KTextEditor::Plugin* plugin) {
RK_TRACE (APP);
@@ -458,27 +479,37 @@ QObject* KatePluginIntegrationWindow::createPluginView(KTextEditor::Plugin* plug
// our MDI windows are enabled / disabled on activation. To hack around this, the catch the added clients,
// and put them, where they belong.
connect(factory(), &KXMLGUIFactory::clientAdded, this, &KatePluginIntegrationWindow::catchXMLGUIClientsHack);
- QObject *view = plugin->createView(main);
+ active_plugin = plugin;
+ PluginResources& resources = plugin_resources.insert(plugin, PluginResources()).value();
+ resources.view = plugin->createView(main);
+ active_plugin = 0;
disconnect(factory(), &KXMLGUIFactory::clientAdded, this, &KatePluginIntegrationWindow::catchXMLGUIClientsHack);
KXMLGUIClient* hacked_parent = this;
- for (int i = 0; i < caught_clients.size(); ++i) {
- if (i < created_tool_views.size()) {
- hacked_parent = created_tool_views[i];
+ QString id = app->idForPlugin(plugin);
+ for (int i = 0; i < resources.clients.size(); ++i) {
+ KXMLGUIClient* client = resources.clients[i];
+ RKMDIWindow* window = resources.windows.value(i);
+ if (window) {
+ hacked_parent = window->getPart();;
}
- factory()->removeClient(caught_clients[i]);
- hacked_parent->insertChildClient(caught_clients[i]);
+ factory()->removeClient(client);
+ fixupPluginUI(id, i, client, window);
+ hacked_parent->insertChildClient(client);
}
- caught_clients.clear();
- created_tool_views.clear();
+ // TODO: If child clients were added to the window, itself, we need to tell the main window to rebuild.
- plugin_views.insert(plugin, view);
- connect(plugin, &QObject::destroyed, [&]() { plugin_views.remove(plugin); });
- return view;
+ connect(plugin, &QObject::destroyed, [&]() { plugin_resources.remove(plugin); });
+ return resources.view;
}
void KatePluginIntegrationWindow::catchXMLGUIClientsHack(KXMLGUIClient* client) {
RK_TRACE (APP);
- caught_clients.append(client);
+ if (active_plugin) {
+ RK_ASSERT(plugin_resources.contains(active_plugin));
+ plugin_resources[active_plugin].clients.append(client);
+ } else {
+ RK_DEBUG(APP, DL_DEBUG, "XML client created by unknown kate plugin");
+ }
}
// TODO: Don't forget to make sure to emit all the signals!
diff --git a/rkward/windows/katepluginintegration.h b/rkward/windows/katepluginintegration.h
index e2e6ba8e..b366a925 100644
--- a/rkward/windows/katepluginintegration.h
+++ b/rkward/windows/katepluginintegration.h
@@ -26,6 +26,7 @@
#include <QMap>
class KatePluginIntegrationWindow;
+class RKMDIWindow;
/** This class provides implementations for the KTextEditor::Application interface.
* Note that there is a separate interface KatePluginIntegrationWindow / KTextEditor::MainWindow that serves
@@ -64,6 +65,7 @@ private:
KTextEditor::Plugin *plugin;
};
QMap<QString, PluginInfo> known_plugins;
+ QString idForPlugin(const KTextEditor::Plugin *plugin) const;
QString idForPlugin(const KPluginMetaData &plugin) const;
};
@@ -101,14 +103,19 @@ private:
friend class KatePluginIntegrationApp;
KTextEditor::MainWindow *main;
QObject* createPluginView(KTextEditor::Plugin* plugin);
- QHash<KTextEditor::Plugin*, QObject*> plugin_views;
+ struct PluginResources {
+ PluginResources() : view(0) {};
+ QObject *view;
+ QList<KXMLGUIClient*> clients;
+ QList<RKMDIWindow*> windows;
+ };
+ QHash<KTextEditor::Plugin*, PluginResources> plugin_resources;
KatePluginIntegrationApp *app;
private slots:
void catchXMLGUIClientsHack(KXMLGUIClient* client);
private:
- QList<KXMLGUIClient*> caught_clients;
- QList<KXMLGUIClient*> created_tool_views;
+ KTextEditor::Plugin* active_plugin;
};
#endif
diff --git a/rkward/windows/rkmdiwindow.cpp b/rkward/windows/rkmdiwindow.cpp
index 9a3803ae..e777e5f6 100644
--- a/rkward/windows/rkmdiwindow.cpp
+++ b/rkward/windows/rkmdiwindow.cpp
@@ -2,7 +2,7 @@
rkmdiwindow - description
-------------------
begin : Tue Sep 26 2006
- copyright : (C) 2006 - 2017 by Thomas Friedrichsmeier
+ copyright : (C) 2006 - 2020 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -73,7 +73,7 @@ RKMDIWindow::RKMDIWindow (QWidget *parent, int type, bool tool_window, const cha
status_popup = 0;
status_popup_container = 0;
- setWindowIcon (RKStandardIcons::iconForWindow (this));
+ if (!(type & KatePluginWindow)) setWindowIcon (RKStandardIcons::iconForWindow (this));
}
RKMDIWindow::~RKMDIWindow () {
@@ -109,6 +109,7 @@ void RKMDIWindow::setCaption (const QString &caption) {
RK_TRACE (APP);
QWidget::setWindowTitle (caption);
emit (captionChanged (this));
+ if (tool_window_bar) tool_window_bar->captionChanged(this);
}
bool RKMDIWindow::isActive () {
diff --git a/rkward/windows/rkmdiwindow.h b/rkward/windows/rkmdiwindow.h
index d5632a43..051472e1 100644
--- a/rkward/windows/rkmdiwindow.h
+++ b/rkward/windows/rkmdiwindow.h
@@ -2,7 +2,7 @@
rkmdiwindow - description
-------------------
begin : Tue Sep 26 2006
- copyright : (C) 2006 - 2017 by Thomas Friedrichsmeier
+ copyright : (C) 2006 - 2020 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -59,6 +59,7 @@ public:
DebugConsoleWindow=1 << 16,
CallstackViewerWindow=1 << 17,
DebugMessageWindow=1 << 18,
+ KatePluginWindow=1 << 19,
DocumentWindow=1 << 29,
ToolWindow=1 << 30,
diff --git a/rkward/windows/rktoolwindowbar.cpp b/rkward/windows/rktoolwindowbar.cpp
index 03c405e3..11e67d13 100644
--- a/rkward/windows/rktoolwindowbar.cpp
+++ b/rkward/windows/rktoolwindowbar.cpp
@@ -2,7 +2,7 @@
rktoolwindowbar - description
-------------------
begin : Fri Oct 12 2007
- copyright : (C) 2007-2019 by Thomas Friedrichsmeier
+ copyright : (C) 2007-2020 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -52,6 +52,13 @@ RKToolWindowBar::~RKToolWindowBar () {
RK_TRACE (APP);
}
+void RKToolWindowBar::captionChanged (RKMDIWindow* window) {
+ RK_TRACE (APP);
+
+ int id = widget_to_id.value (window);
+ tab (id)->setText (window->shortCaption ());
+}
+
void RKToolWindowBar::restoreSize (const KConfigGroup &cg) {
RK_TRACE (APP);
diff --git a/rkward/windows/rktoolwindowbar.h b/rkward/windows/rktoolwindowbar.h
index c10e3052..5c0b8c2b 100644
--- a/rkward/windows/rktoolwindowbar.h
+++ b/rkward/windows/rktoolwindowbar.h
@@ -2,7 +2,7 @@
rktoolwindowbar - description
-------------------
begin : Fri Oct 12 2007
- copyright : (C) 2007, 2011 by Thomas Friedrichsmeier
+ copyright : (C) 2007-2020 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -50,6 +50,7 @@ public:
void restoreSize (const KConfigGroup &cg);
void saveSize (KConfigGroup &cg) const;
+ void captionChanged(RKMDIWindow* window);
private slots:
void tabClicked (int id);
void changeAttachment ();
More information about the rkward-tracker
mailing list