From: John L. <jr...@us...> - 2006-09-22 22:29:25
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv4748/wxLua/samples Modified Files: editor.wx.lua Log Message: unify some of the event handling Index: editor.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/editor.wx.lua,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** editor.wx.lua 20 Sep 2006 04:07:38 -0000 1.22 --- editor.wx.lua 22 Sep 2006 22:29:21 -0000 1.23 *************** *** 804,808 **** function SaveFile(editor, filePath) - local saved = nil local st = editor:GetText() local backPath = filePath..".bak" --- 804,807 ---- *************** *** 815,821 **** editor:EmptyUndoBuffer() SetDocumentModified(editor:GetId(), nil, true) ! saved = 1 end ! return saved end --- 814,821 ---- editor:EmptyUndoBuffer() SetDocumentModified(editor:GetId(), nil, true) ! return true end ! ! return false end *************** *** 878,893 **** SaveFileAs(editor) end) - frame:Connect(ID_SAVEAS, wx.wxEVT_UPDATE_UI, function (event) local editor = GetEditor() ! if editor then ! local id = editor:GetId() ! if openDocuments[id] then ! event:Enable(openDocuments[id].isModified ~= nil) ! end ! else ! event:Enable(false) ! end end) --- 878,885 ---- SaveFileAs(editor) end) frame:Connect(ID_SAVEAS, wx.wxEVT_UPDATE_UI, function (event) local editor = GetEditor() ! event:Enable(editor ~= nil) end) *************** *** 1053,1126 **** editMenu:Check(ID_AUTOCOMPLETE_ENABLE, autoCompleteEnable) ! function EnableEditorMenuItem(event) local editor = GetEditor() event:Enable(editor ~= nil) end ! frame:Connect(ID_CUT, wx.wxEVT_COMMAND_MENU_SELECTED, ! function (event) ! local editor = GetEditor() ! editor:Cut() ! end) ! frame:Connect(ID_CUT, wx.wxEVT_UPDATE_UI, ! function(event) ! EnableEditorMenuItem(event) ! end) ! frame:Connect(ID_COPY, wx.wxEVT_COMMAND_MENU_SELECTED, ! function (event) ! local editor = GetEditor() ! editor:Copy() ! end) ! frame:Connect(ID_COPY, wx.wxEVT_UPDATE_UI, ! function(event) ! EnableEditorMenuItem(event) ! end) ! frame:Connect(ID_PASTE, wx.wxEVT_COMMAND_MENU_SELECTED, ! function (event) ! local editor = GetEditor() ! editor:Paste() ! end) frame:Connect(ID_PASTE, wx.wxEVT_UPDATE_UI, function (event) local editor = GetEditor() ! if editor then ! -- buggy GTK clipboard runs eventloop and can generate asserts ! if not wx.__WXGTK__ then ! event:Enable(editor:CanPaste()) ! else ! event:Enable(true) ! end ! else ! event:Enable(false) ! end end) ! frame:Connect(ID_CLEAR, wx.wxEVT_COMMAND_MENU_SELECTED, ! function (event) ! local editor = GetEditor() ! editor:Clear() ! end) ! frame:Connect(ID_CLEAR, wx.wxEVT_UPDATE_UI, ! function(event) ! EnableEditorMenuItem(event) ! end) ! frame:Connect(ID_SELECTALL, wx.wxEVT_COMMAND_MENU_SELECTED, ! function (event) ! local editor = GetEditor() ! editor:SelectAll() ! end) ! frame:Connect(ID_SELECTALL, wx.wxEVT_UPDATE_UI, ! function(event) ! EnableEditorMenuItem(event) ! end) ! frame:Connect(ID_UNDO, wx.wxEVT_COMMAND_MENU_SELECTED, ! function (event) ! local editor = GetEditor() ! editor:Undo() ! end) frame:Connect(ID_UNDO, wx.wxEVT_UPDATE_UI, function (event) --- 1045,1090 ---- editMenu:Check(ID_AUTOCOMPLETE_ENABLE, autoCompleteEnable) ! function OnUpdateUIEditMenu(event) -- enable if there is a valid focused editor local editor = GetEditor() event:Enable(editor ~= nil) end ! function OnEditMenu(event) ! local menu_id = event:GetId() ! local editor = GetEditor() ! if editor == nil then return end ! if menu_id == ID_CUT then editor:Cut() ! elseif menu_id == ID_COPY then editor:Copy() ! elseif menu_id == ID_PASTE then editor:Paste() ! elseif menu_id == ID_CLEAR then editor:Clear() ! elseif menu_id == ID_SELECTALL then editor:SelectAll() ! elseif menu_id == ID_UNDO then editor:Undo() ! elseif menu_id == ID_REDO then editor:Redo() ! end ! end ! ! frame:Connect(ID_CUT, wx.wxEVT_COMMAND_MENU_SELECTED, OnEditMenu) ! frame:Connect(ID_CUT, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) ! ! frame:Connect(ID_COPY, wx.wxEVT_COMMAND_MENU_SELECTED, OnEditMenu) ! frame:Connect(ID_COPY, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) ! ! frame:Connect(ID_PASTE, wx.wxEVT_COMMAND_MENU_SELECTED, OnEditMenu) frame:Connect(ID_PASTE, wx.wxEVT_UPDATE_UI, function (event) local editor = GetEditor() ! -- buggy GTK clipboard runs eventloop and can generate asserts ! event:Enable(editor and (wx.__WXGTK__ or editor:CanPaste())) end) ! frame:Connect(ID_CLEAR, wx.wxEVT_COMMAND_MENU_SELECTED, OnEditMenu) ! frame:Connect(ID_CLEAR, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) ! frame:Connect(ID_SELECTALL, wx.wxEVT_COMMAND_MENU_SELECTED, OnEditMenu) ! frame:Connect(ID_SELECTALL, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) ! frame:Connect(ID_UNDO, wx.wxEVT_COMMAND_MENU_SELECTED, OnEditMenu) frame:Connect(ID_UNDO, wx.wxEVT_UPDATE_UI, function (event) *************** *** 1129,1137 **** end) ! frame:Connect(ID_REDO, wx.wxEVT_COMMAND_MENU_SELECTED, ! function (event) ! local editor = GetEditor() ! editor:Redo() ! end) frame:Connect(ID_REDO, wx.wxEVT_UPDATE_UI, function (event) --- 1093,1097 ---- end) ! frame:Connect(ID_REDO, wx.wxEVT_COMMAND_MENU_SELECTED, OnEditMenu) frame:Connect(ID_REDO, wx.wxEVT_UPDATE_UI, function (event) *************** *** 1143,1146 **** --- 1103,1107 ---- function (event) local editor = GetEditor() + if (editor == nil) then return end local pos = editor:GetCurrentPos() local start_pos = editor:WordStartPosition(pos, true) *************** *** 1157,1164 **** end end) ! frame:Connect(ID_AUTOCOMPLETE, wx.wxEVT_UPDATE_UI, ! function(event) ! EnableEditorMenuItem(event) ! end) frame:Connect(ID_AUTOCOMPLETE_ENABLE, wx.wxEVT_COMMAND_MENU_SELECTED, --- 1118,1122 ---- end end) ! frame:Connect(ID_AUTOCOMPLETE, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) frame:Connect(ID_AUTOCOMPLETE_ENABLE, wx.wxEVT_COMMAND_MENU_SELECTED, *************** *** 1177,1181 **** frame:Connect(ID_CLEAROUTPUT, wx.wxEVT_UPDATE_UI, function(event) ! EnableEditorMenuItem(event) end) --- 1135,1139 ---- frame:Connect(ID_CLEAROUTPUT, wx.wxEVT_UPDATE_UI, function(event) ! event:Enable(errorLog and errorLog:IsShown()) end) *************** *** 1402,1409 **** FindReplace() end) ! frame:Connect(ID_FIND, wx.wxEVT_UPDATE_UI, ! function (event) ! EnableEditorMenuItem(event) ! end) frame:Connect(ID_FINDNEXT, wx.wxEVT_COMMAND_MENU_SELECTED, --- 1360,1364 ---- FindReplace() end) ! frame:Connect(ID_FIND, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) frame:Connect(ID_FINDNEXT, wx.wxEVT_COMMAND_MENU_SELECTED, *************** *** 1433,1440 **** FindReplace(1) end) ! frame:Connect(ID_REPLACE, wx.wxEVT_UPDATE_UI, ! function (event) ! EnableEditorMenuItem(event) ! end) frame:Connect(ID_GOTOLINE, wx.wxEVT_COMMAND_MENU_SELECTED, --- 1388,1392 ---- FindReplace(1) end) ! frame:Connect(ID_REPLACE, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) frame:Connect(ID_GOTOLINE, wx.wxEVT_COMMAND_MENU_SELECTED, *************** *** 1452,1459 **** end end) ! frame:Connect(ID_GOTOLINE, wx.wxEVT_UPDATE_UI, ! function (event) ! EnableEditorMenuItem(event) ! end) -- --------------------------------------------------------------------------- --- 1404,1408 ---- end end) ! frame:Connect(ID_GOTOLINE, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) -- --------------------------------------------------------------------------- *************** *** 1520,1527 **** ToggleDebugMarker(editor, row) end) ! frame:Connect(ID_TOGGLEBREAKPOINT, wx.wxEVT_UPDATE_UI, ! function(event) ! EnableEditorMenuItem(event) ! end) frame:Connect(ID_COMPILE, wx.wxEVT_COMMAND_MENU_SELECTED, --- 1469,1473 ---- ToggleDebugMarker(editor, row) end) ! frame:Connect(ID_TOGGLEBREAKPOINT, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) frame:Connect(ID_COMPILE, wx.wxEVT_COMMAND_MENU_SELECTED, *************** *** 1533,1540 **** wx.wxLuaDebuggerServerCompile(filePath, editorText) end) ! frame:Connect(ID_COMPILE, wx.wxEVT_UPDATE_UI, ! function (event) ! EnableEditorMenuItem(event) ! end) frame:Connect(ID_RUN, wx.wxEVT_COMMAND_MENU_SELECTED, --- 1479,1483 ---- wx.wxLuaDebuggerServerCompile(filePath, editorText) end) ! frame:Connect(ID_COMPILE, wx.wxEVT_UPDATE_UI, OnUpdateUIEditMenu) frame:Connect(ID_RUN, wx.wxEVT_COMMAND_MENU_SELECTED, |