public bool OnExportInterlinear(object argument) { // If the currently selected text is from Scripture, then we need to give the dialog // the list of Scripture texts that have been selected for interlinearization. var parent = Parent; while (parent != null && !(parent is InterlinMaster)) { parent = parent.Parent; } var master = parent as InterlinMaster; if (master != null) { var clerk = master.Clerk as InterlinearTextsRecordClerk; if (clerk != null) { clerk.GetScriptureIds(); // initialize the InterestingTextList to include Scripture (prevent a crash trying later) } } bool fFocusBox = TryHideFocusBoxAndUninstall(); ICmObject objRoot = m_objRepo.GetObject(m_hvoRoot); using (var dlg = new InterlinearExportDialog(m_mediator, m_propertyTable, objRoot, m_vc)) { dlg.ShowDialog(this); } if (fFocusBox) { CreateFocusBox(); } return(true); // we handled this }
protected Guid WriteGuidAttributeForObj(int hvo) { if (m_repoObj.IsValidObjectId(hvo)) { ICmObject obj = m_repoObj.GetObject(hvo); Guid guid = obj.Guid; m_writer.WriteAttributeString("guid", guid.ToString()); return(guid); } else { return(Guid.Empty); } }
/// <summary> /// A representation that can be used to create an equivalent LazyManyOnePathSortItem. /// Keep consistent with the LazyManyOnePathSortItem constructor and PersisData. /// </summary> public string PersistData(ICmObjectRepository repo) { StringBuilder builder = new StringBuilder(); builder.Append(PersistGuid(repo.GetObject(m_hvoItem).Guid)); if (PathLength > 0) { for (int i = 0; i < m_pathObjects.Length; i++) { builder.Append(";"); builder.Append(m_pathFlids[i]); builder.Append(";"); builder.Append(PersistGuid(repo.GetObject(m_pathObjects[i]).Guid)); } } return(builder.ToString()); }
/// <summary> /// Map from secondary hvo (in the SilDataAccess) to real object (in ICmOjectRepository). /// </summary> /// <param name="secHvo"></param> /// <returns></returns> public ICmObject RealObject(int secHvo) { int hvoReal = RealHvo(secHvo); if (hvoReal != 0 && m_coRepository != null) { return(m_coRepository.GetObject(hvoReal)); } return(null); }
public bool OnExportInterlinear(object argument) { // If the currently selected text is from Scripture, then we need to give the dialog // the list of Scripture texts that have been selected for interlinearization. var parent = this.Parent; while (parent != null && !(parent is InterlinMaster)) { parent = parent.Parent; } var master = parent as InterlinMaster; var selectedObjs = new List <ICmObject>(); IBookImporter bookImporter = null; if (master != null) { bookImporter = master.Clerk as IBookImporter; var clerk = master.Clerk as InterlinearTextsRecordClerk; if (clerk != null) { foreach (int hvo in clerk.GetScriptureIds()) { selectedObjs.Add(m_objRepo.GetObject(hvo)); } } } //AnalysisOccurrence analOld = OccurrenceContainingSelection(); bool fFocusBox = TryHideFocusBoxAndUninstall(); ICmObject objRoot = m_objRepo.GetObject(m_hvoRoot); using (var dlg = new InterlinearExportDialog(m_mediator, objRoot, m_vc, bookImporter)) { dlg.ShowDialog(this); } if (fFocusBox) { CreateFocusBox(); //int hvoAnalysis = m_fdoCache.MainCacheAccessor.get_ObjectProp(oldAnnotation, CmAnnotationTags.kflidInstanceOf); //TriggerAnnotationSelected(oldAnnotation, hvoAnalysis, false); } return(true); // we handled this }
/// <summary> /// Check for and deal with moves that should not be allowed. /// Previously the only disallowed move was one that reorganized a chart template that is in use. /// This is not the optimum place to 'know' about this, but I (JohnT) am not sure where is. /// Now we are disallowing certain moves within the TextMarkup Tags list too, so I (GordonM) have /// refactored a bit. /// Review: Should these be pulled out to the PossibilityTreeBarHandler subclass? /// </summary> /// <param name="hvoMove"></param> /// <param name="hvoDest"></param> /// <returns>true if a problem was reported and the move should be cancelled.</returns> private bool CheckAndReportForbiddenMove(int hvoMove, int hvoDest) { var movingPossItem = m_possRepo.GetObject(hvoMove); if (movingPossItem != null) { var rootPoss = movingPossItem.MainPossibility; int hvoRootItem = rootPoss.Hvo; int hvoPossList = rootPoss.OwningList.Hvo; // If we get here hvoPossList is a possibility list and hvoRootItem is a top level item in that list // and movingPossItem is, or is a subpossibility of, that top level item. // 1. Check to see if hvoRootItem is a chart template containing our target. // If so, hvoPossList is owned in the chart templates property. if (m_objRepo.GetObject(hvoPossList).OwningFlid == DsDiscourseDataTags.kflidConstChartTempl) { return(CheckAndReportBadDiscourseTemplateMove(movingPossItem, hvoRootItem, hvoPossList, hvoDest)); } // 2. Check to see if hvoRootItem is a TextMarkup TagList containing our target (i.e. a Tag type). // If so, hvoPossList is owned in the text markup tags property. if (m_objRepo.GetObject(hvoPossList).OwningFlid == LangProjectTags.kflidTextMarkupTags) { return(CheckAndReportBadTagListMove(movingPossItem, hvoRootItem, hvoPossList, hvoDest)); } } return(false); // not detecting problems with moving other kinds of things. }
internal string LinkRef(int hvo) { ICmObjectRepository repo = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>(); if (!repo.IsValidObjectId(hvo)) { return(null); } Guid guid = repo.GetObject(hvo).Guid; FwLinkArgs link = new FwLinkArgs("lexiconEdit", guid); return(link.ToString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a new owned object /// </summary> /// <typeparam name="TObj">The type of object</typeparam> /// <param name="srcRepository">The repository that holds the object.</param> /// <param name="srcObj">The object (used to create a new object of the same type).</param> /// <returns>The created object</returns> /// ------------------------------------------------------------------------------------ private TObj CreateOwnedObj <TObj>(ICmObjectRepository srcRepository, TObj srcObj) where TObj : ICmObject { if (srcObj.Owner == null) { throw new ArgumentException("Can't create Owned Copy of unowned original!", "srcObj"); } int owningFlidType = m_mdc.GetFieldType(srcObj.OwningFlid); // Determine appropriate owner of copy // If source's owner has also been copied, we want to add this copy to the copy! // If a delegate has not been set, use the source's owner as the copy's owner. ICmObject copied; if (!m_sourceToCopyMap.TryGetValue(srcObj.Owner.Hvo, out copied)) { copied = (m_topLevelOwnerFunct == kAddToSourceOwner) ? srcObj.Owner : null; } Debug.Assert(copied != null, "Non top-level objects should have their owner already copied"); int ord; switch (owningFlidType) { case (int)CellarPropertyType.OwningAtomic: ord = -2; break; case (int)CellarPropertyType.OwningCollection: ord = -1; break; case (int)CellarPropertyType.OwningSequence: // put copy at end of sequence until told otherwise ord = m_sda.get_VecSize(copied.Hvo, srcObj.OwningFlid); break; default: throw new NotImplementedException("Unsupported owningFlidType."); } int newHvo = m_sda.MakeNewObject(srcObj.ClassID, copied.Hvo, srcObj.OwningFlid, ord); return((TObj)srcRepository.GetObject(newHvo)); }
/// <summary> /// Determine whether this UOW can safely Undo. /// Higher-level methods are responsible for determining whether this UOW conflicts with /// those in other stacks. This method is mainly focused on whether referential integrity will be broken. /// </summary> internal bool CanUndo(ICmObjectRepository objRepo) { var deletedGuids = new HashSet <Guid>(from obj in m_deletedObjects select obj.Guid); if (m_changes.OfType <FdoStateChangeBase>().Any(change => change.CreatesProblemReferenceOnUndo(objRepo, deletedGuids))) { return(false); } // Now verify that none of the new objects which this action creates will leave a dangling // reference if deleted. if (m_newObjects.Count == 0) { return(true); } // If any of the new objects is has already been deleted, we don't have to worry about leaving refs to it! var newObjects = new HashSet <ICmObject>(from id in m_newObjects where objRepo.IsValidObjectId(id.Guid) select objRepo.GetObject(id)); int externalIncomingRefs = newObjects.Sum(obj => ((ICmObjectInternal)obj).IncomingRefsNotFrom(newObjects)); if (externalIncomingRefs == 0) { return(true); } // OK, there are problem references AFTER the change...will undoing it fix them? var newGuids = new HashSet <Guid>(from id in m_newObjects select id.Guid); foreach (var item in m_changes) { var change = item as FdoStateChangeBase; if (change != null) { externalIncomingRefs -= change.CountDeletedRefsToOnUndo(newGuids); } } return(externalIncomingRefs == 0); }
public ICmObject GetObject(ICmObjectRepository repo) { return repo.GetObject(this); }
public ICmObject GetObject(ICmObjectRepository repo) { return(repo.GetObject(this)); }
/// <summary> /// Determine whether this UOW can safely Redo. /// Higher-level methods are responsible for determining whether this UOW conflicts with /// those in other stacks. This method is mainly focused on whether referential integrity will be broken. /// </summary> /// <returns></returns> internal bool CanRedo(ICmObjectRepository objRepo) { var newGuids = new HashSet <Guid>(from id in m_newObjects select id.Guid); foreach (var item in m_changes) { if (!item.IsRedoable) { return(false); } var change = item as FdoStateChangeBase; if (change == null) { continue; // assume other changes are redoable if they think they are } if (change.CreatesProblemReferenceOnRedo(objRepo, newGuids)) { return(false); } } // Now verify that none of the objects which this action deletes will leave a dangling // reference if deleted (except references which the action already deletes itself). // (We don't need to check objects created by this UOW; they won't get re-created by undoing it.) if (m_deletedObjects.Count == 0) { return(true); } var delObjects = new HashSet <ICmObject>( from obj in m_deletedObjects where !newGuids.Contains(obj.Guid) select objRepo.GetObject(obj)); int externalIncomingRefs = delObjects.Sum(obj => ((ICmObjectInternal)obj).IncomingRefsNotFrom(delObjects)); if (externalIncomingRefs == 0) { return(true); } // OK, there are potential problem references after we redo the change...will redoing it fix them? var oldGuids = new HashSet <Guid>(from obj in m_deletedObjects select obj.Guid); foreach (var item in m_changes) { var change = item as FdoStateChangeBase; if (change != null) { externalIncomingRefs -= change.CountDeletedRefsToOnRedo(oldGuids); } } return(externalIncomingRefs == 0); }
/// <summary> /// Takes a coded number string and interprets it. /// Only the first code in the string is interpreted. /// The emedded codes are: /// %d for an integer /// %A, %a for upper and lower alpha, /// %I, %i for upper and lower roman numerals, /// %O for outline number (a real number) /// %z is short for %d.%a.%i; the lowest level is incremented or set. /// </summary> /// <param name="rghvo">hvo array of senses</param> /// <param name="ihvo">A sequence number or index (into rghvo).</param> /// <param name="xaNum">The sequence number format to apply</param> /// <returns>The format filled in with the sequence number</returns> private string CalculateAndFormatSenseLabel(int[] rghvo, int ihvo, XmlAttribute xaNum) { var sNum = ""; var sTag = xaNum.Value; int ich; for (ich = 0; ich < sTag.Length; ++ich) { if (sTag[ich] != '%' || sTag.Length <= ich + 1) { continue; } ++ich; switch (sTag[ich]) { case 'd': sNum = string.Format("{0}", ihvo + 1); break; case 'A': sNum = AlphaOutline.NumToAlphaOutline(ihvo + 1); break; case 'a': sNum = AlphaOutline.NumToAlphaOutline(ihvo + 1).ToLower(); break; case 'I': sNum = RomanNumerals.IntToRoman(ihvo + 1); break; case 'i': sNum = RomanNumerals.IntToRoman(ihvo + 1).ToLower(); break; case 'O': if (m_cache.MetaDataCacheAccessor.get_IsVirtual(m_flid)) { sNum = String.Format("{0}", ihvo + 1); } else { sNum = m_cache.GetOutlineNumber(m_objRepo.GetObject(rghvo[ihvo]), false, true); } break; case 'z': sNum = GetOutlineStyle2biv(rghvo, ihvo); break; // MDL: can only get to this case for "%%" - does it mean anything? case '%': sTag.Remove(ich, 1); // removes the 2nd % --ich; break; } break; // ich is the position of the code character after the last % } // sNum is the ordinate that will replace the 2-letter code. if (sNum.Length != 0) { sTag = (sTag.Remove(ich - 1, 2)).Insert(ich - 1, sNum); } return(sTag); }
public bool OkToMove(int hvoDstOwner, int flidDst, int ihvoDstStart, ObjectDragInfo odi) { CheckDisposed(); FDO.FdoCache cache = Slice.ContainingDataTree.Cache; ICmObjectRepository repo = cache.ServiceLocator.GetInstance <ICmObjectRepository>(); if (flidDst == odi.FlidSrc) { // Verify that it is not a no-operation. if (hvoDstOwner == odi.HvoSrcOwner) { // Same property of same object. If it's a collection, disable. CellarPropertyType fieldType = (CellarPropertyType)cache.DomainDataByFlid.MetaDataCache.GetFieldType((int)flidDst); // We can't drag it to the position it's already at; that's no change. We also can't drag it // to the position one greater: that amounts to trying to place it after itself, which (after // removing it from before itself) amounts to a no-operation. if (fieldType == CellarPropertyType.OwningSequence && ihvoDstStart != odi.IhvoSrcStart && ihvoDstStart != odi.IhvoSrcStart + 1) { // It's a sequence and the target and source positions are different, so we can do it. return(true); } } else { // Different objects; need to verify no circular ownership involved. for (int ihvo = odi.IhvoSrcStart; ihvo <= odi.IhvoSrcEnd; ihvo++) { int hvo = cache.DomainDataByFlid.get_VecItem(odi.HvoSrcOwner, odi.FlidSrc, ihvo); // See if hvoDstOwner is owned by hvo ICmObject obj2 = repo.GetObject(hvoDstOwner); // loop from hvo2 to root owner of hvo2. If hvo2 or any of its owners is hvo, // we have a problem. while (obj2 != null) { if (hvo == obj2.Hvo) { return(false); // circular ownership, can't drop. } obj2 = obj2.Owner; } } return(true); } } else { // Different property, check signature. IFwMetaDataCache mdc = cache.DomainDataByFlid.MetaDataCache; int luclid = mdc.GetDstClsId((int)flidDst); for (int ihvo = odi.IhvoSrcStart; ihvo <= odi.IhvoSrcEnd; ihvo++) { int hvo = cache.DomainDataByFlid.get_VecItem(odi.HvoSrcOwner, odi.FlidSrc, ihvo); int cls = repo.GetObject(hvo).ClassID; while (cls != 0 && cls != luclid) { cls = mdc.GetBaseClsId(cls); } if (cls == 0) { return(false); // wrong signature, can't drop. } } // All sigs OK, allow drop. return(true); } // If none of those cases is OK, can't do it. return(false); }
/// <summary> /// A representation that can be used to create an equivalent LazyManyOnePathSortItem. /// Keep consistent with the LazyManyOnePathSortItem constructor and PersisData. /// </summary> public string PersistData(ICmObjectRepository repo) { StringBuilder builder = new StringBuilder(); builder.Append(PersistGuid(repo.GetObject(m_hvoItem).Guid)); if (PathLength > 0) { for (int i = 0; i < m_pathObjects.Length; i++) { builder.Append(";"); builder.Append(m_pathFlids[i]); builder.Append(";"); builder.Append(PersistGuid(repo.GetObject(m_pathObjects[i]).Guid)); } } return builder.ToString(); }