Development/Tutorials/Kross/Script-Actions

Contents

Introduction

This tutorial uses the script plugin technique explained in The Module Plugins and explains how to code your application in order to easily add new script actions into menus. Two typical scenarios are:

- scripts shipped by default by the application developer
- custom scripts added by the user

The effect of such description will be the creation of a new menu item called "Dummy Script" in the "Tools" menu. The action associated to the new menu item will execute the script defined in the "file" path.

Placing text and comment attributes on the same line with tag name is important for extractattr script that extracts strings for i18n.

Kross::ScriptingPlugin have two additional slots that can be useful for applications to use:

/** * This slot will open/create a scriptactions.rc file at $KDEHOME/share/apps/application/scripts/ * which will override other kross rc files. This allows a user to extend existing menus with new actions. */virtualvoidslotEditScriptActions();/** * Deletes the user rc file, which has the effect of falling back to the default script actions (if any). */virtualvoidslotResetScriptActions();

The KPart plugin rc file

Suggestion on how to use the edit and reset script actions (respective slots provided by Kross::ScriptingPlugin class):