code cleanup
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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