finally more structure
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using OwnChar.App.Desktop.Api;
|
||||
using OwnChar.App.Desktop.Api.Parameters;
|
||||
using OwnChar.Manager;
|
||||
using Pilz.Plugins.Advanced;
|
||||
using Pilz.Plugins.Advanced.UI.Telerik;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Telerik.WinControls.UI;
|
||||
|
||||
@@ -9,34 +12,81 @@ namespace OwnChar.App.Desktop.UI.Windows
|
||||
{
|
||||
public partial class MainWindow : RadTabbedForm
|
||||
{
|
||||
private readonly OwnCharManager? manager = new();
|
||||
|
||||
public MainWindowApi Api { get; }
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
Api = new(this);
|
||||
InitializeComponent();
|
||||
PluginFeatureController.Instance.Features.Get(FeatureCodes.MainTab).InsertItemsTo(radMenuItem2.Items, customClickHandler: MainTabItem_Clicked);
|
||||
PluginFeatureController.Instance.Features.Get(FeatureCodes.QuickAction).InsertItemsTo(radTabbedFormControl1.RightItems, customClickHandler: RightItem_Clicked);
|
||||
}
|
||||
|
||||
public class MainWindowApi(MainWindow mainWindow) : IMainWindowApi
|
||||
{
|
||||
public MainWindow MainWindow { get; } = mainWindow;
|
||||
|
||||
public void CloseTab(Control content)
|
||||
public OwnCharManager? Manager => MainWindow.manager;
|
||||
|
||||
public void OpenTab(Control content, string title)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
MainWindow.OpenTab(content, title);
|
||||
}
|
||||
|
||||
public void OpenTab(Control content)
|
||||
public void CloseTab(Control content)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
MainWindow.CloseTab(content);
|
||||
}
|
||||
|
||||
public bool IsTabOpen(Control content)
|
||||
{
|
||||
return MainWindow.FindTab(content) != null;
|
||||
}
|
||||
|
||||
public bool IsTabOpen<T>()
|
||||
{
|
||||
return MainWindow.FindTab<T>() != null;
|
||||
}
|
||||
}
|
||||
|
||||
private void MainTabItem_Clicked(object? sender, EventArgs e)
|
||||
private MainWindowParams GetMainWindowParams()
|
||||
{
|
||||
//if (sender is RadMenuItem item && item.Tag is PluginModule module)
|
||||
//...Add() ... module.CreateUI(), "Titel", null);
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user