Commit cb907fb8 authored by Christoph Cullmann's avatar Christoph Cullmann

implement more plugin interfaces to allow plugin to get signals when other...

implement more plugin interfaces to allow plugin to get signals when other plugin views got created/deleted
this will allow plugin to talk to each other more easily ;)
first test will be projectplugin => searchplugin, to allow searches in current active project ;)
parent b11cc072
......@@ -204,7 +204,7 @@ KateMainWindow::KateMainWindow (KConfig *sconfig, const QString &sgroup)
connect(this,SIGNAL(sigShowPluginConfigPage(Kate::PluginConfigPageInterface *,uint)),this,SLOT(showPluginConfigPage(Kate::PluginConfigPageInterface *,uint)));
}
KateMainWindow::~KateMainWindow()
......@@ -341,7 +341,7 @@ void KateMainWindow::setupActions()
connect(m_viewManager, SIGNAL(viewChanged()), this, SLOT(slotUpdateOpenWith()));
connect(m_viewManager, SIGNAL(viewChanged()), this, SLOT(slotUpdateBottomViewBar()));
connect(m_viewManager, SIGNAL(viewChanged()), this, SLOT(slotUpdateTopViewBar()));
slotWindowActivated ();
// session actions
......@@ -575,7 +575,7 @@ void KateMainWindow::dropEvent( QDropEvent *event )
void KateMainWindow::slotDropEvent( QDropEvent * event )
{
if (event->mimeData() == 0) return;
//
// are we dropping files?
//
......@@ -606,7 +606,7 @@ void KateMainWindow::slotDropEvent( QDropEvent * event )
m_viewManager->openUrl (*i);
}
}
}
}
//
// or are we dropping text?
//
......@@ -887,7 +887,7 @@ void KateMainWindow::saveGlobalProperties( KConfig* sessionConfig )
// save plugin config !!
KateApp::self()->pluginManager()->writeConfig (sessionConfig);
}
void KateMainWindow::saveWindowConfig(const KConfigGroup &_config)
......@@ -954,7 +954,7 @@ void KateMainWindow::queueModifiedOnDisc(KTextEditor::Document *doc)
s_modOnHdDialog= new KateMwModOnHdDialog( list, this );
m_modignore = true;
KWindowSystem::setOnAllDesktops( s_modOnHdDialog->winId(), true);
bool res = s_modOnHdDialog->exec();
s_modOnHdDialog->exec();
delete s_modOnHdDialog; // s_modOnHdDialog is set to 0 in destructor of KateMwModOnHdDialog (jowenn!!!)
m_modignore = false;
} else {
......@@ -971,4 +971,13 @@ bool KateMainWindow::event( QEvent *e )
return KateMDI::MainWindow::event(e);
}
Kate::PluginView *KateMainWindow::pluginView (const QString &name)
{
Kate::Plugin *plugin = KateApp::self()->pluginManager()->plugin (name);
if (!plugin)
return 0;
return m_pluginViews.value (plugin);
}
// kate: space-indent on; indent-width 2; replace-tabs on;
......@@ -110,9 +110,15 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa
{
return m_dbusObjectPath;
}
/**
* various methodes to get some little info out of this
* get a plugin view with identifier \p name.
* \param name the plugin's name
* \return pointer to the plugin view if a plugin with \p name is loaded and has a view for this mainwindow,
* otherwise null
*/
Kate::PluginView *pluginView (const QString &name);
public:
/** Returns the URL of the current document.
* anders: I add this for use from the file selector. */
......@@ -247,7 +253,7 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa
private Q_SLOTS:
void slotUpdateBottomViewBar();
void slotUpdateTopViewBar();
private Q_SLOTS:
void slotDocumentCloseAll();
void slotDocumentCloseOther();
......@@ -308,7 +314,7 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa
static KateMwModOnHdDialog *s_modOnHdDialog;
public Q_SLOTS:
void showPluginConfigPage(Kate::PluginConfigPageInterface *configpageinterface,uint id);
void showPluginConfigPage(Kate::PluginConfigPageInterface *configpageinterface,uint id);
protected:
virtual bool event( QEvent *e );
......
......@@ -73,20 +73,20 @@ void KatePluginManager::setupPluginList ()
info.alwaysLoad=info.service->property("X-Kate-LoadAlways").toBool();
info.load = false;
info.plugin = 0L;
if (info.alwaysLoad)
alwaysLoad.push_back (info);
else
others.push_back (info);
}
}
/**
* prefer always load plugins in handling
*/
m_pluginList = alwaysLoad;
m_pluginList << others;
/**
* construct fast lookup map
*/
......@@ -110,14 +110,14 @@ void KatePluginManager::loadConfig (KConfig* config)
for (int i = 0; i < m_pluginList.size(); ++i)
m_pluginList[i].load = cg.readEntry (m_pluginList[i].service->library(), false);
}
/**
* some plugins should be always loaded, like the holy filetree
*/
for (int i = 0; i < m_pluginList.size(); ++i)
if (m_pluginList[i].service->property("X-Kate-LoadAlways").toBool())
m_pluginList[i].load = true;
m_pluginList[i].load = true;
for (KatePluginList::iterator it = m_pluginList.begin();it != m_pluginList.end(); ++it)
{
if (it->load)
......@@ -199,11 +199,12 @@ void KatePluginManager::enablePluginGUI (KatePluginInfo *item, KateMainWindow *w
return;
// lookup if there is already a view for it..
Kate::PluginView *createdView = 0;
if (!win->pluginViews().contains(item->plugin))
{
// create the view + try to correctly load shortcuts, if it's a GUI Client
Kate::PluginView *view = item->plugin->createView(win->mainWindow());
win->pluginViews().insert (item->plugin, view);
createdView = item->plugin->createView(win->mainWindow());
win->pluginViews().insert (item->plugin, createdView);
}
// load session config if needed
......@@ -212,6 +213,9 @@ void KatePluginManager::enablePluginGUI (KatePluginInfo *item, KateMainWindow *w
int winID = KateApp::self()->mainWindowID(win);
win->pluginViews().value(item->plugin)->readSessionConfig(config, QString("Plugin:%1:MainWindow:%2").arg(item->saveName()).arg(winID));
}
if (createdView)
emit win->mainWindow()->pluginViewCreated (item->service->library(), createdView);
}
void KatePluginManager::enablePluginGUI (KatePluginInfo *item)
......@@ -236,8 +240,10 @@ void KatePluginManager::disablePluginGUI (KatePluginInfo *item, KateMainWindow *
return;
// really delete the view of this plugin
delete win->pluginViews().value(item->plugin);
Kate::PluginView *deletedView = win->pluginViews().value(item->plugin);
delete deletedView;
win->pluginViews().remove (item->plugin);
emit win->mainWindow()->pluginViewDeleted (item->service->library(), deletedView);
}
void KatePluginManager::disablePluginGUI (KatePluginInfo *item)
......@@ -258,7 +264,7 @@ Kate::Plugin *KatePluginManager::plugin (const QString &name)
*/
if (!m_name2Plugin.contains(name))
return 0;
/**
* real plugin instance, if any ;)
*/
......@@ -277,14 +283,14 @@ class Kate::Plugin *KatePluginManager::loadPlugin (const QString &name, bool per
*/
if (!m_name2Plugin.contains(name))
return 0;
/**
* load, bail out on error
*/
loadPlugin (m_name2Plugin.value(name));
if (!m_name2Plugin.value(name)->plugin)
return 0;
/**
* perhaps patch not load again back to "ok, load it once again on next loadConfig"
*/
......@@ -299,12 +305,12 @@ void KatePluginManager::unloadPlugin (const QString &name, bool permanent)
*/
if (!m_name2Plugin.contains(name))
return;
/**
* unload
*/
unloadPlugin (m_name2Plugin.value(name));
/**
* perhaps patch load again back to "ok, load it once again on next loadConfig"
*/
......
/* This file is part of the KDE project
Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
......@@ -95,7 +95,7 @@ namespace Kate
return d->win->createToolView (plugin,identifier, (KMultiTabBar::KMultiTabBarPosition)pos, icon, text);
}
bool MainWindow::moveToolView (QWidget *widget, MainWindow::Position pos)
{
if (!widget || !qobject_cast<KateMDI::ToolView*>(widget))
......@@ -125,6 +125,11 @@ namespace Kate
d->win->showPluginConfigPage(configpageinterface,id);
}
PluginView *MainWindow::pluginView (const QString &name)
{
return d->win->pluginView (name);
}
}
// kate: space-indent on; indent-width 2; replace-tabs on;
......
......@@ -37,9 +37,10 @@ namespace KTextEditor
namespace Kate
{
class PluginConfigPageInterface;
class Plugin;
class PluginView;
/**
* \brief Interface to a mainwindow.
*
......@@ -145,7 +146,7 @@ namespace Kate
#undef signals
#define signals public
#endif
Q_SIGNALS:
signals:
#ifndef Q_MOC_RUN
#undef signals
#define signals protected
......@@ -168,6 +169,25 @@ namespace Kate
*/
void unhandledShortcutOverride (QEvent *e);
/**
* This signal is emitted when a Plugin::View is created for this main window.
*
* @param name name of plugin
* @param pluginView the new plugin view
*/
void pluginViewCreated (const QString &name, Kate::PluginView *pluginView);
/**
* This signal is emitted when the Plugin::View got deleted.
*
* @param name name of plugin
* @param pluginView the deleted plugin view
*
* Warning !!! DO NOT ACCESS THE DATA REFERENCED BY THE POINTER, IT IS ALREADY INVALID
* Use the pointer only to remove mappings in hash or maps
*/
void pluginViewDeleted (const QString &name, Kate::PluginView *pluginView);
/*
* ToolView stuff, here all stuff belong which allows to
* add/remove and manipulate the toolview of this main windows
......@@ -212,7 +232,6 @@ namespace Kate
*/
QWidget *createToolView (Kate::Plugin* plugin, const QString &identifier, MainWindow::Position pos, const QPixmap &icon, const QString &text);
/**
* Move the toolview \p widget to position \p pos.
* \param widget the toolview to move, where the widget was constructed
......@@ -239,7 +258,6 @@ namespace Kate
*/
bool hideToolView (QWidget *widget);
/**
* This function is used by a plugin to open the kate configuration dialog
* at one of its own config pages.
......@@ -247,11 +265,18 @@ namespace Kate
* \param id the positional id of the page within the configuration
*/
void showPluginConfigPage(Kate::PluginConfigPageInterface *configpageinterface,uint id);
/**
* Get a plugin view with identifier \p name.
* \param name the plugin's name
* \return pointer to the plugin view if a plugin with \p name is loaded and has a view for this mainwindow,
* otherwise NULL
*/
PluginView *pluginView (const QString &name);
private:
class PrivateMainWindow *d;
};
}
#endif
......
......@@ -93,12 +93,11 @@ bool KateProject::reload ()
*/
m_name = globalGroup["name"].toString();
qDebug ("name %s", qPrintable(m_name));
/**
* now, clear model once and load other stuff that is possible in all groups
*/
m_model->clear ();
m_files.clear ();
loadGroup (m_model->invisibleRootItem(), globalGroup);
/**
......@@ -252,6 +251,11 @@ void KateProject::loadDirectory (QStandardItem *parent, const QVariantMap &direc
*/
files.sort ();
/**
* append to FULL files list
*/
m_files += files;
/**
* construct paths first in tree and items in a map
*/
......
......@@ -37,12 +37,12 @@ class KateProject : public QObject
* construct empty project
*/
KateProject ();
/**
* deconstruct project
*/
~KateProject ();
/**
* Load a project.
* Only works once, afterwards use reload().
......@@ -50,14 +50,14 @@ class KateProject : public QObject
* @return success
*/
bool load (const QString &fileName);
/**
* Try to reload a project.
* If the reload fails, e.g. because the file is not readable or corrupt, nothing will happen!
* @return success
*/
bool reload ();
/**
* Accessor to file name.
* @return file name
......@@ -66,7 +66,7 @@ class KateProject : public QObject
{
return m_fileName;
}
/**
* Accessor to project name.
* @return project name
......@@ -75,7 +75,7 @@ class KateProject : public QObject
{
return m_name;
}
/**
* Accessor for the model.
* @return model of this project
......@@ -84,7 +84,15 @@ class KateProject : public QObject
{
return m_model;
}
/**
* Flat list of all files in the project
*/
QStringList files ()
{
return m_files;
}
private:
/**
* Load one group inside the project tree.
......@@ -93,29 +101,34 @@ class KateProject : public QObject
* @param group variant map for this group
*/
void loadGroup (QStandardItem *parent, const QVariantMap &group);
/**
* Load one directory entry in the current parent item.
* @param parent parent standard item in the model
* @param directory directory specification to load
*/
void loadDirectory (QStandardItem *parent, const QVariantMap &directory);
private:
/**
* project file name
*/
QString m_fileName;
/**
* project name
*/
QString m_name;
/**
* standard item model with content of this project
*/
QStandardItemModel *m_model;
/**
* all project files
*/
QStringList m_files;
};
#endif
......
......@@ -52,12 +52,12 @@ KateProjectPluginView::KateProjectPluginView( KateProjectPlugin *plugin, Kate::M
* create toolview
*/
m_toolView = mainWindow()->createToolView ("kateproject", Kate::MainWindow::Left, SmallIcon("project-open"), i18n("Projects"));
/**
* populate the toolview
*/
m_toolBox = new QToolBox (m_toolView);
/**
* connect to important signals, e.g. for auto project view creation
*/
......@@ -70,7 +70,7 @@ KateProjectPluginView::~KateProjectPluginView()
* cu toolview
*/
delete m_toolView;
/**
* cu gui client
*/
......@@ -83,23 +83,23 @@ KateProjectView *KateProjectPluginView::viewForProject (KateProject *project)
* needs valid project
*/
Q_ASSERT (project);
/**
* existing view?
*/
if (m_project2View.contains (project))
return m_project2View.value (project);
/**
* create new view
*/
KateProjectView *view = new KateProjectView (this, project);
/**
* attach to toolbox
*/
m_toolBox->addItem (view, project->name());
/**
* remember and return it
*/
......@@ -125,5 +125,23 @@ void KateProjectPluginView::writeSessionConfig( KConfigBase* config, const QStri
Q_UNUSED( groupPrefix );
}
QString KateProjectPluginView::currentProjectFileName ()
{
QWidget *active = m_toolBox->currentWidget ();
if (!active)
return QString ();
return static_cast<KateProjectView *> (active)->project()->fileName ();
}
QStringList KateProjectPluginView::currentProjectFiles ()
{
QWidget *active = m_toolBox->currentWidget ();
if (!active)
return QStringList ();
return static_cast<KateProjectView *> (active)->project()->files ();
}
// kate: space-indent on; indent-width 2; replace-tabs on;
......@@ -31,13 +31,28 @@ class KateProjectPluginView : public Kate::PluginView, public Kate::XMLGUIClient
{
Q_OBJECT
Q_PROPERTY(QString currentProjectFileName READ currentProjectFileName)
Q_PROPERTY(QStringList currentProjectFiles READ currentProjectFiles)
public:
KateProjectPluginView( KateProjectPlugin *plugin, Kate::MainWindow *mainWindow );
~KateProjectPluginView();
virtual void readSessionConfig( KConfigBase* config, const QString& groupPrefix );
virtual void writeSessionConfig( KConfigBase* config, const QString& groupPrefix );
/**
* which project file is currently active?
* @return empty string if none, else project file name
*/
QString currentProjectFileName ();
/**
* files for the current active project?
* @return empty list if none, else project files as stringlist
*/
QStringList currentProjectFiles ();
public slots:
/**
* Create view for given project.
......@@ -46,23 +61,23 @@ class KateProjectPluginView : public Kate::PluginView, public Kate::XMLGUIClient
* @return view
*/
KateProjectView *viewForProject (KateProject *project);
private:
/**
* our plugin
*/
KateProjectPlugin *m_plugin;
/**
* our projects toolview
*/
QWidget *m_toolView;
/**
* the toolbox for the projects
*/
QToolBox *m_toolBox;
/**
* project => view
*/
......
......@@ -42,25 +42,34 @@ class KateProjectView : public QTreeView
* @param project project this view is for
*/
KateProjectView (KateProjectPluginView *pluginView, KateProject *project);
/**
* deconstruct project
*/
~KateProjectView ();
/**
* our project.
* @return project
*/
KateProject *project () const
{
return m_project;
}
private Q_SLOTS:
/**
* item got activated, do stuff, like open document
* @param index model index of activated item
*/
void slotActivated (const QModelIndex &index);
private:
/**
* our plugin view
*/
KateProjectPluginView *m_pluginView;
/**
* our project
*/
......
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