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 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; }
void OpenTab(Control content, string title);
void CloseTab(Control content);
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; }
}
}

View File

@@ -1,15 +1,9 @@
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; }
}
}

View File

@@ -1,14 +1,8 @@
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;
}
}

View File

@@ -1,14 +1,8 @@
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;
}
}

View File

@@ -1,12 +1,10 @@
using OwnChar.App.Desktop.Api;
using OwnChar.Plugins;
using Pilz.Configuration;
using OwnChar.Plugins;
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";
@@ -22,5 +20,4 @@ namespace OwnChar.App.Desktop
{
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 LoginProvider = "ownchar.app.desktop.main.login.provider";
}
}

View File

@@ -2,10 +2,10 @@
using OwnChar.App.Desktop.UI.MainTabs;
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>
{
internal class HomeFeature() : PluginFunction(FeatureCodes.QuickAction, "ownchar.home", "Home"), IPluginFeatureProvider<HomeFeature>
{
public static HomeFeature Instance { get; } = new();
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
@@ -14,5 +14,4 @@ namespace OwnChar.App.Desktop.Features.MainWindow.QuickAction
p.Api.OpenTab(new TabUserView(p.Api, p.Api.Manager?.CurrentUser), p.Api.Manager!.CurrentUser!.Username!);
return null;
}
}
}

View File

@@ -3,10 +3,10 @@ using OwnChar.App.Desktop.LangRes;
using OwnChar.App.Desktop.UI.MainTabs;
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>
{
internal class SettingsFeature() : PluginFunction(FeatureCodes.QuickAction, "ownchar.settings", "Settings"), IPluginFeatureProvider<SettingsFeature>
{
public static SettingsFeature Instance { get; } = new();
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
@@ -15,5 +15,4 @@ namespace OwnChar.App.Desktop.Features.MainWindow.QuickAction
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.Plugins" Version="2.1.9" />
<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.Telerik" Version="1.4.0" />
<PackageReference Include="Pilz.Plugins.Advanced.UI" Version="1.5.1" />
<PackageReference Include="Pilz.Plugins.Advanced.UI.Telerik" Version="1.4.1" />
<PackageReference Include="UI.for.WinForms.AllControls.Net70" Version="2024.1.312" />
</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 Pilz.Configuration;
using System;
@@ -9,10 +8,10 @@ using System.Windows.Forms;
using Telerik.WinControls;
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; }
@@ -43,8 +42,7 @@ namespace OwnChar.App.Desktop
// Start main window
var mainWindow = new MainWindow();
AppApi.Instance.MainWindow = mainWindow.Api;
AppApi.Instance.MainWindow = mainWindow;
Application.Run(mainWindow);
}
}
}

View File

@@ -1,22 +1,14 @@
using OwnChar.App.Desktop.Api;
using OwnChar.App.Desktop.LangRes;
using OwnChar.App.Desktop.UI.Windows;
using OwnChar.Model;
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 System.Windows.Forms;
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;
@@ -92,5 +84,4 @@ namespace OwnChar.App.Desktop.UI.MainTabs.Controls
listItem[0] = character.Name;
}
}
}

View File

@@ -1,19 +1,9 @@
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 System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls.UI.Diagrams.Primitives;
using System.Windows.Forms;
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()
{
InitializeComponent();
@@ -22,5 +12,4 @@ namespace OwnChar.App.Desktop.UI.MainTabs.Controls
// Auflistung der Gruppen
// Hinzufügen
// Löschen + Umbenennen (Wenn Admin/Mod)
}
}

View File

@@ -1,17 +1,9 @@
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 System.Windows.Forms;
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()
{
InitializeComponent();
@@ -19,5 +11,4 @@ namespace OwnChar.App.Desktop.UI.MainTabs.Controls
// Auflisten von Nutzern
// -> z.B. Freunden oder Mitgliedern einer Gruppe
}
}

View File

@@ -1,13 +1,12 @@
using OwnChar.App.Desktop.Api;
using OwnChar.App.Desktop.UI.MainTabs.Controls;
using OwnChar.Model;
using Pilz.UI.Telerik.Dialogs;
using Pilz.UI;
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;
@@ -22,5 +21,4 @@ namespace OwnChar.App.Desktop.UI.MainTabs
{
}
}
}

View File

@@ -1,12 +1,12 @@
using OwnChar.App.Desktop.Api;
using OwnChar.Model;
using Pilz.UI.Telerik.Dialogs;
using Pilz.UI;
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;
@@ -21,5 +21,4 @@ namespace OwnChar.App.Desktop.UI.MainTabs
{
// ...
}
}
}

View File

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

View File

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

View File

@@ -1,12 +1,12 @@
using OwnChar.App.Desktop.Api;
using OwnChar.Model;
using Pilz.UI.Telerik.Dialogs;
using Pilz.UI;
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;
@@ -31,5 +31,4 @@ namespace OwnChar.App.Desktop.UI.MainTabs
{
characterListControl1.LoadContent(mainApi, profile);
}
}
}

View File

@@ -30,33 +30,23 @@ namespace OwnChar.App.Desktop.UI.Windows
/// </summary>
private void InitializeComponent()
{
radTabbedFormControl1 = new RadTabbedFormControl();
radTabbedFormControl2 = new RadTabbedFormControl();
((System.ComponentModel.ISupportInitialize)radTabbedFormControl1).BeginInit();
((System.ComponentModel.ISupportInitialize)radTabbedFormControl2).BeginInit();
((System.ComponentModel.ISupportInitialize)this).BeginInit();
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.Location = new System.Drawing.Point(0, 0);
radTabbedFormControl2.Name = "radTabbedFormControl2";
radTabbedFormControl2.Size = new System.Drawing.Size(780, 589);
radTabbedFormControl2.TabIndex = 1;
radTabbedFormControl2.Text = "RadForm1";
radTabbedFormControl2.Name = "radTabbedFormControl1";
radTabbedFormControl2.ShowNewTabButton = false;
radTabbedFormControl2.Size = new System.Drawing.Size(768, 583);
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
//
@@ -68,7 +58,6 @@ namespace OwnChar.App.Desktop.UI.Windows
ShowIcon = false;
Text = "RadForm1";
Load += MainWindow_Load;
((System.ComponentModel.ISupportInitialize)radTabbedFormControl1).EndInit();
((System.ComponentModel.ISupportInitialize)radTabbedFormControl2).EndInit();
((System.ComponentModel.ISupportInitialize)this).EndInit();
ResumeLayout(false);

View File

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