wiki:NextFootnote

1. Simple footnote insertion

This plugin adds the next footnote number at at the cursors position and then jumps to the end of the page where the footnote text can be edited.

# Footnotes plugin for WikidPad
# Inserts the next footnote number at the cursors position
# and, at the same time, at the bottom of the current wiki word
#
# Paste this code into a file named footnotes.py
# Save the file in the directory user_extensions in the WikidPad directory
# Create the directory user_extensions if it doesn't exist
#
# License: GNU GPL
# Feel free to improve the features as well as the plugin code

WIKIDPAD_PLUGIN = (("MenuFunctions",1),)

def describeMenuItems(pwiki):

        global nextNumber
        return ((nextFootnote, "Insert footnote\tShift-Alt-F", "Insert next footnote"),)

def nextFootnote(pwiki, evt):

        pwiki.saveAllDocPages()
        editor = pwiki.getActiveEditor()

        content = pwiki.getWikiData().getContent( pwiki.getCurrentWikiWord() )
        content = content.replace('[',' [').replace(']','] ').replace('\\ [','\\[')
        content = content.split()

        numbers = [1]
        for word in content:

                i = len(content)
                if word[0] == '[' and word[-1] == ']' and word[1:-1].isdigit():
                        numbers.append(int(word[1:-1])+1)
                i = i+1

        editor.AddText( '[' + str(max(numbers)) + ']' )
        editor.GotoPos(editor.GetLength())
        editor.AddText( '\n[' + str(max(numbers)) + '] ' )

2. Footnote dialog insertion

This plugin uses a dialog for footnote insertion, which can be useful in long pages if you don't want to jump up and down on a page. It inserts the footnote number at the cursors position and, at the same time, the text at the bottom of the current wiki word. If text is entered, it keeps the cursor at the footnote numbers position. If no text is entered, it inserts the footnote number and then jumps to the end of the page for editing the footnote text.

# Footnotes dialog plugin for WikidPad
#
# Opens a dialog with a text field to add text for the next footnote number.
# It inserts the footnote number at the cursors position
# and the text at the bottom of the current wiki word.
# If text is entered it keeps the cursor at the footnote numbers position.
# If no text is entered it inserts the footnote number and then jumps to the
# end of the page for editing the footnote text.
#
# Paste this code into a file named footnoteDialog.py
# Save the file in the directory user_extensions in the WikidPad directory
# Create the directory user_extensions if it doesn't exist
#
# License: GNU GPL
# Feel free to improve the features as well as the plugin code

import  wx

WIKIDPAD_PLUGIN = (("MenuFunctions",1),)

def describeMenuItems(pwiki):

        global nextNumber
        return ((nextFootnote, "Footnote Dialog\tShift-Alt-D", "Insert footnote"),)

class FootnoteDlg(wx.Dialog):

        def __init__(self, *args, **kwds):

                kwds["style"] = wx.DEFAULT_DIALOG_STYLE
                wx.Dialog.__init__(self, *args, **kwds)

        def FootnoteText(self, number):
                dlg = wx.TextEntryDialog(self,
                'Enter text and press OK to add footnote [%s] at the current position\nand the text at the bottom of the page' %number,
                'Footnote [%s]' %number, '')

                if dlg.ShowModal() == wx.ID_OK:
                        return dlg.GetValue()

                dlg.Destroy()

def nextFootnote(pwiki, evt):

        pwiki.saveAllDocPages()
        editor = pwiki.getActiveEditor()
        curPos = editor.GetCurrentPos()

        content = pwiki.getWikiData().getContent( pwiki.getCurrentWikiWord() )
        content = content.replace('[',' [').replace(']','] ').replace('\\ [','\\[')
        content = content.split()

        numbers = [1]
        for word in content:

                i = len(content)
                if word[0] == '[' and word[-1] == ']' and word[1:-1].isdigit():
                        numbers.append(int(word[1:-1])+1)
                i = i+1

        nextNumber = str(max(numbers))
        text = FootnoteDlg(pwiki).FootnoteText(nextNumber)

        if text is not None and text <> '':

                editor.AddText( '[' + nextNumber + ']' )
                editor.GotoPos(editor.GetLength())
                editor.AddText( '\n[' + nextNumber + '] ' + text )
                editor.GotoPos(curPos + len(nextNumber) + 2 )

        elif text == '':

                editor.AddText( '[' + nextNumber + ']' )
                editor.GotoPos(editor.GetLength())
                editor.AddText( '\n[' + nextNumber + '] ' )

        else:
                return
Last modified 8 years ago Last modified on Feb 6, 2010 9:57:54 AM