code cleanup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user