From b1c19518089f0a93fb34cd09bd367e916acc0ffc Mon Sep 17 00:00:00 2001 From: Rutherther Date: Thu, 2 Feb 2023 23:48:11 +0100 Subject: [PATCH] feat: allow connecting to process from menu --- src/PacketLogger/ViewModels/DockFactory.cs | 6 ++++-- .../ViewModels/MainWindowViewModel.cs | 17 +++++++++++++++++ src/PacketLogger/Views/MainWindow.axaml | 15 ++++++++++++--- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/PacketLogger/ViewModels/DockFactory.cs b/src/PacketLogger/ViewModels/DockFactory.cs index ca473ff..619a6fd 100644 --- a/src/PacketLogger/ViewModels/DockFactory.cs +++ b/src/PacketLogger/ViewModels/DockFactory.cs @@ -25,7 +25,7 @@ namespace PacketLogger.ViewModels; public class DockFactory : Factory, IDisposable { private readonly StatefulRepository _repository; - private readonly NostaleProcesses _processes = new(); + private readonly NostaleProcesses _processes; private readonly CommsInjector _injector; private IRootDock? _rootDock; @@ -34,10 +34,12 @@ public class DockFactory : Factory, IDisposable /// /// Initializes a new instance of the class. /// + /// The nostale processes. /// The communications injector. /// The repository. - public DockFactory(CommsInjector injector, StatefulRepository repository) + public DockFactory(NostaleProcesses processes, CommsInjector injector, StatefulRepository repository) { + _processes = processes; _repository = repository; _injector = injector; } diff --git a/src/PacketLogger/ViewModels/MainWindowViewModel.cs b/src/PacketLogger/ViewModels/MainWindowViewModel.cs index 4a0dd8d..5161614 100644 --- a/src/PacketLogger/ViewModels/MainWindowViewModel.cs +++ b/src/PacketLogger/ViewModels/MainWindowViewModel.cs @@ -5,6 +5,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Collections; using System.Collections.ObjectModel; using System.ComponentModel; using System.IO; @@ -35,6 +36,7 @@ namespace PacketLogger.ViewModels; public class MainWindowViewModel : ViewModelBase, INotifyPropertyChanged { private readonly DockFactory _factory; + private readonly NostaleProcesses _processes; /// /// Initializes a new instance of the class. @@ -44,6 +46,7 @@ public class MainWindowViewModel : ViewModelBase, INotifyPropertyChanged var services = new ServiceCollection() .AddLogging(b => b.ClearProviders().AddConsole()) .AddSingleton() + .AddSingleton() .AddNostaleCore() .AddStatefulInjector() .AddStatefulEntity() @@ -51,6 +54,7 @@ public class MainWindowViewModel : ViewModelBase, INotifyPropertyChanged .AddPacketResponder() .BuildServiceProvider(); + _processes = services.GetRequiredService(); var packetTypes = services.GetRequiredService(); var result = packetTypes.AddDefaultPackets(); @@ -141,6 +145,9 @@ public class MainWindowViewModel : ViewModelBase, INotifyPropertyChanged OpenEmpty = ReactiveCommand.Create (() => _factory.CreateLoadedDocument(doc => doc.OpenDummy.Execute(Unit.Default))); + Connect = ReactiveCommand.Create + (process => _factory.CreateLoadedDocument(doc => doc.OpenProcess.Execute((NostaleProcess)process[0]!))); + NewTab = ReactiveCommand.Create (() => _factory.DocumentDock.CreateDocument?.Execute(null)); @@ -148,6 +155,11 @@ public class MainWindowViewModel : ViewModelBase, INotifyPropertyChanged (() => (Application.Current?.ApplicationLifetime as IControlledApplicationLifetime)?.Shutdown()); } + /// + /// Gets the nostale processes. + /// + public ObservableCollection Processes => _processes.Processes; + /// /// Gets or sets the layout. /// @@ -178,6 +190,11 @@ public class MainWindowViewModel : ViewModelBase, INotifyPropertyChanged /// public ReactiveCommand OpenEmpty { get; } + /// + /// Gets the command that opens empty logger. + /// + public ReactiveCommand Connect { get; } + /// /// Gets the command that opens a new tab. /// diff --git a/src/PacketLogger/Views/MainWindow.axaml b/src/PacketLogger/Views/MainWindow.axaml index 8732fdc..0c350ff 100644 --- a/src/PacketLogger/Views/MainWindow.axaml +++ b/src/PacketLogger/Views/MainWindow.axaml @@ -23,6 +23,15 @@ + + + + + @@ -31,11 +40,11 @@ - - + + - +