Esempio n. 1
0
		/// <summary>
		/// Try to find a WfiWordform object corresponding the the focus selection.
		/// If successful return its guid, otherwise, return Guid.Empty.
		/// </summary>
		/// <returns></returns>
		internal static Guid ActiveWordform(FdoCache cache, Mediator mediator)
		{
			IApp app = mediator.PropertyTable.GetValue("App") as IApp;
			if (app == null)
				return Guid.Empty;
			IFwMainWnd window = app.ActiveMainWindow as IFwMainWnd;
			if (window == null)
				return Guid.Empty;
			IRootSite activeView = window.ActiveView;
			if (activeView == null)
				return Guid.Empty;
			List<IVwRootBox> roots = activeView.AllRootBoxes();
			if (roots.Count < 1)
				return Guid.Empty;
			SelectionHelper helper = SelectionHelper.Create(roots[0].Site);
			if (helper == null)
				return Guid.Empty;
			ITsString word = helper.SelectedWord;
			if (word == null || word.Length == 0)
				return Guid.Empty;
#if WANTPORT // FWR-2784
			int hvoWordform = cache.LangProject.WordformInventoryOA.GetWordformId(word);
			if (hvoWordform == 0 || cache.IsDummyObject(hvoWordform))
				return Guid.Empty;
			return cache.GetGuidFromId(hvoWordform);
#else
			return Guid.Empty;
#endif
		}
Esempio n. 2
0
		/// <summary>
		///
		/// </summary>
		/// <param name="fdoCache"></param>
		/// <param name="dummyAnnHvo"></param>
		/// <returns></returns>
		public static ICmBaseAnnotation ConvertBaseAnnotationToReal(FdoCache fdoCache, int dummyAnnHvo)
		{
			using (SuppressSubTasks supressActionHandler = new SuppressSubTasks(fdoCache, true))
			{
				Debug.Assert(fdoCache.IsDummyObject(dummyAnnHvo));
				if (!fdoCache.IsDummyObject(dummyAnnHvo) ||
					fdoCache.GetClassOfObject(dummyAnnHvo) != CmBaseAnnotation.kclsidCmBaseAnnotation)
				{
					return null; // indicate no change.
				}
				ISilDataAccess sda = fdoCache.MainCacheAccessor;
				ICmBaseAnnotation cbaDummy = (ICmBaseAnnotation)CmObject.CreateFromDBObject(fdoCache, dummyAnnHvo, false);
				ICmBaseAnnotation cbaReal = CreateRealAnnotation(fdoCache, cbaDummy.AnnotationTypeRAHvo, cbaDummy.InstanceOfRAHvo,
					cbaDummy.BeginObjectRAHvo, cbaDummy.Flid, cbaDummy.BeginOffset, cbaDummy.EndOffset);
				cbaReal.WritingSystemRAHvo = cbaDummy.WritingSystemRAHvo;
				int hvoRealAnn = cbaReal.Hvo;

				// transfer any default analysis (guess)
				int ktagTwficDefault = StTxtPara.TwficDefaultFlid(fdoCache);
				int hvoTwficAnalysisGuess = fdoCache.GetObjProperty(dummyAnnHvo, ktagTwficDefault);
				if (hvoTwficAnalysisGuess != 0)
				{
					fdoCache.VwCacheDaAccessor.CacheObjProp(hvoRealAnn, ktagTwficDefault, hvoTwficAnalysisGuess);
				}
				int textSegType = CmAnnotationDefn.TextSegment(fdoCache).Hvo;
				int twficType = CmAnnotationDefn.Twfic(fdoCache).Hvo;
				if (cbaDummy.AnnotationTypeRAHvo == twficType)
					StTxtPara.CacheReplaceTWFICAnnotation(fdoCache, dummyAnnHvo, hvoRealAnn);
				else if (cbaDummy.AnnotationTypeRAHvo == textSegType)
					StTxtPara.CacheReplaceTextSegmentAnnotation(fdoCache, dummyAnnHvo, hvoRealAnn);
				else
					Debug.Assert(true, "CacheReplace does not yet support annotation type " + cbaDummy.AnnotationTypeRAHvo);
				// now clear it from the cache, since we're done with it.
				if (fdoCache.ActionHandlerAccessor != null)
					fdoCache.ActionHandlerAccessor.AddAction(new ClearInfoOnCommitUndoAction(fdoCache, dummyAnnHvo));
				return cbaReal;
			}
		}
