/// <summary> /// Override method to add suitable control. /// </summary> public override void FinishInit() { CheckDisposed(); Debug.Assert(m_cache != null); Debug.Assert(m_configurationNode != null); base.FinishInit(); EntrySequenceReferenceLauncher launcher = new EntrySequenceReferenceLauncher(); string className = m_cache.MetaDataCacheAccessor.GetClassName((uint)m_obj.ClassID); m_fieldName = XmlUtils.GetManditoryAttributeValue(m_configurationNode, "field"); m_flid = AutoDataTreeMenuHandler.ContextMenuHelper.GetFlid(m_cache.MetaDataCacheAccessor, className, m_fieldName); launcher.Initialize(m_cache, m_obj, m_flid, m_fieldName, null, Mediator, DisplayNameProperty, BestWsName); // TODO: Get better default 'best ws'. // We don't want to be visible until later, since otherwise we get a temporary // display in the wrong place with the wrong size that serves only to annoy the // user. See LT-1518 "The drawing of the DataTree for Lexicon/Advanced Edit draws // some initial invalid controls." Becoming visible when we set the width and // height seems to delay things enough to avoid this visual clutter. launcher.Visible = false; Control = launcher; launcher.ViewSizeChanged += new FwViewSizeChangedEventHandler(this.OnViewSizeChanged); VectorReferenceView view = (VectorReferenceView)launcher.MainControl; view.ViewSizeChanged += new FwViewSizeChangedEventHandler(this.OnViewSizeChanged); }
public override ObjectLabel Execute() { ObjectLabel result = null; if (m_lexEntryRef != null) { using (LinkEntryOrSenseDlg dlg = new LinkEntryOrSenseDlg()) { ILexEntry le = null; // assume the owner is the entry (e.g. owner of LexEntryRef) le = m_lexEntryRef.OwnerOfClass <ILexEntry>(); dlg.SetDlgInfo(m_cache, m_mediator, le); dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense"); if (dlg.ShowDialog(m_parentWindow) == DialogResult.OK) { ICmObject obj = dlg.SelectedObject; if (obj != null) { if (!m_lexEntryRef.PrimaryLexemesRS.Contains(obj)) { try { UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW( LexEdStrings.ksUndoCreatingEntry, LexEdStrings.ksRedoCreatingEntry, Cache.ActionHandlerAccessor, () => { if (!m_lexEntryRef.ComponentLexemesRS.Contains(obj)) { m_lexEntryRef.ComponentLexemesRS.Add(obj); } m_lexEntryRef.PrimaryLexemesRS.Add(obj); }); } catch (ArgumentException) { EntrySequenceReferenceLauncher.ReportComponentFailure((ILexEntry)m_lexEntryRef.Owner, obj, true); } } } } } } return(result); }
/// <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 override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) { return; } if (disposing) { // Dispose managed resources here. EntrySequenceReferenceLauncher launcher = Control as EntrySequenceReferenceLauncher; launcher.ViewSizeChanged -= new FwViewSizeChangedEventHandler(this.OnViewSizeChanged); VectorReferenceView view = (VectorReferenceView)launcher.MainControl; view.ViewSizeChanged -= new FwViewSizeChangedEventHandler(this.OnViewSizeChanged); } // Dispose unmanaged resources here, whether disposing is true or false. base.Dispose(disposing); }
public override ObjectLabel Execute() { ObjectLabel result = null; if (m_lexEntry != null) { using (var dlg = new EntryGoDlg()) { dlg.SetDlgInfo(m_cache, null, m_mediator); dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense"); // TODO: When LT-11318 is fixed, use its help topic ID. dlg.SetOkButtonText(LexEdStrings.ksMakeComponentOf); if (dlg.ShowDialog(m_parentWindow) == DialogResult.OK) { try { if (m_lexSense != null) { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoAddComplexForm, LexEdStrings.ksRedoAddComplexForm, m_lexEntry.Cache.ActionHandlerAccessor, () => ((ILexEntry)dlg.SelectedObject).AddComponent((ICmObject)m_lexSense ?? m_lexEntry)); } else { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoAddComplexForm, LexEdStrings.ksRedoAddComplexForm, m_lexEntry.Cache.ActionHandlerAccessor, () => ((ILexEntry)dlg.SelectedObject).AddComponent(m_lexEntry)); } } catch (ArgumentException) { EntrySequenceReferenceLauncher.ReportComponentFailure((ILexEntry)dlg.SelectedObject, m_lexEntry, false); } } } } return(result); }
/// <summary> /// The user selected an item; now we actually need a LexEntryRef. /// </summary> /// <param name="hvoNew"></param> private void AddItem(ICmObject newObj) { CheckDisposed(); bool fForVariant = XmlUtils.GetOptionalBooleanAttributeValue(m_configurationNode, "forVariant", false); string sUndo, sRedo; if (fForVariant) { sUndo = LexEdStrings.ksUndoVariantOf; sRedo = LexEdStrings.ksRedoVariantOf; } else { sUndo = LexEdStrings.ksUndoAddComponent; sRedo = LexEdStrings.ksRedoAddComponent; } try { UndoableUnitOfWorkHelper.Do(sUndo, sRedo, m_obj, () => { ILexEntry ent = m_obj as ILexEntry; // Adapted from part of DtMenuHandler.AddNewLexEntryRef. ILexEntryRef ler = ent.Services.GetInstance <ILexEntryRefFactory>().Create(); ent.EntryRefsOS.Add(ler); if (fForVariant) { // The slice this is part of should only be displayed for lex entries with no VariantEntryRefs. Debug.Assert(ent.VariantEntryRefs.Count() == 0); ler.VariantEntryTypesRS.Add(ent.Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0] as ILexEntryType); ler.RefType = LexEntryRefTags.krtVariant; ler.HideMinorEntry = 0; } else { // The slice this is part of should only be displayed for lex entries with no ComplexEntryRefs. Debug.Assert(ent.ComplexFormEntryRefs.Count() == 0); //ler.ComplexEntryTypesRS.Append(ent.Cache.LangProject.LexDbOA.ComplexEntryTypesOA.PossibilitiesOS[0].Hvo); ler.RefType = LexEntryRefTags.krtComplexForm; ler.HideMinorEntry = 0; // LT-10928 // Logic similar to this is in EntrySequenceReferenceLauncher.AddNewObjectsToProperty() // (when LER already exists so slice is not ghost) ler.PrimaryLexemesRS.Add(newObj); // Since it's a new LER, we can't know it to be a derivative, so by default it is visible. // but do NOT do that here, it's now built into the process of adding it to PrimaryLexemes, // and we don't want to do it twice. // ler.ShowComplexFormsInRS.Add(newObj); ent.ChangeRootToStem(); } // Must do this AFTER setting the RefType (so dependent virtual properties can be updated properly) ler.ComponentLexemesRS.Add(newObj); }); } catch (ArgumentException) { EntrySequenceReferenceLauncher.ReportComponentFailure((ILexEntry)m_obj, newObj, true); return; } }