Exemplo n.º 1
0
        protected virtual void SetTargetValue(string s)
        {
            _pendingValueChange = null;

            Debug.Assert(_dataTarget != null, "Perhaps the binding was already torn down?");
            if (_inMidstOfChange)
            {
                return;
            }

            try
            {
                _inMidstOfChange = true;

                if (_dataTarget is MultiText)
                {
                    MultiText text = (MultiText)_dataTarget;
                    text[_writingSystemId] = s;
                }
                //else if (_dataTarget as IBindingList != null)
                //{
                //    IBindingList list = _dataTarget as IBindingList;
                //    //in addition to add a menu item, this will fire events on the object that owns the list
                //    list.AddNew();
                //}
                else
                {
                    throw new ArgumentException("Binding doesn't understand that type of target.");
                }
            }
            finally
            {
                _inMidstOfChange = false;
            }
        }
Exemplo n.º 2
0
        public void ConvertLiftStringToSimpleStringWithMarkers_TextWithNoSpan()
        {
            LiftString liftStringToConvert = new LiftString("No Markers Here!");
            string     convertedString     = MultiText.ConvertLiftStringToSimpleStringWithMarkers(liftStringToConvert);

            Assert.AreEqual("No Markers Here!", convertedString);
        }
Exemplo n.º 3
0
		public LexExampleSentence(WeSayDataObject parent): base(parent)
		{
			_sentence = new MultiText(this);
			_translation = new MultiText(this);

			WireUpEvents();
		}
Exemplo n.º 4
0
 private void WriteEmbeddedXmlCollection(MultiText text)
 {
     foreach (string rawXml in text.EmbeddedXmlElements)             // todo cp Promote roundtripping to Palaso.Lift / Palaso.Data also then can use MultiTextBase here (or a better interface).
     {
         Writer.WriteRaw(rawXml);
     }
 }
Exemplo n.º 5
0
        public void Equals_Null_False()
        {
            var x = new MultiText();

            x["ws"] = "test";
            Assert.IsFalse(x.Equals(null));
        }
Exemplo n.º 6
0
 private void WriteMultiTextNoWrapper(string propertyName, MultiText text)         // review cp see WriteEmbeddedXmlCollection
 {
     if (!MultiTextBase.IsEmpty(text))
     {
         AddMultitextForms(propertyName, text);
     }
 }
Exemplo n.º 7
0
        private MultiText GetMultiText(string text)
        {
            MultiText word = new MultiText();

            word[VernWs.Id] = text;
            return(word);
        }
Exemplo n.º 8
0
        protected Control MakeBoundControl(MultiText multiTextToBindTo, Field field)
        {
            MultiTextControl m;

            if (_previouslyGhostedControlToReuse == null)
            {
                m = new MultiTextControl(field.WritingSystemIds,
                                         multiTextToBindTo,
                                         field.FieldName,
                                         field.Visibility !=
                                         CommonEnumerations.VisibilitySetting.ReadOnly,
                                         //show annotation
                                         BasilProject.Project.WritingSystems,
                                         field.Visibility,
                                         field.IsSpellCheckingEnabled,
                                         field.IsMultiParagraph,
                                         _serviceProvider);
                if (_columnWidths != null && _columnWidths.Length == 3)
                {
                    m.Width = _columnWidths[1];
                }
            }
            else
            {
                m = _previouslyGhostedControlToReuse;
                _previouslyGhostedControlToReuse = null;
            }
            BindMultiTextControlToField(m, multiTextToBindTo);
            return(m);
        }
