Quantcast

Refactoring. Replaced MyMode with VarrenDevTools

Petr Grabovoy [05-28-16 - 00:07]
Refactoring. Replaced MyMode with VarrenDevTools
Filename
Utils.lua
VarrenDevTool.lua
VarrenDevTool.xml
VarrenDevToolOld.lua
diff --git a/Utils.lua b/Utils.lua
deleted file mode 100644
index 32a7639..0000000
--- a/Utils.lua
+++ /dev/null
@@ -1,7 +0,0 @@
-local ADDON_NAME, VARREN_DEV_TOOLS = ...;
-
-function VARREN_DEV_TOOLS:DEBUG(self, text)
-    if self.debug then
-        print(text);
-    end
-end
\ No newline at end of file
diff --git a/VarrenDevTool.lua b/VarrenDevTool.lua
index 178e4ca..cbec5be 100644
--- a/VarrenDevTool.lua
+++ b/VarrenDevTool.lua
@@ -1,6 +1,6 @@
-local MyModData = { size = 0; first = nil, last = nil }
+local VarrenDevToolLinkedList = { size = 0; first = nil, last = nil }

-function MyModData:GetInfoAtPosition(position)
+function VarrenDevToolLinkedList:GetInfoAtPosition(position)
     if self.size < position or self.first == nil then
         return nil
     end
@@ -14,14 +14,14 @@ function MyModData:GetInfoAtPosition(position)
     return node
 end

-function MyModData:AddNodeAfter(node, prevNode)
+function VarrenDevToolLinkedList:AddNodeAfter(node, prevNode)
     local tempNext = node.next
     node.next = prevNode
     prevNode.next = tempNext
     self.size = self.size + 1;
 end

-function MyModData:AddNodesAfter(nodeList, parentNode)
+function VarrenDevToolLinkedList:AddNodesAfter(nodeList, parentNode)
     local tempNext = parentNode.next
     local currNode = parentNode;

@@ -38,7 +38,7 @@ function MyModData:AddNodesAfter(nodeList, parentNode)
     end
 end

-function MyModData:AddNode(data, dataName)
+function VarrenDevToolLinkedList:AddNode(data, dataName)
     local node = self:NewNode(data, dataName)

     if self.first == nil then
@@ -54,7 +54,7 @@ function MyModData:AddNode(data, dataName)
     self.size = self.size + 1;
 end

-function MyModData:NewNode(data, dataName, padding, parent)
+function VarrenDevToolLinkedList:NewNode(data, dataName, padding, parent)
     return {
         name = dataName,
         value = data,
@@ -64,7 +64,7 @@ function MyModData:NewNode(data, dataName, padding, parent)
     }
 end

-function MyModData:RemoveChildNodes(node)
+function VarrenDevToolLinkedList:RemoveChildNodes(node)
     local currNode = node

     while true do
@@ -86,17 +86,16 @@ function MyModData:RemoveChildNodes(node)
     end
 end

-function MyModData:Clear()
+function VarrenDevToolLinkedList:Clear()
     self.size = 0
     self.first = nil
     self.last = nil
 end

-local ipairs, pairs, next, tonumber, tostring, type, print, string, getmetatable, table,pcall = ipairs, pairs, next, tonumber, tostring, type, print, string, getmetatable, table,pcall
+local pairs, tostring, type, print, string, getmetatable, table,pcall =  pairs, tostring, type, print, string, getmetatable, table,pcall
+local HybridScrollFrame_CreateButtons, HybridScrollFrame_GetOffset, HybridScrollFrame_Update = HybridScrollFrame_CreateButtons,HybridScrollFrame_GetOffset, HybridScrollFrame_Update

-local _G = _G
-
-function MyMod_ExpandCell(info)
+function VarrenDevTool_ExpandCell(info)

     local nodeList = {}
     local padding = info.padding + 1
@@ -104,11 +103,11 @@ function MyMod_ExpandCell(info)
     for k, v in pairs(info.value) do
         if type(v) ~= "userdata" then

