"""
Title_Case.py - A Jython macro for jEdit that changes the
case of selected text, or the entire buffer if no text
is selected to "Title Case". For example, "one day" would
become "One Day".

Copyright 2003 (C) Ollie Rutherfurd <oliver@rutherfurd.net>

$Id: Title_Case.py 28 2003-03-25 22:40:28Z oliver $
"""

def titleCase(textArea):
    textArea.getBuffer().beginCompoundEdit()
    try:
        selections = textArea.getSelection()
        if len(selections) == 0:
            textArea.setText(textArea.getText().title())
        else:
            for sel in selections:
                start,end = sel.start,sel.end
                text = textArea.getText(start, end-start)
                textArea.getBuffer().remove(start, end-start)
                textArea.getBuffer().insert(start, text.title())
    finally:
        textArea.getBuffer().endCompoundEdit()


if __name__ in ('__main__','main'):
    titleCase(init.textArea)

# :indentSize=4:lineSeparator=\n:noTabs=false:tabSize=4:

