PathChooser: add creating folder (#9354)

reviewable/pr9382/r1
hius07 2 years ago committed by GitHub
parent bff1e8deb7
commit 460d42293a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -604,7 +604,6 @@ function CloudStorage:uploadFile(url)
local path_chooser local path_chooser
path_chooser = PathChooser:new{ path_chooser = PathChooser:new{
select_directory = false, select_directory = false,
detailed_file_info = true,
path = self.last_path, path = self.last_path,
onConfirm = function(file_path) onConfirm = function(file_path)
self.last_path = file_path:match("(.*)/") self.last_path = file_path:match("(.*)/")

@ -286,7 +286,6 @@ function Screensaver:chooseFile(document_cover)
local PathChooser = require("ui/widget/pathchooser") local PathChooser = require("ui/widget/pathchooser")
local path_chooser = PathChooser:new{ local path_chooser = PathChooser:new{
select_directory = false, select_directory = false,
select_file = true,
file_filter = function(filename) file_filter = function(filename)
local suffix = util.getFileNameSuffix(filename) local suffix = util.getFileNameSuffix(filename)
if document_cover and DocumentRegistry:hasProvider(filename) then if document_cover and DocumentRegistry:hasProvider(filename) then
@ -295,7 +294,6 @@ function Screensaver:chooseFile(document_cover)
return true return true
end end
end, end,
detailed_file_info = true,
path = self.root_path, path = self.root_path,
onConfirm = function(file_path) onConfirm = function(file_path)
if document_cover then if document_cover then

@ -1,4 +1,5 @@
local BD = require("ui/bidi") local BD = require("ui/bidi")
local ButtonDialog = require("ui/widget/buttondialog")
local ButtonDialogTitle = require("ui/widget/buttondialogtitle") local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
local Device = require("device") local Device = require("device")
local Event = require("ui/event") local Event = require("ui/event")
@ -20,9 +21,9 @@ local PathChooser = FileChooser:extend{
is_borderless = true, is_borderless = true,
select_directory = true, -- allow selecting directories select_directory = true, -- allow selecting directories
select_file = true, -- allow selecting files select_file = true, -- allow selecting files
show_files = true, -- show files, even if select_files=false show_files = true, -- show files, even if select_file=false
-- (directories are always shown, to allow navigation) -- (directories are always shown, to allow navigation)
detailed_file_info = false, -- show size and last mod time in Select message detailed_file_info = true, -- show size and last mod time in Select message (if select_file=true only)
} }
function PathChooser:init() function PathChooser:init()
@ -48,7 +49,7 @@ function PathChooser:init()
self:goHome() self:goHome()
end end
self.onLeftButtonHold = function() self.onLeftButtonHold = function()
UIManager:broadcastEvent(Event:new("ShowFolderShortcutsDialog", function(path) self:changeToPath(path) end)) self:showPlusMenu()
end end
FileChooser.init(self) FileChooser.init(self)
end end
@ -153,4 +154,34 @@ function PathChooser:onMenuHold(item)
return true return true
end end
function PathChooser:showPlusMenu()
local button_dialog
button_dialog = ButtonDialog:new{
buttons = {
{
{
text = _("Folder shortcuts"),
callback = function()
UIManager:close(button_dialog)
UIManager:broadcastEvent(Event:new("ShowFolderShortcutsDialog",
function(path) self:changeToPath(path) end))
end,
},
},
{
{
text = _("New folder"),
callback = function()
UIManager:close(button_dialog)
local FileManager = require("apps/filemanager/filemanager")
FileManager.file_chooser = self
FileManager:createFolder()
end,
},
},
},
}
UIManager:show(button_dialog)
end
return PathChooser return PathChooser

@ -92,9 +92,6 @@ function BookShortcuts:getSubMenuItems()
keep_menu_open = true, keep_menu_open = true,
callback = function(touchmenu_instance) callback = function(touchmenu_instance)
local path_chooser = PathChooser:new{ local path_chooser = PathChooser:new{
select_file = true,
select_directory = true,
detailed_file_info = true,
path = G_reader_settings:readSetting("home_dir"), path = G_reader_settings:readSetting("home_dir"),
onConfirm = function(path) onConfirm = function(path)
self:addShortcut(path) self:addShortcut(path)

@ -339,7 +339,6 @@ Do you want to proceed?]]),
cancel_text = _("No"), cancel_text = _("No"),
ok_callback = function() ok_callback = function()
local path_chooser = PathChooser:new{ local path_chooser = PathChooser:new{
select_directory = true,
select_file = false, select_file = false,
path = self.last_path, path = self.last_path,
onConfirm = function(dir_path) onConfirm = function(dir_path)
@ -380,9 +379,7 @@ end
function TextEditor:chooseFile() function TextEditor:chooseFile()
self:loadSettings() self:loadSettings()
local path_chooser = PathChooser:new{ local path_chooser = PathChooser:new{
select_file = true,
select_directory = false, select_directory = false,
detailed_file_info = true,
path = self.last_path, path = self.last_path,
onConfirm = function(file_path) onConfirm = function(file_path)
-- Remember last_path only when we select a file from it -- Remember last_path only when we select a file from it

Loading…
Cancel
Save