-            nodeList[couner] = MyModData:NewNode(v, tostring(k), padding, info)
+            nodeList[couner] = VarrenDevToolLinkedList:NewNode(v, tostring(k), padding, info)
         else
             local mt = getmetatable(info.value)
             if mt then
-                nodeList[couner] = MyModData:NewNode(mt.__index, "$metatable", padding, info)
+                nodeList[couner] = VarrenDevToolLinkedList:NewNode(mt.__index, "$metatable", padding, info)
             end
         end
         couner = couner + 1
@@ -118,42 +117,44 @@ function MyMod_ExpandCell(info)
         return a.name < b.name
     end)

-    MyModData:AddNodesAfter(nodeList, info)
+    VarrenDevToolLinkedList:AddNodesAfter(nodeList, info)
     info.expanded = true
-    MyModScrollBar_Update()
+    VarrenDevTool_ScrollBar_Update()
 end

-function MyMod_ColapseCell(info)
-    MyModData:RemoveChildNodes(info)
+function VarrenDevTool_ColapseCell(info)
+    VarrenDevToolLinkedList:RemoveChildNodes(info)
     info.expanded = nil
-    print("size: " .. MyModData.size)
-    MyModScrollBar_Update()
+    print("size: " .. VarrenDevToolLinkedList.size)
+    VarrenDevTool_ScrollBar_Update()
 end

-function MyMod_AddData(data, dataName)
-    MyModData:AddNode(data, dataName)
-    MyModScrollBar_Update()
+function VarrenDevTool_AddData(data, dataName)
+    VarrenDevToolLinkedList:AddNode(data, dataName)
+    VarrenDevTool_ScrollBar_Update()
 end
-function MyMod_ClearData()
-    MyModData:Clear()
-    MyModScrollBar_Update()
+
+function VarrenDevTool_ClearData()
+    VarrenDevToolLinkedList:Clear()
+    VarrenDevTool_ScrollBar_Update()
 end

-function MyModScrollBar_Update()
-    local scrollFrame = MyModScrollFrame
+function VarrenDevTool_ScrollBar_Update()
+
+    local scrollFrame = VarrenDevToolScrollFrame

     local buttons = scrollFrame.buttons;
     local offset = HybridScrollFrame_GetOffset(scrollFrame)
-    local totalRowsCount = MyModData.size
+    local totalRowsCount = VarrenDevToolLinkedList.size
     local lineplusoffset; -- an index into our data calculated from the scroll offset

-    local nodeInfo = MyModData:GetInfoAtPosition(offset)
+    local nodeInfo = VarrenDevToolLinkedList:GetInfoAtPosition(offset)
     for k, view in pairs(buttons) do

         lineplusoffset = k + offset;
         -- print("ok: " .. lineplusoffset .. "  " .. offset .. "  " .. k .. " " .. (nodeInfo ~= nil and nodeInfo.name or "nil"))
         if lineplusoffset <= totalRowsCount then
-            MyMod_UpdateListItem(view, nodeInfo, lineplusoffset)
+            VarrenDevTool_UpdateListItem(view, nodeInfo, lineplusoffset)
             nodeInfo = nodeInfo.next
             view:Show();
         else
@@ -167,7 +168,7 @@ end



-function MyMod_UpdateListItem(node, info, id)
+function VarrenDevTool_UpdateListItem(node, info, id)
     local nameButton = node.nameButton;
     local typeButton = node.typeButton
     local valueButton = node.valueButton
@@ -186,7 +187,7 @@ function MyMod_UpdateListItem(node, info, id)
     typeButton:SetText(valueType)
     rowNumberButton:SetText(tostring(id))

-    local color = "MyModBaseFont"
+    local color = "VarrenDevToolBaseFont"
     if valueType == "table" then
         if name ~= "$metatable" then
             if value.GetObjectType then
@@ -195,9 +196,9 @@ function MyMod_UpdateListItem(node, info, id)
                     valueButton:SetText(value:GetObjectType() .. "  " .. tostring(value))
                 end
             end
-            color = "MyModTableFont";
+            color = "VarrenDevToolTableFont";
         else
-            color = "MyModMetatableFont";
+            color = "VarrenDevToolMetatableFont";
         end
         local resultStringName = tostring(name)
         local MAX_STRING_SIZE = 60
