SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
38 stars 10 forks source link

macOS - detect Sketchup.active_model == nil #954

Open MSP-Greg opened 7 months ago

MSP-Greg commented 7 months ago

Recently added an Apple iMac to my desk, mostly to investigate issues with UI::HtmlDialogs.

Just noticed that I can't see a way to determine if there isn't an active model on macOS. Or, there's no observer event/callback for it.

I've got plugin/extension that I wrote a long time ago (circa 2010), and it's a lot of code. Main purpose is export/import, with a few additional features that test and modify models. At the time, the external apps it worked with were Windows only.

Now, as with a lot of apps, everything is cross-platform (macOS & Windows). Recently, the plugin was resurrected, and I'm updating it for a client (new export format). One issue is macOS compatibility.

So, I'm not familiar with all the code. When there is no model open, something is disabling all the menu items. But, the toolbar buttons are still active.

Maybe AppObserver#onActivateModel could be called with nil, since that is the value of Sketchup.active_model when there are no open models? Or, a new event/callback could be added?

Since I'm somewhat new to SU on macOS, I might be missing something...

Fredosixx commented 7 months ago

You are right. There is no way to detect WHEN the last model is closed in Mac OSX. You can sill call Sketchup.active_model, and if it is nil, then it means there is NO model open.

So, I support your request to have a more comprehensive set of observer methods to track models on Mac:

MSP-Greg commented 7 months ago

Thanks. Just trying to provide users with a good UX. Using UI::Command#set_validation_proc allows checking Sketchup.active_model, but that still leaves open dialogs. One could add something in set_validation_proc to disable dialogs.

But, all of the above has been a PITA for an existing plugin/extension that works fine on Windows.

Also, the UX on macOS seems very odd. SU's native toolbars are 'attached' to model windows, but plugin/extension toolbars are not.

None of these issues would exist in macOS SU if all SU UI objects (both native and plugin/extension) were hidden when no model was active...