Exemplo n.º 1
0
        public void InitializeOptions(string groupName, HexViewGroupOptionCollection collection)
        {
            if (groupName == null)
            {
                throw new ArgumentNullException(nameof(groupName));
            }
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            ISettingsSection ctSect;

            if (!toSubGroupSection.TryGetValue(new SubGroupKey(groupName, collection.SubGroup), out ctSect))
            {
                return;
            }

            var toOption = new Dictionary <string, HexViewGroupOption>(StringComparer.Ordinal);

            foreach (var option in collection.Options)
            {
                toOption[option.OptionId] = option;
            }

            foreach (var sect in ctSect.SectionsWithName(OptionName))
            {
                var name = sect.Attribute <string>(OptionNameAttr);
                if (name == null)
                {
                    continue;
                }

                var textValue = sect.Attribute <string>(OptionValueAttr);
                if (textValue == null)
                {
                    continue;
                }

                HexViewGroupOption option;
                if (!toOption.TryGetValue(name, out option))
                {
                    continue;
                }
                if (!option.Definition.CanBeSaved)
                {
                    continue;
                }

                object value;
                if (!TryGetValue(option, textValue, out value))
                {
                    continue;
                }

                option.Value = value;
            }
        }
Exemplo n.º 2
0
        public HexViewOptionsGroupImpl(HexViewOptionsGroupServiceImpl owner, string groupName, TagOptionDefinition[] defaultOptions, OptionsStorage optionsStorage)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }
            if (groupName == null)
            {
                throw new ArgumentNullException(nameof(groupName));
            }
            if (defaultOptions == null)
            {
                throw new ArgumentNullException(nameof(defaultOptions));
            }
            if (optionsStorage == null)
            {
                throw new ArgumentNullException(nameof(optionsStorage));
            }
            this.owner     = owner;
            hexViews       = new List <WpfHexView>();
            toOptions      = new Dictionary <string, HexViewGroupOptionCollection>(StringComparer.OrdinalIgnoreCase);
            this.groupName = groupName;

            foreach (var option in defaultOptions)
            {
                Debug.Assert(option.Name != null);
                if (option.Name == null)
                {
                    continue;
                }

                var subGroup = option.SubGroup;
                Debug.Assert(subGroup != null);
                if (subGroup == null)
                {
                    continue;
                }

                HexViewGroupOptionCollection coll;
                if (!toOptions.TryGetValue(subGroup, out coll))
                {
                    toOptions.Add(subGroup, coll = new HexViewGroupOptionCollection(subGroup));
                }
                coll.Add(new HexViewGroupOption(this, option));
            }

            foreach (var coll in toOptions.Values)
            {
                optionsStorage.InitializeOptions(groupName, coll);
            }
            this.optionsStorage = optionsStorage;
        }