3
0
mirror of https://github.com/britzl/monarch.git synced 2025-11-26 19:00:53 +01:00

Compare commits

..

4 Commits
3.2.0 ... 3.2.2

Author SHA1 Message Date
Brian
03baa3eeb3 Only allow editor script to target .gui (#67)
* Only allow editor script to target .gui

Disable .collection and .gui_script

* whitespace
2020-11-23 08:32:12 +01:00
Marius Petcu
00808c0d56 Implement better behaviour for replace() on popups (#64) 2020-05-28 17:18:51 +02:00
Björn Ritzl
4989939817 Always print errors. Do not rely on monarch debugging 2020-05-28 08:20:43 +02:00
Björn Ritzl
bf880b80fd Print errors if caught in the callback tracker 2020-05-28 08:08:35 +02:00
4 changed files with 93 additions and 39 deletions

View File

@@ -68,7 +68,7 @@ function M.get_commands()
}, },
active = function(opts) active = function(opts)
local path = editor.get(opts.selection, "path") local path = editor.get(opts.selection, "path")
return ends_with(path, ".gui") or ends_with(path, ".collection") or ends_with(path, ".gui_script") return ends_with(path, ".gui")
end, end,
run = function(opts) run = function(opts)
create_files(opts.selection) create_files(opts.selection)

View File

@@ -93,7 +93,7 @@ end
local queue = {} local queue = {}
local function queue_error(message) local function queue_error(message)
log(message) print(message)
log("queue() error - clearing queue") log("queue() error - clearing queue")
while next(queue) do while next(queue) do
table.remove(queue) table.remove(queue)
@@ -686,32 +686,42 @@ function M.show(id, options, data, cb)
local top = stack[#stack] local top = stack[#stack]
-- a screen can ignore the stack by setting the no_stack to true -- a screen can ignore the stack by setting the no_stack to true
local add_to_stack = not options or not options.no_stack local add_to_stack = not options or not options.no_stack
if add_to_stack then if add_to_stack and top then
-- manipulate the current top -- manipulate the current top
-- close popup(s) if needed -- close popup(s) if needed
-- transition out -- transition out
if top then local pop = options and options.pop or 0
local is_not_popup = not screen.popup
local pop_all_popups = is_not_popup -- pop all popups when transitioning screens
-- keep top popup visible if new screen can be shown on top of a popup -- keep top popup visible if new screen can be shown on top of a popup
if top.popup and screen.popup_on_popup then if top.popup and screen.popup and screen.popup_on_popup then
disable(top, screen) disable(top, screen)
else else
-- close all popups, one by one pop_all_popups = true
while top.popup do end
-- close popups, one by one, either all of them or the number specified by options.pop
while top and top.popup do
if not pop_all_popups then
if pop <= 0 then break end
pop = pop - 1
end
stack[#stack] = nil stack[#stack] = nil
show_out(top, screen, callbacks.track()) show_out(top, screen, callbacks.track())
callbacks.yield_until_done() callbacks.yield_until_done()
top = stack[#stack] top = stack[#stack]
end end
-- unload and transition out from top
-- unload the previous screen and transition out from top
-- wait until we are done if showing the same screen as is already visible -- wait until we are done if showing the same screen as is already visible
if top and not top.popup then
local same_screen = top and top.id == screen.id local same_screen = top and top.id == screen.id
show_out(top, screen, callbacks.track()) show_out(top, screen, callbacks.track())
if same_screen or (options and options.sequential) then if same_screen or (options and options.sequential) then
callbacks.yield_until_done() callbacks.yield_until_done()
end end
end end
end
end
-- if the screen we want to show is in the stack -- if the screen we want to show is in the stack
-- already and the clear flag is set then we need -- already and the clear flag is set then we need
@@ -724,13 +734,15 @@ function M.show(id, options, data, cb)
end end
end end
if options and options.pop then -- pop screens off the stack
for i = 1, options.pop do if is_not_popup then
for i = 1, pop do
local stack_top = #stack local stack_top = #stack
if stack_top < 1 then break end if stack_top < 1 then break end
stack[stack_top] = nil stack[stack_top] = nil
end end
end end
end
-- show screen, wait until preloaded if it is already preloading -- show screen, wait until preloaded if it is already preloading
-- this can typpically happen if you do a show() on app start for a -- this can typpically happen if you do a show() on app start for a

View File

@@ -44,7 +44,10 @@ function M.create()
function instance.yield_until_done() function instance.yield_until_done()
local co = coroutine.running() local co = coroutine.running()
callback = function() callback = function()
coroutine.resume(co) local ok, err = coroutine.resume(co)
if not ok then
print(err)
end
end end
invoke_if_done() invoke_if_done()
if not is_done() then if not is_done() then

View File

@@ -329,10 +329,49 @@ return function()
assert(wait_until_shown(POPUP2), "Popup2 was never shown") assert(wait_until_shown(POPUP2), "Popup2 was never shown")
assert_stack({ SCREEN1, POPUP1, POPUP2 }) assert_stack({ SCREEN1, POPUP1, POPUP2 })
monarch.replace(SCREEN2) monarch.replace(SCREEN2)
assert(wait_until_shown(SCREEN2), "Popup2 was never shown") assert(wait_until_shown(SCREEN2), "Screen2 was never shown")
assert_stack({ SCREEN2 }) assert_stack({ SCREEN2 })
end) end)
it("should replace a popup", function()
monarch.show(SCREEN1)
assert(wait_until_shown(SCREEN1), "Screen1 was never shown")
assert_stack({ SCREEN1 })
monarch.show(POPUP1)
assert(wait_until_shown(POPUP1), "Popup1 was never shown")
assert_stack({ SCREEN1, POPUP1 })
monarch.replace(POPUP2)
assert(wait_until_shown(POPUP2), "Popup2 was never shown")
assert_stack({ SCREEN1, POPUP2 })
end)
it("should replace a pop-up two levels down", function()
monarch.show(SCREEN1)
assert(wait_until_shown(SCREEN1), "Screen1 was never shown")
assert_stack({ SCREEN1 })
monarch.show(POPUP1)
assert(wait_until_shown(POPUP1), "Popup1 was never shown")
assert_stack({ SCREEN1, POPUP1 })
monarch.show(POPUP2)
assert(wait_until_shown(POPUP2), "Popup2 was never shown")
assert_stack({ SCREEN1, POPUP1, POPUP2 })
monarch.show(POPUP2, { pop = 2 })
assert(wait_until_shown(POPUP2), "Popup2 was never shown")
assert_stack({ SCREEN1, POPUP2 })
end)
it("shouldn't over-pop popups", function()
monarch.show(SCREEN1)
assert(wait_until_shown(SCREEN1), "Screen1 was never shown")
assert_stack({ SCREEN1 })
monarch.show(POPUP1)
assert(wait_until_shown(POPUP1), "Popup1 was never shown")
assert_stack({ SCREEN1, POPUP1 })
monarch.show(POPUP2, { pop = 10 })
assert(wait_until_shown(POPUP2), "Popup2 was never shown")
assert_stack({ SCREEN1, POPUP2 })
end)
it("should be able to get the id of the screen at the top and bottom of the stack", function() it("should be able to get the id of the screen at the top and bottom of the stack", function()
assert(monarch.top() == nil) assert(monarch.top() == nil)
assert(monarch.bottom() == nil) assert(monarch.bottom() == nil)