move files panel to separate document
This commit is contained in:
parent
1366316895
commit
b8e6918dc8
@ -1,12 +1,6 @@
|
|||||||
<splitbox id="editorRoot" orientation="horizontal" split-pos="0.3">
|
<splitbox id="editorRoot" orientation="horizontal" split-pos="0.3">
|
||||||
<splitbox split-pos="0.75">
|
<splitbox split-pos="0.75">
|
||||||
<panel interval="2" color="0" padding="2">
|
<iframe src="core:files_panel"></iframe>
|
||||||
<textbox pos="2" padding="4,0,4,0" sub-consumer="filter_files" hint="@Filter"></textbox>
|
|
||||||
<panel id="filesList" color="#00000030" interval="6" padding="4"
|
|
||||||
size-func="-1,-45" pos="2,38">
|
|
||||||
<!-- content is generated in script -->
|
|
||||||
</panel>
|
|
||||||
</panel>
|
|
||||||
<panel id="problemsLog"
|
<panel id="problemsLog"
|
||||||
color="#00000030"
|
color="#00000030"
|
||||||
padding="5,15,5,15">
|
padding="5,15,5,15">
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
local writeables = {}
|
local writeables = {}
|
||||||
local registry
|
local registry
|
||||||
local filenames
|
|
||||||
|
|
||||||
local current_file = {
|
local current_file = {
|
||||||
filename = "",
|
filename = "",
|
||||||
@ -49,6 +48,10 @@ events.on("core:error", function (msg, traceback)
|
|||||||
table.insert(errors_all, full)
|
table.insert(errors_all, full)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
events.on("core:open_in_editor", function(filename, linenum)
|
||||||
|
open_file_in_editor(filename, linenum)
|
||||||
|
end)
|
||||||
|
|
||||||
local function find_mutable(filename)
|
local function find_mutable(filename)
|
||||||
local packid = file.prefix(filename)
|
local packid = file.prefix(filename)
|
||||||
if packid == "core" then
|
if packid == "core" then
|
||||||
@ -80,17 +83,6 @@ local function refresh_file_title()
|
|||||||
..(edited and ' *' or '')
|
..(edited and ' *' or '')
|
||||||
end
|
end
|
||||||
|
|
||||||
function filter_files(text)
|
|
||||||
local pattern_safe = text:pattern_safe();
|
|
||||||
local filtered = {}
|
|
||||||
for _, filename in ipairs(filenames) do
|
|
||||||
if filename:find(pattern_safe) then
|
|
||||||
table.insert(filtered, filename)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
build_files_list(filtered, pattern_safe)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_control_combination(keycode)
|
function on_control_combination(keycode)
|
||||||
if keycode == input.keycode("s") then
|
if keycode == input.keycode("s") then
|
||||||
save_current_file()
|
save_current_file()
|
||||||
@ -230,44 +222,11 @@ function open_file_in_editor(filename, line, mutable)
|
|||||||
document.saveIcon.enabled = current_file.modified
|
document.saveIcon.enabled = current_file.modified
|
||||||
end
|
end
|
||||||
|
|
||||||
function build_files_list(filenames, highlighted_part)
|
|
||||||
local files_list = document.filesList
|
|
||||||
files_list.scroll = 0
|
|
||||||
files_list:clear()
|
|
||||||
|
|
||||||
for _, actual_filename in ipairs(filenames) do
|
|
||||||
local filename = actual_filename
|
|
||||||
if highlighted_part then
|
|
||||||
filename = filename:gsub(highlighted_part, "**"..highlighted_part.."**")
|
|
||||||
end
|
|
||||||
local parent = file.parent(filename)
|
|
||||||
local info = registry.get_info(actual_filename)
|
|
||||||
local icon = "file"
|
|
||||||
if info then
|
|
||||||
icon = info.type == "component" and "entity" or info.type
|
|
||||||
end
|
|
||||||
files_list:add(gui.template("script_file", {
|
|
||||||
path = parent .. (parent[#parent] == ':' and '' or '/'),
|
|
||||||
name = file.name(filename),
|
|
||||||
icon = icon,
|
|
||||||
unit = info and info.unit or '',
|
|
||||||
filename = actual_filename,
|
|
||||||
open_func = "open_file_in_editor",
|
|
||||||
}))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_open(mode)
|
function on_open(mode)
|
||||||
registry = require "core:internal/scripts_registry"
|
registry = require "core:internal/scripts_registry"
|
||||||
|
|
||||||
local files_list = document.filesList
|
|
||||||
|
|
||||||
document.editorContainer:setInterval(200, refresh_file_title)
|
document.editorContainer:setInterval(200, refresh_file_title)
|
||||||
|
|
||||||
clear_traceback()
|
clear_traceback()
|
||||||
clear_output()
|
clear_output()
|
||||||
|
|
||||||
filenames = registry.filenames
|
|
||||||
table.sort(filenames)
|
|
||||||
build_files_list(filenames)
|
|
||||||
end
|
end
|
||||||
|
|||||||
7
res/layouts/files_panel.xml
Normal file
7
res/layouts/files_panel.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<panel interval="2" color="0" padding="2">
|
||||||
|
<textbox pos="2" padding="4,0,4,0" sub-consumer="filter_files" hint="@Filter"></textbox>
|
||||||
|
<panel id="filesList" color="#00000030" interval="6" padding="4"
|
||||||
|
size-func="-1,-45" pos="2,38">
|
||||||
|
<!-- content is generated in script -->
|
||||||
|
</panel>
|
||||||
|
</panel>
|
||||||
54
res/layouts/files_panel.xml.lua
Normal file
54
res/layouts/files_panel.xml.lua
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
local registry
|
||||||
|
local filenames
|
||||||
|
|
||||||
|
function filter_files(text)
|
||||||
|
local pattern_safe = text:pattern_safe();
|
||||||
|
local filtered = {}
|
||||||
|
for _, filename in ipairs(filenames) do
|
||||||
|
if filename:find(pattern_safe) then
|
||||||
|
table.insert(filtered, filename)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
build_files_list(filtered, pattern_safe)
|
||||||
|
end
|
||||||
|
|
||||||
|
function open_file_in_editor(filename, linenum)
|
||||||
|
events.emit("core:open_in_editor", filename, linenum)
|
||||||
|
end
|
||||||
|
|
||||||
|
function build_files_list(filenames, highlighted_part)
|
||||||
|
local files_list = document.filesList
|
||||||
|
files_list.scroll = 0
|
||||||
|
files_list:clear()
|
||||||
|
|
||||||
|
for _, actual_filename in ipairs(filenames) do
|
||||||
|
local filename = actual_filename
|
||||||
|
if highlighted_part then
|
||||||
|
filename = filename:gsub(highlighted_part, "**"..highlighted_part.."**")
|
||||||
|
end
|
||||||
|
local parent = file.parent(filename)
|
||||||
|
local info = registry.get_info(actual_filename)
|
||||||
|
local icon = "file"
|
||||||
|
if info then
|
||||||
|
icon = info.type == "component" and "entity" or info.type
|
||||||
|
end
|
||||||
|
files_list:add(gui.template("script_file", {
|
||||||
|
path = parent .. (parent[#parent] == ':' and '' or '/'),
|
||||||
|
name = file.name(filename),
|
||||||
|
icon = icon,
|
||||||
|
unit = info and info.unit or '',
|
||||||
|
filename = actual_filename,
|
||||||
|
open_func = "open_file_in_editor",
|
||||||
|
}))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_open(mode)
|
||||||
|
registry = require "core:internal/scripts_registry"
|
||||||
|
|
||||||
|
local files_list = document.filesList
|
||||||
|
|
||||||
|
filenames = registry.filenames
|
||||||
|
table.sort(filenames)
|
||||||
|
build_files_list(filenames)
|
||||||
|
end
|
||||||
@ -1,6 +1,6 @@
|
|||||||
local export = {
|
local export = {
|
||||||
filenames = {},
|
filenames = {},
|
||||||
classification = {}
|
registry = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
local function collect_components(dirname, dest)
|
local function collect_components(dirname, dest)
|
||||||
@ -9,7 +9,7 @@ local function collect_components(dirname, dest)
|
|||||||
for i, filename in ipairs(files) do
|
for i, filename in ipairs(files) do
|
||||||
if file.ext(filename) == "lua" then
|
if file.ext(filename) == "lua" then
|
||||||
table.insert(dest, filename)
|
table.insert(dest, filename)
|
||||||
export.classification[filename] = {
|
export.registry[filename] = {
|
||||||
type="component",
|
type="component",
|
||||||
unit=file.prefix(filename)..":"..file.stem(filename)
|
unit=file.prefix(filename)..":"..file.stem(filename)
|
||||||
}
|
}
|
||||||
@ -33,13 +33,13 @@ local function collect_scripts(dirname, dest, ismodule)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function load_scripts_list()
|
local function load_scripts_list(packs)
|
||||||
local packs = pack.get_installed()
|
local registry = export.registry
|
||||||
for _, packid in ipairs(packs) do
|
for _, packid in ipairs(packs) do
|
||||||
collect_scripts(packid..":modules", export.filenames, true)
|
collect_scripts(packid..":modules", export.filenames, true)
|
||||||
end
|
end
|
||||||
for _, filename in ipairs(export.filenames) do
|
for _, filename in ipairs(export.filenames) do
|
||||||
export.classification[filename] = {
|
registry[filename] = {
|
||||||
type="module",
|
type="module",
|
||||||
unit=file.join(file.parent(file.prefix(filename)..":"..
|
unit=file.join(file.parent(file.prefix(filename)..":"..
|
||||||
filename:sub(filename:find("/")+1)),
|
filename:sub(filename:find("/")+1)),
|
||||||
@ -51,27 +51,39 @@ local function load_scripts_list()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function export.build_classification()
|
local function load_models_list(packs)
|
||||||
local classification = {}
|
local registry = export.registry
|
||||||
|
for _, filename in ipairs(file.list("models")) do
|
||||||
|
local ext = file.ext(filename)
|
||||||
|
if ext == "xml" then
|
||||||
|
registry[filename] = {type="model"}
|
||||||
|
table.insert(export.filenames, filename)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function export.build_registry()
|
||||||
|
local registry = {}
|
||||||
for id, props in pairs(block.properties) do
|
for id, props in pairs(block.properties) do
|
||||||
classification[props["script-file"]] = {type="block", unit=block.name(id)}
|
registry[props["script-file"]] = {type="block", unit=block.name(id)}
|
||||||
end
|
end
|
||||||
for id, props in pairs(item.properties) do
|
for id, props in pairs(item.properties) do
|
||||||
classification[props["script-file"]] = {type="item", unit=item.name(id)}
|
registry[props["script-file"]] = {type="item", unit=item.name(id)}
|
||||||
end
|
end
|
||||||
local packs = pack.get_installed()
|
local packs = pack.get_installed()
|
||||||
for _, packid in ipairs(packs) do
|
for _, packid in ipairs(packs) do
|
||||||
classification[packid..":scripts/world.lua"] = {type="world", unit=packid}
|
registry[packid..":scripts/world.lua"] = {type="world", unit=packid}
|
||||||
classification[packid..":scripts/hud.lua"] = {type="hud", unit=packid}
|
registry[packid..":scripts/hud.lua"] = {type="hud", unit=packid}
|
||||||
end
|
end
|
||||||
export.classification = classification
|
export.registry = registry
|
||||||
export.filenames = {}
|
export.filenames = {}
|
||||||
|
|
||||||
load_scripts_list()
|
load_scripts_list(packs)
|
||||||
|
load_models_list(packs)
|
||||||
end
|
end
|
||||||
|
|
||||||
function export.get_info(filename)
|
function export.get_info(filename)
|
||||||
return export.classification[filename]
|
return export.registry[filename]
|
||||||
end
|
end
|
||||||
|
|
||||||
return export
|
return export
|
||||||
|
|||||||
@ -63,4 +63,4 @@ cache_names(block)
|
|||||||
cache_names(item)
|
cache_names(item)
|
||||||
|
|
||||||
local scripts_registry = require "core:internal/scripts_registry"
|
local scripts_registry = require "core:internal/scripts_registry"
|
||||||
scripts_registry.build_classification()
|
scripts_registry.build_registry()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user