public bool OnPromoteReversalindexEntry(object cmd)
        {
            //Command command = (Command) cmd;
            Slice slice = m_dataEntryForm.CurrentSlice;

            Debug.Assert(slice != null, "No slice was current");
            if (slice != null)
            {
                FdoCache            cache = m_dataEntryForm.Cache;
                IReversalIndexEntry entry = slice.Object as IReversalIndexEntry;
                int hvoNewOwner           = cache.GetOwnerOfObject(entry.OwnerHVO);
                switch (cache.GetClassOfObject(hvoNewOwner))
                {
                default:
                    throw new ArgumentException("Illegal class.");

                case ReversalIndex.kclsidReversalIndex:
                {
                    IReversalIndex ri = ReversalIndex.CreateFromDBObject(cache, hvoNewOwner);
                    ri.EntriesOC.Add(entry);
                    break;
                }

                case ReversalIndexEntry.kclsidReversalIndexEntry:
                {
                    IReversalIndexEntry rie = ReversalIndexEntry.CreateFromDBObject(cache, hvoNewOwner);
                    rie.SubentriesOC.Add(entry);
                    break;
                }
                }
                // We may need to notify everyone that a virtual property changed.
                //NotifyVirtualChanged(cache, slice);
            }
            return(true);
        }
        /// <summary></summary>
        public void Setup(object o, IRecordListUpdater rlu)
        {
            CheckDisposed();

            Debug.Assert(o != null && o is IReversalIndexEntry);
            IReversalIndexEntry rie = o as IReversalIndexEntry;

            if (m_rlu == null && rlu != null && m_rie == rie)
            {
                m_rlu = rlu;
                m_rlu.RecordChangeHandler = this;
                m_rlu.UpdateList(true);
            }
            else
            {
                m_rie = rie;
                Debug.Assert(m_rie != null);
                int ws = m_rie.Services.WritingSystemManager.GetWsFromStr(m_rie.ReversalIndex.WritingSystem);
                m_originalForm = m_rie.ReversalForm.get_String(ws).Text;
                if (rlu != null)
                {
                    m_rlu = rlu;
                    m_rlu.RecordChangeHandler = this;
                }
            }
        }
        private static void AddSenseToReversaEntry(IReversalIndexEntry riEntry, string gloss, int wsId, FdoCache cache)
        {
            var entry = CXGTests.CreateInterestingLexEntry(cache);

            entry.SensesOS.First().ReversalEntriesRC.Add(riEntry);
            entry.SensesOS[0].Gloss.set_String(wsId, gloss);
        }
        /// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        protected virtual void Dispose(bool disposing)
        {
            System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
            // Must not be run more than once.
            if (m_isDisposed)
            {
                return;
            }

            if (disposing)
            {
                if (Disposed != null)
                {
                    Disposed(this, new EventArgs());
                }

                // Dispose managed resources here.
                if (m_rlu != null)
                {
                    m_rlu.RecordChangeHandler = null;
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_rie          = null;
            m_originalForm = null;
            m_rlu          = null;

            m_isDisposed = true;
        }
Exemple #5
0
        /// <summary>
        /// Execute the change requested by the current selection in the combo.
        /// Basically we want the PartOfSpeech indicated by m_selectedHvo, even if 0,
        /// to become the POS of each record that is appropriate to change.
        /// We do nothing to records where the check box is turned off,
        /// and nothing to ones that currently have an MSA other than an IMoStemMsa.
        /// (a) If the owning entry has an IMoStemMsa with the
        /// right POS, set the sense to use it.
        /// (b) If the sense already refers to an IMoStemMsa, and any other senses
        /// of that entry which point at it are also to be changed, change the POS
        /// of the MSA.
        /// (c) If the entry has an IMoStemMsa which is not used at all, change it to the
        /// required POS and use it.
        /// (d) Make a new IMoStemMsa in the ILexEntry with the required POS and point the sense at it.
        /// </summary>
        public override void DoIt(IEnumerable <int> itemsToChange, ProgressState state)
        {
            CheckDisposed();

            m_cache.DomainDataByFlid.BeginUndoTask(LexEdStrings.ksUndoBulkEditRevPOS,
                                                   LexEdStrings.ksRedoBulkEditRevPOS);
            int i        = 0;
            int interval = Math.Min(100, Math.Max(itemsToChange.Count() / 50, 1));

            foreach (int entryId in itemsToChange)
            {
                i++;
                if (i % interval == 0)
                {
                    state.PercentDone = i * 80 / itemsToChange.Count() + 20;
                    state.Breath();
                }
                IReversalIndexEntry entry = m_cache.ServiceLocator.GetInstance <IReversalIndexEntryRepository>().GetObject(entryId);
                if (m_selectedHvo == 0)
                {
                    entry.PartOfSpeechRA = null;
                }
                else
                {
                    entry.PartOfSpeechRA = m_cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(m_selectedHvo);
                }
            }
            m_cache.DomainDataByFlid.EndUndoTask();
        }
		protected IReversalIndexEntry CreateReversalIndexSubEntry(string subEntryForm, IReversalIndexEntry indexEntry)
		{
			var wsObj = Cache.LanguageProject.DefaultAnalysisWritingSystem;
			var revIndexEntry = m_revIndexEntryFactory.Create();
			indexEntry.SubentriesOS.Add(revIndexEntry);
			revIndexEntry.ReversalForm.set_String(wsObj.Handle, Cache.TsStrFactory.MakeString(subEntryForm, wsObj.Handle));
			return revIndexEntry;
		}
Exemple #7
0
        private bool IsMainReversalEntry(int hvo)
        {
            IReversalIndexEntry entry = null;

            if (Cache.ServiceLocator.IsValidObjectId(hvo))
            {
                entry = Cache.ServiceLocator.GetObject(hvo) as IReversalIndexEntry;
            }
            return(entry != null && entry.Owner is IReversalIndex);            // Subentries are owned by other Entries
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="obj">CmObject that is being displayed.</param>
        /// <param name="flid">The field identifier for the attribute we are displaying.</param>
        /// // cache, obj, flid, node, persistenceProvider, stringTbl
        public AtomicReferencePOSSlice(FdoCache cache, ICmObject obj, int flid,
                                       IPersistenceProvider persistenceProvider, Mediator mediator)
            : base(new UserControl(), cache, obj, flid)
        {
            IVwStylesheet stylesheet = FontHeightAdjuster.StyleSheetFromMediator(mediator);

            m_persistProvider           = persistenceProvider;
            m_tree                      = new TreeCombo();
            m_tree.WritingSystemFactory = cache.LanguageWritingSystemFactoryAccessor;
            m_tree.WritingSystemCode    = m_cache.LangProject.DefaultAnalysisWritingSystem;
            m_tree.Font                 = new System.Drawing.Font(cache.LangProject.DefaultAnalysisWritingSystemFont, 10);
            m_tree.StyleSheet           = stylesheet;
            if (!Application.RenderWithVisualStyles)
            {
                m_tree.HasBorder = false;
            }
            // We embed the tree combo in a layer of UserControl, so it can have a fixed width
            // while the parent window control is, as usual, docked 'fill' to work with the splitter.
            m_tree.Dock  = DockStyle.Left;
            m_tree.Width = 200;
            Control.Controls.Add(m_tree);
            if (m_pOSPopupTreeManager == null)
            {
                ICmPossibilityList list;
                int ws;
                if (obj is ReversalIndexEntry)
                {
                    IReversalIndexEntry rie = obj as IReversalIndexEntry;
                    list = rie.ReversalIndex.PartsOfSpeechOA;
                    ws   = rie.ReversalIndex.WritingSystemRAHvo;
                }
                else
                {
                    list = m_cache.LangProject.PartsOfSpeechOA;
                    ws   = m_cache.LangProject.DefaultAnalysisWritingSystem;
                }
                m_tree.WritingSystemCode           = ws;
                m_pOSPopupTreeManager              = new POSPopupTreeManager(m_tree, m_cache, list, ws, false, mediator, (Form)mediator.PropertyTable.GetValue("window"));
                m_pOSPopupTreeManager.AfterSelect += new TreeViewEventHandler(m_pOSPopupTreeManager_AfterSelect);
            }
            try
            {
                m_handlingMessage = true;
                m_pOSPopupTreeManager.LoadPopupTree(POS == null ? 0 : POS.Hvo);
            }
            finally
            {
                m_handlingMessage = false;
            }
            Control.Height = m_tree.PreferredHeight;
            // m_tree has sensible PreferredHeight once the text is set, UserControl does not.
            // we need to set the Height after m_tree.Text has a value set to it.
        }
        protected IReversalIndex AddReversalIndex(List <ICmObject> addList, IReversalIndexEntry revIndexEntry)
        {
            Assert.IsNotNull(m_revIndexFactory, "Fixture Initialization is not complete.");
            Assert.IsNotNull(m_window, "No window.");

            //create a reversal index for this project.
            var            wsObj    = Cache.LanguageProject.DefaultAnalysisWritingSystem;
            IReversalIndex revIndex = m_revIndexRepo.FindOrCreateIndexForWs(wsObj.Handle);

            //Add an entry to the Reveral index
            revIndex.EntriesOC.Add(revIndexEntry);

            addList.Add(revIndex);
            return(revIndex);
        }
        private static void AddSingleSubSenseToSense(IReversalIndexEntry riEntry, string gloss, int wsId, FdoCache cache)
        {
            CreateSubsenseModel();
            var entry = CXGTests.CreateInterestingLexEntry(cache);
            var sense = entry.SensesOS.First();

            sense.Gloss.set_String(wsId, cache.TsStrFactory.MakeString(gloss, wsId));
            var subSensesOne = sense.Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            sense.SensesOS.Add(subSensesOne);
            var subGloss = "subgloss ";

            subSensesOne.Gloss.set_String(wsId, cache.TsStrFactory.MakeString(subGloss + "1.1", wsId));
            entry.SensesOS[0].SensesOS[0].Gloss.set_String(wsId, subGloss);
            entry.SensesOS.First().SensesOS[0].ReversalEntriesRC.Add(riEntry);
        }
Exemple #11
0
 private bool IsPublishableReversalEntry(IReversalIndexEntry revEntry)
 {
     // We should still display reversal entries that have no senses
     if (!revEntry.ReferringSenses.Any())
     {
         return(true);
     }
     foreach (var sense in revEntry.ReferringSenses)
     {
         if (!m_excludedItems.Contains(sense.Hvo))
         {
             return(true);                       // At least one sense in one entry allows publication.
         }
     }
     return(false);              // nobody wants us.
 }
Exemple #12
0
        public virtual bool OnDisplayGotoReversalEntry(object commandObject,
                                                       ref UIItemDisplayProperties display)
        {
            CheckDisposed();

            IReversalIndexEntry rie = Entry;

            if (rie == null || rie.Owner.Hvo == 0)
            {
                display.Enabled = display.Visible = false;
            }
            else
            {
                display.Enabled = rie.ReversalIndex.EntriesOC.Count > 1 && InFriendlyArea;
                display.Visible = InFriendlyArea;
            }
            return(true);            //we've handled this
        }
Exemple #13
0
        public bool OnMoveReversalindexEntry(object cmd)
        {
            using (var dlg = new ReversalEntryGoDlg())
            {
                Slice slice = m_dataEntryForm.CurrentSlice;
                Debug.Assert(slice != null, "No slice was current");
                var currentEntry = (IReversalIndexEntry)slice.Object;
                dlg.ReversalIndex = currentEntry.ReversalIndex;
                dlg.FilteredReversalEntries.Add(currentEntry);
                IReversalIndexEntry owningEntry = currentEntry.OwningEntry;
                if (owningEntry != null)
                {
                    dlg.FilteredReversalEntries.Add(owningEntry);
                }
                dlg.SetHelpTopic("khtpMoveReversalEntry");
                var wp = new WindowParams {
                    m_btnText = LexEdStrings.ks_MoveEntry, m_title = LexEdStrings.ksMoveRevEntry
                };
                var cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache");
                dlg.SetDlgInfo(cache, wp, m_mediator);
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var newOwner = (IReversalIndexEntry)dlg.SelectedObject;
                    UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoMoveRevEntry,
                                                LexEdStrings.ksRedoMoveRevEntry, Cache.ActionHandlerAccessor,
                                                () =>
                    {
                        newOwner.MoveIfNeeded(currentEntry);
                        newOwner.SubentriesOC.Add(currentEntry);
                    });
                    RecordClerk clerk = m_mediator.PropertyTable.GetValue("ActiveClerk") as RecordClerk;
                    if (clerk != null)
                    {
                        clerk.RemoveItemsFor(currentEntry.Hvo);
                    }
                    // Note: PropChanged should happen on the old owner and the new while completing the unit of work.
                    // Have to jump to a main entry, as RecordClerk doesn't know anything about subentries.
                    m_mediator.BroadcastMessageUntilHandled("JumpToRecord", newOwner.MainEntry.Hvo);
                }
            }

            return(true);
        }
        public bool OnMoveReversalindexEntry(object cmd)
        {
            using (ReversalEntryGoDlg dlg = new ReversalEntryGoDlg())
            {
                Slice slice = m_dataEntryForm.CurrentSlice;
                Debug.Assert(slice != null, "No slice was current");
                IReversalIndexEntry        currentEntry    = (IReversalIndexEntry)slice.Object;
                List <IReversalIndexEntry> filteredEntries = new List <IReversalIndexEntry>();
                filteredEntries.Add(currentEntry);
                IReversalIndexEntry owningEntry = currentEntry.OwningEntry;
                if (owningEntry != null)
                {
                    filteredEntries.Add(owningEntry);
                }

                WindowParams wp = new WindowParams();
                wp.m_btnText = LexEdStrings.ks_MoveEntry;
                wp.m_label   = LexEdStrings.ks_Find_;
                wp.m_title   = LexEdStrings.ksMoveRevEntry;
                dlg.SetDlgInfo(m_mediator, wp, filteredEntries);                 // , true
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    FdoCache            cache    = (FdoCache)m_mediator.PropertyTable.GetValue("cache");
                    IReversalIndexEntry newOwner = ReversalIndexEntry.CreateFromDBObject(cache, dlg.SelectedID);
                    cache.BeginUndoTask(LexEdStrings.ksUndoMoveRevEntry,
                                        LexEdStrings.ksRedoMoveRevEntry);
                    ICmObject newOwningObj = newOwner.MoveIfNeeded(currentEntry);
                    newOwner.SubentriesOC.Add(currentEntry);
                    cache.EndUndoTask();
                    RecordClerk clerk = m_mediator.PropertyTable.GetValue("ActiveClerk") as RecordClerk;
                    if (clerk != null)
                    {
                        clerk.RemoveItemsFor(currentEntry.Hvo);
                    }
                    // Note: PropChanged should happen on the old owner and the new in the 'Add" method call.
                    // Have to jump to a main entry, as RecordClerk doesn't know anything about subentries.
                    m_mediator.BroadcastMessageUntilHandled("JumpToRecord", newOwner.MainEntry.Hvo);
                }
            }

            return(true);
        }
        public bool OnPromoteReversalindexEntry(object cmd)
        {
            //Command command = (Command) cmd;
            Slice slice = m_dataEntryForm.CurrentSlice;

            Debug.Assert(slice != null, "No slice was current");
            if (slice != null)
            {
                FdoCache            cache    = m_dataEntryForm.Cache;
                IReversalIndexEntry entry    = slice.Object as IReversalIndexEntry;
                ICmObject           newOwner = entry.Owner.Owner;
                UndoableUnitOfWorkHelper.Do(((Command)cmd).UndoText, ((Command)cmd).RedoText, newOwner,
                                            () =>
                {
                    switch (newOwner.ClassID)
                    {
                    default:
                        throw new ArgumentException("Illegal class.");

                    case ReversalIndexTags.kClassId:
                        {
                            IReversalIndex ri = (IReversalIndex)newOwner;
                            ri.EntriesOC.Add(entry);
                            break;
                        }

                    case ReversalIndexEntryTags.kClassId:
                        {
                            IReversalIndexEntry rie = (IReversalIndexEntry)newOwner;
                            rie.SubentriesOS.Add(entry);
                            break;
                        }
                    }
                });
                // We may need to notify everyone that a virtual property changed.
                //NotifyVirtualChanged(cache, slice);
            }
            return(true);
        }
        protected override void ReallyDeleteUnderlyingObject()
        {
            IReversalIndexEntry rei = Object as IReversalIndexEntry;
            int hvoGoner            = rei.Hvo;
            int hvoIndex            = rei.ReversalIndex.Hvo;
            IVwVirtualHandler vh    = BaseVirtualHandler.GetInstalledHandler(m_cache, "ReversalIndex", "AllEntries");
            int flid = vh.Tag;

            base.ReallyDeleteUnderlyingObject();

            // Remove goner from the cache.
            vh.Load(hvoIndex, flid, 0, m_cache.VwCacheDaAccessor);

            m_cache.MainCacheAccessor.PropChanged(
                null,
                (int)PropChangeType.kpctNotifyAll,
                hvoIndex,
                flid,
                0,
                0,
                1);
        }
        /// <summary>
        /// Execute the change requested by the current selection in the combo.
        /// Basically we want the PartOfSpeech indicated by m_selectedHvo, even if 0,
        /// to become the POS of each record that is appropriate to change.
        /// We do nothing to records where the check box is turned off,
        /// and nothing to ones that currently have an MSA other than an MoStemMsa.
        /// (a) If the owning entry has an MoStemMsa with the
        /// right POS, set the sense to use it.
        /// (b) If the sense already refers to an MoStemMsa, and any other senses
        /// of that entry which point at it are also to be changed, change the POS
        /// of the MSA.
        /// (c) If the entry has an MoStemMsa which is not used at all, change it to the
        /// required POS and use it.
        /// (d) Make a new MoStemMsa in the LexEntry with the required POS and point the sense at it.
        /// </summary>
        public override void DoIt(Set <int> itemsToChange, ProgressState state)
        {
            CheckDisposed();

            m_cache.BeginUndoTask(LexEdStrings.ksUndoBulkEditRevPOS, LexEdStrings.ksRedoBulkEditRevPOS);
            BulkEditBar.ForceRefreshOnUndoRedo(m_cache.MainCacheAccessor);
            int i        = 0;
            int interval = Math.Min(100, Math.Max(itemsToChange.Count / 50, 1));

            foreach (int entryId in itemsToChange)
            {
                i++;
                if (i % interval == 0)
                {
                    state.PercentDone = i * 80 / itemsToChange.Count + 20;
                    state.Breath();
                }
                IReversalIndexEntry entry = ReversalIndexEntry.CreateFromDBObject(m_cache, entryId);
                entry.PartOfSpeechRAHvo = m_selectedHvo;
            }
            m_cache.EndUndoTask();
        }
