code cleanup

This commit is contained in:
2024-06-11 06:59:17 +02:00
parent 07cacbfbda
commit ac3cfc270c
21 changed files with 317 additions and 414 deletions

View File

@@ -1,15 +1,14 @@
using OwnChar.Manager; using OwnChar.Manager;
using System.Windows.Forms; using System.Windows.Forms;
namespace OwnChar.App.Desktop.Api namespace OwnChar.App.Desktop.Api;
public interface IMainWindowApi
{ {
public interface IMainWindowApi Form Window { get; }
{ OwnCharManager? Manager { get; }
Form Window { get; } void OpenTab(Control content, string title);
OwnCharManager? Manager { get; } void CloseTab(Control content);
void OpenTab(Control content, string title); bool IsTabOpen(Control content);
void CloseTab(Control content); bool IsTabOpen<T>();
bool IsTabOpen(Control content);
bool IsTabOpen<T>();
}
} }

View File

@@ -1,8 +1,7 @@
namespace OwnChar.App.Desktop.Api namespace OwnChar.App.Desktop.Api;
public interface IMainWindowTab
{ {
public interface IMainWindowTab string Name { get; }
{ IMainWindowApi MaindWindow { get; internal set; }
string Name { get; }
IMainWindowApi MaindWindow { get; internal set; }
}
} }

View File

@@ -1,15 +1,9 @@
using Pilz.Configuration; using Pilz.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OwnChar.App.Desktop.Api namespace OwnChar.App.Desktop.Api;
public interface IOwnCharApi
{ {
public interface IOwnCharApi public abstract IMainWindowApi? MainWindow { get; }
{ public abstract ISettings? Settings { get; }
public abstract IMainWindowApi? MainWindow { get; }
public abstract ISettings? Settings { get; }
}
} }

View File

@@ -1,14 +1,8 @@
using OwnChar.Plugins; 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 namespace OwnChar.App.Desktop.Api.Parameters;
public class AppInitParams(IOwnCharApi api) : OwnCharPluginInitParams
{ {
public class AppInitParams(IOwnCharApi api) : OwnCharPluginInitParams public IOwnCharApi Api { get; set; } = api;
{
public IOwnCharApi Api { get; set; } = api;
}
} }

View File

@@ -1,14 +1,8 @@
using Pilz.Plugins.Advanced; 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 namespace OwnChar.App.Desktop.Api.Parameters;
public class MainWindowParams(IMainWindowApi api) : PluginFunctionParameter
{ {
public class MainWindowParams(IMainWindowApi api) : PluginFunctionParameter public IMainWindowApi Api { get; } = api;
{
public IMainWindowApi Api { get; } = api;
}
} }

View File

@@ -1,26 +1,23 @@
using OwnChar.App.Desktop.Api; using OwnChar.Plugins;
using OwnChar.Plugins;
using Pilz.Configuration;
using Pilz.Plugins.Advanced; using Pilz.Plugins.Advanced;
namespace OwnChar.App.Desktop namespace OwnChar.App.Desktop;
public class AppPlugin : IOwnCharPlugin
{ {
public class AppPlugin : IOwnCharPlugin public static AppPlugin? Instance { get; private set; }
public string ID => "OwnChar.App.Desktop";
public string Name => "OwnChar Desktop App";
public AppPlugin()
{ {
public static AppPlugin? Instance { get; private set; } Instance = this;
PluginFeatureController.Instance.RegisterAllOwn();
}
public string ID => "OwnChar.App.Desktop"; public object? GetApi()
public string Name => "OwnChar Desktop App"; {
return AppApi.Instance;
public AppPlugin()
{
Instance = this;
PluginFeatureController.Instance.RegisterAllOwn();
}
public object? GetApi()
{
return AppApi.Instance;
}
} }
} }

View File

@@ -1,9 +1,8 @@
namespace OwnChar.App.Desktop namespace OwnChar.App.Desktop;
public static class FeatureCodes
{ {
public static class FeatureCodes public const string MainTab = "ownchar.app.desktop.main.tab";
{ public const string QuickAction = "ownchar.app.desktop.main.quickaction";
public const string MainTab = "ownchar.app.desktop.main.tab"; public const string LoginProvider = "ownchar.app.desktop.main.login.provider";
public const string QuickAction = "ownchar.app.desktop.main.quickaction";
public const string LoginProvider = "ownchar.app.desktop.main.login.provider";
}
} }