Exemplo n.º 9
0
        private void SetupComboControl(IValueHolder <string> selectedOptionRef)
        {
            _control.Font = (Font)StringCatalog.LabelFont.Clone();
            if (!_list.Options.Exists(delegate(Option o) { return(o.Key == string.Empty || o.Key == "unknown"); }))
            {
                MultiText unspecifiedMultiText = new MultiText();
                unspecifiedMultiText.SetAlternative(_preferredWritingSystem.Id,
                                                    StringCatalog.Get("~unknown",
                                                                      "This is shown in a combo-box (list of options, like Part Of Speech) when no option has been chosen, or the user just doesn't know what to put in this field."));
                Option unspecifiedOption = new Option("unknown", unspecifiedMultiText);
                _control.AddItem(new Option.OptionDisplayProxy(unspecifiedOption,
                                                               _preferredWritingSystem.Id));
            }
            _list.Options.Sort(CompareItems);
            foreach (Option o in _list.Options)
            {
                _control.AddItem(o.GetDisplayProxy(_preferredWritingSystem.Id));
            }
            _control.BackColor = Color.White;

            Value = selectedOptionRef.Value;
            _control.ListCompleted();

            _control.SelectedValueChanged += OnSelectedValueChanged;

            //don't let the mousewheel do the scrolling, as it's likely an accident (http://jira.palaso.org/issues/browse/WS-34670)
            ((Control)_control).MouseWheel += (sender, e) => {
                HandledMouseEventArgs he = e as HandledMouseEventArgs;
                if (he != null)
                {
                    he.Handled = true;
                }
            };
        }
        //------------------------------------------------------------
        private void AddSourceChoice(string label, string key)
        {
            MultiText name = new MultiText();

            name[_ws.Id] = label;
            _sourceChoices.Options.Add(new Option(key, name));
        }
Exemplo n.º 11
0
 /// <summary> Adds vernacular of a word to be written out to lift </summary>
 private static void AddVern(LexEntry entry, Word wordEntry, string vernacularBcp47)
 {
     entry.LexicalForm.MergeIn(MultiText.Create(
                                   new LiftMultiText {
         { vernacularBcp47, wordEntry.Vernacular }
     }));
 }
Exemplo n.º 12
0
        /// <summary>
        /// Handle LIFT's "note" entity
        /// </summary>
        /// <remarks>The difficult thing here is we don't handle anything but a default note.
        /// Any other kind, we put in the xml residue for round-tripping.</remarks>
        public void MergeInNote(PalasoDataObject extensible, string type, LiftMultiText contents, string rawXml)
        {
            var  noteProperty    = extensible.GetProperty <MultiText>(PalasoDataObject.WellKnownProperties.Note);
            bool alreadyHaveAOne = !MultiText.IsEmpty(noteProperty);

            bool weCanHandleThisType = string.IsNullOrEmpty(type) || type == "general";

            if (!alreadyHaveAOne && weCanHandleThisType)
            {
                List <String> writingSystemAlternatives = new List <string>(contents.Count);
                foreach (KeyValuePair <string, string> pair in contents.AsSimpleStrings)
                {
                    writingSystemAlternatives.Add(pair.Key);
                }
                noteProperty = extensible.GetOrCreateProperty <MultiText>(PalasoDataObject.WellKnownProperties.Note);
                MergeIn(noteProperty, contents);
            }
            else             //residue
            {
                var residue = extensible.GetOrCreateProperty <EmbeddedXmlCollection>(PalasoDataObject.GetEmbeddedXmlNameForProperty(PalasoDataObject.WellKnownProperties.Note));
                residue.Values.Add(rawXml);
//                var r = extensible.GetProperty<EmbeddedXmlCollection>(PalasoDataObject.GetEmbeddedXmlNameForProperty(PalasoDataObject.WellKnownProperties.Note));
//                Debug.Assert(r != null);
            }
        }
Exemplo n.º 13
0
        private void Init(string id, Guid guid, DateTime creationTime, DateTime modifiedTime)
        {
            ModificationTime     = modifiedTime;
            ModifiedTimeIsLocked = true;

            Id = id;
            if (guid == Guid.Empty)
            {
                _guid = Guid.NewGuid();
            }
            else
            {
                _guid = guid;
            }
            _lexicalForm    = new MultiText(this);
            _senses         = new BindingList <LexSense>();
            _variants       = new BindingList <LexVariant>();
            _notes          = new BindingList <LexNote>();
            _pronunciations = new BindingList <LexPhonetic>();
            _etymologies    = new BindingList <LexEtymology>();

            CreationTime = creationTime;

            WireUpEvents();

            ModifiedTimeIsLocked = false;
        }
