diff --git a/res/layouts/code_editor.xml b/res/layouts/code_editor.xml index 02881b44..4b61c4d8 100644 --- a/res/layouts/code_editor.xml +++ b/res/layouts/code_editor.xml @@ -8,47 +8,49 @@ - - - - - - - - - + + + + + + + + + + + + - - - + + diff --git a/res/layouts/code_editor.xml.lua b/res/layouts/code_editor.xml.lua index 55250c13..de460f2e 100644 --- a/res/layouts/code_editor.xml.lua +++ b/res/layouts/code_editor.xml.lua @@ -104,10 +104,29 @@ function unlock_access() ) end +local function reload_model(filename, name) + assets.parse_model("xml", document.editor.text, name) +end + function run_current_file() if not current_file.filename then return end + + local info = registry.get_info(current_file.filename) + local script_type = info and info.type or "file" + local unit = info and info.unit + + if script_type == "model" then + print(current_file.filename) + clear_output() + local _, err = pcall(reload_model, current_file.filename, unit) + if err then + document.output:paste(string.format("\n[#FF0000]%s[#FFFFFF]", err)) + end + return + end + local chunk, err = loadstring(document.editor.text, current_file.filename) clear_output() if not chunk then @@ -119,9 +138,7 @@ function run_current_file() ) return end - local info = registry.get_info(current_file.filename) - local script_type = info and info.type or "file" - local unit = info and info.unit + save_current_file() local func = function() @@ -191,6 +208,7 @@ events.on("core:open_traceback", function(traceback_b64) tb_list.size = srcsize end) +--- Save the current file in the code editor if has writeable path. function save_current_file() if not current_file.mutable then return @@ -202,7 +220,22 @@ function save_current_file() document.editor.edited = false end +--- Open a file in the code editor. +--- @param filename string - the path to the file to open. +--- @param line integer - the line number to focus on (optional). +--- @param mutable string - writeable file path (optional). function open_file_in_editor(filename, line, mutable) + debug.log("opening file " .. string.escape(filename) .. " in editor") + + local ext = file.ext(filename) + if ext == "xml" or ext == "vcm" then + document.modelviewer.src = file.stem(filename) + document.modelviewer.visible = true + else + document.modelviewer.visible = false + end + document.codePanel:refresh() + local editor = document.editor local source = file.read(filename):gsub('\t', ' ') editor.scroll = 0 @@ -225,7 +258,7 @@ end function on_open(mode) registry = require "core:internal/scripts_registry" - document.editorContainer:setInterval(200, refresh_file_title) + document.codePanel:setInterval(200, refresh_file_title) clear_traceback() clear_output() diff --git a/res/layouts/console.xml b/res/layouts/console.xml index 16fbbb0b..3772d240 100644 --- a/res/layouts/console.xml +++ b/res/layouts/console.xml @@ -22,8 +22,7 @@ markup="md" > - read_split_box( static std::shared_ptr read_model_viewer( UiXmlReader& reader, const xml::xmlelement& element ) { - auto model = element.attr("model", "").getText(); + auto model = element.attr("src", "").getText(); auto viewer = std::make_shared( reader.getGUI(), glm::vec2(), model ); diff --git a/src/io/engine_paths.cpp b/src/io/engine_paths.cpp index cb2d11e9..39851228 100644 --- a/src/io/engine_paths.cpp +++ b/src/io/engine_paths.cpp @@ -192,6 +192,9 @@ std::string EnginePaths::createWriteableDevice(const std::string& name) { break; } } + if (name == "core") { + folder = "res:"; + } if (folder.emptyOrInvalid()) { throw std::runtime_error("pack not found"); }