Esempio n. 3
0
		/// <summary>
		///
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="form"></param>
		/// <param name="ws"></param>
		/// <param name="fMakeReal">if true, returns a real wordform.
		/// if false, it creates/returns a dummy if it can't find a real one.</param>
		/// <returns></returns>
		public static int FindOrCreateWordform(FdoCache cache, string form, int ws, bool fMakeReal)
		{
			int wfHvo = FindExistingWordform(form, ws, cache);
			IWfiWordform wf = null;
			if (fMakeReal && cache.IsDummyObject(wfHvo))
			{
				// convert this to a real object.
				wf = CmObject.ConvertDummyToReal(cache, wfHvo) as IWfiWordform;
				wfHvo = wf.Hvo;
			}
			if (wfHvo == 0)
			{
				// Give up looking for one, and just make a new one.
				if (fMakeReal)
				{
					wf = cache.LangProject.WordformInventoryOA.AddRealWordform(form, ws);
					wfHvo = wf.Hvo;
					Debug.Assert(wfHvo > 0);
				}
				else
				{
					wfHvo = cache.LangProject.WordformInventoryOA.AddDummyWordform(CreateWordformTss(form, ws));
				}
			}
			return wfHvo;
		}
Esempio n. 4
0
		/// <summary>
		///
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvoAnnotation"></param>
		/// <param name="ichMin"></param>
		/// <param name="ichLim"></param>
		/// <param name="hvoPara"></param>
		/// <param name="fNewAnnotation"></param>
		public static void SetCbaFields(FdoCache cache, int hvoAnnotation, int ichMin, int ichLim, int hvoPara, bool fNewAnnotation)
		{
			if (ichMin < 0 || ichLim < 0)
				throw new ArgumentException("new offsets (" + ichMin + ", " + ichLim + ") will extend cba offsets beyond paragraph limits.");
			bool fIsDummyAnnotation = cache.IsDummyObject(hvoAnnotation);
			// Adjust the character offsets whether an old or new annotation, but to reduce database
			// traffic, only if they've changed.
			ISilDataAccess sda = cache.MainCacheAccessor;
			IVwCacheDa cda = cache.VwCacheDaAccessor;
			if (fNewAnnotation || sda.get_IntProp(hvoAnnotation, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset) != ichMin)
			{
				if (!fIsDummyAnnotation)
					sda.SetInt(hvoAnnotation, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset, ichMin);
				else
					cda.CacheIntProp(hvoAnnotation, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset, ichMin);
			}
			if (fNewAnnotation || sda.get_IntProp(hvoAnnotation, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset) != ichLim)
			{
				if (!fIsDummyAnnotation)
					sda.SetInt(hvoAnnotation, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset, ichLim);
				else
					cda.CacheIntProp(hvoAnnotation, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset, ichLim);
			}
			if (fNewAnnotation || sda.get_ObjectProp(hvoAnnotation, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginObject) != hvoPara)
			{
				// They're always the same, so we can just set both.
				if (!fIsDummyAnnotation)
				{
					sda.SetObjProp(hvoAnnotation, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginObject, hvoPara);
					sda.SetObjProp(hvoAnnotation, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndObject, hvoPara);
				}
				else
				{
					cda.CacheObjProp(hvoAnnotation, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginObject, hvoPara);
					cda.CacheObjProp(hvoAnnotation, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndObject, hvoPara);
				}
			}
		}
Esempio n. 5
0
		/// <summary>
		///
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvoAnnType"></param>
		/// <param name="hvoInstanceOf"></param>
		/// <param name="hvoBeginObject"></param>
		/// <param name="flid"></param>
		/// <param name="beginOffset"></param>
		/// <param name="endOffset"></param>
		/// <returns></returns>
		public static ICmBaseAnnotation CreateRealAnnotation(FdoCache cache, int hvoAnnType, int hvoInstanceOf, int hvoBeginObject, int flid, int beginOffset, int endOffset)
		{
			// This stored procedure is optimized to create an annotation with exactly the information we need here.
			//			string sql = "exec CreateCmBaseAnnotation " + cache.LangProject.Hvo + "," + hvoAnnType + "," + hvoInstanceOf + "," + hvoBeginObject
			//				+ "," + flid +  "," + beginOffset + "," + endOffset;
			//	@Owner int = null,
			//	@annotationType int = null,
			//	@InstanceOf int = null,
			//	@BeginObject int = null,
			//	@CmBaseAnnotation_Flid int = 0,
			//	@CmBaseAnnotation_BeginOffset int = 0,
			//	@CmBaseAnnotation_EndOffset int = 0
			//			DbOps.ExecuteStoredProc(cache, sql, null);
			// can we assume that the object will be inserted at the end?

			// Since we only create real annotations upon a 'confirm', using CmObject shouldn't be too expensive.
			// The advantage of doing it this way is that we readily have the new hvo, and it does the PropChanged for us.
			// (I think CreateCmBaseAnnotation would need to be enhanced to return the new hvo).
			ICmBaseAnnotation cba = CreateUnownedCba(cache);
			cba.Flid = flid;
			cba.AnnotationTypeRAHvo = hvoAnnType;
			if (cache.IsDummyObject(hvoInstanceOf))
			{
				// convert this to a real object.
				ICmObject realInstanceOf = CmObject.ConvertDummyToReal(cache, hvoInstanceOf);
				hvoInstanceOf = realInstanceOf.Hvo;
			}
			Debug.Assert(hvoInstanceOf >= 0, "dummy objects cannot be referenced by a real annotation");
			cba.InstanceOfRAHvo = hvoInstanceOf;
			SetCbaFields(cache, cba.Hvo, beginOffset, endOffset, hvoBeginObject, true);
			return cba;
		}