Exemplo n.º 14
0
        /// <summary> Adds pronunciation audio of a word to be written out to lift </summary>
        private void AddAudio(LexEntry entry, Word wordEntry, string path)
        {
            foreach (var audioFile in wordEntry.Audio)
            {
                var lexPhonetic = new LexPhonetic();

                var util = new Utilities();

                var projectPath = Path.Combine(util.GenerateFilePath(
                                                   Utilities.FileType.Dir, true, "", ""), _projectId);
                projectPath = Path.Combine(projectPath, "Import", "ExtractedLocation");
                var extractedDir = Directory.GetDirectories(projectPath);
                projectPath = Path.Combine(projectPath, extractedDir.Single());
                var src = Path.Combine(util.GenerateFilePath(
                                           Utilities.FileType.Audio, true), Path.Combine(projectPath, "audio", audioFile));
                var dest = Path.Combine(path, audioFile);

                if (File.Exists(src))
                {
                    File.Copy(src, dest, true);

                    var proMultiText = new LiftMultiText {
                        { "href", dest }
                    };
                    lexPhonetic.MergeIn(MultiText.Create(proMultiText));
                    entry.Pronunciations.Add(lexPhonetic);
                }
            }
        }
Exemplo n.º 15
0
        private List <String> ParseQuestions(XmlReader reader)
        {
            var questions = new List <string>();

            reader.ReadToFollowing("CmDomainQ");
            while (reader.IsStartElement("CmDomainQ"))
            {
                XmlReader cmDomainQReader = reader.ReadSubtree();
                cmDomainQReader.ReadToFollowing("Question");
                MultiText mtQuestion = ParseMultiStringElement(cmDomainQReader, false);
                string    question   = mtQuestion.GetBestAlternative(SemanticDomainWs);
                cmDomainQReader.ReadToFollowing("ExampleWords");
                MultiText mtExampleWords = ParseMultiStringElement(cmDomainQReader, true);
                string    exampleWords   = mtExampleWords.GetBestAlternative(SemanticDomainWs);
                if (!String.IsNullOrEmpty(question))
                {
                    string formattedQuestion = "";
                    if (!String.IsNullOrEmpty((exampleWords)))
                    {
                        formattedQuestion = question + " (" + exampleWords + ")";
                    }
                    else
                    {
                        formattedQuestion = question;
                    }
                    questions.Add(formattedQuestion);
                }
                cmDomainQReader.Close();
                reader.ReadToNextSibling("CmDomainQ");
            }
            return(questions);
        }
Exemplo n.º 16
0
        public MultiTextControl(IList <string> writingSystemIds,
                                MultiText multiTextToCopyFormsFrom, string nameForTesting,
                                bool showAnnotationWidget, IWritingSystemRepository allWritingSystems,
                                CommonEnumerations.VisibilitySetting visibility, bool isSpellCheckingEnabled,
                                bool isMultiParagraph, IServiceProvider serviceProvider) : this(allWritingSystems, serviceProvider)
        {
            Name = nameForTesting + "-mtc";
            _writingSystemsForThisField = new List <IWritingSystemDefinition>();
//            foreach (KeyValuePair<string, WritingSystem> pair in allWritingSystems)
//            {
//                if (writingSystemIds.Contains(pair.Key))
//                {
//                    _writingSystemsForThisField.Add(pair.Value);
//                }
//            }
            foreach (var id in writingSystemIds)
            {
                if (allWritingSystems.Contains(id))                 //why wouldn't it?
                {
                    _writingSystemsForThisField.Add(allWritingSystems.Get(id));
                }
            }
            _showAnnotationWidget  = showAnnotationWidget;
            _visibility            = visibility;
            IsSpellCheckingEnabled = isSpellCheckingEnabled;
            _isMultiParagraph      = isMultiParagraph;
            BuildBoxes(multiTextToCopyFormsFrom);
        }
Exemplo n.º 17
0
        private static string RenderField(MultiText text,
                                          CurrentItemEventArgs currentItem,
                                          int sizeBoost,
                                          Field field)
        {
            var rtfBuilder = new StringBuilder();

            if (text != null)
            {
                if (text.Count == 0 && currentItem != null && text == currentItem.DataTarget)
                {
                    rtfBuilder.Append(RenderBlankPosition());
                }

                if (field == null)                 // show them all
                {
                    foreach (string id in WritingSystems.FilterForTextIds(text.Forms.Select(f => f.WritingSystemId)))
                    {
                        var form = text.Forms.First(f => f.WritingSystemId == id);
                        RenderForm(text, currentItem, rtfBuilder, form, sizeBoost);
                    }
                }
                else                 // show all forms turned on in the field
                {
                    foreach (string id in field.WritingSystemIds.Intersect(text.Forms.Select(f => f.WritingSystemId)))
                    {
                        var form = text.Forms.First(f => f.WritingSystemId == id);
                        RenderForm(text, currentItem, rtfBuilder, form, sizeBoost);
                    }
                }
            }
            return(rtfBuilder.ToString());
        }