View File

@@ -2,17 +2,16 @@
using OwnChar.App.Desktop.UI.MainTabs; using OwnChar.App.Desktop.UI.MainTabs;
using Pilz.Plugins.Advanced; using Pilz.Plugins.Advanced;
namespace OwnChar.App.Desktop.Features.MainWindow.QuickAction namespace OwnChar.App.Desktop.Features.MainWindow.QuickAction;
{
internal class HomeFeature() : PluginFunction(FeatureCodes.QuickAction, "ownchar.home", "Home"), IPluginFeatureProvider<HomeFeature>
{
public static HomeFeature Instance { get; } = new();
protected override object? ExecuteFunction(PluginFunctionParameter? @params) internal class HomeFeature() : PluginFunction(FeatureCodes.QuickAction, "ownchar.home", "Home"), IPluginFeatureProvider<HomeFeature>
{ {
if (@params is MainWindowParams p) public static HomeFeature Instance { get; } = new();
p.Api.OpenTab(new TabUserView(p.Api, p.Api.Manager?.CurrentUser), p.Api.Manager!.CurrentUser!.Username!);
return null; protected override object? ExecuteFunction(PluginFunctionParameter? @params)
} {
if (@params is MainWindowParams p)
p.Api.OpenTab(new TabUserView(p.Api, p.Api.Manager?.CurrentUser), p.Api.Manager!.CurrentUser!.Username!);
return null;
} }
} }

View File

@@ -3,17 +3,16 @@ using OwnChar.App.Desktop.LangRes;
using OwnChar.App.Desktop.UI.MainTabs; using OwnChar.App.Desktop.UI.MainTabs;
using Pilz.Plugins.Advanced; using Pilz.Plugins.Advanced;
namespace OwnChar.App.Desktop.Features.MainWindow.QuickAction namespace OwnChar.App.Desktop.Features.MainWindow.QuickAction;
{
internal class SettingsFeature() : PluginFunction(FeatureCodes.QuickAction, "ownchar.settings", "Settings"), IPluginFeatureProvider<SettingsFeature>
{
public static SettingsFeature Instance { get; } = new();
protected override object? ExecuteFunction(PluginFunctionParameter? @params) internal class SettingsFeature() : PluginFunction(FeatureCodes.QuickAction, "ownchar.settings", "Settings"), IPluginFeatureProvider<SettingsFeature>
{ {
if (@params is MainWindowParams p) public static SettingsFeature Instance { get; } = new();
p.Api.OpenTab(new TabSettingsView(), SettingsPageLangRes.Title);
return null; protected override object? ExecuteFunction(PluginFunctionParameter? @params)
} {
if (@params is MainWindowParams p)
p.Api.OpenTab(new TabSettingsView(), SettingsPageLangRes.Title);
return null;
} }
} }

View File

@@ -16,8 +16,8 @@
<PackageReference Include="Pilz.IO" Version="2.0.0" /> <PackageReference Include="Pilz.IO" Version="2.0.0" />
<PackageReference Include="Pilz.Plugins" Version="2.1.9" /> <PackageReference Include="Pilz.Plugins" Version="2.1.9" />
<PackageReference Include="Pilz.Plugins.Advanced" Version="2.7.3" /> <PackageReference Include="Pilz.Plugins.Advanced" Version="2.7.3" />
<PackageReference Include="Pilz.Plugins.Advanced.UI" Version="1.5.0" /> <PackageReference Include="Pilz.Plugins.Advanced.UI" Version="1.5.1" />
<PackageReference Include="Pilz.Plugins.Advanced.UI.Telerik" Version="1.4.0" /> <PackageReference Include="Pilz.Plugins.Advanced.UI.Telerik" Version="1.4.1" />
<PackageReference Include="UI.for.WinForms.AllControls.Net70" Version="2024.1.312" /> <PackageReference Include="UI.for.WinForms.AllControls.Net70" Version="2024.1.312" />
</ItemGroup> </ItemGroup>

View File

