--Script: Script_collector --Version: 1.0 --Author: Maxis mail:m2608@yandex.ru --Note: This script for the organization and management scripts. -- macroScript Script_collector -- category:"Maxis Scripts" ( global DialScriptCollect try (destroyDialog DialScriptCollect) catch() global FolderArr_d global FolderArr = #((getdir #scripts)) global FolderListArr = #("scripts") global ItmPath global Ritem local chkRItem = true local VisDial = true local SetFolderHeight = 70 local DialPos_PosX = 100 local DialPos_PosY = 100 local wdial = 150 local hdial = 300 local fname = (getdir #plugcfg) + "\\ScriptCollector.txt" local Cfile =(getdir #plugcfg) + "\\ScriptCollectorINI.ini" local oldListArr = #() local menuOff = on (-- create a text file at first run fs = "" if (doesFileExist fname) == false then ( fs = createFile fname format "$$FolderArr %\n" FolderArr to:fs format "$$SetFoldrItems %\n" FolderListArr to:fs close fs ) ) if (getINISetting Cfile "ScriptCollector" "DialPos_PosX") == "" then (-- create a ini file at first run setINISetting Cfile "ScriptCollector" "DialPos_PosX" (DialPos_PosX as string) setINISetting Cfile "ScriptCollector" "DialPos_PosY" (DialPos_PosY as string) setINISetting Cfile "ScriptCollector" "DialPos_Width" (wdial as string) setINISetting Cfile "ScriptCollector" "DialPos_Height" (hdial as string) setINISetting Cfile "ScriptCollector" "VisDial" (VisDial as string) setINISetting Cfile "ScriptCollector" "EditChkFile" ("true") setINISetting Cfile "ScriptCollector" "Folder_Height" (SetFolderHeight as string) setiniSetting Cfile "ScriptCollector" "chkRItem" (true as string) ) else( DialPos_PosX = (getINISetting Cfile "ScriptCollector" "DialPos_PosX" as integer) DialPos_PosY = (getINISetting Cfile "ScriptCollector" "DialPos_PosY" as integer) wdial = (getINISetting Cfile "ScriptCollector" "DialPos_Width" as integer) hdial = (getINISetting Cfile "ScriptCollector" "DialPos_Height" as integer) VisDial = (getINISetting Cfile "ScriptCollector" "VisDial" as booleanclass) SetFolderHeight = (getINISetting Cfile "ScriptCollector" "Folder_Height" as integer) chkRItem = (getINISetting Cfile "ScriptCollector" "chkRItem" as booleanclass) ) if Ritem == undefined then (Ritem = 1) fn ReadFolderArr =( fs = openFIle fname skipToString fs "$$FolderArr " FolderArr = readValue fs ignoreStringEscapes:true seek fs 0 skipToString fs "$$SetFoldrItems " FolderListArr = readValue fs close fs DialScriptCollect.lbx_SetFolder.items = FolderListArr ItmPath = FolderArr[Ritem] ) --End ReadFolderArr fn WriteFile =( fs = openFile fname mode:"w+" format "$$FolderArr %\n" FolderArr to:fs format "$$SetFoldrItems %\n" FolderListArr to:fs close fs ) fn getmsfiles =( -- Get ms and mse files in array local MsFiles = #() if DialScriptCollect.btn_getAllFiles.checked == false then (MsFiles = getFiles (ItmPath + "\*.ms*")) -- get single folder else (for i=1 to FolderArr.count do(join MsFiles (getFiles (FolderArr[i] + "\*.ms*")))) -- get all folders for i = 1 to MsFiles.count do (MsFiles[i] = filenameFromPath MsFiles[i]) Iarr = #() for i in MsFiles do( -- Convert all first letter to upper case StrLeng = i.count CutStr = substring i 1 1 Up = toUpper CutStr NewStToArr = Up + (substring i 2 StrLeng) append Iarr NewStToArr ) mk = makeUniqueArray Iarr sort mk DialScriptCollect.lbx_ScriptArray.items = mk ) fn MoveDownarr arr1 numb =( --Move string to down tmparr = copy arr1 #nomap arr1[numb] = tmparr[numb+1] arr1[numb+1] = tmparr[numb] ) fn MoveUParr arr1 numb =( --Move string to Up tmparr = copy arr1 #nomap arr1[numb] = tmparr[numb-1] arr1[numb-1] = tmparr[numb] ) rollout UISet "Settings" width:206 height:271 ( GroupBox grp_edList "Edit List" pos:[5,2] width:197 height:128 label lbl_getNumbItem "__" pos:[13,22] width:14 height:15 label lbl_getSelectItm "Get Selected Item" pos:[31,22] width:112 height:15 button btn_getItm "Get" pos:[149,21] width:46 height:15 GroupBox grp_spr"" pos:[5,11] width:197 height:30 --------------------------------------------------------------------------------------- label lbl_Name "Name:" pos:[13,51] width:31 height:13 edittext edt_name "" pos:[43,48] width:98 height:18 button btn_reName " Rename" pos:[147,47] width:50 height:19 ----- edittext edt_path "" pos:[12,74] width:151 height:18 button btn_getPath "Path" pos:[166,74] width:31 height:18 ----- button btn_addItm "Add" pos:[13,101] width:92 height:19 button btn_delItm "Delete" pos:[111,101] width:85 height:19 ----------------------------------------------------------------------------------------- GroupBox grp_settings "Dialog Settings" pos:[4,134] width:197 height:132 checkbox chk1_visTitleBar " Visible title bar" pos:[15,155] width:100 height:19 checked:VisDial checkbox chk1_Ritem " S Folder" pos:[124,155] width:70 height:19 checked:chkRItem tooltip: "remember the selected item folder" spinner spn_heigthFlist "Folder List Height: " pos:[40,182] width:148 height:16 range:[70,1000,DialScriptCollect.lbx_SetFolder.height] type:#integer scale:1 ----- GroupBox grp4_posDial "Dialog Pos" pos:[8,212] width:189 height:49 spinner spn_posDialX "Pos.x: " pos:[30,235] width:70 height:16 range:[-10000,10000,((GetDialogPos DialScriptCollect).x)] type:#integer scale:1 spinner spn_posDialY "Pos.y: " pos:[122,236] width:70 height:16 range:[-10000,10000,((GetDialogPos DialScriptCollect).y)] type:#integer scale:1 on btn_getItm pressed do( if DialScriptCollect.lbx_SetFolder.selection > 0 do ( lbl_getSelectItm.text = DialScriptCollect.lbx_SetFolder.selected lbl_getNumbItem.text = DialScriptCollect.lbx_SetFolder.selection as string edt_name.text = DialScriptCollect.lbx_SetFolder.selected edt_path.text = FolderArr[DialScriptCollect.lbx_SetFolder.selection] ) ) on btn_reName pressed do( DialScriptCollect.lbx_SetFolder.selected = edt_name.text FolderArr[DialScriptCollect.lbx_SetFolder.selection] = edt_path.text ItmPath = FolderArr[DialScriptCollect.lbx_SetFolder.selection] WriteFile() getmsfiles() oldListArr = DialScriptCollect.lbx_ScriptArray.items ) on btn_getPath pressed do( tmpFolder = getSavePath() if tmpFolder != undefined do( edt_path.text = tmpFolder arr1 = filterstring tmpFolder "\\" Namefolder = arr1[arr1.count] edt_name.text = Namefolder ) ) on btn_addItm pressed do( if DialScriptCollect.lbx_SetFolder.selection > 0 do( if edt_name.text == "" or edt_path.text == "" then messagebox "fill in the missing words" else( testSelection = DialScriptCollect.lbx_SetFolder.selection append FolderListArr edt_name.text append FolderArr edt_path.text DialScriptCollect.lbx_SetFolder.items = FolderListArr DialScriptCollect.lbx_SetFolder.selection = testSelection + 1 WriteFile() ) ) ItmPath = FolderArr[DialScriptCollect.lbx_SetFolder.items.count] getmsfiles() ) on btn_delItm pressed do( -- delete item if DialScriptCollect.lbx_SetFolder.items.count > 1 do( testSelection = DialScriptCollect.lbx_SetFolder.selection deleteitem FolderArr DialScriptCollect.lbx_SetFolder.selection deleteitem FolderListArr DialScriptCollect.lbx_SetFolder.selection DialScriptCollect.lbx_SetFolder.items = FolderListArr DialScriptCollect.lbx_SetFolder.selection = testSelection - 1 WriteFile() ) ItmPath = FolderArr[DialScriptCollect.lbx_SetFolder.selection] getmsfiles() ) on spn_posDialX changed arg do( setDialogPos DialScriptCollect [arg,spn_posDialY.value] DialPos_PosX = arg setINISetting Cfile "ScriptCollector" "DialPos_PosX" (DialPos_PosX as string) ) on spn_posDialY changed arg do( setDialogPos DialScriptCollect [spn_posDialX.value,arg] DialPos_PosY = arg setINISetting Cfile "ScriptCollector" "DialPos_PosY" (DialPos_PosY as string) ) on spn_heigthFlist changed arg do( DialScriptCollect.lbx_SetFolder.height = arg DialScriptCollect.edt_FindName.pos.y = arg + 9 DialScriptCollect.lbx_ScriptArray.pos.y = arg + 30 DialScriptCollect.btn_ClearText.pos.y = arg + 8 DialScriptCollect.lbx_ScriptArray.height = ((DialScriptCollect.height - 36) - arg) SetFolderHeight = arg setINISetting Cfile "ScriptCollector" "Folder_Height" (SetFolderHeight as string) ) on chk1_visTitleBar changed state do( if chk1_visTitleBar.state == true then( VisDial = true destroyDialog DialScriptCollect createDialog DialScriptCollect pos: [DialPos_PosX,DialPos_PosY] width:wdial height:hdial style:#(#style_titlebar , #style_border , #style_sysmenu , #style_resizing) ) else ( VisDial = false destroyDialog DialScriptCollect createDialog DialScriptCollect pos: [DialPos_PosX,DialPos_PosY] width:wdial height:hdial style:#(#style_resizing) ) setINISetting Cfile "ScriptCollector" "VisDial" (VisDial as string) ) on chk1_Ritem changed state do( if state == false do( Ritem = undefined) setiniSetting Cfile "ScriptCollector" "chkRItem" (state as string) ) )--End UI Rollout rollout DialScriptCollect " Script Collector" ( listbox lbx_SetFolder "" items:FolderListArr pos:[5 ,5] width:(wdial - 30) edittext edt_FindName "" pos:[4,SetFolderHeight + 9] width:(wdial - 32) height:17 listbox lbx_ScriptArray "" pos:[5,SetFolderHeight + 30] width:(wdial- 10) button btn_CloseDial " X" pos:[wdial-20,3] width:18 height:16 tooltip:"close" button btn_setDial " S" pos:[wdial - 20,20] width:18 height:16 tooltip:"Settings" button btn_openListener " L" pos:[wdial - 20,38] width:18 height:16 tooltip:"Listener" checkbutton btn_getAllFiles " A" pos:[wdial - 20,57] width:18 height:16 tooltip:"All" button btn_FolderArrUp "|" pos:[0,5] width:6 height:35 tooltip:"Up" button btn_FolderArrDown "|" pos:[0,37] width:6 height:35 tooltip:"Down" button btn_ClearText " c" pos:[wdial - 22,SetFolderHeight + 8] width:20 height:18 on btn_CloseDial pressed do ( destroyDialog DialScriptCollect ) on btn_openListener pressed do (actionMan.executeAction 0 "40472" ) on btn_setDial pressed do (try (DestroyDialog UISEt) catch(); createDialog UISet) on btn_ClearText pressed do(edt_FindName.text = ""; lbx_ScriptArray.items = oldListArr) on btn_FolderArrDown pressed do( if lbx_SetFolder.selection != lbx_SetFolder.items.count then( MoveDownarr FolderArr (lbx_SetFolder.selection) MoveDownarr FolderListArr (lbx_SetFolder.selection) lbx_SetFolder.items = FolderListArr lbx_SetFolder.selection = lbx_SetFolder.selection + 1 WriteFile() ) ) on btn_FolderArrUp pressed do( if lbx_SetFolder.selection != 1 then( MoveUParr FolderArr (lbx_SetFolder.selection) MoveUParr FolderListArr (lbx_SetFolder.selection) lbx_SetFolder.items = FolderListArr lbx_SetFolder.selection = lbx_SetFolder.selection - 1 WriteFile() ) ) on edt_FindName changed arg do ( tmpArr = #() for i=1 to oldListArr.count do( a = findString oldListArr[i] arg if a != undefined do( append tmpArr oldListArr[i] ) ) lbx_ScriptArray.items = tmpArr ) on btn_getAllFiles changed state do(-- Get all files in folder array if state == on then( getmsfiles() oldListArr = lbx_ScriptArray.items menuOff = off ) else( getmsfiles() oldListArr = lbx_ScriptArray.items edt_FindName.text = "" menuOff = on ) ) -- End btn_getAllFiles on lbx_ScriptArray doubleClicked arg do ( if btn_getAllFiles.state == false then( try(fileIn ((ItmPath + "\\")+ lbx_ScriptArray.selected)) catch() ) else ( for i=1 to FolderArr.count do( fl = (FolderArr[i] + "\\" + lbx_ScriptArray.selected) if doesFileExist fl == true do try(fileIn fl) catch() ) ) ) rollout Renamer "Choose Name" ( edittext EdText pos:[1,4] width:150 height:17 button btn_ok " OK" pos:[154,4] width:24 height:17 fn MainD=( msFile = ((ItmPath + "\\") + EdText.text) if (doesFileExist msFile) == false then( renameFile ((ItmPath + "\\")+ lbx_ScriptArray.selected) ((ItmPath + "\\")+ EdText.text) lbx_ScriptArray.selected = EdText.text destroyDialog ReNamer ) else (messageBox "choose a different name") )-- end fn ---------------------------- on ReNamer open do( setFocus EdText EdText.text = lbx_ScriptArray.selected ) ---------------------------- on EdText entered text do( if keyboard.escPressed == false then( MainD() ) else (destroyDialog ReNamer) ) on btn_ok pressed do (MainD()) ) -- end Renamer rollout CreateFIleDialog "Create ms file" width:150 height:50 ( edittext EdText "" pos:[5,4] width:130 height:17 checkbox chk_edtFile " Edit Created File" pos:[5,28] checked:true label lbl_ok"OK" pos:[120,29] fn NewScriptInFolder =( fs = "" msFile = ((ItmPath + "\\") + EdText.text + ".ms") if (doesFileExist msFile) == false then( fs = createFile msFile close fs destroyDialog CreateFIleDialog if chk_edtFile.state == on do (edit msFile) ) else (messageBox "choose a different name") ) ---------------------------- on EdText entered text do( if keyboard.escPressed == false then( NewScriptInFolder() getmsfiles() oldListArr = lbx_ScriptArray.items ) else (destroyDialog CreateFIleDialog) ) on EdText changed arg do(chk_edtFile.enabled = false) on chk_edtFile changed state do( setINISetting Cfile "ScriptCollector" "EditChkFile" (state as string) ) on CreateFIleDialog open do( setFocus EdText chk_edtFile.checked = getINISetting Cfile "ScriptCollector" "EditChkFile" as booleanClass ) )-- end CreateFIleDialog rollout MoveInFolder "Move In Folder" width:130 height:155 ( listbox MoveIn "" pos:[13,26] width:110 height:7 pos:[13,7] width:109 button btn_moveIn ">>>>" pos:[27,130] width:52 height:19 button btn_closeMovDial " EXIT" pos:[81,130] width:40 height:19 label lbl_LabfileStat "File Status:" pos:[14,7] width:55 height:13 label lbl_dispStat "" pos:[74,7] width:40 height:13 checkbox chk_move "Checkbox" pos:[7,132] width:16 height:18 checked:true tooltip:"Checked - Move File" local ItmPath_m on btn_closeMovDial pressed do (destroyDialog MoveInFolder) on MoveIn selected arg do(ItmPath_m = FolderArr_d[arg]; format "ItmPath_m = %\n" ItmPath_m) on btn_moveIn pressed do( if lbx_ScriptArray.selection > 0 do ( if doesFileExist (ItmPath_m +"\\" + DialScriptCollect.lbx_ScriptArray.selected) == true then lbl_dispStat.text ="False" else ( if chk_move.state == true then( copyFile ((ItmPath + "\\")+ DialScriptCollect.lbx_ScriptArray.selected) (ItmPath_m + "\\" + DialScriptCollect.lbx_ScriptArray.selected) deleteFIle ((ItmPath + "\\")+ DialScriptCollect.lbx_ScriptArray.selected) lbx_ScriptArray.items = deleteItem lbx_ScriptArray.items lbx_ScriptArray.selection lbl_dispStat.text = "Moved" ) else ( copyFile ((ItmPath + "\\")+ DialScriptCollect.lbx_ScriptArray.selected) (ItmPath_m + "\\" + DialScriptCollect.lbx_ScriptArray.selected) lbl_dispStat.text = "Copied" ) ) ) ) -- ENd btn_moveIn on MoveInFolder open do ( c_FLarr = copy FolderListArr #nomap c_Farr = copy FolderArr #nomap FolderListArr_d = (deleteItem c_FLarr DialScriptCollect.lbx_SetFolder.selection) FolderArr_d = (deleteItem c_Farr DialScriptCollect.lbx_SetFolder.selection) ItmPath_m = FolderArr_d[1] MoveIn.items = FolderListArr_d ) ) -- ENd MoveInFolder local rcm fn createMenu = ( rcMenu rcm ( menuItem rcEdit "Edit Script" menuItem rcRename "Reaname" enabled:menuOff separator spr menuItem rcNewScript "New Script" enabled:menuOff menuItem rcMove "Move in " enabled:menuOff menuItem rcDelete "Delete Script" enabled:menuOff ----------------------------------- on rcEdit picked do ( if btn_getAllFiles.state == false then( try(edit ((ItmPath + "\\")+ lbx_ScriptArray.selected)) catch() ) else ( for i=1 to FolderArr.count do( fl = (FolderArr[i] + "\\" + lbx_ScriptArray.selected) if doesFileExist fl == true do try(edit fl) catch() ) ) ) on rcRename picked do ( RollPos = mouse.screenpos CreateDialog ReNamer pos: RollPos width:180 height:25 ) on rcNewScript picked do( RollPos = mouse.screenpos createDialog CreateFIleDialog pos: RollPos --style:#() ) on rcMove picked do( RollPosx = ((GetDialogPos DialScriptCollect).x) + (DialScriptCollect.width) + 5 RollPosy = mouse.screenpos.y - 100 createDialog MoveInFolder pos:[RollPosx,RollPosy] ) on rcDelete picked do ( if queryBox ("Delete " + lbx_ScriptArray.selected) beep:true then( deleteFile ((ItmPath + "\\")+ lbx_ScriptArray.selected) lbx_ScriptArray.items = deleteItem lbx_ScriptArray.items lbx_ScriptArray.selection ) else print "Error" ) )--EndRcMenu )--EndFnMenu on lbx_SetFolder selected arg do ( if MoveInFolder.isDisplayed == true do (-- move in folder c_FLarr = copy FolderListArr #nomap c_Farr = copy FolderArr #nomap FolderListArr_d = (deleteItem c_FLarr DialScriptCollect.lbx_SetFolder.selection) FolderArr_d = (deleteItem c_Farr DialScriptCollect.lbx_SetFolder.selection) MoveInFolder.MoveIn.items = FolderListArr_d format "FolderArr_d = %\n" FolderArr_d ) --end Ritem = arg ItmPath = FolderArr[arg] getmsfiles() oldListArr = lbx_ScriptArray.items ) -- end sf on lbx_ScriptArray rightClick arg do ( popUpMenu rcm rollout:DialScriptCollect align:#align_topcenter) on DialScriptCollect moved pos do( DialPos_PosX = (GetDialogPos DialScriptCollect).x DialPos_PosY = (GetDialogPos DialScriptCollect).y setINISetting Cfile "ScriptCollector" "DialPos_PosX" (DialPos_PosX as string) setINISetting Cfile "ScriptCollector" "DialPos_PosY" (DialPos_PosY as string) ) on DialScriptCollect resized size do( wdial = DialScriptCollect.width hdial = DialScriptCollect.height lbx_ScriptArray.width = wdial- 10 lbx_ScriptArray.height = (hdial - 36) - SetFolderHeight lbx_SetFolder.width = wdial - 30 btn_CloseDial.pos.x = wdial - 20 btn_setDial.pos.x = wdial - 20 btn_getAllFiles.pos.x = wdial - 20 btn_openListener.pos.x = wdial - 20 edt_FindName.width = wdial - 32 btn_ClearText.pos.x = wdial - 22 ---------------------- setINISetting Cfile "ScriptCollector" "DialPos_Width" (wdial as string) setINISetting Cfile "ScriptCollector" "DialPos_Height" (hdial as string) ---------------------- ) on DialScriptCollect open do ( lbx_SetFolder.height = SetFolderHeight lbx_ScriptArray.height = (hdial - 36) - SetFolderHeight lbx_SetFolder.selection = Ritem createMenu() ReadFolderArr() getmsfiles() oldListArr = lbx_ScriptArray.items setfocus edt_FindName ) ) -- end DialScriptCollect createDialog DialScriptCollect pos: [DialPos_PosX,DialPos_PosY] width:wdial height:hdial style:(if VisDial == false then #(#style_resizing)else(#(#style_titlebar , #style_border , #style_sysmenu , #style_resizing))) )--End Script