Exemplo n.º 18
0
 /// <summary>
 /// Copy the forms into the boxes that we already have. Does not change which boxes we have!
 /// </summary>
 /// <param name="text"></param>
 public void SetMultiText(MultiText text)
 {
     foreach (IControlThatKnowsWritingSystem box in TextBoxes)
     {
         var s = text.GetExactAlternative(box.WritingSystem.Id);
         box.Text = s ?? string.Empty;
     }
 }
Exemplo n.º 19
0
 private Control MeaningFieldControl(Field field, MultiText meaningText)
 {
     if (field != null && field.GetDoShow(meaningText, this.ShowNormallyHiddenFields))
     {
         return(MakeBoundControl(meaningText, field));
     }
     return(null);
 }
Exemplo n.º 20
0
        private void ClearSenseCustom()
        {
            MultiText customFieldInSense =
                _sense.GetOrCreateProperty <MultiText>("customFieldInSense");

            customFieldInSense["th"] = string.Empty;
            _entry.CleanUpAfterEditting();
        }
Exemplo n.º 21
0
        private void ClearExampleCustom()
        {
            MultiText customFieldInExample =
                _examples.GetOrCreateProperty <MultiText>("customFieldInExample");

            customFieldInExample["th"] = string.Empty;
            _entry.CleanUpAfterEditting();
        }
Exemplo n.º 22
0
		public void Notification()
		{
			_gotHandlerNotice = false;
			MultiText text = new MultiText();
			text.PropertyChanged += propertyChangedHandler;
			text.SetAlternative("zox", "");
			Assert.IsTrue(_gotHandlerNotice);
		}
Exemplo n.º 23
0
        public void Find_QueryHasDIfferentCase_StillFinds()
        {
            MultiText x = new MultiText();

            x["aBc"] = "alpha";
            Assert.AreSame("alpha", x.Find("AbC").Form);
            Assert.AreSame(x.Find("aBc"), x.Find("AbC"));
        }
Exemplo n.º 24
0
        /// <summary> Adds vernacular of a word to be written out to lift </summary>
        private void AddVern(LexEntry entry, Word wordEntry, string projectId)
        {
            var lang = _projService.GetProject(projectId).Result.VernacularWritingSystem;

            entry.LexicalForm.MergeIn(MultiText.Create(new LiftMultiText {
                { lang, wordEntry.Vernacular }
            }));
        }
Exemplo n.º 25
0
 public LexEtymology(string type, string source)
 {
     Type    = type;
     Source  = source;
     Traits  = new List <LexTrait>();
     Fields  = new List <LexField>();
     Gloss   = new MultiText();
     Comment = new MultiText();
 }
Exemplo n.º 26
0
        public void Notification()
        {
            _gotHandlerNotice = false;
            MultiText text = new MultiText();

            text.PropertyChanged += propertyChangedHandler;
            text.SetAlternative("zox", "");
            Assert.IsTrue(_gotHandlerNotice);
        }
Exemplo n.º 27
0
		public LexEtymology(string type, string source)
		{
			Type = type;
			Source = source;
			Traits = new List<LexTrait>();
			Fields = new List<LexField>();
			Gloss = new MultiText();
			Comment = new MultiText();
		}
Exemplo n.º 28
0
        private static void AssertPropertyHasExpectedMultiText(PalasoDataObject dataObject,
                                                               string name)
        {
            //must match what is created by MakeBasicLiftMultiText()
            MultiText mt = dataObject.GetProperty <MultiText>(name);

            Assert.AreEqual(2, mt.Forms.Length);
            Assert.AreEqual("dos", mt["ws-two"]);
        }
Exemplo n.º 29
0
        public void GetOrCreateSenseWithMeaning_SenseDoesExists_ExistingSense()
        {
            MultiText meaning = new MultiText();

            meaning.SetAlternative("th", "sense");

            LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);

            Assert.AreSame(_sense, sense);
        }