@@ -1,5 +1,4 @@
using OwnChar.App.Desktop.Api; using OwnChar.App.Desktop.UI.Windows;
using OwnChar.App.Desktop.UI.Windows;
using OwnChar.Plugins; using OwnChar.Plugins;
using Pilz.Configuration; using Pilz.Configuration;
using System; using System;
@@ -9,42 +8,41 @@ using System.Windows.Forms;
using Telerik.WinControls; using Telerik.WinControls;
using Telerik.WinControls.Themes; using Telerik.WinControls.Themes;
namespace OwnChar.App.Desktop namespace OwnChar.App.Desktop;
internal static class Program
{ {
internal static class Program public static ISettingsManager? SettingsManager { get; private set; }
public static string? AppTempFolder { get; private set; }
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{ {
public static ISettingsManager? SettingsManager { get; private set; } // Load settings
public static string? AppTempFolder { get; private set; } AppTempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OwnChar", "Desktop");
SettingsManager = new SettingsManager(Path.Combine(AppTempFolder, "Settings.json"), true);
AppApi.Instance.Settings = SettingsManager.Instance;
/// <summary> // Prepair user interface
/// The main entry point for the application. Application.EnableVisualStyles();
/// </summary> Application.SetCompatibleTextRenderingDefault(false);
[STAThread] ThemeResolutionService.ApplicationThemeName = new Office2019LightTheme().ThemeName;
static void Main()
// Load plugins
OwnCharPlugins.Instance.LoadOwnPlugins();
var pluginPath = Path.Combine(Path.GetDirectoryName(Pilz.IO.Extensions.GetExecutablePath())!, "Plugins");
if (Directory.Exists(pluginPath))
{ {
// Load settings var plugins = Directory.GetDirectories(pluginPath, "*", SearchOption.TopDirectoryOnly).Select(n => Path.Combine(n, n + ".dll")).ToArray();
AppTempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OwnChar", "Desktop"); OwnCharPlugins.Instance.LoadPlugins(plugins);
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))
{
var plugins = Directory.GetDirectories(pluginPath, "*", SearchOption.TopDirectoryOnly).Select(n => Path.Combine(n, n + ".dll")).ToArray();
OwnCharPlugins.Instance.LoadPlugins(plugins);
}
// Start main window
var mainWindow = new MainWindow();
AppApi.Instance.MainWindow = mainWindow.Api;
Application.Run(mainWindow);
} }
// Start main window
var mainWindow = new MainWindow();
AppApi.Instance.MainWindow = mainWindow;
Application.Run(mainWindow);
} }
} }

View File

