<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>pnotepad.org forums &#187; Topic: pypn script -- duplicate text in new doc and paste as new</title>
		<link>http://pnotepad.org/forums/topic/570</link>
		<description>Programmer&#039;s Notepad Forums</description>
		<language>en-US</language>
		<pubDate>Thu, 09 Feb 2012 06:05:35 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.3</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://pnotepad.org/forums/search.php</link>
		</textInput>
		<atom:link href="http://pnotepad.org/forums/rss/topic/570" rel="self" type="application/rss+xml" />

		<item>
                        <title>pypn script -- duplicate text in new doc and paste as new (NickDMax)</title>
			<link>http://pnotepad.org/forums/topic/570#post-2003</link>
			<pubDate>Tue, 28 Apr 2009 15:07:43 +0000</pubDate>
			<dc:creator>NickDMax</dc:creator>
			<guid isPermaLink="false">2003@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;a little fix for the &#38;quot;paste as new&#38;quot; feature. This still had the logic ensuring that a document was selected, but this is not really very convenient for a &#38;quot;Paste as New&#38;quot; feature.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;@script(&#38;amp;quot;Paste As New&#38;amp;quot;, &#38;amp;quot;DocUtils&#38;amp;quot;)
def pasteAsNew():
    &#38;amp;quot;&#38;amp;quot;&#38;amp;quot; This script will paste the current contense of the clipboard into a new document &#38;amp;quot;&#38;amp;quot;&#38;amp;quot;
    newDoc = pn.NewDocument(None)
    newEditor = scintilla.Scintilla(newDoc)
    newEditor.BeginUndoAction()
    newEditor.Paste()
    newEditor.EndUndoAction()
    pass&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
                        <title>pypn script -- duplicate text in new doc and paste as new (NickDMax)</title>
			<link>http://pnotepad.org/forums/topic/570#post-1987</link>
			<pubDate>Tue, 28 Apr 2009 06:31:52 +0000</pubDate>
			<dc:creator>NickDMax</dc:creator>
			<guid isPermaLink="false">1987@http://pnotepad.org/forums/</guid>
			<description>&#60;p&#62;One thing I often do is extract a section of a file from one file open a new document and paste the result into it for later processing... I call this &#38;quot;clipboarding&#38;quot; and I do a good bit of it.&#60;/p&#62;
&#60;p&#62;Here is a script that will automate that process. If you select a section of text and run the duplicate script it will open a new document and write in the content. If you do not have a selection this will duplicate the current document in an new window.&#60;/p&#62;
&#60;p&#62;The file also contains a simple function to paste the contents of the clipboard into the a new document. &#60;/p&#62;
&#60;p&#62;docUtils.py:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;###############################################################################
## DocUtils scripts -- the purpose of this script is to provide functions for
## dealing with new documents.
## By: NickDMax

import pn
import scintilla
from pypn.decorators import script

@script(&#38;quot;Duplicate&#38;quot;, &#38;quot;DocUtils&#38;quot;)
def dupDocument():
    &#38;quot;&#38;quot;&#38;quot; This script will extract the current selection to a new document. &#38;quot;&#38;quot;&#38;quot;
    &#38;quot;&#38;quot;&#38;quot; if there is no selection then it will duplicate the entire document. &#38;quot;&#38;quot;&#38;quot;
    doc = pn.CurrentDoc()
    if doc is not None:     #Lets try not to crash pn too often...
        editor = scintilla.Scintilla(pn.CurrentDoc())
        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()
    pass

@script(&#38;quot;PasteAs New&#38;quot;, &#38;quot;DocUtils&#38;quot;)
def pasteAsNew():
    &#38;quot;&#38;quot;&#38;quot; This script will paste the current contense of the clipboard into a new document &#38;quot;&#38;quot;&#38;quot;
    doc = pn.CurrentDoc()
    if doc is not None:     #Lets try not to crash pn too often...
        newDoc = pn.NewDocument(None)
        newEditor = scintilla.Scintilla(newDoc)
        newEditor.BeginUndoAction()
        newEditor.Paste()
        newEditor.EndUndoAction()
    pass&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>

