Example #1
0
        private static IEnumerable <EmojiCategory> GetAllCategories()
        {
            LUT = new Dictionary <string, EmojiCategory>();

            var match_group    = new Regex(@"^# group: (.*)");
            var match_sequence = new Regex(@"^([0-9A-F ]+[0-9A-F]).*");
            var list           = new List <EmojiCategory>();

            using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("3rdparty.emoji-test.txt"))
                using (StreamReader sr = new StreamReader(s))
                {
                    EmojiCategory last_category = null;
                    string        buffer        = sr.ReadToEnd();
                    foreach (var line in buffer.Split('\r', '\n'))
                    {
                        var m = match_group.Match(line);
                        if (m.Success)
                        {
                            last_category = new EmojiCategory()
                            {
                                Name = m.Groups[1].ToString()
                            };
                            list.Add(last_category);
                        }

                        m = match_sequence.Match(line);
                        if (m.Success)
                        {
                            string value = "";
                            foreach (var codepoint in m.Groups[1].ToString().Split(' '))
                            {
                                value += char.ConvertFromUtf32(Convert.ToInt32(codepoint, 16));
                            }
                            LUT[value] = last_category;

                            // Set icon for this category
                            if (string.IsNullOrEmpty(last_category.Icon))
                            {
                                last_category.Icon = value;
                            }
                        }
                    }
                }

            return(list);
        }
Example #2
0
        private void InitializeComponents()
        {
            var category_lut = new Dictionary <Category, CategoryViewModel>();

            // Fill category list
            foreach (var category in CodepointCategory.AllCategories)
            {
                m_categories.Add(category_lut[category] = new CategoryViewModel(this, category));
            }

            foreach (var category in EmojiCategory.AllCategories)
            {
                m_categories.Add(category_lut[category] = new CategoryViewModel(this, category));
            }

            var macro_viewmodel = new CategoryViewModel(this, new MacroCategory("User Macros"));

            m_categories.Add(macro_viewmodel);

            // Compute a list of sorted codepoint categories for faster lookups
            var sorted_categories = new SortedList <int, CategoryViewModel>();

            foreach (var category in m_categories)
            {
                if (category.RangeEnd > 0)
                {
                    sorted_categories.Add(category.RangeEnd, category);
                }
            }

            // Fill sequence list and assign them a category
            foreach (var desc in Settings.GetSequenceDescriptions())
            {
                CategoryViewModel main_viewmodel = null, emoji_viewmodel = null;

                var emoji_category = EmojiCategory.FromEmojiString(desc.Result);
                if (emoji_category != null)
                {
                    category_lut.TryGetValue(emoji_category, out emoji_viewmodel);
                    emoji_viewmodel.IsEmpty = false;
                }

                // TODO: optimize me
                if (desc.Utf32 != -1)
                {
                    foreach (var kv in sorted_categories)
                    {
                        if (kv.Key >= desc.Utf32)
                        {
                            main_viewmodel         = kv.Value;
                            main_viewmodel.IsEmpty = false;
                            break;
                        }
                    }
                }
                else if (emoji_category == null)
                {
                    macro_viewmodel.IsEmpty = false;
                    main_viewmodel          = macro_viewmodel;
                }

                m_sequences.Add(new SequenceViewModel(desc)
                {
                    Category      = main_viewmodel,
                    EmojiCategory = emoji_viewmodel,
                });
            }

            RefreshCategoryFilters();
            RefreshSequenceFilters();
        }
Example #3
0
        private void InitializeComponents()
        {
            var category_lut = new Dictionary <Category, CategoryViewModel>();

            // Fill the category tree
            m_favorites = new CategoryViewModel(this, new TopCategory(i18n.Text.Favorites + " ⭐"));
            m_categories.Add(m_favorites);

            var all_unicode_vm = new CategoryViewModel(this, new TopCategory(i18n.Text.UnicodeCharacters + " — ŵ Ǿ à Ꝏ Σ ⍾ ꟿ"));

            foreach (var c in CodepointCategory.AllCategories)
            {
                all_unicode_vm.Children.Add(category_lut[c] = new CategoryViewModel(this, c));
            }
            m_categories.Add(all_unicode_vm);

            var all_emoji_vm = new CategoryViewModel(this, new TopCategory(i18n.Text.Emoji + " ☺🍄🐨"));

            foreach (var c in EmojiCategory.AllCategories)
            {
                all_emoji_vm.Children.Add(category_lut[c] = new CategoryViewModel(this, c));
            }
            m_categories.Add(all_emoji_vm);

            m_macros = new CategoryViewModel(this, new TopCategory(i18n.Text.UserMacros + " ( ͡° ͜ʖ ͡°)"));
            m_categories.Add(m_macros);

            // Compute a list of sorted codepoint categories for faster lookups
            var sorted_categories = new SortedList <int, CategoryViewModel>();

            foreach (var category in all_unicode_vm.Children)
            {
                if (category.RangeEnd > 0)
                {
                    sorted_categories.Add(category.RangeEnd, category);
                }
            }

            // Fill sequence list and assign them a category
            foreach (var desc in Settings.GetSequenceDescriptions())
            {
                CategoryViewModel main_viewmodel = null, emoji_viewmodel = null;

                var emoji_category = EmojiCategory.FromEmojiString(desc.Result);
                if (emoji_category != null)
                {
                    category_lut.TryGetValue(emoji_category, out emoji_viewmodel);
                    emoji_viewmodel.IsEmpty = false;
                }

                // TODO: optimize me
                if (desc.Utf32 != -1)
                {
                    foreach (var kv in sorted_categories)
                    {
                        if (kv.Key >= desc.Utf32)
                        {
                            main_viewmodel         = kv.Value;
                            main_viewmodel.IsEmpty = false;
                            break;
                        }
                    }
                }

                m_sequences.Add(new SequenceViewModel(desc)
                {
                    UnicodeCategoryVM = main_viewmodel,
                    EmojiCategoryVM   = emoji_viewmodel,
                });
            }

            RefreshSequenceFilters();
        }