Exemple #18
0
        /// <summary>
        /// Handles the xCore message to go to a reversal entry.
        /// </summary>
        /// <param name="argument">The xCore Command object.</param>
        /// <returns>true</returns>
        public bool OnGotoReversalEntry(object argument)
        {
            CheckDisposed();

            using (ReversalEntryGoDlg dlg = new ReversalEntryGoDlg())
            {
                List <IReversalIndexEntry> filteredEntries = new List <IReversalIndexEntry>();
                filteredEntries.Add(Entry);
                WindowParams wp = new WindowParams();
                wp.m_btnText = LexEdStrings.ks_GoTo;
                wp.m_label   = LexEdStrings.ks_Find_;
                wp.m_title   = LexEdStrings.ksFindRevEntry;
                dlg.SetDlgInfo(m_mediator, wp, filteredEntries);                 // , false
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    // Can't Go to a subentry, so we have to go to its main entry.
                    FdoCache            cache    = (FdoCache)m_mediator.PropertyTable.GetValue("cache");
                    IReversalIndexEntry selEntry = ReversalIndexEntry.CreateFromDBObject(cache, dlg.SelectedID);
                    m_mediator.BroadcastMessageUntilHandled("JumpToRecord", selEntry.MainEntry.Hvo);
                }
            }
            return(true);
        }
        protected override DummyCmObject GetMergeinfo(WindowParams wp, List <DummyCmObject> mergeCandidates, out string guiControl, out string helpTopic)
        {
            wp.m_title = FdoUiStrings.ksMergeReversalEntry;
            wp.m_label = FdoUiStrings.ksEntries;

            IReversalIndexEntry rie = ReversalIndexEntry.CreateFromDBObject(m_cache, Object.Hvo);
            int wsIndex             = rie.ReversalIndex.WritingSystemRAHvo;

            foreach (int rieInnerHvo in rie.ReversalIndex.AllEntries)
            {
                IReversalIndexEntry rieInner = ReversalIndexEntry.CreateFromDBObject(m_cache, rieInnerHvo);
                if (rieInner.Hvo != Object.Hvo)
                {
                    mergeCandidates.Add(
                        new DummyCmObject(
                            rieInner.Hvo,
                            rieInner.ShortName,
                            wsIndex));
                }
            }
            guiControl = "MergeReversalEntryList";
            helpTopic  = "khtpMergeReversalEntry";
            return(new DummyCmObject(m_hvo, rie.ShortName, wsIndex));
        }
