From b2b7d4c442dffc518f0f29d3fabb9c06ea9c4229 Mon Sep 17 00:00:00 2001 From: MichaelTheShifter Date: Tue, 5 Jul 2016 18:29:22 -0400 Subject: [PATCH] on_window_open(userdata ShiftOSDesktop, string) and on_window_close(userdata ShiftOSDesktop, string) now report window GUIDs to their handlers instead of userdata Form objects. You can now use get_window(string) to get a Form from a window GUID. --- source/WindowsFormsApplication1/API.cs | 4 +- .../Controls/WindowBorder.cs | 1 + .../Engine/Lua_Interp.cs | 52 ++++++++++++++----- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/source/WindowsFormsApplication1/API.cs b/source/WindowsFormsApplication1/API.cs index f952a18..2fe6126 100644 --- a/source/WindowsFormsApplication1/API.cs +++ b/source/WindowsFormsApplication1/API.cs @@ -82,7 +82,8 @@ public class ModApplauncherItem public class API { - + public static Dictionary OpenGUIDs = new Dictionary(); + /// /// Settings file. /// @@ -1188,6 +1189,7 @@ public static void CreateForm(Form formToCreate, string AppName, Image AppIcon) } })); WindowComposition.SafeToAddControls = true; + API.OpenGUIDs.Add(formToCreate, Guid.NewGuid().ToString()); API.CurrentSession.Invoke(new Action(() => { CurrentSession.InvokeWindowOp("open", formToCreate); })); }; bw.RunWorkerAsync(); diff --git a/source/WindowsFormsApplication1/Controls/WindowBorder.cs b/source/WindowsFormsApplication1/Controls/WindowBorder.cs index ccd86ee..50f245d 100644 --- a/source/WindowsFormsApplication1/Controls/WindowBorder.cs +++ b/source/WindowsFormsApplication1/Controls/WindowBorder.cs @@ -785,6 +785,7 @@ private void Clock_FormClosing(object sender, FormClosingEventArgs e) WindowComposition.CloseForm(this.ParentForm, pbtn, API.CurrentSkin.WindowCloseAnimation); } API.CurrentSession.InvokeWindowOp("close", this.ParentForm); + API.OpenGUIDs.Remove(this.ParentForm); } } #endregion diff --git a/source/WindowsFormsApplication1/Engine/Lua_Interp.cs b/source/WindowsFormsApplication1/Engine/Lua_Interp.cs index 5b338ae..529518e 100644 --- a/source/WindowsFormsApplication1/Engine/Lua_Interp.cs +++ b/source/WindowsFormsApplication1/Engine/Lua_Interp.cs @@ -137,16 +137,24 @@ public void RegisterCore() { desktop.WindowOpened += (win) => { - mod.win = win; - mod(func + "(win)"); + mod(func + $"(\"{API.OpenGUIDs[win]}\")"); }; }); + mod.get_window = new Func((guid) => + { + Form frm = null; + foreach(var kv in API.OpenGUIDs) + { + if (kv.Value == guid) + frm = kv.Key; + } + return frm; + }); mod.on_window_close += new Action((desktop, func) => { desktop.WindowClosed += (win) => { - mod.win = win; - mod(func + "(win)"); + mod(func + $"(\"{API.OpenGUIDs[win]}\")"); }; }); mod.on_window_titlebar_redraw += new Action((desktop, func) => @@ -342,6 +350,25 @@ public void RegisterCore() mod.json_serialize = new Func((objectToSerialize) => Newtonsoft.Json.JsonConvert.SerializeObject(objectToSerialize)); mod.json_unserialize = new Func((json_string) => Newtonsoft.Json.JsonConvert.DeserializeObject(json_string)); mod.open_image = new Func((filename) => OpenImage(filename)); + mod.list_add = new Action((lst, itm) => + { + if(lst is ListBox) + { + var box = lst as ListBox; + box.Items.Add(itm); + } + }); + mod.list_get_selected = new Func((lst) => + { + if(lst is ListBox) + { + return (lst as ListBox).SelectedItem?.ToString(); + } + else + { + return null; + } + }); mod.get_skin = new Func(() => { return API.CurrentSkin; @@ -618,16 +645,9 @@ public void RegisterCore() mod.toggle_unity = new Action(() => API.CurrentSession.SetUnityMode()); mod.lua = new Func((luacode) => { - var li = new LuaInterpreter(); - try - { - li.mod(luacode); - return "success"; - } - catch (Exception ex) - { - return ex.Message; - } + mod(luacode); + return "success"; + }); mod.fileskimmer_open += new Action((filters, func) => { @@ -1063,6 +1083,10 @@ public Control ConstructControl(string type, string text, int x, int y, int widt stxt.SetLanguage(SyntaxSettings.Language.Lua); ctrl = stxt; break; + case "list": + var lst = new ListBox(); + ctrl = lst; + break; case "button": var btn = new Button(); btn.FlatStyle = FlatStyle.Flat;