Merge pull request #4750 from larsbrubaker/master

master
This commit is contained in:
Lars Brubaker 2020-05-16 22:57:03 -07:00 committed by GitHub
commit e9db1b52cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 140 additions and 32 deletions

View file

@ -119,7 +119,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
Margin = new BorderDouble(right: 4),
Selectable = false
});
};
}
this.HighlightRegion.AddChild(textWidget = new TextWidget(this.Text, pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
{
@ -141,6 +141,48 @@ namespace MatterHackers.MatterControl.CustomWidgets
this.Nodes.CollectionChanged += this.Nodes_CollectionChanged;
}
public override void OnKeyDown(KeyEventArgs keyEvent)
{
base.OnKeyDown(keyEvent);
var restoreFocus = Focused;
if (!keyEvent.Handled)
{
switch (keyEvent.KeyCode)
{
case Keys.Right:
this.Expanded = true;
keyEvent.Handled = true;
break;
case Keys.Left:
if (!this.Expanded)
{
if (this.NodeParent != null)
{
// navigate back up to the parent of this node
TreeView.SelectedNode = this.NodeParent;
}
restoreFocus = false;
}
else
{
this.Expanded = false;
}
keyEvent.Handled = true;
break;
}
}
if (restoreFocus && !Focused)
{
Focus();
}
}
private void Nodes_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
@ -328,7 +370,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
/// </summary>
public int Level { get; }
//
// Summary:
// Gets the next sibling tree node.
//
@ -336,7 +377,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
// A TreeNode that represents the next sibling tree node.
public TreeNode NextNode { get; }
//
// Summary:
// Gets the next visible tree node.
//
@ -344,7 +384,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
// A TreeNode that represents the next visible tree node.
public TreeNode NextVisibleNode { get; }
//
// Summary:
// Gets or sets the font that is used to display the text on the tree node label.
//
@ -352,7 +391,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
// The StyledTypeFace that is used to display the text on the tree node label.
public StyledTypeFace NodeFont { get; set; }
//
// Summary:
// Gets the parent tree node of the current tree node.
//
@ -365,7 +403,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
public int PointSize { get; set; }
//
// Summary:
// Gets the previous sibling tree node.
//
@ -373,7 +410,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
// A TreeNode that represents the previous sibling tree node.
public TreeNode PrevNode { get; }
//
// Summary:
// Gets the previous visible tree node.
//
@ -381,7 +417,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
// A TreeNode that represents the previous visible tree node.
public TreeNode PrevVisibleNode { get; }
//
// Summary:
// Gets a value indicating whether the tree node is in the selected state.
//
@ -400,7 +435,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
}
}
//
// Summary:
// Gets or sets the image list index value of the image that is displayed when the
// tree node is in the selected state.
@ -409,7 +443,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
// A zero-based index value that represents the image position in an ImageList.
public ImageBuffer SelectedImage { get; set; }
//
// Summary:
// Gets or sets the index of the image that is used to indicate the state of the
// TreeNode when the parent TreeView has
@ -423,7 +456,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
// The specified index is less than -1 or greater than 14.
public ImageBuffer StateImage { get; set; }
//
// Summary:
// Gets or sets the object that contains data about the tree node.
//
@ -433,7 +465,6 @@ namespace MatterHackers.MatterControl.CustomWidgets
public Color TextColor { get; set; }
//
// Summary:
// Gets the parent tree view that the tree node is assigned to.
//

View file

