From: John L. <jr...@us...> - 2006-10-04 02:49:22
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv31238/wxLua/samples Modified Files: editor.wx.lua Log Message: Index: editor.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/editor.wx.lua,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** editor.wx.lua 26 Sep 2006 05:05:55 -0000 1.26 --- editor.wx.lua 28 Sep 2006 22:26:06 -0000 1.27 *************** *** 260,268 **** function UpdateStatusText(editor) if editor then ! local pos = editor:GetCurrentPos() ! local row = editor:LineFromPosition(pos) ! local col = 1 + pos - editor:PositionFromLine(row) ! frame:SetStatusText("Ln "..tostring(row + 1).." Col "..tostring(col), 3) if editor:GetOvertype() then --- 260,268 ---- function UpdateStatusText(editor) if editor then ! local pos = editor:GetCurrentPos() ! local line = editor:LineFromPosition(pos) ! local col = 1 + pos - editor:PositionFromLine(line) ! frame:SetStatusText("Ln "..tostring(line + 1).." Col "..tostring(col), 3) if editor:GetOvertype() then *************** *** 1200,1204 **** fHaveFound = nil ! frame:SetStatusText("Not found.") else fHaveFound = 1 --- 1200,1204 ---- fHaveFound = nil ! frame:SetStatusText("Find text not found.") else fHaveFound = 1 *************** *** 1435,1440 **** end ! function ToggleDebugMarker(editor, row) ! local markers = editor:MarkerGet(row) if markers >= CURRENT_LINE_MARKER_VALUE then markers = markers - CURRENT_LINE_MARKER_VALUE --- 1435,1440 ---- end ! function ToggleDebugMarker(editor, line) ! local markers = editor:MarkerGet(line) if markers >= CURRENT_LINE_MARKER_VALUE then markers = markers - CURRENT_LINE_MARKER_VALUE *************** *** 1443,1464 **** local filePath = MakeDebugFileName(editor, openDocuments[id].filePath) if markers >= BREAKPOINT_MARKER_VALUE then ! editor:MarkerDelete(row, BREAKPOINT_MARKER) if debugServer then ! debugServer:RemoveBreakPoint(filePath, row) end else ! editor:MarkerAdd(row, BREAKPOINT_MARKER) if debugServer then ! debugServer:AddBreakPoint(filePath, row) end end end frame:Connect(ID_TOGGLEBREAKPOINT, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) local editor = GetEditor() ! local pos = editor:GetCurrentPos() ! local row = editor:LineFromPosition(pos) ! ToggleDebugMarker(editor, row) end) frame:Connect(ID_TOGGLEBREAKPOINT, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) --- 1443,1473 ---- local filePath = MakeDebugFileName(editor, openDocuments[id].filePath) if markers >= BREAKPOINT_MARKER_VALUE then ! editor:MarkerDelete(line, BREAKPOINT_MARKER) if debugServer then ! debugServer:RemoveBreakPoint(filePath, line) end else ! editor:MarkerAdd(line, BREAKPOINT_MARKER) if debugServer then ! debugServer:AddBreakPoint(filePath, line) end end end + function DisplayOutput(message) + if splitter:IsSplit() == false then + local x, y = frame:GetClientSize() + splitter:SplitHorizontally(notebook, errorLog, (2 * y) / 3) + end + errorLog:SetReadOnly(false) + errorLog:AddText(message) + errorLog:SetReadOnly(true) + end + frame:Connect(ID_TOGGLEBREAKPOINT, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) local editor = GetEditor() ! local line = editor:LineFromPosition(editor:GetCurrentPos()) ! ToggleDebugMarker(editor, line) end) frame:Connect(ID_TOGGLEBREAKPOINT, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) *************** *** 1470,1474 **** local id = editor:GetId() local filePath = MakeDebugFileName(editor, openDocuments[id].filePath) ! wx.wxLuaDebuggerServerCompile(filePath, editorText) end) frame:Connect(ID_COMPILE, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) --- 1479,1489 ---- local id = editor:GetId() local filePath = MakeDebugFileName(editor, openDocuments[id].filePath) ! local ret, errMsg, line_num = wx.CompileLuaScript(editorText, filePath) ! ! if line_num > -1 then ! DisplayOutput("Compliation error on line number :"..tostring(line_num).."\n") ! editor:GotoLine(line_num-1) ! end ! DisplayOutput(errMsg.."\n") end) frame:Connect(ID_COMPILE, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) *************** *** 1521,1527 **** end) frame:Connect(ID_START_DEBUG, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) ! debugServer = wx.wxLuaDebuggerServer(portNumber) if debugServer then debugServer:StartClient() --- 1536,1690 ---- end) + function CreateDebugServer() + local debugServer = wx.wxLuaDebuggerServer(portNumber) + if not debugServer then return nil end + + function DownloadBreakpoints(editor, fileName) + local nextLine = editor:MarkerNext(0, BREAKPOINT_MARKER_VALUE) + while nextLine ~= -1 do + debugServer:AddBreakPoint(fileName, nextLine) + nextLine = editor:MarkerNext(nextLine + 1, BREAKPOINT_MARKER_VALUE) + end + end + + debugServer:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_CLIENT_CONNECTED, + function (event) + if debugServer then + for id, document in pairs(openDocuments) do + local editor = document.editor + local editorText = editor:GetText() + local filePath = MakeDebugFileName(editor, document.filePath) + debugServer:Run(filePath, editorText) + DownloadBreakpoints(editor, filePath) + end + fIsConnected = 1 + debugServer:Step() + fIsRunning = 1 + + UpdateUIMenuItems() + end + DisplayOutput("Client connected\n") + end) + + function DebuggerIgnoreFile(fileName) + ignoreFlag = nil + for idx, ignoreFile in pairs(ignoredFilesList) do + if string.upper(ignoreFile) == string.upper(fileName) then + ignoreFlag = 1 + end + end + return ignoreFlag + end + + debugServer:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_BREAK, + function (event) + if exitingProgram then return end + local line = event:GetLineNumber() + local eventFileName = event:GetFileName() + if string.sub(eventFileName, 1, 1) == '@' then + eventFileName = string.sub(eventFileName, 2, -1) + if wx.wxIsAbsolutePath(eventFileName) == false then + eventFileName = wx.wxGetCwd().."/"..eventFileName + end + end + if wx.wxPlatformWindows then + eventFileName = wx.wxUnix2DosFilename(eventFileName) + end + local fileFound = false + DisplayOutput("At Breakpoint line: "..tostring(line).." file: "..eventFileName.."\n") + for id, document in pairs(openDocuments) do + local editor = document.editor + local filePath = MakeDebugFileName(editor, document.filePath) + -- for running in cygwin, use same type of separators + filePath = string.gsub(filePath, "\\", "/") + local eventFileName_ = string.gsub(eventFileName, "\\", "/") + if string.upper(filePath) == string.upper(eventFileName_) then + local selection = document.index + notebook:SetSelection(selection) + SetEditorSelection(selection) + editor:MarkerAdd(line, CURRENT_LINE_MARKER) + editor:EnsureVisibleEnforcePolicy(line) + fileFound = true + break + end + end + if not DebuggerIgnoreFile(eventFileName) then + if not fileFound then + local fileDialog = wx.wxFileDialog(frame, + "Select file for debugging", + "", + eventFileName, + "Lua files (*.lua)|*.lua|Text files (*.txt)|*.txt|All files (*)|*", + wx.wxOPEN) + if fileDialog:ShowModal() == wx.wxID_OK then + local editor = LoadFile(fileDialog:GetPath(), fileDialog:GetFilename()) + if editor then + editor:MarkerAdd(line, CURRENT_LINE_MARKER) + editor:EnsureVisibleEnforcePolicy(line) + editor:SetReadOnly(true) + fileFound = true + end + end + fileDialog:Destroy() + end + if not fileFound then + table.insert(ignoredFilesList, eventFileName) + end + end + + if fileFound then + fIsRunning = nil + ProcessWatches() + elseif debugServer then + debugServer:Continue() + fIsRunning = 1 + end + end) + + debugServer:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_PRINT, + function (event) + DisplayOutput(event:GetMessage().."\n") + end) + + debugServer:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_ERROR, + function (event) + DisplayOutput("wxLua ERROR: "..event:GetMessage().."\n") + end) + + debugServer:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_EXIT, + function (event) + for id, document in pairs(openDocuments) do + local editor = document.editor + editor:MarkerDeleteAll(CURRENT_LINE_MARKER) + end + fIsConnected = nil + if debugServer then + debugServer:Delete() + fIsRunning = nil + debugServer = nil + end + SetAllEditorsReadOnly(false) + ignoredFilesList = {} + DisplayOutput("\nDebugger Client finished\n\n") + end) + + debugServer:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_EVALUATE_EXPR, + function (event) + if watchListCtrl then + watchListCtrl:SetStringItem(event:GetReference(), + 1, + event:GetMessage()) + end + end) + + + + return debugServer + end + + frame:Connect(ID_START_DEBUG, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) ! debugServer = CreateDebugServer() if debugServer then debugServer:StartClient() *************** *** 1660,1812 **** end) - function DownloadBreakpoints(editor, fileName) - local nextLine = editor:MarkerNext(0, BREAKPOINT_MARKER_VALUE) - while nextLine ~= -1 do - debugServer:AddBreakPoint(fileName, nextLine) - nextLine = editor:MarkerNext(nextLine + 1, BREAKPOINT_MARKER_VALUE) - end - end - - editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_CLIENT_CONNECTED, - function (event) - if debugServer then - for id, document in pairs(openDocuments) do - local editor = document.editor - local editorText = editor:GetText() - local filePath = MakeDebugFileName(editor, document.filePath) - debugServer:Run(filePath, editorText) - DownloadBreakpoints(editor, filePath) - end - fIsConnected = 1 - debugServer:Step() - fIsRunning = 1 - - UpdateUIMenuItems() - end - DisplayOutput("Client connected\n") - - end) - - function DebuggerIgnoreFile(fileName) - ignoreFlag = nil - for idx, ignoreFile in pairs(ignoredFilesList) do - if string.upper(ignoreFile) == string.upper(fileName) then - ignoreFlag = 1 - end - end - return ignoreFlag - end - - editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_BREAK, - function (event) - if exitingProgram then return end - local row = event:GetLineNumber() - local eventFileName = event:GetFileName() - if string.sub(eventFileName, 1, 1) == '@' then - eventFileName = string.sub(eventFileName, 2, -1) - if wx.wxIsAbsolutePath(eventFileName) == false then - eventFileName = wx.wxGetCwd().."/"..eventFileName - end - end - if wx.wxPlatformWindows then - eventFileName = wx.wxUnix2DosFilename(eventFileName) - end - local fileFound = false - DisplayOutput("At Breakpoint line: "..tostring(row).." file: "..eventFileName.."\n") - for id, document in pairs(openDocuments) do - local editor = document.editor - local filePath = MakeDebugFileName(editor, document.filePath) - -- for running in cygwin, use same type of separators - filePath = string.gsub(filePath, "\\", "/") - local eventFileName_ = string.gsub(eventFileName, "\\", "/") - if string.upper(filePath) == string.upper(eventFileName_) then - local selection = document.index - notebook:SetSelection(selection) - SetEditorSelection(selection) - editor:MarkerAdd(row, CURRENT_LINE_MARKER) - editor:EnsureVisibleEnforcePolicy(row) - fileFound = true - break - end - end - if not DebuggerIgnoreFile(eventFileName) then - if not fileFound then - local fileDialog = wx.wxFileDialog(frame, - "Select file for debugging", - "", - eventFileName, - "Lua files (*.lua)|*.lua|Text files (*.txt)|*.txt|All files (*)|*", - wx.wxOPEN) - if fileDialog:ShowModal() == wx.wxID_OK then - local editor = LoadFile(fileDialog:GetPath(), fileDialog:GetFilename()) - if editor then - editor:MarkerAdd(row, CURRENT_LINE_MARKER) - editor:EnsureVisibleEnforcePolicy(row) - editor:SetReadOnly(true) - fileFound = true - end - end - fileDialog:Destroy() - end - if not fileFound then - table.insert(ignoredFilesList, eventFileName) - end - end - - if fileFound then - fIsRunning = nil - ProcessWatches() - elseif debugServer then - debugServer:Continue() - fIsRunning = 1 - end - end) - - function DisplayOutput(message) - if splitter:IsSplit() == false then - local x, y = frame:GetClientSize() - splitter:SplitHorizontally(notebook, errorLog, (2 * y) / 3) - end - errorLog:SetReadOnly(false) - errorLog:AddText(message) - errorLog:SetReadOnly(true) - end - - editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_PRINT, - function (event) - DisplayOutput(event:GetMessage().."\n") - end) - - editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_ERROR, - function (event) - DisplayOutput("wxLua ERROR: "..event:GetMessage().."\n") - end) - - editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_EXIT, - function (event) - for id, document in pairs(openDocuments) do - local editor = document.editor - editor:MarkerDeleteAll(CURRENT_LINE_MARKER) - end - fIsConnected = nil - if debugServer then - debugServer:Delete() - fIsRunning = nil - debugServer = nil - end - SetAllEditorsReadOnly(false) - ignoredFilesList = {} - DisplayOutput("\nDebugger Client finished\n\n") - end) - - editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUGGER_EVALUATE_EXPR, - function (event) - if watchListCtrl then - watchListCtrl:SetStringItem(event:GetReference(), - 1, - event:GetMessage()) - end - end) - -- --------------------------------------------------------------------------- -- Create the Help menu and attach the callback functions --- 1823,1826 ---- |