Skip to content

Commit

Permalink
v1.0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
juleswhi committed Mar 21, 2024
1 parent dbca39b commit 5c45478
Show file tree
Hide file tree
Showing 42 changed files with 187 additions and 54 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ These tools also provide a base that your application can build upon.
Dotnet CLI:

```
dotnet add package SSDCourseworkTooling --version 0.1.0
dotnet add package SSDCourseworkTooling
```

NuGet Package Manager:

```
NuGet\Install-Package WinFormsScraper -Version 1.3.0
NuGet\Install-Package SSDCourseworkTooling
```

Visual Studio NuGet:
Expand Down
Empty file added docs/CreatingForms.md
Empty file.
Empty file added docs/CustomMasterForm.md
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified examples/CreatingUser/.vs/CreatingUser/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/CreatingUser/CreatingUser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SSDCourseworkTooling" Version="1.0.1-alpha1" />
<PackageReference Include="SSDCourseworkTooling" Version="1.0.2.1-beta" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion examples/CreatingUser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ static void Main()
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
FormManager.Start<formLogin>();
Start<formLogin>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
".NETCoreApp,Version=v7.0": {
"CreatingUser/1.0.0": {
"dependencies": {
"SSDCourseworkTooling": "1.0.1-alpha1"
"SSDCourseworkTooling": "1.0.2.1-beta"
},
"runtime": {
"CreatingUser.dll": {}
Expand All @@ -22,14 +22,14 @@
}
}
},
"SSDCourseworkTooling/1.0.1-alpha1": {
"SSDCourseworkTooling/1.0.2.1-beta": {
"dependencies": {
"Newtonsoft.Json": "13.0.3"
},
"runtime": {
"lib/net7.0-windows7.0/SSDCourseworkTooling.dll": {
"assemblyVersion": "1.0.1.0",
"fileVersion": "1.0.1.0"
"assemblyVersion": "1.0.2.1",
"fileVersion": "1.0.2.1"
}
}
}
Expand All @@ -48,12 +48,12 @@
"path": "newtonsoft.json/13.0.3",
"hashPath": "newtonsoft.json.13.0.3.nupkg.sha512"
},
"SSDCourseworkTooling/1.0.1-alpha1": {
"SSDCourseworkTooling/1.0.2.1-beta": {
"type": "package",
"serviceable": true,
"sha512": "sha512-rdZMtnUQNz1b3GFt9JV+gBirxU0bZttlo2t9Bp4IOxuRc4oIrCAv0H92gTt8LB5qbIaUZ1JIBrWl79hTzjfOtQ==",
"path": "ssdcourseworktooling/1.0.1-alpha1",
"hashPath": "ssdcourseworktooling.1.0.1-alpha1.nupkg.sha512"
"sha512": "sha512-60sQgcyCTRhdeTBpqEK+BUCFFc2YY9CMaU8DvyyyHt3yvnTdeATBMHHNVV5LJnr0kC4USyaZqxyRLpE+28nQIg==",
"path": "ssdcourseworktooling/1.0.2.1-beta",
"hashPath": "ssdcourseworktooling.1.0.2.1-beta.nupkg.sha512"
}
}
}
Binary file not shown.
Binary file modified examples/CreatingUser/bin/Debug/net7.0-windows/CreatingUser.pdb
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"dependencies": {
"SSDCourseworkTooling": {
"target": "Package",
"version": "[1.0.1-alpha1, )"
"version": "[1.0.2.1-beta, )"
}
},
"imports": [
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4467d9483a2f8f714a1763a8a9b26dcfebe40cbe
4095b7bc6fdce1532dfac8983bf6214f6e4ee905
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ C:\Users\i hate windows\Documents\GitHub\ssd-winforms-tooling\examples\CreatingU
C:\Users\i hate windows\Documents\GitHub\ssd-winforms-tooling\examples\CreatingUser\obj\Debug\net7.0-windows\CreatingUser.pdb
C:\Users\i hate windows\Documents\GitHub\ssd-winforms-tooling\examples\CreatingUser\obj\Debug\net7.0-windows\CreatingUser.genruntimeconfig.cache
C:\Users\i hate windows\Documents\GitHub\ssd-winforms-tooling\examples\CreatingUser\obj\Debug\net7.0-windows\ref\CreatingUser.dll
C:\Users\i hate windows\Documents\GitHub\ssd-winforms-tooling\examples\CreatingUser\obj\Debug\net7.0-windows\CreatingUser.formMainMainMain.resources
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
}
}
},
"SSDCourseworkTooling/1.0.1-alpha1": {
"SSDCourseworkTooling/1.0.2.1-beta": {
"dependencies": {
"Newtonsoft.Json": "13.0.3"
},
"runtime": {
"lib/net7.0-windows7.0/SSDCourseworkTooling.dll": {
"assemblyVersion": "1.0.1.0",
"fileVersion": "1.0.1.0"
"assemblyVersion": "1.0.2.1",
"fileVersion": "1.0.2.1"
}
}
}
Expand All @@ -35,12 +35,12 @@
"path": "newtonsoft.json/13.0.3",
"hashPath": "newtonsoft.json.13.0.3.nupkg.sha512"
},
"SSDCourseworkTooling/1.0.1-alpha1": {
"SSDCourseworkTooling/1.0.2.1-beta": {
"type": "package",
"serviceable": true,
"sha512": "sha512-rdZMtnUQNz1b3GFt9JV+gBirxU0bZttlo2t9Bp4IOxuRc4oIrCAv0H92gTt8LB5qbIaUZ1JIBrWl79hTzjfOtQ==",
"path": "ssdcourseworktooling/1.0.1-alpha1",
"hashPath": "ssdcourseworktooling.1.0.1-alpha1.nupkg.sha512"
"sha512": "sha512-60sQgcyCTRhdeTBpqEK+BUCFFc2YY9CMaU8DvyyyHt3yvnTdeATBMHHNVV5LJnr0kC4USyaZqxyRLpE+28nQIg==",
"path": "ssdcourseworktooling/1.0.2.1-beta",
"hashPath": "ssdcourseworktooling.1.0.2.1-beta.nupkg.sha512"
}
}
}
Binary file not shown.
Binary file not shown.
Binary file modified examples/CreatingUser/obj/Debug/net7.0-windows/CreatingUser.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
14 changes: 7 additions & 7 deletions examples/CreatingUser/obj/project.assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
}
},
"SSDCourseworkTooling/1.0.1-alpha1": {
"SSDCourseworkTooling/1.0.2.1-beta": {
"type": "package",
"dependencies": {
"Newtonsoft.Json": "13.0.3"
Expand Down Expand Up @@ -63,23 +63,23 @@
"packageIcon.png"
]
},
"SSDCourseworkTooling/1.0.1-alpha1": {
"sha512": "rdZMtnUQNz1b3GFt9JV+gBirxU0bZttlo2t9Bp4IOxuRc4oIrCAv0H92gTt8LB5qbIaUZ1JIBrWl79hTzjfOtQ==",
"SSDCourseworkTooling/1.0.2.1-beta": {
"sha512": "60sQgcyCTRhdeTBpqEK+BUCFFc2YY9CMaU8DvyyyHt3yvnTdeATBMHHNVV5LJnr0kC4USyaZqxyRLpE+28nQIg==",
"type": "package",
"path": "ssdcourseworktooling/1.0.1-alpha1",
"path": "ssdcourseworktooling/1.0.2.1-beta",
"files": [
".nupkg.metadata",
"LICENSE",
"README.md",
"lib/net7.0-windows7.0/SSDCourseworkTooling.dll",
"ssdcourseworktooling.1.0.1-alpha1.nupkg.sha512",
"ssdcourseworktooling.1.0.2.1-beta.nupkg.sha512",
"ssdcourseworktooling.nuspec"
]
}
},
"projectFileDependencyGroups": {
"net7.0-windows7.0": [
"SSDCourseworkTooling >= 1.0.1-alpha1"
"SSDCourseworkTooling >= 1.0.2.1-beta"
]
},
"packageFolders": {
Expand Down Expand Up @@ -131,7 +131,7 @@
"dependencies": {
"SSDCourseworkTooling": {
"target": "Package",
"version": "[1.0.1-alpha1, )"
"version": "[1.0.2.1-beta, )"
}
},
"imports": [
Expand Down
4 changes: 2 additions & 2 deletions examples/CreatingUser/obj/project.nuget.cache
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"version": 2,
"dgSpecHash": "HcvCwCk8tbPi4FBqcjR94bcpEuBkEe0s9dybMSK8oqiRGXlVCRnPvkrm/iUVNKIca1IQlRpfKL1OsWY7Vi+k9w==",
"dgSpecHash": "qACPvW3rw+8cmYaYEmQb5VFNwr41Wm9ZxcQSx6d8Ax6bwd9aEBtEvwqcKFprZBuJTPJBl/y9XEtWHxIz1BL6yA==",
"success": true,
"projectFilePath": "C:\\Users\\i hate windows\\Documents\\GitHub\\ssd-winforms-tooling\\examples\\CreatingUser\\CreatingUser.csproj",
"expectedPackageFiles": [
"C:\\Users\\i hate windows\\.nuget\\packages\\newtonsoft.json\\13.0.3\\newtonsoft.json.13.0.3.nupkg.sha512",
"C:\\Users\\i hate windows\\.nuget\\packages\\ssdcourseworktooling\\1.0.1-alpha1\\ssdcourseworktooling.1.0.1-alpha1.nupkg.sha512"
"C:\\Users\\i hate windows\\.nuget\\packages\\ssdcourseworktooling\\1.0.2.1-beta\\ssdcourseworktooling.1.0.2.1-beta.nupkg.sha512"
],
"logs": []
}
76 changes: 68 additions & 8 deletions src/FormSystem/FormManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,82 @@ public static class FormManager

internal static State GlobalState { get; set; } = new State();

private static formMaster _master = new();
private static IFormMaster? _master;

public static void Start<T>(Action<formMaster>? callback = null) where T : Form, new()
{
_master = new formMaster();

Trigger<T>();

if (callback is Action<formMaster> action)
if (callback is Action<IFormMaster> action)
{
action(_master);
}

Application.Run(_master);
Application.Run((formMaster)_master);
}

// Name "Activate" is already used as part of the Form namespace
public static void Trigger<T>(State? state = null) where T : Form, new()
public static void Start<TMasterForm, TStartForm>(Action<TMasterForm>? callback = null)
where TMasterForm : Form, IFormMaster, new()
where TStartForm : Form, new()
{
// Create instance of TMasterForm
var master = CreateForm<TMasterForm>();

_master = master;

Trigger<TStartForm>();

if(callback is Action<IFormMaster> action)
{
action(_master);
}

Application.Run((TMasterForm)_master);

}

/// <summary>
/// A method which loads another form to the master form
/// </summary>
/// <typeparam name="T">The type of form to load</typeparam>
/// <param name="state">Any state to pass through</param>
/// <returns>A state representing either a Success or Failure</returns>
public static State Trigger<T>(State? state = null) where T : Form, new()
{
if(_master is null)
{
return FlagFailure;
}

state ??= new();

T form = CreateForm<T>(state);

_master.LoadForm(form);

return FlagSuccess;
}

public static void Trigger<T>(params State[] state) where T : Form, new()
/// <summary>
/// A method which loads another form to the master form
/// </summary>
/// <typeparam name="T">The type of form to load</typeparam>
/// <param name="state">An array of any state to pass through</param>
/// <returns>A state representing either a Success or Failure</returns>
public static State Trigger<T>(params State[] state) where T : Form, new()
{
if(_master is null)
{
return FlagFailure;
}

T form = CreateForm<T>(AddStates(state));

_master.LoadForm(form);

return FlagSuccess;
}

public static void Trigger<T>(object obj, params StateType[] stateTypes)
Expand All @@ -49,7 +94,12 @@ public static void Trigger<T>(object obj, params StateType[] stateTypes)
Trigger<T>(state);
}

// Create the form instance and pass both global state and scoped state
/// <summary>
/// Creates a form from a type, and attempts to pass state through
/// </summary>
/// <typeparam name="T">The type of form to create</typeparam>
/// <param name="state">The state to be passed through</param>
/// <returns>The form object</returns>
private static T CreateForm<T>(State? state = null) where T : Form, new()
{
state ??= new State();
Expand All @@ -62,14 +112,24 @@ public static void Trigger<T>(object obj, params StateType[] stateTypes)
}


private static void PassStateToForm<T>(this T instance, State state) where T : Form, new()
/// <summary>
/// Attempts to pass state to the form
/// </summary>
/// <typeparam name="T">The type of form to be passed into</typeparam>
/// <param name="instance">The actual form to be state-ified</param>
/// <param name="state">The state to be passed into the form</param>
private static State PassStateToForm<T>(this T instance, State state) where T : Form, new()
{
var method = typeof(IState).GetMethods()[0];

if (method is not null && typeof(IState).IsAssignableFrom(typeof(T)))
{
method!.Invoke(instance, [state]);
return FlagSuccess;
}

return FlagFailure;

}
#endregion
}
24 changes: 24 additions & 0 deletions src/FormSystem/IFormMaster.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace FormSystem;

public interface IFormMaster
{
Panel GetHolder();
void LoadForm(Form form)
{

form.TopLevel = false;
form.Dock = DockStyle.Fill;
form.FormBorderStyle = FormBorderStyle.None;
form.Enabled = true;
form.Visible = true;

var panel = GetHolder();

panel.Controls.Clear();
panel.Controls.Add(form);
panel.Show();
form.Show();

form.Refresh();
}
}
7 changes: 3 additions & 4 deletions src/Forms/formMaster.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
namespace FormSystem.Forms;

public partial class formMaster : Form
public partial class formMaster : Form, IFormMaster
{
public Func<Panel>? GetHolder { get; set; } = null;
public formMaster()
{
InitializeComponent();
panelHolder.Dock = DockStyle.Fill;
GetHolder = () => panelHolder;
}

public Panel GetHolder() => panelHolder;

public void LoadForm(Form form)
{
form.TopLevel = false;
Expand All @@ -25,5 +25,4 @@ public void LoadForm(Form form)

Refresh();
}

}
Loading

0 comments on commit 5c45478

Please sign in to comment.