root/branches/greitmayr/extensions/referrals.py @ 28

Revision 28, 1.8 kB (checked in by gerhard, 8 years ago)

implemented a new plugin type that adds extension menu items and toolbars.
a simple example plugin was added that creates a list of referers in the current wiki

Line 
1# Example plugin for EditorFunctions type plugins
2# The functionality was originally implemented by endura29 <endura29@gmail.com>
3#
4# The plugin allows to install new menu items and toolbar items and register a
5# a function with each that is called. The function must accept one argument which
6# is the instance of PersonalWikiFrame providing access to the editor and the data store.
7#
8# To register a menu item implement the function describeMenuItem to return a
9# tuple containing the callback function, the item string and an item tooltip.
10#
11# To register a toolbar item implement the function describeToolbarItem to return
12# a tuple containing the callback function, item label, item icon and tooltip.
13#
14# both register functions must accept one argument which is again the
15# PersonalWikiFrame instance
16
17# descriptor for EditorFunctions plugin type
18WIKIDPAD_PLUGIN = (("EditorFunctions",1),)
19
20def describeMenuItem(wiki):
21    return (referrals, "Show Referring Wikis\tctrl-r", "Show Referring Wikis")
22
23def describeToolbarItem(wiki):
24    (index, icon) = wiki.iconLookup["rename"]
25    return (referrals, "Referers", icon, "Show Referring Wikis")
26
27def referrals(wiki):
28    wiki.editor.AddText("\n------------------------\n")
29    parents = wiki.wikiData.getParentRelationships(wiki.currentWikiWord)
30    wiki.editor.AddText("*%s Wikis referring to*   %s\n" % (len(parents), wiki.currentWikiWord))
31    for word in parents:
32        wiki.editor.AddText("%s\n" % word)
33    wiki.editor.AddText("------------------------\n")
34    children = wiki.wikiData.getChildRelationships(wiki.currentWikiWord)
35    wiki.editor.AddText("*%s Wikis referred to by* %s\n" % (len(children), wiki.currentWikiWord))
36    for word in children:
37        wiki.editor.AddText("%s\n" % word)
38    wiki.editor.AddText("------------------------\n")
Note: See TracBrowser for help on using the browser.