Commit 8485730c authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

connect message signals & add test message use

parent 7071a3ac
......@@ -8,6 +8,7 @@
#include "gitcommitdialog.h"
#include "gitstatusmodel.h"
#include "kateproject.h"
#include "kateprojectpluginview.h"
#include "stashdialog.h"
#include <QContextMenuEvent>
......@@ -123,6 +124,13 @@ void GitWidget::initGitExe()
void GitWidget::sendMessage(const QString &message, bool warn)
{
// use generic output view
// FIXME: proper attributes
// if finished => remove the other case below!
QVariantMap genericMessage;
genericMessage.insert(QStringLiteral("plainText"), message);
Q_EMIT m_pluginView->message(genericMessage);
// quickfix crash on startup
if (!m_mainWin->activeView()) {
return;
......
......@@ -114,6 +114,13 @@ Q_SIGNALS:
*/
void configUpdated();
/**
* Signal for outgoing message, the host application will handle them!
* Will be handled in all open main windows.
* @param message outgoing message we send to the host application
*/
void message(const QVariantMap &message);
public Q_SLOTS:
/**
* New document got created, we need to update our connections
......
......@@ -182,6 +182,13 @@ Q_SIGNALS:
*/
void gotoSymbol(const QString &word, int &results);
/**
* Signal for outgoing message, the host application will handle them!
* Will only be handled inside the main windows of this plugin view.
* @param message outgoing message we send to the host application
*/
void message(const QVariantMap &message);
private Q_SLOTS:
/**
* This slot is called whenever the active view changes in our main window.
......
......@@ -610,6 +610,16 @@ private:
*/
KateOutputView *m_outputView = nullptr;
public:
/**
* Accessor for unique output view per main window.
* @return our output view, will always exist!
*/
KateOutputView *outputView()
{
return m_outputView;
}
public:
static void unsetModifiedOnDiscDialogIfIf(KateMwModOnHdDialog *diag)
{
......
......@@ -6,8 +6,25 @@
#include "kateoutputview.h"
#include <QTreeView>
#include <QVBoxLayout>
KateOutputView::KateOutputView(KateMainWindow *mainWindow, QWidget *parent)
: QWidget(parent)
, m_mainWindow(mainWindow)
{
// simple vbox layout with just the tree view ATM
// TODO: e.g. filter and such!
QVBoxLayout *layout = new QVBoxLayout(this);
m_messagesTreeView = new QTreeView(this);
m_messagesTreeView->setModel(&m_messagesModel);
layout->addWidget(m_messagesTreeView);
}
void KateOutputView::slotMessage(const QVariantMap &message)
{
// first dummy implementation: just add message 1:1 as text to output
if (message.contains(QStringLiteral("plainText"))) {
m_messagesModel.appendRow(new QStandardItem(message.value(QStringLiteral("plainText")).toString().trimmed()));
}
}
......@@ -7,9 +7,11 @@
#ifndef __KATE_OUTPUT_VIEW_H__
#define __KATE_OUTPUT_VIEW_H__
#include <QStandardItemModel>
#include <QWidget>
class KateMainWindow;
class QTreeView;
/**
* Widget to output stuff e.g. for plugins.
......@@ -19,14 +21,36 @@ class KateOutputView : public QWidget
Q_OBJECT
public:
/**
* Construct new output, we do that once per main window
* @param mainWindow parent main window
* @param parent parent widget (e.g. the tool view in the main window)
*/
KateOutputView(KateMainWindow *mainWindow, QWidget *parent);
public Q_SLOTS:
/**
* slot for incoming messages
* @param message incoming message we shall handle
*/
void slotMessage(const QVariantMap &message);
private:
/**
* the main window we belong to
* each main window has exactly one KateOutputView
*/
KateMainWindow *const m_mainWindow = nullptr;
/**
* Internal tree view to display the messages we get
*/
QTreeView *m_messagesTreeView = nullptr;
/**
* Our message model, at the moment a standard item model
*/
QStandardItemModel m_messagesModel;
};
#endif
......@@ -11,6 +11,7 @@
#include "kateapp.h"
#include "katedebug.h"
#include "katemainwindow.h"
#include "kateoutputview.h"
#include <KConfig>
#include <KConfigGroup>
......@@ -19,6 +20,7 @@
#include <QFile>
#include <QFileInfo>
#include <QMetaObject>
#include <ktexteditor/sessionconfiginterface.h>
......@@ -221,10 +223,20 @@ void KatePluginManager::enablePluginGUI(KatePluginInfo *item, KateMainWindow *wi
// lookup if there is already a view for it..
QObject *createdView = nullptr;
if (!win->pluginViews().contains(item->plugin)) {
// ensure messaging is connected, if available, for the complete plugin
if (item->plugin->metaObject()->indexOfSignal("message(QVariantMap)") != -1) {
connect(item->plugin, SIGNAL(message(const QVariantMap &)), win->outputView(), SLOT(slotMessage(const QVariantMap &)), Qt::UniqueConnection);
}
// create the view + try to correctly load shortcuts, if it's a GUI Client
createdView = item->plugin->createView(win->wrapper());
if (createdView) {
win->pluginViews().insert(item->plugin, createdView);
// ensure messaging is connected, if available, for view, too!
if (createdView->metaObject()->indexOfSignal("message(QVariantMap)") != -1) {
connect(createdView, SIGNAL(message(const QVariantMap &)), win->outputView(), SLOT(slotMessage(const QVariantMap &)), Qt::UniqueConnection);
}
}
}
......
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