@@ -214,14 +215,14 @@ function MyMod_UpdateListItem(node, info, id)
         nameButton:SetText(resultStringName .. "   (" .. tablelength(value) .. ") ");

     elseif valueType == "userdata" then
-        color = "MyModTableFont";
+        color = "VarrenDevToolTableFont";
     elseif valueType == "string" then
         valueButton:SetText(string.gsub(string.gsub(tostring(value), "|n", ""), "\n", ""))
-        color = "MyModStringFont";
+        color = "VarrenDevToolStringFont";
     elseif valueType == "number" then
-        color = "MyModNumberFont";
+        color = "VarrenDevToolNumberFont";
     elseif valueType == "function" then
-        color = "MyModFunctionFont";
+        color = "VarrenDevToolFunctionFont";
     end


@@ -235,22 +236,22 @@ function MyMod_UpdateListItem(node, info, id)
         nameButton:SetScript("OnMouseUp", function(self, button, down)
             print("click")
             if info.expanded then
-                MyMod_ColapseCell(info)
+                VarrenDevTool_ColapseCell(info)
             else
-                MyMod_ExpandCell(info)
+                VarrenDevTool_ExpandCell(info)
             end
         end)
     elseif valueType == "function" then
         nameButton:SetScript("OnMouseUp", function(self, button, down)
             print("click")
-            MyMod_TryCallFunction(info)
+            VarrenDevTool_TryCallFunction(info)
         end)
     else
         nameButton:SetScript("OnMouseUp", nil)
     end
 end

-function MyMod_TryCallFunction(info)
+function VarrenDevTool_TryCallFunction(info)
     local value = info.value

     local ok, result = pcall(value)
@@ -277,4 +278,11 @@ function MyMod_TryCallFunction(info)
             print(parent.name ..":".. info.name .."() returns: " .. additionalInfo.. "  ("..resultType ..")" )
         end
     end
-end
\ No newline at end of file
+end
+
+
+function DEBUG(self, text)
+    if self.debug then
+        print(text);
+    end
+end
diff --git a/VarrenDevTool.xml b/VarrenDevTool.xml
index e1d3ce3..9a12344 100644
--- a/VarrenDevTool.xml
+++ b/VarrenDevTool.xml
@@ -1,34 +1,34 @@
 <Ui>
     <Script file="VarrenDevTool.lua"/>
-    <Font name="MyModDefaultFont" inherits="SystemFont_Small" justifyH="LEFT" virtual="true"/>
-    <Font name="MyModTableFont" inherits="MyModDefaultFont" virtual="true">
+    <Font name="VarrenDevToolDefaultFont" inherits="SystemFont_Small" justifyW="LEFT" justifyH="LEFT" virtual="true"/>
+
+    <Font name="VarrenDevToolTableFont" inherits="VarrenDevToolDefaultFont" virtual="true">
         <Color r="0.41" g="0.80" b="0.94"/>
     </Font>
-    <Font name="MyModStringFont" inherits="MyModDefaultFont" virtual="true">
+    <Font name="VarrenDevToolStringFont" inherits="VarrenDevToolDefaultFont" virtual="true">
         <Color r="0.67" g="0.83" b="0.45"/>
     </Font>
-    <Font name="MyModNumberFont" inherits="MyModDefaultFont" virtual="true">
+    <Font name="VarrenDevToolNumberFont" inherits="VarrenDevToolDefaultFont" virtual="true">
         <Color r="1.0" g="0.96" b="0.41"/>
     </Font>
-    <Font name="MyModFunctionFont" inherits="MyModDefaultFont" virtual="true">
+    <Font name="VarrenDevToolFunctionFont" inherits="VarrenDevToolDefaultFont" virtual="true">
         <Color r="1.0" g="0.49" b="0.04"/>
     </Font>
-    <Font name="MyModBaseFont" inherits="MyModDefaultFont" virtual="true">
+    <Font name="VarrenDevToolBaseFont" inherits="VarrenDevToolDefaultFont" virtual="true">
         <Color r="1.0" g="1.0" b="1.0"/>
     </Font>
