Exemple #1
0
        private void HandleChooserForBackRefs(string fieldName, bool fPropContainsEntryRefs)
        {
            string displayWs = "analysis vernacular";
            IEnumerable <ICmObject> options;

            if (m_obj is ILexEntry)
            {
                options = ((ILexEntry)m_obj).ComplexFormEntries.Cast <ICmObject>();
            }
            else
            {
                options = ((ILexSense)m_obj).ComplexFormEntries.Cast <ICmObject>();
            }
            var oldValue = from hvo in ((ISilDataAccessManaged)m_cache.DomainDataByFlid).VecProp(m_obj.Hvo, m_flid)
                           select m_cache.ServiceLocator.GetObject(hvo);

            // We want a collection of LexEntries as the current values. If we're displaying lex entry refs we want their owners.
            if (fPropContainsEntryRefs)
            {
                oldValue = from obj in oldValue select obj.Owner;
            }

            var labels = ObjectLabel.CreateObjectLabels(m_cache, options,
                                                        m_displayNameProperty, displayWs);

            using (ReallySimpleListChooser chooser = new ReallySimpleListChooser(null,
                                                                                 labels, fieldName, m_cache, oldValue,
                                                                                 false, m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider")))
            {
                chooser.HideDisplayUsageCheckBox();
                chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);                    // may set TextParamHvo
                chooser.Text = fieldName == "Subentries" ? LexEdStrings.ksChooseSubentries : LexEdStrings.ksChooseVisibleComplexForms;
                chooser.SetHelpTopic(Slice.GetChooserHelpTopicID() + "-CFChooser");
                chooser.InitializeExtras(null, Mediator, m_propertyTable);
                // Step 3 of LT-11155:
                chooser.AddLink(LexEdStrings.ksAddAComplexForm, ReallySimpleListChooser.LinkType.kDialogLink,
                                new AddComplexFormChooserCommand(m_cache, false, null, m_mediator, m_propertyTable, m_obj, FindForm()));
                DialogResult res = chooser.ShowDialog();
                if (DialogResult.Cancel == res)
                {
                    return;
                }
                var chosenObjects = chooser.ChosenObjects;
                if (chosenObjects != null)
                {
                    if (fPropContainsEntryRefs)
                    {
                        chosenObjects = from ILexEntry le in chosenObjects
                                        from ler in le.EntryRefsOS
                                        where ler.RefType == LexEntryRefTags.krtComplexForm
                                        select(ICmObject) ler;
                    }
                    SetItems(chosenObjects);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Override method to handle launching of a chooser for selecting lexical entries or senses.
        /// </summary>
        protected override void HandleChooser()
        {
            if (m_flid == LexEntryRefTags.kflidComponentLexemes)
            {
                using (LinkEntryOrSenseDlg dlg = new LinkEntryOrSenseDlg())
                {
                    ILexEntry le = null;
                    if (m_obj.ClassID == LexEntryTags.kClassId)
                    {
                        // filter this entry from the list.
                        le = m_obj as ILexEntry;
                    }
                    else
                    {
                        // assume the owner is the entry (e.g. owner of LexEntryRef)
                        le = m_obj.OwnerOfClass <ILexEntry>();
                    }
                    dlg.SetDlgInfo(m_cache, m_mediator, m_propertyTable, le);
                    String str = ShowHelp.RemoveSpaces(this.Slice.Label);
                    dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense-" + str);
                    if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
                    {
                        AddItem(dlg.SelectedObject);
                    }
                }
            }
            else if (m_flid == LexEntryRefTags.kflidPrimaryLexemes)
            {
                string displayWs = "analysis vernacular";
                if (m_configurationNode != null)
                {
                    XmlNode node = m_configurationNode.SelectSingleNode("deParams");
                    if (node != null)
                    {
                        displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
                    }
                }
                ILexEntryRef ler = m_obj as ILexEntryRef;
                Debug.Assert(ler != null);
                var labels = ObjectLabel.CreateObjectLabels(m_cache, ler.ComponentLexemesRS.Cast <ICmObject>(),
                                                            m_displayNameProperty, displayWs);
                using (ReallySimpleListChooser chooser = new ReallySimpleListChooser(null,
                                                                                     labels, "PrimaryLexemes", m_cache, ler.PrimaryLexemesRS.Cast <ICmObject>(),
                                                                                     false, m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider")))
                {
                    chooser.HideDisplayUsageCheckBox();
                    chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);                        // may set TextParamHvo
                    chooser.Text = LexEdStrings.ksChooseWhereToShowSubentry;
                    chooser.SetHelpTopic(Slice.GetChooserHelpTopicID());
                    chooser.InitializeExtras(null, Mediator, m_propertyTable);
                    chooser.AddLink(LexEdStrings.ksAddAComponent, ReallySimpleListChooser.LinkType.kDialogLink,
                                    new AddPrimaryLexemeChooserCommand(m_cache, false, null, m_mediator, m_propertyTable, m_obj, FindForm()));
                    DialogResult res = chooser.ShowDialog();
                    if (DialogResult.Cancel == res)
                    {
                        return;
                    }
                    if (chooser.ChosenObjects != null)
                    {
                        SetItems(chooser.ChosenObjects);
                    }
                }
            }
            else
            {
                string fieldName = m_obj.Cache.MetaDataCacheAccessor.GetFieldName(m_flid);
                Debug.Assert(m_obj is ILexEntry || m_obj is ILexSense);
                switch (fieldName)
                {
                case "ComplexFormEntries":
                    using (var dlg = new EntryGoDlg())
                    {
                        dlg.StartingEntry = m_obj as ILexEntry ?? (m_obj as ILexSense).Entry;
                        dlg.SetDlgInfo(m_cache, null, m_mediator, m_propertyTable);
                        String str = ShowHelp.RemoveSpaces(Slice.Label);
                        dlg.SetHelpTopic("khtpChooseComplexFormEntryOrSense-" + str);
                        dlg.SetOkButtonText(LexEdStrings.ksMakeComponentOf);
                        if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
                        {
                            try
                            {
                                UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoAddComplexForm, LexEdStrings.ksRedoAddComplexForm,
                                                            m_obj.Cache.ActionHandlerAccessor,
                                                            () => ((ILexEntry)dlg.SelectedObject).AddComponent(m_obj));
                            }
                            catch (ArgumentException)
                            {
                                MessageBoxes.ReportLexEntryCircularReference(dlg.SelectedObject, m_obj, false);
                            }
                        }
                    }
                    break;

                case "VisibleComplexFormEntries":                         // obsolete?
                case "Subentries":
                    HandleChooserForBackRefs(fieldName, false);
                    break;

                case "VisibleComplexFormBackRefs":
                    HandleChooserForBackRefs(fieldName, true);
                    break;

                default:
                    Debug.Fail("EntrySequenceReferenceLauncher should only be used for variants, components, or complex forms");
                    break;
                }
            }
        }
        /// <summary>
        /// Override method to handle launching of a chooser for selecting lexical entries or senses.
        /// </summary>
        protected override void HandleChooser()
        {
            Debug.Assert(m_flid == (int)LexEntryRef.LexEntryRefTags.kflidComponentLexemes ||
                         m_flid == (int)LexEntryRef.LexEntryRefTags.kflidPrimaryLexemes);
            if (m_flid == (int)LexEntryRef.LexEntryRefTags.kflidComponentLexemes)
            {
                using (LinkEntryOrSenseDlg dlg = new LinkEntryOrSenseDlg())
                {
                    ILexEntry le = null;
                    if (m_obj.ClassID == LexEntry.kclsidLexEntry)
                    {
                        // filter this entry from the list.
                        le = m_obj as ILexEntry;
                    }
                    else
                    {
                        // assume the owner is the entry (e.g. owner of LexEntryRef)
                        int hvoEntry = m_cache.GetOwnerOfObjectOfClass(m_obj.Hvo, LexEntry.kclsidLexEntry);
                        if (hvoEntry != 0)
                        {
                            le = LexEntry.CreateFromDBObject(m_cache, hvoEntry);
                        }
                    }
                    dlg.SetDlgInfo(m_cache, m_mediator, le);
                    String str = ShowHelp.RemoveSpaces(this.Slice.Label);
                    dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense-" + str);
                    if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
                    {
                        AddItem(dlg.SelectedID);
                    }
                }
            }
            else if (m_flid == (int)LexEntryRef.LexEntryRefTags.kflidPrimaryLexemes)
            {
                string displayWs = "analysis vernacular";
                if (m_configurationNode != null)
                {
                    XmlNode node = m_configurationNode.SelectSingleNode("deParams");
                    if (node != null)
                    {
                        displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
                    }
                }
                ILexEntryRef ler = m_obj as ILexEntryRef;
                Debug.Assert(ler != null);
                List <int> candidates = new List <int>();
                candidates.AddRange(ler.ComponentLexemesRS.HvoArray);
                ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates,
                                                                         m_displayNameProperty, displayWs);
                using (ReallySimpleListChooser chooser = new ReallySimpleListChooser(null,
                                                                                     labels, "PrimaryLexemes", m_cache, ler.PrimaryLexemesRS.HvoArray, false))

                {
                    chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);                        // may set TextParamHvo

                    chooser.Text = "Choose where to show subentry";

                    //chooser.ReplaceTreeView(Mediator, "WordformsBrowseView");

                    chooser.InitializeExtras(null, Mediator);
                    chooser.AddLink("Add a Component...", ReallySimpleListChooser.LinkType.kDialogLink,
                                    new AddComponentChooserCommand(m_cache, false, null, m_mediator, m_obj, FindForm()));
                    DialogResult res = chooser.ShowDialog();
                    if (DialogResult.Cancel == res)
                    {
                        return;
                    }
                    if (chooser.ChosenHvos != null)
                    {
                        SetItems(chooser.ChosenHvos);
                    }
                }
            }
        }