-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhistoryview.lua
71 lines (63 loc) · 1.67 KB
/
historyview.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local _ = require("gettext")
local History = require("history")
-- Maybe we should extend the history module?
local HistoryView = {
}
function HistoryView:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function HistoryView:getContinueButton(load_puzzle_cb)
local history = History:new{}
if #history:get() > 0 then
local history_item = history:get()[1]
return {
text = _(("Continue \"%s\""):format(history_item['puzzle_title'])),
callback = function()
load_puzzle_cb(history_item)
end
}
else
return nil
end
end
--[[--
Return a list that can be used to populate a plugin menu.
]]
function HistoryView:getMenuItems(load_puzzle_cb, clear_history_cb)
local menu_items = {}
local sub_menu_items = {}
-- If the user has started a puzzle, we'll add a new option to the menu.
local history = History:new{}
if #history:get() > 0 then
local history_list = {}
for i, item in ipairs(history:get()) do
table.insert(sub_menu_items, {
text = item['puzzle_title'],
callback = function()
load_puzzle_cb(item)
end
})
end
-- Add a clear history button
table.insert(sub_menu_items,
{
text = _("Clear history"),
keep_menu_open = false,
callback = function()
history:clear()
end
}
)
table.insert(menu_items, {
text = _("History"),
sub_item_table = sub_menu_items
})
return menu_items
else
return nil
end
end
return HistoryView