Example #1
0
        public static InterlinLineChoices Restore(string data, ILgWritingSystemFactory wsf, int defVern, int defAnalysis, ILangProject proj)
        {
            InterlinLineChoices result;

            string[] parts = data.Split(',');

            switch (parts[0])
            {
            case "InterlinLineChoices":
                result = new InterlinLineChoices(defVern, defAnalysis, proj);
                break;

            case "EditableInterlinLineChoices":
                result = new EditableInterlinLineChoices(defVern, defAnalysis, proj);
                break;

            default:
                throw new Exception("Unrecognised type of InterlinLineChoices: " + parts[0]);
            }
            for (int i = 1; i < parts.Length; i++)
            {
                string[] flidAndWs = parts[i].Split('%');
                if (flidAndWs.Length != 2)
                {
                    throw new Exception("Unrecognized InterlinLineSpec: " + parts[i]);
                }
                int flid = Int32.Parse(flidAndWs[0]);
                int ws   = wsf.GetWsFromStr(flidAndWs[1]);
                result.Add(flid, ws);
            }
            return(result);
        }
Example #2
0
        public void Persistence()
        {
            var wsManager = new WritingSystemManager();
            CoreWritingSystemDefinition enWs;

            wsManager.GetOrSet("en", out enWs);
            int wsEng = enWs.Handle;

            CoreWritingSystemDefinition frWs;

            wsManager.GetOrSet("fr", out frWs);
            int wsFrn = frWs.Handle;

            CoreWritingSystemDefinition deWs;

            wsManager.GetOrSet("de", out deWs);
            int wsGer = deWs.Handle;

            InterlinLineChoices choices = new InterlinLineChoices(m_lp, wsFrn, wsEng);

            MakeStandardState(choices);
            string persist = choices.Persist(wsManager);

            choices = InterlinLineChoices.Restore(persist, wsManager, m_lp, wsFrn, wsEng);

            Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[4].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[5].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[6].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[7].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[8].Flid);

            // Check writing systems assigned by default.
            Assert.AreEqual(wsFrn, choices[0].WritingSystem);
            Assert.AreEqual(wsEng, choices[5].WritingSystem);
            Assert.AreEqual(wsFrn, choices[2].WritingSystem);

            choices = new EditableInterlinLineChoices(m_lp, 0, wsEng);
            MakeStandardState(choices);
            choices.Add(InterlinLineChoices.kflidLexGloss, wsGer);
            Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[5].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[6].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[7].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[8].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[9].Flid);

            Assert.AreEqual(wsGer, choices[4].WritingSystem);
        }
        public void Persistence()
        {
            ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create();

            try
            {
                int wsEng = 1;
                int wsFrn = 2;
                int wsGer = 3;
                wsf.AddWritingSystem(wsEng, "en");
                wsf.AddWritingSystem(wsFrn, "fr");
                wsf.AddWritingSystem(wsGer, "de");
                InterlinLineChoices choices = new InterlinLineChoices(wsFrn, wsEng);
                MakeStandardState(choices);
                string persist = choices.Persist(wsf);
                choices = InterlinLineChoices.Restore(persist, wsf, wsFrn, wsEng);

                Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[4].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[5].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[6].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[7].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[8].Flid);

                // Check writing systems assigned by default.
                Assert.AreEqual(wsFrn, choices[0].WritingSystem);
                Assert.AreEqual(wsEng, choices[5].WritingSystem);
                Assert.AreEqual(wsFrn, choices[2].WritingSystem);

                choices = new EditableInterlinLineChoices(0, wsEng);
                MakeStandardState(choices);
                choices.Add(InterlinLineChoices.kflidLexGloss, wsGer);
                Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[5].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[6].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[7].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[8].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[9].Flid);

                Assert.AreEqual(wsGer, choices[4].WritingSystem);
            }
            finally
            {
                // we must shutdown and marshal this or else it could mess up other tests.
                wsf.Shutdown();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wsf);
            }
        }
