public AlreadySelectedException(IOptionGroup group, IOption option, IOption selected) : this("The option '" + option.Key() + "' was specified but an option from this group " + "has already been selected: '" + selected.Key() + "'") { OptionGroup = group; Option = option; SelectedOption = selected; }
/// <summary> /// Creates a <seealso cref="DataTable"/>. /// and adds corresponding column definitions. /// </summary> /// <param name="tableSchema"></param> /// <returns></returns> private static DataTable CreateTable(IOptionGroup tableSchema) { DataTable dataTable = new DataTable(tableSchema.Name); foreach (var item in tableSchema.GetOptionDefinitions()) { DataColumn col = new DataColumn(item.OptionName, (item.TypeOfValue == typeof(SecureString) ? typeof(string) : item.TypeOfValue)); col.AllowDBNull = item.IsOptional; dataTable.Columns.Add(col); } return(dataTable); }
/// <summary> /// Save changed settings back to model for further /// application and persistence in file system. /// </summary> /// <param name="settingData"></param> private void SaveOptionsToModel(IOptionGroup optionsOptionGroup) { var schema = optionsOptionGroup.GetOptionDefinition("BookmarkedFolders"); schema.List_Clear(); if (Bookmarks.Count > 0) { foreach (var item in Bookmarks) { schema.List_AddValue(item, item); } } }
/// <summary> /// Reset the view model to those options that are going to be presented for editing. /// </summary> /// <param name="settingData"></param> internal static void LoadOptionsFromModel(IOptionGroup optGroup, IList collection) { var opt = optGroup.GetOptionDefinition("BookmarkedFolders"); foreach (var item in opt.List_GetListOfKeyValues()) { string sValue = item.Value as string; if (sValue != null) { collection.Add(sValue); } } }
/// <summary> /// Reset the view model to those options that are going to be presented for editing. /// </summary> /// <param name="settingData"></param> private void LoadOptionsFromModel(IOptionGroup optGroup) { SecureString securePassword = optGroup.GetValue <SecureString>("MSTranslate.TranslationServicePassword"); SecureString secureUser = optGroup.GetValue <SecureString>("MSTranslate.TranslationServiceUser"); mReloadFilesOnAppStart = optGroup.GetValue <bool>("ReloadOpenFilesFromLastSession"); mMSTranslateService = new TranslationService ( optGroup.GetValue <string>("MSTranslate.TranslationServiceUri"), secureUser, securePassword ); var settings = GetService <ISettingsManager>(); // Initialize localization settings Languages = new List <LanguageCollection>(settings.GetSupportedLanguages()); // Set default language to make sure app neutral is selected and available for sure // (this is a fallback if all else fails) try { var langOpt = optGroup.GetValue <string>("LanguageSelected"); LanguageSelected = Languages.FirstOrDefault(lang => lang.BCP47 == langOpt); if (LanguageSelected == null) { LanguageSelected = Languages[0]; } } catch { } var service = GetService <ITranslator>(); DefaultSourceLanguageSelected = GetLanguageOptionFromModel(service, optGroup, "DefaultSourceLanguage", "DefaultSourceLanguage", 0); DefaultTargetLanguageSelected = GetLanguageOptionFromModel(service, optGroup, "DefaultTargetLanguage", "DefaultTargetLanguage", 1); // get copy of actual value and min, max value definitions from model into viewmodel IconSize = optGroup.GetValue <int>("DefaultIconSize"); IconSizeMax = settings.IconSizeMax; IconSizeMin = settings.IconSizeMin; ColorGridOption = optGroup.GetValue <bool>("ColorGridOption"); AlternatingColor = optGroup.GetValue <Color>("AlternatingGridColor"); }
public virtual void Dispose() { GetOptionHandler().Dispose(delegateItem, this); if (delegateItem != null) { if (listener != null) { listener.Disconnect(delegateItem); listener = null; } delegateItem = null; lookup = null; dictionaryOverride = null; group = null; } }
internal ChildBuilderContext(IOptionBuilderContext context, string prefix, string groupName, ISelectionProvider <T> selectionProvider) { IOptionGroup group = context.Lookup <IOptionGroup>(); if (group != null && groupName != string.Empty) { group.Items.Add(this.parentGroup = new OptionGroup(groupName)); } else { this.parentGroup = group; } this.parent = context; this.propertyPrefix = CreatePrefix(prefix, groupName); this.selectionProvider = selectionProvider; }
private void AssertNotSelected(IOptionGroup group, IOption option) { IOption selectedOption; if (groupSelectedOptions.TryGetValue(group, out selectedOption)) { if (!selectedOption.Key().Equals(option.Key())) { throw new AlreadySelectedException(group, option, selectedOption); } } else { groupSelectedOptions[group] = option; } }
protected void ProcessOption(IOptions options, string arg, string[] tokens, ref int index) { bool hasOption = options.HasOption(arg); // if there is no option throw an UnrecognisedOptionException if (!hasOption) { throw new UnrecognizedOptionException("Unrecognized option: " + arg, arg); } // get the option represented by arg OptionValue opt = new OptionValue(options.GetOption(arg)); // if the option is a required option remove the option from // the requiredOptions list if (opt.Option.IsRequired) { options.RequiredOptions.Remove(opt.Option.Key()); } // if the option is in an OptionGroup make that option the selected // option of the group if (options.GetOptionGroup(opt.Option) != null) { IOptionGroup group = options.GetOptionGroup(opt.Option); if (group.IsRequired) { foreach (var option in group.Options) { options.RequiredOptions.Remove(option.Key()); } } // group.SetSelected(opt.Option); AssertNotSelected(group, opt.Option); } // if the option takes an argument value if (opt.Option.HasArgument()) { ProcessArguments(options, opt, tokens, ref index); } // set the option on the command line cmd.AddOption(opt); }
/// <summary> /// Retrieve an <see cref="IOptionItem"/> instance from nested groups. /// </summary> /// <remarks>Path elements are seperated by dots</remarks> /// <param name="itemPath"></param> /// <returns></returns> public IOptionItem GetItemByName(string itemPath) { IOptionGroup item = this; string[] pathArray = itemPath.Split('.'); for (int i = 0; i < pathArray.Length - 1; i++) { string s = pathArray[i]; item = item[s] as IOptionGroup; if (item == null) { return(null); } } //last step... return(item[pathArray[pathArray.Length - 1]]); }
/// <summary> /// Called when the <see cref="View">view</see> changed. /// </summary> /// <param name="oldView">The old view.</param> /// <param name="newView">The new view.</param> protected virtual void OnViewChanged(IModelView oldView, IModelView newView) { if (view != null) { SetValue(RootItemProperty, null); } this.view = newView; if (this.view != null) { view.IsAutoAdopt = IsAutoAdopt; view.IsAutoCommit = IsAutoCommit; IOptionGroup item = view.GetViewItem(view.Handler) as IOptionGroup; SetValue(RootItemProperty, item); } else { SetValue(RootItemProperty, null); } }
/// <inheritdoc/> public virtual void AddItems(IOptionBuilderContext context, Type subjectType, object subject) { DefaultBrushOptionBuilder brushOptionBuilder = new DefaultBrushOptionBuilder(); brushOptionBuilder.AllowNullValue = AllowNullValue; brushOptionBuilder.AddItems(context, typeof(Brush), null); FloatOptionItem widthItem = new FloatOptionItem(DefaultPenPropertyMapBuilder.Width); bool widthItemAdded = context.BindItem(widthItem, DefaultPenPropertyMapBuilder.Width); GenericOptionItem <DashStyle> dashStyleItem = new GenericOptionItem <DashStyle>(DefaultPenPropertyMapBuilder.DashStyle, OptionItem.VALUE_UNDEFINED); dashStyleItem.SetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE, true); dashStyleItem.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false); // dashStyleItem.SetAttribute(OptionItem.CUSTOM_TABLEITEM_EDITOR, typeof(PenDashStyleUITypeEditor)); EnumUITypeEditor <DashStyle> editor = new EnumUITypeEditor <DashStyle>(); editor.Renderer = new DashStyleItemRenderer(); dashStyleItem.SetAttribute(OptionItem.CUSTOM_TABLEITEM_EDITOR, editor); // dashStyleItem.SetAttribute(OptionItem.CUSTOM_CELLRENDERER, typeof(DashStyleItemRenderer)); bool dashStyleItemAdded = context.BindItem(dashStyleItem, DefaultPenPropertyMapBuilder.DashStyle); IOptionGroup parent = context.Lookup <IOptionGroup>(); if (parent != null) { IOptionItem fillTypeItem = parent[DefaultBrushPropertyMapBuilder.FillType]; ConstraintManager cm = parent.Lookup <ConstraintManager>(); if (cm != null && fillTypeItem != null) { ICondition cond = ConstraintManager.LogicalCondition.Not(cm.CreateValueEqualsCondition(fillTypeItem, null)); if (widthItemAdded) { cm.SetEnabledOnCondition(cond, widthItem); } if (dashStyleItemAdded) { cm.SetEnabledOnCondition(cond, dashStyleItem); } } } }
/// <summary> /// Save changed settings back to model for further /// application and persistence in file system. /// </summary> /// <param name="settingData"></param> private void SaveOptionsToModel(IOptionGroup optionsOptionGroup) { var loginData = MSTranslateGetData(); optionsOptionGroup.SetValue("MSTranslate.TranslationServiceUri", loginData.TranslationServiceUri); optionsOptionGroup.SetValue("MSTranslate.TranslationServiceUser", loginData.TranslationServiceUser); optionsOptionGroup.SetValue("MSTranslate.TranslationServicePassword", loginData.TranslationServicePassword); optionsOptionGroup.SetValue("ReloadOpenFilesFromLastSession", ReloadFilesOnAppStart); optionsOptionGroup.SetValue("LanguageSelected", LanguageSelected.BCP47); optionsOptionGroup.SetValue("DefaultSourceLanguage", DefaultSourceLanguageSelected.Bcp47_LangCode); optionsOptionGroup.SetValue("DefaultTargetLanguage", DefaultTargetLanguageSelected.Bcp47_LangCode); optionsOptionGroup.SetValue("DefaultIconSize", (int)IconSize); optionsOptionGroup.SetValue("ColorGridOption", (bool)ColorGridOption); optionsOptionGroup.SetValue("AlternatingGridColor", AlternatingColor); }
internal static bool SaveBookmarksToModel(IEnumerable <IFSItemViewModel> collection, IOptionGroup optionsOptionGroup) { var schema = optionsOptionGroup.GetOptionDefinition("BookmarkedFolders"); bool listsAreEqual = true; int iCount = 0; foreach (var item in collection) { object val; if (schema.List_TryGetValue(item.FullPath, out val) == false) { listsAreEqual = false; break; } iCount++; } if (listsAreEqual == true) { if (iCount == collection.Count()) { return(false); } } // Clear list and copy all values since they differ schema.List_Clear(); foreach (var item in collection) { schema.List_AddValue(item.FullPath, item.FullPath); } optionsOptionGroup.SetUndirty(true); return(true); }
/// <summary> /// Save changed settings back to model for further /// application and persistence in file system. /// </summary> /// <param name="settingData"></param> public void SaveOptionsToModel(IOptionGroup optGroup) { optGroup.SetValue("ReloadOpenFilesFromLastSession", ReloadFilesOnAppStart); if (LanguageSelected != null) { optGroup.SetValue("LanguageSelected", LanguageSelected.BCP47); } var opt = optGroup.GetOptionDefinition("BookmarkedFolders"); optGroup.List_Clear("BookmarkedFolders"); if (Bookmarks.Count > 0) { var schema = optGroup.GetOptionDefinition("BookmarkedFolders"); foreach (var item in Bookmarks) { schema.List_AddValue(item, item); } } }
/// <summary> /// Creates a unique id-able name for list items that are indirectly attached to OptionsGroups /// but are physically stored in their own table (to enable storage of multiple values in XML). /// </summary> /// <param name="optionsGroup"></param> /// <param name="optionSchema"></param> /// <returns></returns> private string CreateListItemTableName(IOptionGroup optionsGroup, IOptionsSchema optionSchema) { return("${" + optionsGroup.Name + "}${" + optionSchema.OptionName + "}"); }
/// <inheritdoc /> public void Add(IOptionGroup group) { throw new NotImplementedException(); }
internal static bool BindItemHelper(IOptionItem item, string virtualPropertyName, IOptionGroup group, ISelectionProvider <T> selectionProvider, string prefix, bool addToOptionHandler) { bool retval = false; IOptionItemFilter <T> filter = item.Lookup <IOptionItemFilter <T> >(); string finalName = DefaultOptionBuilderContext <object> .CreatePrefix(prefix, virtualPropertyName); OptionItemValidities validities; if (filter == null) { validities = CheckValidity(new DefaultOptionItemFilter <T>(finalName), selectionProvider); } else { validities = CheckValidity(new DefaultOptionItemFilter <T>(finalName), selectionProvider) & CheckValidity(filter, selectionProvider); } if (validities != OptionItemValidities.Invalid) { CompositeHandler <T> .Create(selectionProvider, finalName, item); if (addToOptionHandler) { group.Items.Add(item); } retval = true; if (validities != OptionItemValidities.ReadWrite) { item.Enabled = false; } } return(retval); }
public static object GetValue(this IOptionGroup group, string groupName, string itemName) { return(((IOptionGroup)GetItemByName(group, groupName)).GetItemByName(itemName).Value); }
public static IOptionGroup GetGroupByName(this IOptionGroup group, string groupName) { return((IOptionGroup)group.Items.FirstOrDefault(item => item is IOptionGroup && item.Name == groupName)); }
public WeakGroupListener(CopiedOptionGroup group, IOptionGroup optionGroup) { this.reference = new WeakReference(group); optionGroup.Items.CollectionChanged += new NotifyCollectionChangedEventHandler(Items_CollectionChanged); }
public void Disconnect(IOptionGroup item) { item.Items.CollectionChanged -= Items_CollectionChanged; }
IOptions IOptions.AddOptionGroup(IOptionGroup group) { return(AddOptionGroup((OptionGroup)group)); }
public CopiedOptionGroup(IOptionGroup delegateItem, IOptionGroup group) : base(delegateItem, group) { Init(delegateItem); }
/// <inheritdoc /> public void Add(IOptionGroup group) { _groups.Add(group); }
private void AssertNotSelected(IOptionGroup group, IOption option) { IOption selectedOption; if (groupSelectedOptions.TryGetValue(group, out selectedOption)) { if (!selectedOption.Key().Equals(option.Key())) throw new AlreadySelectedException(group, option, selectedOption); } else { groupSelectedOptions[group] = option; } }
IOptions IOptions.AddOptionGroup(IOptionGroup group) { return AddOptionGroup((OptionGroup) group); }
public static IEnumerable <string> Names(this IOptionGroup group) { return(group.Options.Select(x => x.Name)); }
private void UpdateStyle(Type newValue) { Style style = null; if (Item != null) { object o = Item.Attributes[OptionItem.CustomDialogitemEditor]; if (o != null) { if (o is string || o is ResourceKey) { var controlTemplate = this.TryFindResource(o) as Style; if (controlTemplate != null) { style = controlTemplate; } } else if (o is Style) { style = (Style)o; } } } if (style == null) { while (style == null && newValue != null) { string fullName = GetFullName(newValue); if (Item is IOptionGroup) { int level = 0; IOptionGroup group = (IOptionGroup)Item; // determine if group consists of groups, only bool justGroups = group.Items.All(optionItem => (optionItem is IOptionGroup)); while (group != null) { group = group.Owner; level++; } if (!justGroups && level == 1) { level = 2; } if (((IOptionGroup)Item).Items.Count == 1) { //Discard invisible groups with only one child IOptionItem singleChild = ((IOptionGroup)Item).Items[0]; var hintAttr = singleChild.Attributes[DefaultEditorFactory.RenderingHintsAttribute]; if (hintAttr is DefaultEditorFactory.RenderingHints && (DefaultEditorFactory.RenderingHints)hintAttr == DefaultEditorFactory.RenderingHints.Invisible) { style = this.TryFindResource("EmptyGroup.OptionItemPresenter") as Style; } } if (style == null) { style = this.TryFindResource(fullName + ".Level" + level + ".OptionGroup.OptionItemPresenter") as Style; if (style == null) { style = this.TryFindResource(fullName + ".OptionGroup.OptionItemPresenter") as Style; } if (style == null) { style = this.TryFindResource("OptionGroup.Level" + level + ".OptionItemPresenter") as Style; if (style == null) { style = this.TryFindResource("OptionGroup.OptionItemPresenter") as Style; } } } } else { style = this.TryFindResource(fullName + ".OptionItemPresenter") as Style; } newValue = newValue.BaseType; } if (style == null) { style = this.TryFindResource(ItemType.FullName + ".OptionItemPresenter") as Style; if (style == null) { style = this.TryFindResource("OptionItemPresenter") as Style; } } } if (style != null) { this.Style = style; } }