Esempio n. 6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get all annotations that refer to the given object in the InstanceOf property,
		/// and which do not have null for the BeginObject property.
		/// </summary>
		/// <param name="cache">The cache to use.</param>
		/// <param name="hvo">The object that may have annotations.</param>
		/// <returns>A List that contains zero, or more, integers for the values in the InstanceOf property.</returns>
		/// ------------------------------------------------------------------------------------
		public static List<int> AnnotationsForInstanceOf(FdoCache cache, int hvo)
		{
			Debug.Assert(!cache.IsDummyObject(hvo), "Currently only handles real objects.");
			string qry = " select cba.Id" +
				" from CmBaseAnnotation_ cba" +
				" where cba.InstanceOf=? AND cba.BeginObject is not null";
			return DbOps.ReadIntsFromCommand(cache, qry, hvo);
		}
Esempio n. 7
0
		/// <summary>
		/// same as SetCbaFields, except also sets the hvoInstanceOf.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvoAnnotation"></param>
		/// <param name="ichMin"></param>
		/// <param name="ichLim"></param>
		/// <param name="hvoPara"></param>
		/// <param name="hvoInstanceOf"></param>
		/// <param name="fNewAnnotation"></param>
		public static void SetCbaFields(FdoCache cache, int hvoAnnotation, int ichMin, int ichLim, int hvoPara, int hvoInstanceOf, bool fNewAnnotation)
		{
			ISilDataAccess sda = cache.MainCacheAccessor;
			IVwCacheDa cda = cache.VwCacheDaAccessor;
			if (fNewAnnotation || sda.get_ObjectProp(hvoAnnotation, (int)CmBaseAnnotation.CmAnnotationTags.kflidInstanceOf) != hvoInstanceOf)
			{
				if (cache.IsDummyObject(hvoAnnotation))
					cda.CacheObjProp(hvoAnnotation, (int)CmAnnotation.CmAnnotationTags.kflidInstanceOf, hvoInstanceOf);
				else
					sda.SetObjProp(hvoAnnotation, (int)CmAnnotation.CmAnnotationTags.kflidInstanceOf, hvoInstanceOf);
			}
			CmBaseAnnotation.SetCbaFields(cache, hvoAnnotation, ichMin, ichLim, hvoPara, fNewAnnotation);
		}