Exemplo n.º 30
0
        public void ConvertLiftStringToSimpleStringWithMarkers_TextWithOneSpan()
        {
            LiftString liftStringToConvert = new LiftString("Text to Mark Up!");
            LiftSpan   span1 = new LiftSpan(0, 4, "", "", "");

            liftStringToConvert.Spans.Add(span1);
            string convertedString = MultiText.ConvertLiftStringToSimpleStringWithMarkers(liftStringToConvert);

            Assert.AreEqual("<span>Text</span> to Mark Up!", convertedString);
        }
Exemplo n.º 31
0
        private static void FillInMultiTextOfNewObject(object o,
                                                       string propertyName,
                                                       IWritingSystemDefinition writingSystem,
                                                       string value)
        {
            PropertyInfo info = o.GetType().GetProperty(propertyName);
            MultiText    text = (MultiText)info.GetValue(o, null);

            text.SetAlternative(writingSystem.Id, value);
        }
Exemplo n.º 32
0
		public void MergedGuyHasCorrectParentsOnForms()
		{
			MultiText x = new MultiText();
			x["a"] = "alpha";
			MultiText y = new MultiText();
			y["b"] = "beta";
			x.MergeIn(y);
			Assert.AreSame(y, y.Find("b").Parent);
			Assert.AreSame(x, x.Find("b").Parent);
		}
Exemplo n.º 33
0
 protected void WriteURLRef(string key, string href, MultiText caption)
 {
     if (!string.IsNullOrEmpty(href))
     {
         Writer.WriteStartElement(key);
         Writer.WriteAttributeString("href", href);
         WriteMultiWithWrapperIfNonEmpty(key, "label", caption);
         Writer.WriteEndElement();
     }
 }
Exemplo n.º 34
0
        public void MergeInNote_NoteHasTypeOfGeneral_Added()
        {
            LexEntry e = MakeSimpleEntry();

            _builder.MergeInNote(e, "general", MakeBasicLiftMultiText(), string.Empty);
            MultiText mt = e.GetProperty <MultiText>(PalasoDataObject.WellKnownProperties.Note);

            Assert.AreEqual("uno", mt["ws-one"]);
            Assert.AreEqual("dos", mt["ws-two"]);
        }
Exemplo n.º 35
0
        public void WidgetToTarget()
        {
            MultiText text = new MultiText();
            WeSayTextBox widget =
                    new WeSayTextBox(new WritingSystem("vernacular", new Font("Arial", 12)), null);

            var binding = new TextBinding(text, "vernacular", widget);

            widget.Text = "aaa";
            widget.Dispose();//this is hard to test now, because the biding only fires when focus is lost or the target ui control goes away
            Assert.AreEqual("aaa", text["vernacular"]);
        }
Exemplo n.º 36
0
        public void TargetToWidget()
        {
            MultiText text = new MultiText();
            WeSayTextBox widget =
                    new WeSayTextBox(new WritingSystem("vernacular", new Font("Arial", 12)), null);
            new TextBinding(text, "vernacular", widget);

            text["vernacular"] = "hello";
            Assert.AreEqual("hello", widget.Text);
            text["vernacular"] = null;
            Assert.AreEqual("", widget.Text);
        }
		private void CreateThreeDifferentLexEntries(GetMultiTextFromLexEntryDelegate getMultiTextFromLexEntryDelegate)
		{
			LexEntry[] lexEntriesToSort = new LexEntry[3];
			MultiText[] propertyOfLexentry = new MultiText[3];

			lexEntriesToSort[0] = _repository.CreateItem();
			propertyOfLexentry[0] = getMultiTextFromLexEntryDelegate(lexEntriesToSort[0]);
			propertyOfLexentry[0].SetAlternative("de", "de Word2");

			lexEntriesToSort[1] = _repository.CreateItem();
			propertyOfLexentry[1] = getMultiTextFromLexEntryDelegate(lexEntriesToSort[1]);
			propertyOfLexentry[1].SetAlternative("de", "de Word3");

			lexEntriesToSort[2] = _repository.CreateItem();
			propertyOfLexentry[2] = getMultiTextFromLexEntryDelegate(lexEntriesToSort[2]);
			propertyOfLexentry[2].SetAlternative("de", "de Word1");

			_repository.SaveItem(lexEntriesToSort[0]);
			_repository.SaveItem(lexEntriesToSort[1]);
			_repository.SaveItem(lexEntriesToSort[2]);
		}
