mirror of
				https://github.com/9ParsonsB/Pulsar.git
				synced 2025-11-03 15:26:43 -05:00 
			
		
		
		
	New UI framework changes
This commit is contained in:
		@@ -3,6 +3,7 @@ using Observatory.Framework.Files;
 | 
				
			|||||||
using Observatory.Framework.Interfaces;
 | 
					using Observatory.Framework.Interfaces;
 | 
				
			||||||
using Observatory.NativeNotification;
 | 
					using Observatory.NativeNotification;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.ObjectModel;
 | 
				
			||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Observatory.PluginManagement
 | 
					namespace Observatory.PluginManagement
 | 
				
			||||||
@@ -96,47 +97,39 @@ namespace Observatory.PluginManagement
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="worker"></param>
 | 
					        /// <param name="worker"></param>
 | 
				
			||||||
        /// <param name="item"></param>
 | 
					        /// <param name="item"></param>
 | 
				
			||||||
        public void AddGridItem(IObservatoryWorker worker, object item)
 | 
					        public void AddGridItem(IObservatoryWorker worker, List<object> item)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
 | 
					            Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                worker.PluginUI.DataGrid.Add(item);
 | 
					                ObservableCollection<object> newRow = new(item);
 | 
				
			||||||
 | 
					                worker.PluginUI.BasicGrid.Items.Add(newRow);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                //Hacky removal of original empty object if one was used to populate columns
 | 
					                //Hacky removal of original empty object if one was used to populate columns
 | 
				
			||||||
                if (worker.PluginUI.DataGrid.Count == 2)
 | 
					                if (worker.PluginUI.BasicGrid.Items.Count == 2)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    if (FirstRowIsAllNull(worker))
 | 
					                    bool allNull = true;
 | 
				
			||||||
                        worker.PluginUI.DataGrid.RemoveAt(0);
 | 
					                    
 | 
				
			||||||
 | 
					                    foreach (var cell in worker.PluginUI.BasicGrid.Items[0])
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        if (cell != null)
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
 | 
					                            allNull = false;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (allNull)
 | 
				
			||||||
 | 
					                        worker.PluginUI.BasicGrid.Items.RemoveAt(0);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        public void ClearGrid(IObservatoryWorker worker)
 | 
				
			||||||
        /// Adds multiple items to the datagrid on UI thread to ensure visual update.
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        /// <param name="worker"></param>
 | 
					 | 
				
			||||||
        /// <param name="items"></param>
 | 
					 | 
				
			||||||
        public void AddGridItems(IObservatoryWorker worker, IEnumerable<object> items)
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
 | 
					            Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var cleanEmptyRow = worker.PluginUI.DataGrid.Count == 1 && FirstRowIsAllNull(worker) && items.Count() > 0;
 | 
					                worker.PluginUI.BasicGrid.Items.Clear();
 | 
				
			||||||
                foreach (var item in items)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    worker.PluginUI.DataGrid.Add(item);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                if (cleanEmptyRow)
 | 
					 | 
				
			||||||
                    worker.PluginUI.DataGrid.RemoveAt(0);
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        public void ClearGrid(IObservatoryWorker worker, object templateItem)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                worker.PluginUI.DataGrid.Add(templateItem);
 | 
					 | 
				
			||||||
                while (worker.PluginUI.DataGrid.Count > 1)
 | 
					 | 
				
			||||||
                    worker.PluginUI.DataGrid.RemoveAt(0);
 | 
					 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,11 +61,11 @@ namespace Observatory.UI.ViewModels
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public BasicUIViewModel(BasicGrid basicGrid)
 | 
				
			||||||
        public BasicUIViewModel(ObservableCollection<string> headers, ObservableCollection<string> formats)
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Headers = headers;
 | 
					            Headers = basicGrid.Headers;
 | 
				
			||||||
            Formats = formats;
 | 
					            Formats = basicGrid.Formats;
 | 
				
			||||||
 | 
					            Items = basicGrid.Items;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private PluginUI.UIType _uiType;
 | 
					        private PluginUI.UIType _uiType;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ namespace Observatory.UI.ViewModels
 | 
				
			|||||||
                {
 | 
					                {
 | 
				
			||||||
                    CoreModel coreModel = new();
 | 
					                    CoreModel coreModel = new();
 | 
				
			||||||
                    coreModel.Name = worker.ShortName;
 | 
					                    coreModel.Name = worker.ShortName;
 | 
				
			||||||
                    coreModel.UI = new BasicUIViewModel(worker.PluginUI.DataGrid)
 | 
					                    coreModel.UI = new BasicUIViewModel(worker.PluginUI.BasicGrid)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        UIType = worker.PluginUI.PluginUIType
 | 
					                        UIType = worker.PluginUI.PluginUIType
 | 
				
			||||||
                    };
 | 
					                    };
 | 
				
			||||||
