94 lines
2.8 KiB
C#
94 lines
2.8 KiB
C#
using OwnChar.App.Desktop.Api;
|
|
using OwnChar.App.Desktop.Api.Parameters;
|
|
using OwnChar.Data;
|
|
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;
|
|
|
|
namespace OwnChar.App.Desktop.UI.Windows
|
|
{
|
|
public partial class MainWindow : RadTabbedForm
|
|
{
|
|
private readonly OwnCharManager? manager = new(new JsonFileDataProvider());
|
|
|
|
public MainWindowApi Api { get; }
|
|
|
|
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 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);
|
|
}
|
|
|
|
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());
|
|
}
|
|
}
|
|
}
|