api-issue-tracker icon indicating copy to clipboard operation
api-issue-tracker copied to clipboard

Missing events for closing documents (MacOS)

Open SimonWeinbergerEnscape opened this issue 2 years ago • 2 comments

Repro steps:

  1. Start SketchUp 2023 (or earlier version) on MacOS
  2. Go to state with exactly one open document (document A)
  3. Close document A

Expected behavior: ANY observer receives an event. AppObserver.onActivateModel with nil argument would work. ModelObserver.onDeleteModel would work, but that method is not called in my tests.

Actual behavior: No event at all. Only workaround is to use UI.start_timer and poll Model.valid?, which I'd like to avoid.

Alternatively: 2. Go to state with multiple open documents 3. Click menu "File"->"Close All"

Expected behavior: ANY observer receives an event. Actual behavior: No event at all.

Slight variation: 2. Go to state with multiple open documents 3. Close one document

Actual behavior: AppObserver.onActivateModel receives a call, but during that call Model.valid? of the closed document is still true.

High level use case: Our plugin (Enscape) wants to keep track of all currently opened documents to show these documents and their content in our own UI elements.

SimonWeinbergerEnscape avatar Aug 01 '23 11:08 SimonWeinbergerEnscape

ModelObserver.onDeleteModel would work, but that method is not called in my tests.

We have an open issue for this already:

Actual behavior: AppObserver.onActivateModel receives a call, but during that call Model.valid? of the closed document is still true.

So, we should have some clarity (in the documentation) whether this is happening just before the model document is closed ... so for example state could be saved, ... but an observer would not be able to tell that the model was going to close, closing, or had been closed.

Hmmmm... the docs for Model#close says ...

On Mac OS, only the active model can be closed.

So, I assume that the answer to my above question is true, ... the closing model is made the active model if say a user clicks the close button of the document window.

Actual behavior: No event at all. Only workaround is to use UI.start_timer and poll Model.valid?, which I'd like to avoid.

Yes, I would assume that Sketchup.active_model returns nil when no models are open on the Mac ?

Do you see ModelObserver#onEraseAll firing at all when models are closed on the Mac ?

DanRathbun avatar Aug 01 '23 18:08 DanRathbun

Logged as: SKEXT-3814

sketchup[bot] avatar Aug 07 '23 06:08 sketchup[bot]