Merge pull request #2 from onefifth/persist_scroll_position
Persist scroll position
This commit is contained in:
commit
52c07cd475
@ -66,7 +66,13 @@ function meta.__index:init()
|
||||
self.idleUpdates = {}
|
||||
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
|
||||
|
||||
function meta.__index:show( show )
|
||||
@ -272,6 +278,7 @@ function meta.__index:getSourcePage( source )
|
||||
page.pageIdx = self.sourceBook:GetPageCount()
|
||||
self.sourceBook:AddPage( page:getRoot(), name )
|
||||
page:registerEvent( "onBreakPointChanged", function( ... ) self:runEvents_( "onBreakPointChanged", source, ... ) end )
|
||||
page:registerEvent( "onScrollChanged", function( ... ) self:runEvents_( "onScrollChanged", source, ... ) end )
|
||||
end
|
||||
return page
|
||||
end
|
||||
|
@ -5,6 +5,8 @@ local ui =
|
||||
editor = require( "ui.editor" ),
|
||||
}
|
||||
|
||||
local wx = require( "wx" )
|
||||
|
||||
local lfs = require( "lfs" )
|
||||
|
||||
local assert = assert
|
||||
@ -23,7 +25,10 @@ function new( parent, source )
|
||||
local page = {}
|
||||
setmetatable( page, meta )
|
||||
page.editor = ui.editor.new( parent )
|
||||
page.events = { onBreakPointChanged = {} }
|
||||
page.events = {
|
||||
onBreakPointChanged = {},
|
||||
onScrollChanged = {},
|
||||
}
|
||||
page:setSource_( source )
|
||||
page.editor.breakpointCallback = function( line )
|
||||
page:runEvents_( "onBreakPointChanged", line )
|
||||
@ -53,6 +58,9 @@ function meta.__index:update()
|
||||
assert( string.sub( self.source, 1, 1 ) == "@" )
|
||||
local fileName = string.sub( self.source, 2 )
|
||||
|
||||
local scrollPosition = self:GetScrollPos()
|
||||
self:runEvents_( "onScrollChanged", scrollPosition )
|
||||
|
||||
local newDate = lfs.attributes( fileName, "modification" ) or 0
|
||||
if newDate > self.sourceDate then
|
||||
print( "reloading source file "..fileName )
|
||||
@ -78,6 +86,14 @@ function meta.__index:getFocus()
|
||||
return ed:GetCurrentLine() + 1
|
||||
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 )
|
||||
local editor = self.editor.editor
|
||||
if self.currentLine == line then return end
|
||||
|
@ -11,6 +11,8 @@ local ui =
|
||||
}
|
||||
local lfs = require( "lfs" )
|
||||
|
||||
local wx = require( "wx" )
|
||||
|
||||
require( "coxpcall" )
|
||||
local coxpcall = coxpcall
|
||||
local copcall = copcall
|
||||
@ -37,6 +39,15 @@ local meta = { __index = {} }
|
||||
|
||||
local complexValueManagerMeta = { __index = {} }
|
||||
|
||||
local function createClientConfig(name)
|
||||
return {
|
||||
name = name,
|
||||
mappings = {},
|
||||
breakpoints = {},
|
||||
scrollPositions = {},
|
||||
}
|
||||
end
|
||||
|
||||
function new( engine, window )
|
||||
local res =
|
||||
{
|
||||
@ -133,6 +144,7 @@ function meta.__index:run_()
|
||||
self.window:registerEvent( "onBreakPointChanged", wrapCb( function( ... ) self:onBreakPointChanged_( ... ) end ) )
|
||||
self.window:registerEvent( "onFileOpen", wrapCb( function( ... ) self:onFileOpen_( ... ) end ) )
|
||||
self.window:registerEvent( "onFileClosed", wrapCb( function( ... ) self:onFileClosed_( ... ) end ) )
|
||||
self.window:registerEvent( "onScrollChanged", wrapCb(function( ... ) self:onScrollChanged_( ...) end ) )
|
||||
|
||||
self.window:registerEvent( "onApplicationExiting", wrapCb( function( ... ) self:onApplicationExiting_( ... ) end ) )
|
||||
|
||||
@ -143,7 +155,7 @@ function meta.__index:run_()
|
||||
|
||||
self.window.watch.evaluateCallback = wrapCb( function( expr ) return self:evaluateExpression_( expr ) end )
|
||||
|
||||
self.configs.global = { name = "global", breakpoints = {} }
|
||||
self.configs.global = createClientConfig('global')
|
||||
self:loadConfig_( "global" )
|
||||
|
||||
self:sleep_()
|
||||
@ -200,6 +212,22 @@ function meta.__index:run_()
|
||||
end
|
||||
end
|
||||
|
||||
function meta.__index:getActiveClientConfig_()
|
||||
local activeClientId = self.activeClient
|
||||
|
||||
if activeClientId == nil then
|
||||
return self.configs.global
|
||||
end
|
||||
|
||||
local clientData = self.clients[activeClientId]
|
||||
|
||||
if clientData == nil then
|
||||
return self.configs.global
|
||||
end
|
||||
|
||||
return clientData.config
|
||||
end
|
||||
|
||||
function meta.__index:evaluateExpression_( expr )
|
||||
local clientId = self.activeClient
|
||||
local client = self.engine.getClient( clientId )
|
||||
@ -397,6 +425,17 @@ function meta.__index:onApplicationExiting_()
|
||||
self.window.threads:setData( nil )
|
||||
end
|
||||
|
||||
function meta.__index:refreshScrollPosition_()
|
||||
local config = self:getActiveClientConfig_()
|
||||
|
||||
for source, sp in pairs( config.scrollPositions ) do
|
||||
local page = self.window:getSourcePage( source )
|
||||
if page ~= nil then
|
||||
page:SetScrollPos(sp)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function meta.__index:refreshBreakPoints_()
|
||||
local clientId = self.activeClient
|
||||
local config = nil
|
||||
@ -460,6 +499,7 @@ function meta.__index:onFileOpen_( path )
|
||||
self:setSourceFocus_( source, 1 )
|
||||
self:refreshPointers_()
|
||||
self:refreshBreakPoints_()
|
||||
self:refreshScrollPosition_()
|
||||
end
|
||||
|
||||
function meta.__index:onFileClosed_( source )
|
||||
@ -468,6 +508,12 @@ function meta.__index:onFileClosed_( source )
|
||||
end
|
||||
end
|
||||
|
||||
function meta.__index:onScrollChanged_( source, position )
|
||||
local clientConfig = self:getActiveClientConfig_()
|
||||
clientConfig.scrollPositions[source] = position
|
||||
clientConfig.dirty = true
|
||||
end
|
||||
|
||||
function meta.__index:onThreadClicked_( clientId, threadId )
|
||||
print( "Thread clicked: client="..clientId..", thread="..threadId )
|
||||
local clientData = self.clients[clientId]
|
||||
@ -684,7 +730,7 @@ function meta.__index:onNewClient_( clientId )
|
||||
local client = self.engine.getClient( clientId )
|
||||
local name = client:name()
|
||||
if self.configs[name] == nil then
|
||||
self.configs[name] = { name = name, mappings = {}, breakpoints = {} }
|
||||
self.configs[name] = createClientConfig(name)
|
||||
self:loadConfig_( name )
|
||||
end
|
||||
self.clients[clientId] = { dirty = true, activeThread = "current", activeLevel = 1, config = self.configs[name] }
|
||||
@ -742,12 +788,19 @@ function meta.__index:saveConfig_( name )
|
||||
openFiles[page.pageIdx+1] = source
|
||||
end
|
||||
local breakpoints = clientConfig.breakpoints
|
||||
local scrollPositions = clientConfig.scrollPositions
|
||||
|
||||
local path = "clients/"..name.."/config.lua"
|
||||
lfs.mkdir( "clients" )
|
||||
lfs.mkdir( "clients/"..name )
|
||||
local file = assert( io.open( path, "w" ) )
|
||||
file:write( grldc.net.serialize( { mappings = clientConfig.mappings, openFiles = openFiles, breakpoints = breakpoints, breakOnConnection = clientConfig.breakOnConnection } ) )
|
||||
file:write( grldc.net.serialize( {
|
||||
mappings = clientConfig.mappings,
|
||||
openFiles = openFiles,
|
||||
breakpoints = breakpoints,
|
||||
scrollPositions = scrollPositions,
|
||||
breakOnConnection = clientConfig.breakOnConnection
|
||||
} ) )
|
||||
file:close()
|
||||
print( "Saved config \""..name.."\"" )
|
||||
clientConfig.lastConfigSave = os.time()
|
||||
@ -775,6 +828,12 @@ function meta.__index:loadConfig_( name )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if config.scrollPositions ~= nil then
|
||||
for source, sp in pairs( config.scrollPositions ) do
|
||||
clientConfig.scrollPositions[source] = sp
|
||||
end
|
||||
end
|
||||
end
|
||||
if clientConfig.breakOnConnection == nil then
|
||||
clientConfig.breakOnConnection = true
|
||||
|
Loading…
Reference in New Issue
Block a user