Browse Source

onScrollChanged event, get/set scroll position of sourcePage control

pull/1/head
robin 8 years ago
parent
commit
4b1ffb5125
  1. 9
      server/wxLdb/ui/mainWindow.lua
  2. 18
      server/wxLdb/ui/sourcePage.lua

9
server/wxLdb/ui/mainWindow.lua

@ -66,7 +66,13 @@ function meta.__index:init()
self.idleUpdates = {} self.idleUpdates = {}
self.frame:Connect( wx.wxEVT_IDLE, function( event ) self:onIdleUpdate_( event ) end ) self.frame:Connect( wx.wxEVT_IDLE, function( event ) self:onIdleUpdate_( event ) end )
self.events = { onBreakPointChanged = {}, onFileOpen = {}, onFileClosed = {}, onApplicationExiting = {} } self.events = {
onBreakPointChanged = {},
onFileOpen = {},
onFileClosed = {},
onApplicationExiting = {},
onScrollChanged = {}
}
end end
function meta.__index:show( show ) function meta.__index:show( show )
@ -272,6 +278,7 @@ function meta.__index:getSourcePage( source )
page.pageIdx = self.sourceBook:GetPageCount() page.pageIdx = self.sourceBook:GetPageCount()
self.sourceBook:AddPage( page:getRoot(), name ) self.sourceBook:AddPage( page:getRoot(), name )
page:registerEvent( "onBreakPointChanged", function( ... ) self:runEvents_( "onBreakPointChanged", source, ... ) end ) page:registerEvent( "onBreakPointChanged", function( ... ) self:runEvents_( "onBreakPointChanged", source, ... ) end )
page:registerEvent( "onScrollChanged", function( ... ) self:runEvents_( "onScrollChanged", source, ... ) end )
end end
return page return page
end end

18
server/wxLdb/ui/sourcePage.lua

@ -5,6 +5,8 @@ local ui =
editor = require( "ui.editor" ), editor = require( "ui.editor" ),
} }
local wx = require( "wx" )
local lfs = require( "lfs" ) local lfs = require( "lfs" )
local assert = assert local assert = assert
@ -23,7 +25,10 @@ function new( parent, source )
local page = {} local page = {}
setmetatable( page, meta ) setmetatable( page, meta )
page.editor = ui.editor.new( parent ) page.editor = ui.editor.new( parent )
page.events = { onBreakPointChanged = {} } page.events = {
onBreakPointChanged = {},
onScrollChanged = {},
}
page:setSource_( source ) page:setSource_( source )
page.editor.breakpointCallback = function( line ) page.editor.breakpointCallback = function( line )
page:runEvents_( "onBreakPointChanged", line ) page:runEvents_( "onBreakPointChanged", line )
@ -53,6 +58,9 @@ function meta.__index:update()
assert( string.sub( self.source, 1, 1 ) == "@" ) assert( string.sub( self.source, 1, 1 ) == "@" )
local fileName = string.sub( self.source, 2 ) local fileName = string.sub( self.source, 2 )
local scrollPosition = self:GetScrollPos()
self:runEvents_( "onScrollChanged", scrollPosition )
local newDate = lfs.attributes( fileName, "modification" ) or 0 local newDate = lfs.attributes( fileName, "modification" ) or 0
if newDate > self.sourceDate then if newDate > self.sourceDate then
print( "reloading source file "..fileName ) print( "reloading source file "..fileName )
@ -78,6 +86,14 @@ function meta.__index:getFocus()
return ed:GetCurrentLine() + 1 return ed:GetCurrentLine() + 1
end end
function meta.__index:SetScrollPos( pos )
self.editor.editor:LineScroll(0, pos)
end
function meta.__index:GetScrollPos()
return self.editor.editor:GetScrollPos( wx.wxVERTICAL )
end
function meta.__index:setCurrentLine( line ) function meta.__index:setCurrentLine( line )
local editor = self.editor.editor local editor = self.editor.editor
if self.currentLine == line then return end if self.currentLine == line then return end

Loading…
Cancel
Save