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,96 +1,87 @@
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;
private Group? group;
public CharacterListControl()
{
InitializeComponent();
}
private IMainWindowApi? mainApi;
private UserProfile? profile;
private Group? group;
public void LoadContent(IMainWindowApi mainApi, UserProfile? profile)
{
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();
}
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)
{
foreach (Character character in characters)
{
AddCharToList(character);
}
AddCharToList(character);
}
radListView_CharList.EndUpdate();
}
private void AddCharToList(Character character)
{
var newItem = new ListViewDataItem();
UpdateCharListViewItem(newItem, character);
newItem.Value = character;
}
radListView_CharList.EndUpdate();
}
private void UpdateCharListViewItem(ListViewDataItem listItem, Character character)
{
listItem[0] = character.Name;
private void AddCharToList(Character character)
{
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.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()
{
public GroupListControl()
{
InitializeComponent();
}
// Auflistung der Gruppen
// Hinzufügen
// Löschen + Umbenennen (Wenn Admin/Mod)
InitializeComponent();
}
// Auflistung der Gruppen
// Hinzufügen
// Löschen + Umbenennen (Wenn Admin/Mod)
}

View File

@@ -1,23 +1,14 @@
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()
{
public MemberListControl()
{
InitializeComponent();
}
// Auflisten von Nutzern
// -> z.B. Freunden oder Mitgliedern einer Gruppe
InitializeComponent();
}
// 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.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;
public TabCharView(IMainWindowApi mainApi, Character character)
{
private readonly IMainWindowApi mainApi;
private readonly Character character;
this.mainApi = mainApi;
this.character = character;
InitializeComponent();
}
public TabCharView(IMainWindowApi mainApi, Character character)
{
this.mainApi = mainApi;
this.character = character;
InitializeComponent();
}
public void LoadContent()
{
public void LoadContent()
{
}
}
}

View File

@@ -1,25 +1,24 @@
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;
public TabGroupView(IMainWindowApi mainApi, Group group)
{
private readonly IMainWindowApi mainApi;
private readonly Group group;
this.mainApi = mainApi;
this.group = group;
InitializeComponent();
}
public TabGroupView(IMainWindowApi mainApi, Group group)
{
this.mainApi = mainApi;
this.group = group;
InitializeComponent();
}
public void LoadContent()
{
// ...
}
public void LoadContent()
{
// ...
}
}

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,18 +1,17 @@
using Pilz.UI.Telerik.Dialogs;
using Pilz.UI;
using System.Windows.Forms;
namespace OwnChar.App.Desktop.UI.MainTabs
{
public partial class TabSettingsView : UserControl, ILoadContent
{
public TabSettingsView()
{
InitializeComponent();
}
namespace OwnChar.App.Desktop.UI.MainTabs;
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.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;
private TabUserView(IMainWindowApi mainApi, UserAccount? account, UserProfile? profile)
{
private readonly IMainWindowApi mainApi;
private readonly UserAccount? account;
private readonly UserProfile? profile;
this.mainApi = mainApi;
this.account = account;
this.profile = profile;
InitializeComponent();
}
private TabUserView(IMainWindowApi mainApi, UserAccount? account, UserProfile? profile)
{
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, 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>
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,91 +10,70 @@ using System.Linq;
using System.Windows.Forms;
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()
{
Api = new(this);
InitializeComponent();
PluginFeatureController.Instance.Features.Get(FeatureCodes.QuickAction).InsertItemsTo(radTabbedFormControl1.RightItems, customClickHandler: RightItem_Clicked);
}
public 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;
}
public class MainWindowApi(MainWindow mainWindow) : IMainWindowApi
{
public MainWindow MainWindow { get; } = mainWindow;
public void CloseTab(Control content)
{
if (FindTab(content) is RadTabbedFormControlTab tab)
radTabbedFormControl1.Tabs.Remove(tab);
}
public Form Window => MainWindow;
public OwnCharManager Manager => MainWindow.manager;
public bool IsTabOpen(Control content)
{
return FindTab(content) != null;
}
public void OpenTab(Control content, string title)
{
MainWindow.OpenTab(content, title);
}
public bool IsTabOpen<T>()
{
return FindTab<T>() != null;
}
public void CloseTab(Control content)
{
MainWindow.CloseTab(content);
}
private RadTabbedFormControlTab? FindTab(Control content)
{
return radTabbedFormControl1.Tabs.FirstOrDefault(n => n.Tag == content);
}
public bool IsTabOpen(Control content)
{
return MainWindow.FindTab(content) != null;
}
private RadTabbedFormControlTab? FindTab<T>()
{
return radTabbedFormControl1.Tabs.FirstOrDefault(n => n.Tag is T);
}
public bool IsTabOpen<T>()
{
return MainWindow.FindTab<T>() != null;
}
}
private void RightItem_Clicked(object? sender, EventArgs e)
{
if (sender is RadMenuItem item && item.Tag is PluginFunction function)
function.Execute(GetMainWindowParams());
}
private MainWindowParams GetMainWindowParams()
{
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<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);
}
private void MainWindow_Load(object sender, EventArgs e)
{
OpenTab(new TabLoginView(this), LoginPageLangRes.Title);
}
}