@@ -55,7 +55,7 @@ namespace Observatory.UI.ViewModels
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            tabs.Add(new CoreModel() { Name = "Core", UI = new BasicUIViewModel(new ObservableCollection<object>()) { UIType = Framework.PluginUI.UIType.Core } });
 | 
					            tabs.Add(new CoreModel() { Name = "Core", UI = new BasicUIViewModel(new Framework.BasicGrid()) { UIType = Framework.PluginUI.UIType.Core } });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (Properties.Core.Default.StartMonitor)
 | 
					            if (Properties.Core.Default.StartMonitor)
 | 
				
			||||||
                ToggleMonitor();
 | 
					                ToggleMonitor();
 | 
				
			||||||
@@ -112,67 +112,95 @@ namespace Observatory.UI.ViewModels
 | 
				
			|||||||
            try
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var exportFolder = Properties.Core.Default.ExportFolder;
 | 
					                var exportFolder = Properties.Core.Default.ExportFolder;
 | 
				
			||||||
                if (string.IsNullOrEmpty(exportFolder) || !Directory.Exists(exportFolder))
 | 
					
 | 
				
			||||||
 | 
					                if (string.IsNullOrEmpty(exportFolder))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    exportFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
 | 
					                    exportFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
 | 
				
			||||||
 | 
					 | 
				
			||||||
                    OpenFolderDialog openFolderDialog = new()
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        Directory = exportFolder
 | 
					 | 
				
			||||||
                    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    var application = (IClassicDesktopStyleApplicationLifetime)Avalonia.Application.Current.ApplicationLifetime;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    var selectedFolder = await openFolderDialog.ShowAsync(application.MainWindow);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (!string.IsNullOrEmpty(selectedFolder))
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        Properties.Core.Default.ExportFolder = selectedFolder;
 | 
					 | 
				
			||||||
                        Properties.Core.Default.Save();
 | 
					 | 
				
			||||||
                        exportFolder = selectedFolder;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var exportStyle = Properties.Core.Default.ExportStyle;
 | 
					                OpenFolderDialog openFolderDialog = new()
 | 
				
			||||||
                if (string.IsNullOrEmpty(exportStyle))
 | 
					 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    exportStyle = "Fixed width";
 | 
					                    Directory = exportFolder
 | 
				
			||||||
                    Properties.Core.Default.ExportStyle = exportStyle;
 | 
					                };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                var application = (IClassicDesktopStyleApplicationLifetime)Avalonia.Application.Current.ApplicationLifetime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                var selectedFolder = await openFolderDialog.ShowAsync(application.MainWindow);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (!string.IsNullOrEmpty(selectedFolder))
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    Properties.Core.Default.ExportFolder = selectedFolder;
 | 
				
			||||||
                    Properties.Core.Default.Save();
 | 
					                    Properties.Core.Default.Save();
 | 
				
			||||||
                }
 | 
					                    exportFolder = selectedFolder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                foreach (var tab in tabs.Where(t => t.Name != "Core"))
 | 
					                    foreach (var tab in tabs.Where(t => t.Name != "Core"))
 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    var ui = (BasicUIViewModel)tab.UI;
 | 
					 | 
				
			||||||
                    List<object> selectedData;
 | 
					 | 
				
			||||||
                    bool specificallySelected = ui.SelectedItems?.Count > 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (specificallySelected)
 | 
					 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        selectedData = new();
 | 
					                        var ui = (BasicUIViewModel)tab.UI;
 | 
				
			||||||
 | 
					                        List<object> selectedData;
 | 
				
			||||||
 | 
					                        bool specificallySelected = ui.SelectedItems?.Count > 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        foreach (var item in ui.SelectedItems)
 | 
					                        if (specificallySelected)
 | 
				
			||||||
                            selectedData.Add(item);
 | 
					                        {
 | 
				
			||||||
 | 
					                            selectedData = new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            foreach (var item in ui.SelectedItems)
 | 
				
			||||||
 | 
					                                selectedData.Add(item);
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        else
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
 | 
					                            selectedData = new(); // TODO: Make this work in new UI
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        var columns = selectedData[0].GetType().GetProperties();
 | 
				
			||||||
 | 
					                        Dictionary<string, int> colSize = new();
 | 
				
			||||||
 | 
					                        Dictionary<string, List<string>> colContent = new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        foreach (var column in columns)
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
 | 
					                            colSize.Add(column.Name, 0);
 | 
				
			||||||
 | 
					                            colContent.Add(column.Name, new());
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        foreach (var line in selectedData)
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
 | 
					                            var lineType = line.GetType(); // some plugins have different line types, so don't move this out of loop
 | 
				
			||||||
 | 
					                            foreach (var column in colContent)
 | 
				
			||||||
 | 
					                            {
 | 
				
			||||||
 | 
					                                var cellValue = lineType.GetProperty(column.Key)?.GetValue(line)?.ToString() ?? string.Empty;
 | 
				
			||||||
 | 
					                                column.Value.Add(cellValue);
 | 
				
			||||||
 | 
					                                if (colSize[column.Key] < cellValue.Length)
 | 
				
			||||||
 | 
					                                    colSize[column.Key] = cellValue.Length;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        System.Text.StringBuilder exportData = new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        foreach (var colTitle in colContent.Keys)
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
 | 
					                            if (colSize[colTitle] < colTitle.Length)
 | 
				
			||||||
 | 
					                                colSize[colTitle] = colTitle.Length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            exportData.Append(colTitle.PadRight(colSize[colTitle]) + "  ");
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        exportData.AppendLine();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        for (int i = 0; i < colContent.First().Value.Count; i++)
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
 | 
					                            foreach (var column in colContent)
 | 
				
			||||||
 | 
					                            {
 | 
				
			||||||
 | 
					                                if (column.Value[i].Length > 0 && !char.IsNumber(column.Value[i][0]) && column.Value[i].Count(char.IsLetter) / (float)column.Value[i].Length > 0.25)
 | 
				
			||||||
 | 
					                                    exportData.Append(column.Value[i].PadRight(colSize[column.Key]) + "  ");
 | 
				
			||||||
 | 
					                                else
 | 
				
			||||||
 | 
					                                    exportData.Append(column.Value[i].PadLeft(colSize[column.Key]) + "  ");
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            exportData.AppendLine();
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        string exportPath = $"{exportFolder}{System.IO.Path.DirectorySeparatorChar}Observatory Export - {DateTime.UtcNow:yyyyMMdd-HHmmss} - {tab.Name}.txt";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        System.IO.File.WriteAllText(exportPath, exportData.ToString());
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        selectedData = ui.BasicUIGrid.ToList();
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    System.Text.StringBuilder exportData;
 | 
					 | 
				
			||||||
                    switch (exportStyle)
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        case "Tab separated":
 | 
					 | 
				
			||||||
                            exportData = ExportTabSeparated(selectedData);
 | 
					 | 
				
			||||||
                            break;
 | 
					 | 
				
			||||||
                        default: // Fixed width.
 | 
					 | 
				
			||||||
                            exportData = ExportFixedWidth(selectedData);
 | 
					 | 
				
			||||||
                            break;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    string exportPath = $"{exportFolder}{System.IO.Path.DirectorySeparatorChar}Observatory Export - {DateTime.UtcNow:yyyyMMdd-HHmmss} - {tab.Name}.txt";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    System.IO.File.WriteAllText(exportPath, exportData.ToString());
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            catch (Exception e)
 | 
					            catch (Exception e)
 | 
				
			||||||
@@ -182,78 +210,6 @@ namespace Observatory.UI.ViewModels
 | 
				
			|||||||
                    new List<(string, string)> { ("An error occurred while exporting; output may be missing or incomplete." + Environment.NewLine +
 | 
					                    new List<(string, string)> { ("An error occurred while exporting; output may be missing or incomplete." + Environment.NewLine +
 | 
				
			||||||
                    "Please check the error log (found in your Documents folder) for more details and visit our discord to report it.", e.Message) });
 | 
					                    "Please check the error log (found in your Documents folder) for more details and visit our discord to report it.", e.Message) });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					 | 
				
			||||||
            static System.Text.StringBuilder ExportTabSeparated(List<object> selectedData)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                System.Text.StringBuilder exportData = new();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                var columnNames = selectedData[0].GetType().GetProperties().Select(c => c.Name).ToList();
 | 
					 | 
				
			||||||
                exportData.AppendJoin('\t', columnNames).AppendLine();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                var lastColumn = columnNames.Last();
 | 
					 | 
				
			||||||
                foreach (var line in selectedData)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    var lineType = line.GetType(); // some plugins have different line types, so don't move this out of loop
 | 
					 | 
				
			||||||
                    foreach (var columnName in columnNames)
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        var cellValue = lineType.GetProperty(columnName)?.GetValue(line)?.ToString() ?? string.Empty;
 | 
					 | 
				
			||||||
                        exportData.Append(cellValue).Append('\t');
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    exportData.AppendLine();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                return exportData;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            static System.Text.StringBuilder ExportFixedWidth(List<object> selectedData)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                Dictionary<string, int> colSize = new();
 | 
					 | 
				
			||||||
                Dictionary<string, List<string>> colContent = new();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                var columns = selectedData[0].GetType().GetProperties();
 | 
					 | 
				
			||||||
                foreach (var column in columns)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    colSize.Add(column.Name, column.Name.Length);
 | 
					 | 
				
			||||||
                    colContent.Add(column.Name, new());
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                foreach (var line in selectedData)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    var lineType = line.GetType(); // some plugins have different line types, so don't move this out of loop
 | 
					 | 
				
			||||||
                    foreach (var column in colContent)
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        var cellValue = lineType.GetProperty(column.Key)?.GetValue(line)?.ToString() ?? string.Empty;
 | 
					 | 
				
			||||||
                        column.Value.Add(cellValue);
 | 
					 | 
				
			||||||
                        if (colSize[column.Key] < cellValue.Length)
 | 
					 | 
				
			||||||
                            colSize[column.Key] = cellValue.Length;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                System.Text.StringBuilder exportData = new();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                foreach (var colTitle in colContent.Keys)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    if (colSize[colTitle] < colTitle.Length)
 | 
					 | 
				
			||||||
                        colSize[colTitle] = colTitle.Length;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    exportData.Append(colTitle.PadRight(colSize[colTitle]) + "  ");
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                exportData.AppendLine();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                for (int i = 0; i < colContent.First().Value.Count; i++)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    foreach (var column in colContent)
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        if (column.Value[i].Length > 0 && !char.IsNumber(column.Value[i][0]) && column.Value[i].Count(char.IsLetter) / (float)column.Value[i].Length > 0.25)
 | 
					 | 
				
			||||||
                            exportData.Append(column.Value[i].PadRight(colSize[column.Key]) + "  ");
 | 
					 | 
				
			||||||
                        else
 | 
					 | 
				
			||||||
                            exportData.Append(column.Value[i].PadLeft(colSize[column.Key]) + "  ");
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    exportData.AppendLine();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return exportData;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void ClearGrid()
 | 
					        public void ClearGrid()
 | 
				
			||||||
@@ -262,15 +218,7 @@ namespace Observatory.UI.ViewModels
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                var ui = (BasicUIViewModel)tab.UI;
 | 
					                var ui = (BasicUIViewModel)tab.UI;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var rowTemplate = ui.BasicUIGrid.First();
 | 
					                ui.Items.Clear();
 | 
				
			||||||
 | 
					 | 
				
			||||||
                foreach (var property in rowTemplate.GetType().GetProperties())
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    property.SetValue(rowTemplate, null);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                ui.BasicUIGrid.Clear();
 | 
					 | 
				
			||||||
                ui.BasicUIGrid.Add(rowTemplate);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // For some reason UIType's change event will properly
 | 
					                // For some reason UIType's change event will properly
 | 
				
			||||||
                // redraw the grid, not BasicUIGrid's.
 | 
					                // redraw the grid, not BasicUIGrid's.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										23
									
								
								ObservatoryFramework/BasicGrid.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								ObservatoryFramework/BasicGrid.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Collections.ObjectModel;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Text;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Observatory.Framework
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public class BasicGrid
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public BasicGrid()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Headers = new();
 | 
				
			||||||
 | 
					            Formats = new();
 | 
				
			||||||
 | 
					            Items = new();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public readonly ObservableCollection<string> Headers;
 | 
				
			||||||
 | 
					        public readonly ObservableCollection<string> Formats;
 | 
				
			||||||
 | 
					        public readonly ObservableCollection<ObservableCollection<object>> Items;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -154,7 +154,7 @@ namespace Observatory.Framework.Interfaces
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="worker">Reference to the calling plugin's worker interface.</param>
 | 
					        /// <param name="worker">Reference to the calling plugin's worker interface.</param>
 | 
				
			||||||
        /// <param name="item">Grid item to be added. Object type should match original template item used to create the grid.</param>
 | 
					        /// <param name="item">Grid item to be added. Object type should match original template item used to create the grid.</param>
 | 
				
			||||||
        public void AddGridItem(IObservatoryWorker worker, object item);
 | 
					        public void AddGridItem(IObservatoryWorker worker, List<object> item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Add multiple items to the bottom of the basic UI grid.
 | 
					        /// Add multiple items to the bottom of the basic UI grid.
 | 
				
			||||||
@@ -167,8 +167,7 @@ namespace Observatory.Framework.Interfaces
 | 
				
			|||||||
        /// Clears basic UI grid, removing all items.
 | 
					        /// Clears basic UI grid, removing all items.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="worker">Reference to the calling plugin's worker interface.</param>
 | 
					        /// <param name="worker">Reference to the calling plugin's worker interface.</param>
 | 
				
			||||||
        /// <param name="templateItem">Template item used to re-initialise the grid.</param>
 | 
					        public void ClearGrid(IObservatoryWorker worker);
 | 
				
			||||||
        public void ClearGrid(IObservatoryWorker worker, object templateItem);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Requests current Elite Dangerous status.json content.
 | 
					        /// Requests current Elite Dangerous status.json content.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1439,26 +1439,18 @@
 | 
				
			|||||||
            <param name="notificationId">Guid of notification to be updated.</param>
 | 
					            <param name="notificationId">Guid of notification to be updated.</param>
 | 
				
			||||||
            <param name="notificationEventArgs">NotificationArgs object specifying updated notification content and behaviour.</param>
 | 
					            <param name="notificationEventArgs">NotificationArgs object specifying updated notification content and behaviour.</param>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:Observatory.Framework.Interfaces.IObservatoryCore.AddGridItem(Observatory.Framework.Interfaces.IObservatoryWorker,System.Object)">
 | 
					        <member name="M:Observatory.Framework.Interfaces.IObservatoryCore.AddGridItem(Observatory.Framework.Interfaces.IObservatoryWorker,System.Collections.Generic.List{System.Object})">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            Add an item to the bottom of the basic UI grid.
 | 
					            Add an item to the bottom of the basic UI grid.
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
            <param name="worker">Reference to the calling plugin's worker interface.</param>
 | 
					            <param name="worker">Reference to the calling plugin's worker interface.</param>
 | 
				
			||||||
            <param name="item">Grid item to be added. Object type should match original template item used to create the grid.</param>
 | 
					            <param name="item">Grid item to be added. Object type should match original template item used to create the grid.</param>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:Observatory.Framework.Interfaces.IObservatoryCore.AddGridItems(Observatory.Framework.Interfaces.IObservatoryWorker,System.Collections.Generic.IEnumerable{System.Object})">
 | 
					        <member name="M:Observatory.Framework.Interfaces.IObservatoryCore.ClearGrid(Observatory.Framework.Interfaces.IObservatoryWorker)">
 | 
				
			||||||
            <summary>
 | 
					 | 
				
			||||||
            Add multiple items to the bottom of the basic UI grid.
 | 
					 | 
				
			||||||
            </summary>
 | 
					 | 
				
			||||||
            <param name="worker">Reference to the calling plugin's worker interface.</param>
 | 
					 | 
				
			||||||
            <param name="items">Grid items to be added. Object types should match original template item used to create the grid.</param>
 | 
					 | 
				
			||||||
        </member>
 | 
					 | 
				
			||||||
        <member name="M:Observatory.Framework.Interfaces.IObservatoryCore.ClearGrid(Observatory.Framework.Interfaces.IObservatoryWorker,System.Object)">
 | 
					 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            Clears basic UI grid, removing all items.
 | 
					            Clears basic UI grid, removing all items.
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
            <param name="worker">Reference to the calling plugin's worker interface.</param>
 | 
					            <param name="worker">Reference to the calling plugin's worker interface.</param>
 | 
				
			||||||
            <param name="templateItem">Template item used to re-initialise the grid.</param>
 | 
					 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:Observatory.Framework.Interfaces.IObservatoryCore.GetStatus">
 | 
					        <member name="M:Observatory.Framework.Interfaces.IObservatoryCore.GetStatus">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
@@ -1520,13 +1512,12 @@
 | 
				
			|||||||
            <para>(Untested/not implemented)</para>
 | 
					            <para>(Untested/not implemented)</para>
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="F:Observatory.Framework.PluginUI.DataGrid">
 | 
					        <member name="F:Observatory.Framework.PluginUI.BasicGrid">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            <para>Collection bound to DataGrid used byu plugins with UIType.Basic.</para>
 | 
					            <para>>Two-dimensional collection of items to display in UI grid for UIType.Basic</para>
 | 
				
			||||||
            <para>Objects in collection should be of a class defined within the plugin consisting of string properties.<br/>Each object is a single row, and the property names are used as column headers.</para>
 | 
					 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
        <member name="M:Observatory.Framework.PluginUI.#ctor(System.Collections.ObjectModel.ObservableCollection{System.Object})">
 | 
					        <member name="M:Observatory.Framework.PluginUI.#ctor(Observatory.Framework.BasicGrid)">
 | 
				
			||||||
            <summary>
 | 
					            <summary>
 | 
				
			||||||
            Instantiate PluginUI of UIType.Basic.
 | 
					            Instantiate PluginUI of UIType.Basic.
 | 
				
			||||||
            </summary>
 | 
					            </summary>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,25 +23,9 @@ namespace Observatory.Framework
 | 
				
			|||||||
        public object UI;
 | 
					        public object UI;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// <para>Collection bound to DataGrid used by plugins with UIType.Basic.</para>
 | 
					        /// <para>>Two-dimensional collection of items to display in UI grid for UIType.Basic</para>
 | 
				
			||||||
        /// <para>Objects in collection should be of a class defined within the plugin consisting of string properties.<br/>Each object is a single row, and the property names are used as column headers.</para>
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public ObservableCollection<object> DataGrid;
 | 
					        public BasicGrid BasicGrid;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// <para>Collection bound to DataGrid headers used by plugins with UIType.Basic.</para>
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        public ObservableCollection<string> Headers;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// <para>Collection used to specify formatting of items in respective columns.</para>
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        public ObservableCollection<string> Formats;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					 | 
				
			||||||
        /// <para>Two-dimensional collection of items to display in UI grid.</para>
 | 
					 | 
				
			||||||
        /// </summary>
 | 
					 | 
				
			||||||
        public ObservableCollection<ObservableCollection<object>> Items;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Instantiate PluginUI of UIType.Basic.
 | 
					        /// Instantiate PluginUI of UIType.Basic.
 | 
				
			||||||
@@ -50,10 +34,10 @@ namespace Observatory.Framework
 | 
				
			|||||||
        /// <para>Collection bound to DataGrid used byu plugins with UIType.Basic.</para>
 | 
					        /// <para>Collection bound to DataGrid used byu plugins with UIType.Basic.</para>
 | 
				
			||||||
        /// <para>Objects in collection should be of a class defined within the plugin consisting of string properties.<br/>Each object is a single row, and the property names are used as column headers.</para>
 | 
					        /// <para>Objects in collection should be of a class defined within the plugin consisting of string properties.<br/>Each object is a single row, and the property names are used as column headers.</para>
 | 
				
			||||||
        /// </param>
 | 
					        /// </param>
 | 
				
			||||||
        public PluginUI(ObservableCollection<object> DataGrid)
 | 
					        public PluginUI(BasicGrid basicGrid)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            PluginUIType = UIType.Basic;
 | 
					            PluginUIType = UIType.Basic;
 | 
				
			||||||
            this.DataGrid = DataGrid;
 | 
					            BasicGrid = basicGrid;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user