1
1
local ConfirmBox = require (" ui/widget/confirmbox" )
2
2
local DataStorage = require (" datastorage" )
3
3
local Dispatcher = require (" dispatcher" )
4
- local FFIUtil = require (" ffi/util" )
5
4
local LuaSettings = require (" luasettings" )
6
5
local PathChooser = require (" ui/widget/pathchooser" )
7
6
local ReadHistory = require (" readhistory" )
8
7
local UIManager = require (" ui/uimanager" )
9
8
local WidgetContainer = require (" ui/widget/container/widgetcontainer" )
9
+ local ffiUtil = require (" ffi/util" )
10
10
local lfs = require (" libs/libkoreader-lfs" )
11
- local util = require (" util" )
12
11
local _ = require (" gettext" )
13
- local T = FFIUtil .template
12
+ local C_ = _ .pgettext
13
+ local T = ffiUtil .template
14
14
15
15
local BookShortcuts = WidgetContainer :extend {
16
16
name = " bookshortcuts" ,
@@ -20,32 +20,25 @@ local BookShortcuts = WidgetContainer:extend{
20
20
21
21
function BookShortcuts :onDispatcherRegisterActions ()
22
22
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 )
29
26
Dispatcher :registerAction (k , {category = " none" , event = " BookShortcut" , title = title , general = true , arg = k ,})
30
27
end
31
28
end
32
29
end
33
30
34
31
function BookShortcuts :onBookShortcut (path )
35
- if util .pathExists (path ) then
32
+ local mode = lfs .attributes (path , " mode" )
33
+ if mode then
36
34
local file
37
- if lfs . attributes ( path , " mode" ) ~= " file" then
35
+ if mode ~= " file" then
38
36
if G_reader_settings :readSetting (" BookShortcuts_directory_action" ) == " FM" then
39
37
if self .ui .file_chooser then
40
38
self .ui .file_chooser :changeToPath (path )
41
39
else -- called from Reader
42
40
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 )
49
42
end
50
43
else
51
44
file = ReadHistory :getFileByDirectory (path , G_reader_settings :isTrue (" BookShortcuts_recursive_directory" ))
@@ -54,8 +47,8 @@ function BookShortcuts:onBookShortcut(path)
54
47
file = path
55
48
end
56
49
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 )
59
52
end
60
53
end
61
54
end
@@ -104,37 +97,42 @@ function BookShortcuts:getSubMenuItems()
104
97
end ,
105
98
},
106
99
{
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 ,
108
102
keep_menu_open = true ,
109
103
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
+ },
110
110
{
111
111
text = last_text ,
112
+ radio = true ,
112
113
checked_func = function () return G_reader_settings :readSetting (" BookShortcuts_directory_action" ) == " Last" end ,
113
114
callback = function () G_reader_settings :saveSetting (" BookShortcuts_directory_action" , " Last" ) end ,
114
115
},
115
116
{
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 ,
119
121
},
120
122
},
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 ,
128
123
separator = true ,
129
- }
124
+ },
130
125
}
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
132
130
table.insert (sub_item_table , {
133
- text = k ,
131
+ text = icon .. text ,
134
132
callback = function () self :onBookShortcut (k ) end ,
135
133
hold_callback = function (touchmenu_instance )
136
134
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 " ,
138
136
ok_text = _ (" Delete" ),
139
137
ok_callback = function ()
140
138
self :deleteShortcut (k )
158
156
function BookShortcuts :deleteShortcut (name )
159
157
self .shortcuts .data [name ] = nil
160
158
Dispatcher :removeAction (name )
159
+ if self .ui .profiles then
160
+ self .ui .profiles :updateProfiles (name )
161
+ end
161
162
self .updated = true
162
163
end
163
164
0 commit comments