Creating scripts
This commit is contained in:
@@ -211,19 +211,17 @@ impl EditorState {
|
|||||||
fn open_scripts_dialog(&mut self) {
|
fn open_scripts_dialog(&mut self) {
|
||||||
let mut names: Vec<String> = self.world.scripts.keys().cloned().collect();
|
let mut names: Vec<String> = self.world.scripts.keys().cloned().collect();
|
||||||
names.sort();
|
names.sort();
|
||||||
self.dialog = Some(Dialog::list("Scripts", names, false, |resp, ed: &mut EditorState| {
|
self.dialog = Some(Dialog::list("Scripts", names, true, |resp, ed: &mut EditorState| {
|
||||||
if let ListDialogResponse::Select(name) = resp {
|
match resp {
|
||||||
ed.open_script_editor(&name);
|
ListDialogResponse::Select(name) | ListDialogResponse::Create(name) => {
|
||||||
|
let source = ed.world.scripts.get(&name).cloned().unwrap_or_default();
|
||||||
|
ed.code_editor = Some(CodeEditor::new(&name, &source));
|
||||||
|
}
|
||||||
|
ListDialogResponse::Cancel => {}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Opens the code editor on the named script (empty if the name is unknown).
|
|
||||||
fn open_script_editor(&mut self, name: &str) {
|
|
||||||
let source = self.world.scripts.get(name).cloned().unwrap_or_default();
|
|
||||||
self.code_editor = Some(CodeEditor::new(name, &source));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Closes the code editor, saving its text back into the in-memory script pool
|
/// Closes the code editor, saving its text back into the in-memory script pool
|
||||||
/// (mirrors how the Name/Entry-board dialogs mutate the loaded `World`).
|
/// (mirrors how the Name/Entry-board dialogs mutate the loaded `World`).
|
||||||
pub(crate) fn close_script_editor(&mut self) {
|
pub(crate) fn close_script_editor(&mut self) {
|
||||||
|
|||||||
Reference in New Issue
Block a user