Workbench icon indicating copy to clipboard operation
Workbench copied to clipboard

Consider option to open preview in a separate window

Open vixalien opened this issue 2 years ago • 8 comments

It would be nice to have an option to open the preview in a separate window.

This can be useful when testing a responsive layout and seeing how the UI reacts to different sizes.

vixalien avatar May 11 '23 09:05 vixalien

:+1:

hint: if you don't have JS code, you can do so by selecting Vala instead of JavaScript

sonnyp avatar May 11 '23 10:05 sonnyp

Here are some pointers to get this working

There is a menu now in the preview panel so we can add the option "Preview in Window" there using settings.create_action.

As for actually opening the preview in a window, it can be done here https://github.com/sonnyp/Workbench/blob/fa40deb025adb1a78a6b853ec00ae4c9ce1678f4/src/Previewer/Internal.js#L73

sonnyp avatar May 11 '23 10:05 sonnyp

thanks. how does vala do it though, I think preview() just sets the child.

oh, does that mean we would need to create a new GtkWindow if the "Preview in Window" option is enabled??

vixalien avatar May 11 '23 10:05 vixalien

oh, does that mean we would need to create a new GtkWindow if the "Preview in Window" option is enabled??

Right, we need to create a window and set its content with the object to preview. Note that the window needs to stay around so that it can be reused when there are updates.

sonnyp avatar May 11 '23 10:05 sonnyp

An other option is to wrap your UI in a GtkWindow - Workbench will automagically offer to open the preview in a window. update works too.

But it would be nice if it worked without having to wrap.

sonnyp avatar May 11 '23 10:05 sonnyp

But it would be nice if it worked without having to wrap.

for sure.

Note that the window needs to stay around

I'm currently lost on how to implement this. is there some code that checks if the child is a GtkWindow or one of it's descendants, so that it offers to open the window in a separate window?

vixalien avatar May 11 '23 10:05 vixalien

Search for GtkRoot in src/Previewer/utils.js

sonnyp avatar May 11 '23 10:05 sonnyp

hmm i can look at this at a later date. you can assign me if you like.

vixalien avatar May 11 '23 11:05 vixalien