@@ -43,49 +43,50 @@ type RhinoSync private () =
4343 static let mutable clear : unit -> unit = // changed via reflection below from Fesh
4444 fun () -> ()
4545
46- static let initFeshPrint () =
47- let allAss = AppDomain.CurrentDomain.GetAssemblies()
48- match allAss |> Array.tryFind ( fun a -> a.GetName() .Name = " Fesh" ) with
49- | Some feshAssembly ->
50- try
51- let printModule = feshAssembly.GetType " Fesh.Model.IFeshLogModule"
52- if notNull printModule then
53- let cl = printModule.GetProperty( " clear" ) .GetValue( feshAssembly)
54- if notNull cl then
55- let clt = cl :?> unit -> unit
56- clear <- clt
57-
58- try
59- let pc = printModule.GetProperty( " printColorTupled" ) .GetValue( feshAssembly)
60- if notNull pc then
61- let pct = pc :?> int * int * int * string -> unit
62- printColor <- pct
63-
64- let pnc = printModule.GetProperty( " printnColorTupled" ) .GetValue( feshAssembly)
65- if notNull pnc then
66- let pct = pnc :?> int * int * int * string -> unit
67- printNewLineColor <- pct
68-
69- with ex ->
70- eprintfn " The Fesh.Model.IFeshLogModule.clear was found but printColorTupled failed. The Error was: %A " ex
71-
72- with ex ->
73- eprintfn " The Fesh was found but setting up color printing failed. The Error was: %A " ex
74- | None -> ()
75-
76- match allAss |> Array.tryFind ( fun a -> a.GetName() .Name = " Pretty" ) with
77- | Some prettyAssembly ->
78- try
79- let prettySettings = prettyAssembly.GetType " Pretty.PrettySettings"
80- if notNull prettySettings then
81- let formatters = prettySettings.GetProperty( " Formatters" ) .GetValue( prettyAssembly) :?> ResizeArray< obj -> option< string>>
82- if notNull formatters then
83- prettyFormatters <- formatters
46+ // static let initFeshPrint() =
47+
48+ // let allAss = AppDomain.CurrentDomain.GetAssemblies()
49+ // match allAss |> Array.tryFind (fun a -> a.GetName().Name = "Fesh") with
50+ // | Some feshAssembly ->
51+ // try
52+ // let printModule = feshAssembly.GetType "Fesh.Model.IFeshLogModule"
53+ // if notNull printModule then
54+ // let cl = printModule.GetProperty("clear").GetValue(feshAssembly)
55+ // if notNull cl then
56+ // let clt = cl :?> unit -> unit
57+ // clear <- clt
58+
59+ // try
60+ // let pc = printModule.GetProperty( "printColorTupled" ).GetValue(feshAssembly)
61+ // if notNull pc then
62+ // let pct = pc :?> int * int * int * string -> unit
63+ // printColor <- pct
64+
65+ // let pnc = printModule.GetProperty("printnColorTupled").GetValue(feshAssembly)
66+ // if notNull pnc then
67+ // let pct = pnc :?> int * int * int * string -> unit
68+ // printNewLineColor <- pct
69+
70+ // with ex ->
71+ // eprintfn "The Fesh.Model.IFeshLogModule.clear was found but printColorTupled failed. The Error was: %A" ex
72+
73+ // with ex ->
74+ // eprintfn "The Fesh was found but setting up color printing failed. The Error was: %A" ex
75+ // |None -> ()
8476
77+ // match allAss |> Array.tryFind (fun a -> a.GetName().Name = "Pretty") with
78+ // | Some prettyAssembly ->
79+ // try
80+ // let prettySettings = prettyAssembly.GetType "Pretty.PrettySettings"
81+ // if notNull prettySettings then
82+ // let formatters = prettySettings.GetProperty("Formatters").GetValue(prettyAssembly) :?> ResizeArray<obj -> option<string>>
83+ // if notNull formatters then
84+ // prettyFormatters <- formatters
8585
86- with ex ->
87- eprintfn " An Assembly 'Pretty' was found but setting up color printing failed. The Error was: %A " ex
88- | None -> ()
86+
87+ // with ex ->
88+ // eprintfn "An Assembly 'Pretty' was found but setting up color printing failed. The Error was: %A" ex
89+ // |None -> ()
8990
9091
9192
@@ -95,7 +96,7 @@ type RhinoSync private () =
9596 static let mutable initIsPending = true
9697
9798 //only called when actually needed in DoSync methods below.
98- static let init () =
99+ static let initSync () =
99100 initIsPending <- false
100101 if isNull feshRhAssembly then
101102 // it s ok to log errors here since we check 'if notNull feshRh then'
@@ -107,47 +108,44 @@ type RhinoSync private () =
107108 if notNull feshRh then
108109 feshRhAssembly <- feshRh.Assembly
109110 feshRhinoSyncModule <- feshRhAssembly.GetType " Fesh.Rhino.Sync"
110- initFeshPrint()
111111 with e ->
112112 log " Rhino.Scripting.dll could not get feshRhinoSyncModule from Fesh Assembly via Reflection: %A " e
113113
114114 if notNull feshRhinoSyncModule then
115115 // it s ok to log errors here since feshRhinoSyncModule is not null and we expect to find those all:
116116 try
117117 hideEditor <- feshRhinoSyncModule.GetProperty( " hideEditor" ) .GetValue( feshRhAssembly) :?> Action
118- //if isNull hideEditor then
119- //log "Rhino.Scripting.dll: Fesh.Rhino.Sync.hideEditor is null" // null is expected when the Fesh plugin is loaded but the editor is not running.
120118 with e ->
121119 log " Rhino.Scripting.dll: Fesh.Rhino.Sync.hideEditor failed with: %O " e
122120
123121 try
124122 showEditor <- feshRhinoSyncModule.GetProperty( " showEditor" ) .GetValue( feshRhAssembly) :?> Action
125- // if isNull showEditor then
126- // log "Rhino.Scripting.dll: Fesh.Rhino.Sync showEditor is null" // null is expected when the Fesh plugin is loaded but the editor is not running.
127123 with e ->
128124 log " Rhino.Scripting.dll: Fesh.Rhino.Sync.showEditor failed with: %O " e
129125
130126 try
131127 isEditorVisible <- feshRhinoSyncModule.GetProperty( " isEditorVisible" ) .GetValue( feshRhAssembly) :?> Func< bool>
132- //if isNull isEditorVisible then
133- // log "Rhino.Scripting.dll: Fesh.Rhino.Sync isEditorVisible is null" // null is expected when the Fesh plugin is loaded but the editor is not running.
134128 with e ->
135129 log " Rhino.Scripting.dll: Fesh.Rhino.Sync.isEditorVisible failed with: %O " e
136130
137131 try
138132 syncContext <- feshRhinoSyncModule.GetProperty( " syncContext" ) .GetValue( feshRhAssembly) :?> Threading.SynchronizationContext
139- //if isNull syncContext then
140- //log "Rhino.Scripting.dll: Fesh.Rhino.Sync.syncContext is null"// null is expected when the Fesh plugin is loaded but the editor is not running.
141-
142133 with e ->
143134 log " Rhino.Scripting.dll: Fesh.Rhino.Sync.syncContext failed with: %O " e
144135
136+
137+
138+ try
139+
140+ initFeshPrint( feshRhAssembly)
141+
145142 else
146143 // Fesh syncContext not found via reflection,
147144 // The code is not used from within Fesh.Rhino plugin
148145 // let just use AsyncInvoke from Eto.Forms.Application
149146 // https://pages.picoe.ca/docs/api/html/M_Eto_Forms_Application_AsyncInvoke.htm#!
150- syncContext <- null
147+ // syncContext <- null
148+ syncContext <- Threading.SynchronizationContext.Current
151149
152150 //
153151 // // try to get just the sync context from Windows form ( that works on Mac.Mono) (WPF is not anymore referenced by this project)
@@ -162,7 +160,7 @@ type RhinoSync private () =
162160 // should be called via reflection from Fesh.Rhino in case Rhino.Scripting is loaded already by another plugin.
163161 // Reinitialize Rhino.Scripting just in case it is loaded already in the current AppDomain:
164162 // to have showEditor and hideEditor actions setup correctly.
165- new Action( init )
163+ new Action( initSync )
166164
167165
168166 // An alternative to do! Async.SwitchToContext syncContext
@@ -187,33 +185,36 @@ type RhinoSync private () =
187185 /// Set to false to disable the logging off errors to
188186 /// RhinoApp.WriteLine and the error stream (eprintfn).
189187 static member LogErrors
190- with get() = logErrors
191- and set v = logErrors <- v
188+ with get() : bool = logErrors
189+ and set v : unit = logErrors <- v
192190
193191 /// The SynchronizationContext of the currently Running Rhino Instance,
194192 /// This SynchronizationContext is loaded via reflection from the Fesh.Rhino plugin
195193 static member SyncContext
196- with get() =
194+ with get() : Threading.SynchronizationContext =
197195 if isNull syncContext then
198- initialize.Invoke() // init()
196+ initialize.Invoke() // this is the same as init()
199197 syncContext
200- and set v =
198+ and set v : unit =
201199 syncContext <- v
202200
203201 /// Hide the WPF Window of currently running Fesh Editor.
204202 /// Or do nothing if not running in Fesh Editor.
205- static member HideEditor () = if notNull hideEditor then hideEditor.Invoke()
203+ static member HideEditor () =
204+ if notNull hideEditor then hideEditor.Invoke()
206205
207206 /// Show the WPF Window of currently running Fesh Editor.
208207 /// Or do nothing if not running in Fesh Editor.
209- static member ShowEditor () = if notNull showEditor then showEditor.Invoke()
208+ static member ShowEditor () =
209+ if notNull showEditor then showEditor.Invoke()
210210
211211 // The Assembly currently running Fesh Editor Window.
212212 // Or 'null' if not running in Fesh Editor.
213213 // static member FeshRhinoAssembly :Reflection.Assembly = feshRhAssembly
214214
215215 //static member Initialize() = init() // not called in ActiveDocument module anymore , only called when actually needed in DoSync methods below.
216- static member PrettyFormatters = prettyFormatters
216+ static member PrettyFormatters : ResizeArray < obj -> option < string >> =
217+ prettyFormatters
217218
218219 /// Prints in both RhinoApp.WriteLine and Console.WriteLine, or Fesh Editor with color if running.
219220 /// Red green blue text , NO new line
@@ -239,7 +240,7 @@ type RhinoSync private () =
239240 /// Evaluates a function on UI Thread.
240241 static member DoSync ( func : unit -> 'T ) : 'T =
241242 if RhinoApp.InvokeRequired then
242- if initIsPending then init ()
243+ if initIsPending then initSync ()
243244 if isNull syncContext then
244245 Eto.Forms.Application.Instance.Invoke func
245246
@@ -262,7 +263,7 @@ type RhinoSync private () =
262263 static member DoSyncRedraw ( func : unit -> 'T ) : 'T =
263264 let redraw = RhinoDoc.ActiveDoc.Views.RedrawEnabled
264265 if RhinoApp.InvokeRequired then
265- if initIsPending then init ()
266+ if initIsPending then initSync ()
266267 if isNull syncContext then
267268 Eto.Forms.Application.Instance.Invoke func
268269
@@ -291,7 +292,7 @@ type RhinoSync private () =
291292 let redraw = RhinoDoc.ActiveDoc.Views.RedrawEnabled
292293
293294 if RhinoApp.InvokeRequired then
294- if initIsPending then init () // do first
295+ if initIsPending then initSync () // do first
295296 if isNull syncContext then
296297 Eto.Forms.Application.Instance.Invoke func
297298
@@ -314,7 +315,7 @@ type RhinoSync private () =
314315 return res
315316 } |> Async.RunSynchronously
316317 else
317- if initIsPending then init () // because even when we are in sync we still need to see if the Fesh window is showing or not.
318+ if initIsPending then initSync () // because even when we are in sync we still need to see if the Fesh window is showing or not.
318319 let isWinVis = if isNull isEditorVisible then false else isEditorVisible.Invoke() // do after init
319320 //eprintfn "Hiding Fesh sync..isWinVis:%b" isWinVis
320321 if isWinVis && notNull hideEditor then hideEditor.Invoke()
0 commit comments