Quantcast

Add configurable font size, added a slash command, fixed bugs

James Whitehead II [07-17-10 - 13:10]
Add configurable font size, added a slash command, fixed bugs

  * Added a new config button to the toolbar which will open the UI options panel to the WowLua page.
  * This config panel can be used to customize the font size used for WowLua
  * Fixed cursor navigation in the editor
  * Added a slash command (/luarun /wowluarun) that takes the name of a page to run, and runs it
Filename
Localization.enUS.lua
WowLua.lua
WowLua.toc
WowLua.xml
WowLua_Config.lua
images/config.tga
diff --git a/Localization.enUS.lua b/Localization.enUS.lua
index 7cf0696..79cceae 100644
--- a/Localization.enUS.lua
+++ b/Localization.enUS.lua
@@ -20,8 +20,15 @@ L.TOOLTIPS["Unlock"] = { name = "Unlock", text = "This page is locked to prevent
 L.TOOLTIPS["Previous"] = { name = "Previous", text = "Navigate back one page" }
 L.TOOLTIPS["Next"] = { name = "Next", text = "Navigate forward one page" }
 L.TOOLTIPS["Run"] = { name = "Run", text = "Run the current script" }
+L.TOOLTIPS["Config"] = { name = "Config", text = "Open the configuration panel for WowLua" }
 L.TOOLTIPS["Close"] = { name = "Close" }

 L.OPEN_MENU_TITLE = "Select a Script"
 L.SAVE_AS_TEXT = "Save %s with the following name:"
 L.UNSAVED_TEXT = "You have unsaved changes on this page that will be lost if you navigate away from it.  Continue?"
+L.CONFIG_SUBTITLE = "This panel can be used to configure the NinjaPanel LDB display."
+L.CONFIG_TITLE = "%s Configuration"
+L.CONFIG_FONTSIZE = "Font size"
+L.CONFIG_LABEL_FONTSIZE = "Font size:"
+L.CONFIG_FONTSIZE_TOOLTIP = "Configure the font size of the WowLua frame interpreter/editor"
+
diff --git a/WowLua.lua b/WowLua.lua
index 3ef272b..5685720 100644
--- a/WowLua.lua
+++ b/WowLua.lua
@@ -5,8 +5,10 @@
   WowLua is an interactive interpreter for World of Warcraft
 --------------------------------------------------------------------------]]--

+local addon = ...
+local version = GetAddOnMetadata("WowLua", "Version") or "SVN"
 WowLua = {
-	VERSION = "WowLua 1.0 Interactive Interpreter",
+	VERSION = "WowLua v" .. version .. " Interactive Interpreter",
 	queue = {},
 	queuePos = 0,
 }
@@ -18,10 +20,25 @@ WowLua_DB = {
 	},
 	currentPage = 1,
 	untitled = 2,
+    fontSize = 14,
 }

 local DB = {}

+local eframe = CreateFrame("Frame")
+eframe:RegisterEvent("ADDON_LOADED")
+eframe:SetScript("OnEvent", function(self, event, ...)
+    if event == "ADDON_LOADED" then
+        local arg1 = ...
+        if arg1 == addon then
+            if WowLua_DB.fontSize then
+                local file, height, flags = WowLuaMonoFont:GetFont()
+                WowLuaMonoFont:SetFont(file, WowLua_DB.fontSize, flags)
+            end
+        end
+    end
+end)
+
 function WowLua:CreateNewPage()
 	local name = format(L.NEW_PAGE_TITLE, WowLua_DB.untitled)
 	WowLua_DB.untitled = WowLua_DB.untitled + 1
@@ -74,7 +91,7 @@ function WowLua:SelectPage(id)
 		WowLua_DB.currentPage = id
 		return WowLua_DB.pages[id], id
 	elseif type(id) == "string" then
-		for idx,entry in ipairs(WowLuaDB.pages) do
+		for idx,entry in ipairs(WowLua_DB.pages) do
 			if entry.name == id then
 				WowLua_DB.currentPage = idx
 				return entry, idx
@@ -274,6 +291,8 @@ function WowLua:Button_OnClick(button)
 		WowLua:Button_Next(button)
 	elseif operation == "Run" then
 		WowLua:Button_Run(button)
