Пример #1
0
        /// <summary>
        /// Fire command for label index (in <see cref="lblColl"/>).
        /// </summary>
        private void fire(int ix)
        {
            // Prepare plain text for clipboard, and optionally (for formatted full entry), also html.
            string plainText = "text";
            string html      = null;
            // Our plain text options
            Label lbl = lblColl[ix];

            if (lbl == lblHanzi1)
            {
                plainText = script == SearchScript.Traditional ? entry.ChTrad : entry.ChSimpl;
            }
            else if (lbl == lblHanzi2)
            {
                plainText = entry.ChTrad;
            }
            else if (lbl == lblPinyin)
            {
                plainText = CedictFormatter.GetPinyinString(entry.GetPinyinForDisplay(true));
            }
            else if (lbl == lblFullCedict)
            {
                plainText = CedictFormatter.GetCedict(entry);
            }
            else if (lbl == lblFullFormatted)
            {
                html      = CedictFormatter.GetHtml(tprov, entry, script);
                plainText = CedictFormatter.StripPlainFromHtml(html);
            }
            else if (lbl == lblSense)
            {
                html      = CedictFormatter.GetSenseHtml(entry.GetSenseAt(senseIx), script);
                plainText = CedictFormatter.StripPlainFromHtml(html);
            }

            // Copy to clipboard: plain text
            if (html == null)
            {
                Clipboard.SetText(plainText);
            }
            // Copy to clipboard: formatted HTML
            else
            {
                ClipboardHelper.CopyToClipboard(html, plainText);
            }

            // TO-DO:
            // - Sense (after updating getSense to mind single search script)
            // !!!
            // - Sense ID hover behavior in OneResultControl, sense ID passed to context menu

            // Let parent control know that command has been triggered: time to close context menu.
            cmdTriggered(this);
        }
Пример #2
0
        /// <summary>
        /// Gets display strings by combining entry, sense index, and localized strings.
        /// </summary>
        private void getDisplayStrings(ITextProvider tprov, int senseIx,
                                       out string fullFormatted, out string fullCedict,
                                       out string hanzi1, out string hanzi2, out string pinyin, out string sense)
        {
            fullFormatted = tprov.GetString("CtxtCopyEntryFormatted");
            fullCedict    = tprov.GetString("CtxtCopyEntryCedict");
            pinyin        = tprov.GetString("CtxtCopyPinyin");
            string pinyinVal = CedictFormatter.GetPinyinString(entry.GetPinyinForDisplay(true), Magic.CtxtMenuMaxSyllableLength);

            pinyin = string.Format(pinyin, pinyinVal);
            sense  = null;
            hanzi1 = null;
            hanzi2 = null;
            if (script == SearchScript.Simplified || script == SearchScript.Traditional || entry.ChSimpl == entry.ChTrad)
            {
                hanzi1 = tprov.GetString("CtxtCopyHanzi");
                string hanzi1Val = script == SearchScript.Traditional ? entry.ChTrad : entry.ChSimpl;
                hanzi1Val = ellipse(hanzi1Val, Magic.CtxtMenuMaxSyllableLength);
                hanzi1    = string.Format(hanzi1, hanzi1Val);
            }
            else
            {
                hanzi1 = tprov.GetString("CtxtCopySimplified");
                string hanzi1Val = ellipse(entry.ChSimpl, Magic.CtxtMenuMaxSyllableLength);
                hanzi1 = string.Format(hanzi1, hanzi1Val);
                hanzi2 = tprov.GetString("CtxtCopyTraditional");
                string hanzi2Val = ellipse(entry.ChTrad, Magic.CtxtMenuMaxSyllableLength);
                hanzi2 = string.Format(hanzi2, hanzi2Val);
            }
            if (senseIx != -1)
            {
                sense = tprov.GetString("CtxtCopySense");
                string senseVal = getSense(senseIx);
                senseVal = ellipse(senseVal, Magic.CtxtMenuMaxSenseLength);
                sense    = string.Format(sense, senseVal);
            }
        }