@@ -1,96 +1,87 @@
using OwnChar.App.Desktop.Api; using OwnChar.App.Desktop.Api;
using OwnChar.App.Desktop.LangRes; using OwnChar.App.Desktop.LangRes;
using OwnChar.App.Desktop.UI.Windows;
using OwnChar.Model; using OwnChar.Model;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Telerik.WinControls.UI; using Telerik.WinControls.UI;
namespace OwnChar.App.Desktop.UI.MainTabs.Controls namespace OwnChar.App.Desktop.UI.MainTabs.Controls;
public partial class CharacterListControl : UserControl
{ {
public partial class CharacterListControl : UserControl
private IMainWindowApi? mainApi;
private UserProfile? profile;
private Group? group;
public CharacterListControl()
{ {
InitializeComponent();
}
private IMainWindowApi? mainApi; public void LoadContent(IMainWindowApi mainApi, UserProfile? profile)
private UserProfile? profile; {
private Group? group; LoadContent(mainApi, profile, null);
}
public CharacterListControl() public void LoadContent(IMainWindowApi mainApi, Group? group)
{
LoadContent(mainApi, null, group);
}
private void LoadContent(IMainWindowApi mainApi, UserProfile? profile, Group? group)
{
this.mainApi = mainApi;
this.profile = profile;
this.group = group;
PrepareList();
LoadList();
}
// Laden aller -eigenen- Charaktere
// Spalte zum Anzeigen der Gruppen-Zugehörigkeit
// Hinzufügen und Löschen von Charakteren
private void PrepareList()
{
radListView_CharList.BeginUpdate();
radListView_CharList.Columns.Clear();
radListView_CharList.Columns.Add(CharListControlLangRes.Column_CharName);
if (profile != null)
radListView_CharList.Columns.Add(CharListControlLangRes.Column_CharGroup);
else if (group != null)
radListView_CharList.Columns.Add(CharListControlLangRes.Column_CharOwner);
radListView_CharList.EndUpdate();
}
private void LoadList()
{
radListView_CharList.BeginUpdate();
radListView_CharList.Items.Clear();
if (profile != null && mainApi?.Manager?.Characters.GetCharacters(profile) is IEnumerable<Character> characters)
{ {
InitializeComponent(); foreach (Character character in characters)
}
public void LoadContent(IMainWindowApi mainApi, UserProfile? profile)
{
LoadContent(mainApi, profile, null);
}
public void LoadContent(IMainWindowApi mainApi, Group? group)
{
LoadContent(mainApi, null, group);
}
private void LoadContent(IMainWindowApi mainApi, UserProfile? profile, Group? group)
{
this.mainApi = mainApi;
this.profile = profile;
this.group = group;
PrepareList();
LoadList();
}
// Laden aller -eigenen- Charaktere
// Spalte zum Anzeigen der Gruppen-Zugehörigkeit
// Hinzufügen und Löschen von Charakteren
private void PrepareList()
{
radListView_CharList.BeginUpdate();
radListView_CharList.Columns.Clear();
radListView_CharList.Columns.Add(CharListControlLangRes.Column_CharName);
if (profile != null)
radListView_CharList.Columns.Add(CharListControlLangRes.Column_CharGroup);
else if (group != null)
radListView_CharList.Columns.Add(CharListControlLangRes.Column_CharOwner);
radListView_CharList.EndUpdate();
}
private void LoadList()
{
radListView_CharList.BeginUpdate();
radListView_CharList.Items.Clear();
if (profile != null && mainApi?.Manager?.Characters.GetCharacters(profile) is IEnumerable<Character> characters)
{ {
foreach (Character character in characters) AddCharToList(character);
{
AddCharToList(character);
}
} }
radListView_CharList.EndUpdate();
} }
private void AddCharToList(Character character) radListView_CharList.EndUpdate();
{ }
var newItem = new ListViewDataItem();
UpdateCharListViewItem(newItem, character);
newItem.Value = character;
}
private void UpdateCharListViewItem(ListViewDataItem listItem, Character character) private void AddCharToList(Character character)
{ {
listItem[0] = character.Name; var newItem = new ListViewDataItem();
UpdateCharListViewItem(newItem, character);
newItem.Value = character;
}
private void UpdateCharListViewItem(ListViewDataItem listItem, Character character)
{
listItem[0] = character.Name;
}
} }
} }

View File

@@ -1,26 +1,15 @@
using System; using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls.UI.Diagrams.Primitives;
namespace OwnChar.App.Desktop.UI.MainTabs.Controls namespace OwnChar.App.Desktop.UI.MainTabs.Controls;
public partial class GroupListControl : UserControl
{ {
public partial class GroupListControl : UserControl public GroupListControl()
{ {
public GroupListControl() InitializeComponent();
{
InitializeComponent();
}
// Auflistung der Gruppen
// Hinzufügen
// Löschen + Umbenennen (Wenn Admin/Mod)
} }
// Auflistung der Gruppen
// Hinzufügen
// Löschen + Umbenennen (Wenn Admin/Mod)
} }

View File

@@ -1,23 +1,14 @@
using System; using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OwnChar.App.Desktop.UI.MainTabs.Controls namespace OwnChar.App.Desktop.UI.MainTabs.Controls;
public partial class MemberListControl : UserControl
{ {
public partial class MemberListControl : UserControl public MemberListControl()
{ {
public MemberListControl() InitializeComponent();
{
InitializeComponent();
}
// Auflisten von Nutzern
// -> z.B. Freunden oder Mitgliedern einer Gruppe
} }
// Auflisten von Nutzern
// -> z.B. Freunden oder Mitgliedern einer Gruppe
} }

View File

