private static void RebuildDisplayIfNeed(DictionaryGUIState state, Inspector.Options options)
        {
            if (state.display == null ||
                Event.current.type == EventType.Layout && (state.searchInput.changed || IsKeyChanged(state, options) ||
                                                           state.display.bucketSize != options.listBucketSize ||
                                                           state.display.sort != options.sortFields))
            {
                var display = new DictionaryDisplay();
                display.keys       = state.Keys(options);
                display.bucketSize = options.listBucketSize;
                display.sort       = options.sortFields;

                if (!string.IsNullOrEmpty(state.searchInput.text))
                {
                    display.resultKeys = FilterKeys(display.keys, state.searchInput);
                }
                else
                {
                    display.resultKeys = display.keys;
                }

                if (options.sortFields)
                {
                    display.resultKeys = Sorted(display.resultKeys);
                }
                state.display = display;
            }
        }
Exemplo n.º 2
0
        // Umbraco.Code.MapAll -Icon -Trashed -Alias
        private void Map(IDictionaryItem source, DictionaryDisplay target, MapperContext context)
        {
            target.Id       = source.Id;
            target.Key      = source.Key;
            target.Name     = source.ItemKey;
            target.ParentId = source.ParentId ?? Guid.Empty;
            target.Udi      = Udi.Create(Constants.UdiEntityType.DictionaryItem, source.Key);
            if (_commonMapper != null)
            {
                target.ContentApps.AddRange(_commonMapper.GetContentAppsForEntity(source));
            }

            // build up the path to make it possible to set active item in tree
            // TODO: check if there is a better way
            if (source.ParentId.HasValue)
            {
                var ids = new List <int> {
                    -1
                };
                var parentIds = new List <int>();
                GetParentId(source.ParentId.Value, _localizationService, parentIds);
                parentIds.Reverse();
                ids.AddRange(parentIds);
                ids.Add(source.Id);
                target.Path = string.Join(",", ids);
            }
            else
            {
                target.Path = "-1," + source.Id;
            }

            // add all languages and  the translations
            foreach (var lang in _localizationService.GetAllLanguages())
            {
                var langId      = lang.Id;
                var translation = source.Translations.FirstOrDefault(x => x.LanguageId == langId);

                target.Translations.Add(new DictionaryTranslationDisplay
                {
                    IsoCode     = lang.IsoCode,
                    DisplayName = lang.CultureInfo.DisplayName,
                    Translation = (translation != null) ? translation.Value : string.Empty,
                    LanguageId  = lang.Id
                });
            }
        }