From 6e6c91e7d7331774e28a26f0c88a0f26656688fb Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 5 Jun 2018 17:34:40 -0700 Subject: [PATCH 1/3] Remove wrapping container, remove padding --- SetupWizard/DesignSpaceHelp.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/SetupWizard/DesignSpaceHelp.cs b/SetupWizard/DesignSpaceHelp.cs index b5ab7c35f..3ef131584 100644 --- a/SetupWizard/DesignSpaceHelp.cs +++ b/SetupWizard/DesignSpaceHelp.cs @@ -99,13 +99,6 @@ namespace MatterHackers.MatterControl this.HeaderText = "How to succeed with MatterControl".Localize(); this.ChildBorderColor = theme.GetBorderColor(75); - var container = new FlowLayoutWidget(FlowDirection.TopToBottom) - { - HAnchor = HAnchor.Stretch, - VAnchor = VAnchor.Stretch - }; - contentRow.AddChild(container); - var tabControl = new SimpleTabs(theme, new GuiWidget()) { HAnchor = HAnchor.Stretch, @@ -113,7 +106,8 @@ namespace MatterHackers.MatterControl }; tabControl.TabBar.BackgroundColor = theme.TabBarBackground; - container.AddChild(tabControl); + contentRow.AddChild(tabControl); + contentRow.Padding = 0; // add the mouse commands var mouseControls = new FlowLayoutWidget() From 19fb79769a57f44e517dc020d02b6fb2f9094715 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 5 Jun 2018 17:54:03 -0700 Subject: [PATCH 2/3] Add support for opening to Help -> TargetGuideID - Issue MatterHackers/MCCentral#3515 Support linking to tree nodes in help (use this for "What's new" link on initial run --- ApplicationView/ApplicationController.cs | 2 +- .../ApplicationSettingsView.cs | 2 +- PartPreviewWindow/PartPreviewContent.cs | 2 +- PartPreviewWindow/Tabs.cs | 5 ++ PartPreviewWindow/ViewControls3D.cs | 2 +- SetupWizard/DesignSpaceHelp.cs | 57 ++++++++++--------- 6 files changed, 38 insertions(+), 32 deletions(-) diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index 700704c7b..b9669acb2 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -2337,7 +2337,7 @@ namespace MatterHackers.MatterControl { UiThread.RunOnIdle(() => { - DialogWindow.Show(new DesignSpaceGuide("Guides Tab", "")); + DialogWindow.Show(new DesignSpaceGuide("AllGuides")); }); } diff --git a/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs b/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs index 695e979f6..89127a019 100644 --- a/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs +++ b/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs @@ -107,7 +107,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage { UiThread.RunOnIdle(() => { - DialogWindow.Show(new DesignSpaceGuide("Guides Tab", "")); + DialogWindow.Show(new DesignSpaceGuide("AllGuides")); }); }); diff --git a/PartPreviewWindow/PartPreviewContent.cs b/PartPreviewWindow/PartPreviewContent.cs index 37e21891b..ee2fce97b 100644 --- a/PartPreviewWindow/PartPreviewContent.cs +++ b/PartPreviewWindow/PartPreviewContent.cs @@ -110,7 +110,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow seeWhatsNewButton.Click += (s, e) => UiThread.RunOnIdle(() => { UserSettings.Instance.set(UserSettingsKey.LastReadWhatsNew, JsonConvert.SerializeObject(DateTime.Now)); - DialogWindow.Show(new DesignSpaceGuide("What's New Tab", "")); + DialogWindow.Show(new DesignSpaceGuide("What's New")); }); tabControl.TabBar.ActionArea.AddChild(seeWhatsNewButton); diff --git a/PartPreviewWindow/Tabs.cs b/PartPreviewWindow/Tabs.cs index 64487cdbc..289d45745 100644 --- a/PartPreviewWindow/Tabs.cs +++ b/PartPreviewWindow/Tabs.cs @@ -181,6 +181,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { this.ActiveTabChanged?.Invoke(this, null); } + + internal int GetTabIndex(SimpleTab tab) + { + return _allTabs.IndexOf(tab); + } } public class ChromeTabs : SimpleTabs diff --git a/PartPreviewWindow/ViewControls3D.cs b/PartPreviewWindow/ViewControls3D.cs index 3aec98b9d..77a5f151f 100644 --- a/PartPreviewWindow/ViewControls3D.cs +++ b/PartPreviewWindow/ViewControls3D.cs @@ -613,7 +613,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { UiThread.RunOnIdle(() => { - DialogWindow.Show(new DesignSpaceGuide("", "")); + DialogWindow.Show(new DesignSpaceGuide()); }); } } diff --git a/SetupWizard/DesignSpaceHelp.cs b/SetupWizard/DesignSpaceHelp.cs index 3ef131584..ff70ebe69 100644 --- a/SetupWizard/DesignSpaceHelp.cs +++ b/SetupWizard/DesignSpaceHelp.cs @@ -81,20 +81,14 @@ namespace MatterHackers.MatterControl public class DesignSpaceGuide : DialogPage { - private List whatsNewGuides = new List(); - private List allAvailableGuides = new List(); + private Dictionary nodesByID; + private TreeView treeView; - - public DesignSpaceGuide(string preSelectTabName, string guideKey) + public DesignSpaceGuide(string guideKey = null) : base("Close".Localize()) { WindowSize = new Vector2(800, 600); - allAvailableGuides = ApplicationController.Instance.FeatureGuides; - - // TODO: Guides document should have separate properties for differing top level containers - whatsNewGuides = allAvailableGuides; - this.WindowTitle = "MatterControl " + "Help".Localize(); this.HeaderText = "How to succeed with MatterControl".Localize(); this.ChildBorderColor = theme.GetBorderColor(75); @@ -225,6 +219,7 @@ namespace MatterHackers.MatterControl VAnchor = VAnchor.Stretch, Padding = theme.DefaultContainerPadding }; + var guideTab = new ToolTab("Guides".Localize(), tabControl, guideSectionContainer, theme, hasClose: false) { // this can be used to navigate to this tab on construction @@ -232,30 +227,30 @@ namespace MatterHackers.MatterControl }; tabControl.AddTab(guideTab); - AddGuides(guideSectionContainer, allAvailableGuides); + AddGuides(guideSectionContainer); - tabControl.SelectedTabIndex = 0; - if(!string.IsNullOrWhiteSpace(preSelectTabName)) + // If guideKey is empty, switch to first tab + if (string.IsNullOrEmpty(guideKey)) { - // try to find the named tab - int index = 0; - foreach(var tab in tabControl.AllTabs) + tabControl.SelectedTabIndex = 0; + } + else + { + // Otherwise switch to guides tab and select the target item + tabControl.SelectedTabIndex = tabControl.GetTabIndex(guideTab); + + // TODO: Find the target TreeNode by ID and select + if (nodesByID.TryGetValue(guideKey, out TreeNode guideNode)) { - if (tab is GuiWidget widget) - { - if (widget.Name == preSelectTabName) - { - tabControl.SelectedTabIndex = index; - break; - } - } - index++; + treeView.SelectedNode = guideNode; } } } - private void AddGuides(FlowLayoutWidget guideContainer, List guideList) + private void AddGuides(FlowLayoutWidget guideContainer) { + nodesByID = new Dictionary(); + var sequence = new ImageSequence() { FramesPerSecond = 3, @@ -291,7 +286,7 @@ namespace MatterHackers.MatterControl }; rightPanel.AddChild(description); - var treeView = new TreeView(theme) + treeView = new TreeView(theme) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit | VAnchor.Top, @@ -319,13 +314,17 @@ namespace MatterHackers.MatterControl treeView.Load += (s, e) => { rootNode.Expanded = true; - treeView.SelectedNode = rootNode.Nodes.FirstOrDefault(); + + if (treeView.SelectedNode == null) + { + treeView.SelectedNode = rootNode.Nodes.FirstOrDefault(); + } }; TreeNode firstNode = null; double maxMenuItemWidth = 0; - foreach (var guide in guideList) + foreach (var guide in ApplicationController.Instance.FeatureGuides.OrderBy(g => g.MenuName)) { var treeNode = new TreeNode() { @@ -342,6 +341,8 @@ namespace MatterHackers.MatterControl firstNode = treeNode; } + nodesByID.Add(guide.MenuName, treeNode); + rootNode.Nodes.Add(treeNode); } From 64fbf007b7f13903bcc752377ece76b73669d07c Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 5 Jun 2018 17:54:19 -0700 Subject: [PATCH 3/3] Improve protections around lastReadWhatsNew --- SettingsManagement/UserSettings.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/SettingsManagement/UserSettings.cs b/SettingsManagement/UserSettings.cs index c83d499d7..788eb8674 100644 --- a/SettingsManagement/UserSettings.cs +++ b/SettingsManagement/UserSettings.cs @@ -119,9 +119,14 @@ namespace MatterHackers.MatterControl DateTime installTime = new FileInfo(filePath).LastWriteTime; var lastReadWhatsNew = UserSettings.Instance.get(UserSettingsKey.LastReadWhatsNew); DateTime whatsNewReadTime = installTime; - if (lastReadWhatsNew != null) + + if (!string.IsNullOrWhiteSpace(lastReadWhatsNew)) { - whatsNewReadTime = JsonConvert.DeserializeObject(lastReadWhatsNew); + try + { + whatsNewReadTime = JsonConvert.DeserializeObject(lastReadWhatsNew); + } + catch { } } return whatsNewReadTime > installTime;