-    <Font name="MyModMetatableFont" inherits="MyModDefaultFont" virtual="true">
+    <Font name="VarrenDevToolMetatableFont" inherits="VarrenDevToolDefaultFont" virtual="true">
         <Color r="1.0" g="1.0" b="1.0"/>
     </Font>

-
-    <Button text="Test" name="MyModTopButton" inherits="UIPanelButtonTemplate" virtual="true">
+    <Button text="Test" name="VarrenDevToolTopButton" inherits="UIPanelButtonTemplate" virtual="true">
         <Size>
             <AbsDimension x="150" y="25"/>
         </Size>
         <NormalFont style="GameFontHighlightLeft"/>
     </Button>

-    <Frame name="MyModEntryTemplate" virtual="true">
+    <Frame name="VarrenDevToolEntryTemplate" virtual="true">
         <Anchors>
             <Anchor point="TOPLEFT"/>
         </Anchors>
@@ -46,7 +46,7 @@
                     <Anchor point="LEFT"/>
                 </Anchors>

-                <NormalFont style="MyModDefaultFont"/>
+                <NormalFont style="VarrenDevToolDefaultFont"/>
             </Button>
             <Button text="123456" name="$parentRowType" parentKey="typeButton">
                 <Size>
@@ -59,7 +59,7 @@
                     </Anchor>
                 </Anchors>

-                <NormalFont style="MyModDefaultFont"/>
+                <NormalFont style="VarrenDevToolDefaultFont"/>
             </Button>

             <Button text="Test Text" name="$parentNameRow" parentKey="nameButton">
@@ -72,7 +72,7 @@
                     <Anchor point="LEFT" relativeTo="$parentRowCellCount" relativePoint="RIGHT"/>
                 </Anchors>

-                <NormalFont style="MyModDefaultFont"/>
+                <NormalFont style="VarrenDevToolDefaultFont"/>
             </Button>
             <Button text="Test Text" name="$parentValueRow" parentKey="valueButton">
                 <Size>
@@ -86,11 +86,11 @@

                 </Anchors>

-                <NormalFont style="MyModDefaultFont"/>
+                <NormalFont style="VarrenDevToolDefaultFont"/>
             </Button>
         </Frames>
     </Frame>
-    <Frame name="MyMod" parent="UIParent" enableMouse="true" movable="true" resizable="true">
+    <Frame name="VarrenDevTool" parent="UIParent" enableMouse="true" movable="true" resizable="true">
         <Size>
             <AbsDimension x="1200" y="600"/>
         </Size>
@@ -100,15 +100,17 @@
         <Scripts>
             <OnLoad>
                 self:RegisterForDrag("LeftButton");
-                HybridScrollFrame_CreateButtons(self.scrollFrame, "MyModEntryTemplate", 0, -2)
             </OnLoad>
-            <OnShow function="MyModScrollBar_Update"/>
-            <OnDragStart>self:StartSizing()</OnDragStart>
+            <OnDragStart>
+                self:StartSizing()
+            </OnDragStart>
             <OnReceiveDrag>
-                HybridScrollFrame_CreateButtons(self.scrollFrame, "MyModEntryTemplate", 0, -2);
-                MyModScrollBar_Update()
+                VarrenDevTool_ScrollBar_Update()
             </OnReceiveDrag>
-            <OnDragStop>self:StopMovingOrSizing();</OnDragStop>
+            <OnDragStop>
+                HybridScrollFrame_CreateButtons(self.scrollFrame, "VarrenDevToolEntryTemplate", 0, -2)
+                self:StopMovingOrSizing();
+            </OnDragStop>
         </Scripts>
         <Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\Tooltips\UI-Tooltip-Border"
                   tile="true">
@@ -138,7 +140,16 @@
                     </Anchor>
                 </Anchors>
                 <Scripts>