Example #4
0
        public void AddRemoveEditFields()
        {
            InterlinLineChoices choices = new EditableInterlinLineChoices(m_lp, kwsVernInPara, kwsAnalysis);

            choices.Add(InterlinLineChoices.kflidWord);
            choices.Add(InterlinLineChoices.kflidMorphemes);
            choices.Add(InterlinLineChoices.kflidWordGloss);
            choices.Add(InterlinLineChoices.kflidFreeTrans);
            choices.Add(InterlinLineChoices.kflidWordPos);
            choices.Add(InterlinLineChoices.kflidLexGloss);

            Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
            // reordered past ff and word level
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[2].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[3].Flid);
            // reordered past a freeform.
            Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[4].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[5].Flid);

            // We can't remove the Word line.
            string msg;

            Assert.IsFalse(choices.OkToRemove(choices[0], out msg));
            Assert.IsNotNull(msg);
            // Add another word line and make sure we can remove one of them.
            choices.Add(InterlinLineChoices.kflidWord);
            Assert.AreEqual(InterlinLineChoices.kflidWord, choices[1].Flid);
            Assert.IsTrue(choices.OkToRemove(choices[0], out msg));
            Assert.IsNull(msg);
            choices.Remove(choices[0]);
            Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);

            // Other fields can be removed freely
            Assert.IsTrue(choices.OkToRemove(choices[1], out msg));
            Assert.IsNull(msg);
            Assert.IsTrue(choices.OkToRemove(choices[2], out msg));
            Assert.IsNull(msg);
            Assert.IsTrue(choices.OkToRemove(choices[3], out msg));
            Assert.IsNull(msg);
            Assert.IsTrue(choices.OkToRemove(choices[4], out msg));
            Assert.IsNull(msg);
            Assert.IsTrue(choices.OkToRemove(choices[5], out msg));
            Assert.IsNull(msg);

            // Check what goes along with the morphemes line: morpheme line should be independent (LT-6043).
            choices.Remove(choices[1]);
            Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
            // reordered past ff and word level
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[1].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[2].Flid);
            // reordered past a freeform.
            Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[3].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[4].Flid);
            Assert.AreEqual(5, choices.Count);

            // Add Morphemes and Lexentries lines above other MorphemeLevel lines by default.
            choices.Add(InterlinLineChoices.kflidLexEntries);            // bring entries back in
            choices.Add(InterlinLineChoices.kflidMorphemes);             // bring entries and morphemes back in
            Assert.AreEqual(7, choices.Count);
            Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
            choices.Remove(choices[2]);             // and get rid of the entries
            Assert.AreEqual(6, choices.Count);
        }