@ -202,6 +202,65 @@ namespace MatterHackers.MatterControl.CustomWidgets
_selectedNode = null;
}
public override void OnKeyDown(KeyEventArgs keyEvent)
{
if (!keyEvent.Handled)
{
switch (keyEvent.KeyCode)
{
case Keys.Up:
var prev = PreviousVisibleTreeNode(SelectedNode);
if (prev != null)
{
SelectedNode = prev;
keyEvent.Handled = true;
}
break;
case Keys.Down:
var next = NextVisibleTreeNode(SelectedNode);
if (next != null)
{
SelectedNode = next;
keyEvent.Handled = true;
}
break;
}
}
base.OnKeyDown(keyEvent);
}
private TreeNode NextVisibleTreeNode(TreeNode treeNode)
{
var nodes = this.Descendants<TreeNode>((child) => child.Visible).ToList();
var selectedIndex = nodes.IndexOf(SelectedNode);
if (selectedIndex < nodes.Count - 1)
{
return nodes[selectedIndex + 1];
}
return null;
}
private TreeNode PreviousVisibleTreeNode(TreeNode treeNode)
{
var nodes = this.Descendants<TreeNode>((child) => child.Visible).ToList();
var selectedIndex = nodes.IndexOf(SelectedNode);
if (selectedIndex > 0)
{
return nodes[selectedIndex - 1];
}
return null;
}
public TreeNode SelectedNode
{
get => _selectedNode;
@ -211,9 +270,12 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
OnBeforeSelect(null);
var hadFocus = false;
// if the current selection (before change) is !null than clear its background color
if (_selectedNode != null)
{
hadFocus = _selectedNode.ContainsFocus;
_selectedNode.HighlightRegion.BackgroundColor = Color.Transparent;
}
@ -234,7 +296,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
_selectedNode.HighlightRegion.BackgroundColor = theme.AccentMimimalOverlay;
}
this.ScrollIntoView(_selectedNode);
this.ScrollIntoView(_selectedNode);//, ScrollAmount.Minimum);
if (hadFocus)
{
_selectedNode?.Focus();
}
OnAfterSelect(null);
}

View file

@ -27,7 +27,6 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Diagnostics;
using System.IO;
@ -114,6 +113,25 @@ namespace MatterHackers.MatterControl.Library.Widgets.HardwarePage
{
var result = JsonConvert.DeserializeObject<ProductSidData>(json);
productDataContainer.RemoveAllChildren();
foreach (var addOn in result.ProductSku.ProductListing.AddOns)
{
WebCache.RetrieveText($"https://mh-pls-prod.appspot.com/p/1/product-sid/{addOn.AddOnSkuReference}?IncludeListingData=True",
(addOnJson) =>
{
var addOnResult = JsonConvert.DeserializeObject<ProductSidData>(addOnJson);
var icon = new ImageBuffer(80, 0);
if (addOnResult?.ProductSku?.FeaturedImage?.ImageUrl != null)
{
WebCache.RetrieveImageAsync(icon, addOnResult.ProductSku.FeaturedImage.ImageUrl, scaleToImageX: true);
}
addOn.Icon = icon;
});
}
CreateProductDataWidgets(result.ProductSku);
});
});
@ -193,18 +211,9 @@ namespace MatterHackers.MatterControl.Library.Widgets.HardwarePage
theme.ApplyBoxStyle(addonsSection);
addonsSection.Margin = addonsSection.Margin.Clone(left: 0);
foreach (var item in product.ProductListing.AddOns)
{
var icon = new ImageBuffer(80, 0);
if (item.FeaturedImage != null)
{
WebCache.RetrieveImageAsync(icon, item.FeaturedImage.ImageUrl, scaleToImageX: true);
}
var addOnRow = new AddOnRow(item.AddOnTitle, theme, null, icon)
var addOnRow = new AddOnRow(item.AddOnTitle, theme, null, item.Icon)
{
HAnchor = HAnchor.Stretch,
Cursor = Cursors.Hand

View file

@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg.Image;
using System.Collections.Generic;
namespace MatterHackers.MatterControl.Library.Widgets.HardwarePage
@ -54,19 +55,20 @@ namespace MatterHackers.MatterControl.Library.Widgets.HardwarePage
public class ProductListing
{
public string ActiveSkuCount { get; set; }
public List<string> ActiveSkus { get; set; }
public List<AddOns> AddOns { get; set; }
}
public class AddOns
{
public string AddOnListingReference { get; set; }
public string AddOnSkuReference { get; set; }
public string AddOnTitle { get; set; }
public FeaturedImage FeaturedImage { get; set; }
public bool ListingIsActive { get; set; }
public int QuantityAvailable { get; set; }
public bool SingleSku { get; set; }
public bool SkuIsActive { get; set; }
public object AddOnListingReference { get; set; }
public ImageBuffer Icon { get; set; } = new ImageBuffer(80, 0);
}
}

@ -1 +1 @@
Subproject commit 17cac6f9ede0580fc446f7c4b0cc48e4ec7349f3
Subproject commit d58cefe19c7d52038b7173c551555e22586480f0

@ -1 +1 @@
Subproject commit 8a78a0dbe0bcd7940a601bb56cbd94eaa8918843
Subproject commit 607eb087a5170d299b8af1ef4161b9cf9843154c