Advertisement
aporokizzu

newdatainclude.ahk

Mar 8th, 2023
1,367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Autohotkey 3.35 KB | Source Code | 0 0
  1. ; newdatainclude.ahk
  2. ; by PE
  3.  
  4. class NewDataInclude {
  5.  
  6.     LB_NEWDATA() {
  7.  
  8.         return "lbNewData"
  9.  
  10.     }
  11.  
  12.     LB_INCLUDEDFILES() {
  13.  
  14.         return "lbIncludedFiles"
  15.  
  16.     }
  17.    
  18.     BTN_ADD() {
  19.  
  20.         return "btnAdd"
  21.  
  22.     }
  23.    
  24.     ARR_GUI_CTRLS() {
  25.    
  26.         retVal := [
  27.        
  28.             ["ListBox", this.LB_NEWDATA(), "r12 +Multi x16 y36 w208", this._newDataFiles],
  29.             ["ListBox", this.LB_INCLUDEDFILES(), "r12 +Multi x288 y36 w208", this._includedFiles],
  30.            
  31.             ["Button", this.BTN_ADD(), "w32 h32 x240 y32", ">", this.add, this],
  32.        
  33.         ]
  34.        
  35.         return retVal
  36.    
  37.     }
  38.  
  39.     __New() {
  40.    
  41.         this._ready := false
  42.    
  43.         this._includedFiles := ["index.html", "main.js", "plugins.js"]
  44.         this._newDataFiles := ["ping.ogg", "shadow.png", "Classes.json", "bling.pak", "boop.json", "window.png", "Actors.json"]
  45.  
  46.         this.__createGui()
  47.        
  48.     }
  49.    
  50.     __createGui() {
  51.    
  52.         this._gui := Gui("-Resize")
  53.         this._gui.SetFont("s9")
  54.        
  55.         this._guiControls := Map()
  56.        
  57.         this.__addCtrls(this.ARR_GUI_CTRLS())
  58.        
  59.         this._ready := true
  60.        
  61.     }
  62.    
  63.     __addCtrls(arrSource := []) {
  64.    
  65.         controls := arrSource
  66.         controlsLen := controls.Length
  67.        
  68.         Loop controlsLen {
  69.        
  70.             currentCtl := controls[A_Index]
  71.             paramsLen := currentCtl.Length
  72.            
  73.             ctlType := currentCtl[1]
  74.             ctlName := currentCtl[2]
  75.             ctlOptions := currentCtl[3]
  76.            
  77.             this._guiControls[ctlName] := Map()
  78.             this._guiControls[ctlName]["type"] := ctlType
  79.  
  80.             switch this._guiControls[ctlName]["type"] {
  81.  
  82.                 case "ListBox":
  83.                    
  84.                     ctlArraySource := currentCtl[4]
  85.  
  86.                     this._guiControls[ctlName]["ocx"] :=
  87.                         this._gui.AddListBox(
  88.                             ctlOptions,
  89.                             ctlArraySource
  90.                         )
  91.                
  92.                 case "Button":
  93.  
  94.                     ctlCaption := currentCtl[4]
  95.                     ctlFunc := currentCtl[5]
  96.  
  97.                     params := (paramsLen > 5) ? currentCtl[6] : "n/a"
  98.  
  99.                     fnc := (params != "n/a") ? ctlFunc.Bind(params) : ctlFunc
  100.                    
  101.                     this._guiControls[ctlName]["ocx"] :=
  102.                         this._gui.AddButton(
  103.                             ctlOptions,
  104.                             ctlCaption
  105.                         )
  106.  
  107.                     this._guiControls[ctlName]["ocx"].OnEvent(
  108.                         "Click",
  109.                         fnc
  110.                     )
  111.             }
  112.  
  113.         }
  114.    
  115.     }
  116.    
  117.     ctrl(ctlName) {
  118.    
  119.         return this._guiControls[ctlName]["ocx"]
  120.    
  121.     }
  122.    
  123.     __listBox2listBox(src, target) {
  124.    
  125.         selectedItems := this.ctrl(src).Value
  126.        
  127.         if (IsObject(selectedItems)) {
  128.        
  129.             selectedItemsLen := selectedItems.Length
  130.             itemsToMove := []
  131.            
  132.             Loop selectedItemsLen {
  133.            
  134.                 sourceIdx := selectedItems[A_Index]
  135.                 ControlChooseIndex(sourceIdx, this.ctrl(src))
  136.                 item := ControlGetChoice(this.ctrl(src))
  137.                 itemsToMove.Push(item)
  138.             }
  139.            
  140.             ; should be the same as selectedItemsLen, but I don't trust these machines.
  141.            
  142.             itemsToMoveLen := itemsToMove.Length
  143.            
  144.             if (itemsToMove.Length > 0) {
  145.                            
  146.                 this.ctrl(target).Add(itemsToMove)
  147.                
  148.                 oldDelay := A_ControlDelay
  149.                 SetControlDelay -1
  150.                
  151.                 Loop itemsToMoveLen {
  152.                
  153.                     item := itemsToMove[A_Index]
  154.                     sourceIdx := ControlFindItem(item, this.ctrl(src))
  155.                     ControlDeleteItem(sourceIdx, this.ctrl(src))
  156.                    
  157.                 }
  158.                
  159.             }
  160.        
  161.         }
  162.        
  163.     }
  164.    
  165.     add(*) {
  166.    
  167.         source := this.LB_NEWDATA()
  168.         target := this.LB_INCLUDEDFILES()
  169.        
  170.         if (IsObject(this.ctrl(source))) {
  171.        
  172.             this.__listBox2listBox(source, target)
  173.        
  174.         }
  175.        
  176.     }
  177.    
  178.     show() {
  179.    
  180.         if (this._ready) {
  181.        
  182.             this._gui.Show()
  183.        
  184.         }
  185.    
  186.     }
  187.  
  188. }
  189.  
  190. TEST := NewDataInclude()
  191. TEST.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement