ContainingObject() public method

ContainingObject info about anchor.
public ContainingObject ( int level ) : int
level int
return int
Esempio n. 1
0
		/// <summary>
		///  Create one from the specified end of the selection. If that end is not in a
		/// relevant property return null. Also return null if in the same StText as
		/// hvoOther.
		/// </summary>
		/// <param name="info"></param>
		/// <param name="fEndPoint"></param>
		static public TextStateInfo Create(TextSelInfo info, bool fEndPoint, FdoCache cache, int hvoOther)
		{
			int offset = 0; // in the SelInfoStack
			if (info.Tag(fEndPoint) == kflidContents)
			{
				if (info.Levels(fEndPoint) < 2)
					return null;
			}
			else
			{
				// One other case we need to handle is an embedded picture, because deleting it will modify the string.
				if (!info.IsPicture || info.Levels(false) < 3 || info.ContainingObjectTag(1) != kflidContents)
					return null;
				offset = 1; // one more level for the picture.
			}
			int hvoStText = info.ContainingObject(1 + offset, fEndPoint);
			if (hvoStText == hvoOther)
				return null;
			TextStateInfo result = new TextStateInfo();
			result.m_stText = CmObject.CreateFromDBObject(cache, hvoStText) as StText;;
			result.m_hvoPara = info.ContainingObject(offset, fEndPoint);
			foreach (StTxtPara para in result.m_stText.ParagraphsOS)
				result.m_paras.Add(new ParaStateInfo(para));
			result.m_tssAnchorText = cache.GetTsStringProperty(result.m_hvoPara, kflidContents);
			result.m_fCheckOtherParasOfText = true;
			return result;
		}
Esempio n. 2
0
		/// <summary>
		/// If the key is Enter, and the selection is in the contents of an StTxtPara, save information we will need
		/// to adjust things after the keypress executes.
		/// </summary>
		public void StartKeyPressed(KeyPressEventArgs e, Keys modifiers)
		{
			if (m_segDefn_note == 0) //|| !m_parentEditingHelper.Editable
				return; // in-memory testing or we can't edit the view anyways

			m_tsiOrig = new TextSelInfo(m_parentEditingHelper.EditedRootBox);
			// Enhance JohnT: maybe there is something useful we could do if the other end of the selection isn't in the
			// same text, but it's not enough to just get the objects after the end; that produces a crash.
			// A temporary patch is to not attempt this adjustment at all in this case. See TE-8416.
			// This means segmented BT is lost on the trailing part of the paragraph when Enter is used
			// to replace a range, also some precision is lost on scripture notes on that segment. See TE-8419.
			// It should be fixed in the re-architecture, where the delete is handled as a separate UOW.
			if (e.KeyChar == '\r'  && (modifiers & Keys.Shift) == 0 && m_tsiOrig.Selection != null &&
				m_tsiOrig.Tag(true) == kflidContents && m_tsiOrig.Tag(false) == kflidContents &&
				m_cache.GetOwnerOfObject(m_tsiOrig.Hvo(false)) == m_cache.GetOwnerOfObject(m_tsiOrig.Hvo(true)))
			{
				// collect annotations that come after the selection, so we can move those into the new paragraph.
				if (m_tsiOrig.Selection.EndBeforeAnchor)
				{
					// The 'end' of the selection (the boundary after which stuff will be moved)
					// is really the anchor.
					m_hvoParaSelEnd = m_tsiOrig.Hvo(false);
					m_ichSelEnd = m_tsiOrig.IchAnchor;
					m_hvoStText = m_tsiOrig.ContainingObject(1, false);
				}
				else
				{
					m_hvoParaSelEnd = m_tsiOrig.Hvo(true);
					m_ichSelEnd = m_tsiOrig.IchEnd;
					m_hvoStText = m_tsiOrig.ContainingObject(1, true);
				}
				m_ihvoParaPrev = m_cache.GetObjIndex(m_hvoStText, kflidParagraphs, m_hvoParaSelEnd);
				string sql = String.Format("select cba.BeginObject, cba.Id, cba.AnnotationType, cba.BeginOffset, cba.EndOffset from CmBaseAnnotation_ cba " +
					"where cba.BeginObject = {0} and " + "cba.BeginOffset >= {1} " +
					"order by cba.BeginOffset, cba.EndOffset", new object[] { m_hvoParaSelEnd, m_ichSelEnd });
				m_cbaHvosAffectedByEdit = GetCbasPotentiallyAffectedByTextEdit(m_cache, m_hvoParaSelEnd, sql);
				// we will need to subtract the difference from the selection's end.
				m_cchAdjust = -m_ichSelEnd;
				m_parasWeHaveAdjusted.Add(m_hvoParaSelEnd);
			}
			else
			{
				m_hvoStText = 0; // this functionality does not apply.
			}
			if (m_cbaHvosAffectedByEdit != null)
				m_movedAnnsFromAfterInsertBreak.AddRange(m_cbaHvosAffectedByEdit);

		}
