1+ // ViewSet 0.4
2+ // Lamma Studio Design
3+ // 14-4-2021
4+
5+ //Changelog
6+ // 0.1 Initial release
7+ // 0.2 added auto checkOut function
8+ // 0.3 remove old diagnostics replace with generics
9+ // 0.4 check for no windows and get more specific in check
10+ // 0.5 prefs added and kept
11+
12+ #targetengine "session" ;
13+ setPrefs ( ) ;
14+ setView ( ) ;
15+
16+ function setView ( ) {
17+ try {
18+ //
19+ // Clear away any old event listeners so we can reinstall them
20+ //
21+ app . eventListeners . everyItem ( ) . remove ( ) ;
22+ app . addEventListener ( Document . AFTER_OPEN , afterOpenHandler ) ;
23+ //
24+ // Handle the active document if there is one
25+ //
26+ if (
27+ app . documents . length > 0 &&
28+ app . activeDocument &&
29+ app . activeDocument instanceof Document
30+ ) {
31+ afterOpenHandler ( {
32+ target : app . activeDocument ,
33+ eventType : Document . AFTER_OPEN
34+ } ) ;
35+ } ;
36+ } catch ( err ) {
37+ alert ( "MainRoutine Error: " + [ err , err . line ] ) ;
38+ } ;
39+ } ;
40+
41+ function afterOpenHandler ( evt ) {
42+ try {
43+ if ( ( app . documents . item ( 0 ) . windows . length < 2 ) && ( app . documents . item ( 0 ) . windows . length > 0 ) ) {
44+ var savedSettings = eval ( app . extractLabel ( "lsd_vs_usersettings" ) ) ;
45+ // alert ("savedSettings: " + savedSettings);
46+ var doc = app . documents . item ( 0 ) ;
47+ // Set Window to Galley
48+ app . documents . item ( 0 ) . windows . item ( 0 ) . viewTab = ViewTabs . GALLEY_VIEW ;
49+ // Open a new window
50+ app . documents . item ( 0 ) . windows . add ( ) ;
51+ // Set it to Layout and fit it to page
52+ app . documents . item ( 0 ) . windows . item ( 0 ) . viewTab = ViewTabs . LAYOUT_VIEW ;
53+ app . documents . item ( 0 ) . windows . item ( 0 ) . zoom = ZoomOptions . ACTUAL_SIZE ;
54+ // Tile the windows
55+ app . tileWindows ( HorizontalOrVertical . HORIZONTAL ) ;
56+ //Switch on/off the guides
57+ //Dialog choice or settings file to go here
58+ doc . gridPreferences . documentGridShown = savedSettings [ 0 ] ;
59+ doc . gridPreferences . baselineGridShown = savedSettings [ 1 ] ;
60+ doc . guidePreferences . guidesShown = savedSettings [ 2 ] ;
61+ doc . viewPreferences . showFrameEdges = savedSettings [ 3 ] ;
62+ doc . viewPreferences . showRulers = savedSettings [ 4 ] ;
63+ app . textPreferences . showInvisibles = savedSettings [ 5 ] ;
64+ // subs need the notes so leave on
65+ doc . viewPreferences . showNotes = savedSettings [ 6 ] ;
66+ // Code to do auto checkout
67+ app . activeDocument . stories . everyItem ( ) . checkOut ( ) ;
68+ } else {
69+ return ;
70+ } ;
71+ } catch ( err ) {
72+ alert ( "EventHandler Error: " + [ err , err . line ] ) ;
73+ } ;
74+ } ;
75+
76+ function setPrefs ( ) {
77+ try {
78+ var savedSettings = eval ( app . extractLabel ( "lsd_vs_usersettings" ) ) ;
79+ // alert ("savedSettings: " + savedSettings);
80+ if ( savedSettings === undefined ) {
81+ ///////////////////////////////////////////////////////////////////
82+ ///////////// Dialogue to ask you what you want to do /////////////
83+ ///////////////////////////////////////////////////////////////////
84+ var dlgAd = app . dialogs . add ( { name :"Preferences" } ) ;
85+ var dlcAd = dlgAd . dialogColumns . add ( ) ;
86+
87+ //////////////////////// Line type section ////////////////////////
88+ var bpnAd = dlcAd . borderPanels . add ( ) ;
89+ bpnAd . staticTexts . add ( { staticLabel :"Show: " } ) ;
90+
91+ //////////////////// Line type radiobuttonGroup ///////////////////
92+ var docugd = bpnAd . checkboxControls . add ( { staticLabel :"DocumentGrid" , checkedState :false } ) ;
93+ var basegd = bpnAd . checkboxControls . add ( { staticLabel :"BaselineGrid" , checkedState :false } ) ;
94+ var guides = bpnAd . checkboxControls . add ( { staticLabel :"Guides" , checkedState :false } ) ;
95+ var frames = bpnAd . checkboxControls . add ( { staticLabel :"FrameEdges" , checkedState :false } ) ;
96+ var rulers = bpnAd . checkboxControls . add ( { staticLabel :"Rulers" , checkedState :false } ) ;
97+ var invisi = bpnAd . checkboxControls . add ( { staticLabel :"Invisibles" , checkedState :false } ) ;
98+ var noters = bpnAd . checkboxControls . add ( { staticLabel :"Notes" , checkedState :false } ) ;
99+
100+ ///////////// Display dialog and capture user choices /////////////
101+ blnResult = dlgAd . show ( ) ;
102+ if ( blnResult == false ) {
103+ alert ( "Operation cancelled by user." ) ;
104+ exit ( ) ;
105+ } else {
106+ var docgd = docugd . checkedState ;
107+ var basgd = basegd . checkedState ;
108+ var guide = guides . checkedState ;
109+ var frame = frames . checkedState ;
110+ var ruler = rulers . checkedState ;
111+ var invis = invisi . checkedState ;
112+ var notes = noters . checkedState ;
113+ var savedSettings = [ docgd , basgd , guide , frame , ruler , invis , notes ] ;
114+ } ;
115+ dlgAd . destroy ( ) ;
116+ app . insertLabel ( "lsd_vs_usersettings" , savedSettings . toSource ( ) ) ;
117+ } ;
118+ } catch ( err ) {
119+ alert ( "setPrefs Error: " + [ err , err . line ] ) ;
120+ } ;
121+ } ;
0 commit comments