@@ -1,26 +1,24 @@
using OwnChar.App.Desktop.Api; using OwnChar.App.Desktop.Api;
using OwnChar.App.Desktop.UI.MainTabs.Controls;
using OwnChar.Model; using OwnChar.Model;
using Pilz.UI.Telerik.Dialogs; using Pilz.UI;
using System.Windows.Forms; using System.Windows.Forms;
namespace OwnChar.App.Desktop.UI.MainTabs namespace OwnChar.App.Desktop.UI.MainTabs;
public partial class TabCharView : UserControl, ILoadContent
{ {
public partial class TabCharView : UserControl, ILoadContent private readonly IMainWindowApi mainApi;
private readonly Character character;
public TabCharView(IMainWindowApi mainApi, Character character)
{ {
private readonly IMainWindowApi mainApi; this.mainApi = mainApi;
private readonly Character character; this.character = character;
InitializeComponent();
}
public TabCharView(IMainWindowApi mainApi, Character character) public void LoadContent()
{ {
this.mainApi = mainApi;
this.character = character;
InitializeComponent();
}
public void LoadContent()
{
}
} }
} }

View File

@@ -1,25 +1,24 @@
using OwnChar.App.Desktop.Api; using OwnChar.App.Desktop.Api;
using OwnChar.Model; using OwnChar.Model;
using Pilz.UI.Telerik.Dialogs; using Pilz.UI;
using System.Windows.Forms; using System.Windows.Forms;
namespace OwnChar.App.Desktop.UI.MainTabs namespace OwnChar.App.Desktop.UI.MainTabs;
public partial class TabGroupView : UserControl, ILoadContent
{ {
public partial class TabGroupView : UserControl, ILoadContent private readonly IMainWindowApi mainApi;
private readonly Group group;
public TabGroupView(IMainWindowApi mainApi, Group group)
{ {
private readonly IMainWindowApi mainApi; this.mainApi = mainApi;
private readonly Group group; this.group = group;
InitializeComponent();
}
public TabGroupView(IMainWindowApi mainApi, Group group) public void LoadContent()
{ {
this.mainApi = mainApi; // ...
this.group = group;
InitializeComponent();
}
public void LoadContent()
{
// ...
}
} }
} }

View File

@@ -3,7 +3,7 @@ using OwnChar.App.Desktop.LangRes;
using OwnChar.Data; using OwnChar.Data;
using Pilz.Cryptography; using Pilz.Cryptography;
using Pilz.Plugins.Advanced; using Pilz.Plugins.Advanced;
using Pilz.UI.Telerik.Dialogs; using Pilz.UI;
using System; using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;

View File

@@ -1,18 +1,17 @@
using Pilz.UI.Telerik.Dialogs; using Pilz.UI;
using System.Windows.Forms; using System.Windows.Forms;
namespace OwnChar.App.Desktop.UI.MainTabs namespace OwnChar.App.Desktop.UI.MainTabs;
{
public partial class TabSettingsView : UserControl, ILoadContent
{
public TabSettingsView()
{
InitializeComponent();
}
public void LoadContent() public partial class TabSettingsView : UserControl, ILoadContent
{ {
// ... public TabSettingsView()
} {
InitializeComponent();
}
public void LoadContent()
{
// ...
} }
} }

View File

@@ -1,35 +1,34 @@
using OwnChar.App.Desktop.Api; using OwnChar.App.Desktop.Api;
using OwnChar.Model; using OwnChar.Model;
using Pilz.UI.Telerik.Dialogs; using Pilz.UI;
using System.Windows.Forms; using System.Windows.Forms;
namespace OwnChar.App.Desktop.UI.MainTabs namespace OwnChar.App.Desktop.UI.MainTabs;
public partial class TabUserView : UserControl, ILoadContent
{ {
public partial class TabUserView : UserControl, ILoadContent private readonly IMainWindowApi mainApi;
private readonly UserAccount? account;
private readonly UserProfile? profile;
private TabUserView(IMainWindowApi mainApi, UserAccount? account, UserProfile? profile)
{ {
private readonly IMainWindowApi mainApi; this.mainApi = mainApi;
private readonly UserAccount? account; this.account = account;
private readonly UserProfile? profile; this.profile = profile;
InitializeComponent();
}
private TabUserView(IMainWindowApi mainApi, UserAccount? account, UserProfile? profile) public TabUserView(IMainWindowApi mainApi, UserAccount? account) : this(mainApi, account, mainApi.Manager!.Users.GetOwnUserProfile())
{ {
this.mainApi = mainApi; }
this.account = account;
this.profile = profile;
InitializeComponent();
}
public TabUserView(IMainWindowApi mainApi, UserAccount? account) : this(mainApi, account, mainApi.Manager!.Users.GetOwnUserProfile()) public TabUserView(IMainWindowApi mainApi, UserProfile? profile) : this(mainApi, null, profile)
{ {
} }
public TabUserView(IMainWindowApi mainApi, UserProfile? profile) : this(mainApi, null, profile) public void LoadContent()
{ {
} characterListControl1.LoadContent(mainApi, profile);
public void LoadContent()
{
characterListControl1.LoadContent(mainApi, profile);
}
} }
} }

