Пример #1
0
        public DataObject MakeDataObject()
        {
            var data = new DataObject();

            data.SetData(typeof(WordListEntries), this);

            var sb = new StringBuilder();

            foreach (var item in Items)
            {
                CsvUtilities.AppendCSVValue(sb, item.Phrase);
                sb.Append(',');
                CsvUtilities.AppendCSVValue(sb, item.Translation);
                sb.AppendLine();
            }
            data.SetText(sb.ToString(), TextDataFormat.CommaSeparatedValue);

            sb.Length = 0;
            foreach (var item in Items)
            {
                sb.Append(item.Phrase).Append(" -- ").AppendLine(item.Translation);
            }
            data.SetText(sb.ToString());

            // TODO: More formats
            return(data);
        }
Пример #2
0
        DataObject MakeDataObjectFromSelection()
        {
            var data = new DataObject();

            var selection = new List <TranslationPair>(GetSelectedTranslationPairs()).ToArray();

            data.SetData(typeof(TranslationPair[]), selection);

            var sb = new StringBuilder();

            // Add CSV formatted data.
            foreach (var sr in selection)
            {
                CsvUtilities.AppendCSVValue(sb, sr.Phrase);
                sb.Append(',');
                CsvUtilities.AppendCSVValue(sb, sr.Translation);
                sb.AppendLine();
            }
            data.SetData(DataFormats.CommaSeparatedValue, sb.ToString());

            // Add plain text representation.
            sb.Length = 0;
            foreach (var sr in selection)
            {
                sb.Append(sr.Phrase).Append(" -- ").AppendLine(sr.Translation);
            }
            data.SetData(DataFormats.UnicodeText, sb.ToString());
            data.SetData(DataFormats.Text, sb.ToString());

            return(data);
        }