builder improvements. nearing completion.
This commit is contained in:
parent
de2fdb1747
commit
404934e07d
@ -33,9 +33,9 @@ local default = {
|
||||
|
||||
project = {
|
||||
project_name = { index = 1, value = "default", ptype = "string", slen = 64 },
|
||||
project_path = { index = 2, value = "./", ptype = "path", slen = 256 }, -- Always starts empty. Will support a project file.
|
||||
project_file = { index = 3, value = "default.slp", ptype = "file", slen = 64 }, -- Sokol luajit project file
|
||||
project_start = { index = 4, value = "example1.lua", ptype = "file", slen = 128 },
|
||||
project_path = { index = 2, value = ".", ptype = "path", slen = 256 }, -- Always starts empty. Will support a project file.
|
||||
project_file = { index = 3, value = "default.slp", ptype = "file", pfilter = "*.slp", slen = 64 }, -- Sokol luajit project file
|
||||
project_start = { index = 4, value = "example1.lua", ptype = "file", pfilter = "*.lua", slen = 128 },
|
||||
},
|
||||
|
||||
graphics = {
|
||||
|
||||
@ -20,9 +20,9 @@ local default = {
|
||||
|
||||
project = {
|
||||
project_name = { index = 1, value = "default", ptype = "string", slen = 64 },
|
||||
project_path = { index = 2, value = "F:\\dev\\luajit\\Thunc\\sokol-luajit", ptype = "path", slen = 256 }, -- Always starts empty. Will support a project file.
|
||||
project_file = { index = 3, value = "F:\\dev\\luajit\\Thunc\\sokol-luajit\\default.slp", ptype = "file", slen = 64 }, -- Sokol luajit project file
|
||||
project_start = { index = 4, value = "example1.lua", ptype = "file", slen = 128 },
|
||||
project_path = { index = 2, value = ".", ptype = "path", slen = 256 }, -- Always starts empty. Will support a project file.
|
||||
project_file = { index = 3, value = "default.slp", ptype = "file", pfilter = "*.slp", slen = 64 }, -- Sokol luajit project file
|
||||
project_start = { index = 4, value = "example1.lua", ptype = "file", pfilter = "*.lua", slen = 128 },
|
||||
},
|
||||
|
||||
graphics = {
|
||||
@ -40,7 +40,7 @@ local default = {
|
||||
},
|
||||
|
||||
sokol = {
|
||||
sokol_path = { index = 1, value = "F:\\dev\\luajit\\Thunc\\sokol-luajit", ptype = "path", slen = 256 },
|
||||
sokol_path = { index = 1, value = "../../../../", ptype = "path", slen = 256 },
|
||||
sokol_bin = { index = 2, value = "bin/", ptype = "path", slen = 256 },
|
||||
sokol_ffi = { index = 3, value = "ffi/", ptype = "path", slen = 256 },
|
||||
sokol_lua = { index = 4, value = "lua/", ptype = "path", slen = 256 },
|
||||
|
||||
@ -72,11 +72,13 @@ local tabs = {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-- --------------------------------------------------------------------------------------
|
||||
|
||||
local file_select = {
|
||||
popup_active = 0,
|
||||
prop = nil,
|
||||
drives = {},
|
||||
file_selected = "",
|
||||
popup_dim = ffi.new("struct nk_rect",{20, 100, 220, 90}),
|
||||
folder_path = ".",
|
||||
@ -89,23 +91,32 @@ local file_select = {
|
||||
flags = bit.bor(flags, nk.NK_WINDOW_NO_SCROLLBAR)
|
||||
if (nk.nk_group_begin(ctx, "Select File", flags) == true) then
|
||||
|
||||
nk.nk_layout_row_dynamic(ctx, dim.h-90, 1)
|
||||
nk.nk_layout_row_begin(ctx, nk.NK_DYNAMIC, 25, 2)
|
||||
nk.nk_layout_row_push(ctx, 0.2)
|
||||
nk.nk_label(ctx, "Drives: ", 1)
|
||||
|
||||
for k,v in ipairs(udata.drives) do
|
||||
nk.nk_layout_row_push(ctx, 0.1)
|
||||
if(nk.nk_button_label(ctx, v) == true) then
|
||||
udata.folder_path = v
|
||||
end
|
||||
end
|
||||
nk.nk_layout_row_end(ctx)
|
||||
|
||||
nk.nk_layout_row_dynamic(ctx, dim.h-110, 1)
|
||||
local files = dirtools.get_dirlist(udata.folder_path)
|
||||
if(#files == 0 or files[1].name ~= "..") then table.insert(files, 1, { name = ".." }) end
|
||||
local bhit = wdgts.widget_list_buttons(ctx, "select_file", nil, files, dim.w -40 )
|
||||
|
||||
if(bhit) then
|
||||
udata.hit = bhit
|
||||
if(bhit[2] == "..") then
|
||||
udata.folder_path = dirtools.get_folder(udata.folder_path)
|
||||
if(udata.folder_path == nil or udata.folder_path == "") then udata.folder_path = "." end
|
||||
udata.folder_path = dirtools.get_parent(udata.folder_path)
|
||||
else
|
||||
local isfolder = dirtools.is_folder(udata.folder_path.."\\"..udata.hit[2])
|
||||
print(isfolder)
|
||||
local isfolder = files[udata.hit[1]].folder ~= nil
|
||||
if(isfolder == true) then
|
||||
udata.folder_path = udata.folder_path.."\\"..udata.hit[2]
|
||||
udata.folder_path = dirtools.change_folder(udata.folder_path, udata.hit[2])
|
||||
else
|
||||
udata.file_selected = udata.folder_path.."\\"..udata.hit[2]
|
||||
udata.file_selected = dirtools.change_folder(udata.folder_path, udata.hit[2])
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -138,6 +149,7 @@ local folder_select = {
|
||||
prop = nil,
|
||||
popup_dim = ffi.new("struct nk_rect",{20, 100, 220, 90}),
|
||||
folder_path = ".",
|
||||
drives = {},
|
||||
hit = {0, "", 0},
|
||||
|
||||
ui_func = function(ctx, dim, udata)
|
||||
@ -147,18 +159,28 @@ local folder_select = {
|
||||
flags = bit.bor(flags, nk.NK_WINDOW_NO_SCROLLBAR)
|
||||
if (nk.nk_group_begin(ctx, "Select Folder", flags) == true) then
|
||||
|
||||
nk.nk_layout_row_dynamic(ctx, dim.h-90, 1)
|
||||
nk.nk_layout_row_begin(ctx, nk.NK_DYNAMIC, 25, 2)
|
||||
nk.nk_layout_row_push(ctx, 0.2)
|
||||
nk.nk_label(ctx, "Drives: ", 1)
|
||||
|
||||
for k,v in ipairs(udata.drives) do
|
||||
nk.nk_layout_row_push(ctx, 0.1)
|
||||
if(nk.nk_button_label(ctx, v) == true) then
|
||||
udata.folder_path = v
|
||||
end
|
||||
end
|
||||
nk.nk_layout_row_end(ctx)
|
||||
|
||||
nk.nk_layout_row_dynamic(ctx, dim.h-110, 1)
|
||||
local files = dirtools.get_folderslist(udata.folder_path)
|
||||
if(#files == 0 or files[1].name ~= "..") then table.insert(files, 1, { name = ".." }) end
|
||||
local bhit = wdgts.widget_list_buttons(ctx, "folder_files", nil, files, dim.w -40 )
|
||||
|
||||
if(bhit) then
|
||||
udata.hit = bhit
|
||||
if(bhit[2] == "..") then
|
||||
udata.folder_path = dirtools.get_folder(udata.folder_path)
|
||||
if(udata.folder_path == nil or udata.folder_path == "") then udata.folder_path = "." end
|
||||
udata.folder_path = dirtools.get_parent(udata.folder_path)
|
||||
else
|
||||
udata.folder_path = udata.folder_path.."\\"..udata.hit[2]
|
||||
udata.folder_path = dirtools.change_folder(udata.folder_path, udata.hit[2])
|
||||
end
|
||||
end
|
||||
|
||||
@ -186,41 +208,77 @@ local folder_select = {
|
||||
-- --------------------------------------------------------------------------------------
|
||||
-- Extract config and build ffi objects for them
|
||||
-- Each config property shall have a shadow ffi property labeled with _ffi
|
||||
for sectionname, section in pairs(config) do
|
||||
|
||||
for key, prop in pairs(section) do
|
||||
-- If ptype is nill or string its a string
|
||||
if(prop.ptype == "string") then
|
||||
prop.ffi = ffi.new("char[?]", prop.slen )
|
||||
ffi.fill(prop.ffi, prop.slen, 0)
|
||||
ffi.copy(prop.ffi, ffi.string(prop.value))
|
||||
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
|
||||
elseif(prop.ptype == "combo") then
|
||||
prop.ffi = ffi.new("int[1]", prop.value)
|
||||
elseif(prop.ptype == "int") then
|
||||
prop.ffi = ffi.new("int[1]", prop.value)
|
||||
elseif(prop.ptype == "float") then
|
||||
prop.ffi = ffi.new("float[1]", prop.value)
|
||||
elseif(prop.ptype == "path") then
|
||||
prop.ffi = ffi.new("char[?]", prop.slen )
|
||||
ffi.fill(prop.ffi, prop.slen, 0)
|
||||
ffi.copy(prop.ffi, ffi.string(prop.value))
|
||||
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
|
||||
elseif(prop.ptype == "file") then
|
||||
prop.ffi = ffi.new("char[?]", prop.slen )
|
||||
ffi.fill(prop.ffi, prop.slen, 0)
|
||||
ffi.copy(prop.ffi, ffi.string(prop.value))
|
||||
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
|
||||
local function setup_config()
|
||||
|
||||
for sectionname, section in pairs(config) do
|
||||
|
||||
for key, prop in pairs(section) do
|
||||
-- If ptype is nill or string its a string
|
||||
if(prop.ptype == "string") then
|
||||
prop.ffi = ffi.new("char[?]", prop.slen )
|
||||
ffi.fill(prop.ffi, prop.slen, 0)
|
||||
ffi.copy(prop.ffi, ffi.string(prop.value))
|
||||
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
|
||||
elseif(prop.ptype == "combo") then
|
||||
prop.ffi = ffi.new("int[1]", prop.value)
|
||||
elseif(prop.ptype == "int") then
|
||||
prop.ffi = ffi.new("int[1]", prop.value)
|
||||
elseif(prop.ptype == "float") then
|
||||
prop.ffi = ffi.new("float[1]", prop.value)
|
||||
elseif(prop.ptype == "path") then
|
||||
prop.ffi = ffi.new("char[?]", prop.slen )
|
||||
ffi.fill(prop.ffi, prop.slen, 0)
|
||||
ffi.copy(prop.ffi, ffi.string(prop.value))
|
||||
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
|
||||
elseif(prop.ptype == "file") then
|
||||
prop.ffi = ffi.new("char[?]", prop.slen )
|
||||
ffi.fill(prop.ffi, prop.slen, 0)
|
||||
ffi.copy(prop.ffi, ffi.string(prop.value))
|
||||
prop.len_ffi = ffi.new("int[1]", {string.len(prop.value)})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local group_width = ffi.new("int[1]", {320})
|
||||
local group_height = ffi.new("int[1]", {200})
|
||||
end
|
||||
|
||||
-- --------------------------------------------------------------------------------------
|
||||
local pix = {}
|
||||
|
||||
local function init()
|
||||
|
||||
local base_path = "./"
|
||||
pix["baboon"] = wdgts.icon_load(base_path.."images/baboon.png")
|
||||
-- pix["copy"] = icon_load(base_path.."icon/copy.png")
|
||||
-- pix["del"] = icon_load(base_path.."icon/delete.png")
|
||||
-- pix["rocket"] = icon_load(base_path.."icon/rocket.png")
|
||||
-- pix["edit"] = icon_load(base_path.."icon/edit.png")
|
||||
|
||||
winrect[0].x = 0
|
||||
winrect[0].y = 0
|
||||
winrect[0].w = sapp.sapp_width()
|
||||
winrect[0].h = sapp.sapp_height()
|
||||
|
||||
icons[0] = wdgts.icon_load("./icon/home.png")
|
||||
icons[1] = wdgts.icon_load("./icon/phone.png")
|
||||
icons[2] = wdgts.icon_load("./icon/plane.png")
|
||||
icons[3] = wdgts.icon_load("./icon/wifi.png")
|
||||
icons[4] = wdgts.icon_load("./icon/settings.png")
|
||||
icons[5] = wdgts.icon_load("./icon/volume.png")
|
||||
|
||||
folder_select.popup_dim.w = sapp.sapp_width()* 0.4
|
||||
folder_select.popup_dim.h = sapp.sapp_height()* 0.7
|
||||
folder_select.popup_dim.x = sapp.sapp_width()/2-8 - folder_select.popup_dim.w/2
|
||||
folder_select.popup_dim.y = sapp.sapp_height()/2-40 - folder_select.popup_dim.h/2
|
||||
|
||||
file_select.popup_dim.w = sapp.sapp_width()* 0.4
|
||||
file_select.popup_dim.h = sapp.sapp_height()* 0.7
|
||||
file_select.popup_dim.x = sapp.sapp_width()/2-8 - file_select.popup_dim.w/2
|
||||
file_select.popup_dim.y = sapp.sapp_height()/2-40 - file_select.popup_dim.h/2
|
||||
|
||||
setup_config()
|
||||
end
|
||||
|
||||
-- --------------------------------------------------------------------------------------
|
||||
local range_float_value = ffi.new("float[1]")
|
||||
|
||||
local function display_section(ctx, sectionname)
|
||||
|
||||
@ -259,6 +317,7 @@ local function display_section(ctx, sectionname)
|
||||
folder_select.popup_active = 1
|
||||
folder_select.prop = v
|
||||
folder_select.folder_path = v.value
|
||||
folder_select.drives = dirtools.get_drives()
|
||||
end
|
||||
nk.nk_style_set_font(ctx, myfonts[3].handle)
|
||||
elseif(v.ptype == "file") then
|
||||
@ -270,6 +329,7 @@ local function display_section(ctx, sectionname)
|
||||
file_select.popup_active = 1
|
||||
file_select.prop = v
|
||||
file_select.folder_path = dirtools.get_folder(v.value)
|
||||
file_select.drives = dirtools.get_drives()
|
||||
end
|
||||
nk.nk_style_set_font(ctx, myfonts[3].handle)
|
||||
elseif(v.ptype == "combo") then
|
||||
@ -299,15 +359,18 @@ local project_tabs = {
|
||||
display_section(ctx, "project")
|
||||
display_section(ctx, "sokol")
|
||||
end,
|
||||
file_list = {},
|
||||
},
|
||||
{
|
||||
name = "Build",
|
||||
func = function(ctx)
|
||||
display_section(ctx, "platform")
|
||||
end,
|
||||
file_list = {},
|
||||
},
|
||||
{
|
||||
name = "Logs"
|
||||
name = "Logs",
|
||||
file_list = {},
|
||||
}
|
||||
}
|
||||
-- --------------------------------------------------------------------------------------
|
||||
@ -320,6 +383,16 @@ local function project_panel(ctx)
|
||||
-- display_section(ctx, "graphics")
|
||||
-- display_section(ctx, "audio")
|
||||
|
||||
nk.nk_layout_row_dynamic(ctx, 25, 2)
|
||||
local add_folder = false
|
||||
if (nk.nk_button_label(ctx, "Build Release") == true) then
|
||||
add_folder = true
|
||||
end
|
||||
local add_file = false
|
||||
if (nk.nk_button_label(ctx, "Clean All") == true) then
|
||||
add_file = true
|
||||
end
|
||||
|
||||
-- Awesome little radial popup.
|
||||
local res = wdgts.make_pie_popup(ctx, icons, 100, 6)
|
||||
end
|
||||
@ -332,8 +405,20 @@ local function assets_panel(ctx)
|
||||
nk.nk_style_set_font(ctx, myfonts[3].handle)
|
||||
curr_tab = wdgts.widget_notebook(ctx, "assets", tabs, curr_tab, 500, 120)
|
||||
|
||||
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 22, 3)
|
||||
nk.nk_layout_row_end(ctx)
|
||||
nk.nk_layout_row_dynamic(ctx, 25, 2)
|
||||
if (nk.nk_button_label(ctx, "Add Folder") == true) then
|
||||
folder_select.popup_active = 1
|
||||
folder_select.prop = nil
|
||||
folder_select.folder_path = "."
|
||||
folder_select.drives = dirtools.get_drives()
|
||||
end
|
||||
|
||||
if (nk.nk_button_label(ctx, "Add File") == true) then
|
||||
file_select.popup_active = 1
|
||||
file_select.prop = nil
|
||||
file_select.folder_path = dirtools.get_folder(".")
|
||||
file_select.drives = dirtools.get_drives()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -350,6 +435,61 @@ local function main_ui(ctx)
|
||||
folder_select.popup_active = wdgts.widget_popup_panel(ctx, "popup", folder_select.popup_dim, folder_select.ui_func, folder_select, folder_select.popup_active)
|
||||
file_select.popup_active = wdgts.widget_popup_panel(ctx, "popup", file_select.popup_dim, file_select.ui_func, file_select, file_select.popup_active)
|
||||
|
||||
-- /* menubar */
|
||||
local menu_states = { MENU_DEFAULT = 0, MENU_WINDOWS = 1}
|
||||
nk.nk_menubar_begin(ctx)
|
||||
|
||||
-- /* menu #1 */
|
||||
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 25, 2)
|
||||
nk.nk_layout_row_push(ctx, 140)
|
||||
if (nk.nk_menu_begin_label(ctx, "Project", nk.NK_TEXT_LEFT, nk.nk_vec2(120, 200))) then
|
||||
|
||||
nk.nk_layout_row_dynamic(ctx, 35, 1)
|
||||
if (nk.nk_menu_item_label(ctx, "New", nk.NK_TEXT_LEFT)) then
|
||||
init()
|
||||
end
|
||||
nk.nk_layout_row_dynamic(ctx, 35, 1)
|
||||
if (nk.nk_menu_item_label(ctx, "Open", nk.NK_TEXT_LEFT)) then
|
||||
end
|
||||
nk.nk_layout_row_dynamic(ctx, 35, 1)
|
||||
if (nk.nk_menu_item_label(ctx, "Save", nk.NK_TEXT_LEFT)) then
|
||||
end
|
||||
nk.nk_layout_row_dynamic(ctx, 35, 1)
|
||||
if (nk.nk_menu_item_label(ctx, "SaveAs", nk.NK_TEXT_LEFT)) then
|
||||
end
|
||||
nk.nk_layout_row_dynamic(ctx, 35, 1)
|
||||
if (nk.nk_menu_item_label(ctx, "Quit", nk.NK_TEXT_LEFT)) then
|
||||
os.exit()
|
||||
end
|
||||
nk.nk_menu_end(ctx)
|
||||
end
|
||||
|
||||
-- /* menu #2 */
|
||||
nk.nk_layout_row_push(ctx, 60)
|
||||
if (nk.nk_menu_begin_label(ctx, "Tools", nk.NK_TEXT_LEFT, nk.nk_vec2(200, 200))) then
|
||||
|
||||
nk.nk_layout_row_dynamic(ctx, 35, 1)
|
||||
if (nk.nk_menu_item_label(ctx, "Build", nk.NK_TEXT_LEFT)) then
|
||||
end
|
||||
nk.nk_layout_row_dynamic(ctx, 35, 1)
|
||||
if (nk.nk_menu_item_label(ctx, "Build All", nk.NK_TEXT_LEFT)) then
|
||||
end
|
||||
nk.nk_layout_row_dynamic(ctx, 35, 1)
|
||||
if (nk.nk_menu_item_label(ctx, "Clean All", nk.NK_TEXT_LEFT)) then
|
||||
end
|
||||
nk.nk_layout_row_dynamic(ctx, 35, 1)
|
||||
if (nk.nk_menu_item_label(ctx, "Test Build", nk.NK_TEXT_LEFT)) then
|
||||
end
|
||||
nk.nk_layout_row_dynamic(ctx, 35, 1)
|
||||
if (nk.nk_menu_item_label(ctx, "Profile", nk.NK_TEXT_LEFT)) then
|
||||
end
|
||||
nk.nk_menu_end(ctx)
|
||||
end
|
||||
nk.nk_menubar_end(ctx)
|
||||
|
||||
nk.nk_layout_row_begin(ctx, nk.NK_STATIC, 15, 1)
|
||||
nk.nk_layout_row_push(ctx, 140)
|
||||
|
||||
nk.nk_style_set_font(ctx, myfonts[4].handle)
|
||||
|
||||
local flags = nk.NK_WINDOW_BORDER
|
||||
@ -382,41 +522,6 @@ local function main_ui(ctx)
|
||||
return not nk.nk_window_is_closed(ctx, "Overview")
|
||||
end
|
||||
|
||||
-- --------------------------------------------------------------------------------------
|
||||
local pix = {}
|
||||
|
||||
local function init()
|
||||
|
||||
local base_path = "./"
|
||||
pix["baboon"] = wdgts.icon_load(base_path.."images/baboon.png")
|
||||
-- pix["copy"] = icon_load(base_path.."icon/copy.png")
|
||||
-- pix["del"] = icon_load(base_path.."icon/delete.png")
|
||||
-- pix["rocket"] = icon_load(base_path.."icon/rocket.png")
|
||||
-- pix["edit"] = icon_load(base_path.."icon/edit.png")
|
||||
|
||||
winrect[0].x = 0
|
||||
winrect[0].y = 0
|
||||
winrect[0].w = sapp.sapp_width()
|
||||
winrect[0].h = sapp.sapp_height()
|
||||
|
||||
icons[0] = wdgts.icon_load("./icon/home.png")
|
||||
icons[1] = wdgts.icon_load("./icon/phone.png")
|
||||
icons[2] = wdgts.icon_load("./icon/plane.png")
|
||||
icons[3] = wdgts.icon_load("./icon/wifi.png")
|
||||
icons[4] = wdgts.icon_load("./icon/settings.png")
|
||||
icons[5] = wdgts.icon_load("./icon/volume.png")
|
||||
|
||||
folder_select.popup_dim.w = sapp.sapp_width()* 0.4
|
||||
folder_select.popup_dim.h = sapp.sapp_height()* 0.7
|
||||
folder_select.popup_dim.x = sapp.sapp_width()/2-8 - folder_select.popup_dim.w/2
|
||||
folder_select.popup_dim.y = sapp.sapp_height()/2-40 - folder_select.popup_dim.h/2
|
||||
|
||||
file_select.popup_dim.w = sapp.sapp_width()* 0.4
|
||||
file_select.popup_dim.h = sapp.sapp_height()* 0.7
|
||||
file_select.popup_dim.x = sapp.sapp_width()/2-8 - file_select.popup_dim.w/2
|
||||
file_select.popup_dim.y = sapp.sapp_height()/2-40 - file_select.popup_dim.h/2
|
||||
end
|
||||
|
||||
-- --------------------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
|
||||
@ -176,6 +176,7 @@ widgets.widget_notebook = function(ctx, tab_name, tabs, current_tab, height, tab
|
||||
|
||||
-- /* Header */
|
||||
local spacing = ctx.style.window.spacing
|
||||
|
||||
ctx.style.window.spacing = nk.nk_vec2(0,0)
|
||||
local rounding = ctx.style.button.rounding
|
||||
ctx.style.button.rounding = 0
|
||||
@ -187,11 +188,12 @@ widgets.widget_notebook = function(ctx, tab_name, tabs, current_tab, height, tab
|
||||
local widget_width = text_width + 4 * ctx.style.button.padding.x
|
||||
nk.nk_layout_row_push(ctx, widget_width)
|
||||
if (current_tab == i) then
|
||||
-- /* active tab gets highlighted */
|
||||
local button_color = ctx.style.button.normal
|
||||
ctx.style.button.normal = ctx.style.button.active
|
||||
-- /* active tab gets highlighted */
|
||||
local col = ctx.style.button.normal.data.color
|
||||
local button_color = nk.nk_rgb(col.r, col.g, col.b)
|
||||
ctx.style.button.normal.data.color = nk.nk_rgb(col.r, col.g, col.b + 40)
|
||||
if (nk.nk_button_label(ctx, v.name) == true ) then current_tab = i end
|
||||
ctx.style.button.normal = button_color
|
||||
ctx.style.button.normal.data.color = button_color
|
||||
else
|
||||
if(nk.nk_button_label(ctx, v.name) == true) then current_tab = i end
|
||||
end
|
||||
|
||||
@ -28,6 +28,32 @@ end
|
||||
local sep = "\\"
|
||||
if(ffi.os ~= "Windows") then sep = "/" end
|
||||
|
||||
---------------------------------------------------------------------------------------
|
||||
|
||||
dirtools.get_drives = function()
|
||||
local cmd = "wmic logicaldisk get name"
|
||||
-- Note: Add more -t <filetype> to support different file system mounts
|
||||
if(ffi.os ~= "Windows") then cmd = "df -h -t ext4 --output=target" end
|
||||
|
||||
local drives = {}
|
||||
local fh = io.popen(cmd, "r")
|
||||
if(fh) then
|
||||
local data = fh:read("*a")
|
||||
local count = 0
|
||||
for f in string.gmatch(data, "(.-)\n") do
|
||||
f = string.gsub(f, "%s+", "")
|
||||
if(count > 0) then
|
||||
if(#f > 0) then
|
||||
tinsert(drives, f)
|
||||
end
|
||||
end
|
||||
count = count + 1
|
||||
end
|
||||
fh:close()
|
||||
end
|
||||
return drives
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------------------------
|
||||
-- Much safer way to build folder than pattern match (very unstable)
|
||||
dirtools.get_folder = function(path)
|
||||
@ -100,53 +126,34 @@ end
|
||||
|
||||
-- --------------------------------------------------------------------------------------
|
||||
|
||||
local dir_cmd = "dir /b"
|
||||
if(ffi.os ~= "Windows") then dir_cmd = "ls -1" end
|
||||
|
||||
local list_cache = {}
|
||||
|
||||
dirtools.get_dirlist = function(path, cache_update)
|
||||
|
||||
if(list_cache[path] and cache_update == nil) then return list_cache[path] end
|
||||
|
||||
local files = {}
|
||||
local res = ""
|
||||
-- Fill with temp file list of dir /b
|
||||
local fh = io.popen(dir_cmd.." "..path, "r")
|
||||
if(fh) then
|
||||
res = fh:read("*a")
|
||||
fh:close()
|
||||
else
|
||||
print("[Error] dirtools.get_dirlist bad path: "..tostring(path))
|
||||
return files
|
||||
end
|
||||
|
||||
for f in string.gmatch(res, "(.-)\n") do
|
||||
local newfile = { name = ffi.string(f), folder = dirtools.is_folder(path..sep..f) }
|
||||
newfile.select = ffi.new("int[1]")
|
||||
newfile.select[0] = 0
|
||||
table.insert(files, newfile)
|
||||
end
|
||||
|
||||
list_cache[path] = files
|
||||
return files
|
||||
end
|
||||
local allfolders_cmd = "dir /ON /AD /B %s"
|
||||
if(ffi.os ~= "Windows") then allfolders_cmd = "ls -p %s | grep /" end
|
||||
local allfiles_cmd = "dir /ON /A-D /B %s"
|
||||
if(ffi.os ~= "Windows") then allfiles_cmd = "ls -p %s | grep -v /" end
|
||||
|
||||
-- --------------------------------------------------------------------------------------
|
||||
|
||||
local folders_cmd = "dir /Ad /b"
|
||||
if(ffi.os ~= "Windows") then folders_cmd = "ls -1 -d */" end
|
||||
|
||||
local list_folders_cache = {}
|
||||
local list_cache = {}
|
||||
|
||||
dirtools.get_folderslist = function(path, cache_update)
|
||||
|
||||
if(list_folders_cache[path] and cache_update == nil) then return list_folders_cache[path] end
|
||||
-- Check path first. If its a drive on windows then no caching
|
||||
if(ffi.os == "Windows") then
|
||||
local colon = string.sub(path, 2,-1)
|
||||
if(colon == ":") then cache_update = true; path = path..sep end
|
||||
end
|
||||
|
||||
if(list_folders_cache[path] and cache_update == nil) then
|
||||
return list_folders_cache[path]
|
||||
end
|
||||
|
||||
local files = {}
|
||||
table.insert(files, 1, { name = ".." })
|
||||
|
||||
local res = ""
|
||||
-- Fill with temp file list of dir /b
|
||||
local fh = io.popen(folders_cmd.." "..path, "r")
|
||||
local fh = io.popen(string.format(allfolders_cmd, path), "r")
|
||||
if(fh) then
|
||||
res = fh:read("*a")
|
||||
fh:close()
|
||||
@ -156,7 +163,7 @@ dirtools.get_folderslist = function(path, cache_update)
|
||||
end
|
||||
|
||||
for f in string.gmatch(res, "(.-)\n") do
|
||||
local newfile = { name = ffi.string(f)}
|
||||
local newfile = { name = ffi.string(f), folder = true }
|
||||
newfile.select = ffi.new("int[1]")
|
||||
newfile.select[0] = 0
|
||||
table.insert(files, newfile)
|
||||
@ -166,6 +173,65 @@ dirtools.get_folderslist = function(path, cache_update)
|
||||
return files
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------------------------
|
||||
|
||||
dirtools.get_dirlist = function(path, cache_update)
|
||||
|
||||
-- Check path first. If its a drive on windows then no caching
|
||||
if(ffi.os == "Windows") then
|
||||
local colon = string.match(path, "(.)$")
|
||||
if(colon == ":") then path = path..sep end
|
||||
end
|
||||
|
||||
if(list_cache[path] and cache_update == nil) then
|
||||
return list_cache[path]
|
||||
end
|
||||
|
||||
-- Get all the folders first
|
||||
local files = dirtools.get_folderslist(path)
|
||||
|
||||
-- Add the files to the list.
|
||||
local res = ""
|
||||
-- Fill with temp file list of dir /b
|
||||
local fh = io.popen(string.format(allfiles_cmd, path), "r")
|
||||
if(fh) then
|
||||
res = fh:read("*a")
|
||||
fh:close()
|
||||
if(#res == 0) then
|
||||
print(path)
|
||||
list_cache[path] = files
|
||||
return files
|
||||
end
|
||||
else
|
||||
print("[Error] dirtools.get_dirlist bad path: "..tostring(path))
|
||||
return {}
|
||||
end
|
||||
|
||||
for f in string.gmatch(res, "(.-)\n") do
|
||||
local newfile = { name = ffi.string(f), folder = nil }
|
||||
newfile.select = ffi.new("int[1]")
|
||||
newfile.select[0] = 0
|
||||
table.insert(files, newfile)
|
||||
end
|
||||
|
||||
list_cache[path] = files
|
||||
return files
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------------------------
|
||||
dirtools.get_parent = function( path )
|
||||
if(path == nil or path == "") then path = "." end
|
||||
local parentpath = dirtools.get_folder(path)
|
||||
return parentpath
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------------------------
|
||||
dirtools.change_folder = function( path, child )
|
||||
|
||||
local newpath = path..sep..child
|
||||
return newpath
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------------------------
|
||||
-- By default the paths are added
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user