Exemple #20
0
        public void DummyReversalCreatedOnFocusLost()
        {
            NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
            {
                m_lexEntry      = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
                ILexSense sense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();
                m_lexEntry.SensesOS.Add(sense);
            });
            int engWsId = Cache.DefaultAnalWs;

            m_reversalSlice       = new DummyReversalIndexEntrySlice(m_lexEntry.SensesOS[0]);
            m_reversalSlice.Cache = Cache;

            // Creating the reversal index before the slice is fully initialized ensures the reversal index gets loaded into the dummy cache
            IReversalIndex ri = m_revIndexRepo.FindOrCreateIndexForWs(engWsId);

            m_reversalSlice.FinishInit();
            DummyReversalIndexEntrySliceView reversalView = m_reversalSlice.DummyControl;
            int indexFirstEntry = 0;

            reversalView.CacheNewDummyEntry(ri.Hvo, engWsId);             // Create an additional dummy reversal entry before we edit one
            reversalView.EditRevIndexEntryInCache(ri.Hvo, indexFirstEntry, engWsId, TsStringUtils.MakeString("first", engWsId));

            // The dummy cache will have two dummy reversal index entries, but non exists in the real data yet.
            // The reversal index entry control must maintain a dummy entry at the end to allow a place to click to add new entries.
            Assert.AreEqual(0, m_revIndexEntryRepo.Count);
            Assert.AreEqual(2, reversalView.GetIndexSize(ri.Hvo));             // The second dummy entry will remain a dummy
            reversalView.KillFocus(new Control());
            Assert.AreEqual(1, m_revIndexEntryRepo.Count);
            Assert.AreEqual(2, reversalView.GetIndexSize(ri.Hvo));
            IReversalIndexEntry rie = m_revIndexEntryRepo.AllInstances().First();

            Assert.AreEqual("first", rie.ShortName);
            Assert.AreEqual(1, m_lexEntry.SensesOS[0].ReferringReversalIndexEntries.Count());
            Assert.True(m_lexEntry.SensesOS[0].ReferringReversalIndexEntries.Contains(rie));
        }
