Пример #1
0
        private StandardColumnInfo[] CreateStandardColumns()
        {
            var columns = new[]
            {
                new StandardColumnInfo(Serial, r => true),
                new StandardColumnInfo(Package, r => true),
                new StandardColumnInfo(Asset, r => true),
                new StandardColumnInfo(Id, r => !string.IsNullOrWhiteSpace(r.Id)),
                new StandardColumnInfo(Source, r => true),
                new StandardColumnInfo(Target, r => true),
                new StandardColumnInfo(Asset2, r => !string.IsNullOrWhiteSpace(r.Asset2)),
                new StandardColumnInfo(Id2, r => !string.IsNullOrWhiteSpace(r.Id2)),
                new StandardColumnInfo(Target2, r => !GlossyString.IsNullOrEmpty(r.Target2)),
                new StandardColumnInfo(Notes, r => !string.IsNullOrWhiteSpace(r.Notes)),
                new StandardColumnInfo(TagList, r => true),
            };

#if DEBUG
            if (columns.Length != dataGrid.Columns.Count)
            {
                throw new ApplicationException("Extra DataGridColumn in XAML.");
            }
#endif
            return(columns);
        }
Пример #2
0
        public static void OnGlossyTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = d as GlossyTextBlock;
            var inlines = control.Paragraph.Inlines;

            inlines.Clear();
            var gs = e.NewValue as GlossyString;

            if (!GlossyString.IsNullOrEmpty(gs))
            {
                foreach (var run in gs.AsCollection().Select(GlossyPairToRun).Where(r => r != null))
                {
                    inlines.Add(run);
                }
            }
        }
Пример #3
0
 private StandardColumnInfo[] CreateStandardColumns()
 {
     return(new[]
     {
         new StandardColumnInfo(Serial, r => true),
         new StandardColumnInfo(Asset, r => true),
         new StandardColumnInfo(Id, r => !string.IsNullOrWhiteSpace(r.Id)),
         new StandardColumnInfo(Source, r => true),
         new StandardColumnInfo(Target, r => true),
         new StandardColumnInfo(Asset2, r => !string.IsNullOrWhiteSpace(r.Asset2)),
         new StandardColumnInfo(Id2, r => !string.IsNullOrWhiteSpace(r.Id2)),
         new StandardColumnInfo(Target2, r => !GlossyString.IsNullOrEmpty(r.Target2)),
         new StandardColumnInfo(Notes, r => !string.IsNullOrWhiteSpace(r.Notes)),
         new StandardColumnInfo(TagList, r => true),
     });
 }
Пример #4
0
 public static bool IsNullOrEmpty(GlossyString glossy)
 {
     return(glossy == null || glossy.Pairs.Count == 0);
 }
Пример #5
0
 /// <summary>
 /// Create a frozen copy of a GlossyString.
 /// </summary>
 /// <param name="original"></param>
 public GlossyString(GlossyString original)
 {
     Pairs   = original.Pairs.ToArray();
     _Frozen = true;
 }
