mirror of
https://github.com/koreader/koreader
synced 2024-10-31 21:20:20 +00:00
Merge pull request #628 from tigran123/highlights
Fix deleting highlights via Shift-N + cleanup of battery logging.
This commit is contained in:
commit
f27ee2f5fa
@ -9,10 +9,12 @@ end
|
||||
|
||||
-- log battery level in "batlog.txt" file, blevent can be any string
|
||||
function logBatteryLevel(blevent)
|
||||
if not G_battery_logging then return end
|
||||
|
||||
local file = io.open("batlog.txt", "a+")
|
||||
if file then
|
||||
if file:seek("end") == 0 then -- write the header only once
|
||||
file:write(string.format("DATE\t\tTIME\t\tBATTERY\tEVENT\n"))
|
||||
file:write("DATE\t\tTIME\t\tBATTERY\tEVENT\n")
|
||||
end
|
||||
file:write(string.format("%s\t%s\t%s\t%s\n",
|
||||
os.date("%d-%b-%y"), os.date("%T"),
|
||||
|
10
commands.lua
10
commands.lua
@ -168,7 +168,7 @@ function Commands:new(obj)
|
||||
function()
|
||||
--os.execute("echo 'screensaver in' >> /mnt/us/event_test.txt")
|
||||
if G_charging_mode == false and G_screen_saver_mode == false then
|
||||
if G_battery_logging then logBatteryLevel("SLEEP") end
|
||||
logBatteryLevel("SLEEP")
|
||||
Screen:saveCurrentBB()
|
||||
InfoMessage:inform("Going into screensaver... ", DINFO_NODELAY, 0, MSG_AUX)
|
||||
Screen.kpv_rotation_mode = Screen.cur_rotation_mode
|
||||
@ -184,7 +184,7 @@ function Commands:new(obj)
|
||||
function()
|
||||
--os.execute("echo 'screensaver out' >> /mnt/us/event_test.txt")
|
||||
if G_screen_saver_mode == true and G_charging_mode == false then
|
||||
if G_battery_logging then logBatteryLevel("WAKEUP") end
|
||||
logBatteryLevel("WAKEUP")
|
||||
util.usleep(1500000)
|
||||
os.execute("killall -stop cvm")
|
||||
fb:setOrientation(Screen.kpv_rotation_mode)
|
||||
@ -199,7 +199,7 @@ function Commands:new(obj)
|
||||
function()
|
||||
--os.execute("echo 'usb in' >> /mnt/us/event_test.txt")
|
||||
if G_charging_mode == false and G_screen_saver_mode == false then
|
||||
if G_battery_logging then logBatteryLevel("USB PLUG") end
|
||||
logBatteryLevel("USB PLUG")
|
||||
Screen:saveCurrentBB()
|
||||
Screen.kpv_rotation_mode = Screen.cur_rotation_mode
|
||||
fb:setOrientation(Screen.native_rotation_mode)
|
||||
@ -220,7 +220,7 @@ function Commands:new(obj)
|
||||
fb:setOrientation(Screen.kpv_rotation_mode)
|
||||
Screen:restoreFromSavedBB()
|
||||
fb:refresh(0)
|
||||
if G_battery_logging then logBatteryLevel("USB UNPLUG") end
|
||||
logBatteryLevel("USB UNPLUG")
|
||||
end
|
||||
FileChooser:setPath(FileChooser.path)
|
||||
FileChooser.pagedirty = true
|
||||
@ -231,7 +231,7 @@ function Commands:new(obj)
|
||||
-- I suggest one should probably change the hotkey to, say, Alt+Space
|
||||
obj:add(KEY_P, MOD_SHIFT, "P", "make screenshot",
|
||||
function()
|
||||
if G_battery_logging then logBatteryLevel("SCREENSHOT") end
|
||||
logBatteryLevel("SCREENSHOT")
|
||||
Screen:screenshot()
|
||||
end
|
||||
)
|
||||
|
@ -2218,45 +2218,48 @@ function UniReader:prevBookMarkedPage()
|
||||
end
|
||||
|
||||
function UniReader:showHighLight()
|
||||
local menu_items, highlight_page, highlight_num = {}, {}, {}
|
||||
local ret_code, item_no = -1, -1
|
||||
local menu_items, highlight_page, highlight_num
|
||||
local ret_code, item_no, height = -1, -1, G_height
|
||||
|
||||
-- build menu items
|
||||
for k,v in pairs(self.highlight) do
|
||||
if type(k) == "number" then
|
||||
for k1,v1 in ipairs(v) do
|
||||
table.insert(menu_items, v1.text)
|
||||
table.insert(highlight_page, k)
|
||||
table.insert(highlight_num, k1)
|
||||
local function rebuild_menu()
|
||||
menu_items, highlight_page, highlight_num = {}, {}, {}
|
||||
for page,highlights in pairs(self.highlight) do -- iterate all pages with highlights
|
||||
if type(page) == "number" then
|
||||
for num,highlight in ipairs(highlights) do -- iterate all highlights on this page
|
||||
table.insert(menu_items, highlight.text)
|
||||
table.insert(highlight_page, page)
|
||||
table.insert(highlight_num, num)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
rebuild_menu()
|
||||
|
||||
if #menu_items == 0 then
|
||||
return InfoMessage:inform("No HighLights found ", DINFO_DELAY, 1, MSG_WARN)
|
||||
end
|
||||
|
||||
while true do
|
||||
hl_menu = SelectMenu:new{
|
||||
local hl_menu = SelectMenu:new{
|
||||
menu_title = "HighLights ("..tostring(#menu_items).." items)",
|
||||
item_array = menu_items,
|
||||
deletable = true,
|
||||
}
|
||||
ret_code, item_no = hl_menu:choose(0, fb.bb:getHeight())
|
||||
ret_code, item_no = hl_menu:choose(0, height)
|
||||
if ret_code then
|
||||
return self:goto(highlight_page[ret_code])
|
||||
elseif item_no then -- delete item
|
||||
local hpage = highlight_page[item_no]
|
||||
local hnum = highlight_num[item_no]
|
||||
table.remove(self.highlight[hpage], hnum)
|
||||
if #self.highlight[hpage] == 0 then
|
||||
table.remove(self.highlight, hpage)
|
||||
local page, num = highlight_page[item_no], highlight_num[item_no]
|
||||
table.remove(self.highlight[page], num)
|
||||
if #self.highlight[page] == 0 then
|
||||
table.remove(self.highlight, page)
|
||||
end
|
||||
table.remove(menu_items, item_no)
|
||||
rebuild_menu()
|
||||
if #menu_items == 0 then
|
||||
return self:redrawCurrentPage()
|
||||
end
|
||||
else
|
||||
else -- return via Back
|
||||
return self:redrawCurrentPage()
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user