Esempio n. 3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Called when [delete record].
		/// </summary>
		/// <param name="commandObject">The command object.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public override bool OnDeleteRecord(object commandObject)
		{
			CheckDisposed();

			if (m_rootb == null)
				MakeRoot();

			IVwSelection vwsel = m_rootb.Selection;
			if (vwsel == null)
				return false;
			ISilDataAccess sda = m_bv.SpecialCache;
			List<XmlNode> columns = m_xbvvc.ColumnSpecs;
			if (columns == null || columns.Count == 0)
				return false;		// Something is broken!

			TextSelInfo tsi = new TextSelInfo(m_rootb.Selection);
			if (tsi.ContainingObject(0) == XmlRDEBrowseViewVc.khvoNewItem)
			{
				ClearColumnStringsFromNewRow();
			}
			else
			{
				// 1. Remove the domain from the sense shown in the second column.
				// 2. Delete the sense iff it is now empty except for the definition shown.
				// 3. Delete the entry iff the entry now has no senses.
#if false // JohnT: don't understand the following code at all. In particular it makes no sense
				// to use ihvoRoot to index rgvsli; ihvoRoot is always zero in this view, it has only one root.
				// Possibly this was an unsuccessful attempt to adapt some generic code I wrote to this
				// particular application involving senses and entries?
				// I'm leaving it in existence for now in case the original author turns up and
				// can explain what he was getting at.
				int cLevels = vwsel.get_BoxDepth(true);
				int iLevel;
				int cBoxes = -1;
				int iBox = -1;
				VwBoxType[] rgvbt = new VwBoxType[cLevels];
				VwBoxType vbt = VwBoxType.kvbtUnknown;
				for (iLevel = 0; iLevel < cLevels; ++iLevel)
				{
					vbt = vwsel.get_BoxType(false, iLevel);
					if (vbt == VwBoxType.kvbtTableCell)
					{
						cBoxes = vwsel.get_BoxCount(true, iLevel);
						iBox = vwsel.get_BoxIndex(true, iLevel);
						break;
					}
				}
				Debug.Assert(cBoxes == 2);
				Debug.Assert(iBox != -1);
				int hvoEntry;
				int hvoSense;
				if (iBox == 0)
				{
					hvoEntry = rgvsli[ihvoRoot].hvo;
					IVwSelection vwsel2 = m_rootb.MakeSelInBox(vwsel, false, iLevel, 1,
						true, false, false);
					SelLevInfo[] rgvsli2 = SelLevInfo.AllTextSelInfo(vwsel, vwsel2.CLevels(false) - 1,
						out ihvoRoot, out tag, out cpropPrevious, out ichAnchor, out ichEnd,
						out ws, out fAssocPrev, out ihvoEnd, out ttp);
					hvoSense = rgvsli2[ihvoRoot].hvo;
				}
				else
				{
					hvoSense = rgvsli[ihvoRoot].hvo;
					IVwSelection vwsel2 = m_rootb.MakeSelInBox(vwsel, false, iLevel, 0,
						true, false, false);
					SelLevInfo[] rgvsli2 = SelLevInfo.AllTextSelInfo(vwsel, vwsel2.CLevels(false) - 1,
						out ihvoRoot, out tag, out cpropPrevious, out ichAnchor, out ichEnd,
						out ws, out fAssocPrev, out ihvoEnd, out ttp);
					hvoEntry = rgvsli2[ihvoRoot].hvo;
				}
#else
				int cvsli = tsi.Levels(false) - 1;
				int tag = tsi.ContainingObjectTag(cvsli - 1);
				Debug.Assert(cvsli >= 1); // there should be at least one level (each row is a sense)
				// The outermost thing in the VC is a display of all the senses of the root domain.
				// Therefore the last thing in rgvsli is always the information identifying the sense we
				// want to process.
				int hvoSense = tsi.ContainingObject(cvsli - 1);
				int hvoEntry = m_fdoCache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(hvoSense).Owner.Hvo;
#endif
				// If this was an editable object, it no longer is, because it's about to no longer exist.
				RDEVc.EditableObjectsRemove(hvoSense);

				var le = m_fdoCache.ServiceLocator.GetInstance<ILexEntryRepository>().GetObject(hvoEntry);
				var ls = m_fdoCache.ServiceLocator.GetInstance<ILexSenseRepository>().GetObject(hvoSense);
				string sUndo = XMLViewsStrings.ksUndoDeleteRecord;
				string sRedo = XMLViewsStrings.ksRedoDeleteRecord;
				UndoableUnitOfWorkHelper.Do(sUndo, sRedo, Cache.ActionHandlerAccessor, () =>
				{
					ls.SemanticDomainsRC.Remove(Cache.ServiceLocator.GetInstance<ICmSemanticDomainRepository>().GetObject(m_hvoRoot));
					if (ls.SemanticDomainsRC.Count == 0 &&
					ls.AnthroCodesRC.Count == 0 &&
					ls.AppendixesRC.Count == 0 &&
					ls.DomainTypesRC.Count == 0 &&
					ls.ThesaurusItemsRC.Count == 0 &&
					ls.UsageTypesRC.Count == 0)
					{
						bool fKeep = false;
						ITsString tss = ls.Gloss.AnalysisDefaultWritingSystem;
						if (tss != null && tss.Length > 0)
							fKeep = true;
						if (!fKeep)
						{
							tss = ls.Gloss.UserDefaultWritingSystem;
							if (tss != null && tss.Length > 0)
								fKeep = true;
						}
						if (!fKeep)
						{
							tss = ls.Gloss.VernacularDefaultWritingSystem;
							if (tss != null && tss.Length > 0)
								fKeep = true;
						}
						if (!fKeep)
						{
							tss = ls.Definition.VernacularDefaultWritingSystem;
							if (tss != null && tss.Length > 0)
								fKeep = true;
						}
						if (!fKeep)
						{
							tss = ls.DiscourseNote.AnalysisDefaultWritingSystem;
							if (tss != null && tss.Length > 0)
								fKeep = true;
						}
						if (!fKeep)
						{
							tss = ls.DiscourseNote.UserDefaultWritingSystem;
							if (tss != null && tss.Length > 0)
								fKeep = true;
						}
						if (!fKeep)
						{
							tss = ls.DiscourseNote.VernacularDefaultWritingSystem;
							if (tss != null && tss.Length > 0)
								fKeep = true;
						}
						if (!fKeep)
						{
							tss = ls.ScientificName;
							if (tss != null && tss.Length > 0)
								fKeep = true;
						}
						if (!fKeep)
						{
							tss = ls.Source;
							if (tss != null && tss.Length > 0)
								fKeep = true;
						}
						if (!fKeep)
						{
							le.SensesOS.Remove(ls);
							ls = null;
						}
					}
					if (ls == null && le.SensesOS.Count == 0)
					{
						le.Delete();
						le = null;
					}
				});
			}
			return true;
		}