Kross

scriptingplugin.h
1 /* This file is part of the KDE project
2  Copyright (C) 2008 Paulo Moura Guedes <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KROSS_PLUGIN_H
21 #define KROSS_PLUGIN_H
22 
23 #include <kparts/plugin.h>
24 
25 #include <kross/ui/krossui_export.h>
26 #include <kross/core/childreninterface.h>
27 
28 namespace Kross
29 {
30 class ActionCollection;
31 }
32 
33 class QWidget;
34 
35 namespace Kross
36 {
37 
38 /**
39  * The ScriptingPlugin class loads additional actions stored in rc files with the
40  * KrossScripting format:
41  *
42  * \code
43  * <KrossScripting>
44  * <collection name="file" text="File">
45  * <script name="dummy_script" text="Dummy Script" comment="Dummy Script example"
46  * file="dummy_script.py" interpreter="python" />
47  * </collection>
48  * </KrossScripting>
49  * \endcode
50  *
51  * The 'name' attribute in collection element will be used to match the menu object name.
52  * If no menu already exists with this name, a new one is created. In this example, the user will
53  * see a menu item with the text "Dummy Script" in "File" menu, which will execute the dummy_script.py script.
54  *
55  * By default it tries to find kross rc files in %APPDATA%/scripts directory.
56  * Clients of this class can use slotEditScriptActions() as a way to override and/or extend the
57  * default script actions (if they exist at all).
58  *
59  * You may create multiple instances of ScriptingPlugin by using alternative c'tor.
60  */
61 class KROSSUI_EXPORT ScriptingPlugin : public KParts::Plugin
62 {
63  Q_OBJECT
64 public:
65 
66  /**
67  * Constructor.
68  *
69  * \param parent The parent QObject this QObject is child of.
70  */
71  explicit ScriptingPlugin(QObject *parent = nullptr);
72 
73  /**
74  * Allows having actions defined in a custom location, eg for project-specific actions
75  *
76  * \param userActionsFile scripts.rc filepath -- file may be modified by user
77  * \param referenceActionsDir dir -- %APPDATA%/scripts/%referenceActionsDir% contains standard actions for this plugin instance; has a lower priority than \a userActionsFile.
78  */
79  ScriptingPlugin(const QString &collectionName, const QString &userActionsFile, const QString &referenceActionsDir = QString(), QObject *parent = nullptr);
80 
81  /**
82  * Destructor.
83  */
84  ~ScriptingPlugin() override;
85 
86  /**
87  * Re-implement in order to load additional kross scripting rc files.
88  */
89  void setDOMDocument(const QDomDocument &document, bool merge = false) override;
90 
91  /**
92  * Add a QObject to the list of children. The object will be published to the scripting code.
93  * \param object The QObject instance that should be added to the list of children.
94  * \param name The name the QObject should be known under. If not defined, the
95  * QObject's objectName is used.
96  */
97  void addObject(QObject *object, const QString &name/* = QString()*/, ChildrenInterface::Options options/* = ChildrenInterface::NoOption*/);
98 
99  ///\deprecated use another addObject overload
100  void addObject(QObject *object, const QString &name = QString()); //BIC
101 
102 protected Q_SLOTS:
103 
104  /**
105  * This slot will open/create a scriptactions.rc file in XDG_DATA_HOME/application/scripts/
106  * which will override other kross rc files. This allows a user to extend existing menus with new actions.
107  */
108  virtual void slotEditScriptActions();
109 
110  /**
111  * Deletes the user rc file, which has the effect of falling back to the default script actions (if any).
112  */
113  virtual void slotResetScriptActions();
114 
115 private:
116  QDomDocument buildDomDocument(const QDomDocument &document);
117  void buildDomDocument(QDomDocument &document, Kross::ActionCollection *collection);
118  void save();
119 
120 private:
121  class ScriptingPluginPrivate;
122  ScriptingPluginPrivate *const d;
123 };
124 
125 }
126 
127 #endif
The ScriptingPlugin class loads additional actions stored in rc files with the KrossScripting format:
The ActionCollection class manages collections of Action instances.
Options
Additional options that could be defined for a QObject instance.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 10 2023 04:00:45 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.