From fb0898fad1b57e8efcec23a2065f45328eef55d4 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Mon, 20 May 2024 18:50:10 +0200 Subject: [PATCH] finally more structure --- OwnChar | 2 +- OwnChar.App.Desktop/Api/IMainWindowApi.cs | 8 ++- OwnChar.App.Desktop/Api/IOwnCharApi.cs | 7 +- .../Api/Parameters/AppInitParams.cs | 14 ++++ .../Api/Parameters/MainWindowParams.cs | 14 ++++ OwnChar.App.Desktop/AppApi.cs | 3 + OwnChar.App.Desktop/AppPlugin.cs | 3 +- .../MainWindow/MainTabs/TabMyGroupsFeature.cs | 16 ----- .../MainWindow/MainTabs/TabMyUserFeature.cs | 16 ----- .../MainWindow/QuickAction/HomeFeature.cs | 16 ++--- .../MainWindow/QuickAction/SettingsFeature.cs | 16 ++--- .../OwnChar.App.Desktop.csproj | 4 ++ OwnChar.App.Desktop/Program.cs | 14 +++- .../UI/MainTabs/TabCharView.cs | 20 ++++-- .../UI/MainTabs/TabGroupView.cs | 27 ++++---- .../UI/MainTabs/TabGroupsView.cs | 24 +++---- .../UI/MainTabs/TabSettingsView.Designer.cs | 37 +++++++++++ .../UI/MainTabs/TabSettingsView.cs | 18 +++++ .../UI/MainTabs/TabUserView.cs | 37 +++++++---- .../UI/Windows/MainWindow.Designer.cs | 21 +++++- OwnChar.App.Desktop/UI/Windows/MainWindow.cs | 66 ++++++++++++++++--- OwnChar.Plugins | 2 +- 22 files changed, 279 insertions(+), 106 deletions(-) create mode 100644 OwnChar.App.Desktop/Api/Parameters/AppInitParams.cs create mode 100644 OwnChar.App.Desktop/Api/Parameters/MainWindowParams.cs delete mode 100644 OwnChar.App.Desktop/Features/MainWindow/MainTabs/TabMyGroupsFeature.cs delete mode 100644 OwnChar.App.Desktop/Features/MainWindow/MainTabs/TabMyUserFeature.cs create mode 100644 OwnChar.App.Desktop/UI/MainTabs/TabSettingsView.Designer.cs create mode 100644 OwnChar.App.Desktop/UI/MainTabs/TabSettingsView.cs diff --git a/OwnChar b/OwnChar index dab404d..b2f0a80 160000 --- a/OwnChar +++ b/OwnChar @@ -1 +1 @@ -Subproject commit dab404d95e1320f88ef183725b5a49c410692cad +Subproject commit b2f0a80872ccb736dd58eb95512d70a19087fa6e diff --git a/OwnChar.App.Desktop/Api/IMainWindowApi.cs b/OwnChar.App.Desktop/Api/IMainWindowApi.cs index bad4d94..8187294 100644 --- a/OwnChar.App.Desktop/Api/IMainWindowApi.cs +++ b/OwnChar.App.Desktop/Api/IMainWindowApi.cs @@ -1,10 +1,14 @@ -using System.Windows.Forms; +using OwnChar.Manager; +using System.Windows.Forms; namespace OwnChar.App.Desktop.Api { public interface IMainWindowApi { - void OpenTab(Control content); + OwnCharManager? Manager { get; } + void OpenTab(Control content, string title); void CloseTab(Control content); + bool IsTabOpen(Control content); + bool IsTabOpen(); } } diff --git a/OwnChar.App.Desktop/Api/IOwnCharApi.cs b/OwnChar.App.Desktop/Api/IOwnCharApi.cs index 1280b25..7f1ffb4 100644 --- a/OwnChar.App.Desktop/Api/IOwnCharApi.cs +++ b/OwnChar.App.Desktop/Api/IOwnCharApi.cs @@ -1,4 +1,5 @@ -using System; +using Pilz.Configuration; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,7 +9,7 @@ namespace OwnChar.App.Desktop.Api { public interface IOwnCharApi { - public static IOwnCharApi Instance { get; } = new AppApi(); - public IMainWindowApi? MainWindow { get; internal set; } + public abstract IMainWindowApi? MainWindow { get; } + public abstract ISettings? Settings { get; } } } diff --git a/OwnChar.App.Desktop/Api/Parameters/AppInitParams.cs b/OwnChar.App.Desktop/Api/Parameters/AppInitParams.cs new file mode 100644 index 0000000..4d022c6 --- /dev/null +++ b/OwnChar.App.Desktop/Api/Parameters/AppInitParams.cs @@ -0,0 +1,14 @@ +using OwnChar.Plugins; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OwnChar.App.Desktop.Api.Parameters +{ + public class AppInitParams(IOwnCharApi api) : OwnCharPluginInitParams + { + public IOwnCharApi Api { get; set; } = api; + } +} diff --git a/OwnChar.App.Desktop/Api/Parameters/MainWindowParams.cs b/OwnChar.App.Desktop/Api/Parameters/MainWindowParams.cs new file mode 100644 index 0000000..665e5b2 --- /dev/null +++ b/OwnChar.App.Desktop/Api/Parameters/MainWindowParams.cs @@ -0,0 +1,14 @@ +using Pilz.Plugins.Advanced; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OwnChar.App.Desktop.Api.Parameters +{ + public class MainWindowParams(IMainWindowApi api) : PluginFunctionParameter + { + public IMainWindowApi Api { get; } = api; + } +} diff --git a/OwnChar.App.Desktop/AppApi.cs b/OwnChar.App.Desktop/AppApi.cs index 883b795..cccac22 100644 --- a/OwnChar.App.Desktop/AppApi.cs +++ b/OwnChar.App.Desktop/AppApi.cs @@ -1,4 +1,5 @@ using OwnChar.App.Desktop.Api; +using Pilz.Configuration; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +10,8 @@ namespace OwnChar.App.Desktop { public sealed class AppApi : IOwnCharApi { + public static AppApi Instance { get; } = new(); public IMainWindowApi? MainWindow { get; internal set; } + public ISettings? Settings { get; internal set; } } } diff --git a/OwnChar.App.Desktop/AppPlugin.cs b/OwnChar.App.Desktop/AppPlugin.cs index 455f281..791d9bd 100644 --- a/OwnChar.App.Desktop/AppPlugin.cs +++ b/OwnChar.App.Desktop/AppPlugin.cs @@ -1,5 +1,6 @@ using OwnChar.App.Desktop.Api; using OwnChar.Plugins; +using Pilz.Configuration; using Pilz.Plugins.Advanced; namespace OwnChar.App.Desktop @@ -19,7 +20,7 @@ namespace OwnChar.App.Desktop public object? GetApi() { - return IOwnCharApi.Instance; + return AppApi.Instance; } } } diff --git a/OwnChar.App.Desktop/Features/MainWindow/MainTabs/TabMyGroupsFeature.cs b/OwnChar.App.Desktop/Features/MainWindow/MainTabs/TabMyGroupsFeature.cs deleted file mode 100644 index 5347eb6..0000000 --- a/OwnChar.App.Desktop/Features/MainWindow/MainTabs/TabMyGroupsFeature.cs +++ /dev/null @@ -1,16 +0,0 @@ -using OwnChar.App.Desktop.UI.MainTabs; -using Pilz.Plugins.Advanced; -using Pilz.Plugins.Advanced.UI.Telerik; - -namespace OwnChar.App.Desktop.Features.MainWindow.MainTabs -{ - internal class TabMyGroupsFeature() : PluginModule(FeatureCodes.MainTab, "ownchar.mygroups", "My groups"), IPluginFeatureProvider - { - public static TabMyGroupsFeature Instance { get; } = new(); - - protected override PluginModuleUI CreateNewUI() - { - return new TabGroupsView(); - } - } -} diff --git a/OwnChar.App.Desktop/Features/MainWindow/MainTabs/TabMyUserFeature.cs b/OwnChar.App.Desktop/Features/MainWindow/MainTabs/TabMyUserFeature.cs deleted file mode 100644 index 07c120e..0000000 --- a/OwnChar.App.Desktop/Features/MainWindow/MainTabs/TabMyUserFeature.cs +++ /dev/null @@ -1,16 +0,0 @@ -using OwnChar.App.Desktop.UI.MainTabs; -using Pilz.Plugins.Advanced; -using Pilz.Plugins.Advanced.UI.Telerik; - -namespace OwnChar.App.Desktop.Features.MainWindow.MainTabs -{ - internal class TabMyUserFeature() : PluginModule(FeatureCodes.MainTab, "ownchar.myuser", "My user"), IPluginFeatureProvider - { - public static TabMyUserFeature Instance { get; } = new(); - - protected override PluginModuleUI CreateNewUI() - { - return new TabUserView(); - } - } -} diff --git a/OwnChar.App.Desktop/Features/MainWindow/QuickAction/HomeFeature.cs b/OwnChar.App.Desktop/Features/MainWindow/QuickAction/HomeFeature.cs index 9b2c7e0..9136210 100644 --- a/OwnChar.App.Desktop/Features/MainWindow/QuickAction/HomeFeature.cs +++ b/OwnChar.App.Desktop/Features/MainWindow/QuickAction/HomeFeature.cs @@ -1,18 +1,18 @@ -using OwnChar.App.Desktop.Features.MainWindow.MainTabs; +using OwnChar.App.Desktop.Api.Parameters; +using OwnChar.App.Desktop.UI.MainTabs; using Pilz.Plugins.Advanced; -using Pilz.Plugins.Advanced.UI.Telerik; -using System; namespace OwnChar.App.Desktop.Features.MainWindow.QuickAction { - internal class HomeFeature() : PluginModule(FeatureCodes.QuickAction, "ownchar.home", "Home"), IPluginFeatureProvider + internal class HomeFeature() : PluginFunction(FeatureCodes.QuickAction, "ownchar.home", "Home"), IPluginFeatureProvider { - public static TabMyUserFeature Instance { get; } = new(); + public static HomeFeature Instance { get; } = new(); - protected override PluginModuleUI CreateNewUI() + protected override object? ExecuteFunction(PluginFunctionParameter? @params) { - throw new NotImplementedException(); - //return new TabEditChar(); + if (@params is MainWindowParams p) + p.Api.OpenTab(new TabUserView(p.Api, p.Api.Manager?.CurrentUser)); + return null; } } } diff --git a/OwnChar.App.Desktop/Features/MainWindow/QuickAction/SettingsFeature.cs b/OwnChar.App.Desktop/Features/MainWindow/QuickAction/SettingsFeature.cs index bacf8ef..4a676cb 100644 --- a/OwnChar.App.Desktop/Features/MainWindow/QuickAction/SettingsFeature.cs +++ b/OwnChar.App.Desktop/Features/MainWindow/QuickAction/SettingsFeature.cs @@ -1,18 +1,18 @@ -using OwnChar.App.Desktop.Features.MainWindow.MainTabs; +using OwnChar.App.Desktop.Api.Parameters; +using OwnChar.App.Desktop.UI.MainTabs; using Pilz.Plugins.Advanced; -using Pilz.Plugins.Advanced.UI.Telerik; -using System; namespace OwnChar.App.Desktop.Features.MainWindow.QuickAction { - internal class SettingsFeature() : PluginModule(FeatureCodes.QuickAction, "ownchar.settings", "Settings"), IPluginFeatureProvider + internal class SettingsFeature() : PluginFunction(FeatureCodes.QuickAction, "ownchar.settings", "Settings"), IPluginFeatureProvider { - public static TabMyUserFeature Instance { get; } = new(); + public static SettingsFeature Instance { get; } = new(); - protected override PluginModuleUI CreateNewUI() + protected override object? ExecuteFunction(PluginFunctionParameter? @params) { - throw new NotImplementedException(); - //return new TabSettings(); + if (@params is MainWindowParams p) + p.Api.OpenTab(new TabSettingsView()); + return null; } } } diff --git a/OwnChar.App.Desktop/OwnChar.App.Desktop.csproj b/OwnChar.App.Desktop/OwnChar.App.Desktop.csproj index 0c6523a..51ee656 100644 --- a/OwnChar.App.Desktop/OwnChar.App.Desktop.csproj +++ b/OwnChar.App.Desktop/OwnChar.App.Desktop.csproj @@ -26,6 +26,10 @@ + + + + diff --git a/OwnChar.App.Desktop/Program.cs b/OwnChar.App.Desktop/Program.cs index aea7e7d..e1d4ac7 100644 --- a/OwnChar.App.Desktop/Program.cs +++ b/OwnChar.App.Desktop/Program.cs @@ -1,6 +1,7 @@ using OwnChar.App.Desktop.Api; using OwnChar.App.Desktop.UI.Windows; using OwnChar.Plugins; +using Pilz.Configuration; using System; using System.IO; using System.Linq; @@ -12,16 +13,26 @@ namespace OwnChar.App.Desktop { internal static class Program { + public static ISettingsManager? SettingsManager { get; private set; } + public static string? AppTempFolder { get; private set; } + /// /// The main entry point for the application. /// [STAThread] static void Main() { + // Load settings + AppTempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OwnChar", "Desktop"); + SettingsManager = new SettingsManager(Path.Combine(AppTempFolder, "Settings.json"), true); + AppApi.Instance.Settings = SettingsManager.Instance; + + // Prepair user interface Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); ThemeResolutionService.ApplicationThemeName = new Office2019LightTheme().ThemeName; + // Load plugins OwnCharPlugins.Instance.LoadOwnPlugins(); var pluginPath = Path.Combine(Path.GetDirectoryName(Pilz.IO.Extensions.GetExecutablePath())!, "Plugins"); if (Directory.Exists(pluginPath)) @@ -30,8 +41,9 @@ namespace OwnChar.App.Desktop OwnCharPlugins.Instance.LoadPlugins(plugins); } + // Start main window var mainWindow = new MainWindow(); - IOwnCharApi.Instance.MainWindow = mainWindow.Api; + AppApi.Instance.MainWindow = mainWindow.Api; Application.Run(mainWindow); } } diff --git a/OwnChar.App.Desktop/UI/MainTabs/TabCharView.cs b/OwnChar.App.Desktop/UI/MainTabs/TabCharView.cs index 59cbc0e..b0cf8dc 100644 --- a/OwnChar.App.Desktop/UI/MainTabs/TabCharView.cs +++ b/OwnChar.App.Desktop/UI/MainTabs/TabCharView.cs @@ -1,13 +1,25 @@ -using Pilz.Plugins.Advanced.UI.Telerik; +using OwnChar.App.Desktop.Api; +using OwnChar.Model; +using Pilz.UI.Telerik.Dialogs; +using System.Windows.Forms; namespace OwnChar.App.Desktop.UI.MainTabs { - public partial class TabCharView : PluginModuleUI + public partial class TabCharView : UserControl, ILoadContent { - public TabCharView() + private readonly IMainWindowApi mainApi; + private readonly Character character; + + public TabCharView(IMainWindowApi mainApi, Character character) { - ActionPanelVisible = false; + this.mainApi = mainApi; + this.character = character; InitializeComponent(); } + + public void LoadContent() + { + // ... + } } } diff --git a/OwnChar.App.Desktop/UI/MainTabs/TabGroupView.cs b/OwnChar.App.Desktop/UI/MainTabs/TabGroupView.cs index 25d77e9..3833e03 100644 --- a/OwnChar.App.Desktop/UI/MainTabs/TabGroupView.cs +++ b/OwnChar.App.Desktop/UI/MainTabs/TabGroupView.cs @@ -1,22 +1,25 @@ -using Pilz.Plugins.Advanced.UI.Telerik; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using OwnChar.App.Desktop.Api; +using OwnChar.Model; +using Pilz.UI.Telerik.Dialogs; using System.Windows.Forms; namespace OwnChar.App.Desktop.UI.MainTabs { - public partial class TabGroupView : PluginModuleUI + public partial class TabGroupView : UserControl, ILoadContent { - public TabGroupView() + private readonly IMainWindowApi mainApi; + private readonly Group group; + + public TabGroupView(IMainWindowApi mainApi, Group group) { - ActionPanelVisible = false; + this.mainApi = mainApi; + this.group = group; InitializeComponent(); } + + public void LoadContent() + { + // ... + } } } diff --git a/OwnChar.App.Desktop/UI/MainTabs/TabGroupsView.cs b/OwnChar.App.Desktop/UI/MainTabs/TabGroupsView.cs index cdec21c..ae1527b 100644 --- a/OwnChar.App.Desktop/UI/MainTabs/TabGroupsView.cs +++ b/OwnChar.App.Desktop/UI/MainTabs/TabGroupsView.cs @@ -1,22 +1,22 @@ -using Pilz.Plugins.Advanced.UI.Telerik; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using OwnChar.App.Desktop.Api; +using Pilz.UI.Telerik.Dialogs; using System.Windows.Forms; namespace OwnChar.App.Desktop.UI.MainTabs { - public partial class TabGroupsView : PluginModuleUI + public partial class TabGroupsView : UserControl, ILoadContent { - public TabGroupsView() + private readonly IMainWindowApi mainApi; + + public TabGroupsView(IMainWindowApi mainApi) { - ActionPanelVisible = false; + this.mainApi = mainApi; InitializeComponent(); } + + public void LoadContent() + { + // ... + } } } diff --git a/OwnChar.App.Desktop/UI/MainTabs/TabSettingsView.Designer.cs b/OwnChar.App.Desktop/UI/MainTabs/TabSettingsView.Designer.cs new file mode 100644 index 0000000..35f4476 --- /dev/null +++ b/OwnChar.App.Desktop/UI/MainTabs/TabSettingsView.Designer.cs @@ -0,0 +1,37 @@ +namespace OwnChar.App.Desktop.UI.MainTabs +{ + partial class TabSettingsView + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Komponenten-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + } + + #endregion + } +} diff --git a/OwnChar.App.Desktop/UI/MainTabs/TabSettingsView.cs b/OwnChar.App.Desktop/UI/MainTabs/TabSettingsView.cs new file mode 100644 index 0000000..342385f --- /dev/null +++ b/OwnChar.App.Desktop/UI/MainTabs/TabSettingsView.cs @@ -0,0 +1,18 @@ +using Pilz.UI.Telerik.Dialogs; +using System.Windows.Forms; + +namespace OwnChar.App.Desktop.UI.MainTabs +{ + public partial class TabSettingsView : UserControl, ILoadContent + { + public TabSettingsView() + { + InitializeComponent(); + } + + public void LoadContent() + { + // ... + } + } +} diff --git a/OwnChar.App.Desktop/UI/MainTabs/TabUserView.cs b/OwnChar.App.Desktop/UI/MainTabs/TabUserView.cs index ecdb2d0..d45af55 100644 --- a/OwnChar.App.Desktop/UI/MainTabs/TabUserView.cs +++ b/OwnChar.App.Desktop/UI/MainTabs/TabUserView.cs @@ -1,22 +1,35 @@ -using Pilz.Plugins.Advanced.UI.Telerik; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using OwnChar.App.Desktop.Api; +using OwnChar.Model; +using Pilz.UI.Telerik.Dialogs; using System.Windows.Forms; namespace OwnChar.App.Desktop.UI.MainTabs { - public partial class TabUserView : PluginModuleUI + public partial class TabUserView : UserControl, ILoadContent { - public TabUserView() + private readonly IMainWindowApi mainApi; + private readonly UserAccount? account; + private readonly UserProfile? profile; + + private TabUserView(IMainWindowApi mainApi, UserAccount? account, UserProfile? profile) { - ActionPanelVisible = false; + this.mainApi = mainApi; + this.account = account; + this.profile = profile; InitializeComponent(); } + + public TabUserView(IMainWindowApi mainApi, UserAccount? account) : this(mainApi, account, mainApi.Manager.Users.GetUserProfile(account)) + { + } + + public TabUserView(IMainWindowApi mainApi, UserProfile? profile) : this(mainApi, null, profile) + { + } + + public void LoadContent() + { + // ... + } } } diff --git a/OwnChar.App.Desktop/UI/Windows/MainWindow.Designer.cs b/OwnChar.App.Desktop/UI/Windows/MainWindow.Designer.cs index 51d7ff4..a1975d2 100644 --- a/OwnChar.App.Desktop/UI/Windows/MainWindow.Designer.cs +++ b/OwnChar.App.Desktop/UI/Windows/MainWindow.Designer.cs @@ -1,4 +1,6 @@ -namespace OwnChar.App.Desktop.UI.Windows +using Telerik.WinControls.UI; + +namespace OwnChar.App.Desktop.UI.Windows { partial class MainWindow { @@ -28,13 +30,28 @@ /// private void InitializeComponent() { + radTabbedFormControl1 = new Telerik.WinControls.UI.RadTabbedFormControl(); radMenu1 = new Telerik.WinControls.UI.RadMenu(); radMenuItem1 = new Telerik.WinControls.UI.RadMenuItem(); radMenuItem2 = new Telerik.WinControls.UI.RadMenuItem(); + ((System.ComponentModel.ISupportInitialize)(this.radTabbedFormControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)radMenu1).BeginInit(); ((System.ComponentModel.ISupportInitialize)this).BeginInit(); SuspendLayout(); // + // radTabbedFormControl1 + // + this.radTabbedFormControl1.Location = new System.Drawing.Point(0, 0); + this.radTabbedFormControl1.Name = "radTabbedFormControl1"; + this.radTabbedFormControl1.ShowNewTabButton = false; + this.radTabbedFormControl1.Size = new System.Drawing.Size(768, 583); + this.radTabbedFormControl1.TabIndex = 0; + this.radTabbedFormControl1.TabWidth = 200; + this.radTabbedFormControl1.Text = "MainForm"; + ((Telerik.WinControls.UI.RadTabbedFormControlElement)(radTabbedFormControl1.GetChildAt(0))).Text = "MainForm"; + ((Telerik.WinControls.UI.RadQuickAccessOverflowButton)(radTabbedFormControl1.GetChildAt(0).GetChildAt(3).GetChildAt(1))).Visibility = Telerik.WinControls.ElementVisibility.Collapsed; + ((Telerik.WinControls.UI.RadQuickAccessOverflowButton)(radTabbedFormControl1.GetChildAt(0).GetChildAt(4).GetChildAt(1))).Visibility = Telerik.WinControls.ElementVisibility.Collapsed; + // // radMenu1 // radMenu1.Items.AddRange(new Telerik.WinControls.RadItem[] { radMenuItem1, radMenuItem2 }); @@ -63,6 +80,7 @@ Name = "MainWindow"; Text = "RadForm1"; ((System.ComponentModel.ISupportInitialize)radMenu1).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.radTabbedFormControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)this).EndInit(); ResumeLayout(false); PerformLayout(); @@ -70,6 +88,7 @@ #endregion + private Telerik.WinControls.UI.RadTabbedFormControl radTabbedFormControl1; private Telerik.WinControls.UI.RadMenu radMenu1; private Telerik.WinControls.UI.RadMenuItem radMenuItem1; private Telerik.WinControls.UI.RadMenuItem radMenuItem2; diff --git a/OwnChar.App.Desktop/UI/Windows/MainWindow.cs b/OwnChar.App.Desktop/UI/Windows/MainWindow.cs index 5cca06b..b90fa02 100644 --- a/OwnChar.App.Desktop/UI/Windows/MainWindow.cs +++ b/OwnChar.App.Desktop/UI/Windows/MainWindow.cs @@ -1,7 +1,10 @@ using OwnChar.App.Desktop.Api; +using OwnChar.App.Desktop.Api.Parameters; +using OwnChar.Manager; using Pilz.Plugins.Advanced; using Pilz.Plugins.Advanced.UI.Telerik; using System; +using System.Linq; using System.Windows.Forms; using Telerik.WinControls.UI; @@ -9,34 +12,81 @@ namespace OwnChar.App.Desktop.UI.Windows { public partial class MainWindow : RadTabbedForm { + private readonly OwnCharManager? manager = new(); + public MainWindowApi Api { get; } public MainWindow() { Api = new(this); InitializeComponent(); - PluginFeatureController.Instance.Features.Get(FeatureCodes.MainTab).InsertItemsTo(radMenuItem2.Items, customClickHandler: MainTabItem_Clicked); + PluginFeatureController.Instance.Features.Get(FeatureCodes.QuickAction).InsertItemsTo(radTabbedFormControl1.RightItems, customClickHandler: RightItem_Clicked); } public class MainWindowApi(MainWindow mainWindow) : IMainWindowApi { public MainWindow MainWindow { get; } = mainWindow; - public void CloseTab(Control content) + public OwnCharManager? Manager => MainWindow.manager; + + public void OpenTab(Control content, string title) { - throw new NotImplementedException(); + MainWindow.OpenTab(content, title); } - public void OpenTab(Control content) + public void CloseTab(Control content) { - throw new NotImplementedException(); + MainWindow.CloseTab(content); + } + + public bool IsTabOpen(Control content) + { + return MainWindow.FindTab(content) != null; + } + + public bool IsTabOpen() + { + return MainWindow.FindTab() != null; } } - private void MainTabItem_Clicked(object? sender, EventArgs e) + private MainWindowParams GetMainWindowParams() { - //if (sender is RadMenuItem item && item.Tag is PluginModule module) - //...Add() ... module.CreateUI(), "Titel", null); + return new MainWindowParams(Api); + } + + private void OpenTab(Control content, string title) + { + var newTab = new RadTabbedFormControlTab(); + content.Dock = DockStyle.Fill; + newTab.Controls.Add(content); + newTab.Text = title; + newTab.Tag = content; + content.Tag = newTab; + radTabbedFormControl1.Tabs.Add(newTab); + radTabbedFormControl1.SelectedTab = newTab; + } + + private void CloseTab(Control content) + { + if (FindTab(content) is RadTabbedFormControlTab tab) + radTabbedFormControl1.Tabs.Remove(tab); + } + + private RadTabbedFormControlTab? FindTab(Control content) + { + return radTabbedFormControl1.Tabs.FirstOrDefault(n => n.Tag == content); + } + + private RadTabbedFormControlTab? FindTab() + { + return radTabbedFormControl1.Tabs.FirstOrDefault(n => n.Tag is T); + } + + private void RightItem_Clicked(object? sender, EventArgs e) + { + if (sender is RadMenuItem item && item.Tag is PluginFunction function) + function.Execute(GetMainWindowParams()); } } } diff --git a/OwnChar.Plugins b/OwnChar.Plugins index 3855c09..5192dc3 160000 --- a/OwnChar.Plugins +++ b/OwnChar.Plugins @@ -1 +1 @@ -Subproject commit 3855c09d37f0825c19c699602d9a1631484cc666 +Subproject commit 5192dc38b25a2a9732f23a899c11455e8495c635