From 07420bda07be65130e9c343df5d83cefdab62077 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 2 Mar 2012 01:44:52 +0100 Subject: [PATCH] added Shift+B to add current page to jumpstack This allows us to bootstap jumpstack if we don't have table of contents --- pdfreader.lua | 58 +++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/pdfreader.lua b/pdfreader.lua index 327e41bee..1191c3ccc 100644 --- a/pdfreader.lua +++ b/pdfreader.lua @@ -248,6 +248,33 @@ function PDFReader:show(no) self.slot_visible = slot; end +function PDFReader:add_jump(pageno) + local jump_item = nil + -- add current page to jump_stack if no in + for _t,_v in ipairs(self.jump_stack) do + if _v.page == pageno then + jump_item = _v + table.remove(self.jump_stack, _t) + elseif _v.page == no then + -- the page we jumped to should not be show in stack + table.remove(self.jump_stack, _t) + end + end + -- create a new one if not found + if not jump_item then + jump_item = { + page = pageno, + datetime = os.date("%Y-%m-%d %H:%M:%S"), + } + end + -- insert at the start + table.insert(self.jump_stack, 1, jump_item) + if #self.jump_stack > 10 then + -- remove the last element to keep the size less than 10 + table.remove(self.jump_stack) + end +end + -- change current page and cache next page after rendering function PDFReader:goto(no) if no < 1 or no > self.doc:getPages() then @@ -256,30 +283,7 @@ function PDFReader:goto(no) -- for jump_stack if self.pageno and math.abs(self.pageno - no) > 1 then - local jump_item = nil - -- add current page to jump_stack if no in - for _t,_v in ipairs(self.jump_stack) do - if _v.page == self.pageno then - jump_item = _v - table.remove(self.jump_stack, _t) - elseif _v.page == no then - -- the page we jumped to should not be show in stack - table.remove(self.jump_stack, _t) - end - end - -- create a new one if not found - if not jump_item then - jump_item = { - page = self.pageno, - datetime = os.date("%Y-%m-%d %H:%M:%S"), - } - end - -- insert at the start - table.insert(self.jump_stack, 1, jump_item) - if #self.jump_stack > 10 then - -- remove the last element to keep the size less than 10 - table.remove(self.jump_stack) - end + self:add_jump(self.pageno) end self.pageno = no @@ -446,7 +450,11 @@ function PDFReader:inputloop() elseif ev.code == KEY_T then self:showTOC() elseif ev.code == KEY_B then - self:showJumpStack() + if self.shiftmode then + self:add_jump(self.pageno) + else + self:showJumpStack() + end elseif ev.code == KEY_J then self:setrotate( self.globalrotate + 10 ) elseif ev.code == KEY_K then