gui = {} gui.xrc = "./core/gui.xrc" --// Load the XRC resource file to be displayed local res = wx.wxXmlResource() res:InitAllHandlers() res:Load(gui.xrc) gui.frame = wx.wxDialog() if res:LoadDialog(gui.frame, wx.NULL, "ID_WXDIALOG") == false then wx.wxMessageBox("Error loading XRC resource file "..gui.xrc, "Error", wx.wxOK + wx.wxICON_ERROR) wx.wxExit(0) end --// Manage the events gui.SelectFile = gui.frame:FindWindow(res.GetXRCID("ID_SELECT_FILE")):DynamicCast("wxFilePickerCtrl") gui.SelectFile:Connect(wx.wxID_ANY, wx.wxEVT_COMMAND_FILEPICKER_CHANGED, function (event) gui.Filename = gui.SelectFile:GetPath() loadEditor(gui.EditFile,gui.Filename) end) gui.SelectFile:SetPath("./scripts/") gui.EditFile = gui.frame:FindWindow(res.GetXRCID("ID_EDIT_FILE")):DynamicCast("wxPanel") gui.SaveFile = gui.frame:FindWindow(res.GetXRCID("ID_SAVE_FILE")):DynamicCast("wxButton") gui.SaveFile:Connect(wx.wxEVT_COMMAND_BUTTON_CLICKED, function (event) if gui.SelectFile:GetTextCtrl():GetValue() ~= "" then gui.Filename = gui.SelectFile:GetTextCtrl():GetValue() end if gui.Filename == nil then wx.wxMessageBox("Specify at least a translation filename !", "Error", wx.wxOK + wx.wxICON_ERROR) elseif wx.wxMessageBox("Do you really want to save "..gui.Filename.." ?", "Confirmation", wx.wxYES_NO + wx.wxICON_QUESTION) == wx.wxYES then saveEditor(gui.Filename) end end) gui.SelectDir = gui.frame:FindWindow(res.GetXRCID("ID_SELECT_DIR")):DynamicCast("wxDirPickerCtrl") gui.SelectDir:Connect(wx.wxID_ANY, wx.wxEVT_COMMAND_DIRPICKER_CHANGED, function (event) gui.Dirname = gui.SelectDir:GetPath() wx.wxBeginBusyCursor() filefulldir(gui.Dirname) fulldirprv = nil gui.EditDir:ClearAll() gui.EditDir:InsertColumn(0, "Type", wx.wxLIST_FORMAT_LEFT, 40) gui.EditDir:InsertColumn(1, "Name", wx.wxLIST_FORMAT_LEFT, 180) gui.EditDir:InsertColumn(2, "Size", wx.wxLIST_FORMAT_LEFT, 80) gui.EditDir:InsertColumn(3, "Path", wx.wxLIST_FORMAT_LEFT, 320) for i,j in pairs(fulldir) do local row = gui.EditDir:InsertItem(i-1, j[1]) gui.EditDir:SetItem(row, 0, j[1]) gui.EditDir:SetItem(row, 1, j[2]) gui.EditDir:SetItem(row, 2, tostring(j[3])) gui.EditDir:SetItem(row, 3, j[4]) if j[1]=="dir" then gui.EditDir:SetItemBackgroundColour(row, wx.wxColour(155,255,255)) end end wx.wxEndBusyCursor() end) gui.EditDir = gui.frame:FindWindow(res.GetXRCID("ID_EDIT_DIR")):DynamicCast("wxListCtrl") gui.PreviewDir = gui.frame:FindWindow(res.GetXRCID("ID_PREVIEW_DIR")):DynamicCast("wxButton") gui.PreviewDir:Connect(wx.wxEVT_COMMAND_BUTTON_CLICKED, function (event) fulldirprv = nil if getTextEditor() == "" then wx.wxMessageBox("Select a translation script to run, click [Browse] button", "Error", wx.wxOK + wx.wxICON_ERROR) elseif fulldir == nil then wx.wxMessageBox("Select a directory, click [Browse] button", "Error", wx.wxOK + wx.wxICON_ERROR) else wx.wxBeginBusyCursor() local fnc = loadstring("function OnStart() end function OnRun(type,name,path,size) end function OnStop() end") fnc() fnc,err = loadstring(getTextEditor()) if fnc==nil then error(err) end fnc() OnStart() local k=1 fulldirprv = {} for i,j in pairs(fulldir) do j[5] = tostring(OnRun(j[1],j[2],j[4],j[3])) if j[5]~=j[2] then fulldirprv[k] = fulldir[i] k = k + 1 end end gui.EditDir:ClearAll() gui.EditDir:InsertColumn(0, "Type", wx.wxLIST_FORMAT_LEFT, 40) gui.EditDir:InsertColumn(1, "Name", wx.wxLIST_FORMAT_LEFT, 180) gui.EditDir:InsertColumn(2, "New Name", wx.wxLIST_FORMAT_LEFT, 180) gui.EditDir:InsertColumn(3, "Size", wx.wxLIST_FORMAT_LEFT, 80) gui.EditDir:InsertColumn(4, "Path", wx.wxLIST_FORMAT_LEFT, 320) for i,j in pairs(fulldirprv) do local row = gui.EditDir:InsertItem(i-1, j[1]) gui.EditDir:SetItem(row, 0, j[1]) gui.EditDir:SetItem(row, 1, j[2]) gui.EditDir:SetItem(row, 2, j[5]) gui.EditDir:SetItem(row, 3, tostring(j[3])) gui.EditDir:SetItem(row, 4, j[4]) if j[1]=="dir" then gui.EditDir:SetItemBackgroundColour(row, wx.wxColour(155,255,255)) end end wx.wxEndBusyCursor() end end) gui.ApplyDir = gui.frame:FindWindow(res.GetXRCID("ID_APPLY_DIR")):DynamicCast("wxButton") gui.ApplyDir:Connect(wx.wxEVT_COMMAND_BUTTON_CLICKED, function (event) if fulldirprv == nil then wx.wxMessageBox("Click [Preview] button first", "Error", wx.wxOK + wx.wxICON_ERROR) else local row = gui.EditDir:GetSelectedItemCount() if row > 0 then if wx.wxMessageBox("Do you really want to apply changes to "..row.." item(s)", "Script Renamer", wx.wxYES_NO + wx.wxICON_QUESTION) == wx.wxYES then wx.wxBeginBusyCursor() local i=-1 while true do i = gui.EditDir:GetNextItem(i, wx.wxLIST_NEXT_ALL, wx.wxLIST_STATE_SELECTED) if i == -1 then break else if fulldirprv[i+1][5] ~= "" and fulldirprv[i+1][2] ~= fulldirprv[i+1][5] then local _,err = os.rename(fulldirprv[i+1][4].."/"..fulldirprv[i+1][2],fulldirprv[i+1][4].."/"..fulldirprv[i+1][5]) if err then fulldirprv[i+1][6] = "KO : "..err else fulldirprv[i+1][6] = "OK" end end end end gui.EditDir:ClearAll() gui.EditDir:InsertColumn(0, "Type", wx.wxLIST_FORMAT_LEFT, 40) gui.EditDir:InsertColumn(1, "Name", wx.wxLIST_FORMAT_LEFT, 180) gui.EditDir:InsertColumn(2, "Old Name", wx.wxLIST_FORMAT_LEFT, 180) gui.EditDir:InsertColumn(3, "Result", wx.wxLIST_FORMAT_LEFT, 180) gui.EditDir:InsertColumn(4, "Size", wx.wxLIST_FORMAT_LEFT, 80) gui.EditDir:InsertColumn(5, "Path", wx.wxLIST_FORMAT_LEFT, 320) for i,j in pairs(fulldirprv) do if j[6]~="" then local row = gui.EditDir:InsertItem(i-1, j[1]) gui.EditDir:SetItem(row, 0, j[1]) gui.EditDir:SetItem(row, 1, j[5]) gui.EditDir:SetItem(row, 2, j[2]) gui.EditDir:SetItem(row, 3, j[6]) gui.EditDir:SetItem(row, 4, tostring(j[3])) gui.EditDir:SetItem(row, 5, j[4]) if j[6]~="OK" then gui.EditDir:SetItemBackgroundColour(row, wx.wxColour(255,155,155)) end end end wx.wxEndBusyCursor() end fulldir = nil else wx.wxMessageBox("Select at least one item to apply changes", "Script Renamer", wx.wxOK + wx.wxICON_EXCLAMATION) end end end) gui.frame:Connect(wx.wxEVT_CLOSE_WINDOW, function (event) if gui.SelectFile:GetTextCtrl():GetValue() ~= "" then gui.Filename = gui.SelectFile:GetTextCtrl():GetValue() end if gui.Filename ~= nil then if wx.wxMessageBox("Do you really want to save "..gui.Filename.." ?", "Confirmation", wx.wxYES_NO + wx.wxICON_QUESTION) == wx.wxYES then saveEditor(gui.Filename) end end wx.wxExit(0) end) --// Everything is initialized now we can display the frame function OnError(msg) local i,j,k = string.find(msg,"]:(.+)\nstack") if k~=nil then wx.wxMessageBox("Line "..k, "Script Error", wx.wxOK + wx.wxICON_ERROR) else wx.wxMessageBox(msg, "System Error", wx.wxOK + wx.wxICON_ERROR) end wx.wxEndBusyCursor() end createEditor(gui.EditFile) --gui.frame:SetTitle("") gui.frame:Centre() gui.frame:Show(true)