-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.lua
More file actions
117 lines (102 loc) · 3.81 KB
/
main.lua
File metadata and controls
117 lines (102 loc) · 3.81 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
-- Entry point for the Menu Disabler plugin. Initializes the plugin and loads all modules.
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local UIManager = require("ui/uimanager")
local InfoMessage = require("ui/widget/infomessage")
local _ = require("gettext")
require("ui/plugin/insert_menu").add("menu_disabler")
local MenuDisabler = WidgetContainer:extend{
is_doc_only = false,
settings_path = require("datastorage"):getSettingsDir(),
editing_cache = nil,
active_dialog = nil,
profiles_file = "menu_disabler_profiles.lua",
}
local modules_path = "user.plugins.menu_disabler.koplugin.modules."
local function load_module(name)
local path = debug.getinfo(1).source:match("@?(.*[\\/])")
local f = assert(loadfile(path .. "modules/" .. name .. ".lua"))
return f()
end
load_module("constants")(MenuDisabler)
load_module("backend")(MenuDisabler)
load_module("profiles")(MenuDisabler)
load_module("search")(MenuDisabler)
load_module("menus")(MenuDisabler)
function MenuDisabler:init()
self.ui.menu:registerToMainMenu(self)
end
function MenuDisabler:showDialog(dialog)
if self.active_dialog and self.active_dialog ~= dialog then
pcall(function() UIManager:close(self.active_dialog) end)
self.active_dialog = nil
end
local orig_close = dialog.close_callback
dialog.close_callback = function(...)
if type(orig_close) == "function" then pcall(orig_close, ...) end
if self.active_dialog == dialog then self.active_dialog = nil end
end
self.active_dialog = dialog
UIManager:show(dialog)
end
function MenuDisabler:closeDialogIfMatch(dialog)
if dialog and self.active_dialog == dialog then
UIManager:close(dialog)
self.active_dialog = nil
end
end
function MenuDisabler:addToMainMenu(menu_items)
local is_doc_open = self.ui.document ~= nil
menu_items.menu_disabler = {
text = _("Menu Disabler"),
sub_item_table = {
{
text = _("Customize File Manager Menus"),
callback = function() self:initSession("filemanager") end,
},
{
text = is_doc_open and _("Customize Reader Menus (Close book first)") or _("Customize Reader Menus"),
enabled = not is_doc_open,
callback = function()
if is_doc_open then
UIManager:show(InfoMessage:new{
text = _("To prevent instability, please close the current book before editing Reader menus."),
timeout = 4
})
else
self:initSession("reader")
end
end
},
{
text = is_doc_open and _("Profiles (Save/Load/Delete) (Close book first)") or _("Profiles (Save/Load/Delete)"),
enabled = not is_doc_open,
sub_item_table_func = function()
return self:getProfilesMenu()
end,
separator = true,
},
{
text = _("Apply File Manager Layout to Reader"),
callback = function() self:copySettings() end
},
{
text = _("Reset All Menus to Default"),
callback = function() self:confirmResetEverything() end
}
}
}
end
function MenuDisabler:initSession(menu_type)
if self.active_dialog then
pcall(function() UIManager:close(self.active_dialog) end)
self.active_dialog = nil
end
local filename = menu_type .. "_menu_order.lua"
self.editing_cache = {
type = menu_type,
filename = filename,
data = self:generateWorkingList(menu_type, filename)
}
self:showCategoryList()
end
return MenuDisabler