SIL.FieldWorks.IText.InterlinDocForAnalysis.AddNote C# (CSharp) Метод

AddNote() публичный Метод

public AddNote ( Command command ) : void
command Command
Результат void
		public void AddNote(Command command)
		{
			IVwSelection sel = MakeSandboxSel();
			// If there's no sandbox selection, there may be one in the site itself, perhaps in another
			// free translation.
			if (sel == null && RootBox != null)
				sel = RootBox.Selection;
			if (sel == null)
				return; // Enhance JohnT: give an error, or disable the command.
			int cvsli = sel.CLevels(false);
			cvsli--; // CLevels includes the string property itself, but AllTextSelInfo doesn't need it.

			// Out variables for AllTextSelInfo.
			int ihvoRoot;
			int tagTextProp;
			int cpropPrevious;
			int ichAnchor;
			int ichEnd;
			int ws;
			bool fAssocPrev;
			int ihvoEnd;
			ITsTextProps ttpBogus;
			// Main array of information retrived from sel that made combo.
			SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli,
				out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
				out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);

			// Identify the segment.
			// This is important because although we are currently displaying just an StTxtPara,
			// eventually it might be part of a higher level structure. We want this to work
			// no matter how much higher level structure there is.
			int itagSegments = -1;
			for (int i = rgvsli.Length; --i >= 0; )
			{
				if (rgvsli[i].tag == StTxtParaTags.kflidSegments)
				{
					itagSegments = i;
					break;
				}
			}
			if (itagSegments == -1)
				return; // Enhance JohnT: throw? disable command? Give an error?

			int hvoSeg = rgvsli[itagSegments].hvo;
			var seg = Cache.ServiceLocator.GetObject(hvoSeg) as ISegment;
			UndoableUnitOfWorkHelper.Do(command.UndoText, command.RedoText, Cache.ActionHandlerAccessor,
				() =>
				{
					var note = Cache.ServiceLocator.GetInstance<INoteFactory>().Create();
					seg.NotesOS.Add(note);
				});

			TryHideFocusBoxAndUninstall();
			if (m_vc.LineChoices.IndexOf(InterlinLineChoices.kflidNote) < 0)
			{
				m_vc.LineChoices.Add(InterlinLineChoices.kflidNote);
				PersistAndDisplayChangedLineChoices();
			}

			// Now try to make a new selection in the note we just made.
			// The elements of rgvsli from itagSegments onwards form a path to the segment.
			// In the segment we want the note propery, specifically the new one we just made.
			// We want to select at the start of it.
			// LT-12613: We're adding an extra segment here:
			SelLevInfo[] rgvsliNew = new SelLevInfo[rgvsli.Length - itagSegments + 2];
			for (int i = 2; i < rgvsliNew.Length; i++)
				rgvsliNew[i] = rgvsli[i + itagSegments - 2];
			rgvsliNew[0].ihvo = seg.NotesOS.Count - 1;
			rgvsliNew[0].tag = SegmentTags.kflidNotes;
			rgvsliNew[0].cpropPrevious = 0;
			// LT-12613: Define extra segment here:
			rgvsliNew[1].ihvo = 0;
			rgvsliNew[1].tag = Cache.MetaDataCacheAccessor.GetFieldId2(CmObjectTags.kClassId, "Self", false);
			rgvsliNew[1].cpropPrevious = 0;
			RootBox.MakeTextSelInObj(0, rgvsliNew.Length, rgvsliNew, 0, null, true, true, false, false, true);
			// Don't steal the focus from another window.  See FWR-1795.
			if (ParentForm == Form.ActiveForm)
				Focus(); // So we can actually see the selection we just made.
		}
InterlinDocForAnalysis