From bcce72f36b5eac1dff5b737c39971a90dcdaeb2d Mon Sep 17 00:00:00 2001 From: James Whitehead II Date: Sat, 17 Jul 2010 13:10:26 +0000 Subject: [PATCH] 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 --- Localization.enUS.lua | 7 ++++ WowLua.lua | 103 ++++++++++++++++++++++++++++++++++++------------- WowLua.toc | 3 +- WowLua.xml | 45 +++++++++++---------- WowLua_Config.lua | 51 ++++++++++++++++++++++++ images/config.tga | Bin 0 -> 12179 bytes 6 files changed, 160 insertions(+), 49 deletions(-) create mode 100644 WowLua_Config.lua create mode 100755 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 @@ - + + + + + - + @@ -286,10 +290,19 @@ WowLuaButton_Lock:Show() + +