From: John L. <jr...@us...> - 2006-09-07 04:20:57
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv22903/wxLua/samples Modified Files: editor.wx.lua Log Message: cleanup and formatting in the wxlua editor.wx.lua move SetStackDialog to the wxLuaHandler so it can be used by other programs more easily start work on using the socket code in the wxluaeditor formatting in wxldserv.cpp Index: editor.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/editor.wx.lua,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** editor.wx.lua 25 May 2006 03:55:23 -0000 1.18 --- editor.wx.lua 7 Sep 2006 04:20:54 -0000 1.19 *************** *** 115,138 **** statusBar = frame:CreateStatusBar( 4 ) toolBar = frame:CreateToolBar(wx.wxNO_BORDER + wx.wxTB_FLAT + wx.wxTB_DOCKABLE) -- note: Ususally the bmp size isn't necessary, but the HELP icon is not the right size in MSW local toolBmpSize = toolBar:GetToolBitmapSize() ! toolBar:AddToolSimple(ID_NEW, "New", wx.wxArtProvider_GetBitmap(wx.wxART_NORMAL_FILE, wx.wxART_MENU, toolBmpSize), "Creates an empty document") ! toolBar:AddToolSimple(ID_OPEN, "Open", wx.wxArtProvider_GetBitmap(wx.wxART_FILE_OPEN, wx.wxART_MENU, toolBmpSize), "Opens an existing document") ! toolBar:AddToolSimple(ID_SAVE, "Save", wx.wxArtProvider_GetBitmap(wx.wxART_FILE_SAVE, wx.wxART_MENU, toolBmpSize), "Saves the document") ! toolBar:AddToolSimple(ID_SAVEALL, "Save All", wx.wxArtProvider_GetBitmap(wx.wxART_NEW_DIR, wx.wxART_MENU, toolBmpSize), "Saves all documents") toolBar:AddSeparator() ! toolBar:AddToolSimple(ID_CUT, "Cut", wx.wxArtProvider_GetBitmap(wx.wxART_CUT, wx.wxART_MENU, toolBmpSize), "Cut the selection") ! toolBar:AddToolSimple(ID_COPY, "Copy", wx.wxArtProvider_GetBitmap(wx.wxART_COPY, wx.wxART_MENU, toolBmpSize), "Copy the selection") ! toolBar:AddToolSimple(ID_PASTE, "Paste", wx.wxArtProvider_GetBitmap(wx.wxART_PASTE, wx.wxART_MENU, toolBmpSize), "Paste the clipboard") toolBar:AddSeparator() toolBar:AddToolSimple(ID_UNDO, "Undo", wx.wxArtProvider_GetBitmap(wx.wxART_UNDO, wx.wxART_MENU, toolBmpSize), "Undo last edit") ! toolBar:AddToolSimple(ID_REDO, "Redo", wx.wxArtProvider_GetBitmap(wx.wxART_REDO, wx.wxART_MENU, toolBmpSize), "Redo last undo") toolBar:AddSeparator() toolBar:AddToolSimple(ID_FIND, "Find", wx.wxArtProvider_GetBitmap(wx.wxART_FIND, wx.wxART_MENU, toolBmpSize), "Find text") toolBar:AddToolSimple(ID_REPLACE, "Replace", wx.wxArtProvider_GetBitmap(wx.wxART_FIND_AND_REPLACE, wx.wxART_MENU, toolBmpSize), "Find and replace text") toolBar:AddSeparator() ! toolBar:AddToolSimple(ID_ABOUT, "About", wx.wxArtProvider_GetBitmap(wx.wxART_HELP, wx.wxART_MENU, toolBmpSize), "About wxLua IDE") toolBar:Realize() --- 115,141 ---- statusBar = frame:CreateStatusBar( 4 ) + local status_txt_width = statusBar:GetTextExtent("OVR ") + frame:SetStatusWidths{-1, status_txt_width+4, status_txt_width+4, 150} + frame:SetStatusText("Ready") toolBar = frame:CreateToolBar(wx.wxNO_BORDER + wx.wxTB_FLAT + wx.wxTB_DOCKABLE) -- note: Ususally the bmp size isn't necessary, but the HELP icon is not the right size in MSW local toolBmpSize = toolBar:GetToolBitmapSize() ! toolBar:AddToolSimple(ID_NEW, "New", wx.wxArtProvider_GetBitmap(wx.wxART_NORMAL_FILE, wx.wxART_MENU, toolBmpSize), "Creates an empty document") ! toolBar:AddToolSimple(ID_OPEN, "Open", wx.wxArtProvider_GetBitmap(wx.wxART_FILE_OPEN, wx.wxART_MENU, toolBmpSize), "Opens an existing document") ! toolBar:AddToolSimple(ID_SAVE, "Save", wx.wxArtProvider_GetBitmap(wx.wxART_FILE_SAVE, wx.wxART_MENU, toolBmpSize), "Saves the document") ! toolBar:AddToolSimple(ID_SAVEALL, "Save All", wx.wxArtProvider_GetBitmap(wx.wxART_NEW_DIR, wx.wxART_MENU, toolBmpSize), "Saves all documents") toolBar:AddSeparator() ! toolBar:AddToolSimple(ID_CUT, "Cut", wx.wxArtProvider_GetBitmap(wx.wxART_CUT, wx.wxART_MENU, toolBmpSize), "Cut the selection") ! toolBar:AddToolSimple(ID_COPY, "Copy", wx.wxArtProvider_GetBitmap(wx.wxART_COPY, wx.wxART_MENU, toolBmpSize), "Copy the selection") ! toolBar:AddToolSimple(ID_PASTE, "Paste", wx.wxArtProvider_GetBitmap(wx.wxART_PASTE, wx.wxART_MENU, toolBmpSize), "Paste the clipboard") toolBar:AddSeparator() toolBar:AddToolSimple(ID_UNDO, "Undo", wx.wxArtProvider_GetBitmap(wx.wxART_UNDO, wx.wxART_MENU, toolBmpSize), "Undo last edit") ! toolBar:AddToolSimple(ID_REDO, "Redo", wx.wxArtProvider_GetBitmap(wx.wxART_REDO, wx.wxART_MENU, toolBmpSize), "Redo last undo") toolBar:AddSeparator() toolBar:AddToolSimple(ID_FIND, "Find", wx.wxArtProvider_GetBitmap(wx.wxART_FIND, wx.wxART_MENU, toolBmpSize), "Find text") toolBar:AddToolSimple(ID_REPLACE, "Replace", wx.wxArtProvider_GetBitmap(wx.wxART_FIND_AND_REPLACE, wx.wxART_MENU, toolBmpSize), "Find and replace text") toolBar:AddSeparator() ! toolBar:AddToolSimple(ID_ABOUT, "About", wx.wxArtProvider_GetBitmap(wx.wxART_HELP, wx.wxART_MENU, toolBmpSize), "About wxLua IDE") toolBar:Realize() *************** *** 222,225 **** --- 225,229 ---- end + -- ---------------------------------------------------------------------------- -- Get the current editor page of the notebook or nil if none function getEditor(selection) *************** *** 234,237 **** --- 238,250 ---- end + function setEditorSelection(selection) + local editor = getEditor(selection) + if editor then + editor:SetFocus() + isFileAlteredOnDisk(editor) + end + updateStatusText(editor) + end + -- Update the statusbar text of the frame using the given editor function updateStatusText(editor) *************** *** 261,270 **** end ! function getModTime(filePath) local fileName = wx.wxFileName(filePath) return fileName:GetModificationTime(); end ! function isAlteredOnDisk(editor) local id = editor:GetId() if openDocuments[id] then --- 274,283 ---- end ! function getFileModTime(filePath) local fileName = wx.wxFileName(filePath) return fileName:GetModificationTime(); end ! function isFileAlteredOnDisk(editor) local id = editor:GetId() if openDocuments[id] then *************** *** 275,279 **** if filePath and (string.len(filePath) > 0) then if oldModTime and oldModTime:IsValid() then ! local modTime = getModTime(filePath) if modTime:IsValid() and oldModTime:IsEarlierThan(modTime) then local ret = wx.wxMessageBox(fileName.." has been modified on disk. Do you want to reload it?", --- 288,292 ---- if filePath and (string.len(filePath) > 0) then if oldModTime and oldModTime:IsValid() then ! local modTime = getFileModTime(filePath) if modTime:IsValid() and oldModTime:IsEarlierThan(modTime) then local ret = wx.wxMessageBox(fileName.." has been modified on disk. Do you want to reload it?", *************** *** 299,304 **** end end - else - openDocuments[id].modTime = modTime -- set the time end end --- 312,315 ---- *************** *** 306,331 **** end - function setEditorSelection(selection) - local editor = getEditor(selection) - if editor then - editor:SetFocus() - isAlteredOnDisk(editor) - end - updateStatusText(editor) - end - - function createAutoCompList(key) - --local len = string.len(key) - local userList = {} - for index, value in pairs(wx) do - --if string.sub(index, 1, len) == key then - if string.find(index, key, 1, 1) == 1 then -- perhaps faster? - table.insert(userList, index.." ") - end - end - table.sort(userList) - return table.concat(userList) - end - function setDocumentModified(id, modified, resetModTime) local fileName = openDocuments[id].fileName --- 317,320 ---- *************** *** 340,344 **** openDocuments[id].isModified = nil if resetModTime and filePath and string.len(filePath) > 0 then ! openDocuments[id].modTime = getModTime(filePath) end notebook:SetPageText(openDocuments[id].index, fileName) --- 329,333 ---- openDocuments[id].isModified = nil if resetModTime and filePath and string.len(filePath) > 0 then ! openDocuments[id].modTime = getFileModTime(filePath) end notebook:SetPageText(openDocuments[id].index, fileName) *************** *** 476,480 **** end) ! editor:Connect(wx.wxEVT_STC_MODIFIED, function ( event ) end) editor:Connect(wx.wxEVT_STC_SAVEPOINTREACHED, --- 465,469 ---- end) ! --editor:Connect(wx.wxEVT_STC_MODIFIED, function ( event ) end) editor:Connect(wx.wxEVT_STC_SAVEPOINTREACHED, *************** *** 515,519 **** editor:SetLexer(wx.wxSTC_LEX_LUA) ! -- Note: these keywords are shameless ripped from scite 1.68 editor:SetKeyWords(0, [[and break do else elseif end false for function if --- 504,508 ---- editor:SetLexer(wx.wxSTC_LEX_LUA) ! -- Note: these keywords are shamelessly ripped from scite 1.68 editor:SetKeyWords(0, [[and break do else elseif end false for function if *************** *** 556,560 **** editor:SetKeyWords(5, table.concat(wxkeywords)) - else editor:SetLexer(wx.wxSTC_LEX_NULL) --- 545,548 ---- *************** *** 563,566 **** --- 551,567 ---- end + function createAutoCompList(key) + --local len = string.len(key) + local userList = {} + for index, value in pairs(wx) do + --if string.sub(index, 1, len) == key then + if string.find(index, key, 1, 1) == 1 then -- perhaps faster? + table.insert(userList, index.." ") + end + end + table.sort(userList) + return table.concat(userList) + end + menuBar = wx.wxMenuBar() fileMenu = wx.wxCreateMenu{ *************** *** 612,616 **** openDocuments[id].filePath = filePath openDocuments[id].fileName = fileName ! openDocuments[id].modTime = getModTime(filePath) notebook:SetPageText(openDocuments[id].index, fileName) saved = 1 --- 613,617 ---- openDocuments[id].filePath = filePath openDocuments[id].fileName = fileName ! openDocuments[id].modTime = getFileModTime(filePath) notebook:SetPageText(openDocuments[id].index, fileName) saved = 1 *************** *** 864,873 **** end ! function enableMenuItem( event ) local editor = getEditor() event:Enable(editor ~= nil) end ! function findSelectedItem() local count = watchListCtrl:GetSelectedItemCount() if count > 0 then --- 865,874 ---- end ! function enableEditorMenuItem( event ) local editor = getEditor() event:Enable(editor ~= nil) end ! function findSelectedWatchItem() local count = watchListCtrl:GetSelectedItemCount() if count > 0 then *************** *** 956,960 **** watchWindow:Connect(ID_EDITWATCH, wx.wxEVT_COMMAND_MENU_SELECTED, function ( event ) ! local row = findSelectedItem() if row >= 0 then watchListCtrl:EditLabel(row) --- 957,961 ---- watchWindow:Connect(ID_EDITWATCH, wx.wxEVT_COMMAND_MENU_SELECTED, function ( event ) ! local row = findSelectedWatchItem() if row >= 0 then watchListCtrl:EditLabel(row) *************** *** 968,972 **** watchWindow:Connect(ID_REMOVEWATCH, wx.wxEVT_COMMAND_MENU_SELECTED, function ( event ) ! local row = findSelectedItem() if row >= 0 then watchListCtrl:DeleteItem(row) --- 969,973 ---- watchWindow:Connect(ID_REMOVEWATCH, wx.wxEVT_COMMAND_MENU_SELECTED, function ( event ) ! local row = findSelectedWatchItem() if row >= 0 then watchListCtrl:DeleteItem(row) *************** *** 1062,1066 **** frame:Connect(ID_CUT, wx.wxEVT_UPDATE_UI, function(event) ! enableMenuItem(event) end) --- 1063,1067 ---- frame:Connect(ID_CUT, wx.wxEVT_UPDATE_UI, function(event) ! enableEditorMenuItem(event) end) *************** *** 1072,1076 **** frame:Connect(ID_COPY, wx.wxEVT_UPDATE_UI, function(event) ! enableMenuItem(event) end) --- 1073,1077 ---- frame:Connect(ID_COPY, wx.wxEVT_UPDATE_UI, function(event) ! enableEditorMenuItem(event) end) *************** *** 1102,1106 **** frame:Connect(ID_CLEAR, wx.wxEVT_UPDATE_UI, function(event) ! enableMenuItem(event) end) --- 1103,1107 ---- frame:Connect(ID_CLEAR, wx.wxEVT_UPDATE_UI, function(event) ! enableEditorMenuItem(event) end) *************** *** 1112,1116 **** frame:Connect(ID_SELECTALL, wx.wxEVT_UPDATE_UI, function(event) ! enableMenuItem(event) end) --- 1113,1117 ---- frame:Connect(ID_SELECTALL, wx.wxEVT_UPDATE_UI, function(event) ! enableEditorMenuItem(event) end) *************** *** 1134,1138 **** frame:Connect(ID_AUTOCOMPLETE, wx.wxEVT_UPDATE_UI, function(event) ! enableMenuItem(event) end) --- 1135,1139 ---- frame:Connect(ID_AUTOCOMPLETE, wx.wxEVT_UPDATE_UI, function(event) ! enableEditorMenuItem(event) end) *************** *** 1153,1157 **** frame:Connect(ID_CLEAROUTPUT, wx.wxEVT_UPDATE_UI, function(event) ! enableMenuItem(event) end) --- 1154,1158 ---- frame:Connect(ID_CLEAROUTPUT, wx.wxEVT_UPDATE_UI, function(event) ! enableEditorMenuItem(event) end) *************** *** 1184,1188 **** findMenu = wx.wxCreateMenu{ ! { ID_FIND, "&Find\tCtrl-F", "Find the specified text" }, { ID_FINDNEXT, "Find &Next\tF3", "Find the next occurrence of the specified text" }, { ID_FINDPREV, "Find &Previous\tShift-F3", "Repeat the search backwards in the file" }, --- 1185,1189 ---- findMenu = wx.wxCreateMenu{ ! { ID_FIND, "&Find\tCtrl-F", "Find the specified text" }, { ID_FINDNEXT, "Find &Next\tF3", "Find the next occurrence of the specified text" }, { ID_FINDPREV, "Find &Previous\tShift-F3", "Repeat the search backwards in the file" }, *************** *** 1407,1411 **** frame:Connect(ID_FIND, wx.wxEVT_UPDATE_UI, function ( event ) ! enableMenuItem(event) end) --- 1408,1412 ---- frame:Connect(ID_FIND, wx.wxEVT_UPDATE_UI, function ( event ) ! enableEditorMenuItem(event) end) *************** *** 1438,1442 **** frame:Connect(ID_REPLACE, wx.wxEVT_UPDATE_UI, function ( event ) ! enableMenuItem(event) end) --- 1439,1443 ---- frame:Connect(ID_REPLACE, wx.wxEVT_UPDATE_UI, function ( event ) ! enableEditorMenuItem(event) end) *************** *** 1457,1484 **** frame:Connect(ID_GOTOLINE, wx.wxEVT_UPDATE_UI, function ( event ) ! enableMenuItem(event) end) - --[[ - function layoutChildren(event) - if toolBar then - local x, y = frame:GetClientSize() - - if wx.__WXMSW__ then - toolBar:SetSize(x, -1) - else - toolBar:SetSize(x, 34) - end - toolBar:Move(0, 0) - - local xoffset, yoffset = toolBar:GetSize() - - splitter:SetDimensions(0, yoffset, x, y - yoffset) - else - event:Skip() - end - end - -- FIXME frame:CreateToolBar lays it out correctly now - --frame:Connect(wx.wxEVT_SIZE, layoutChildren) - ]] function closeWindow(event) --- 1458,1463 ---- frame:Connect(ID_GOTOLINE, wx.wxEVT_UPDATE_UI, function ( event ) ! enableEditorMenuItem(event) end) function closeWindow(event) *************** *** 1535,1539 **** frame:Connect(ID_TOGGLEBREAKPOINT, wx.wxEVT_UPDATE_UI, function(event) ! enableMenuItem(event) end) --- 1514,1518 ---- frame:Connect(ID_TOGGLEBREAKPOINT, wx.wxEVT_UPDATE_UI, function(event) ! enableEditorMenuItem(event) end) *************** *** 1555,1570 **** frame:Connect(ID_RUN, wx.wxEVT_COMMAND_MENU_SELECTED, function ( event ) ! -- FIXME - I don't understand why you would would want to run *all* the notebook pages? --[[ ! local fileList = {} ! saveAll() ! for id, document in pairs(openDocuments) do ! local filePath = document.filePath ! if filePath == nil then ! return ! end ! table.insert(fileList, ' "'..filePath..'"') ! end ! local cmd = '"'..programName..'" '..table.concat(fileList) ]] local editor = getEditor(); --- 1534,1549 ---- frame:Connect(ID_RUN, wx.wxEVT_COMMAND_MENU_SELECTED, function ( event ) ! -- FIXME - I don't understand why you would would want to run *all* the notebook pages? --[[ ! local fileList = {} ! saveAll() ! for id, document in pairs(openDocuments) do ! local filePath = document.filePath ! if filePath == nil then ! return ! end ! table.insert(fileList, ' "'..filePath..'"') ! end ! local cmd = '"'..programName..'" '..table.concat(fileList) ]] local editor = getEditor(); *************** *** 1608,1612 **** frame:Connect(ID_COMPILE, wx.wxEVT_UPDATE_UI, function ( event ) ! enableMenuItem(event) end) --- 1587,1591 ---- frame:Connect(ID_COMPILE, wx.wxEVT_UPDATE_UI, function ( event ) ! enableEditorMenuItem(event) end) *************** *** 1740,1744 **** end) ! editorApp:Connect(-1, wx.wxEVT_WXLUA_DEBUG_CLIENT_CONNECTED, function (event) if debugServer then --- 1719,1723 ---- end) ! editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUG_CLIENT_CONNECTED, function (event) if debugServer then *************** *** 1767,1771 **** end ! editorApp:Connect(-1, wx.wxEVT_WXLUA_DEBUG_BREAK, function (event) if exitingProgram then return end --- 1746,1750 ---- end ! editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUG_BREAK, function (event) if exitingProgram then return end *************** *** 1842,1856 **** end ! editorApp:Connect(-1, wx.wxEVT_WXLUA_DEBUG_PRINT, function (event) displayOutput(event:GetMessage().."\n") end) ! editorApp:Connect(-1, wx.wxEVT_WXLUA_DEBUG_ERROR, function (event) displayOutput(event:GetMessage().."\n") end) ! editorApp:Connect(-1, wx.wxEVT_WXLUA_DEBUG_EXIT, function (event) for id, document in pairs(openDocuments) do --- 1821,1835 ---- end ! editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUG_PRINT, function (event) displayOutput(event:GetMessage().."\n") end) ! editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUG_ERROR, function (event) displayOutput(event:GetMessage().."\n") end) ! editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUG_EXIT, function (event) for id, document in pairs(openDocuments) do *************** *** 1869,1873 **** end) ! editorApp:Connect(-1, wx.wxEVT_WXLUA_DEBUG_EVALUATE_EXPR, function (event) if watchListCtrl then --- 1848,1852 ---- end) ! editorApp:Connect(wx.wxID_ANY, wx.wxEVT_WXLUA_DEBUG_EVALUATE_EXPR, function (event) if watchListCtrl then *************** *** 1953,1958 **** frame:Connect(ID_ABOUT, wx.wxEVT_COMMAND_MENU_SELECTED, displayAbout) - frame:SetStatusWidths{-1, 29, 29, 150} - frame:SetStatusText("Ready") frame:SetMenuBar(menuBar) --- 1932,1935 ---- |