From 36948fe955a267cb76a6ae04785b12a8d9679d4f Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 23 Oct 2018 11:52:10 -0700 Subject: [PATCH 1/6] Remove RunOnIdle in InventoryTreeView constructor --- .../Library/Widgets/InventoryTreeView.cs | 173 +++++++++--------- 1 file changed, 84 insertions(+), 89 deletions(-) diff --git a/MatterControlLib/Library/Widgets/InventoryTreeView.cs b/MatterControlLib/Library/Widgets/InventoryTreeView.cs index e5d14920f..540006a1e 100644 --- a/MatterControlLib/Library/Widgets/InventoryTreeView.cs +++ b/MatterControlLib/Library/Widgets/InventoryTreeView.cs @@ -51,107 +51,104 @@ namespace MatterHackers.MatterControl.PrintLibrary public InventoryTreeView(ThemeConfig theme) : base (theme) { - UiThread.RunOnIdle(() => + rootColumn = new FlowLayoutWidget(FlowDirection.TopToBottom) { - rootColumn = new FlowLayoutWidget(FlowDirection.TopToBottom) - { - HAnchor = HAnchor.Stretch, - VAnchor = VAnchor.Fit - }; - this.AddChild(rootColumn); + HAnchor = HAnchor.Stretch, + VAnchor = VAnchor.Fit + }; + this.AddChild(rootColumn); - // Printers - printersNode = new TreeNode(theme) - { - Text = "Printers".Localize(), - HAnchor = HAnchor.Stretch, - AlwaysExpandable = true, - Image = AggContext.StaticData.LoadIcon("printer.png", 16, 16, theme.InvertIcons) - }; - printersNode.TreeView = this; + // Printers + printersNode = new TreeNode(theme) + { + Text = "Printers".Localize(), + HAnchor = HAnchor.Stretch, + AlwaysExpandable = true, + Image = AggContext.StaticData.LoadIcon("printer.png", 16, 16, theme.InvertIcons) + }; + printersNode.TreeView = this; - var forcedHeight = 20; - var mainRow = printersNode.Children.FirstOrDefault(); - mainRow.HAnchor = HAnchor.Stretch; - mainRow.AddChild(new HorizontalSpacer()); + var forcedHeight = 20; + var mainRow = printersNode.Children.FirstOrDefault(); + mainRow.HAnchor = HAnchor.Stretch; + mainRow.AddChild(new HorizontalSpacer()); - // add in the create printer button - var createPrinter = new IconButton(AggContext.StaticData.LoadIcon("md-add-circle_18.png", 18, 18, theme.InvertIcons), theme) - { - Name = "Create Printer", - VAnchor = VAnchor.Center, - Margin = theme.ButtonSpacing.Clone(left: theme.ButtonSpacing.Right), - ToolTipText = "Create Printer".Localize(), - Height = forcedHeight, - Width = forcedHeight - }; + // add in the create printer button + var createPrinter = new IconButton(AggContext.StaticData.LoadIcon("md-add-circle_18.png", 18, 18, theme.InvertIcons), theme) + { + Name = "Create Printer", + VAnchor = VAnchor.Center, + Margin = theme.ButtonSpacing.Clone(left: theme.ButtonSpacing.Right), + ToolTipText = "Create Printer".Localize(), + Height = forcedHeight, + Width = forcedHeight + }; - createPrinter.Click += (s, e) => UiThread.RunOnIdle(() => + createPrinter.Click += (s, e) => UiThread.RunOnIdle(() => + { + if (ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPrinting + || ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPaused) { - if (ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPrinting - || ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPaused) - { - StyledMessageBox.ShowMessageBox("Please wait until the print has finished and try again.".Localize(), "Can't add printers while printing".Localize()); - } - else - { - DialogWindow.Show(PrinterSetup.GetBestStartPage(PrinterSetup.StartPageOptions.ShowMakeModel)); - } - }); - mainRow.AddChild(createPrinter); + StyledMessageBox.ShowMessageBox("Please wait until the print has finished and try again.".Localize(), "Can't add printers while printing".Localize()); + } + else + { + DialogWindow.Show(PrinterSetup.GetBestStartPage(PrinterSetup.StartPageOptions.ShowMakeModel)); + } + }); + mainRow.AddChild(createPrinter); - // add in the import printer button - var importPrinter = new IconButton(AggContext.StaticData.LoadIcon("md-import_18.png", 18, 18, theme.InvertIcons), theme) - { - VAnchor = VAnchor.Center, - Margin = theme.ButtonSpacing, - ToolTipText = "Import Printer".Localize(), - Height = forcedHeight, - Width = forcedHeight - }; - importPrinter.Click += (s, e) => UiThread.RunOnIdle(() => - { - AggContext.FileDialogs.OpenFileDialog( - new OpenFileDialogParams( - "settings files|*.ini;*.printer;*.slice"), - (result) => + // add in the import printer button + var importPrinter = new IconButton(AggContext.StaticData.LoadIcon("md-import_18.png", 18, 18, theme.InvertIcons), theme) + { + VAnchor = VAnchor.Center, + Margin = theme.ButtonSpacing, + ToolTipText = "Import Printer".Localize(), + Height = forcedHeight, + Width = forcedHeight + }; + importPrinter.Click += (s, e) => UiThread.RunOnIdle(() => + { + AggContext.FileDialogs.OpenFileDialog( + new OpenFileDialogParams( + "settings files|*.ini;*.printer;*.slice"), + (result) => + { + if (!string.IsNullOrEmpty(result.FileName) + && File.Exists(result.FileName)) { - if (!string.IsNullOrEmpty(result.FileName) - && File.Exists(result.FileName)) + //simpleTabs.RemoveTab(simpleTabs.ActiveTab); + if (ProfileManager.ImportFromExisting(result.FileName)) { - //simpleTabs.RemoveTab(simpleTabs.ActiveTab); - if (ProfileManager.ImportFromExisting(result.FileName)) - { - string importPrinterSuccessMessage = "You have successfully imported a new printer profile. You can find '{0}' in your list of available printers.".Localize(); - DialogWindow.Show( - new ImportSucceeded( - importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(result.FileName)))); - } - else - { - StyledMessageBox.ShowMessageBox("Oops! Settings file '{0}' did not contain any settings we could import.".Localize().FormatWith(Path.GetFileName(result.FileName)), "Unable to Import".Localize()); - } + string importPrinterSuccessMessage = "You have successfully imported a new printer profile. You can find '{0}' in your list of available printers.".Localize(); + DialogWindow.Show( + new ImportSucceeded( + importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(result.FileName)))); } - }); - }); - mainRow.AddChild(importPrinter); + else + { + StyledMessageBox.ShowMessageBox("Oops! Settings file '{0}' did not contain any settings we could import.".Localize().FormatWith(Path.GetFileName(result.FileName)), "Unable to Import".Localize()); + } + } + }); + }); + mainRow.AddChild(importPrinter); - rootColumn.AddChild(printersNode); + rootColumn.AddChild(printersNode); - InventoryTreeView.RebuildPrintersList(printersNode, theme); - this.Invalidate(); + InventoryTreeView.RebuildPrintersList(printersNode, theme); + this.Invalidate(); - // Filament - var materialsNode = new TreeNode(theme) - { - Text = "Materials".Localize(), - AlwaysExpandable = true, - Image = AggContext.StaticData.LoadIcon("filament.png", 16, 16, theme.InvertIcons) - }; - materialsNode.TreeView = this; + // Filament + var materialsNode = new TreeNode(theme) + { + Text = "Materials".Localize(), + AlwaysExpandable = true, + Image = AggContext.StaticData.LoadIcon("filament.png", 16, 16, theme.InvertIcons) + }; + materialsNode.TreeView = this; - rootColumn.AddChild(materialsNode); - }, 1); + rootColumn.AddChild(materialsNode); PrinterSettings.SettingChanged.RegisterEvent((s, e) => { @@ -169,8 +166,6 @@ namespace MatterHackers.MatterControl.PrintLibrary } }, ref unregisterEvents); - - PrinterSettings.SettingChanged.RegisterEvent((s, e) => { string settingsName = (e as StringEventArgs)?.Data; From 2ee7848093d44d95cce694955c116de639e557ec Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 23 Oct 2018 11:52:36 -0700 Subject: [PATCH 2/6] Make context menu icons menu theme aware --- MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs index 85beab1fc..e0c2d88fa 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs @@ -326,6 +326,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private Dictionary InitWorkspaceActions() { + bool invertIcons = ApplicationController.Instance.MenuTheme.InvertIcons; + return new Dictionary() { { @@ -334,7 +336,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { ID = "Insert", Title = "Insert".Localize(), - Icon = AggContext.StaticData.LoadIcon("cube.png", 16, 16, theme.InvertIcons), + Icon = AggContext.StaticData.LoadIcon("cube.png", 16, 16, invertIcons), Action = () => { var extensionsWithoutPeriod = new HashSet(ApplicationSettings.OpenDesignFileParams.Split('|').First().Split(',').Select(s => s.Trim().Trim('.'))); @@ -411,7 +413,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { ID = "Export", Title = "Export".Localize(), - Icon = AggContext.StaticData.LoadIcon("cube_export.png", 16, 16), + Icon = AggContext.StaticData.LoadIcon("cube_export.png", 16, 16, invertIcons), Action = () => { UiThread.RunOnIdle(async () => From e2c5ae4bfdde9ae74d20214eca313e39cf026f6c Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 23 Oct 2018 12:37:50 -0700 Subject: [PATCH 3/6] Add SchemaVersion to reset themes to default on change - Extract embedded ThemeSet type to new file - Eliminate redundant SerializedTheme type - Issue MatterHackers/MCCentral#4353 Toggle buttons missing dots --- .../ApplicationView/ApplicationController.cs | 30 +++------ .../ApplicationView/Themes/DirectoryTheme.cs | 42 ++++++------- .../ApplicationView/Themes/IColorTheme.cs | 4 +- .../ApplicationView/Themes/ThemeSet.cs | 63 +++++++++++++++++++ .../ApplicationSettings/ThemeColorPanel.cs | 4 +- StaticData/Themes/System/Affinity/theme.json | 5 -- StaticData/Themes/System/Classic/theme.json | 5 -- StaticData/Themes/System/Solarized/theme.json | 5 -- 8 files changed, 93 insertions(+), 65 deletions(-) create mode 100644 MatterControlLib/ApplicationView/Themes/ThemeSet.cs delete mode 100644 StaticData/Themes/System/Affinity/theme.json delete mode 100644 StaticData/Themes/System/Classic/theme.json delete mode 100644 StaticData/Themes/System/Solarized/theme.json diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 0c7341030..073a8c96c 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -152,6 +152,12 @@ namespace MatterHackers.MatterControl if (File.Exists(ProfileManager.Instance.ProfileThemeSetPath)) { themeset = JsonConvert.DeserializeObject(File.ReadAllText(ProfileManager.Instance.ProfileThemeSetPath)); + + // If the serialized format is older than the current format, null and fall back to latest default below + if (themeset.SchemeVersion != ThemeSet.LatestSchemeVersion) + { + themeset = null; + } } } catch { } @@ -159,7 +165,7 @@ namespace MatterHackers.MatterControl if (themeset == null) { var themeProvider = ThemeProviders.Values.First(); - themeset = themeProvider.GetTheme(themeProvider.ThemeNames.First(), themeProvider.DefaultColor); + themeset = themeProvider.GetTheme(themeProvider.ThemeNames.First()); } DefaultThumbView.ThumbColor = new Color(themeset.Theme.Colors.PrimaryTextColor, 30); @@ -199,28 +205,6 @@ namespace MatterHackers.MatterControl } } - public class ThemeSet - { - public string ThemeID { get; set; } - - public string Name { get; set; } - - public ThemeConfig Theme { get; set; } - - public ThemeConfig MenuTheme { get; set; } - - public List AccentColors { get; set; } = new List(); - - public void SetAccentColor(Color accentColor) - { - this.Theme.PrimaryAccentColor = accentColor; - this.Theme.AccentMimimalOverlay = accentColor.WithAlpha(90); - - this.MenuTheme.PrimaryAccentColor = accentColor; - this.MenuTheme.AccentMimimalOverlay = accentColor.WithAlpha(90); - } - } - public class ApplicationController { public HelpArticle HelpArticles { get; set; } diff --git a/MatterControlLib/ApplicationView/Themes/DirectoryTheme.cs b/MatterControlLib/ApplicationView/Themes/DirectoryTheme.cs index e628a8f8b..de8cb5789 100644 --- a/MatterControlLib/ApplicationView/Themes/DirectoryTheme.cs +++ b/MatterControlLib/ApplicationView/Themes/DirectoryTheme.cs @@ -37,50 +37,45 @@ namespace MatterHackers.MatterControl using MatterHackers.Agg.Platform; using Newtonsoft.Json; - public class SerializedTheme : IColorTheme - { - public string Name { get; set; } - - public Color DefaultColor { get; set; } - - public IEnumerable ThemeNames { get; set; } - - public ThemeSet GetTheme(string mode, Color accentColor) - { - throw new System.NotImplementedException(); - } - } - public class DirectoryTheme : IColorTheme { private string path; + public DirectoryTheme() { } public DirectoryTheme(string directory) { - var themeSetData = JsonConvert.DeserializeObject( - AggContext.StaticData.ReadAllText(Path.Combine(directory, "theme.json"))); - path = directory; this.Name = Path.GetFileName(directory); this.ThemeNames = AggContext.StaticData.GetFiles(directory).Where(p => Path.GetFileName(p) != "theme.json").Select(p => Path.GetFileNameWithoutExtension(p)).ToArray(); - - this.DefaultColor = themeSetData.DefaultColor; } public string Name { get; } - public Color DefaultColor { get; } - public IEnumerable ThemeNames { get; } public ThemeSet GetTheme(string themeName, Color accentColor) { - ThemeSet themeset = null; + var themeset = this.LoadTheme(themeName); + themeset.SetAccentColor(accentColor); + return themeset; + } + + public ThemeSet GetTheme(string themeName) + { + var themeset = this.LoadTheme(themeName); + themeset.SetAccentColor(themeset.AccentColors.First()); + + return themeset; + } + + private ThemeSet LoadTheme(string themeName) + { + ThemeSet themeset; try { themeset = JsonConvert.DeserializeObject( @@ -92,8 +87,9 @@ namespace MatterHackers.MatterControl AggContext.StaticData.ReadAllText(Path.Combine(path, this.ThemeNames.First() + ".json"))); } + // Set SchemaVersion at construction time + themeset.SchemeVersion = ThemeSet.LatestSchemeVersion; themeset.ThemeID = themeName; - themeset.SetAccentColor(accentColor); return themeset; } diff --git a/MatterControlLib/ApplicationView/Themes/IColorTheme.cs b/MatterControlLib/ApplicationView/Themes/IColorTheme.cs index eb39c46aa..6ccd54719 100644 --- a/MatterControlLib/ApplicationView/Themes/IColorTheme.cs +++ b/MatterControlLib/ApplicationView/Themes/IColorTheme.cs @@ -36,9 +36,11 @@ namespace MatterHackers.MatterControl public interface IColorTheme { string Name { get; } - Color DefaultColor { get; } + + ThemeSet GetTheme(string mode); ThemeSet GetTheme(string mode, Color accentColor); + IEnumerable ThemeNames { get; } } } \ No newline at end of file diff --git a/MatterControlLib/ApplicationView/Themes/ThemeSet.cs b/MatterControlLib/ApplicationView/Themes/ThemeSet.cs new file mode 100644 index 000000000..3df28705b --- /dev/null +++ b/MatterControlLib/ApplicationView/Themes/ThemeSet.cs @@ -0,0 +1,63 @@ +/* +Copyright (c) 2018, John Lewin +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. +*/ + +using System.Collections.Generic; +using MatterHackers.Agg; + +namespace MatterHackers.MatterControl +{ + public class ThemeSet + { + public static int LatestSchemeVersion { get; } = 20181023; + + public string ThemeID { get; set; } + + public string Name { get; set; } + + public ThemeConfig Theme { get; set; } + + public ThemeConfig MenuTheme { get; set; } + + public List AccentColors { get; set; } = new List(); + + public void SetAccentColor(Color accentColor) + { + this.Theme.PrimaryAccentColor = accentColor; + this.Theme.AccentMimimalOverlay = accentColor.WithAlpha(90); + + this.MenuTheme.PrimaryAccentColor = accentColor; + this.MenuTheme.AccentMimimalOverlay = accentColor.WithAlpha(90); + } + + /// + /// The latest version of the theme file format. When changed, the clients state becomes invalid and will require a reset to the new theme format + /// + public int SchemeVersion { get; set; } + } +} \ No newline at end of file diff --git a/MatterControlLib/ConfigurationPage/ApplicationSettings/ThemeColorPanel.cs b/MatterControlLib/ConfigurationPage/ApplicationSettings/ThemeColorPanel.cs index b59537824..93d3b11d6 100644 --- a/MatterControlLib/ConfigurationPage/ApplicationSettings/ThemeColorPanel.cs +++ b/MatterControlLib/ConfigurationPage/ApplicationSettings/ThemeColorPanel.cs @@ -95,8 +95,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage colorSelector.RebuildColorButtons(); this.CreateThemeModeButtons(); - - this.PreviewTheme(_themeProvider.DefaultColor); } } private void CreateThemeModeButtons() @@ -138,7 +136,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage } else { - themeset = provider.GetTheme(themeName, provider.DefaultColor); + themeset = provider.GetTheme(themeName); } previewContainer.AddChild(new ThemePreviewButton(themeset, this) diff --git a/StaticData/Themes/System/Affinity/theme.json b/StaticData/Themes/System/Affinity/theme.json deleted file mode 100644 index 2fd50cc7a..000000000 --- a/StaticData/Themes/System/Affinity/theme.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "DefaultMode": "Dark", - "DefaultColor": "#cb4b16", - "Colors": ["#b58900", "#cb4b16", "#dc322f", "#d33682", "#6c71c4", "#268bd2", "#2aa198", "#859900"] -} \ No newline at end of file diff --git a/StaticData/Themes/System/Classic/theme.json b/StaticData/Themes/System/Classic/theme.json deleted file mode 100644 index ab9fb9901..000000000 --- a/StaticData/Themes/System/Classic/theme.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "DefaultMode": "Dark", - "DefaultColor": "#ac193dff", - "Colors": ["#ac193dff", "#dc4fadff", "#ff8119ff", "#008a17ff", "#004b8bff", "#008299ff", "#5db2ffff", "#4617b4ff", "#8c0095ff", "#585858ff"] -} \ No newline at end of file diff --git a/StaticData/Themes/System/Solarized/theme.json b/StaticData/Themes/System/Solarized/theme.json deleted file mode 100644 index ae45c2800..000000000 --- a/StaticData/Themes/System/Solarized/theme.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "DefaultMode": "Dark", - "DefaultColor": "#b58900", - "Colors": ["#b58900", "#cb4b16", "#dc322f", "#d33682", "#6c71c4", "#268bd2", "#2aa198", "#859900"] -} \ No newline at end of file From f7c28b5b8d76c36458eef91c83654d42bb0c9a94 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 23 Oct 2018 14:16:54 -0700 Subject: [PATCH 4/6] Ensure active tab remains on ReloadAll - Issue MatterHackers/MCCentral#4356 --- MatterControlLib/PartPreviewWindow/PartPreviewContent.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/PartPreviewContent.cs b/MatterControlLib/PartPreviewWindow/PartPreviewContent.cs index 05e360f8f..fc686140d 100644 --- a/MatterControlLib/PartPreviewWindow/PartPreviewContent.cs +++ b/MatterControlLib/PartPreviewWindow/PartPreviewContent.cs @@ -289,8 +289,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } - tabControl.SelectedTabKey = tabKey; - var brandMenu = new BrandMenuButton(theme) { HAnchor = HAnchor.Fit, @@ -307,6 +305,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow this.CreatePartTab(workspace); } + tabControl.SelectedTabKey = tabKey; + UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent((s, e) => { SetLinkButtonsVisibility(s, new StringEventArgs("Unknown")); From aaf0216f73d4b5e333b48efc142846b4773c8aea Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 23 Oct 2018 14:20:55 -0700 Subject: [PATCH 5/6] Add icon to Open button - Issue MatterHackers/MCCentral#4319 Open button should become IconButton and be duplicated on toolbar --- .../Library/Widgets/PrintLibraryWidget.cs | 9 ++++++--- StaticData/Icons/fa-folder-open_16.png | Bin 0 -> 294 bytes 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 StaticData/Icons/fa-folder-open_16.png diff --git a/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs b/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs index 9e02a0bfb..60d010ca4 100644 --- a/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs +++ b/MatterControlLib/Library/Widgets/PrintLibraryWidget.cs @@ -68,7 +68,7 @@ namespace MatterHackers.MatterControl.PrintLibrary private OverflowBar navBar; private GuiWidget searchButton; - public PrintLibraryWidget(PartPreviewContent partPreviewContent, ThemeConfig theme) + public PrintLibraryWidget(PartPreviewContent partPreviewContent, ThemeConfig theme, PopupMenuButton popupMenuButton) { this.theme = theme; this.partPreviewContent = partPreviewContent; @@ -172,12 +172,15 @@ namespace MatterHackers.MatterControl.PrintLibrary }; toolbar.AddChild(showFolders); - var openButton = new TextButton("Open", theme) + var openButton = new TextIconButton("Open".Localize(), AggContext.StaticData.LoadIcon("fa-folder-open_16.png", 16, 16, theme.InvertIcons), theme) { Margin = theme.ButtonSpacing, + ToolTipText = "Open File".Localize() }; openButton.Click += (s, e) => { + popupMenuButton.CloseMenu(); + var extensionsWithoutPeriod = new HashSet(ApplicationSettings.OpenDesignFileParams.Split('|').First().Split(',').Select(t => t.Trim().Trim('.'))); foreach (var extension in ApplicationController.Instance.Library.ContentProviders.Keys) @@ -200,7 +203,7 @@ namespace MatterHackers.MatterControl.PrintLibrary { ViewControls3D.LoadAndAddPartsToPlate(this, openParams.FileNames, ApplicationController.Instance.DragDropData.SceneContext); }); - }); + }, .1); }; toolbar.AddChild(openButton); diff --git a/StaticData/Icons/fa-folder-open_16.png b/StaticData/Icons/fa-folder-open_16.png new file mode 100644 index 0000000000000000000000000000000000000000..30d9392a2f24ac48b0fe3bffc66ff1e8722a5718 GIT binary patch literal 294 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`&C3 z=qc&oEhQjyD4X!*ov<#}EtuWC^tcH*Q48cFbq^Sg*mh@#?}$EsV3$b|?m9 z9%ATDi;>uU`htkyp&5FI7jfvfWjQmLu-OhGlA_4Q(;4eu0V2dPv3k-L-q(`4hBnwv%CSGPCwKIx}CNbP0l+XkKOxRw} literal 0 HcmV?d00001 From e2a9356f6ddc1cdd626cf799f44eec69ac3536c4 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 23 Oct 2018 14:22:32 -0700 Subject: [PATCH 6/6] Prevent crash due to null Parent reference - Unwire event listener when parent is null - Issue MatterHackers/MCCentral#4357 Crash due to "Add Content" -> popup logic problems --- .../PartPreviewWindow/ViewControls3D.cs | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/ViewControls3D.cs b/MatterControlLib/PartPreviewWindow/ViewControls3D.cs index 6704acc45..321dfc888 100644 --- a/MatterControlLib/PartPreviewWindow/ViewControls3D.cs +++ b/MatterControlLib/PartPreviewWindow/ViewControls3D.cs @@ -542,7 +542,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var systemWindow = this.Parents().FirstOrDefault(); - var printLibraryWidget = new PrintLibraryWidget(partPreviewContent, theme) + var printLibraryWidget = new PrintLibraryWidget(partPreviewContent, theme, libraryPopup) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Absolute, @@ -561,14 +561,21 @@ namespace MatterHackers.MatterControl.PartPreviewWindow void systemWindownMouseDown(object s2, MouseEventArgs mouseEvent) { - // MouseUp on our SystemWindow outside of our bounds should call close - var resizeContainerMousePosition = verticalResizeContainer.TransformFromScreenSpace(mouseEvent.Position); - bool mouseUpOnWidget = resizeContainerMousePosition.X >= 0 && resizeContainerMousePosition.X <= verticalResizeContainer.Width - && resizeContainerMousePosition.Y >= 0 && resizeContainerMousePosition.Y <= verticalResizeContainer.Height; - - if (!mouseUpOnWidget) + if (verticalResizeContainer.Parent != null) + { + // MouseUp on our SystemWindow outside of our bounds should call close + var resizeContainerMousePosition = verticalResizeContainer.TransformFromScreenSpace(mouseEvent.Position); + bool mouseUpOnWidget = resizeContainerMousePosition.X >= 0 && resizeContainerMousePosition.X <= verticalResizeContainer.Width + && resizeContainerMousePosition.Y >= 0 && resizeContainerMousePosition.Y <= verticalResizeContainer.Height; + + if (!mouseUpOnWidget) + { + libraryPopup.CloseMenu(); + systemWindow.MouseDown -= systemWindownMouseDown; + } + } + else { - libraryPopup.CloseMenu(); systemWindow.MouseDown -= systemWindownMouseDown; } }; @@ -661,7 +668,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { if (filesToLoad != null && filesToLoad.Length > 0) { - await Task.Run(() => loadAndAddPartsToPlate(filesToLoad, sceneContext)); if (originatingWidget.HasBeenClosed)