View File

@@ -30,33 +30,23 @@ namespace OwnChar.App.Desktop.UI.Windows
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
radTabbedFormControl1 = new RadTabbedFormControl();
radTabbedFormControl2 = new RadTabbedFormControl(); radTabbedFormControl2 = new RadTabbedFormControl();
((System.ComponentModel.ISupportInitialize)radTabbedFormControl1).BeginInit();
((System.ComponentModel.ISupportInitialize)radTabbedFormControl2).BeginInit(); ((System.ComponentModel.ISupportInitialize)radTabbedFormControl2).BeginInit();
((System.ComponentModel.ISupportInitialize)this).BeginInit(); ((System.ComponentModel.ISupportInitialize)this).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// radTabbedFormControl1
//
radTabbedFormControl1.Location = new System.Drawing.Point(0, 0);
radTabbedFormControl1.Name = "radTabbedFormControl1";
radTabbedFormControl1.ShowNewTabButton = false;
radTabbedFormControl1.Size = new System.Drawing.Size(768, 583);
radTabbedFormControl1.TabIndex = 0;
radTabbedFormControl1.TabWidth = 200;
radTabbedFormControl1.Text = "MainForm";
((RadTabbedFormControlElement)radTabbedFormControl1.GetChildAt(0)).Text = "MainForm";
((RadQuickAccessOverflowButton)radTabbedFormControl1.GetChildAt(0).GetChildAt(3).GetChildAt(1)).Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
((RadQuickAccessOverflowButton)radTabbedFormControl1.GetChildAt(0).GetChildAt(4).GetChildAt(1)).Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
//
// radTabbedFormControl2 // radTabbedFormControl2
// //
radTabbedFormControl2.Location = new System.Drawing.Point(0, 0); radTabbedFormControl2.Location = new System.Drawing.Point(0, 0);
radTabbedFormControl2.Name = "radTabbedFormControl2"; radTabbedFormControl2.Name = "radTabbedFormControl1";
radTabbedFormControl2.Size = new System.Drawing.Size(780, 589); radTabbedFormControl2.ShowNewTabButton = false;
radTabbedFormControl2.TabIndex = 1; radTabbedFormControl2.Size = new System.Drawing.Size(768, 583);
radTabbedFormControl2.Text = "RadForm1"; radTabbedFormControl2.TabIndex = 0;
radTabbedFormControl2.TabWidth = 200;
radTabbedFormControl2.Text = "MainForm";
((RadTabbedFormControlElement)radTabbedFormControl2.GetChildAt(0)).Text = "MainForm";
((RadQuickAccessOverflowButton)radTabbedFormControl2.GetChildAt(0).GetChildAt(3).GetChildAt(1)).Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
((RadQuickAccessOverflowButton)radTabbedFormControl2.GetChildAt(0).GetChildAt(4).GetChildAt(1)).Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
// //
// MainWindow // MainWindow
// //
@@ -68,7 +58,6 @@ namespace OwnChar.App.Desktop.UI.Windows
ShowIcon = false; ShowIcon = false;
Text = "RadForm1"; Text = "RadForm1";
Load += MainWindow_Load; Load += MainWindow_Load;
((System.ComponentModel.ISupportInitialize)radTabbedFormControl1).EndInit();
((System.ComponentModel.ISupportInitialize)radTabbedFormControl2).EndInit(); ((System.ComponentModel.ISupportInitialize)radTabbedFormControl2).EndInit();
((System.ComponentModel.ISupportInitialize)this).EndInit(); ((System.ComponentModel.ISupportInitialize)this).EndInit();
ResumeLayout(false); ResumeLayout(false);