Exemplo n.º 38
0
		private void Init(string id, Guid guid, DateTime creationTime, DateTime modifiedTime)
		{
			ModificationTime = modifiedTime;
			ModifiedTimeIsLocked = true;

			Id = id;
			if (guid == Guid.Empty)
			{
				_guid = Guid.NewGuid();
			}
			else
			{
				_guid = guid;
			}
			_lexicalForm = new MultiText(this);
			_senses = new BindingList<LexSense>();
			CreationTime = creationTime;

			WireUpEvents();

			ModifiedTimeIsLocked = false;
		}
Exemplo n.º 39
0
        public MultiTextControl(IList<string> writingSystemIds,
								MultiText multiTextToCopyFormsFrom,
								string nameForTesting,
								bool showAnnotationWidget,
								WritingSystemCollection allWritingSystems,
								CommonEnumerations.VisibilitySetting visibility,
								bool isSpellCheckingEnabled)
            : this(allWritingSystems)
        {
            Name = nameForTesting + "-mtc";
            _writingSystemsForThisField = new List<WritingSystem>();
            foreach (KeyValuePair<string, WritingSystem> pair in allWritingSystems)
            {
                if (writingSystemIds.Contains(pair.Key))
                {
                    _writingSystemsForThisField.Add(pair.Value);
                }
            }
            _showAnnotationWidget = showAnnotationWidget;
            _visibility = visibility;
            _isSpellCheckingEnabled = isSpellCheckingEnabled;
            BuildBoxes(multiTextToCopyFormsFrom);
        }
Exemplo n.º 40
0
		private static void RenderForm(MultiText text,
									   CurrentItemEventArgs currentItem,
									   StringBuilder rtfBuilder,
									   LanguageForm form,
									   int sizeBoost)
		{
			if (IsCurrentField(text, form, currentItem))
			{
				rtfBuilder.Append(@"\ul");
			}
			rtfBuilder.Append(SwitchToWritingSystem(form.WritingSystemId, sizeBoost));
			rtfBuilder.Append(form.Form); // + " ");
			if (IsCurrentField(text, form, currentItem))
			{
				//rtfBuilder.Append(" ");
				//rtfBuilder.Append(Convert.ToChar(160));
				rtfBuilder.Append(@"\ulnone ");
				//rtfBuilder.Append(Convert.ToChar(160));
			}
			rtfBuilder.Append(" ");
		}
