forked from butscher/WikidPad
-
Notifications
You must be signed in to change notification settings - Fork 0
InsertNewLink
Christian Ziemski edited this page Mar 7, 2016
·
4 revisions
This plugin inserts a link to a non-existing page at the text cursor's current position. This is useful when you need to create a new cross-linked page but haven't figured out the name of it. It's based on, and works in conjunction with, the autoNew extension.
The plugin has been tested and verified for wikidPad versions:
- 1.9rc04
- 2.0beta03-beta04
import re
# InsertNewLink.py, plugin for wikidPad.
# Published under the same license as wikidPad (GPL 2.1 or later):
# http://www.gnu.org/copyleft/gpl.html
# Feel free to improve the plugin.
# This plugin is based on the extension "autoNew.py".
# It inserts a link to a new non-existing page at the text cursor's current position.
# The link has the format of "New+next number"
# "auotNew.py" and this plugin can be used in conjunction with each other.
# Add the plugin InsertNewLink.py to the directory user_extensions in wikidPad directory.
# Select it from the Plugins menu or press Ctrl-Shift-I to create a new link.
# Set your wikidPad version here as '1.9' or '2.0'.
wpversion = 'your wikidPad version'
WIKIDPAD_PLUGIN = (("MenuFunctions",1),)
def describeMenuItems(wiki):
kb = wiki.getKeyBindings()
return ((newLink, _(u"Insert new link") + u"\tShift-Ctrl-I" +
kb.Plugin_new_link, _(u"Insert new link")),)
_testRE = re.compile(ur"^New[0-9]{6}$")
def newLink(wiki, evt):
wiki.saveAllDocPages()
if wpversion < '2.0':
candidates = wiki.getWikiData().getWikiWordsStartingWith(u"New",
includeAliases=True)
else:
candidates = wiki.getWikiData().getWikiLinksStartingWith(u"New",
includeAliases=True)
candidates = filter(lambda w: _testRE.match(w), candidates)
numbers = map(lambda w: int(w[3:]), candidates)
if len(numbers) == 0:
nextNumber = 1
else:
nextNumber = max(numbers) + 1
editor = wiki.getActiveEditor()
editor.AddText("[" + u"New%06i" % nextNumber + "]")
Source: http://trac.wikidpad2.webfactional.com/wiki/InsertNewLink