Skip to content

Commit

Permalink
Menu item fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Borna authored and Borna committed May 13, 2024
1 parent a03b144 commit 4ea3594
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class Client
/// PluginInfos for loaded plugins.
/// </summary>
public List<PluginInfo> plugins;
private readonly List<ToolStripMenuItem> pluginmenuitems;
/// <summary>
/// Client constructor.
/// </summary>
Expand All @@ -84,6 +85,7 @@ public Client(Main main)
messages_snd = [];
servers = [];
plugins = [];
pluginmenuitems = [];
_ = LoadPlugins();
my = Encryption.GenerateECDH();
_ = LoadServers();
Expand Down Expand Up @@ -388,6 +390,10 @@ public async Task Disconnect(bool force = false)
client.Dispose();
}
//start new client
foreach(ToolStripMenuItem item in pluginmenuitems)
{
main.mainmenu.Items.Remove(item);
}
main.client = new Client(main);
await main.client.LoadServers();
//close all
Expand Down Expand Up @@ -619,6 +625,7 @@ public async Task LoadPlugins()
public void AddMainMenu(ToolStripMenuItem item)
{
main.mainmenu.Items.Add(item);
pluginmenuitems.Add(item);
}
}
}
24 changes: 24 additions & 0 deletions Test client plugin/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Windows.Forms;
using Client;

namespace Test_client_plugin
{
public class Class1 : IPlugin
{
public Client.Client? Client { get; set; }
public void Initialize()
{
ToolStripMenuItem menuitem = new()
{
Text = "Test"
};
menuitem.Click += Menuitem_Click;
Client?.AddMainMenu(menuitem);
}

private void Menuitem_Click(object? sender, EventArgs e)
{
MessageBox.Show("Test plugin");
}
}
}
17 changes: 17 additions & 0 deletions Test client plugin/Test client plugin.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>Test_client_plugin</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Client\Client.csproj">
<Private>False</Private>
<CopyLocalSatelliteAssemblies>False</CopyLocalSatelliteAssemblies>
<ExcludeAssets>all</ExcludeAssets>
</ProjectReference>
</ItemGroup>
</Project>
20 changes: 17 additions & 3 deletions chat.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Transport", "Transport\Tran
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CA6C16D3-8BBE-4830-BA96-7AA37C168D10}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
Plugin creation.md = Plugin creation.md
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test client", "Test client\Test client.csproj", "{B1A2A36D-2EFC-47B7-B478-EDF2E28291C3}"
Expand All @@ -27,9 +27,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfigurationData", "Config
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server_interface", "Server_interface\Server_interface.csproj", "{BC4EE1E2-FBF1-4D44-BE1D-FF3959363CC4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Guide", "Guide\Guide.csproj", "{F40764D5-2242-4E48-A58E-4474C78580D9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Guide", "Guide\Guide.csproj", "{F40764D5-2242-4E48-A58E-4474C78580D9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test server plugin", "Test server plugin\Test server plugin.csproj", "{3C32E620-1CD6-460B-9154-545CC04C449D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test server plugin", "Test server plugin\Test server plugin.csproj", "{3C32E620-1CD6-460B-9154-545CC04C449D}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test client plugin", "Test client plugin\Test client plugin.csproj", "{AACAD186-A433-4478-A8FE-C9380B143FF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -173,6 +175,18 @@ Global
{3C32E620-1CD6-460B-9154-545CC04C449D}.Release|x64.Build.0 = Release|Any CPU
{3C32E620-1CD6-460B-9154-545CC04C449D}.Release|x86.ActiveCfg = Release|Any CPU
{3C32E620-1CD6-460B-9154-545CC04C449D}.Release|x86.Build.0 = Release|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Debug|x64.ActiveCfg = Debug|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Debug|x64.Build.0 = Debug|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Debug|x86.ActiveCfg = Debug|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Debug|x86.Build.0 = Debug|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Release|Any CPU.Build.0 = Release|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Release|x64.ActiveCfg = Release|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Release|x64.Build.0 = Release|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Release|x86.ActiveCfg = Release|Any CPU
{AACAD186-A433-4478-A8FE-C9380B143FF1}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 4ea3594

Please sign in to comment.