Skip to content

Commit cda2dca

Browse files
authored
BookShortcuts: open file with associated provider (koreader#13106)
1 parent 42de1fb commit cda2dca

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

plugins/bookshortcuts.koplugin/main.lua

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
local ConfirmBox = require("ui/widget/confirmbox")
22
local DataStorage = require("datastorage")
33
local Dispatcher = require("dispatcher")
4-
local FFIUtil = require("ffi/util")
54
local LuaSettings = require("luasettings")
65
local PathChooser = require("ui/widget/pathchooser")
76
local ReadHistory = require("readhistory")
87
local UIManager = require("ui/uimanager")
98
local WidgetContainer = require("ui/widget/container/widgetcontainer")
9+
local ffiUtil = require("ffi/util")
1010
local lfs = require("libs/libkoreader-lfs")
11-
local util = require("util")
1211
local _ = require("gettext")
13-
local T = FFIUtil.template
12+
local C_ = _.pgettext
13+
local T = ffiUtil.template
1414

1515
local BookShortcuts = WidgetContainer:extend{
1616
name = "bookshortcuts",
@@ -20,32 +20,25 @@ local BookShortcuts = WidgetContainer:extend{
2020

2121
function BookShortcuts:onDispatcherRegisterActions()
2222
for k,v in pairs(self.shortcuts.data) do
23-
if util.pathExists(k) then
24-
local title = k
25-
if lfs.attributes(k, "mode") == "file" then
26-
local directory, filename = util.splitFilePathName(k) -- luacheck: no unused
27-
title = filename
28-
end
23+
local mode = lfs.attributes(k, "mode")
24+
if mode then
25+
local title = T(C_("File", "Open %1"), mode == "file" and k:gsub(".*/", "") or k)
2926
Dispatcher:registerAction(k, {category="none", event="BookShortcut", title=title, general=true, arg=k,})
3027
end
3128
end
3229
end
3330

3431
function BookShortcuts:onBookShortcut(path)
35-
if util.pathExists(path) then
32+
local mode = lfs.attributes(path, "mode")
33+
if mode then
3634
local file
37-
if lfs.attributes(path, "mode") ~= "file" then
35+
if mode ~= "file" then
3836
if G_reader_settings:readSetting("BookShortcuts_directory_action") == "FM" then
3937
if self.ui.file_chooser then
4038
self.ui.file_chooser:changeToPath(path)
4139
else -- called from Reader
4240
self.ui:onClose()
43-
local FileManager = require("apps/filemanager/filemanager")
44-
if FileManager.instance then
45-
FileManager.instance:reinit(path)
46-
else
47-
FileManager:showFiles(path)
48-
end
41+
self.ui:showFileManager(path)
4942
end
5043
else
5144
file = ReadHistory:getFileByDirectory(path, G_reader_settings:isTrue("BookShortcuts_recursive_directory"))
@@ -54,8 +47,8 @@ function BookShortcuts:onBookShortcut(path)
5447
file = path
5548
end
5649
if file then
57-
local ReaderUI = require("apps/reader/readerui")
58-
ReaderUI:showReader(file)
50+
local FileManager = require("apps/filemanager/filemanager")
51+
FileManager.openFile(self.ui, file)
5952
end
6053
end
6154
end
@@ -104,37 +97,42 @@ function BookShortcuts:getSubMenuItems()
10497
end,
10598
},
10699
{
107-
text_func = function() return T(_("Folder action: %1"), G_reader_settings:readSetting("BookShortcuts_directory_action", "FM") == "FM" and FM_text or last_text) end,
100+
text_func = function() return T(_("Folder action: %1"),
101+
G_reader_settings:readSetting("BookShortcuts_directory_action", "FM") == "FM" and FM_text or last_text) end,
108102
keep_menu_open = true,
109103
sub_item_table = {
104+
{
105+
text = FM_text,
106+
radio = true,
107+
checked_func = function() return G_reader_settings:readSetting("BookShortcuts_directory_action") == "FM" end,
108+
callback = function() G_reader_settings:saveSetting("BookShortcuts_directory_action", "FM") end,
109+
},
110110
{
111111
text = last_text,
112+
radio = true,
112113
checked_func = function() return G_reader_settings:readSetting("BookShortcuts_directory_action") == "Last" end,
113114
callback = function() G_reader_settings:saveSetting("BookShortcuts_directory_action", "Last") end,
114115
},
115116
{
116-
text = FM_text,
117-
checked_func = function() return G_reader_settings:readSetting("BookShortcuts_directory_action") == "FM" end,
118-
callback = function() G_reader_settings:saveSetting("BookShortcuts_directory_action", "FM") end,
117+
text = _("Recursively search folders"),
118+
enabled_func = function() return G_reader_settings:readSetting("BookShortcuts_directory_action") == "Last" end,
119+
checked_func = function() return G_reader_settings:isTrue("BookShortcuts_recursive_directory") end,
120+
callback = function() G_reader_settings:flipNilOrFalse("BookShortcuts_recursive_directory") end,
119121
},
120122
},
121-
},
122-
{
123-
text = _("Recursively search folders"),
124-
keep_menu_open = true,
125-
checked_func = function() return G_reader_settings:isTrue("BookShortcuts_recursive_directory") end,
126-
enabled_func = function() return G_reader_settings:readSetting("BookShortcuts_directory_action") == "Last" end,
127-
callback = function() G_reader_settings:flipNilOrFalse("BookShortcuts_recursive_directory") end,
128123
separator = true,
129-
}
124+
},
130125
}
131-
for k,v in FFIUtil.orderedPairs(self.shortcuts.data) do
126+
for k in ffiUtil.orderedPairs(self.shortcuts.data) do
127+
local mode = lfs.attributes(k, "mode")
128+
local icon = mode and (mode == "file" and "\u{F016} " or "\u{F114} ") or "\u{F48E} "
129+
local text = mode == "file" and k:gsub(".*/", "") or k
132130
table.insert(sub_item_table, {
133-
text = k,
131+
text = icon .. text,
134132
callback = function() self:onBookShortcut(k) end,
135133
hold_callback = function(touchmenu_instance)
136134
UIManager:show(ConfirmBox:new{
137-
text = _("Do you want to delete this shortcut?"),
135+
text = _("Do you want to delete this shortcut?") .. "\n\n" .. k .. "\n",
138136
ok_text = _("Delete"),
139137
ok_callback = function()
140138
self:deleteShortcut(k)
@@ -158,6 +156,9 @@ end
158156
function BookShortcuts:deleteShortcut(name)
159157
self.shortcuts.data[name] = nil
160158
Dispatcher:removeAction(name)
159+
if self.ui.profiles then
160+
self.ui.profiles:updateProfiles(name)
161+
end
161162
self.updated = true
162163
end
163164

0 commit comments

Comments
 (0)