Esempio n. 1
0
		/// <summary>
		/// Get the writing system for the given ReversalIndexEntry.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvoObj"></param>
		/// <param name="wsDefault"></param>
		/// <returns></returns>
		public static int GetReversalIndexEntryWritingSystem(FdoCache cache, int hvoObj, int wsDefault)
		{
			if (cache != null && hvoObj != 0)
			{
				IReversalIndex ri = null;
				int clid = cache.GetClassOfObject(hvoObj);
				switch (clid)
				{
					case ReversalIndex.kclsidReversalIndex:
						ri = ReversalIndex.CreateFromDBObject(cache, hvoObj);
						break;
					case ReversalIndexEntry.kclsidReversalIndexEntry:
						int hvoReversalIndex = cache.GetOwnerOfObjectOfClass(hvoObj, ReversalIndex.kclsidReversalIndex);
						if (hvoReversalIndex > 0)
							ri = ReversalIndex.CreateFromDBObject(cache, hvoReversalIndex);
						break;
					case PartOfSpeech.kclsidPartOfSpeech:
						// It may be nested, but we need the owner (index) of the list,
						// no matter how high up.
						int reversalIndexId = cache.GetOwnerOfObjectOfClass(hvoObj, ReversalIndex.kclsidReversalIndex);
						if (reversalIndexId > 0)
							ri = ReversalIndex.CreateFromDBObject(cache, reversalIndexId);
						break;
					case LexSense.kclsidLexSense:
					// Pick a plausible default reversal index for the LexSense.
					case LexDb.kclsidLexDb: // happens while initializing bulk edit combos
					default: // since this doesn't actually depend on the hvo, it's not a bad general default.
						List<int> rgriCurrent = cache.LangProject.LexDbOA.CurrentReversalIndices;
						if (rgriCurrent.Count > 0)
						{
							ri = ReversalIndex.CreateFromDBObject(cache, (int)rgriCurrent[0]);
						}
						else
						{
							if (cache.LangProject.LexDbOA.ReversalIndexesOC.Count > 0)
							{
								int hvo = cache.LangProject.LexDbOA.ReversalIndexesOC.HvoArray[0];
								ri = (IReversalIndex)CmObject.CreateFromDBObject(cache, hvo);
							}
						}
						break;
				}
				if (ri != null)
					return ri.WritingSystemRAHvo;
			}
			return wsDefault;
		}
		/// <summary>
		/// when calling the dialog from an "Insert Variant" context this
		/// constructor is used to indicate that m_startingEntry is a componentLexeme
		/// rather than the variant
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="mediator"></param>
		/// <param name="componentLexeme">the entry we wish to find or create a variant for.</param>
		protected void SetDlgInfoForComponentLexeme(FdoCache cache, Mediator mediator, IVariantComponentLexeme componentLexeme)
		{
			m_fBackRefToVariant = true;
			ILexEntry startingEntry = null;
			if (componentLexeme.ClassID == LexEntry.kclsidLexEntry)
			{
				startingEntry = componentLexeme as LexEntry;
			}
			else
			{
				int hvoEntry = cache.GetOwnerOfObjectOfClass(componentLexeme.Hvo, LexEntry.kclsidLexEntry);
				if (hvoEntry != 0)
					startingEntry = LexEntry.CreateFromDBObject(cache, hvoEntry);
			}
			base.SetDlgInfo(cache, mediator, startingEntry);
			// we are looking for an existing variant form
			// so hide the Entry/Sense radio group box.
			grplbl.Visible = false;
			// also hide variant type.
			tcVariantTypes.Visible = false;
			lblVariantType.Visible = false;
			m_fGetVariantEntryTypeFromTreeCombo = false;
			lblCreateEntry.Visible = false;

			// The dialog title and other labels need to reflect "Insert Variant" context.
			m_formLabel.Text = LexTextControls.ks_Variant;
			this.Text = LexTextControls.ksFindVariant;
			btnInsert.Text = LexTextControls.ks_Create;
			// We disable the "Create" button when we don't have text in the Find textbox.
			UpdateButtonCreateNew();
		}
Esempio n. 3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Replaces all references to one paragraph in the footnote cache with another. Used to
		/// update the cache when a paragraph is being merged with another.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="oldParaHvo">id of paragraph being merged into another</param>
		/// <param name="newParaHvo">id of paragraph surviving the merge</param>
		/// ------------------------------------------------------------------------------------
		public static void ReplaceReferencesToParagraph(FdoCache cache, int oldParaHvo, int newParaHvo)
		{
			int bookHvo = cache.GetOwnerOfObjectOfClass(oldParaHvo, (int)ScrBook.kclsidScrBook);
			if (bookHvo <= 0)
			{
				Debug.Fail("Footnotes have to be contained in paragraphs owned by books.");
				return;
			}
			Guid bookGuid = cache.GetGuidFromId(bookHvo);

			Dictionary<int, FootnoteHashEntry> dict;
			// Don't bother on empty cache - it will be created when needed. Need to use HVO to get
			// GUID so we don't create the book and potentially cause the refresh routine to be called.
			if (!cache.TryGetHashtable<int, FootnoteHashEntry>(bookGuid, out dict) || dict.Count == 0)
				return;

			foreach (FootnoteHashEntry entry in dict.Values)
			{
				if (entry.HvoPara == oldParaHvo)
					entry.HvoPara = newParaHvo;
			}
		}