+    elseif operation == "Config" then
+        WowLua:Button_Config(button)
 	elseif operation == "Close" then
 		WowLua:Button_Close(button)
 	end
@@ -621,6 +640,10 @@ function WowLua:Button_Run()
 	end
 end

+function WowLua:Button_Config()
+    InterfaceOptionsFrame_OpenToCategory("WowLua")
+end
+
 function WowLua:Button_Close()
 	if self:IsModified() then
 		-- Display the unsaved changes dialog
@@ -649,31 +672,6 @@ function WowLua:SetTitle(modified)
 	WowLuaFrameTitle:SetFormattedText("%s%s - WowLua Editor", entry.name, self:IsModified() and "*" or "")
 end

-SLASH_WOWLUA1 = "/lua"
-SLASH_WOWLUA2 = "/wowlua"
-local first = true
-SlashCmdList["WOWLUA"] = function(txt)
-	local page, entry = WowLua:GetCurrentPage()
-	if first then
-		WowLuaFrameEditBox:SetText(entry.content)
-		WowLuaFrameEditBox:SetWidth(WowLuaFrameEditScrollFrame:GetWidth())
-		WowLua:SetTitle(false)
-		first = false
-	end
-
-	WowLuaFrame:Show()
-
-	if processSpecialCommands(txt) then
-		return
-	end
-
-	if txt:match("%S") then
-		WowLua:ProcessLine(txt)
-	end
-
-	WowLuaFrameCommandEditBox:SetFocus()
-end
-
 function WowLua:OnSizeChanged(frame)
 	-- The first graphic is offset 13 pixels to the right
 	local width = frame:GetWidth() - 13
@@ -915,3 +913,54 @@ BINDING_NAME_TOGGLE_WOWLUA = "Show/Hide window"
 BINDING_NAME_RUN_WOWLUA = "Run current page"
 BINDING_NAME_SAVE_WOWLUA = "Save current page"

+SLASH_WOWLUA1 = "/lua"
+SLASH_WOWLUA2 = "/wowlua"
+local first = true
+SlashCmdList["WOWLUA"] = function(txt)
+	local page, entry = WowLua:GetCurrentPage()
+	if first then
+		WowLuaFrameEditBox:SetText(entry.content)
+		WowLuaFrameEditBox:SetWidth(WowLuaFrameEditScrollFrame:GetWidth())
+		WowLua:SetTitle(false)
+		first = false
+	end
+
+	WowLuaFrame:Show()
+
+	if processSpecialCommands(txt) then
+		return
+	end
+
+	if txt:match("%S") then
+		WowLua:ProcessLine(txt)
+	end
+
+	WowLuaFrameCommandEditBox:SetFocus()
+end
+
+local function printf(fmt, ...)
+    print(fmt:format(...))
+end
+
+SLASH_WOWLUARUN1 = "/luarun"
+SLASH_WOWLUARUN2 = "/wowluarun"
+SlashCmdList["WOWLUARUN"] = function(txt, editbox)
+    local entry, idx = WowLua:SelectPage(txt)
+    if not entry then
+        printf("|cFF33FF99WowLua|r: Unable to find a page named '%s'", txt)
+        return
+    else
+        printf("|cFF33FF99WowLua|r: Running page '%s'", txt)
+        local func, err = loadstring(entry.content, "WowLua")
+        if not func then
+            printf("|cFF33FF99WowLua|r: Error compiling page '%s': %s", txt, err)
+        else
+            -- Call the function
+            local succ, err = pcall(func)
+
+            if not succ then
+                printf("|cFF33FF99WowLua|r: Error while running page '%s': %s", txt, err)
+            end
+        end
+    end
+end
diff --git a/WowLua.toc b/WowLua.toc
index 562102a..0338bb7 100644
--- a/WowLua.toc
+++ b/WowLua.toc
@@ -4,7 +4,7 @@
 ## Author: Cladhaire
 ## Notes: Interactive Lua interpreter and scratchpad
 ## LoadManagers: AddonLoader
-## X-LoadOn-Slash: /wowlua, /lua
+## X-LoadOn-Slash: /wowlua, /lua, /wowluarun, /luarun
 ## SavedVariables: WowLua_DB

 Localization.enUS.lua
