DynamicAppSettingsTabProvider([ImportMany] IEnumerable <Lazy <IDynamicAppSettingsTab, IDynamicAppSettingsTabMetadata> > mefDynTabs, [ImportMany] IEnumerable <Lazy <ISimpleAppOptionProvider, ISimpleAppOptionProviderMetadata> > simpleAppOptionProviders) { this.guidToDynTab = new Dictionary <Guid, DynTab>(); foreach (var dt in mefDynTabs) { if (string.IsNullOrWhiteSpace(dt.Metadata.Title)) { Debug.Fail(string.Format("Missing dyn tab title. Type: {0}", dt.Value.GetType())); continue; } Guid guid; if (!Guid.TryParse(dt.Metadata.Guid, out guid)) { Debug.Fail(string.Format("Could not parse guid: '{0}'", dt.Metadata.Guid)); continue; } DynTab dynTab; if (guidToDynTab.TryGetValue(guid, out dynTab)) { Debug.Assert(dynTab.Order == dt.Metadata.Order && dynTab.Title == dt.Metadata.Title); } else { dynTab = new DynTab { Order = dt.Metadata.Order, Title = ResourceHelper.GetString(dt.Value, dt.Metadata.Title), }; guidToDynTab.Add(guid, dynTab); } } foreach (var mo in simpleAppOptionProviders) { Guid guid; if (!Guid.TryParse(mo.Metadata.Guid, out guid)) { Debug.Fail(string.Format("Could not parse guid: '{0}'", mo.Metadata.Guid)); continue; } DynTab dynTab; if (!guidToDynTab.TryGetValue(guid, out dynTab)) { Debug.Fail(string.Format("Couldn't find a dyn tab with guid {0}", guid)); continue; } dynTab.Providers.Add(mo); } }
DynamicAppSettingsTabCreator([ImportMany] IEnumerable<Lazy<IDynamicAppSettingsTab, IDynamicAppSettingsTabMetadata>> mefDynTabs, [ImportMany] IEnumerable<Lazy<ISimpleAppOptionCreator, ISimpleAppOptionCreatorMetadata>> mefOptions) { this.guidToDynTab = new Dictionary<Guid, DynTab>(); foreach (var dt in mefDynTabs) { if (string.IsNullOrWhiteSpace(dt.Metadata.Title)) { Debug.Fail(string.Format("Missing dyn tab title. Type: {0}", dt.Value.GetType())); continue; } Guid guid; if (!Guid.TryParse(dt.Metadata.Guid, out guid)) { Debug.Fail(string.Format("Could not parse guid: '{0}'", dt.Metadata.Guid)); continue; } DynTab dynTab; if (guidToDynTab.TryGetValue(guid, out dynTab)) Debug.Assert(dynTab.Order == dt.Metadata.Order && dynTab.Title == dt.Metadata.Title); else { dynTab = new DynTab { Order = dt.Metadata.Order, Title = ResourceHelper.GetString(dt.Value, dt.Metadata.Title), }; guidToDynTab.Add(guid, dynTab); } } foreach (var mo in mefOptions) { Guid guid; if (!Guid.TryParse(mo.Metadata.Guid, out guid)) { Debug.Fail(string.Format("Could not parse guid: '{0}'", mo.Metadata.Guid)); continue; } DynTab dynTab; if (!guidToDynTab.TryGetValue(guid, out dynTab)) { Debug.Fail(string.Format("Couldn't find a dyn tab with guid {0}", guid)); continue; } dynTab.Creators.Add(mo); } }
public DynAppSettingsTab(DynTab dt) { this.Order = dt.Order; this.Title = dt.Title; this.options = new List <ISimpleAppOption>(); var grid = new Grid(); grid.Margin = new Thickness(5); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); foreach (var option in dt.Providers.SelectMany(a => a.Value.Create()).OrderBy(a => a.Order)) { var uiObjs = CreateUIElements(option); if (uiObjs == null) { Debug.Fail(string.Format("Couldn't create a dyn option UI object. It must implement ISimpleAppOptionCheckBox, ISimpleAppOptionButton, ISimpleAppOptionTextBox, or ISimpleAppOptionUserContent. Type: {0}", option.GetType())); continue; } Debug.Assert(uiObjs.Length == 1 || uiObjs.Length == 2); switch (uiObjs.Length) { case 1: Grid.SetColumnSpan(uiObjs[0], 2); Grid.SetColumn(uiObjs[0], 0); break; case 2: for (int i = 0; i < uiObjs.Length; i++) { uiObjs[i].ClearValue(Grid.ColumnSpanProperty); Grid.SetColumn(uiObjs[i], i); } break; default: continue; } for (int i = 0; i < uiObjs.Length; i++) { var f = uiObjs[i] as FrameworkElement; if (f == null) { continue; } f.Margin = new Thickness(i > 0 ? 5 : 0, grid.RowDefinitions.Count == 0 ? 0 : 5, 0, 0); } foreach (var o in uiObjs) { Grid.SetRow(o, grid.RowDefinitions.Count); o.ClearValue(Grid.RowSpanProperty); grid.Children.Add(o); } grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); options.Add(option); } this.UIObject = new ScrollViewer { // Disable the horizontal scrollbar since textboxes will grow if the text // doesn't fit and there's a horizontal scrollbar. HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled, VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Content = grid, }; }
IAppSettingsTab Create(DynTab dt) { var tab = new DynAppSettingsTab(dt); return(tab.Count == 0 ? null : tab); }
public DynAppSettingsTab(DynTab dt) { this.order = dt.Order; this.title = dt.Title; this.options = new List<ISimpleAppOption>(); var grid = new Grid(); grid.Margin = new Thickness(5); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); foreach (var option in dt.Creators.SelectMany(a => a.Value.Create()).OrderBy(a => a.Order)) { var uiObjs = CreateUIElements(option); if (uiObjs == null) { Debug.Fail(string.Format("Couldn't create a dyn option UI object. It must implement ISimpleAppOptionCheckBox, ISimpleAppOptionButton, ISimpleAppOptionTextBox, or ISimpleAppOptionUserContent. Type: {0}", option.GetType())); continue; } Debug.Assert(uiObjs.Length == 1 || uiObjs.Length == 2); switch (uiObjs.Length) { case 1: Grid.SetColumnSpan(uiObjs[0], 2); Grid.SetColumn(uiObjs[0], 0); break; case 2: for (int i = 0; i < uiObjs.Length; i++) { uiObjs[i].ClearValue(Grid.ColumnSpanProperty); Grid.SetColumn(uiObjs[i], i); } break; default: continue; } for (int i = 0; i < uiObjs.Length; i++) { var f = uiObjs[i] as FrameworkElement; if (f == null) continue; f.Margin = new Thickness(i > 0 ? 5 : 0, grid.RowDefinitions.Count == 0 ? 0 : 5, 0, 0); } foreach (var o in uiObjs) { Grid.SetRow(o, grid.RowDefinitions.Count); o.ClearValue(Grid.RowSpanProperty); grid.Children.Add(o); } grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); options.Add(option); } this.uiObject = new ScrollViewer { // Disable the horizontal scrollbar since textboxes will grow if the text // doesn't fit and there's a horizontal scrollbar. HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled, VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Content = grid, }; }
IAppSettingsTab Create(DynTab dt) { var tab = new DynAppSettingsTab(dt); return tab.Count == 0 ? null : tab; }