public static Control GetControlForProperty(PluginSettingStore store, PropertyInfo property) { var attr = property.GetCustomAttribute <PropertyAttribute>(); PluginSetting setting = store[property]; if (setting == null) { setting = new PluginSetting(property, null); store.Settings.Add(setting); } var settingBinding = new DelegateBinding <PluginSetting>( () => store[property], (v) => store[property] = v ); var control = GetControlForSetting(property, settingBinding); if (control != null) { // Apply all visual modifier attributes foreach (ModifierAttribute modifierAttr in property.GetCustomAttributes <ModifierAttribute>()) { control = ApplyModifierAttribute(control, modifierAttr); } control.Width = 400; return(new Group(attr.DisplayName ?? property.Name, control, Orientation.Horizontal, false)); } else { throw new NullReferenceException($"{nameof(control)} is null. This is likely due to {property.PropertyType.Name} being an unsupported type."); } }
public MetadataViewer() { actions = new StackLayout { Orientation = Orientation.Horizontal, Spacing = 5, Items = { new StackLayoutItem { Expand = true, Control = uninstallButton = new Button(UninstallHandler) { Text = "Uninstall" } }, new StackLayoutItem { Expand = true, Control = installButton = new Button(InstallHandler) } } }; var installedBinding = new DelegateBinding <bool>( () => { var contexts = AppInfo.PluginManager.GetLoadedPlugins(); return(contexts.Any(t => PluginMetadata.Match(t.GetMetadata(), Metadata))); }, addChangeEvent: (e) => MetadataChanged += e, removeChangeEvent: (e) => MetadataChanged -= e ); var updateableBinding = new DelegateBinding <bool>( () => { var repo = PluginMetadataList.Repository; if (repo == null) { return(false); } var updatableFromRepository = from meta in repo where PluginMetadata.Match(meta, Metadata) where meta.PluginVersion > Metadata.PluginVersion where CurrentDriverVersion >= meta.SupportedDriverVersion orderby meta.PluginVersion descending select meta; return(updatableFromRepository.Any()); }, addChangeEvent: (e) => MetadataChanged += e, removeChangeEvent: (e) => MetadataChanged -= e ); var installableBinding = new DelegateBinding <bool>( () => updateableBinding.GetValue() || !installedBinding.GetValue(), addChangeEvent: (e) => MetadataChanged += e, removeChangeEvent: (e) => MetadataChanged += e ); uninstallButton.GetEnabledBinding().Bind(installedBinding); installButton.TextBinding.Bind(updateableBinding.Convert(c => c ? "Update" : "Install")); installButton.GetEnabledBinding().Bind(installableBinding); content = new Scrollable { Content = new StackLayout { Padding = 5, Spacing = 5, HorizontalContentAlignment = HorizontalAlignment.Stretch, Items = { new AlignedGroup { Text = "Name", Content = name = new Label() }, new AlignedGroup { Text = "Owner", Content = owner = new Label() }, new AlignedGroup { Text = "Description", Content = description = new Label { Wrap = WrapMode.Word } }, new AlignedGroup { Text = "Driver Version", Content = driverVersion = new Label() }, new AlignedGroup { Text = "Plugin Version", Content = pluginVersion = new Label() }, new AlignedGroup { Text = "Source Code Repository", Content = sourceCode = new Button { Width = 175, Text = "Show source code" } }, new AlignedGroup { Text = "Wiki", Content = wiki = new Button { Width = 175, Text = "Show plugin wiki" } }, new AlignedGroup { Text = "License", Content = license = new Label() }, new StackLayoutItem(null, true), actions } } }; name.TextBinding.Bind(MetadataBinding.Child(c => c.Name)); owner.TextBinding.Bind(MetadataBinding.Child(c => c.Owner)); description.TextBinding.Bind(MetadataBinding.Child(c => c.Description)); driverVersion.TextBinding.Bind(MetadataBinding.Child(c => c.SupportedDriverVersion).Convert(v => v?.ToString())); pluginVersion.TextBinding.Bind(MetadataBinding.Child(c => c.PluginVersion).Convert(v => v?.ToString())); license.TextBinding.Bind(MetadataBinding.Child(c => c.LicenseIdentifier)); sourceCode.GetEnabledBinding().Bind(MetadataBinding.Child(c => c.RepositoryUrl).Convert(c => c != null)); sourceCode.Click += (sender, e) => DesktopInterop.Open(Metadata.RepositoryUrl); wiki.GetEnabledBinding().Bind(MetadataBinding.Child(c => c.WikiUrl).Convert(c => c != null)); wiki.Click += (sender, e) => DesktopInterop.Open(Metadata.WikiUrl); AppInfo.PluginManager.AssembliesChanged += HandleAssembliesChanged; }