Skip to content

Fix various issues with the previewers #821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/PanelCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ export default function PanelCode({ builder, previewer, settings }) {
function switchLanguage() {
panel.language = dropdown_code_lang.selected_item?.string;
stack_code.visible_child_name = panel.language;
previewer.useInternal().catch(console.error);
if (panel.language === "JavaScript") {
previewer.useInternal().catch(console.error);
} else {
// If we switch language to anything other than JS,
// we need the user to hit "Run" first to compile the code and/or
// init the demo in the external previewer.
previewer.hideShowPreviewerButton().catch(console.error);
}
}
switchLanguage();

Expand Down
7 changes: 6 additions & 1 deletion src/Previewer/External.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export default function External({ output, builder, onWindowChange }) {
console.debug(err);
return;
}
stack.set_visible_child_name("open_window");
// only do this, if we were previously on "close_window", because it's possible
// we have just been replaced with the internal previewer, which may have
// already switched tro "inline"
if (stack.get_visible_child_name() === "close_window") {
stack.set_visible_child_name("open_window");
}
}

function stop() {
Expand Down
7 changes: 6 additions & 1 deletion src/Previewer/Previewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default function Previewer({
stack.set_visible_child_name("close_window");
} else {
stack.set_visible_child_name("open_window");
useInternal().catch(console.error);
}
},
output,
Expand Down Expand Up @@ -276,6 +275,7 @@ export default function Previewer({

current = previewer;

button_open.show();
handler_id_button_open = button_open.connect("clicked", async () => {
try {
await current.open();
Expand All @@ -301,6 +301,10 @@ export default function Previewer({
}
}

async function hideShowPreviewerButton() {
button_open.hide();
}

builder.get_object("button_screenshot").connect("clicked", () => {
screenshot({ application, window, current }).catch(console.error);
});
Expand All @@ -323,6 +327,7 @@ export default function Previewer({
},
useExternal,
useInternal,
hideShowPreviewerButton,
setPanelCode(v) {
panel_code = v;
},
Expand Down
2 changes: 1 addition & 1 deletion src/Previewer/previewer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ namespace Workbench {
private void set_window (Gtk.Window window) {
this.window?.destroy ();
this.window = window;
this.window.hide_on_close = true;
this.window.close_request.connect (this.on_window_closed);
}

private bool on_window_closed () {
this.window_open (false);
this.window = null;
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/langs/python/python-previewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ def set_window(self, the_window: Gtk.Window):
if self.window is not None:
self.window.destroy()
self.window = the_window
# Make sure the preview can be re-opened by using the "Show Preview Window" button.
self.window.set_hide_on_close(True)
self.window.connect("close-request", self.on_window_closed)

def on_window_closed(self, *args):
self.window_open(False)
self.window = None
return False

def on_css_parsing_error(self, _css, section: Gtk.CssSection, error: GLib.Error):
Expand Down