-                <OnLoad>     self.update = MyModScrollBar_Update </OnLoad>
+                    <OnShow>
+                        print("OnShow GetHeight: "..self:GetHeight())
+                        HybridScrollFrame_CreateButtons(self, "VarrenDevToolEntryTemplate", 0, -2)
+                        VarrenDevTool_ScrollBar_Update()
+                    </OnShow>
+
+                    <OnLoad>
+                        print("OnLoad GetHeight: "..self:GetHeight())
+                        self.update = VarrenDevTool_ScrollBar_Update
+                    </OnLoad>
                 </Scripts>
                 <Frames>
                     <Slider name="$parentScrollBar" inherits="HybridScrollBarTemplate">
@@ -149,17 +160,23 @@
                     </Slider>
                 </Frames>
             </ScrollFrame>
-            <Frame name="$parentTopBar" parent="MyMod" enableMouse="true">
+            <Frame name="$parentTopBar" parent="VarrenDevTool" enableMouse="true">
                 <Size>
-                    <AbsDimension  y="25"/>
+                    <AbsDimension y="25"/>
                 </Size>
                 <Scripts>
                     <OnLoad>
                         self:RegisterForDrag("LeftButton");
                     </OnLoad>
-                    <OnDragStart>self:GetParent():StartMoving()</OnDragStart>
-                    <OnReceiveDrag>MyModScrollBar_Update()</OnReceiveDrag>
-                    <OnDragStop>self:GetParent():StopMovingOrSizing();</OnDragStop>
+                    <OnDragStart>
+                        self:GetParent():StartMoving()
+                    </OnDragStart>
+                    <OnReceiveDrag>
+                        VarrenDevTool_ScrollBar_Update()
+                    </OnReceiveDrag>
+                    <OnDragStop>
+                        self:GetParent():StopMovingOrSizing();
+                    </OnDragStop>
                 </Scripts>

                 <Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background"
@@ -178,31 +195,31 @@
                     <Anchor point="BOTTOM" relativeTo="$parent" relativePoint="TOP"/>
                 </Anchors>
                 <Frames>
-                    <Button text="CLEAR" name="$parentClearButton" inherits="MyModTopButton">
+                    <Button text="CLEAR" name="$parentClearButton" inherits="VarrenDevToolTopButton">
                         <Scripts>
                             <OnClick>
-                                MyMod_ClearData()
+                                VarrenDevTool_ClearData()
                             </OnClick>
                         </Scripts>
                         <Anchors>
-                            <Anchor point="TOPLEFT" />
+                            <Anchor point="TOPLEFT"/>
                         </Anchors>
                     </Button>
-                    <Button text="_G" name="$parentAddGlobalButton" inherits="MyModTopButton">
+                    <Button text="_G" name="$parentAddGlobalButton" inherits="VarrenDevToolTopButton">
                         <Scripts>
                             <OnClick>
-                                MyMod_AddData(_G, "_G")
+                                VarrenDevTool_AddData(_G, "_G")
                             </OnClick>
                         </Scripts>
                         <Anchors>
                             <Anchor point="LEFT" relativeTo="$parentClearButton" relativePoint="RIGHT"/>
                         </Anchors>
                     </Button>
-                    <Button text="Unit" name="$parentAddPlayerInfoButton" inherits="MyModTopButton">
+                    <Button text="Unit" name="$parentAddPlayerInfoButton" inherits="VarrenDevToolTopButton">
                         <Scripts>
                             <OnClick>
                                 local name, realm = UnitFullName("player")
-                                MyMod_AddData(UnitGUID("player"), name .. "-" .. realm)
+                                VarrenDevTool_AddData(UnitGUID("player"), name .. "-" .. realm)
                             </OnClick>
                         </Scripts>
                         <Anchors>
@@ -211,7 +228,6 @@
                     </Button>
                 </Frames>
             </Frame>
-
         </Frames>
     </Frame>
 </Ui>