@@ -12,3 +12,4 @@ Localization.enUS.lua
 WowLua.lua
 FAIAP.lua
 WowLua.xml
+WowLua_Config.lua
diff --git a/WowLua.xml b/WowLua.xml
index 5e5b2e0..f855faf 100644
--- a/WowLua.xml
+++ b/WowLua.xml
@@ -23,13 +23,17 @@
 		</Scripts>
 	</Frame>

-	<Frame name="WowLuaFrame" toplevel="true" movable="true" parent="UIParent" enableMouse="true" resizable="true" frameStrata="MEDIUM">
+    <Font name="WowLuaMonoFont" font="Interface\AddOns\WowLua\fonts\VeraMono.ttf">
+		<FontHeight val="14"/>
+    </Font>
+
+	<Frame name="WowLuaFrame" toplevel="true" hidden="true" movable="true" parent="UIParent" enableMouse="true" resizable="true" frameStrata="MEDIUM">
 		<Size x="640" y="512"/>
 		<Anchors>
 			<Anchor point="CENTER"/>
 		</Anchors>
 		<ResizeBounds>
-			<minResize x="365" y="300"/>
+			<minResize x="385" y="300"/>
 		</ResizeBounds>
 		<Layers>
 			<Layer level="BACKGROUND">
@@ -286,10 +290,19 @@
 										WowLuaButton_Lock:Show()
 									</OnHide>
 								</Scripts>
+                            </Button>
+                            <Button name="WowLuaButton_Config" inherits="WowLuaButtonTemplate">
+								<Anchors>
+									<Anchor point="LEFT" relativeTo="WowLuaButton_Lock" relativePoint="RIGHT">
+										<Offset x="5" y="0"/>
+									</Anchor>
+								</Anchors>
+								<NormalTexture file="Interface\AddOns\WowLua\images\config"/>
+								<HighlightTexture file="Interface\AddOns\WowLua\images\highlight"/>
 							</Button>
 							<Button name="WowLuaButton_Previous" inherits="WowLuaButtonTemplate">
 								<Anchors>
-									<Anchor point="LEFT" relativeTo="WowLuaButton_Lock" relativePoint="RIGHT">
+									<Anchor point="LEFT" relativeTo="WowLuaButton_Config" relativePoint="RIGHT">
 										<Offset x="5" y="0"/>
 									</Anchor>
 								</Anchors>
@@ -451,10 +464,8 @@
 							<OnEditFocusGained>
 								self:ClearFocus()
 							</OnEditFocusGained>
-							</Scripts>
-						<FontString font="Interface\AddOns\WowLua\fonts\VeraMono.ttf">
-							<FontHeight val="14"/>
-						</FontString>
+						</Scripts>
+                        <FontString inherits="WowLuaMonoFont"/>
 					</EditBox>
 				</ScrollChild>
 			</ScrollFrame>
@@ -493,10 +504,9 @@
 						</Anchors>
 						<Layers>
 							<Layer level="BACKGROUND">
-								<FontString name="$parentLineTest" font="Interface\AddOns\WowLua\fonts\VeraMono.ttf" hidden="true">
+								<FontString name="$parentLineTest" inherits="WowLuaMonoFont" hidden="true">
 									<Anchor point="TOPLEFT" relativePoint="TOPLEFT"/>
 									<Anchor point="TOPRIGHT" relativePoint="TOPRIGHT"/>
-									<FontHeight val="14"/>
 								</FontString>
 							</Layer>
 						</Layers>
@@ -520,12 +530,10 @@
 								WowLuaFrameEditScrollFrameScrollBar:SetValue(WowLuaFrameEditScrollFrame:GetVerticalScroll())
 							</OnCursorChanged>
 							<OnUpdate>
-								ScrollingEdit_OnUpdate(WowLuaFrameEditScrollFrame)
+								ScrollingEdit_OnUpdate(self, elapsed, WowLuaFrameEditScrollFrame)
 							</OnUpdate>
 						</Scripts>