Пример #6
0
        public GlossyString GlossyFromInline(InlineString inline, bool ignore_show_specials = false)
        {
            var g = new GlossyString();

            foreach (var rwp in inline.RunsWithProperties)
            {
                Gloss gloss;
                var   prop = rwp.Property;
                if (ShowChanges)
                {
                    switch (prop)
                    {
                    case InlineProperty.None: gloss = Gloss.None; break;

                    case InlineProperty.Ins: gloss = Gloss.INS; break;

                    case InlineProperty.Del: gloss = Gloss.DEL; break;

                    case InlineProperty.Emp: gloss = Gloss.EMP; break;

                    default:
                        throw new ApplicationException("internal error: unknown InlineProperty value in RWP.");
                    }
                }
                else
                {
                    switch (prop)
                    {
                    case InlineProperty.None: gloss = Gloss.None; break;

                    case InlineProperty.Ins: gloss = Gloss.None; break;

                    case InlineProperty.Del: continue;     // XXX

                    case InlineProperty.Emp: gloss = Gloss.EMP; break;

                    default:
                        throw new ApplicationException("internal error: unknown InlineProperty value in RWP.");
                    }
                }

                var run = rwp.Run;
                if (run is InlineText)
                {
                    var str = (run as InlineText).Text;
                    if (!ShowSpecials || ignore_show_specials)
                    {
                        g.Append(str, gloss);
                    }
                    else
                    {
                        int p = 0;
                        for (int q = 0; q < str.Length; q++)
                        {
#if true
                            // The version with SpecialCharChecker.
                            var c = str[q];
                            if (SpecialCharChecker[c % SpecialCharChecker.Length] == c)
                            {
                                if (q > p)
                                {
                                    g.Append(str.Substring(p, q - p), Gloss.None);
                                }
                                g.Append(SpecialCharMapRaw[c], gloss | Gloss.SYM);
                                g.Append(SpecialCharMapAlt[c], gloss | Gloss.ALT);
                                p = q + 1;
                            }
#else
                            // The version without SpecialCharChecker.
                            string special;
                            if (SpecialCharMap.TryGetValue(str[q], out special))
                            {
                                if (q > p)
                                {
                                    g.Append(str.Substring(p, q - p), Gloss.None);
                                }
                                g.Append(SpecialCharMapRaw[c], Gloss.SYM);
                                g.Append(SpecialCharMapAlt[c], Gloss.ALT);
                                p = q + 1;
                            }
#endif
                        }
                        if (p < str.Length)
                        {
                            g.Append(str.Substring(p), gloss);
                        }
                    }
                }
                else if (run is InlineTag)
                {
                    var tag  = (InlineTag)run;
                    var text = tag.ToString((InlineString.Render)TagShowing);
                    if (!string.IsNullOrEmpty(text))
                    {
                        g.Append(text, gloss | Gloss.TAG);
                    }
                }
                else
                {
                    throw new ApplicationException("internal error: unknown type in RWP.Run");
                }
            }
            g.Frozen = true;
            return(g);
        }
Пример #7
0
        public GlossyString GlossyFromInline(InlineString inline, bool ignore_show_specials = false)
        {
            var g = new GlossyString();

            foreach (var run in inline.RunsWithProperties.Where(rwp => rwp.Property != InlineProperty.Del).Select(rwp => rwp.Run))
            {
                if (run is InlineText)
                {
                    var str = (run as InlineText).Text;
                    if (!ShowSpecials || ignore_show_specials)
                    {
                        g.Append(str, Gloss.None);
                    }
                    else
                    {
                        int p = 0;
                        for (int q = 0; q < str.Length; q++)
                        {
#if true
                            // The version with SpecialCharChecker.
                            var c = str[q];
                            if (SpecialCharChecker[c % SpecialCharChecker.Length] == c)
                            {
                                if (q > p)
                                {
                                    g.Append(str.Substring(p, q - p), Gloss.None);
                                }
                                g.Append(SpecialCharMapRaw[c], Gloss.SYM);
                                g.Append(SpecialCharMapAlt[c], Gloss.ALT);
                                p = q + 1;
                            }
#else
                            // The version without SpecialCharChecker.
                            string special;
                            if (SpecialCharMap.TryGetValue(str[q], out special))
                            {
                                if (q > p)
                                {
                                    g.Append(str.Substring(p, q - p), Gloss.None);
                                }
                                g.Append(SpecialCharMapRaw[c], Gloss.SYM);
                                g.Append(SpecialCharMapAlt[c], Gloss.ALT);
                                p = q + 1;
                            }
#endif
                        }
                        if (p < str.Length)
                        {
                            g.Append(str.Substring(p), Gloss.None);
                        }
                    }
                }
                else if (run is InlineTag)
                {
                    var tag = (InlineTag)run;
                    switch (ShowTag)
                    {
                    case TagShowing.None:
                        break;

                    case TagShowing.Name:
                        g.Append(BuildTagString(tag, tag.Number.ToString()), Gloss.TAG);
                        break;

                    case TagShowing.Disp:
                        g.Append(Enclose(tag.Display) ?? BuildTagString(tag, tag.Name), Gloss.TAG);
                        break;

                    case TagShowing.Code:
                        g.Append(tag.Code ?? BuildTagString(tag, "*"), Gloss.TAG);
                        break;

                    default:
                        throw new ApplicationException("internal error");
                    }
                }
                else
                {
                    throw new ApplicationException("internal error");
                }
            }
            g.Frozen = true;
            return(g);
        }