\ No newline at end of file
diff --git a/VarrenDevToolOld.lua b/VarrenDevToolOld.lua
deleted file mode 100644
index 9872f1c..0000000
--- a/VarrenDevToolOld.lua
+++ /dev/null
@@ -1,126 +0,0 @@
-local ADDON_NAME, VARREN_DEV_TOOLS = ...
-
---message('Hello World!')
-function VARREN_DEV_TOOLS:new(o)
-    o = o or {}
-    setmetatable(o, self)
-    self.__index = self
-    self.data = {}
-    return o
-end
-
-function VARREN_DEV_TOOLS:Init()
-    self:initGUI()
-end
-
-function VARREN_DEV_TOOLS:initGUI()
-    self.frame = self:CreateFrame()
-    -- message('Hello World!')
-
-    local test = "<html><body><p>Demo Start</p><p>"
-
-    local testtbl = { a = {h=7,g=45},b=10,c=15 }
-    for key, value in pairs(C_LFGList) do
-        test = test .. key .. "<br />"
-    end
-
-    self:AddNode(testtbl, "testtbl")
-    test = test .. "</p><p>Demo End</p></body></html>"
-    --frame:SetText(test)
-    --frame:SetFont('Fonts\\FRIZQT__.TTF', 11)
-end
-
-function VARREN_DEV_TOOLS:CreateFrame()
- --   local frame = CreateFrame("Frame", "MUI_BuffFrame", UIParent, "BasicFrameTemplateWithInset")
-    local frame = CreateFrame("Frame", "MUI_BuffFrame", UIParent)
-    --local frame = CreateFrame("SimpleHTML", "MUI_BuffFrame", UIParent)
-
-    --local scrollFrame = CreateFrame("ScrollFrame")
-    -- scrollFrame:SetScrollChild(frame)
-    -- scrollFrame:SetSize(800, 800)
-    frame:SetSize(800, 800)
-
-    frame:SetPoint("CENTER", UIParent, "CENTER")
-    frame:Show()
-    -- scrollFrame:Show()
-    return frame
-end
-
-function VARREN_DEV_TOOLS:AddNodeAtPosition(var, helperText, order, position)
-    local mybutton = CreateFrame("Button", "mybutton".. position, self.frame, "UIPanelButtonTemplate")
-    mybutton:SetPoint("TOP", 2 + 22 * order, -22  * (position + 1))
-    mybutton:SetWidth(790 - (22 * order))
-    mybutton:SetHeight(22)
-    local text = self:TextFromVar(var, helperText)
-    mybutton:SetText(text)
-
-    self.data[position] = {
-        var = var,
-        order = order,
-        expanded = false,
-       -- text = text
-    }
-
-    mybutton:SetID(position)
-
-    if type(var) == "table" or type(var) == "userdata" then
-        mybutton:SetScript("OnMouseUp", function(self, button, down)
-            print("click")
-            local isExpanded = VARREN_DEV_TOOLS.data[position].expanded
-
-            if not isExpanded then
-                VARREN_DEV_TOOLS:Expand(mybutton)
-            end
-        end)
-    end
-end
-
-function VARREN_DEV_TOOLS:AddNode(var, helperText)
-    self:AddNodeAtPosition(var, helperText, 0, 1)
-end
-
-function VARREN_DEV_TOOLS:TextFromVar(var, helperName)
-    if type(var) ~= "table" and type(var) ~= "userdata" then
-        return helperName .. ": " .. tostring(var)
-    end
-
-    return "table: " .. helperName .. " - " .. tostring(var)
-end
-
-function VARREN_DEV_TOOLS:Expand(node)
-
-    local id = node:GetID()
-    print(id)
-    self:PrintTable(self.data)
-
-    local info = self.data[id]
-
-    info.expanded = true
-
-    local nodeInfo = info.var
-    local order = info.order + 1
-    local i = id + 1
-
-
-    for key, value in pairs(nodeInfo) do
-        self:AddNodeAtPosition(value, key, order, i)
-        i = i + 1
-    end
-end
-
-function VARREN_DEV_TOOLS:PrintTable(table, padding)
-    if  not padding then padding = "" end
-
-    for key, value in pairs(table) do
-        if type(value) ~= "table" and type(value) ~= "userdata" then
-            print(padding .. key .. ": " .. tostring(value))
-        else
-            print(padding .. key)
-            self:PrintTable(value, padding.. "---")
-        end
-    end
-end
-
-
-local VARREN_DEV_TOOLS_INST = VARREN_DEV_TOOLS:new()
-VARREN_DEV_TOOLS_INST:Init()