Exemple #21
0
		private void WriteReversal(TextWriter w, IReversalIndexEntry reversal)
		{
			w.Write("<reversal type=\"{0}\">", MakeSafeAndNormalizedAttribute(reversal.ReversalIndex.WritingSystem));
			WriteAllForms(w, null, null, "form", reversal.ReversalForm);
			if (reversal.PartOfSpeechRA != null)
				w.WriteLine("<grammatical-info value=\"{0}\"/>", BestAlternative(reversal.PartOfSpeechRA.Name, m_wsEn));
			if (reversal.OwningEntry != null)
				WriteOwningReversal(w, reversal.OwningEntry);
			w.WriteLine("</reversal>");
		}
        protected IReversalIndexEntry CreateReversalIndexSubEntry(string subEntryForm, IReversalIndexEntry indexEntry)
        {
            var wsObj         = Cache.LanguageProject.DefaultAnalysisWritingSystem;
            var revIndexEntry = m_revIndexEntryFactory.Create();

            indexEntry.SubentriesOS.Add(revIndexEntry);
            revIndexEntry.ReversalForm.set_String(wsObj.Handle, Cache.TsStrFactory.MakeString(subEntryForm, wsObj.Handle));
            return(revIndexEntry);
        }
 private static void AddEntryAndChildrenRecursively(ICollection <int> hvos, IReversalIndexEntry entry)
 {
     hvos.Add(entry.Hvo);
     entry.AllOwnedObjects.Where(obj => obj is IReversalIndexEntry).ForEach(subentry => hvos.Add(subentry.Hvo));
 }
