Quantcast

Close button now shows unsaved dialog

Cogwheel-17646 [04-30-08 - 03:16]
Close button now shows unsaved dialog
No longer auto-saves on run (should we add an auto save check box?)
Filename
Localization.enUS.lua
WowLua.lua
WowLua.xml
diff --git a/Localization.enUS.lua b/Localization.enUS.lua
index 151297d..2fd0e54 100644
--- a/Localization.enUS.lua
+++ b/Localization.enUS.lua
@@ -8,18 +8,18 @@ L.NEW_PAGE_TITLE = "Untitled %d"
 L.RELOAD_COMMAND = "/reload"
 L.RESET_COMMAND  = "/reset"

-L.TOOLTIPS = {
-	["New"] = { name = "New", text = "Create a new script page" },
-	["Open"] = { name = "Open", text = "Open an existing script page" },
-	["Save"] = { name = "Save", text = "Save the current page\n\nHint: You can shift-click this button to rename a page" },
-	["Undo"] = { name = "Undo", text = "Revert to the last saved version" },
-	["Delete"] = { name = "Delete", text = "Delete the current page" },
-	["Lock"] = { name = "Lock", text = "This page is unlocked to allow changes. Click to lock." },
-	["Unlock"] = { name = "Unlock", text = "This page is locked to prevent changes. Click to unlock." },
-	["Previous"] = { name = "Previous", text = "Navigate back one page" },
-	["Next"] = { name = "Next", text = "Navigate forward one page" },
-	["Run"] = { name = "Run", text = "Run the current script" },
-}
+L.TOOLTIPS = {}
+L.TOOLTIPS["New"] = { name = "New", text = "Create a new script page" }
+L.TOOLTIPS["Open"] = { name = "Open", text = "Open an existing script page" }
+L.TOOLTIPS["Save"] = { name = "Save", text = "Save the current page\n\nHint: You can shift-click this button to rename a page" }
+L.TOOLTIPS["Undo"] = { name = "Undo", text = "Revert to the last saved version" }
+L.TOOLTIPS["Delete"] = { name = "Delete", text = "Delete the current page" }
+L.TOOLTIPS["Lock"] = { name = "Lock", text = "This page is unlocked to allow changes. Click to lock." }
+L.TOOLTIPS["Unlock"] = { name = "Unlock", text = "This page is locked to prevent changes. Click to unlock." }
+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["Close"] = { name = "Close" }

 L.OPEN_MENU_TITLE = "Select a Script"
 L.SAVE_AS_TEXT = "Save %s with the following name:"
diff --git a/WowLua.lua b/WowLua.lua
index e76337b..306c678 100644
--- a/WowLua.lua
+++ b/WowLua.lua
@@ -270,6 +270,8 @@ function WowLua:Button_OnClick(button)
 		WowLua:Button_Next(button)
 	elseif operation == "Run" then
 		WowLua:Button_Run(button)
+	elseif operation == "Close" then
+		WowLua:Button_Close(button)
 	end
 end

@@ -517,7 +519,6 @@ function WowLua.lockedTextChanged(box)
 end

 function WowLua:Button_Run()
-	self:Button_Save()
 	local text = WowLuaFrameEditBox:GetText()

 	-- Run the script, if there is an error then highlight it
@@ -546,6 +547,17 @@ function WowLua:Button_Run()
 	end
 end

+function WowLua:Button_Close()
+	if self:IsModified() then
+		-- Display the unsaved changes dialog
+		local dialog = StaticPopup_Show("WOWLUA_UNSAVED")
+		dialog.data = "Button_Close"
+		return
+	end
+
+	HideUIPanel(WowLuaFrame)
+end
+
 function WowLua:IsModified()
 	local page,entry = self:GetCurrentPage()
 	local orig = entry.content
diff --git a/WowLua.xml b/WowLua.xml
index b80c3a1..c046e2d 100644
--- a/WowLua.xml
+++ b/WowLua.xml
@@ -159,12 +159,23 @@
 			</Layer>
 		</Layers>
 		<Frames>
-			<Button name="$parentClose" inherits="UIPanelCloseButton">
+			<Button name="WowLuaButton_Close" inherits="UIPanelCloseButton">
 				<Anchors>
 					<Anchor point="TOPRIGHT">
 						<Offset x="5" y="-10"/>
 					</Anchor>
 				</Anchors>
+				<Scripts>
+					<OnClick>
+						WowLua:Button_OnClick(self, button)
+					</OnClick>
+					<OnEnter>
+						WowLua:Button_OnEnter(self)
+					</OnEnter>
+					<OnLeave>
+						WowLua:Button_OnLeave(self)
+					</OnLeave>
+				</Scripts>
 			</Button>
 			<Button name="$parentDragHeader">
 				<Size y="60"/>