diff --git a/commands.lua b/commands.lua index 2b793092e..4957552be 100644 --- a/commands.lua +++ b/commands.lua @@ -222,5 +222,12 @@ function Commands:new(obj) G_charging_mode = false end ) + -- Shift+P would be overwritten in inputbox by entering char 'P' + -- I suggest one should probably change the hotkey to, say, Alt+Space + obj:add(KEY_P, MOD_SHIFT, "P", "make screenshot", + function() + Screen:screenshot() + end + ) return obj end diff --git a/dialog.lua b/dialog.lua index 4c3f0b1e9..632b9b146 100644 --- a/dialog.lua +++ b/dialog.lua @@ -2,7 +2,6 @@ require "widget" require "font" InfoMessage = { - face = Font:getFace("infofont", 25) } function InfoMessage:show(text,refresh_mode) @@ -22,7 +21,7 @@ function InfoMessage:show(text,refresh_mode) }), TextWidget:new({ text = text, - face = Font:getFace("cfont", 30) + face = Font:getFace("infofont", 30) }) }) }) diff --git a/extentions.lua b/extentions.lua index 073d64324..64b393be4 100644 --- a/extentions.lua +++ b/extentions.lua @@ -3,20 +3,24 @@ ext = { djvuRead = ";djvu;", pdfRead = ";pdf;xps;cbz;", - --creRead = ";epub;txt;rtf;htm;html;mobi;prc;azw;fb2;chm;pdb;doc;tcr;zip;" + creRead = ";epub;txt;rtf;htm;html;mobi;prc;azw;fb2;chm;pdb;doc;tcr;zip;" -- seems to accept pdb-files for PalmDoc only } + function ext:getReader(ftype) local s = ";" if ftype == "" then return nil - elseif string.find(self.djvuRead,s..ftype..s) then - return DJVUReader elseif string.find(self.pdfRead,s..ftype..s) then return PDFReader - else + elseif string.find(self.djvuRead,s..ftype..s) then + return DJVUReader + elseif FileChooser.filemanager_expert_mode > FileChooser.BEGINNERS_MODE + or string.find(self.creRead,s..ftype..s) then return CREReader + else + return nil end end diff --git a/filechooser.lua b/filechooser.lua index 9416b0ffb..d0455b3c6 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -11,14 +11,10 @@ require "dialog" require "extentions" FileChooser = { - -- title height - title_H = 40, - -- spacing between lines - spacing = 36, - -- foot height - foot_H = 28, - -- horisontal margin - margin_H = 10, + title_H = 40, -- title height + spacing = 36, -- spacing between lines + foot_H = 28, -- foot height + margin_H = 10, -- horisontal margin -- state buffer dirs = nil, @@ -29,11 +25,20 @@ FileChooser = { current = 1, oldcurrent = 0, exception_message = nil, - -- NuPogodi, 20.05.12: added new parameters to make helppage available + pagedirty = true, markerdirty = false, perpage, clipboard = lfs.currentdir() .. "/clipboard", -- NO finishing slash + + -- NuPogodi, 04.09.2012: introduced modes that configures the filechoser + -- for users with various purposes & skills + filemanager_expert_mode, -- default value is defined in reader.lua + -- the definitions + BEGINNERS_MODE = 1, -- the filemanager content is restricted by files with reader-related extentions; safe renaming (no extention) + ADVANCED_MODE = 2, -- no extention-based filtering; renaming with extentions; appreciable danger to crash crengine by improper docs + ROOT_MODE = 3, -- TODO: all functions (including non-stable and dangerous) + } function getProperTitleLength(txt,font_face,max_width) @@ -52,7 +57,7 @@ end function BatteryLevel() local fn, battery = "/tmp/kindle-battery-info", "?" -- NuPogodi, 18.05.12: This command seems to work even without Amazon Kindle framework - os.execute("(gasgauge-info ".."-s) ".."> "..fn) + os.execute("gasgauge-info -s > "..fn) if io.open(fn,"r") then for lines in io.lines(fn) do battery = " " .. lines end else @@ -62,10 +67,9 @@ function BatteryLevel() end function DrawTitle(text,lmargin,y,height,color,font_face) - -- radius for round corners - local r = 6 - -- redefine to ignore the input for background color - color = 3 + local r = 6 -- radius for round corners + color = 3 -- redefine to ignore the input for background color + fb.bb:paintRect(1, 1, fb.bb:getWidth() - 2, height - r, color) blitbuffer.paintBorder(fb.bb, 1, height/2, fb.bb:getWidth() - 2, height/2, height/2, color, r) -- to have a horisontal gap between text & background rectangle @@ -115,7 +119,6 @@ function DrawFileItem(name,x,y,image) end iw:free() end --- end of old NuPogodi's functions function getAbsolutePath(aPath) local abs_path @@ -178,9 +181,6 @@ function FileChooser:setPath(newPath) end end --- NuPogodi, 20.05.12: FileChooser:choose is totally rewritten --- to make helppage with hotkeys available for users - function FileChooser:choose(ypos, height) self.perpage = math.floor(height / self.spacing) - 2 self.pagedirty = true @@ -395,17 +395,25 @@ function FileChooser:addAllCommands() end -- if folder == ".." end -- function ) --- NuPogodi, 24.05.12: Added function to rename documents (extention comes from the old file) --- Tigran, 18/08/12: corrected the rename operation to include extension. + -- make renaming flexible: it either keeps old extention (BEGINNERS_MODE) or + -- allows to rename the whole filename including the extention self.commands:add(KEY_R, MOD_SHIFT, "R", "rename file", function(self) local oldname = self:FullFileName() if oldname then - local name_we = self.files[self.perpage*(self.page-1)+self.current - #self.dirs] + -- NuPogodi, 04.09.2012: safe mode (keep old extentions) + -- Tigran, 18/08/12: corrected the rename operation to include extension.) + local oldname = self:FullFileName() + local name_we = self.files[self.perpage*(self.page-1)+self.current-#self.dirs] + local ext = "" + if self.filemanager_expert_mode <= self.BEGINNERS_MODE then + ext = "."..string.lower(string.match(oldname, ".+%.([^.]+)") or "") + name_we = string.sub(name_we, 1, -1-string.len(ext)) + end local newname = InputBox:input(0, 0, "New filename:", name_we) if newname then - newname = self.path.."/"..newname + newname = self.path.."/"..newname..ext os.rename(oldname, newname) os.rename(DocToHistory(oldname), DocToHistory(newname)) self:setPath(self.path) @@ -414,28 +422,17 @@ function FileChooser:addAllCommands() end end ) --- end of changes (NuPogodi) - self.commands:add({KEY_F, KEY_AA}, nil, "F", - "goto font menu", + -- NuPogodi, 04.09.12: menu to switch the filechooser mode + self.commands:add(KEY_M, MOD_ALT, "M", + "set mode for filemanager", function(self) - -- NuPogodi, 18.05.12: define the number of the current font in face_list - local item_no = 0 - local face_list = Font:getFontList() - while face_list[item_no] ~= Font.fontmap.cfont and item_no < #face_list do - item_no = item_no + 1 - end - - local fonts_menu = SelectMenu:new{ - menu_title = "Fonts Menu", - item_array = face_list, - -- NuPogodi, 18.05.12: define selected item - current_entry = item_no - 1, - } - local re, font = fonts_menu:choose(0, G_height) - if re then - Font.fontmap["cfont"] = font - Font:update() - end + self:changeFileChooserMode() + end + ) + self.commands:add({KEY_F, KEY_AA}, nil, "F", + "change font faces", + function(self) + Font:chooseFonts() self.pagedirty = true end ) @@ -468,8 +465,6 @@ function FileChooser:addAllCommands() self.pagedirty = true end -- function ) - --- NuPogodi, 23.05.12: new functions to manipulate (copy & move) files via clipboard self.commands:add(KEY_C, MOD_SHIFT, "C", "copy file to \'clipboard\'", function(self) @@ -534,19 +529,6 @@ function FileChooser:addAllCommands() self.pagedirty = true end ) --- end of changes (NuPogodi) - self.commands:add(KEY_P, MOD_SHIFT, "P", - "make screenshot", - function(self) - Screen:screenshot() - end - ) - self.commands:add({KEY_BACK, KEY_HOME}, nil, "Back", - "exit", - function(self) - return "break" - end - ) self.commands:add(KEY_K, MOD_SHIFT, "K", "run calculator", function(self) @@ -555,9 +537,15 @@ function FileChooser:addAllCommands() self.pagedirty = true end ) + self.commands:add({KEY_BACK, KEY_HOME}, nil, "Back", + "exit", + function(self) + return "break" + end + ) end --- NuPogodi, 23.05.12: returns full filename or nil (if folder) +-- returns full filename or nil (if folder) function FileChooser:FullFileName() local file local folder = self.dirs[self.perpage*(self.page-1)+self.current] @@ -587,3 +575,45 @@ function FileChooser:InQuotes(text) return "\""..text.."\"" end +--[[ NuPogodi, 04.09.2012: to make it more easy for users with various purposes and skills. +ATM, one may leave only silent toggling between BEGINNERS_MODE <> ADVANCED_MODE +-- But, in future, one more (the so called ROOT_MODE) might also be rather useful. +Shitch this mode on should allow developers & beta-testers to use some unstable +and/or dangerous functions able to crash the reader. ]] + +function FileChooser:changeFileChooserMode() + local face_list = { "safe mode for beginners", "advanced mode for experienced users", "expert mode for beta-testers & developers" } + local modes_menu = SelectMenu:new{ + menu_title = "Select proper mode to manage files", + item_array = face_list, + current_entry = self.filemanager_expert_mode - 1, + } + local m = modes_menu:choose(0, G_height) + if m and m ~= self.filemanager_expert_mode then + --[[ TODO: to allow multiline-rendering for info messages & to include detailed description of the selected mode + local msg = "Press 'Y' to accept new mode..." + if m==self.BEGINNERS_MODE then + msg = "You have selected safe mode for beginners: the filemanager shows only files with the reader-related extentions (*.pdf, *.djvu, etc.); ".. + "safe renaming (no extentions); unstable or dangerous functions are NOT included. "..msg + elseif m==self.ADVANCED_MODE then + msg = "You have selected advanced mode for experienced users: the filemanager shows all files; ".. + "you may rename not only their names, but also the extentions; the files with unknown extentions would be sent to CREReader ".. + "and could crash the reader. Please, use it in your own risk. "..msg + else -- ROOT_MODE + msg = "You have selected the most advanced and dangerous mode. I hope You know what you are doing. God bless You. "..msg + end + InfoMessage:show(msg, 1) + if self:ReturnKey() == KEY_Y then ]] + if (self.filemanager_expert_mode == self.BEGINNERS_MODE and m > self.BEGINNERS_MODE) + or (m == self.BEGINNERS_MODE and self.filemanager_expert_mode > self.BEGINNERS_MODE) then + self.filemanager_expert_mode = m -- make sure that new mode is set before... + self:setPath(self.path) -- refreshing the folder content + else + self.filemanager_expert_mode = m + end + G_reader_settings:saveSetting("filemanager_expert_mode", self.filemanager_expert_mode) + -- end + end + self.pagedirty = true +end + diff --git a/filehistory.lua b/filehistory.lua index bdd29bc15..6fc5bd717 100644 --- a/filehistory.lua +++ b/filehistory.lua @@ -128,7 +128,6 @@ function FileHistory:addAllCommands() self.pagedirty = true end ) - -- last documents self.commands:add(KEY_L, nil, "L", "last documents", function(self) @@ -136,7 +135,6 @@ function FileHistory:addAllCommands() self.pagedirty = true end ) - -- show help page self.commands:add(KEY_H, nil, "H", "show help page", function(self) @@ -144,15 +142,6 @@ function FileHistory:addAllCommands() self.pagedirty = true end ) - -- make screenshot - self.commands:add(KEY_P, MOD_SHIFT, "P", - "make screenshot", - function(self) - Screen:screenshot() - end - ) - - -- file info self.commands:add({KEY_FW_RIGHT, KEY_I}, nil, "joypad right", "document details", function(self) @@ -160,8 +149,7 @@ function FileHistory:addAllCommands() FileInfo:show(file_entry.dir,file_entry.name) self.pagedirty = true end - ) - + ) self.commands:add(KEY_FW_UP, nil, "joypad up", "goto previous item", function(self) @@ -202,30 +190,12 @@ function FileHistory:addAllCommands() end ) self.commands:add({KEY_F, KEY_AA}, nil, "F", - "font menu", + "change font faces", function(self) - -- NuPogodi, 18.05.12: define the number of the current font in face_list - local item_no = 0 - local face_list = Font:getFontList() - while face_list[item_no] ~= Font.fontmap.cfont and item_no < #face_list do - item_no = item_no + 1 - end - - local fonts_menu = SelectMenu:new{ - menu_title = "Fonts Menu", - item_array = face_list, - -- NuPogodi, 18.05.12: define selected item - current_entry = item_no - 1, - } - local re, font = fonts_menu:choose(0, G_height) - if re then - Font.fontmap["cfont"] = font - Font:update() - end + Font:chooseFonts() self.pagedirty = true end ) - self.commands:add({KEY_ENTER, KEY_FW_PRESS}, nil, "Enter", "open selected item", function(self) @@ -242,12 +212,6 @@ function FileHistory:addAllCommands() self.pagedirty = true end ) - self.commands:add({KEY_BACK, KEY_HOME}, nil, "Back", - "back", - function(self) - return "break" - end - ) self.commands:add({KEY_DEL}, nil, "Del", "delete history entry", function(self) @@ -266,14 +230,12 @@ function FileHistory:addAllCommands() self.pagedirty = true end ) ---[[ self.commands:add({KEY_B}, nil, "B", - "file browser", + self.commands:add({KEY_BACK, KEY_HOME}, nil, "Back", + "back", function(self) - --FileChooser:setPath(".") - FileChooser:choose(0, G_height) - self.pagedirty = true + return "break" end - )]] + ) end function FileHistory:choose(keywords) diff --git a/fileinfo.lua b/fileinfo.lua index a4726b649..0434a850d 100644 --- a/fileinfo.lua +++ b/fileinfo.lua @@ -5,86 +5,79 @@ require "font" require "inputbox" require "dialog" require "settings" ---require "extentions" FileInfo = { - -- title height - title_H = 40, - -- spacing between lines - spacing = 36, - -- foot height - foot_H = 28, - -- horisontal margin - margin_H = 10, + title_H = 40, -- title height + spacing = 36, -- spacing between lines + foot_H = 28, -- foot height + margin_H = 10, -- horisontal margin -- state buffer + pagedirty = true, result = {}, - files = {}, - lcolumn_width = 0, + commands = {}, items = 0, - page = 1, - current = 1, pathfile = "", } -function FileInfo:FileCreated(fname,attr) +function FileInfo:FileCreated(fname, attr) return os.date("%d %b %Y, %H:%M:%S", lfs.attributes(fname,attr)) end --- NuPogodi, 26.05.12: a bit changed to return string from size -function FileInfo:FileSize(size) - if size < 1024 then - return size.." Bytes" - elseif size < 2^20 then - return string.format("%.2f", size/2^10).."KB ("..size.." Bytes)" - else - return string.format("%.2f", size/2^20).."MB ("..size.." Bytes)" - end -end -- end of changes (NuPogodi, 26.05.12) -function FileInfo:init(path,fname) +function FileInfo:FileSize(size) + if size < 1024 then return size.." Bytes" + elseif size < 2^20 then return string.format("%.2f", size/2^10).."KB ("..size.." Bytes)" + else return string.format("%.2f", size/2^20).."MB ("..size.." Bytes)" + end +end + +function FileInfo:init(path, fname) self.pathfile = path.."/"..fname - self.result = {} - self:addAllCommands() + -- add commands only once + if not self.commands then + self:addAllCommands() + end local info_entry = {dir = "Name", name = fname} table.insert(self.result, info_entry) info_entry = {dir = "Path", name = path} table.insert(self.result, info_entry) - -- NuPogodi, 26.05.12: now one has to call FileInfo:FileSize(integer) - info_entry = {dir = "Size", name = FileInfo:FileSize(lfs.attributes(self.pathfile,"size"))} + + info_entry = {dir = "Size", name = FileInfo:FileSize(lfs.attributes(self.pathfile, "size"))} table.insert(self.result, info_entry) - -- NuPogodi, 26.05.12: size & filename of unzipped entry for zips + -- size & filename of unzipped entry for zips if string.lower(string.match(fname, ".+%.([^.]+)")) == "zip" then local outfile = "./data/zip_content" - local l, s = 1, "" - os.execute("unzip ".."-l \""..self.pathfile.."\" > "..outfile) + local l, s = 1 + os.execute("unzip -l \""..self.pathfile.."\" > "..outfile) if io.open(outfile, "r") then for lines in io.lines(outfile) do if l == 4 then s = lines break else l = l + 1 end end - -- due to rewriting FileInfo:FileSize(integer), one can use it now - info_entry = { dir = "Unpacked", name = FileInfo:FileSize(tonumber(string.sub(s,1,11))) } - table.insert(self.result, info_entry) + if s then + info_entry = { dir = "Unpacked", name = FileInfo:FileSize(tonumber(string.sub(s,1,11))) } + table.insert(self.result, info_entry) + end --[[ TODO: When the fileentry inside zips is encoded as ANSI (codes 128-255) any attempt to print such fileentry causes crash by drawing!!! When fileentries are encoded as UTF8, everything seems fine info_entry = { dir = "Content", name = string.sub(s,29,-1) } table.insert(self.result, info_entry) ]] end - end -- end of changes (NuPogodi, 26.05.12) + end - info_entry = {dir = "Created", name = FileInfo:FileCreated(self.pathfile,"change")} + info_entry = {dir = "Created", name = FileInfo:FileCreated(self.pathfile, "change")} table.insert(self.result, info_entry) - info_entry = {dir = "Modified", name = FileInfo:FileCreated(self.pathfile,"modification")} + info_entry = {dir = "Modified", name = FileInfo:FileCreated(self.pathfile, "modification")} table.insert(self.result, info_entry) -- if the document was already opened local history = DocToHistory(self.pathfile) - local file, msg = io.open(history,"r") + local file, msg = io.open(history, "r") if not file then info_entry = {dir = "Last Read", name = "Never"} table.insert(self.result, info_entry) else - info_entry = {dir = "Last Read", name = FileInfo:FileCreated(history,"change")} + info_entry = {dir = "Last Read", name = FileInfo:FileCreated(history, "change")} table.insert(self.result, info_entry) local file_type = string.lower(string.match(self.pathfile, ".+%.([^.]+)")) local to_search, add, factor = "[\"last_percent\"]", "%", 100 @@ -94,100 +87,73 @@ function FileInfo:init(path,fname) factor = 1 end for line in io.lines(history) do - if string.match(line,"%b[]") == to_search then + if string.match(line, "%b[]") == to_search then local cdc = tonumber(string.match(line, "%d+")) / factor - info_entry = {dir = "Completed", name = string.format("%d",cdc)..add } + info_entry = {dir = "Completed", name = string.format("%d", cdc)..add } table.insert(self.result, info_entry) end end end - self.items = #self.result - -- now calculating the horizontal space for left column - local tw, width - for i = 1, self.items do - tw = TextWidget:new({text = self.result[i].dir, face = Font:getFace("tfont", 22)}) - width = tw:getSize().w - if width > self.lcolumn_width then self.lcolumn_width = width end - tw:free() - end end -function FileInfo:show(path,name) - -- at first, one has to test whether the file still exists or not - -- it's necessary for last documents +function FileInfo:show(path, name) + -- at first, one has to test whether the file still exists or not: necessary for last documents if not io.open(path.."/"..name,"r") then return nil end -- then goto main functions - self.perpage = math.floor(G_height / self.spacing) - 2 - self.pagedirty = true - self.markerdirty = false FileInfo:init(path,name) - + -- local variables + local cface, lface, tface, fface, width, xrcol, c, dy, ev, keydef, ret_code while true do - local cface = Font:getFace("cfont", 22) - local lface = Font:getFace("tfont", 22) - local tface = Font:getFace("tfont", 25) - local fface = Font:getFace("ffont", 16) - if self.pagedirty then - self.markerdirty = true - -- gap between title rectangle left & left text drawing point + -- refresh the fonts, if not yet defined or updated via 'F' + cface = Font:getFace("cfont", 22) + lface = Font:getFace("tfont", 22) + tface = Font:getFace("tfont", 25) + fface = Font:getFace("ffont", 16) + -- drawing fb.bb:paintRect(0, 0, G_width, G_height, 0) - -- draw menu title - DrawTitle("Document Information",self.margin_H,0,self.title_H,4,tface) - -- position of left column - local x1 = self.margin_H - -- position of right column + its width + a small gap between columns - local x2 = x1 + self.lcolumn_width + 15 - -- y-position correction because of the multiline drawing - local dy, c = 5, 1 - for c = 1, self.perpage do - local i = (self.page - 1) * self.perpage + c - if i <= self.items then - y = self.title_H + self.spacing * c + dy - renderUtf8Text(fb.bb, x1, y, lface, self.result[i].dir, true) - dy = dy + renderUtf8Multiline(fb.bb, x2, y, cface, self.result[i].name, true, - G_width - self.margin_H - x2, 1.65).y - y - end + DrawTitle("Document Information", self.margin_H, 0, self.title_H, 3, tface) + -- now calculating xrcol-position for the right column + width = 0 + for c = 1, self.items do + width = math.max(sizeUtf8Text(0, G_width, lface, self.result[c].dir, true).x, width) + end + xrcol = self.margin_H + width + 25 + dy = 5 -- to store the y-position correction 'cause of the multiline drawing + for c = 1, self.items do + y = self.title_H + self.spacing * c + dy + renderUtf8Text(fb.bb, self.margin_H, y, lface, self.result[c].dir, true) + dy = dy + renderUtf8Multiline(fb.bb, xrcol, y, cface, self.result[c].name, true, + G_width - self.margin_H - xrcol, 1.65).y - y end - -- draw footer - all_page = math.ceil(self.items/self.perpage) - DrawFooter("Page "..self.page.." of "..all_page,fface,self.foot_H) - end - - if self.pagedirty then fb:refresh(0) self.pagedirty = false - end - - local ev = input.saveWaitForEvent() + end + -- waiting for user's commands + ev = input.saveWaitForEvent() ev.code = adjustKeyEvents(ev) if ev.type == EV_KEY and ev.value ~= EVENT_VALUE_KEY_RELEASE then keydef = Keydef:new(ev.code, getKeyModifier()) - Debug("key pressed: "..tostring(keydef)) - + --Debug("key pressed: "..tostring(keydef)) command = self.commands:getByKeydef(keydef) if command ~= nil then - Debug("command to execute: "..tostring(command)) + --Debug("command to execute: "..tostring(command)) ret_code = command.func(self, keydef) else - Debug("command not found: "..tostring(command)) + --Debug("command not found: "..tostring(command)) end - if ret_code == "break" then break end - - if self.selected_item ~= nil then - Debug("# selected "..self.selected_item) - return self.selected_item - end - end -- if + end -- if ev.type end -- while true + -- clear results + self.pagedirty = true + result = {} return nil end function FileInfo:addAllCommands() self.commands = Commands:new{} - self.commands:add({KEY_SPACE}, nil, "Space", "refresh page manually", function(self) @@ -200,7 +166,14 @@ function FileInfo:addAllCommands() HelpPage:show(0, G_height, self.commands) self.pagedirty = true end - ) + ) + self.commands:add({KEY_F, KEY_AA}, nil, "F", + "change font faces", + function(self) + Font:chooseFonts() + self.pagedirty = true + end + ) self.commands:add(KEY_L, nil, "L", "last documents", function(self) @@ -209,55 +182,6 @@ function FileInfo:addAllCommands() self.pagedirty = true end ) - self.commands:add({KEY_F, KEY_AA}, nil, "F", - "font menu", - function(self) - local item_no = 0 - local face_list = Font:getFontList() - while face_list[item_no] ~= Font.fontmap.cfont and item_no < #face_list do - item_no = item_no + 1 - end - - local fonts_menu = SelectMenu:new{ - menu_title = "Fonts Menu", - item_array = face_list, - current_entry = item_no - 1, - } - local re, font = fonts_menu:choose(0, G_height) - if re then - Font.fontmap["cfont"] = font - Font:update() - end - self.pagedirty = true - end - ) - self.commands:add({KEY_PGFWD, KEY_LPGFWD}, nil, ">", - "next page", - function(self) - if self.page < (self.items / self.perpage) then - if self.current + self.page*self.perpage > self.items then - self.current = self.items - self.page*self.perpage - end - self.page = self.page + 1 - self.pagedirty = true - else - self.current = self.items - (self.page-1)*self.perpage - self.markerdirty = true - end - end - ) - self.commands:add({KEY_PGBCK, KEY_LPGBCK}, nil, "<", - "previous page", - function(self) - if self.page > 1 then - self.page = self.page - 1 - self.pagedirty = true - else - self.current = 1 - self.markerdirty = true - end - end - ) self.commands:add({KEY_ENTER, KEY_FW_PRESS}, nil, "Enter", "open document", function(self) @@ -265,13 +189,6 @@ function FileInfo:addAllCommands() self.pagedirty = true end ) - -- make screenshot - self.commands:add(KEY_P, MOD_SHIFT, "P", - "make screenshot", - function(self) - Screen:screenshot() - end - ) self.commands:add({KEY_BACK, KEY_FW_LEFT}, nil, "Back", "back", function(self) diff --git a/filesearcher.lua b/filesearcher.lua index 1c6dcfc6e..008b81042 100644 --- a/filesearcher.lua +++ b/filesearcher.lua @@ -7,14 +7,10 @@ require "dialog" require "extentions" FileSearcher = { - -- title height - title_H = 40, - -- spacing between lines - spacing = 36, - -- foot height - foot_H = 28, - -- horisontal margin - margin_H = 10, + title_H = 40, -- title height + spacing = 36, -- spacing between lines + foot_H = 28, -- foot height + margin_H = 10, -- horisontal margin -- state buffer dirs = {}, @@ -119,7 +115,6 @@ end function FileSearcher:addAllCommands() self.commands = Commands:new{} - -- last documents self.commands:add(KEY_L, nil, "L", "last documents", function(self) @@ -128,7 +123,6 @@ function FileSearcher:addAllCommands() self.pagedirty = true end ) - -- show help page self.commands:add(KEY_H, nil, "H", "show help page", function(self) @@ -136,15 +130,6 @@ function FileSearcher:addAllCommands() self.pagedirty = true end ) - -- make screenshot - self.commands:add(KEY_P, MOD_SHIFT, "P", - "make screenshot", - function(self) - Screen:screenshot() - end - ) - - -- file info self.commands:add({KEY_FW_RIGHT, KEY_I}, nil, "joypad right", "document details", function(self) @@ -153,7 +138,6 @@ function FileSearcher:addAllCommands() self.pagedirty = true end ) - self.commands:add(KEY_FW_UP, nil, "joypad up", "goto previous item", function(self) @@ -208,26 +192,9 @@ function FileSearcher:addAllCommands() end ) self.commands:add({KEY_F, KEY_AA}, nil, "F", - "font menu", + "change font faces", function(self) - -- NuPogodi, 18.05.12: define the number of the current font in face_list - local item_no = 0 - local face_list = Font:getFontList() - while face_list[item_no] ~= Font.fontmap.cfont and item_no < #face_list do - item_no = item_no + 1 - end - - local fonts_menu = SelectMenu:new{ - menu_title = "Fonts Menu", - item_array = face_list, - -- NuPogodi, 18.05.12: define selected item - current_entry = item_no - 1, - } - local re, font = fonts_menu:choose(0, G_height) - if re then - Font.fontmap["cfont"] = font - Font:update() - end + Font:chooseFonts() self.pagedirty = true end ) @@ -247,12 +214,6 @@ function FileSearcher:addAllCommands() self.pagedirty = true end ) - self.commands:add({KEY_BACK, KEY_HOME}, nil, "Back", - "back", - function(self) - return "break" - end - ) self.commands:add({KEY_DEL}, nil, "Del", "delete document", function(self) @@ -277,20 +238,18 @@ function FileSearcher:addAllCommands() end -- if ev.type == EV_KEY end -- while end - ) self.commands:add({KEY_SPACE}, nil, "Space", + ) + self.commands:add({KEY_SPACE}, nil, "Space", "refresh page manually", function(self) self.pagedirty = true end ) ---[[ self.commands:add({KEY_B}, nil, "B", - "file browser", + self.commands:add({KEY_BACK, KEY_HOME}, nil, "Back", + "back", function(self) - --FileChooser:setPath(".") - FileChooser:choose(0, G_height) - self.pagedirty = true + return "break" end - )]] end function FileSearcher:choose(keywords) @@ -315,8 +274,7 @@ function FileSearcher:choose(keywords) fb.bb:paintRect(0, 0, G_width, G_height, 0) -- draw menu title - DrawTitle("Search Results for \'"..string.upper(self.keywords).."\'",self.margin_H,0,self.title_H,4,tface) - + DrawTitle("Search Results for \'"..string.upper(self.keywords).."\'",self.margin_H,0,self.title_H,3,tface) -- draw results local c if self.items == 0 then -- nothing found @@ -336,11 +294,9 @@ function FileSearcher:choose(keywords) end end end - -- draw footer all_page = math.ceil(self.items/self.perpage) - DrawFooter("Page "..self.page.." of "..all_page,fface,self.foot_H) - + DrawFooter("Page "..self.page.." of "..all_page,fface,self.foot_H) end if self.markerdirty then diff --git a/font.lua b/font.lua index d3d0b24d4..e6c0f2c51 100644 --- a/font.lua +++ b/font.lua @@ -1,37 +1,18 @@ - Font = { fontmap = { - -- default font for menu contents - cfont = "droid/DroidSans.ttf", - -- default font for title - tfont = "droid/DroidSans.ttf", - -- default font for footer - ffont = "droid/DroidSans.ttf", - - -- default font for reading position info - rifont = "droid/DroidSans.ttf", - - -- default font for pagination display - pgfont = "droid/DroidSans.ttf", - - -- selectmenu: font for item shortcut - scfont = "droid/DroidSansMono.ttf", - - -- help page: font for displaying keys - hpkfont = "droid/DroidSansMono.ttf", - -- font for displaying help messages - hfont = "droid/DroidSans.ttf", - - -- font for displaying input content - -- we have to use mono here for better distance controlling - infont = "droid/DroidSansMono.ttf", - - -- font for info messages - infofont = "droid/DroidSans.ttf", + cfont = "droid/DroidSans.ttf", -- filemanager: for menu contents + tfont = "droid/DroidSans.ttf", -- filemanager: for title + ffont = "droid/DroidSans.ttf", -- filemanager: for footer + infofont = "droid/DroidSans.ttf", -- info messages + rifont = "droid/DroidSans.ttf", -- readers: for reading position info + scfont = "droid/DroidSansMono.ttf", -- selectmenu: font for item shortcut + hpkfont = "droid/DroidSansMono.ttf", -- help page: font for displaying keys + hfont = "droid/DroidSans.ttf", -- help page: font for displaying help messages + infont = "droid/DroidSansMono.ttf", -- inputbox: use mono for better distance controlling + -- pgfont = "droid/DroidSans.ttf", -- was in use in heppage to render footer + -- to be repalced by ffont }, - fontdir = os.getenv("FONTDIR") or "./fonts", - -- face table faces = {}, } @@ -40,7 +21,7 @@ Font = { function Font:getFace(font, size) if not font then -- default to content font - font = self.cfont + font = "cfont" end local face = self.faces[font..size] @@ -89,3 +70,81 @@ function Font:update() self.faces = {} clearGlyphCache() end + +-- NuPogodi, 05.09.12: added function to change fontface for ANY item in Font.fontmap +-- choose the Fonts.fontmap-item that has to be changed +function Font:chooseItemForFont(initial) + local items_list = {} + local item_no, item_found = 1, false + local description -- additional info to display in menu + -- define auxilary function + function add_element(_index) + if _index == "cfont" then description = "filemanager: menu contents" + elseif _index == "tfont" then description = "filemanager: header title" + elseif _index == "ffont" then description = "filemanager: footer" + elseif _index == "rifont" then description = "readers: reading position info" + elseif _index == "scfont" then description = "selectmenu: item shortcuts" + elseif _index == "hpkfont" then description = "help page: hotkeys" + elseif _index == "hfont" then description = "help page: description" + elseif _index == "infont" then description = "inputbox: on-screen keyboard & user input" + elseif _index == "infofont" then description = "info messages" + else --[[ not included in Font.fontmap ]] description = "nothing; not used anymore" + end + -- then, search for number of initial item in the list Font.fontmap + if not item_found then + if _index ~= initial then + item_no = item_no + 1 + else + item_found = true + end + end + table.insert(items_list, "[".._index.."] for "..description) + end + table.foreach(Font.fontmap, add_element) + + -- goto menu to select the item which font should be changed + local items_menu = SelectMenu:new{ + menu_title = "Select item to change", + item_array = items_list, + current_entry = item_no - 1, + own_glyph = 2, -- use Font.fontmap-values to render 'items_menu'-items + } + local ok, item_font = items_menu:choose(0, fb.bb:getHeight()) + if not ok then + return nil + end + -- and selecting from the font index included in [...] from the whole string + return string.sub(string.match(item_font,"%b[]"), 2, -2) +end + +-- choose font for the 'item_font' in Fonts.fontmap +function Font:chooseFontForItem(item_font) + item_font = item_font or "cfont" + local item_no = 0 + local face_list = Font:getFontList() + while face_list[item_no] ~= Font.fontmap[item_font] and item_no < #face_list do + item_no = item_no + 1 + end + local fonts_menu = SelectMenu:new{ + menu_title = "Fonts Menu", + item_array = face_list, + current_entry = item_no - 1, + own_glyph = 1, -- use the item from item_array to render 'fonts_menu'-items + } + local re, font = fonts_menu:choose(0, G_height) + if re then + Font.fontmap[item_font] = font + Font:update() + end +end + +-- to remain in menu with Font.fontmap-items until 'Back' +function Font:chooseFonts() + local item_font = "cfont" -- initial value + while item_font ~= nil do + item_font = self:chooseItemForFont(item_font) + if item_font then + self:chooseFontForItem(item_font) + end + end +end diff --git a/helppage.lua b/helppage.lua index 869608dce..e753058e2 100644 --- a/helppage.lua +++ b/helppage.lua @@ -8,40 +8,24 @@ require "commands" HelpPage = { -- Other Class vars: - - -- title height - title_H = 40, - -- horisontal margin - margin_H = 10, - -- foot height - foot_H = 28, - -- background color - bg_color = 4, - -- spacing between lines - spacing = 25, + title_H = 40, -- title height + margin_H = 10, -- horisontal margin + foot_H = 28, -- foot height + bg_color = 3, -- background color + spacing = 25, -- spacing between lines -- state buffer commands = nil, items = 0, page = 1, - - -- font for displaying keys - fsize = 20, - face = Font:getFace("hpkfont", 20), - - -- font for displaying help messages - hfsize = 20, - hface = Font:getFace("hfont", 20), - - -- font for paging display - ffsize = 15, - fface = Font:getFace("pgfont", 15) } --- Other Class vars: - --- 02.06.12: added parameter 'title' for the header to make this function usable for various documentation purposes function HelpPage:show(ypos, height, commands, title) + local face = Font:getFace("hpkfont", 20) + local hface = Font:getFace("hfont", 20) + local fface = Font:getFace("ffont", 16) + local tface = Font:getFace("tfont", 25) + self.commands = {} self.items = 0 local keys = {} @@ -56,9 +40,9 @@ function HelpPage:show(ypos, height, commands, title) end table.sort(self.commands,function(w1,w2) return w1.order own glyphs for items like "Droid/DroidSans.ttf" + -- own_glyph = 2 => own glyphs for Font.fontmap._index like "ffont", "tfont", etc. } function SelectMenu:new(o) @@ -229,18 +233,16 @@ function SelectMenu:choose(ypos, height) self.pagedirty = true self.markerdirty = false self.last_shortcut = 0 - - -- NuPogodi, 18.02.12: let us define the starting position - -- If it was, certainly, send before by SelectMenu:new() via current_entry + self.current_entry = math.min(self.current_entry,self.items) - -- self.current_entry = math.max(self.current_entry,1) + -- now calculating the page & cursor self.page = math.floor(self.current_entry / self.perpage) + 1 self.page = math.max(1, self.page) self.current = self.current_entry - (self.page - 1) * self.perpage + 1 self.current = math.max(1, self.current) - -- end of changes (NuPogodi) - + local own_face + while true do local cface = Font:getFace("cfont", 22) local tface = Font:getFace("tfont", 25) @@ -252,10 +254,8 @@ function SelectMenu:choose(ypos, height) if self.pagedirty then fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0) self.markerdirty = true - -- draw menu title (new version with clock & battery) - DrawTitle(self.menu_title,self.margin_H,0,self.title_H,4,tface) - - + -- draw menu title + DrawTitle(self.menu_title,self.margin_H,0,self.title_H,3,tface) -- draw items fb.bb:paintRect(0, ypos + self.title_H + self.margin_H, fb.bb:getWidth(), height - self.title_H, 0) if self.items == 0 then @@ -291,14 +291,15 @@ function SelectMenu:choose(ypos, height) end self.last_shortcut = c - -- NuPogodi, 15.05.12: paint items by own glyphs if the menu title == 'Fonts Menu', - -- but not "Fonts Menu " (crereader.lua); the problem is crereader creates own list - -- with the font families, rather then filenames of available fonts - local own_face = cface - if self.menu_title == "Fonts Menu" then + -- NuPogodi, 30.08.12: improved method to use own fontface for each menu item + if self.own_glyph == 1 then -- Font.fontmap[_index], like "Droid/DroidSans.ttf" own_face = Font:getFace(self.item_array[i], 22) + elseif self.own_glyph == 2 then -- Font.fontmap._index, like "[cfont] description" + own_face = Font:getFace(string.sub(string.match(self.item_array[i],"%b[]"), 2, -2), 22) + else + own_face = cface end - -- NuPogodi, 18.05.12: rendering menu items ( fixed too long strings) + -- rendering menu items if sizeUtf8Text(lx,fb.bb:getWidth(),own_face,self.item_array[i],true).x < (fw - 10) then renderUtf8Text(fb.bb,lx,y,own_face,self.item_array[i],true) else diff --git a/unireader.lua b/unireader.lua index 7889fa22a..2184f4694 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2113,7 +2113,7 @@ function UniReader:addAllCommands() if not re or re==(1-unireader.globalzoom_mode) or re==1 or re==8 or re==9 then -- if not proper zoom-mode unireader:redrawCurrentPage() else -- in most cases the message is not necessary, so feel you free to comment - InfoMessage:show("Redrawing in new zoom mode...", 1) + -- InfoMessage:show("Redrawing in new zoom mode...", 1) unireader:setglobalzoom_mode(1-re) end end) @@ -2165,12 +2165,9 @@ function UniReader:addAllCommands() local page = NumInputBox:input(G_height-100, 100, "Page:", "current page "..self.pageno, true) -- convert string to number - if not pcall(function () page = page + 0 end) then + if not pcall(function () page = math.floor(page) end) + or page < 1 or page > unireader.doc:getPages() then page = unireader.pageno - else - if page < 1 or page > unireader.doc:getPages() then - page = unireader.pageno - end end unireader:goto(page) end) @@ -2664,13 +2661,6 @@ function UniReader:addAllCommands() end end ) - self.commands:add(KEY_P, MOD_SHIFT, "P", - "make screenshot", - function(unireader) - Screen:screenshot() - end - ) - -- NuPogodi, 03.09.12: moved the exit commands here: just cosmetics self.commands:add(KEY_BACK,MOD_ALT,"Back", "close document", function(unireader)