Exemple #24
0
		/// <summary>
		/// Move 'this' to a safe place, if needed.
		/// </summary>
		/// <param name="rieSrc"></param>
		/// <remarks>
		/// When merging or moving a reversal entry, the new home ('this') may actually be owned by
		/// the other entry, in which case 'this' needs to be relocated, before the merge/move.
		/// </remarks>
		/// <returns>
		/// 1. The new owner (ReversalIndex or ReversalIndexEntry), or
		/// 2. null, if no move was needed.
		/// </returns>
		public ICmObject MoveIfNeeded(IReversalIndexEntry rieSrc)
		{
			Debug.Assert(rieSrc != null);
			ICmObject newOwner = null;
			IReversalIndexEntry rieOwner = this;
			while (true)
			{
				rieOwner = rieOwner.OwningEntry;
				if (rieOwner == null || rieOwner.Equals(rieSrc))
					break;
			}
			if (rieOwner != null && rieOwner.Equals(rieSrc))
			{
				// Have to move 'this' to a safe location.
				rieOwner = rieSrc.OwningEntry;
				if (rieOwner != null)
				{
					rieOwner.SubentriesOC.Add(this);
					newOwner = rieOwner;
				}
				else
				{
					// Move it clear up to the index.
					IReversalIndex ri = rieSrc.ReversalIndex;
					ri.EntriesOC.Add(this);
					newOwner = ri;
				}
			}
			// 'else' means there is no ownership issues to using normal merging/moving.

			return newOwner;
		}
        public void FindOrCreateReversalEntry()
        {
            int            wsEn     = Cache.DefaultAnalWs;
            IReversalIndex revIndex = null;

            UndoableUnitOfWorkHelper.Do("undo make index", "redo make index", m_actionHandler,
                                        () =>
            {
                revIndex =
                    Cache.ServiceLocator.GetInstance <IReversalIndexRepository>().FindOrCreateIndexForWs(wsEn);
            });
            IReversalIndexEntry empty = null;

            UndoableUnitOfWorkHelper.Do("undo make rie", "redo make rie", m_actionHandler,
                                        () =>
            {
                empty = revIndex.FindOrCreateReversalEntry("");
            });
            IReversalIndexEntry bank = null;

            UndoableUnitOfWorkHelper.Do("undo make rie", "redo make rie", m_actionHandler,
                                        () =>
            {
                bank = revIndex.FindOrCreateReversalEntry("bank");
            });

            Assert.IsNotNull(bank);
            Assert.AreEqual("bank", bank.LongName);

            m_actionHandler.Undo();             // deletes bank

            IReversalIndexEntry bank2 = null;

            UndoableUnitOfWorkHelper.Do("undo make rie", "redo make rie", m_actionHandler,
                                        () =>
            {
                bank2 = revIndex.FindOrCreateReversalEntry("bank");
            });
            Assert.AreNotEqual(bank, bank2, "should make a new rie after Undo deletes old one");

            // Enhance JohnT: if we could look for one without creating it, we should test that Redo will
            // reinstate the old object. But we can't Redo that action, because we've made new actions since.

            bank = bank2;             // treat that as the base from here on.
            UndoableUnitOfWorkHelper.Do("undo make rie", "redo make rie", m_actionHandler,
                                        () =>
            {
                bank2 = revIndex.FindOrCreateReversalEntry("bank");
            });
            Assert.AreEqual(bank, bank2, "should find the same RIE for the same name");

            IReversalIndexEntry moneybank = null;

            UndoableUnitOfWorkHelper.Do("undo set rie name", "redo set rie name", m_actionHandler,
                                        () =>
            {
                bank.ReversalForm.set_String(wsEn, bank.Cache.TsStrFactory.MakeString("moneybank", wsEn));
                moneybank = revIndex.FindOrCreateReversalEntry("moneybank");
            });
            Assert.AreEqual(bank, moneybank, "changing existing name should allow us to find old one under new name");

            m_actionHandler.Undo();                            // name is back to 'bank'
            bank = revIndex.FindOrCreateReversalEntry("bank"); // should not need UOW
            Assert.AreEqual(bank, moneybank, "after Undo should find same item under original name");
            m_actionHandler.Redo();
            moneybank = revIndex.FindOrCreateReversalEntry("moneybank");
            Assert.AreEqual(bank, moneybank, "after Redodo should find same item under new name");

            UndoableUnitOfWorkHelper.Do("undo rest of stuff", "redo rest of stuff", m_actionHandler,
                                        () =>
            {
                bank = revIndex.FindOrCreateReversalEntry("bank");
                Assert.IsNotNull(bank);
                Assert.AreNotEqual(bank, moneybank,
                                   "after rename, should make new object when looking up old name");

                var riverbank = revIndex.FindOrCreateReversalEntry("bank:of river");
                Assert.AreEqual("of river", riverbank.ShortName);
                Assert.AreEqual("bank: of river", riverbank.LongName);
                Assert.AreEqual(bank, riverbank.Owner);
                var riverbank2 = revIndex.FindOrCreateReversalEntry("bank: of river");
                Assert.AreEqual(riverbank, riverbank2);

                moneybank = revIndex.FindOrCreateReversalEntry("bank: for money");
                Assert.IsNotNull(moneybank);
                Assert.AreNotEqual(riverbank, moneybank);
                Assert.AreEqual("bank: for money", moneybank.LongName);

                var planebank = revIndex.FindOrCreateReversalEntry("bank: tilt:plane");
                Assert.AreEqual("bank: tilt: plane", planebank.LongName);
                Assert.AreEqual(bank, planebank.Owner.Owner);
            });
        }
		protected IReversalIndex AddReversalIndex(List<ICmObject> addList, IReversalIndexEntry revIndexEntry)
		{
			Assert.IsNotNull(m_revIndexFactory, "Fixture Initialization is not complete.");
			Assert.IsNotNull(m_window, "No window.");

			//create a reversal index for this project.
			var wsObj = Cache.LanguageProject.DefaultAnalysisWritingSystem;
			IReversalIndex revIndex = m_revIndexRepo.FindOrCreateIndexForWs(wsObj.Handle);
			//Add an entry to the Reveral index
			revIndex.EntriesOC.Add(revIndexEntry);

			addList.Add(revIndex);
			return revIndex;
		}
		/// <summary>
		/// Executes in two distinct scenarios.
		///
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		///
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing"></param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		///
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		protected virtual void Dispose(bool disposing)
		{
			System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
			// Must not be run more than once.
			if (m_isDisposed)
				return;

			if (disposing)
			{
				if (Disposed != null)
					Disposed(this, new EventArgs());

				// Dispose managed resources here.
				if (m_rlu != null)
					m_rlu.RecordChangeHandler = null;
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_rie = null;
			m_originalForm = null;
			m_rlu = null;

			m_isDisposed = true;
		}
		private static void AddEntryAndChildrenRecursively(ICollection<int> hvos, IReversalIndexEntry entry)
		{
			hvos.Add(entry.Hvo);
			entry.AllOwnedObjects.Where(obj => obj is IReversalIndexEntry).ForEach(subentry => hvos.Add(subentry.Hvo));
		}
Exemple #29
0
		private void WriteOwningReversal(TextWriter w, IReversalIndexEntry reversal)
		{
			w.WriteLine("<main>");
			WriteAllForms(w, null, null, "form", reversal.ReversalForm);
			if (reversal.PartOfSpeechRA != null)
				w.WriteLine("<grammatical-info value=\"{0}\"/>", BestAlternative(reversal.PartOfSpeechRA.Name, m_wsEn));
			if (reversal.OwningEntry != null)
				WriteOwningReversal(w, reversal.OwningEntry);
			w.WriteLine("</main>");
		}
		/// <summary></summary>
		public void Setup(object o, IRecordListUpdater rlu)
		{
			CheckDisposed();

			Debug.Assert(o != null && o is IReversalIndexEntry);
			IReversalIndexEntry rie = o as IReversalIndexEntry;
			if (m_rlu == null && rlu != null && m_rie == rie)
			{
				m_rlu = rlu;
				m_rlu.RecordChangeHandler = this;
				m_rlu.UpdateList(true);
			}
			else
			{
				m_rie = rie;
				Debug.Assert(m_rie != null);
				int ws = m_rie.Services.WritingSystemManager.GetWsFromStr(m_rie.ReversalIndex.WritingSystem);
				m_originalForm = m_rie.ReversalForm.get_String(ws).Text;
				if (rlu != null)
				{
					m_rlu = rlu;
					m_rlu.RecordChangeHandler = this;
				}
			}
		}