diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index f657f8cf5..e1c6ee796 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -704,6 +704,33 @@ namespace MatterHackers.MatterControl return actions.ToDictionary(a => a.ID); } + public static void OpenFileWithSystemDialog(Action openFiles) + { + var extensionsWithoutPeriod = new HashSet(ApplicationSettings.OpenDesignFileParams.Split('|').First().Split(',').Select(t => t.Trim().Trim('.'))); + + foreach (var extension in ApplicationController.Instance.Library.ContentProviders.Keys) + { + extensionsWithoutPeriod.Add(extension.ToUpper()); + } + + var extensionsArray = extensionsWithoutPeriod.OrderBy(t => t).ToArray(); + + string filter = string.Format( + "{0}|{1}", + string.Join(",", extensionsArray), + string.Join("", extensionsArray.Select(t => $"*.{t.ToLower()};").ToArray())); + + UiThread.RunOnIdle(() => + { + AggContext.FileDialogs.OpenFileDialog( + new OpenFileDialogParams(filter, multiSelect: true), + (openParams) => + { + openFiles?.Invoke(openParams.FileNames); + }); + }, .1); + } + public async Task OpenIntoNewTab(IEnumerable selectedLibraryItems) { await this.MainView.CreateNewDesignTab(false); diff --git a/MatterControlLib/ApplicationView/BrandMenuButton.cs b/MatterControlLib/ApplicationView/BrandMenuButton.cs index e7960e6b4..9ac1dc13b 100644 --- a/MatterControlLib/ApplicationView/BrandMenuButton.cs +++ b/MatterControlLib/ApplicationView/BrandMenuButton.cs @@ -28,6 +28,7 @@ either expressed or implied, of the FreeBSD Project. */ using System; +using System.Linq; using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.Agg.Platform; @@ -92,6 +93,11 @@ namespace MatterHackers.MatterControl PopupMenu.MenuItem menuItem; + menuItem = popupMenu.CreateMenuItem("Open File", StaticData.Instance.LoadIcon("fa-folder-open_16.png", 16, 16).SetToColor(menuTheme.TextColor)); + menuItem.Click += (s, e) => ApplicationController.OpenFileWithSystemDialog((fileNames) => ApplicationController.Instance.MainView.OpenFile(fileNames.FirstOrDefault())); + + popupMenu.CreateSeparator(); + menuItem = popupMenu.CreateMenuItem("Help".Localize(), StaticData.Instance.LoadIcon("help_page.png", 16, 16).SetToColor(menuTheme.TextColor)); menuItem.Click += (s, e) => ApplicationController.Instance.ShowApplicationHelp("Docs"); diff --git a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs index fd64e1840..73a794cf9 100644 --- a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs +++ b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs @@ -466,14 +466,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } #endif - public void OpenDropFile(string filePath) + public void OpenFile(string filePath) { Instance_OpenNewFile(this, filePath); } private async void Instance_OpenNewFile(object sender, string filePath) { - if (File.Exists(filePath)) + if (!string.IsNullOrEmpty(filePath) + && File.Exists(filePath)) { if (Path.GetExtension(filePath).ToLower() == ".mcx") { diff --git a/MatterControlLib/PartPreviewWindow/Tabs.cs b/MatterControlLib/PartPreviewWindow/Tabs.cs index 504d1ff16..8b7f19426 100644 --- a/MatterControlLib/PartPreviewWindow/Tabs.cs +++ b/MatterControlLib/PartPreviewWindow/Tabs.cs @@ -289,7 +289,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { foreach (var file in e.DragFiles) { - ApplicationController.Instance.MainView.OpenDropFile(file); + ApplicationController.Instance.MainView.OpenFile(file); } } }; diff --git a/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs b/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs index 056bf3f81..2b1278275 100644 --- a/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs +++ b/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs @@ -650,38 +650,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var openFileButton = openMenuItems.CreateMenuItem("Add File to Bed".Localize(), StaticData.Instance.LoadIcon("fa-folder-open_16.png", 16, 16).SetToColor(theme.TextColor)); openFileButton.Click += (s, e) => - { - var extensionsWithoutPeriod = new HashSet(ApplicationSettings.OpenDesignFileParams.Split('|').First().Split(',').Select(t => t.Trim().Trim('.'))); - - foreach (var extension in ApplicationController.Instance.Library.ContentProviders.Keys) - { - extensionsWithoutPeriod.Add(extension.ToUpper()); - } - - var extensionsArray = extensionsWithoutPeriod.OrderBy(t => t).ToArray(); - - string filter = string.Format( - "{0}|{1}", - string.Join(",", extensionsArray), - string.Join("", extensionsArray.Select(t => $"*.{t.ToLower()};").ToArray())); - - UiThread.RunOnIdle(() => - { - AggContext.FileDialogs.OpenFileDialog( - new OpenFileDialogParams(filter, multiSelect: true), - (openParams) => - { - sceneContext.AddToPlate(openParams.FileNames); - }); - }, .1); - }; - - // popupMenu.AddChild(openLibraryButton, 0); + { + ApplicationController.OpenFileWithSystemDialog((fileNames) => + { + sceneContext.AddToPlate(fileNames); + }); + }; return popupMenu; } - private void UpdateToolbarButtons(object sender, EventArgs e) + private void UpdateToolbarButtons(object sender, EventArgs e) { // Set enabled level based on operation rules foreach (var (button, operation) in operationButtons.Select(kvp => (kvp.Key, kvp.Value)))