"Paste As New" by NickDMax
Rating:









(0 votes)
| Name: | Paste As New |
|---|---|
| Uploaded By: | NickDMax |
| Date Created: | May 4, 2009 3:09 p.m. |
| Date Modified: | May 4, 2009 3:09 p.m. |
| Description: | Utility functions to paste the clipboard as a new document, or to extract the current selection as a new document. |
| Num Views: | 343 |
| Num Downloads: | 131 |
Contents
###############################################################################
## 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()