From 12d8291a20cadc5067b57aa6063d4091993e6436 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Thu, 20 Jun 2019 22:54:05 -0700 Subject: [PATCH] Restore Explorer file association support - Issue MatterHackers/MCCentral#5719 Windows Explorer file associations fail to open file --- .../ApplicationView/ApplicationController.cs | 8 +++-- Program.cs | 31 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 7cb277d97..d3f8641dc 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -2503,7 +2503,8 @@ namespace MatterHackers.MatterControl SourceItem = history.NewPlatingItem() }); - this.OpenWorkspace(workspace); + // Open but no need to save + this.OpenWorkspace(workspace, WorkspacesChangedEventArgs.OperationType.Restore); } } @@ -4068,6 +4069,9 @@ Support and tutorials: { try { + // Initial load builds UI elements, then constructs workspace tabs as they're encountered in RestoreUserTabs() + await applicationController.RestoreUserTabs(); + // Batch startup actions await applicationController.Tasks.Execute( "Finishing Startup".Localize(), @@ -4099,8 +4103,6 @@ Support and tutorials: await applicationController.Tasks.Execute(task.Title, null, task.Action); } - // Initial load builds UI elements, then constructs workspace tabs as they're encountered in RestoreUserTabs() - await applicationController.RestoreUserTabs(); if (ApplicationSettings.Instance.get(UserSettingsKey.ShownWelcomeMessage) != "false") { diff --git a/Program.cs b/Program.cs index a2d93ec3a..5471496d0 100644 --- a/Program.cs +++ b/Program.cs @@ -55,7 +55,9 @@ namespace MatterHackers.MatterControl private static RaygunClient _raygunClient; - private static string mainServiceName = ""; + private static string mainServiceName = "shell"; + + private const string ServiceBaseUri = "net.pipe://localhost/mattercontrol"; [STAThread] public static void Main(string[] args) @@ -105,11 +107,7 @@ namespace MatterHackers.MatterControl return; } - // #endif - var serviceHost = new ServiceHost( - typeof(LocalService), - new Uri[] { new Uri("net.pipe://localhost/mattercontrol") }); - + var serviceHost = new ServiceHost(typeof(LocalService), new[] { new Uri(ServiceBaseUri) }); serviceHost.AddServiceEndpoint(typeof(IMainService), new NetNamedPipeBinding(), mainServiceName); serviceHost.Open(); @@ -118,6 +116,25 @@ namespace MatterHackers.MatterControl string.Join(", ", serviceHost.Description.Endpoints.Select(s => s.ListenUri.AbsoluteUri).ToArray())); } + // If MatterControl isn't running and valid files were shelled, schedule a StartupAction to open the files after load + var shellFiles = args.Where(f => File.Exists(f) && shellFileExtensions.Contains(Path.GetExtension(f).ToLower())); + if (shellFiles.Any()) + { + ApplicationController.StartupActions.Add(new ApplicationController.StartupAction() + { + Title = "Shell Files", + Priority = 0, + Action = () => + { + // Open each shelled file + foreach (string file in shellFiles) + { + ApplicationController.Instance.ShellOpenFile(file); + } + } + }); + } + // Load optional user configuration IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true) @@ -217,7 +234,7 @@ namespace MatterHackers.MatterControl new ServiceEndpoint( ContractDescription.GetContract(typeof(IMainService)), new NetNamedPipeBinding(), - new EndpointAddress($"net.pipe://localhost/{mainServiceName}"))) + new EndpointAddress($"{ServiceBaseUri}/{mainServiceName}"))) { }