-						<FontString font="Interface\AddOns\WowLua\fonts\VeraMono.ttf">
-							<FontHeight val="14"/>
-						</FontString>
+                        <FontString inherits="WowLuaMonoFont"/>
 					</EditBox>
 				</ScrollChild>
 			</ScrollFrame>
@@ -567,11 +575,10 @@
 						</Texture>
 					</Layer>
 					<Layer level="ARTWORK">
-						<FontString name="$parentPrompt" text="&gt; " font="Interface\AddOns\WowLua\fonts\VeraMono.ttf">
+                        <FontString name="$parentPrompt" text="&gt; " inherits="WowLuaMonoFont">
 							<Anchors>
 								<Anchor point="LEFT"/>
 							</Anchors>
-							<FontHeight val="14"/>
 						</FontString>
 					</Layer>
 				</Layers>
@@ -599,9 +606,7 @@
 								self:AddHistoryLine(text);
 							</OnEnterPressed>
 						</Scripts>
-						<FontString font="Interface\AddOns\WowLua\fonts\VeraMono.ttf">
-							<FontHeight val="14"/>
-						</FontString>
+                        <FontString inherits="WowLuaMonoFont"/>
 					</EditBox>
 				</Frames>
 			</Frame>
@@ -661,9 +666,7 @@
                         WowLuaFrameCommandEditBox:SetFocus()
                     </OnMouseDown>
 				</Scripts>
-				<FontString font="Interface\AddOns\WowLua\fonts\VeraMono.ttf" justifyH="LEFT">
-					<FontHeight val="14"/>
-				</FontString>
+                <FontString inherits="WowLuaMonoFont" justifyH="LEFT"/>
 			</ScrollingMessageFrame>
 		</Frames>
 		<Scripts>
diff --git a/WowLua_Config.lua b/WowLua_Config.lua
new file mode 100644
index 0000000..b42b838
--- /dev/null
+++ b/WowLua_Config.lua
@@ -0,0 +1,51 @@
+local addon = ...
+
+local L = WowLuaLocals
+local frame = CreateFrame("Frame", addon .. "ConfigFrame", InterfaceOptionsFramePanelContainer)
+frame.name = addon
+frame:Hide()
+frame:SetScript("OnShow", function(frame)
+    local title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
+    title:SetPoint("TOPLEFT", 16, -16)
+    title:SetText(L.CONFIG_TITLE:format(addon))
+
+    local subtitle = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
+    subtitle:SetHeight(35)
+    subtitle:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
+    subtitle:SetPoint("RIGHT", frame, -32, 0)
+    subtitle:SetNonSpaceWrap(true)
+    subtitle:SetJustifyH("LEFT")
+    subtitle:SetJustifyV("TOP")
+    subtitle:SetText(L.CONFIG_SUBTITLE)
+
+    local slider = CreateFrame("Slider", addon .. "ConfigFontSlider", frame, "OptionsSliderTemplate")
+    slider:SetPoint("TOPLEFT", subtitle, "BOTTOMLEFT", 0, -15)
+    slider:SetMinMaxValues(5, 30)
+    slider:SetValueStep(1)
+    slider.text = _G[slider:GetName() .. "Text"]
+    slider.low = _G[slider:GetName() .. "Low"]
+    slider.high = _G[slider:GetName() .. "High"]
+
+    slider.text:SetText(L.CONFIG_LABEL_FONTSIZE)
+    slider.low:SetText("Small")
+    slider.high:SetText("Large")
+    slider.tooltipText = L.CONFIG_FONTSIZE_TOOLTIP
+
+    slider:SetScript("OnValueChanged", function(self, value)
+        local file, height, flags = WowLuaMonoFont:GetFont()
+        WowLuaMonoFont:SetFont(file, value, flags)
+        WowLua_DB.fontSize = value
+    end)
+
+    local Refresh;
+    function Refresh()
+        if not frame:IsVisible() then return end
+        local file, height, flags = WowLuaMonoFont:GetFont()
+        slider:SetValue(height)
+    end
+
+    frame:SetScript("OnShow", Refresh)
+    Refresh()
+end)
+
+InterfaceOptions_AddCategory(frame)
diff --git a/images/config.tga b/images/config.tga
new file mode 100755
index 0000000..299dcd0
Binary files /dev/null and b/images/config.tga differ