Fixed recents.

This commit is contained in:
David Lannan 2024-11-23 11:03:02 +10:30
parent e221bc4b03
commit 9013bde402
4 changed files with 29 additions and 10 deletions

View File

@ -1 +1 @@
["F:\\dev\\luajit\\Thunc\\sokol-luajit\\builds\\cube_sapp\\cube_sapp2.slp","F:\\dev\\luajit\\Thunc\\sokol-luajit\\builds\\cube_sapp\\cube_sapp.slp"]
["F:\\dev\\luajit\\Thunc\\sokol-luajit\\builds\\cube_sapp\\cube_sapp.slp","F:\\dev\\luajit\\Thunc\\sokol-luajit\\builds\\cube_sapp\\cube_sapp2.slp"]

View File

@ -105,13 +105,17 @@ settings.add_recents = function( filename )
if(settings.recents) then
-- Check it isnt already in the list, add to first and remove the other.
local removal = {}
local cleaned_recents = {}
for i, v in ipairs(settings.recents) do
if string.match(v, filename) then table.insert(removal, i) end
local testf = string.gsub(filename, "%-", "_")
local testv = string.gsub(v, "%-", "_")
if string.match(testf, testv) then
else
table.insert(cleaned_recents, v)
end
for i, v in ipairs(removal) do
table.remove(settings.recents, v)
end
settings.recents = cleaned_recents
table.insert(settings.recents, 1, filename)
end
end

View File

@ -38,13 +38,16 @@ file_selector.create_file_list = function( name, rect, recent_files )
if (nk.nk_group_begin(ctx, name, flags) == true) then
nk.nk_layout_row_dynamic(ctx, dim.h-90, 1)
nk.nk_layout_row_dynamic(ctx, dim.h-115, 1)
local bhit = wdgts.widget_list_buttons(ctx, "recent_file", nil, udata.recent_files, dim.w -40 )
if(bhit) then
udata.file_selected = bhit[2]
end
nk.nk_layout_row_dynamic(ctx, 25, 1)
nk.nk_label(ctx, string.format("Selected: %s",udata.file_selected), 1)
nk.nk_layout_row_dynamic(ctx, 25, 2)
if (nk.nk_button_label(ctx, "Cancel") == true) then
udata.popup_active = 0
@ -199,7 +202,7 @@ end
-- --------------------------------------------------------------------------------------
file_selector.show = function(select_obj)
file_selector.show = function(select_obj, callback)
select_obj.popup_active = 1
if(callback) then select_obj.callback = callback end

View File

@ -161,7 +161,10 @@ panel.init = function()
setup_config()
settings.load_recents()
recent_files = fsel.create_file_list("Choose Recent", dim2, {})
popup_wide = sapp.sapp_width()* 0.8
local dim3 = nk.nk_rect( sapp.sapp_width()/2-8 - popup_wide/2,
sapp.sapp_height()/2-40 - popup_high/2, popup_wide, popup_high)
recent_files = fsel.create_file_list("Choose Recent", dim3, {})
end
-- --------------------------------------------------------------------------------------
@ -333,6 +336,12 @@ panel.show_recents = function(ctx)
end
recent_files.recent_files = panel.recent_list
fsel.show(recent_files, function(udata, res)
if(res == true) then
panel.current_path = udata.file_selected
settings.load(udata.file_selected)
settings.add_recents(udata.file_selected)
print("Opened: "..udata.file_selected)
end
end)
end
@ -475,7 +484,10 @@ panel.input = function(event)
sapp.sapp_height()/2-40 - popup_high/2, popup_wide, popup_high)
file_select.popup_dim = dim2
recent_files.popup_dim = dim2
popup_wide = sapp.sapp_width()* 0.8
local dim3 = nk.nk_rect( sapp.sapp_width()/2-8 - popup_wide/2,
sapp.sapp_height()/2-40 - popup_high/2, popup_wide, popup_high)
recent_files.popup_dim = dim3
end
end