Esempio n. 8
0
		/// <summary>
		/// get the ws at the twfic's BeginOffset in its paragraph.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="hvoTwfic">The hvo twfic.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public static int GetTwficWs(FdoCache cache, int hvoTwfic)
		{
			Debug.Assert(cache.IsValidObject(hvoTwfic, CmBaseAnnotation.kClassId),
				String.Format("expected valid hvo({0}).", hvoTwfic));
			if (hvoTwfic <= 0 && !cache.IsDummyObject(hvoTwfic))
				throw new ArgumentException(String.Format("expected valid hvo({0}).", hvoTwfic));
			int hvoPara = cache.GetObjProperty(hvoTwfic,
				(int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginObject);
			int ichBeginOffset = cache.GetIntProperty(hvoTwfic,
				(int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset);
			int ws = GetWsAtParaOffset(cache, hvoPara, ichBeginOffset);
			return ws;
		}
Esempio n. 9
0
		/// <summary>
		/// Load the information we need to display a paragraph of free (back) translations: for each paragraph
		/// load its segments, for each segment load the free translation. We assume the segments
		/// property of each paragraph already exists, and want the BeginOffset, EndOffset, BeginObject, and Free Translation
		/// properties of each segment, and the Comment of the FT.
		/// Also ensures all the segments are real and have an FT annotation.
		/// </summary>
		/// <param name="paragraphs"></param>
		/// <param name="cache"></param>
		/// <param name="ws"></param>
		public static void LoadSegmentFreeTranslations(int[] paragraphs, FdoCache cache, int ws)
		{
			int kflidSegments = SegmentsFlid(cache);
			List<int> segments = new List<int>();
			foreach (int hvoPara in paragraphs)
			{
				int[] segs = cache.GetVectorProperty(hvoPara, kflidSegments, true);
				int iseg = 0;
				foreach (int hvoSeg in segs)
				{
					int hvoRealSeg = hvoSeg;
					if (cache.IsDummyObject(hvoSeg))
						hvoRealSeg = CmBaseAnnotation.ConvertBaseAnnotationToReal(cache, hvoSeg).Hvo;
					segments.Add(hvoRealSeg);
					segs[iseg++] = hvoRealSeg;
				}
				// Update the list.
				cache.VwCacheDaAccessor.CacheVecProp(hvoPara, kflidSegments, segs, segs.Length);
			}

			if (segments.Count == 0)
				return; // somehow we can have none, and then the query fails.

			int hvoFt = cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation);
			string ids = JoinIds(segments.ToArray(), ",");
			int kflidFT = SegmentFreeTranslationFlid(cache);

			if (cache.DatabaseAccessor != null)
			{
				string sql =
					@"select seg.id, seg.BeginObject, seg.BeginOffset, seg.EndOffset, ft.id, ft.class$, ft.UpdStmp, ftc.Txt, ftc.Fmt from CmBaseAnnotation seg
					join CmIndirectAnnotation_AppliesTo ftseg on ftseg.Dst = seg.id
					join CmIndirectAnnotation_ ft on ft.id = ftseg.Src and ft.AnnotationType = " +
					hvoFt + @"
					left outer join CmAnnotation_Comment ftc on ftc.Obj = ft.id and ftc.ws = " + ws +
					@"
					where seg.id in (" + ids + ")";
				IDbColSpec dcs = DbColSpecClass.Create();
				dcs.Push((int) DbColType.koctBaseId, 0, 0, 0); // ID (of segment)
				dcs.Push((int) DbColType.koctObj, 1, (int) CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginObject, 0);
				dcs.Push((int) DbColType.koctInt, 1, (int) CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset, 0);
				dcs.Push((int) DbColType.koctInt, 1, (int) CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset, 0);
				dcs.Push((int) DbColType.koctObj, 1, kflidFT, 0); // Free translation indirect annotation
				dcs.Push((int) DbColType.koctInt, 5, (int) CmObjectFields.kflidCmObject_Class, 0); // class of FT annotation
				dcs.Push((int) DbColType.koctTimeStamp, 5, 0, 0); // timestamp of FT annotation
				dcs.Push((int)DbColType.koctMlsAlt, 5, (int)CmAnnotation.CmAnnotationTags.kflidComment, ws);
				dcs.Push((int)DbColType.koctFmt, 5, (int)CmAnnotation.CmAnnotationTags.kflidComment, ws);
				cache.LoadData(sql, dcs, 0);
			}

			// Make sure each segment has a free translation.
			foreach (int hvoSeg in segments)
			{
				int hvoFT = cache.GetObjProperty(hvoSeg, kflidFT);
				if (hvoFT == 0)
				{
					ICmIndirectAnnotation ann = CmIndirectAnnotation.CreateUnownedIndirectAnnotation(cache);
					ann.AppliesToRS.Append(hvoSeg);
					ann.AnnotationTypeRAHvo = hvoFt;
					cache.VwCacheDaAccessor.CacheObjProp(hvoSeg, kflidFT, ann.Hvo);
				}
			}
		}
Esempio n. 10
0
		/// <summary>
		/// Find a dummy segment wordform annotation, and replace with a real annotation it in the cache.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvoOldAnnotation"></param>
		/// <param name="hvoNewAnnotation"></param>
		/// <returns>if nonzero, this will be inserted in place of the old one.
		/// if zero, we'll simply delete the old one.</returns>
		internal static void CacheReplaceTWFICAnnotation(FdoCache cache, int hvoOldAnnotation, int hvoNewAnnotation)
		{
			int ktagSegmentForms = CmBaseAnnotation.SegmentFormsFlid(cache);
			int kflidOccurrences = WfiWordform.OccurrencesFlid(cache);
			ISilDataAccess sda = cache.MainCacheAccessor;
			int hvoParaSeg = 0;
			int iParaSeg = -1;
			bool fIsFirstTwfic = false;
			int iSegForm = StTxtPara.TwficSegmentLocation(cache, hvoOldAnnotation, out hvoParaSeg, out iParaSeg, out fIsFirstTwfic);
			IVwCacheDa cda = cache.VwCacheDaAccessor;
			int[] newItems = hvoNewAnnotation != 0 ? new int[] { hvoNewAnnotation } : new int[0];
			if (hvoParaSeg != 0 && iSegForm >= 0)
			{
				CacheReplaceOneUndoAction cacheReplaceSegmentFormAction = new CacheReplaceOneUndoAction(cache, hvoParaSeg,
					ktagSegmentForms, iSegForm, iSegForm + 1, newItems);
				cacheReplaceSegmentFormAction.DoIt();
				if (cache.ActionHandlerAccessor != null)
				{
					cache.ActionHandlerAccessor.AddAction(cacheReplaceSegmentFormAction);
				}
			}
			int hvoOldWordform = 0;
			if (WfiWordform.TryGetWfiWordformFromInstanceOf(cache, hvoOldAnnotation, out hvoOldWordform))
			{
				// replace the dummy annotation on its wordform, if we haven't already.
				List<int> dummyAnnotations = new List<int>(cache.GetVectorProperty(hvoOldWordform, kflidOccurrences, true));
				int iAnn = dummyAnnotations.IndexOf(hvoOldAnnotation);
				if (iAnn >= 0)
				{
					CacheReplaceOneUndoAction cacheReplaceOccurrenceAction = new CacheReplaceOneUndoAction(cache, hvoOldWordform,
						kflidOccurrences, iAnn, iAnn + 1, newItems);
					cacheReplaceOccurrenceAction.DoIt();
					if (cache.ActionHandlerAccessor != null)
					{
						cache.ActionHandlerAccessor.AddAction(cacheReplaceOccurrenceAction);
					}
				}
			}
			// try converting the owning segment to real, if we're converting the twfic to real.
			if (hvoOldAnnotation != 0 && hvoNewAnnotation != 0 &&
				cache.IsDummyObject(hvoOldAnnotation) && !cache.IsDummyObject(hvoNewAnnotation) &&
				cache.IsDummyObject(hvoParaSeg))
			{
				hvoParaSeg = CmBaseAnnotation.ConvertBaseAnnotationToReal(cache, hvoParaSeg).Hvo;
			}
		}
Esempio n. 11
0
			/// <summary>
			/// Return the segment range in terms of the segment indexes of the BeginObject segment property of the given hvoCba.
			/// </summary>
			/// <param name="cache"></param>
			/// <param name="hvoCba"></param>
			/// <param name="iBeginSegment">zero-based index into segments</param>
			/// <param name="iEndSegment">zero-based into segments</param>
			/// <returns></returns>
			static public bool TryGetSegmentRange(FdoCache cache, int hvoCba,
				out int iBeginSegment, out int iEndSegment)
			{
				iBeginSegment = -1;
				iEndSegment = -1;
				int[] segments = null;
				// if it's a twfic type, then use twfic info, otherwise find a segment range.
				ICmBaseAnnotation cba = CmBaseAnnotation.CreateFromDBObject(cache, hvoCba);
				int hvoPara = cba.BeginObjectRAHvo;
				IVwVirtualHandler vh;
				// first try to get the segments from our Segments virtual handler
				// if that has not been loaded for the paragraph, try SegmentsIgnoreTwfics
				// to save time.
				if (cache.TryGetVirtualHandler(StTxtPara.SegmentsFlid(cache), out vh) &&
					(vh as BaseFDOPropertyVirtualHandler).IsPropInCache(cache.MainCacheAccessor, hvoPara, 0))
				{
					if (cba.AnnotationTypeRAHvo != 0)
					{
						StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(cache, hvoCba);
						if (twficInfo.SegmentIndex >= 0)
						{
							iBeginSegment = twficInfo.SegmentIndex;		// return zero-based index.
						}
						else if (!cache.IsDummyObject(hvoCba))
						{
							int segIndexLogical;
							string sql = string.Format("exec GetSegmentIndex {0}, {1}", hvoCba, CmAnnotationDefn.TextSegment(cache).Hvo);
							DbOps.ReadOneIntFromCommand(cache, sql, null, out segIndexLogical);
							if (segIndexLogical > 0)
								iBeginSegment = segIndexLogical - 1;	 // subtract 1 to get a zero-based index.
						}
					}
					if (iBeginSegment < 0)
						segments = cache.GetVectorProperty(hvoPara, vh.Tag, true);
				}
				else if (cache.TryGetVirtualHandler(StTxtPara.SegmentsIgnoreTwficsFlid(cache), out vh))
				{
					segments = cache.GetVectorProperty(hvoPara, vh.Tag, true);
				}
				if (iBeginSegment < 0)
				{
					// this is annotation into a paragraph (but may not be a twfic or exist in SegForms).
					// if it's not a twfic, find a segment range.
					ISilDataAccess sda = cache.MainCacheAccessor;
					int ihvoSeg = 0;
					int cbaBeginOffset = cba.BeginOffset;
					int cbaEndOffset = cba.EndOffset;
					for (; ihvoSeg < segments.Length; ihvoSeg++)
					{
						int segEndOffset = sda.get_IntProp(segments[ihvoSeg], (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset);
						if (segEndOffset <= cbaBeginOffset)
						{
							continue;
						}
						else if (iBeginSegment < 0)
						{
							iBeginSegment = ihvoSeg;
						}
						if (segEndOffset > cbaEndOffset)
						{
							iEndSegment = ihvoSeg;
							break; // we've passed our annotation's EndOffset, so the previous segment is the last one in range.
						}
					}
					// ihvoSeg should now be one index passed the segment in our range. this eguals the logical segment number.
					if (iBeginSegment >= 0 && iEndSegment == -1)
					{
						iEndSegment = ihvoSeg < segments.Length ? ihvoSeg - 1 : segments.Length - 1;
					}
				}
				return iBeginSegment >= 0;
			}
Esempio n. 12
0
		/// <summary>
		/// Try to find a WfiWordform object corresponding the the focus selection.
		/// If successful return its guid, otherwise, return Guid.Empty.
		/// </summary>
		/// <returns></returns>
		internal static Guid ActiveWordform(FdoCache cache)
		{
			if (!(FwApp.App is FwXApp))
				return Guid.Empty;
			FwXWindow window = (FwApp.App as FwXApp).ActiveMainWindow as FwXWindow;
			if (window == null)
				return Guid.Empty;
			IRootSite activeView = window.ActiveView;
			if (activeView == null)
				return Guid.Empty;
			List<IVwRootBox> roots = activeView.AllRootBoxes();
			if (roots.Count < 1)
				return Guid.Empty;
			SelectionHelper helper = SelectionHelper.Create(roots[0].Site);
			if (helper == null)
				return Guid.Empty;
			ITsString word = helper.SelectedWord;
			if (word == null || word.Length == 0)
				return Guid.Empty;
			int hvoWordform = cache.LangProject.WordformInventoryOA.GetWordformId(word);
			if (hvoWordform == 0 || cache.IsDummyObject(hvoWordform))
				return Guid.Empty;
			return cache.GetGuidFromId(hvoWordform);
		}
Esempio n. 13
0
		private bool SetDlgInfo1(Mediator mediator, XmlNode configurationParameters)
		{
			using (new WaitCursor(this))
			{
				m_mediator = mediator;
				m_configurationParameters = configurationParameters;

				m_btnRefresh.Image = SIL.FieldWorks.Resources.ResourceHelper.RefreshIcon;

				m_rbDiscardAnalyses.Checked = m_mediator.PropertyTable.GetBoolProperty("RemoveAnalyses", true);
				m_rbKeepAnalyses.Checked = !m_rbDiscardAnalyses.Checked;
				m_rbDiscardAnalyses.Click += new EventHandler(m_rbDiscardAnalyses_Click);
				m_rbKeepAnalyses.Click += new EventHandler(m_rbDiscardAnalyses_Click);

				m_cbUpdateLexicon.Checked = m_mediator.PropertyTable.GetBoolProperty("UpdateLexiconIfPossible", true);
				m_cbCopyAnalyses.Checked = m_mediator.PropertyTable.GetBoolProperty("CopyAnalysesToNewSpelling", true);
				m_cbCopyAnalyses.Click += new EventHandler(m_cbCopyAnalyses_Click);
				m_cbMaintainCase.Checked = m_mediator.PropertyTable.GetBoolProperty("MaintainCaseOnChangeSpelling", true);
				m_cbMaintainCase.Click += new EventHandler(m_cbMaintainCase_Click);
				m_cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache");
				m_cbNewSpelling.TextBox.MaxLength = m_cache.MaxFieldLength((int) WfiWordform.WfiWordformTags.kflidForm);
				if (m_cache.IsDummyObject(m_srcwfiWordform.Hvo))
				{
					m_srcwfiWordform = (IWfiWordform)(m_cache.LangProject.WordformInventoryOA as WordformInventory).ConvertDummyToReal(WordformInventory.ConcordanceWordformsFlid(m_cache), m_srcwfiWordform.Hvo);
					// wfClerk now has the defunct dummy wf, so it needs to be updated to include the new real wf.
					if (m_wfClerk != null)
						m_wfClerk.UpdateList(true);
				}

				// We need to use the 'best vern' ws,
				// since that is what is showing in the Words-Analyses detail edit control.
				// Access to this respeller dlg is currently (Jan. 2008) only via a context menu in the detail edit pane.
				// The user may be showing multiple wordform WSes in the left hand browse view,
				// but we have no way of knowing if the user thinks one of those alternatives is wrong without asking.
				m_vernWs = m_cache.LangProject.ActualWs(
					LangProject.kwsFirstVern,
					m_srcwfiWordform.Hvo,
					(int)WfiWordform.WfiWordformTags.kflidForm);
				// Bail out if no vernacular writing system was found (see LT-8892).
				Debug.Assert(m_vernWs != 0);
				if (m_vernWs == 0)
					return false;
				// Bail out, rather than run into a null reference exception.
				// (Should fix LT-7666.)
				if (m_srcwfiWordform.Form.GetAlternativeTss(m_vernWs) == null || m_srcwfiWordform.Form.GetAlternativeTss(m_vernWs).Length == 0)
					return false;

				m_cbNewSpelling.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor;
				m_cbNewSpelling.WritingSystemCode = m_vernWs;
				m_cbNewSpelling.StyleSheet = FontHeightAdjuster.StyleSheetFromMediator(m_mediator);
				Debug.Assert(m_cbNewSpelling.StyleSheet != null); // if it is we get a HUGE default font (and can't get the correct size)
				if (m_cbNewSpelling.WritingSystemFactory.get_EngineOrNull(m_vernWs).RightToLeft)
				{
					m_cbNewSpelling.RightToLeft = RightToLeft.Yes;
				}
				m_cbNewSpelling.Tss = m_srcwfiWordform.Form.GetAlternativeTss(m_vernWs);
				m_cbNewSpelling.AdjustForStyleSheet(this, null, m_cbNewSpelling.StyleSheet);
				if (!Application.RenderWithVisualStyles)
					m_cbNewSpelling.Padding = new Padding(1, 2, 1, 1);

				SetSuggestions();

				m_btnApply.Enabled = false;
				m_cbNewSpelling.TextChanged += new EventHandler(m_dstWordform_TextChanged);

				// Setup source browse view.
				XmlNode toolNode = configurationParameters.SelectSingleNode("controls/control[@id='srcSentences']/parameters");
				m_srcClerk = RecordClerkFactory.CreateClerk(m_mediator, toolNode);
				m_srcClerk.OwningObject = m_srcwfiWordform;
				m_sourceSentences.Init(m_mediator, toolNode);

				m_sourceSentences.CheckBoxChanged += new CheckBoxChangedEventHandler(sentences_CheckBoxChanged);

				m_moreMinSize = Size;
				m_moreMinSize.Height -= m_sourceSentences.Height / 2;
				m_lessMinSize = m_moreMinSize;
				m_lessMinSize.Height -= m_optionsPanel.Height;
				AdjustHeightAndMinSize(Height - m_optionsPanel.Height, m_lessMinSize);
				m_optionsPanel.Visible = false;
				m_btnMore.Image = ResourceHelper.MoreButtonDoubleArrowIcon;
				m_btnMore.Click += new EventHandler(btnMore_Click);
				m_sMoreButtonText = m_btnMore.Text;

				m_optionsPanel.Paint += new PaintEventHandler(m_optionsPanel_Paint);
				m_btnPreviewClear.Click += new EventHandler(m_btnPreviewClear_Click);

				// no good...code in MakeRoot of XmlBrowseView happens later and overrides. Control with
				// selectionType attr in Xml configuration.
				//m_sourceSentences.BrowseViewer.SelectedRowHighlighting = XmlBrowseViewBase.SelectionHighlighting.none;

				m_lblExplainText = m_lblExplainDisabled.Text;
				// We only reload the list when refresh is pressed.
				m_srcClerk.ListLoadingSuppressed = true;
				// We initially check everything.
				m_enabledItems.AddRange(m_sourceSentences.BrowseViewer.AllItems);
				foreach (int hvoCba in m_enabledItems)
				{
					m_cache.VwCacheDaAccessor.CacheIntProp(hvoCba, m_sourceSentences.BrowseViewer.PreviewEnabledTag, 1);
					m_cache.VwCacheDaAccessor.CacheIntProp(hvoCba, XmlBrowseViewBaseVc.ktagItemSelected, 1);
				}
				CheckForOtherOccurrences();
				SetEnabledState();
			}
			return true;
		}
Esempio n. 14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes an instance of the CmObject class for an existing object. It will be
		/// loaded if it has not already been.
		/// </summary>
		/// <param name="fcCache">fdoCache</param>
		/// <param name="hvo">HVO</param>
		/// ------------------------------------------------------------------------------------
		protected void InitExisting(FdoCache fcCache, int hvo)
		{
			bool fCheckValidity = false;
#if DEBUG
			if (s_checkValidity && !fcCache.IsDummyObject(hvo))
				fCheckValidity = true;
#endif
			// If the object's class is already cached, assume all the FDO preload data is too.
			// Occasionally we will get a miss, where the class has been loaded some other way,
			// but we will auto-load the properties actually used in that case, and on the other
			// hand we save a huge amount of time not reloading objects we've already loaded.
			bool fLoadIntoCache =
				!fcCache.MainCacheAccessor.get_IsPropInCache(hvo, (int)CmObjectFields.kflidCmObject_Class,
				(int)CellarModuleDefns.kcptInteger, 0);
			InitExisting(fcCache, hvo, fCheckValidity, fLoadIntoCache);
		}
Esempio n. 15
0
		/// <summary>
		/// Takes the information from a dummy object and allows its owner to create a real object in the database.
		/// NOTE: after calling this, users need to make sure they no longer try to use the old hvoDummy object.
		/// </summary>
		/// <param name="fcCache"></param>
		/// <param name="hvoDummy">id corresponding to the object to convert. Minimally it should have a class id cached
		/// and an OwningFlid corresponding to a virtual handler that implements IDummyRequestConversion. </param>
		/// <returns>real object based on new database entry created for the dummy object,
		/// null if conversion did not take place.</returns>
		public static ICmObject ConvertDummyToReal(FdoCache fcCache, int hvoDummy)
		{
			// suppress changes in display.
			using (new IgnorePropChanged(fcCache, PropChangedHandling.SuppressView))
			{
				// This conversion should not be an undoable task, so suppress the action handler.
				// (cf. LT-5330, LT-5417).
				using (SuppressSubTasks supressActionHandler = new SuppressSubTasks(fcCache, true))
				{
					ICmObject realObj = null;
					Debug.Assert(fcCache.IsDummyObject(hvoDummy));
					if (fcCache.IsDummyObject(hvoDummy))
					{
						// see if we can convert this to a real object before loading it.
						int owningFlid = fcCache.GetOwningFlidOfObject(hvoDummy);
						IVwVirtualHandler vh = fcCache.VwCacheDaAccessor.GetVirtualHandlerId(owningFlid);
						Debug.Assert(vh != null && vh is IDummyRequestConversion);
						if (vh != null && vh is IDummyRequestConversion)
						{
							RequestConversionToRealEventArgs args = new RequestConversionToRealEventArgs(hvoDummy,
								0, null, true);
							args.OwningFlid = owningFlid;
							(vh as IDummyRequestConversion).OnRequestConversionToReal(hvoDummy, args);
							realObj = args.RealObject as ICmObject;
						}
					}
					return realObj;
				}
			}
		}
Esempio n. 16
0
		/// <summary>
		/// Delete the objects which are the ids in the Set.
		/// </summary>
		public static void DeleteObjects(Set<int> idsToDel, FdoCache cache,
			bool fRequiresFullRefreshOfViewInUndoRedo,
			VwClearInfoAction vwClearInfoAction, bool fUndo, ProgressState state)
		{
			Set<int> realIdsToDel = new Set<int>();
			foreach (int hvo in idsToDel)
			{
				if (cache.IsDummyObject(hvo))
					continue;	// don't try removing dummy object from cache. otherwise, you can't undo it.
				realIdsToDel.Add(hvo);
			}
			if (realIdsToDel.Count == 0)
				return;
			if (fUndo && realIdsToDel.Count == 1 && fRequiresFullRefreshOfViewInUndoRedo || cache.DatabaseAccessor == null)
			{
				// Just one object...more efficient to to it directly, also, it lets many
				// tests pass that would otherwise need a real database.
				foreach (int hvo in realIdsToDel)
				{
					cache.DeleteObject(hvo);
				}
			}
			else
			{
				IActionHandler acth = cache.ActionHandlerAccessor;
				if (acth == null)
					fUndo = false;	// May be null if we are currently suppressing Subtasks
				int iMin = 0;
				int[] ids = realIdsToDel.ToArray();
				int step = 50;
				if (state != null)
				{
					// 600 4-digit ids, 500 5-digit ids, 428 6-digit ids, 375 7-digit ids
					int cChunks = (ids.Length / 450) + 1;
					step = 60 / cChunks;
					if (step == 0)
						step = 1;
				}
				while (iMin < ids.Length)
				{
					int iLim = iMin;
					string hvoList = CmObject.MakePartialIdList(ref iLim, ids);
					ObjectGroupUndoItem item;
					if (iMin > 0 || iLim < ids.Length)
					{
						Set<int> idsDel = new Set<int>(iLim - iMin);
						for (int i = iMin; i < iLim; ++i)
							idsDel.Add(ids[i]);
						item = new ObjectGroupUndoItem(idsDel, hvoList, cache,
							fRequiresFullRefreshOfViewInUndoRedo, fUndo);
					}
					else
					{
						item = new ObjectGroupUndoItem(realIdsToDel, hvoList, cache,
							fRequiresFullRefreshOfViewInUndoRedo, fUndo);
					}
					item.DoIt(vwClearInfoAction);
					if (fUndo)
						acth.AddAction(item);
					if (state != null)
					{
						int percent = state.PercentDone + step;
						state.PercentDone = percent;
						state.Breath();
					}
					iMin = iLim;
				}
			}
		}