View File

@@ -2,9 +2,6 @@
using OwnChar.App.Desktop.Api.Parameters; using OwnChar.App.Desktop.Api.Parameters;
using OwnChar.App.Desktop.LangRes; using OwnChar.App.Desktop.LangRes;
using OwnChar.App.Desktop.UI.MainTabs; using OwnChar.App.Desktop.UI.MainTabs;
using OwnChar.Data;
using OwnChar.Data.Managers;
using OwnChar.Data.Providers.JsonFile;
using OwnChar.Manager; using OwnChar.Manager;
using Pilz.Plugins.Advanced; using Pilz.Plugins.Advanced;
using Pilz.Plugins.Advanced.UI.Telerik; using Pilz.Plugins.Advanced.UI.Telerik;
@@ -13,91 +10,70 @@ using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using Telerik.WinControls.UI; using Telerik.WinControls.UI;
namespace OwnChar.App.Desktop.UI.Windows namespace OwnChar.App.Desktop.UI.Windows;
public partial class MainWindow : RadTabbedForm, IMainWindowApi
{ {
public partial class MainWindow : RadTabbedForm Form IMainWindowApi.Window => this;
public OwnCharManager Manager { get; } = new();
public MainWindow()
{ {
private readonly OwnCharManager manager = new(); InitializeComponent();
PluginFeatureController.Instance.Features.Get(FeatureCodes.QuickAction).InsertItemsTo(radTabbedFormControl1.RightItems, customClickHandler: RightItem_Clicked);
}
public MainWindowApi Api { get; } private MainWindowParams GetMainWindowParams()
{
return new MainWindowParams(this);
}
public MainWindow() public void OpenTab(Control content, string title)
{ {
Api = new(this); var newTab = new RadTabbedFormControlTab();
InitializeComponent(); content.Dock = DockStyle.Fill;
PluginFeatureController.Instance.Features.Get(FeatureCodes.QuickAction).InsertItemsTo(radTabbedFormControl1.RightItems, customClickHandler: RightItem_Clicked); newTab.Controls.Add(content);
} newTab.Text = title;
newTab.Tag = content;
content.Tag = newTab;
radTabbedFormControl1.Tabs.Add(newTab);
radTabbedFormControl1.SelectedTab = newTab;
}
public class MainWindowApi(MainWindow mainWindow) : IMainWindowApi public void CloseTab(Control content)
{ {
public MainWindow MainWindow { get; } = mainWindow; if (FindTab(content) is RadTabbedFormControlTab tab)
radTabbedFormControl1.Tabs.Remove(tab);
}
public Form Window => MainWindow; public bool IsTabOpen(Control content)
public OwnCharManager Manager => MainWindow.manager; {
return FindTab(content) != null;
}
public void OpenTab(Control content, string title) public bool IsTabOpen<T>()
{ {
MainWindow.OpenTab(content, title); return FindTab<T>() != null;
} }
public void CloseTab(Control content) private RadTabbedFormControlTab? FindTab(Control content)
{ {
MainWindow.CloseTab(content); return radTabbedFormControl1.Tabs.FirstOrDefault(n => n.Tag == content);
} }
public bool IsTabOpen(Control content) private RadTabbedFormControlTab? FindTab<T>()
{ {
return MainWindow.FindTab(content) != null; return radTabbedFormControl1.Tabs.FirstOrDefault(n => n.Tag is T);
} }
public bool IsTabOpen<T>() private void RightItem_Clicked(object? sender, EventArgs e)
{ {
return MainWindow.FindTab<T>() != null; if (sender is RadMenuItem item && item.Tag is PluginFunction function)
} function.Execute(GetMainWindowParams());
} }
private MainWindowParams GetMainWindowParams() private void MainWindow_Load(object sender, EventArgs e)
{ {
return new MainWindowParams(Api); OpenTab(new TabLoginView(this), LoginPageLangRes.Title);
}
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<T>()
{
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());
}
private void MainWindow_Load(object sender, EventArgs e)
{
Api.OpenTab(new TabLoginView(Api), LoginPageLangRes.Title);
}
} }
} }