123 lines
3.1 KiB
C#
123 lines
3.1 KiB
C#
using OwnChar.Api;
|
|
using OwnChar.App.Desktop.Api;
|
|
using OwnChar.App.Desktop.Api.Parameters;
|
|
using OwnChar.App.Desktop.LangRes;
|
|
using OwnChar.App.Desktop.Settings;
|
|
using OwnChar.App.Desktop.UI.MainTabs;
|
|
using OwnChar.Manager;
|
|
using Pilz.Plugins.Advanced;
|
|
using Pilz.Plugins.Advanced.UI.Telerik;
|
|
using Pilz.UI;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using Telerik.WinControls.UI;
|
|
using Telerik.Windows.Diagrams.Core;
|
|
|
|
namespace OwnChar.App.Desktop.UI.Windows;
|
|
|
|
public partial class MainWindow : RadTabbedForm, IMainWindowApi
|
|
{
|
|
private readonly MainWindowSettings settings = AppApi.Instance.Settings.Get<MainWindowSettings>();
|
|
|
|
Form IMainWindowApi.Window => this;
|
|
public IOwnCharManager Manager { get; } = new OwnCharManager();
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
if (!settings.AllowAero)
|
|
AllowAero = false;
|
|
|
|
PluginFeatureController.Instance.Features.Get(FeatureCodes.QuickAction)
|
|
.InsertItemsTo(radTabbedFormControl2.RightItems, customClickHandler: RightItem_Clicked)
|
|
.ForEach(item => item.DisplayStyle = Telerik.WinControls.DisplayStyle.Image);
|
|
}
|
|
|
|
protected virtual MainWindowParams GetMainWindowParams()
|
|
{
|
|
return new MainWindowParams(this);
|
|
}
|
|
|
|
public void OpenTab(Control content, string title)
|
|
{
|
|
content.BackColor = System.Drawing.Color.Transparent;
|
|
content.Dock = DockStyle.Fill;
|
|
|
|
var newTab = new RadTabbedFormControlTab
|
|
{
|
|
Text = title,
|
|
Tag = content
|
|
};
|
|
|
|
content.Tag = newTab;
|
|
newTab.Controls.Add(content);
|
|
|
|
radTabbedFormControl2.Tabs.Add(newTab);
|
|
radTabbedFormControl2.SelectedTab = newTab;
|
|
|
|
if (content is ILoadContent loadContent)
|
|
loadContent.LoadContent();
|
|
}
|
|
|
|
public void CloseTab(Control content)
|
|
{
|
|
if (FindTab(content) is RadTabbedFormControlTab tab)
|
|
radTabbedFormControl2.Tabs.Remove(tab);
|
|
}
|
|
|
|
public bool IsTabOpen(Control content)
|
|
{
|
|
return FindTab(content) != null;
|
|
}
|
|
|
|
public bool IsTabOpen<T>()
|
|
{
|
|
return FindTab<T>() != null;
|
|
}
|
|
|
|
public void Logout()
|
|
{
|
|
Logout(true);
|
|
}
|
|
|
|
private void Logout(bool openLogin)
|
|
{
|
|
Manager.Logout();
|
|
if (openLogin)
|
|
Login();
|
|
}
|
|
|
|
private void Login()
|
|
{
|
|
OpenTab(new TabLoginView(this), LoginPageLangRes.Title);
|
|
}
|
|
|
|
private RadTabbedFormControlTab? FindTab(Control content)
|
|
{
|
|
return radTabbedFormControl2.Tabs.FirstOrDefault(n => n.Tag == content);
|
|
}
|
|
|
|
private RadTabbedFormControlTab? FindTab<T>()
|
|
{
|
|
return radTabbedFormControl2.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)
|
|
{
|
|
Login();
|
|
}
|
|
|
|
private void MainWindow_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
Logout(false);
|
|
}
|
|
}
|