Exemplo n.º 41
0
		public void Add_MultiTextWithScaryUnicodeChar_IsExported()
		{
			const string expected =
				"<form\r\n\tlang=\"de\">\r\n\t<text>This has a segment separator character at the end&#x1F;</text>\r\n</form>";
			//  1F is the character for "Segment Separator" and you can insert it by right-clicking in windows
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This has a segment separator character at the end\u001F");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
Exemplo n.º 42
0
		public void Add_MalformedXmlWithWithScaryUnicodeChar_IsExportedAsText()
		{
			const string expected = "<form\r\n\tlang=\"de\">\r\n\t<text>This &lt;span href=\"reference\"&gt;is not well &#x1F; formed&lt;span&gt; XML!</text>\r\n</form>";
			//  1F is the character for "Segment Separator" and you can insert it by right-clicking in windows
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This <span href=\"reference\">is not well \u001F formed<span> XML!");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
 //------------------------------------------------------------
 private void AddSourceChoice(string label, string key, string description)
 {
     MultiText name = new MultiText();
     name[_ws.Id] = label;
     Option item = new Option(key, name);
     item.Description.SetAlternative(_ws.Id, description);
     _sourceChoices.Options.Add(item);
     _choiceKeys.Add(key);
 }
Exemplo n.º 44
0
		public void Add_MultiTextWithMalFormedXML_IsExportedText()
		{
			const string expected =
				"<form\r\n\tlang=\"de\">\r\n\t<text>This &lt;span href=\"reference\"&gt;is not well formed&lt;span&gt; XML!</text>\r\n</form>";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This <span href=\"reference\">is not well formed<span> XML!");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
Exemplo n.º 45
0
        private void BuildBoxes(MultiText multiText)
        {
            SuspendLayout();

            if (Controls.Count > 0)
            {
                _textBoxes.Clear();
                Controls.Clear();
                RowCount = 0;
                RowStyles.Clear();
            }
            Debug.Assert(RowCount == 0);
            foreach (WritingSystem writingSystem in WritingSystemsForThisField)
            {
                RowStyles.Add(new RowStyle(SizeType.AutoSize));
                WeSayTextBox box = AddTextBox(writingSystem, multiText);

                Label label = AddWritingSystemLabel(box);
                label.Click += subControl_Click;
                label.MouseWheel += subControl_MouseWheel;

                Controls.Add(label, 0, RowCount);
                Controls.Add(box, 1, RowCount);

                if (_showAnnotationWidget) //false for ghosts
                {
                    //TODO: THIS IS TRANSITIONAL CODE... AnnotationWidget should probably become a full control (or go away)
                    AnnotationWidget aw = new AnnotationWidget(multiText,
                                                               writingSystem.Id,
                                                               box.Name + "-annotationWidget");
                    Control annotationControl = aw.MakeControl(new Size()); //p.Size);
                    annotationControl.Click += subControl_Click;
                    annotationControl.Anchor = AnchorStyles.Right | AnchorStyles.Top;
                    Controls.Add(annotationControl, 2, RowCount);
                }
                //else
                //{
                //    SetColumnSpan(box, 2);
                //}
                RowCount++;
            }

            ResumeLayout(false);
        }
Exemplo n.º 46
0
		public static IEnumerable<string> SplitGlossAtSemicolon(MultiText gloss, string writingSystemId)
		{
			bool exact = true;
			string glossText = gloss.GetExactAlternative(writingSystemId);
			if (glossText == string.Empty)
			{
				exact = false;
				glossText = gloss.GetBestAlternative(writingSystemId, "*");
				if (glossText == "*")
				{
					glossText = string.Empty;
				}
			}

			List<string> result = new List<string>();
			string[] keylist = glossText.Split(new char[] { ';' });
			for (int i = 0; i < keylist.Length; i++)
			{
				string k = keylist[i].Trim();
				if (/*keylist.Length > 1 &&*/ k.Length == 0)
				{
					continue;
				}
				if (exact || i == keylist.Length - 1)
				{
					result.Add(k);
				}
				else
				{
					result.Add(k + "*");
				}
			}
			return result;
		}
Exemplo n.º 47
0
		public void GetOrCreateSenseWithMeaning_SenseDoesNotExist_NewSenseWithMeaning()
		{
			MultiText meaning = new MultiText();
			meaning.SetAlternative("th", "new");

			LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);
			Assert.AreNotSame(_sense, sense);
#if GlossMeaning
			Assert.AreEqual("new", sense.Gloss.GetExactAlternative("th"));
#else
			Assert.AreEqual("new", sense.Definition.GetExactAlternative("th"));
#endif
		}
Exemplo n.º 48
0
		public void GetOrCreateSenseWithMeaning_SenseWithEmptyStringExists_ExistingSense()
		{
			ClearSenseMeaning();

			MultiText meaning = new MultiText();
			meaning.SetAlternative("th", string.Empty);

			LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);
			Assert.AreSame(_sense, sense);
		}
Exemplo n.º 49
0
		public void GetOrCreateSenseWithMeaning_SenseDoesExists_ExistingSense()
		{
			MultiText meaning = new MultiText();
			meaning.SetAlternative("th", "sense");

			LexSense sense = _entry.GetOrCreateSenseWithMeaning(meaning);
			Assert.AreSame(_sense, sense);
		}
Exemplo n.º 50
0
		public Option(string humanReadableKey, MultiText name) //, Guid guid)
		{
			_humanReadableKey = humanReadableKey;
			_name = name;
			//SearchKeys = new List<string>();
		}
Exemplo n.º 51
0
		public void Add_MultiTextWithWellFormedXMLAndScaryCharacter_IsExportedAsXML()
		{
			const string expected =
			"<form\r\n\tlang=\"de\">\r\n\t<text>This <span href=\"reference\">is well &#x1F; formed</span> XML!</text>\r\n</form>";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", "This <span href=\"reference\">is well \u001F formed</span> XML!");
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
Exemplo n.º 52
0
		private static bool IsCurrentField(MultiText text,
										   LanguageForm l,
										   CurrentItemEventArgs currentItem)
		{
			if (currentItem == null)
			{
				return false;
			}
			return (currentItem.DataTarget == text &&
					currentItem.WritingSystemId == l.WritingSystemId);
		}