Example #5
0
        public void EditMoveUp()
        {
            InterlinLineChoices choices = new EditableInterlinLineChoices(m_lp, kwsVernInPara, kwsAnalysis);

            // To make it less confusing, here we add them in an order that does not produce
            // reordering.
            MakeStandardState(choices);
            //choices.Add(InterlinLineChoices.kflidWord); // 0
            //choices.Add(InterlinLineChoices.kflidMorphemes); // 1
            //choices.Add(InterlinLineChoices.kflidLexEntries); //2
            //choices.Add(InterlinLineChoices.kflidLexGloss); //3
            //choices.Add(InterlinLineChoices.kflidLexPos); //4
            //choices.Add(InterlinLineChoices.kflidWordGloss); //5
            //choices.Add(InterlinLineChoices.kflidWordPos); //6
            //choices.Add(InterlinLineChoices.kflidFreeTrans); //7
            //choices.Add(InterlinLineChoices.kflidLitTrans); //8

            Assert.IsFalse(choices.OkToMoveUp(0));            // words line already at top
            Assert.IsTrue(choices.OkToMoveUp(1));             // morphemes
            Assert.IsTrue(choices.OkToMoveUp(2));             // lex entries
            Assert.IsTrue(choices.OkToMoveUp(3));             // lex gloss
            Assert.IsTrue(choices.OkToMoveUp(4));             // lex pos
            Assert.IsTrue(choices.OkToMoveUp(5));             // will move past whole morph bundle
            Assert.IsTrue(choices.OkToMoveUp(6));
            Assert.IsFalse(choices.OkToMoveUp(7));            // free can't go anywhere
            Assert.IsTrue(choices.OkToMoveUp(8));

            choices.MoveUp(4);
            // nothing complicated, two items changed place.
            Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[3].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);

            choices = new EditableInterlinLineChoices(m_lp, kwsVernInPara, kwsAnalysis);
            MakeStandardState(choices);
            choices.MoveUp(5);
            // Moves past whole morpheme bundle
            Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[1].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[2].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[3].Flid);

            // Now, the morphemes line can move up, to move the whole bundle.
            Assert.IsTrue(choices.OkToMoveUp(2)); // morphemes line now below word gloss.
            choices.MoveUp(2);                    // whole bundle moves.
            Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[5].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);

            choices = new EditableInterlinLineChoices(m_lp, kwsVernInPara, kwsAnalysis);
            MakeStandardState(choices);
            choices.MoveUp(6);
            // nothing complicated, two items changed place.
            Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[5].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[6].Flid);

            choices = new EditableInterlinLineChoices(m_lp, kwsVernInPara, kwsAnalysis);
            MakeStandardState(choices);
            choices.MoveUp(8);
            // nothing complicated, two items changed place.
            Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[7].Flid);
            Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[8].Flid);

            // Try finding some default ws values.
            choices = new EditableInterlinLineChoices(m_lp, kwsVernInPara, kwsAnalysis);
            Assert.AreEqual(0, choices.Count);
            List <int> wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidWord);

            Assert.AreEqual(0, wsList.Count);
            wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidWord, true);
            Assert.AreEqual(1, wsList.Count);
            Assert.AreEqual(kwsVernInPara, wsList[0]);
            wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidWordGloss);
            Assert.AreEqual(0, wsList.Count);
            wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidWordGloss, true);
            Assert.AreEqual(1, wsList.Count);
            Assert.AreEqual(Cache.DefaultAnalWs, wsList[0]);

            // Try one with another WS.
            choices = new EditableInterlinLineChoices(m_lp, kwsVernInPara, kwsAnalysis);
            MakeStandardState(choices);
            wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidLexGloss);
            Assert.AreEqual(1, wsList.Count);
            Assert.AreEqual(WritingSystemServices.kwsFirstAnal, wsList[0]);
            choices.Add(InterlinLineChoices.kflidLexGloss, 3004);             //becomes 4 (by default, after existing field with same flid)
            wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidLexGloss);
            Assert.AreEqual(2, wsList.Count);
            Assert.AreEqual(WritingSystemServices.kwsFirstAnal, wsList[0]);
            Assert.AreEqual(3004, wsList[1]);
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
            choices.MoveDown(4);
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[5].Flid);
            Assert.IsTrue(choices.OkToMoveUp(5));
            choices.MoveUp(5);
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
            Assert.AreEqual(3004, choices[4].WritingSystem);
            Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[5].Flid);
            Assert.IsTrue(choices.OkToMoveUp(5));

            Assert.IsTrue(choices.OkToMoveUp(4));
            choices.MoveUp(4);
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
            Assert.AreEqual(3004, choices[3].WritingSystem);
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
            Assert.AreEqual(WritingSystemServices.kwsFirstAnal, choices[4].WritingSystem);
            Assert.IsTrue(choices.OkToMoveUp(3));

            // Another ws of entries can move up just as far (not past the primary
            // one that has the controls).
            choices = new EditableInterlinLineChoices(m_lp, kwsVernInPara, kwsAnalysis);
            MakeStandardState(choices);
            wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidLexEntries);
            Assert.AreEqual(1, wsList.Count);
            Assert.AreEqual(kwsVernInPara, wsList[0]);
            choices.Add(InterlinLineChoices.kflidLexEntries, 3005);             //becomes 3
            wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidLexEntries);
            Assert.AreEqual(2, wsList.Count);
            Assert.AreEqual(kwsVernInPara, wsList[0]);
            Assert.AreEqual(3005, wsList[1]);
            Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[3].Flid);
            choices.MoveDown(3);
            choices.MoveDown(4);
            Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[5].Flid);
            Assert.IsTrue(choices.OkToMoveUp(5));
            choices.MoveUp(5);
            Assert.IsTrue(choices.OkToMoveUp(4));
            choices.MoveUp(4);
            Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[3].Flid);
            Assert.AreEqual(3005, choices[3].WritingSystem);
            Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
            Assert.AreEqual(WritingSystemServices.kwsFirstAnal, choices[4].WritingSystem);
            Assert.IsTrue(choices.OkToMoveUp(3));             // not past primary LexEntry.

            // Another ws of morphemes can move up just under the primary one (not past the primary
            // one that has the controls).
            choices = new EditableInterlinLineChoices(m_lp, kwsVernInPara, kwsAnalysis);
            MakeStandardState(choices);
            choices.Add(InterlinLineChoices.kflidMorphemes, 3006);             //becomes 2
            wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidMorphemes);
            Assert.AreEqual(2, wsList.Count);
            Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[2].Flid);
            choices.MoveDown(2);
            choices.MoveDown(3);
            choices.MoveDown(4);
            Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[5].Flid);
            Assert.IsTrue(choices.OkToMoveUp(5));
            choices.MoveUp(5);
            Assert.IsTrue(choices.OkToMoveUp(4));
            choices.MoveUp(4);
            Assert.IsTrue(choices.OkToMoveUp(3));
            choices.MoveUp(3);
            Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[2].Flid);
            Assert.AreEqual(3006, choices[2].WritingSystem);
            Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[3].Flid);
            Assert.IsTrue(choices.OkToMoveUp(2));             // not past primary morphemes.

            // Another ws of word starts out right after it.
            choices = new EditableInterlinLineChoices(m_lp, kwsVernInPara, kwsAnalysis);
            MakeStandardState(choices);
            choices.Add(InterlinLineChoices.kflidWord, 3007);             //becomes 1
            Assert.AreEqual(InterlinLineChoices.kflidWord, choices[1].Flid);
            wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidWord);
            Assert.AreEqual(2, wsList.Count);
        }
		public void AddRemoveEditFields()
		{
			InterlinLineChoices choices = new EditableInterlinLineChoices(0, kwsAnalysis);
			choices.Add(InterlinLineChoices.kflidWord);
			choices.Add(InterlinLineChoices.kflidMorphemes);
			choices.Add(InterlinLineChoices.kflidWordGloss);
			choices.Add(InterlinLineChoices.kflidFreeTrans);
			choices.Add(InterlinLineChoices.kflidWordPos);
			choices.Add(InterlinLineChoices.kflidLexGloss);

			Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
			// reordered past ff and word level
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[2].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[3].Flid);
			// reordered past a freeform.
			Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[4].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[5].Flid);

			// We can't remove the Word line.
			string msg;
			Assert.IsFalse(choices.OkToRemove(choices[0], out msg));
			Assert.IsNotNull(msg);
			// Add another word line and make sure we can remove one of them.
			choices.Add(InterlinLineChoices.kflidWord);
			Assert.AreEqual(InterlinLineChoices.kflidWord, choices[1].Flid);
			Assert.IsTrue(choices.OkToRemove(choices[0], out msg));
			Assert.IsNull(msg);
			choices.Remove(choices[0]);
			Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);

			// Other fields can be removed freely
			Assert.IsTrue(choices.OkToRemove(choices[1], out msg));
			Assert.IsNull(msg);
			Assert.IsTrue(choices.OkToRemove(choices[2], out msg));
			Assert.IsNull(msg);
			Assert.IsTrue(choices.OkToRemove(choices[3], out msg));
			Assert.IsNull(msg);
			Assert.IsTrue(choices.OkToRemove(choices[4], out msg));
			Assert.IsNull(msg);
			Assert.IsTrue(choices.OkToRemove(choices[5], out msg));
			Assert.IsNull(msg);

			// Check what goes along with the morphemes line: morpheme line should be independent (LT-6043).
			choices.Remove(choices[1]);
			Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
			// reordered past ff and word level
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[1].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[2].Flid);
			// reordered past a freeform.
			Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[3].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[4].Flid);
			Assert.AreEqual(5, choices.Count);

			// Add Morphemes and Lexentries lines above other MorphemeLevel lines by default.
			choices.Add(InterlinLineChoices.kflidLexEntries); // bring entries back in
			choices.Add(InterlinLineChoices.kflidMorphemes); // bring entries and morphemes back in
			Assert.AreEqual(7, choices.Count);
			Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
			choices.Remove(choices[2]); // and get rid of the entries
			Assert.AreEqual(6, choices.Count);
		}
		public void Persistence()
		{
			ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create();
			try
			{
				int wsEng = 1;
				int wsFrn = 2;
				int wsGer = 3;
				wsf.AddWritingSystem(wsEng, "en");
				wsf.AddWritingSystem(wsFrn, "fr");
				wsf.AddWritingSystem(wsGer, "de");
				InterlinLineChoices choices = new InterlinLineChoices(wsFrn, wsEng);
				MakeStandardState(choices);
				string persist = choices.Persist(wsf);
				choices = InterlinLineChoices.Restore(persist, wsf, wsFrn, wsEng);

				Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[4].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[5].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[6].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[7].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[8].Flid);

				// Check writing systems assigned by default.
				Assert.AreEqual(wsFrn, choices[0].WritingSystem);
				Assert.AreEqual(wsEng, choices[5].WritingSystem);
				Assert.AreEqual(wsFrn, choices[2].WritingSystem);

				choices = new EditableInterlinLineChoices(0, wsEng);
				MakeStandardState(choices);
				choices.Add(InterlinLineChoices.kflidLexGloss, wsGer);
				Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[5].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[6].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[7].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[8].Flid);
				Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[9].Flid);

				Assert.AreEqual(wsGer, choices[4].WritingSystem);
			}
			finally
			{
				// we must shutdown and marshal this or else it could mess up other tests.
				wsf.Shutdown();
				System.Runtime.InteropServices.Marshal.ReleaseComObject(wsf);
			}
		}
		public void EditMoveUp()
		{
			InterlinLineChoices choices = new EditableInterlinLineChoices(0, kwsAnalysis);
			// To make it less confusing, here we add them in an order that does not produce
			// reordering.
			MakeStandardState(choices);
			//choices.Add(InterlinLineChoices.kflidWord); // 0
			//choices.Add(InterlinLineChoices.kflidMorphemes); // 1
			//choices.Add(InterlinLineChoices.kflidLexEntries); //2
			//choices.Add(InterlinLineChoices.kflidLexGloss); //3
			//choices.Add(InterlinLineChoices.kflidLexPos); //4
			//choices.Add(InterlinLineChoices.kflidWordGloss); //5
			//choices.Add(InterlinLineChoices.kflidWordPos); //6
			//choices.Add(InterlinLineChoices.kflidFreeTrans); //7
			//choices.Add(InterlinLineChoices.kflidLitTrans); //8

			Assert.IsFalse(choices.OkToMoveUp(0)); // words line already at top
			Assert.IsTrue(choices.OkToMoveUp(1)); // morphemes
			Assert.IsTrue(choices.OkToMoveUp(2)); // lex entries
			Assert.IsTrue(choices.OkToMoveUp(3)); // lex gloss
			Assert.IsTrue(choices.OkToMoveUp(4)); // lex pos
			Assert.IsTrue(choices.OkToMoveUp(5)); // will move past whole morph bundle
			Assert.IsTrue(choices.OkToMoveUp(6));
			Assert.IsFalse(choices.OkToMoveUp(7)); // free can't go anywhere
			Assert.IsTrue(choices.OkToMoveUp(8));

			choices.MoveUp(4);
			// nothing complicated, two items changed place.
			Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[3].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);

			choices = new EditableInterlinLineChoices(0, kwsAnalysis);
			MakeStandardState(choices);
			choices.MoveUp(5);
			// Moves past whole morpheme bundle
			Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[1].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[2].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[3].Flid);

			// Now, the morphemes line can move up, to move the whole bundle.
			Assert.IsTrue(choices.OkToMoveUp(2)); // morphemes line now below word gloss.
			choices.MoveUp(2); // whole bundle moves.
			Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[5].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);

			choices = new EditableInterlinLineChoices(0, kwsAnalysis);
			MakeStandardState(choices);
			choices.MoveUp(6);
			// nothing complicated, two items changed place.
			Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[5].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[6].Flid);

			choices = new EditableInterlinLineChoices(0, kwsAnalysis);
			MakeStandardState(choices);
			choices.MoveUp(8);
			// nothing complicated, two items changed place.
			Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[7].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[8].Flid);

			// Try finding some default ws values.
			choices = new EditableInterlinLineChoices(0, kwsAnalysis);
			Assert.AreEqual(0, choices.Count);
			List<int> wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidWord);
			Assert.AreEqual(0, wsList.Count);
			wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidWord, true);
			Assert.AreEqual(1, wsList.Count);
			Assert.AreEqual(kwsVern, wsList[0]);
			wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidWordGloss);
			Assert.AreEqual(0, wsList.Count);
			wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidWordGloss, true);
			Assert.AreEqual(1, wsList.Count);
			Assert.AreEqual(kwsAnalysis, wsList[0]);

			// Try one with another WS.
			choices = new EditableInterlinLineChoices(0, kwsAnalysis);
			MakeStandardState(choices);
			wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidLexGloss);
			Assert.AreEqual(1, wsList.Count);
			Assert.AreEqual(LangProject.kwsFirstAnal, wsList[0]);
			choices.Add(InterlinLineChoices.kflidLexGloss, 3004); //becomes 4 (by default, after existing field with same flid)
			wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidLexGloss);
			Assert.AreEqual(2, wsList.Count);
			Assert.AreEqual(LangProject.kwsFirstAnal, wsList[0]);
			Assert.AreEqual(3004, wsList[1]);
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
			choices.MoveDown(4);
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[5].Flid);
			Assert.IsTrue(choices.OkToMoveUp(5));
			choices.MoveUp(5);
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
			Assert.AreEqual(3004, choices[4].WritingSystem);
			Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[5].Flid);
			Assert.IsTrue(choices.OkToMoveUp(5));

			Assert.IsTrue(choices.OkToMoveUp(4));
			choices.MoveUp(4);
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
			Assert.AreEqual(3004, choices[3].WritingSystem);
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
			Assert.AreEqual((int)LangProject.kwsFirstAnal, choices[4].WritingSystem);
			Assert.IsTrue(choices.OkToMoveUp(3));

			// Another ws of entries can move up just as far (not past the primary
			// one that has the controls).
			choices = new EditableInterlinLineChoices(0, kwsAnalysis);
			MakeStandardState(choices);
			wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidLexEntries);
			Assert.AreEqual(1, wsList.Count);
			Assert.AreEqual(kwsVern, wsList[0]);
			choices.Add(InterlinLineChoices.kflidLexEntries, 3005); //becomes 3
			wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidLexEntries);
			Assert.AreEqual(2, wsList.Count);
			Assert.AreEqual(kwsVern, wsList[0]);
			Assert.AreEqual(3005, wsList[1]);
			Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[3].Flid);
			choices.MoveDown(3);
			choices.MoveDown(4);
			Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[5].Flid);
			Assert.IsTrue(choices.OkToMoveUp(5));
			choices.MoveUp(5);
			Assert.IsTrue(choices.OkToMoveUp(4));
			choices.MoveUp(4);
			Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[3].Flid);
			Assert.AreEqual(3005, choices[3].WritingSystem);
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
			Assert.AreEqual((int)LangProject.kwsFirstAnal, choices[4].WritingSystem);
			Assert.IsTrue(choices.OkToMoveUp(3)); // not past primary LexEntry.

			// Another ws of morphemes can move up just under the primary one (not past the primary
			// one that has the controls).
			choices = new EditableInterlinLineChoices(0, kwsAnalysis);
			MakeStandardState(choices);
			choices.Add(InterlinLineChoices.kflidMorphemes, 3006); //becomes 2
			wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidMorphemes);
			Assert.AreEqual(2, wsList.Count);
			Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[2].Flid);
			choices.MoveDown(2);
			choices.MoveDown(3);
			choices.MoveDown(4);
			Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[5].Flid);
			Assert.IsTrue(choices.OkToMoveUp(5));
			choices.MoveUp(5);
			Assert.IsTrue(choices.OkToMoveUp(4));
			choices.MoveUp(4);
			Assert.IsTrue(choices.OkToMoveUp(3));
			choices.MoveUp(3);
			Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[2].Flid);
			Assert.AreEqual(3006, choices[2].WritingSystem);
			Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[3].Flid);
			Assert.IsTrue(choices.OkToMoveUp(2)); // not past primary morphemes.

			// Another ws of word starts out right after it.
			choices = new EditableInterlinLineChoices(0, kwsAnalysis);
			MakeStandardState(choices);
			choices.Add(InterlinLineChoices.kflidWord, 3007); //becomes 1
			Assert.AreEqual(InterlinLineChoices.kflidWord, choices[1].Flid);
			wsList = choices.WritingSystemsForFlid(InterlinLineChoices.kflidWord);
			Assert.AreEqual(2, wsList.Count);
		}
		public void Persistence()
		{
			var wsManager = new PalasoWritingSystemManager();
			IWritingSystem enWs;
			wsManager.GetOrSet("en", out enWs);
			int wsEng = enWs.Handle;

			IWritingSystem frWs;
			wsManager.GetOrSet("fr", out frWs);
			int wsFrn = frWs.Handle;

			IWritingSystem deWs;
			wsManager.GetOrSet("de", out deWs);
			int wsGer = deWs.Handle;

			InterlinLineChoices choices = new InterlinLineChoices(m_lp, wsFrn, wsEng);
			MakeStandardState(choices);
			string persist = choices.Persist(wsManager);
			choices = InterlinLineChoices.Restore(persist, wsManager, m_lp, wsFrn, wsEng);

			Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[4].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[5].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[6].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[7].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[8].Flid);

			// Check writing systems assigned by default.
			Assert.AreEqual(wsFrn, choices[0].WritingSystem);
			Assert.AreEqual(wsEng, choices[5].WritingSystem);
			Assert.AreEqual(wsFrn, choices[2].WritingSystem);

			choices = new EditableInterlinLineChoices(m_lp, 0, wsEng);
			MakeStandardState(choices);
			choices.Add(InterlinLineChoices.kflidLexGloss, wsGer);
			Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[5].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[6].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[7].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[8].Flid);
			Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[9].Flid);

			Assert.AreEqual(wsGer, choices[4].WritingSystem);
		}
