[updated] Preserving view when switching between doc windows

Get help using and writing Nisus Writer Pro macros.
Post Reply
goldste4
Posts: 98
Joined: 2010-02-22 15:06:48

[updated] Preserving view when switching between doc windows

Post by goldste4 »

[Edit: I had copied the wrong macro code into the post initially, it now has the correct code]

Hello all,

I have a macro that I use to automatically cut and paste material from the document I'm currently editing to a scrap document. The macro then switches back to the original document so I can continue my editing. The macro uses the command "Document.setActive $doc" to switch back to the original file.

All works perfectly if the document I'm currently editing is in Page or Draft view. However, if the original document is in Full Screen mode, when the macro switches back to it, the document reverts to Page or Draft depending on what it last was in.

So, finally, here is the question: how can I have the macro switch back to the document I'm currently editing and return it to Full Screen mode?

Thanks in advance,
Josh

For what it is worth, here is the current macro:

Code: Select all

#Get name and path or document being edited.
$doc = Document.active
$path = $doc.filePath
$name = $doc.displayName

#Assemble path and name of Scrap file (always “X -- ” + edited document); always in same folder
$xpath = $path.filePathByRemovingLastComponent
$xname = ‘X -- ’
$xname &= $name
$xpath = $xpath.filePathByAppendingComponent ($xname)

$text = Read Selection # copy current document's selected text
Menu ':Edit:Delete'

# See if X-file Exists: Open it or create it.
If File.existsAtPath($xpath)
   Open $xpath
Else
   New
   Save As $xpath
End

$xdoc = Document.active
Select Document End # move to end of x-document
Type Text "******\n"
$xdoc.insertText( $text, 'm' ) # insert text
Type Text "\n\n"
Save
Document.setActive $doc
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: [updated] Preserving view when switching between doc win

Post by martin »

goldste4 wrote:So, finally, here is the question: how can I have the macro switch back to the document I'm currently editing and return it to Full Screen mode?
This isn't too hard- the trick is restoring Full Screen only if that was the active view mode. But you can test that using the "Menu State" command. So your code will look something like this:

Code: Select all

#Get name and path or document being edited.
$doc = Document.active
$isFullScreen = Menu State ':View:Full Screen'
...
Document.setActive $doc
If $isFullScreen
	Menu 'Full Screen'
End
Let me know if you have any troubles.
goldste4
Posts: 98
Joined: 2010-02-22 15:06:48

Re: [updated] Preserving view when switching between doc win

Post by goldste4 »

Hi Martin,
Perfect! I feel bad for not thinking of it myself, although knowing the quickness and quality of the responses on the Macro forum can make one who isn't very versed in NWP's macro language, like me, a bit lazy . . .
Thanks again,
Josh
Post Reply