using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Comal.Classes;
using InABox.Clients;
using InABox.Configuration;
using InABox.Core;
using InABox.DynamicGrid;
using InABox.Reports;
using InABox.Core.Reports;
using InABox.Scripting;
using InABox.Wpf.Reports;
using InABox.WPF;
using InABox.Wpf;
using PRSDesktop.Configuration;
using Fluent;
using Button = Fluent.Button;
using ContextMenu = System.Windows.Controls.ContextMenu;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using MenuItem = Fluent.MenuItem;
namespace PRSDesktop;
///
/// Interaction logic for SecondaryWindow.xaml
///
public partial class SecondaryWindow : RibbonWindow, IPanelHostControl
{
private readonly Guid _id = Guid.Empty;
private readonly string _modulesection = "";
private readonly string _type = "";
private bool bLoaded;
private List CurrentModules = new List();
public IBasePanel Panel { get; private set; }
private PanelHost PanelHost;
public SecondaryWindow(Guid id, string type, string modulesection, double left, double top, double width, double height)
{
PanelHost = new PanelHost(this);
_id = id;
_modulesection = modulesection;
InitializeComponent();
Left = left;
Top = top;
Width = width;
Height = height;
Title = string.Format("{0} - PRS Desktop (Release {1})", modulesection, CoreUtils.GetVersion());
SecondaryTab.Header = modulesection;
Panel = PanelHost.LoadPanel(Type.GetType(type), modulesection);
ContentBorder.Child = Panel as UIElement;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
PanelHost.Refresh();
bLoaded = true;
}
private void RefreshMenu_Click(object sender, RoutedEventArgs e)
{
PanelHost.Refresh();
}
private void Wiki_Click(object sender, RoutedEventArgs e)
{
Process.Start("https://prsdigital.com.au/wiki/index.php/" + _type.Replace(" ", "_").Replace("/", ""));
}
#region Save / Load Window Location
private void SaveSettings()
{
if (App.IsClosing)
return;
var tuple = new Tuple(
Panel.GetType().EntityName(),
_modulesection,
Left,
Top,
Width,
Height
);
App.DatabaseSettings.SecondaryWindows[_id] = tuple;
new LocalConfiguration(App.Profile).Save(App.DatabaseSettings);
}
private void Window_Closing(object sender, CancelEventArgs e)
{
PanelHost.UnloadPanel(e);
if (e.Cancel) return;
if (App.IsClosing)
return;
App.DatabaseSettings.SecondaryWindows.Remove(_id);
new LocalConfiguration(App.Profile).Save(App.DatabaseSettings);
}
private void Window_LocationChanged(object sender, EventArgs e)
{
if (bLoaded)
SaveSettings();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (bLoaded)
SaveSettings();
}
#endregion
public void CreatePanelAction(PanelAction action)
{
if (action.OnPopulate != null)
{
Fluent.DropDownButton button = null;
if (action.OnExecute != null)
{
button = new Fluent.SplitButton();
((Fluent.SplitButton)button).Click += (o, e) => action.Execute();
}
else
button = new Fluent.DropDownButton();
button.MinWidth = 60;
button.DataContext = action;
button.DropDownOpened += (sender, args) => { button.ItemsSource = CreateMenuItems(action); };
button.Bind(Fluent.DropDownButton.HeaderProperty, x => x.Caption, null);
button.Bind(Fluent.DropDownButton.LargeIconProperty, x => x.Image,
new BitmapToBitmapImageConverter());
button.Bind(ContextMenuProperty, x => x.Menu);
button.Bind(IsEnabledProperty, x => x.IsEnabled);
button.Bind(VisibilityProperty, x => x.Visibility);
Actions.Items.Add(button);
CurrentModules.Add(button);
}
else
{
var button = new Fluent.Button()
{
MinWidth = 60,
DataContext = action
};
button.Bind(Fluent.Button.HeaderProperty, x => x.Caption, null);
button.Bind(Fluent.Button.LargeIconProperty, x => x.Image,
new BitmapToBitmapImageConverter());
button.Bind(Fluent.Button.ContextMenuProperty, x => x.Menu);
button.Bind(Fluent.Button.IsEnabledProperty, x => x.IsEnabled);
button.Bind(Fluent.Button.VisibilityProperty, x => x.Visibility);
button.Click += (o, e) => action.Execute();
Actions.Items.Add(button);
CurrentModules.Add(button);
}
ActionsSeparator.Visibility = Visibility.Visible;
}
private static ObservableCollection