Skip to content
Merged
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
25 changes: 22 additions & 3 deletions src/routes/coder/ribbon/Demos.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<script>
import { python } from "$lib/globals.svelte";
import { SubMenu, MenuItem } from "$lib/utils/menu/frameMenu";
import { MessageDialog } from "$lib/utils/dialog";
import { parsePath } from "$lib/utils/files";
import { Script } from "$lib/experiment";
import { getContext } from "svelte";
import { translate } from "$lib/translation";

let current = getContext("current")

function openDemo(file) {
async function openDemo(file) {
// parse path to an object
file = parsePath(file)
// create script from file
let script = new Script(file);
script.fromFile(file)
await script.fromFile(file)
// remove file path so it just has a name (forcing "save as" rather than "save")
script.file.file = script.file.name
script.file.parent = ""
Expand All @@ -22,7 +24,11 @@
)
// focus
current.tab = current.pages.findIndex(item => item.file.file === script.file.file)
// show save reminder
reminder = true
}

let reminder = $state.raw(false)
</script>


Expand Down Expand Up @@ -56,4 +62,17 @@
{#each Object.entries(demos) as [label, value]}
{@render item(label, value)}
{/each}
{/await}
{/await}


<MessageDialog
title={translate("Reminder")}
buttons={{
OK: evt => {}
}}
bind:shown={reminder}
>
{translate(
"Click 'Save as...' to save this demo before running"
)}
</MessageDialog>
6 changes: 5 additions & 1 deletion src/routes/coder/ribbon/Ribbon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@
icon="/icons/btn-{current.pages[current.tab]?.pilotMode ? "pilot" : "run"}py.svg"
label={current.pages[current.tab]?.pilotMode ? translate("Pilot locally") : translate("Run locally")}
onclick={evt => runPython()}
disabled={!current.pages[current.tab]?.file?.file || current.pages[current.tab]?.file?.ext !== ".py"}
disabled={
!current.pages[current.tab]?.file?.file ||
!current.pages[current.tab]?.file?.parent ||
current.pages[current.tab]?.file?.ext !== ".py"
}
bind:awaiting={awaiting.runpy}
cancel={evt => stopPython()}
borderless
Expand Down