Put in an UnloadLinkAttribute for use on locked content

This commit is contained in:
Lars Brubaker 2018-02-26 15:28:00 -08:00
parent ec2271a108
commit ffd6a0ce5e
3 changed files with 35 additions and 1 deletions

View file

@ -70,6 +70,18 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
[AttributeUsage(AttributeTargets.Class)]
public class UnlockLinkAttribute : Attribute
{
public static string DetailPageBaseUrl => "https://www.matterhackers.com/store/l/";
public string DetailsPageLink { get; private set; }
public UnlockLinkAttribute(string detailsPageLink)
{
DetailsPageLink = detailsPageLink;
}
}
public class PublicPropertyEditor : IObject3DEditor
{
private IObject3D item;
@ -173,6 +185,8 @@ namespace MatterHackers.MatterControl.DesignTools
PropertyInfo = p
});
AddUnlockLinkIfRequired(editControlsContainer, theme);
GuiWidget rowContainer = null;
foreach (var property in editableProperties)
{
@ -454,6 +468,26 @@ namespace MatterHackers.MatterControl.DesignTools
propertyGridModifier?.UpdateControls(this);
}
private void AddUnlockLinkIfRequired(FlowLayoutWidget editControlsContainer, ThemeConfig theme)
{
var unlockLink = item.GetType().GetCustomAttributes(typeof(UnlockLinkAttribute), true).FirstOrDefault() as UnlockLinkAttribute;
if (unlockLink != null
&& !string.IsNullOrEmpty(unlockLink.DetailsPageLink)
&& !item.Persistable)
{
var row = CreateSettingsRow(item.Persistable ? "Registerd" : "Demo Mode");
Button detailsLink = theme.ButtonFactory.Generate("Unlock".Localize(), AggContext.StaticData.LoadIcon("locked.png", 16, 16));
detailsLink.BackgroundColor = theme.Colors.PrimaryAccentColor.AdjustContrast(theme.Colors.PrimaryTextColor, 8).ToColor();
detailsLink.Margin = new BorderDouble(5);
detailsLink.Click += (s, e) =>
{
ApplicationController.Instance.LaunchBrowser(UnlockLinkAttribute.DetailPageBaseUrl + unlockLink.DetailsPageLink);
};
row.AddChild(detailsLink);
editControlsContainer.AddChild(row);
}
}
private GuiWidget CreateEnumEditor(IRebuildable item,
PropertyInfo propertyInfo, Type propertyType, object value, string displayName,
ThemeConfig theme)