Example #10
0
		/// <summary>
		///
		/// </summary>
		/// <param name="data"></param>
		/// <param name="wsf"></param>
		/// <param name="proj"></param>
		/// <param name="defVern">Typically you want to pass in LgWritingSystemTags.kwsVernInParagraph</param>
		/// <param name="defAnalysis"></param>
		/// <returns></returns>
		public static InterlinLineChoices Restore(string data, ILgWritingSystemFactory wsf, ILangProject proj, int defVern, int defAnalysis)
		{
			Debug.Assert(defVern != 0);
			Debug.Assert(defAnalysis != 0);

			InterlinLineChoices result;
			string[] parts = data.Split(',');

			switch(parts[0])
			{
				case "InterlinLineChoices":
					result = new InterlinLineChoices(proj, defVern, defAnalysis);
					break;
				case "EditableInterlinLineChoices":
					result = new EditableInterlinLineChoices(proj, defVern, defAnalysis);
					break;
				default:
					throw new Exception("Unrecognised type of InterlinLineChoices: " + parts[0]);
			}
			for (int i = 1; i < parts.Length; i++)
			{
				string[] flidAndWs = parts[i].Split('%');
				if (flidAndWs.Length != 2)
					throw new Exception("Unrecognized InterlinLineSpec: " + parts[i]);
				int flid = Int32.Parse(flidAndWs[0]);
				int ws = wsf.GetWsFromStr(flidAndWs[1]);
				result.Add(flid, ws);
			}
			return result;
		}