Exemplo n.º 53
0
		public LexSense GetOrCreateSenseWithMeaning(MultiText meaning) //Switch to meaning
		{
			foreach (LexSense sense in Senses)
			{
#if GlossMeaning
				if (meaning.HasFormWithSameContent(sense.Gloss))
#else
				if (meaning.HasFormWithSameContent(sense.Definition))
#endif
				{
					return sense;
				}
			}
			LexSense newSense = new LexSense();
			Senses.Add(newSense);
#if GlossMeaning
			newSense.Gloss.MergeIn(meaning);
#else
			newSense.Definition.MergeIn(meaning);
#endif
			return newSense;
		}
Exemplo n.º 54
0
		public void Add_TextWithSpanAndMeaningfulWhiteSpace_FormattingAndWhitespaceIsUntouched()
		{
			const string formattedText = "\rThis's <span href=\"reference\">\n is a\t\t\n\r\t span</span> with annoying whitespace!\r\n";
			const string expected = "<form\r\n\tlang=\"de\">\r\n\t<text>" + formattedText + "</text>\r\n</form>";
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var multiText = new MultiText();
				multiText.SetAlternative("de", formattedText);
				session.LiftWriter.AddMultitextForms(null, multiText);
				session.LiftWriter.End();
				Assert.AreEqual(expected, session.OutputString());
			}
		}
Exemplo n.º 55
0
		public void MultiText()
		{
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var text = new MultiText();
				text["blue"] = "ocean";
				text["red"] = "sunset";
				session.LiftWriter.AddMultitextForms(null, text);
				AssertEqualsCanonicalString(
					"<form lang=\"blue\"><text>ocean</text></form><form lang=\"red\"><text>sunset</text></form>",
					session.OutputString()
				);
			}
		}
Exemplo n.º 56
0
		/// <summary>
		/// nb: this is used both for the headword of an article, but also for the target of a relation.
		/// </summary>
		private void WriteHeadWordField(LexEntry entry, string outputFieldName)
		{
			if (Template == null)
			{
				throw new InvalidOperationException("Expected a non-null Template");
			}
			MultiText headword = new MultiText();
			Field fieldControllingHeadwordOutput =
					Template.GetField(LexEntry.WellKnownProperties.Citation);
			if (fieldControllingHeadwordOutput == null || !fieldControllingHeadwordOutput.Enabled)
			{
				fieldControllingHeadwordOutput =
						Template.GetField(LexEntry.WellKnownProperties.LexicalUnit);
				if (fieldControllingHeadwordOutput == null)
				{
					throw new ArgumentException("Expected to find LexicalUnit in the view Template");
				}
			}
			//                headword.SetAlternative(HeadWordWritingSystemId, entry.GetHeadWordForm(HeadWordWritingSystemId));

			foreach (string writingSystemId in fieldControllingHeadwordOutput.WritingSystemIds)
			{
				headword.SetAlternative(writingSystemId, entry.GetHeadWordForm(writingSystemId));
			}
			WriteMultiTextAsArtificialField(outputFieldName, headword);
		}
Exemplo n.º 57
0
 public AnnotationWidget(MultiText multitext, string writingSystemId, string nameForTesting)
 {
     _nameForTesting = nameForTesting;
     _multitext = multitext;
     _writingSystemId = writingSystemId;
 }
Exemplo n.º 58
0
		public void Add_MultiTextWithMalFormedXML_IsExportedText()
		{
			MultiText multiText = new MultiText();
			multiText.SetAlternative("de", "This <span href=\"reference\">is not well formed<span> XML!");
			_exporter.Add(null, multiText);
			CheckAnswer("<form lang=\"de\"><text>This &lt;span href=\"reference\"&gt;is not well formed&lt;span&gt; XML!</text></form>");
		}
Exemplo n.º 59
0
		public void WordCollected(MultiText newVernacularWord)
		{
			LexSense sense = new LexSense();
			sense.Definition.MergeIn(CurrentWordAsMultiText);
			sense.Gloss.MergeIn(CurrentWordAsMultiText);
			//we use this for matching up, and well, it probably is a good gloss

			AddSenseToLexicon(newVernacularWord, sense);
		}
Exemplo n.º 60
0
		public void MultiText()
		{
			MultiText text = new MultiText();
			text["blue"] = "ocean";
			text["red"] = "sunset";
			_exporter.Add(null, text);
			CheckAnswer(
					"<form lang=\"blue\"><text>ocean</text></form><form lang=\"red\"><text>sunset</text></form>");
		}