From 227584de220602d2d4618e2f78aa12ba836dc930 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 1 Jan 2018 16:31:39 +0100 Subject: [PATCH] New option - create new directory (#3555) --- frontend/apps/filemanager/filemanager.lua | 158 +++++++++++++++++++--- frontend/ui/widget/iconbutton.lua | 4 - resources/icons/appbar.plus.png | Bin 0 -> 199 bytes 3 files changed, 137 insertions(+), 25 deletions(-) create mode 100644 resources/icons/appbar.plus.png diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index 2811b1822..985fa0d2d 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -1,4 +1,5 @@ local Blitbuffer = require("ffi/blitbuffer") +local Button = require("ui/widget/button") local ButtonDialogTitle = require("ui/widget/buttondialogtitle") local CenterContainer = require("ui/widget/container/centercontainer") local Device = require("device") @@ -12,11 +13,11 @@ local FileManagerHistory = require("apps/filemanager/filemanagerhistory") local FileManagerMenu = require("apps/filemanager/filemanagermenu") local Font = require("ui/font") local FrameContainer = require("ui/widget/container/framecontainer") +local HorizontalGroup = require("ui/widget/horizontalgroup") local IconButton = require("ui/widget/iconbutton") local InfoMessage = require("ui/widget/infomessage") local InputContainer = require("ui/widget/container/inputcontainer") local InputDialog = require("ui/widget/inputdialog") -local OverlapGroup = require("ui/widget/overlapgroup") local PluginLoader = require("pluginloader") local ReaderDictionary = require("apps/reader/modules/readerdictionary") local ReaderUI = require("apps/reader/readerui") @@ -34,6 +35,7 @@ local logger = require("logger") local util = require("ffi/util") local _ = require("gettext") local Screen = Device.screen +local T = require("ffi/util").template local function restoreScreenMode() local screen_mode = G_reader_settings:readSetting("fm_screen_mode") @@ -63,23 +65,37 @@ local FileManager = InputContainer:extend{ mv_bin = Device:isAndroid() and "/system/bin/mv" or "/bin/mv", cp_bin = Device:isAndroid() and "/system/bin/cp" or "/bin/cp", - rm_bin = Device:isAndroid() and "/system/bin/rm" or "/bin/rm", + mkdir_bin = Device:isAndroid() and "/system/bin/mkdir" or "/bin/mkdir", } function FileManager:init() self.show_parent = self.show_parent or self - + local icon_size = Screen:scaleBySize(35) local home_button = IconButton:new{ icon_file = "resources/icons/appbar.home.png", - width = Screen:scaleBySize(35), - height = Screen:scaleBySize(35), + scale_for_dpi = false, + width = icon_size, + height = icon_size, padding = Size.padding.default, - padding_top = Size.padding.small, - padding_left = Size.padding.small, + padding_left = Size.padding.large, + padding_right = Size.padding.large, + padding_bottom = 0, callback = function() self:goHome() end, hold_callback = function() self:setHome() end, } + local plus_button = IconButton:new{ + icon_file = "resources/icons/appbar.plus.png", + scale_for_dpi = false, + width = icon_size, + height = icon_size, + padding = Size.padding.default, + padding_left = Size.padding.large, + padding_right = Size.padding.large, + padding_bottom = 0, + callback = function() self:tapPlus() end, + } + self.path_text = TextWidget:new{ face = Font:getFace("xx_smallinfofont"), text = truncatePath(filemanagerutil.abbreviate(self.root_path)), @@ -88,22 +104,31 @@ function FileManager:init() self.banner = FrameContainer:new{ padding = 0, bordersize = 0, - VerticalGroup:new{ - OverlapGroup:new{ - home_button, - VerticalGroup:new{ - TextWidget:new{ - face = Font:getFace("smalltfont"), - text = self.title, - }, - CenterContainer:new{ - dimen = { w = Screen:getWidth(), h = nil }, - self.path_text, + VerticalGroup:new { + CenterContainer:new { + dimen = { w = Screen:getWidth(), h = nil }, + HorizontalGroup:new { + home_button, + VerticalGroup:new { + Button:new { + bordersize = 0, + padding = 0, + text_font_bold = false, + text_font_face = "smalltfont", + text_font_size = 24, + text = self.title, + width = Screen:getWidth() - 2 * icon_size - 4 * Size.padding.large, + }, }, - }, + plus_button, + } }, - VerticalSpan:new{ width = Screen:scaleBySize(10) }, - }, + CenterContainer:new{ + dimen = { w = Screen:getWidth(), h = nil }, + self.path_text, + }, + VerticalSpan:new{ width = Screen:scaleBySize(5) }, + } } local g_show_hidden = G_reader_settings:readSetting("show_hidden") @@ -335,6 +360,81 @@ function FileManager:init() self:handleEvent(Event:new("SetDimensions", self.dimen)) end +function FileManager:tapPlus() + local buttons = { + { + { + text = _("New folder"), + callback = function() + UIManager:close(self.file_dialog) + self.input_dialog = InputDialog:new{ + title = _("Create new folder"), + input_type = "text", + buttons = { + { + { + text = _("Cancel"), + callback = function() + self:closeInputDialog() + end, + }, + { + text = _("Create"), + callback = function() + self:closeInputDialog() + local new_folder = self.input_dialog:getInputText() + if new_folder and new_folder ~= "" then + self:createFolder(self.file_chooser.path, new_folder) + end + end, + }, + } + }, + } + self.input_dialog:onShowKeyboard() + UIManager:show(self.input_dialog) + end, + }, + }, + { + { + text = _("Paste"), + enabled = self.clipboard and true or false, + callback = function() + self:pasteHere(self.file_chooser.path) + self:onRefresh() + UIManager:close(self.file_dialog) + end, + }, + }, + { + { + text = _("Set as HOME directory"), + callback = function() + self:setHome(self.file_chooser.path) + UIManager:close(self.file_dialog) + end + } + }, + { + { + text = _("Go to HOME directory"), + callback = function() + self:goHome() + UIManager:close(self.file_dialog) + end + } + } + } + + self.file_dialog = ButtonDialogTitle:new{ + title = filemanagerutil.abbreviate(self.file_chooser.path), + title_align = "center", + buttons = buttons, + } + UIManager:show(self.file_dialog) +end + function FileManager:reinit(path, focused_file) self.dimen = Screen:getSize() -- backup the root path and path items @@ -437,6 +537,22 @@ function FileManager:pasteHere(file) end end +function FileManager:createFolder(curr_folder, new_folder) + local folder = curr_folder .. "/" .. new_folder + local code = util.execute(self.mkdir_bin, folder) + local text + if code == 0 then + self:onRefresh() + text = T(_("Folder created:\n %1"), new_folder) + else + text = _("The folder has not been created") + end + UIManager:show(InfoMessage:new{ + text = text, + timeout = 2, + }) +end + function FileManager:deleteFile(file) local ok, err local file_abs_path = util.realpath(file) diff --git a/frontend/ui/widget/iconbutton.lua b/frontend/ui/widget/iconbutton.lua index 662bfd8e1..8558ad95c 100644 --- a/frontend/ui/widget/iconbutton.lua +++ b/frontend/ui/widget/iconbutton.lua @@ -124,8 +124,4 @@ function IconButton:onHoldIconButton() return true end -function IconButton:onSetDimensions(new_dimen) - self.dimen = new_dimen -end - return IconButton diff --git a/resources/icons/appbar.plus.png b/resources/icons/appbar.plus.png new file mode 100644 index 0000000000000000000000000000000000000000..61dcfcb37770e1f518414461190e7e6fe6eb0cb8 GIT binary patch literal 199 zcmeAS@N?(olHy`uVBq!ia0vp^4j{|{BpCXc^q7DYQ24u5xkb)wvbNE#4E7A`N>ARki&0`=IMCkt#BgF1Pvx4l`ldUcCUJ}pN)LRt n+?`jk%or$}c;JsTqe`gC3C>1l-zi6db})Fl`njxgN@xNAD&9MQ literal 0 HcmV?d00001