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 CreateMenuItems(PanelAction action) { var items = new ObservableCollection(); var entries = action.Populate(); if (entries != null) { foreach (var entry in entries) { var item = new Fluent.MenuItem() { Header = entry.Caption, DataContext = entry.Data, Icon = entry.Image?.AsBitmapImage() }; item.Click += (o, eventArgs) => entry.Execute(); items.Add(item); } } return items; } public void CreateReport(PanelAction action) { Print.Visibility = Visibility.Visible; var button = new Button { Header = action.Caption, LargeIcon = action.Image.AsBitmapImage() }; if (action.Menu is not null) { button.ContextMenu = action.Menu; } button.Click += (o, e) => action.Execute(); Print.Items.Add(button); } private void Setup_Click(object sender, RoutedEventArgs e) { var menu = new ContextMenu(); PanelHost.InitialiseSetupMenu(menu); menu.IsOpen = true; } public void ClearActions() { foreach (var module in CurrentModules) { if (module.Parent is Fluent.RibbonGroupBox bar) bar.Items.Remove(module); } CurrentModules.Clear(); ActionsSeparator.Visibility = Visibility.Collapsed; } public void ClearReports() { Print.Items.Clear(); Print.Visibility = Visibility.Visible; } public void Heartbeat() { PanelHost.Heartbeat(); } }