nisus.com
https://www.nisus.com/forum/

[updated] Preserving view when switching between doc windows
https://www.nisus.com/forum/viewtopic.php?f=17&t=4344
Page 1 of 1

Author:  goldste4 [ 2011-06-09 10:07:20 ]
Post subject:  [updated] Preserving view when switching between doc windows

[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:
#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

Author:  martin [ 2011-06-09 12:26:55 ]
Post subject:  Re: [updated] Preserving view when switching between doc win

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:
#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.

Author:  goldste4 [ 2011-06-09 17:35:00 ]
Post subject:  Re: [updated] Preserving view when switching between doc win

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

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/