mirror of
https://github.com/seriocomedy/ShiftOS-C-.git
synced 2025-01-22 10:50:27 -05:00
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.
This commit is contained in:
parent
ad0e84c4be
commit
b2b7d4c442
3 changed files with 42 additions and 15 deletions
|
@ -82,6 +82,7 @@ public class ModApplauncherItem
|
||||||
|
|
||||||
public class API
|
public class API
|
||||||
{
|
{
|
||||||
|
public static Dictionary<Form, string> OpenGUIDs = new Dictionary<Form, string>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Settings file.
|
/// Settings file.
|
||||||
|
@ -1188,6 +1189,7 @@ public static void CreateForm(Form formToCreate, string AppName, Image AppIcon)
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
WindowComposition.SafeToAddControls = true;
|
WindowComposition.SafeToAddControls = true;
|
||||||
|
API.OpenGUIDs.Add(formToCreate, Guid.NewGuid().ToString());
|
||||||
API.CurrentSession.Invoke(new Action(() => { CurrentSession.InvokeWindowOp("open", formToCreate); }));
|
API.CurrentSession.Invoke(new Action(() => { CurrentSession.InvokeWindowOp("open", formToCreate); }));
|
||||||
};
|
};
|
||||||
bw.RunWorkerAsync();
|
bw.RunWorkerAsync();
|
||||||
|
|
|
@ -785,6 +785,7 @@ private void Clock_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
WindowComposition.CloseForm(this.ParentForm, pbtn, API.CurrentSkin.WindowCloseAnimation);
|
WindowComposition.CloseForm(this.ParentForm, pbtn, API.CurrentSkin.WindowCloseAnimation);
|
||||||
}
|
}
|
||||||
API.CurrentSession.InvokeWindowOp("close", this.ParentForm);
|
API.CurrentSession.InvokeWindowOp("close", this.ParentForm);
|
||||||
|
API.OpenGUIDs.Remove(this.ParentForm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -137,16 +137,24 @@ public void RegisterCore()
|
||||||
{
|
{
|
||||||
desktop.WindowOpened += (win) =>
|
desktop.WindowOpened += (win) =>
|
||||||
{
|
{
|
||||||
mod.win = win;
|
mod(func + $"(\"{API.OpenGUIDs[win]}\")");
|
||||||
mod(func + "(win)");
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
mod.get_window = new Func<string, Form>((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<ShiftOSDesktop, string>((desktop, func) =>
|
mod.on_window_close += new Action<ShiftOSDesktop, string>((desktop, func) =>
|
||||||
{
|
{
|
||||||
desktop.WindowClosed += (win) =>
|
desktop.WindowClosed += (win) =>
|
||||||
{
|
{
|
||||||
mod.win = win;
|
mod(func + $"(\"{API.OpenGUIDs[win]}\")");
|
||||||
mod(func + "(win)");
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
mod.on_window_titlebar_redraw += new Action<ShiftOSDesktop, string>((desktop, func) =>
|
mod.on_window_titlebar_redraw += new Action<ShiftOSDesktop, string>((desktop, func) =>
|
||||||
|
@ -342,6 +350,25 @@ public void RegisterCore()
|
||||||
mod.json_serialize = new Func<object, string>((objectToSerialize) => Newtonsoft.Json.JsonConvert.SerializeObject(objectToSerialize));
|
mod.json_serialize = new Func<object, string>((objectToSerialize) => Newtonsoft.Json.JsonConvert.SerializeObject(objectToSerialize));
|
||||||
mod.json_unserialize = new Func<string, object>((json_string) => Newtonsoft.Json.JsonConvert.DeserializeObject(json_string));
|
mod.json_unserialize = new Func<string, object>((json_string) => Newtonsoft.Json.JsonConvert.DeserializeObject(json_string));
|
||||||
mod.open_image = new Func<string, Image>((filename) => OpenImage(filename));
|
mod.open_image = new Func<string, Image>((filename) => OpenImage(filename));
|
||||||
|
mod.list_add = new Action<Control, string>((lst, itm) =>
|
||||||
|
{
|
||||||
|
if(lst is ListBox)
|
||||||
|
{
|
||||||
|
var box = lst as ListBox;
|
||||||
|
box.Items.Add(itm);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mod.list_get_selected = new Func<Control, string>((lst) =>
|
||||||
|
{
|
||||||
|
if(lst is ListBox)
|
||||||
|
{
|
||||||
|
return (lst as ListBox).SelectedItem?.ToString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
mod.get_skin = new Func<Skinning.Skin>(() =>
|
mod.get_skin = new Func<Skinning.Skin>(() =>
|
||||||
{
|
{
|
||||||
return API.CurrentSkin;
|
return API.CurrentSkin;
|
||||||
|
@ -618,16 +645,9 @@ public void RegisterCore()
|
||||||
mod.toggle_unity = new Action(() => API.CurrentSession.SetUnityMode());
|
mod.toggle_unity = new Action(() => API.CurrentSession.SetUnityMode());
|
||||||
mod.lua = new Func<string, string>((luacode) =>
|
mod.lua = new Func<string, string>((luacode) =>
|
||||||
{
|
{
|
||||||
var li = new LuaInterpreter();
|
mod(luacode);
|
||||||
try
|
|
||||||
{
|
|
||||||
li.mod(luacode);
|
|
||||||
return "success";
|
return "success";
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return ex.Message;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
mod.fileskimmer_open += new Action<string, string>((filters, func) =>
|
mod.fileskimmer_open += new Action<string, string>((filters, func) =>
|
||||||
{
|
{
|
||||||
|
@ -1063,6 +1083,10 @@ public Control ConstructControl(string type, string text, int x, int y, int widt
|
||||||
stxt.SetLanguage(SyntaxSettings.Language.Lua);
|
stxt.SetLanguage(SyntaxSettings.Language.Lua);
|
||||||
ctrl = stxt;
|
ctrl = stxt;
|
||||||
break;
|
break;
|
||||||
|
case "list":
|
||||||
|
var lst = new ListBox();
|
||||||
|
ctrl = lst;
|
||||||
|
break;
|
||||||
case "button":
|
case "button":
|
||||||
var btn = new Button();
|
var btn = new Button();
|
||||||
btn.FlatStyle = FlatStyle.Flat;
|
btn.FlatStyle = FlatStyle.Flat;
|
||||||
|
|
Loading…
Reference in a new issue