############################################################################### ## DocUtils scripts -- the purpose of this script is to provide functions for ## extracting /pasting text as new documents. ## By: NickDMax import pn import scintilla from pypn.decorators import script @script("Extract As New", "DocUtils") def dupDocument(): """ This script will extract the current selection to a new document. """ """ if there is no selection then it will duplicate the entire document. """ doc = pn.CurrentDoc() if doc is not None: #Lets try not to crash pn too often... editor = scintilla.Scintilla(doc) start = editor.SelectionStart end = editor.SelectionEnd sch = doc.CurrentScheme if (start == end): #nothing is selected so we will just grab it all... start = 0 end = editor.Length text = editor.GetTextRange(start, end) newDoc = pn.NewDocument(sch) newEditor = scintilla.Scintilla(newDoc) newEditor.BeginUndoAction() newEditor.AppendText(len(text), text) newEditor.EndUndoAction() @script("Paste As New", "DocUtils") def pasteAsNew(): """ This script will paste the current contense of the clipboard into a new document """ newDoc = pn.NewDocument(None) newEditor = scintilla.Scintilla(newDoc) newEditor.BeginUndoAction() newEditor.Paste() newEditor.EndUndoAction()