Esempio n. 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);
                }
            }
        }
        public static SimpleListChooser MakeSenseChooser(FdoCache cache,
                                                         IHelpTopicProvider helpTopicProvider)
        {
            var senses = cache.ServiceLocator.GetInstance <ILexSenseRepository>().AllInstances();
            var labels = ObjectLabel.CreateObjectLabels(cache, senses.Cast <ICmObject>(), "LongNameTSS");
            SimpleListChooser chooser = new SimpleListChooser(null, labels,
                                                              LexEdStrings.ksSenses, helpTopicProvider);

            chooser.Cache = cache;
            return(chooser);
        }
Esempio n. 3
0
		/// <summary>
		/// Handle launching of the environment chooser.
		/// </summary>
		/// <remarks>
		/// Subclasses should override this method, if the SimpleListChooser is not suitable.
		/// </remarks>
		protected override void HandleChooser()
		{
			// get all valid environments
			var candidates = new HashSet<ICmObject>();
			foreach (var env in m_cache.LangProject.PhonologicalDataOA.EnvironmentsOS)
			{
				ConstraintFailure failure;
				if (env.CheckConstraints(PhEnvironmentTags.kflidStringRepresentation, false, out failure))
					candidates.Add(env);
			}

			string displayWs = "analysis vernacular";
			IPhEnvironment selectedEnv = null;
			if (m_configurationNode != null)
			{
				XmlNode node = m_configurationNode.SelectSingleNode("deParams");
				if (node != null)
					displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
			}

			var labels = ObjectLabel.CreateObjectLabels(m_cache, candidates.OrderBy(e => e.ShortName), null, displayWs);

			using (var chooser = new SimpleListChooser(m_persistProvider, labels,
				m_fieldName, m_mediator.HelpTopicProvider))
			{
				chooser.Cache = m_cache;
				chooser.TextParamHvo = m_cache.LangProject.PhonologicalDataOA.Hvo;
				chooser.SetHelpTopic(Slice.GetChooserHelpTopicID(Slice.HelpTopicID));
				chooser.InitializeExtras(m_configurationNode, m_mediator);

				DialogResult res = chooser.ShowDialog();
				if (res != DialogResult.Cancel)
				{
					chooser.HandleAnyJump();

					if (chooser.ChosenOne != null)
						selectedEnv = chooser.ChosenOne.Object as IPhEnvironment;
				}
			}

			// return focus to the view
			m_view.Select();
			if (selectedEnv != null)
			{
				int cellId = -1;
				UndoableUnitOfWorkHelper.Do(MEStrings.ksRuleUndoUpdateEnv, MEStrings.ksRuleRedoUpdateEnv, selectedEnv, () =>
				{
					cellId = UpdateEnvironment(selectedEnv);
				});

				ReconstructView(cellId, -1, true);
			}
		}
        internal ICmObject DisplayChooser(string fieldName, string linkText, string toolName, string guiControl,
                                          IEnumerable <ICmObject> candidates)
        {
            ICmObject obj = null;

            var labels = ObjectLabel.CreateObjectLabels(m_cache, candidates);

            using (var chooser = new SimpleListChooser(m_persistenceProvider, labels,
                                                       fieldName, m_mediator.HelpTopicProvider))
            {
                chooser.Cache        = m_cache;
                chooser.TextParamHvo = m_cache.LangProject.PhonologicalDataOA.Hvo;
                Guid guidTextParam = m_cache.LangProject.PhonologicalDataOA.Guid;
                chooser.AddLink(linkText, SimpleListChooser.LinkType.kGotoLink,
                                new FwLinkArgs(toolName, guidTextParam));
                chooser.ReplaceTreeView(m_mediator, guiControl);
                if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.RegRuleFormulaControl)
                {
                    chooser.SetHelpTopic("khtpChoose-Grammar-PhonFeats-RegRuleFormulaControl");
                }
                else if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.MetaRuleFormulaControl)
                {
                    chooser.SetHelpTopic("khtpChoose-Grammar-PhonFeats-MetaRuleFormulaControl");
                }
                else if (this.Parent is SIL.FieldWorks.XWorks.MorphologyEditor.AffixRuleFormulaControl)
                {
                    chooser.SetHelpTopic("khtpChoose-LexiconEdit-PhonFeats-AffixRuleFormulaControl");
                }

                DialogResult res = chooser.ShowDialog();
                if (res != DialogResult.Cancel)
                {
                    chooser.HandleAnyJump();

                    if (chooser.ChosenOne != null)
                    {
                        obj = chooser.ChosenOne.Object;
                    }
                }
            }

            return(obj);
        }
Esempio n. 5
0
        private void SearchSemanticDomains()
        {
            IEnumerable <ObjectLabel> labels = new List <ObjectLabel>();

            // The FindDomainsThatMatch method returns IEnumerable<ICmSemanticDomain>
            // based on the search string we give it.
            var searchString = TrimmedSearchBoxText;

            if (!string.IsNullOrEmpty(searchString))
            {
                if (m_searchIconSet)
                {
                    // When disabled, we use a Background image rather than a regular image so that it
                    // does not gray out. When showing the search icon, the button is never enabled,
                    // so it is a shame to have it grey-out our pretty magnifying glass. The X however
                    // can work as a normal button image (which avoids needing to make it larger
                    // than the button etc. in order to avoid repeating it as wallpaper, which is how
                    // BackgroundImage works.)
                    btnCancelSearch.Image           = FieldWorks.Resources.Images.X;
                    btnCancelSearch.BackgroundImage = null;
                    m_searchIconSet         = false;
                    btnCancelSearch.Enabled = true;
                }
                domainList.ItemChecked -= OnDomainListChecked;
                var semDomainsToShow = m_semdomRepo.FindDomainsThatMatch(searchString);
                SemanticDomainSelectionUtility.UpdateDomainListLabels(ObjectLabel.CreateObjectLabels(Cache, semDomainsToShow, string.Empty, DisplayWs), domainList, displayUsageCheckBox.Checked);
                domainTree.Visible      = false;
                domainList.Visible      = true;
                domainList.ItemChecked += OnDomainListChecked;
            }
            else
            {
                domainTree.Visible = true;
                domainList.Visible = false;
                if (!m_searchIconSet)
                {
                    btnCancelSearch.BackgroundImage = FieldWorks.Resources.Images.Search;
                    btnCancelSearch.Image           = null;
                    m_searchIconSet         = true;
                    btnCancelSearch.Enabled = false;
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Override method to handle launching of a chooser for selecting lexical entries.
        /// </summary>
        protected override void HandleChooser()
        {
            string displayWs = "analysis vernacular";

#pragma warning disable 219
            string postDialogMessageTrigger = null;
#pragma warning restore 219

            if (m_configurationNode != null)
            {
                XmlNode node = m_configurationNode.SelectSingleNode("deParams");
                if (node != null)
                {
                    displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
                    postDialogMessageTrigger = XmlUtils.GetAttributeValue(node, "postChangeMessageTrigger", null);
                }
            }

            var labels = ObjectLabel.CreateObjectLabels(m_cache, m_obj.ReferenceTargetCandidates(m_flid),
                                                        m_displayNameProperty, displayWs);

            using (MorphTypeChooser chooser = GetChooser(labels))
            {
                chooser.InitializeExtras(m_configurationNode, Mediator, m_propertyTable);
                chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);
                chooser.SetHelpTopic(Slice.GetChooserHelpTopicID());

                var hvoType      = m_cache.DomainDataByFlid.get_ObjectProp(m_obj.Hvo, m_flid);
                var morphTypeRep = m_cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>();
                var type         = hvoType != 0 ? morphTypeRep.GetObject(hvoType) : null;
                chooser.MakeSelection(type);
                // LT-4433 changed the Alternate Forms to choose between Stem and Affix automatically
                // when inserting.  Thus, we need the check box in that environment as well.
                //if (m_obj.OwningFlid != (int)LexEntry.LexEntryTags.kflidLexemeForm)
                //    chooser.ShowAllTypesCheckBoxVisible = false;
                if (chooser.ShowDialog() == DialogResult.OK)
                {
                    var selected = (IMoMorphType)chooser.ChosenOne.Object;
                    MakeMorphTypeChange(selected);
                }
            }
        }
Esempio n. 7
0
        private void m_showAllTypesCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            // If a node is selected, try selecting again when we get through.
            var selected = SelectedObject;
            IEnumerable <ICmObject> candidates;

            if (m_showAllTypesCheckBox.Checked)
            {
                var form = (IMoForm)m_obj;
                candidates = form.GetAllMorphTypeReferenceTargetCandidates();
            }
            else
            {
                candidates = m_obj.ReferenceTargetCandidates(m_flid);
            }
            IEnumerable <ObjectLabel> labels = ObjectLabel.CreateObjectLabels(m_cache, candidates,
                                                                              m_displayNameProperty, "best analorvern");

            LoadTree(labels, null, false);
            MakeSelection(selected);
        }
Esempio n. 8
0
        /// <summary>
        /// Handle launching of the standard chooser.
        /// </summary>
        /// <remarks>
        /// Subclasses should override this method, if the SimpleListChooser is not suitable.
        /// </remarks>
        protected override void HandleChooser()
        {
            const string displayWs = "best analysis";
            var          sense     = m_obj as ILexSense;

            if (sense == null)
            {
                Debug.Assert(sense != null, "This chooser can only be applied to senses");
                // ReSharper disable HeuristicUnreachableCode
                //reachable in release mode you usually intelligent program.
                return;
                // ReSharper restore HeuristicUnreachableCode
            }
            var linkCommandNode = m_configurationNode.SelectSingleNode("descendant::chooserLink");
            var chooser         = new SemanticDomainsChooser
            {
                Mediator          = m_mediator,
                Cache             = m_cache,
                DisplayWs         = displayWs,
                Sense             = sense,
                LinkNode          = linkCommandNode,
                HelpTopicProvider = m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider")
            };

            var labels = ObjectLabel.CreateObjectLabels(m_cache, m_obj.ReferenceTargetCandidates(m_flid),
                                                        m_displayNameProperty, displayWs);

            chooser.Initialize(labels, sense.SemanticDomainsRC, m_propertyTable);
            var result = chooser.ShowDialog();

            if (result == DialogResult.OK)
            {
                UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(Resources.DetailControlsStrings.ksUndoSet,
                                                                Resources.DetailControlsStrings.ksRedoSet,
                                                                m_cache.ActionHandlerAccessor,
                                                                () => sense.SemanticDomainsRC.Replace(sense.SemanticDomainsRC, chooser.SemanticDomains));
            }
        }
Esempio n. 9
0
        protected void ShowDialogAndConvert(int targetClassId)
        {
            // maybe there's a better way, but
            // this creates a temporary LexEntryRef in a temporary LexEntry
            var leFactory  = m_cache.ServiceLocator.GetInstance <ILexEntryFactory>();
            var entry      = leFactory.Create();
            var lerFactory = m_cache.ServiceLocator.GetInstance <ILexEntryRefFactory>();
            var ler        = lerFactory.Create();

            entry.EntryRefsOS.Add(ler);
            m_flid = LexEntryRefTags.kflidVariantEntryTypes;
            m_obj  = ler;
            var labels = ObjectLabel.CreateObjectLabels(m_cache,
                                                        m_obj.ReferenceTargetCandidates(m_flid),
                                                        "LexEntryType" /*"m_displayNameProperty*/,
                                                        "best analysis");

            using (SimpleListChooser chooser = GetChooser(labels, targetClassId))
            {
                chooser.Cache = m_cache;
                chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);
                chooser.SetHelpTopic(s_helpTopic);
                var tv = chooser.TreeView;
                DisableNodes(tv.Nodes, targetClassId);
                m_dlg.Visible = false;                 // no reason to show the utility dialog, too
                var res = chooser.ShowDialog(m_dlg.FindForm());
                if (res == DialogResult.OK && chooser.ChosenObjects.Any())
                {
                    var itemsToChange = (from lexEntryType in chooser.ChosenObjects
                                         where lexEntryType.ClassID != targetClassId
                                         select lexEntryType).Cast <ILexEntryType>();
                    Convert(itemsToChange);
                }
            }
            entry.Delete();             // remove the temporary LexEntry
            m_dlg.Visible = true;       // now we show the utility dialog again
        }
Esempio n. 10
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;
                }
            }
        }
Esempio n. 11
0
        protected override void HandleChooser()
        {
            string displayWs = "analysis vernacular";

#pragma warning disable 219
            string postDialogMessageTrigger = null;
#pragma warning restore 219

            if (m_configurationNode != null)
            {
                XmlNode node = m_configurationNode.SelectSingleNode("deParams");
                if (node != null)
                {
                    displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
                    postDialogMessageTrigger = XmlUtils.GetAttributeValue(node, "postChangeMessageTrigger", null);
                }
            }

            var labels = ObjectLabel.CreateObjectLabels(m_cache, m_obj.ReferenceTargetCandidates(m_flid),
                                                        m_displayNameProperty, displayWs);

            using (MorphTypeChooser chooser = GetChooser(labels))
            {
                bool fMadeMorphTypeChange = false;
                var  entry = (ILexEntry)m_obj.Owner;
                chooser.InitializeExtras(m_configurationNode, Mediator);
                chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);
                chooser.SetHelpTopic(Slice.GetChooserHelpTopicID());

                var hvoType      = m_cache.DomainDataByFlid.get_ObjectProp(m_obj.Hvo, m_flid);
                var morphTypeRep = m_cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>();
                var type         = hvoType != 0 ? morphTypeRep.GetObject(hvoType) : null;
                chooser.MakeSelection(type);
                // LT-4433 changed the Alternate Forms to choose between Stem and Affix automatically
                // when inserting.  Thus, we need the check box in that environment as well.
                //if (m_obj.OwningFlid != (int)LexEntry.LexEntryTags.kflidLexemeForm)
                //    chooser.ShowAllTypesCheckBoxVisible = false;
                if (chooser.ShowDialog() == DialogResult.OK)
                {
                    var    selected = (IMoMorphType)chooser.ChosenOne.Object;
                    var    original = Target as IMoMorphType;
                    string sUndo    = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeUndo", m_ksPath);
                    string sRedo    = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeRedo", m_ksPath);

                    bool fRemoveComponents = false;
                    if (selected.Guid == MoMorphTypeTags.kguidMorphRoot ||
                        selected.Guid == MoMorphTypeTags.kguidMorphBoundRoot)
                    {
                        // changing to root...not allowed to have complex forms.
                        foreach (ILexEntryRef ler in entry.EntryRefsOS)
                        {
                            if (ler.RefType == LexEntryRefTags.krtComplexForm)
                            {
                                fRemoveComponents = true;
                                // If there are no components we will delete without asking...but must then check for more
                                // complex forms that DO have components.
                                if (ler.ComponentLexemesRS.Count > 0)
                                {
                                    // TODO-Linux: Help is not implemented in Mono
                                    if (MessageBox.Show(FindForm(), DetailControlsStrings.ksRootNoComponentsMessage,
                                                        DetailControlsStrings.ksRootNoComponentsCaption, MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0, m_mediator.HelpTopicProvider.HelpFile,
                                                        HelpNavigator.Topic, "/Using_Tools/Lexicon_tools/Lexicon_Edit/change_the_morph_type.htm") != DialogResult.Yes)
                                    {
                                        return;
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    UndoableUnitOfWorkHelper.Do(sUndo, sRedo, entry, () =>
                    {
                        if (fRemoveComponents)
                        {
                            foreach (var ler in entry.EntryRefsOS.Where(entryRef => entryRef.RefType == LexEntryRefTags.krtComplexForm))
                            {
                                entry.EntryRefsOS.Remove(ler);
                            }
                        }

                        if (IsStemType(original) || m_obj is IMoStemAllomorph)
                        {
                            if (IsStemType(selected))
                            {
                                Target = selected;
                            }
                            else
                            {
                                //have to switch from stem to affix
                                fMadeMorphTypeChange = ChangeStemToAffix(entry, selected);
                            }
                        }
                        else
                        {
                            // original is affix variety
                            if (IsStemType(selected))
                            {
                                //have to switch from affix to stem
                                fMadeMorphTypeChange = ChangeAffixToStem(entry, selected);
                            }
                            else
                            {
                                Target = selected;
                            }
                        }
                        if (selected.Guid == MoMorphTypeTags.kguidMorphPhrase)
                        {
                            ILexEntryRef ler = m_cache.ServiceLocator.GetInstance <ILexEntryRefFactory>().Create();
                            entry.EntryRefsOS.Add(ler);
                            ler.RefType        = LexEntryRefTags.krtComplexForm;
                            ler.HideMinorEntry = 1;
                        }
                    });
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Handle launching of the standard chooser.
        /// </summary>
        /// <remarks>
        /// Subclasses should override this method, if the SimpleListChooser is not suitable.
        /// </remarks>
        protected override void HandleChooser()
        {
            string displayWs = "analysis vernacular";
            //string displayWs = "best analysis";
            string postDialogMessageTrigger = null;

            if (m_configurationNode != null)
            {
                XmlNode node = m_configurationNode.SelectSingleNode("deParams");
                if (node != null)
                {
                    displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
                    postDialogMessageTrigger = XmlUtils.GetAttributeValue(node, "postChangeMessageTrigger", null);
                }
            }
            var labels = ObjectLabel.CreateObjectLabels(m_cache, m_obj.ReferenceTargetCandidates(m_flid),
                                                        m_displayNameProperty, displayWs);

            // I (JH) started down this road to sorting the object labels... it proved bumpy
            // and I bailed out and just turned on the "sorted" property of the chooser,
            // which gives us a dumb English sort.
            // but when it is time to get back to this... what I was doing what is misguided
            // because this sorter wants FdoObjects, but object labels don't have those on the
            // surface.  instead, they can readily give a string, through ToString().which is
            // what made me realize that until we have a way to sort something based on ICU, I
            // might as well let .net do the sorting.

            // I'm thinking there's a good chance we will eventually use FieldWorks controls for
            // the chooser in fact we will probably just using normal browse view. Then, that
            // chooser can just do the normal sorting that browse view stew, including letting
            // the user sort based on different properties.

            // however, we need a TreeView in many cases... I think there's also a FieldWorks
            // one of those that probably doesn't have sorting built-in yet...in which case we
            // might want to do the sorting here.

            //SIL.FieldWorks.Filters.RecordSorter sorter =
            //	new SIL.FieldWorks.Filters.PropertyRecordSorter("ShortName");
            //sorter.Sort ((ArrayList) labels);

            using (SimpleListChooser chooser = GetChooser(labels))
            {
                chooser.Cache = m_cache;
                chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);                    // may set TextParamHvo
                if (m_configurationNode != null)
                {
                    // Handle the default case ("owner") for text parameters.

                    // This (old approach) works only if
                    // all of the list items are owned by the same object as the first one in the
                    // list.  (Later elements can be owned by elements owned by that first owner,
                    // if you know what I mean.)
                    //if (candidates.Count != 0)
                    //    chooser.TextParamHvo = m_cache.GetOwnerOfObject((int)candidates[0]);
                    // JohnT: this approach depends on a new FDO method.
                    ICmObject referenceTargetOwner = m_obj.ReferenceTargetOwner(m_flid);
                    if (referenceTargetOwner != null)
                    {
                        chooser.TextParamHvo = referenceTargetOwner.Hvo;
                    }
                    chooser.SetHelpTopic(Slice.GetChooserHelpTopicID());
                    chooser.InitializeExtras(m_configurationNode, Mediator, m_propertyTable);
                }

                var res = chooser.ShowDialog(MainControl.FindForm());
                if (DialogResult.Cancel == res)
                {
                    return;
                }

                if (m_configurationNode != null)
                {
                    chooser.HandleAnyJump();
                }

                if (chooser.ChosenOne != null)
                {
                    AddItem(chooser.ChosenOne.Object);
                }
                else if (chooser.ChosenObjects != null)
                {
                    SetItems(chooser.ChosenObjects);
                }
            }

            //if the configuration file says that we should put up a message dialog after a change has been made,
            //do that now.
            if (postDialogMessageTrigger != null)
            {
                XCore.XMessageBoxExManager.Trigger(postDialogMessageTrigger);
            }
            // If the configuration file says to refresh the slice list, do that now.
            if (ChoicesMade != null)
            {
                ChoicesMade(this, new EventArgs());
            }
        }
        protected override void HandleChooser()
        {
            // YAGNI: may eventually need to make configurable how it comes up with the list of candidates.
            // Currently this is used only for properties of a ghost notebook record.
            var candidateList = (ICmPossibilityList)ReferenceTargetServices.RnGenericRecReferenceTargetOwner(m_cache, m_flid);
            var candidates    = candidateList == null ? null : candidateList.PossibilitiesOS.Cast <ICmObject>();
            // YAGNI: see ReferenceLauncher implementation of this method for a possible approach to
            // making the choice of writing system configurable.
            var labels = ObjectLabel.CreateObjectLabels(m_cache, candidates,
                                                        m_displayNameProperty, "analysis vernacular");
            var chooser = new SimpleListChooser(m_persistProvider,
                                                labels,
                                                m_fieldName,
                                                m_cache,
                                                new ICmObject[0],
                                                m_mediator.HelpTopicProvider);

            chooser.SetHelpTopic(Slice.GetChooserHelpTopicID());

            chooser.SetObjectAndFlid(0, m_flid);
            if (Slice.ConfigurationNode != null)
            {
                // Review JohnT: can any of this be made relevant without an object?
                //    // Handle the default case ("owner") for text parameters.

                //    // This (old approach) works only if
                //    // all of the list items are owned by the same object as the first one in the
                //    // list.  (Later elements can be owned by elements owned by that first owner,
                //    // if you know what I mean.)
                //    //if (candidates.Count != 0)
                //    //    chooser.TextParamHvo = m_cache.GetOwnerOfObject((int)candidates[0]);
                //    // JohnT: this approach depends on a new FDO method.
                //    ICmObject referenceTargetOwner = m_obj.ReferenceTargetOwner(m_flid);
                //    if (referenceTargetOwner != null)
                //        chooser.TextParamHvo = referenceTargetOwner.Hvo;
                //    chooser.SetHelpTopic(Slice.GetChooserHelpTopicID());
                chooser.InitializeExtras(Slice.ConfigurationNode, Mediator);
            }
            var res = chooser.ShowDialog(FindForm());

            if (DialogResult.Cancel == res)
            {
                return;
            }

            if (chooser.HandleAnyJump())
            {
                return;
            }

            if (chooser.ChosenObjects != null && chooser.ChosenObjects.Count() > 0)
            {
                UndoableUnitOfWorkHelper.Do(string.Format(DetailControlsStrings.ksUndoSet, m_fieldName),
                                            string.Format(DetailControlsStrings.ksRedoSet, m_fieldName), m_obj,
                                            () =>
                {
                    // YAGNI: creating the real object may eventually need to be configurable,
                    // perhaps by indicating in the configuration node what class of object to create
                    // and so forth, or perhaps by just putting a "doWhat" attribute on the configuration node
                    // and making a switch here to control what is done. For now this slice is only used
                    // in one situation, where we need to create a notebook record, associate the current object
                    // with it, and add the values to it.
                    ((IText)m_obj).AssociateWithNotebook(false);
                    IRnGenericRec notebookRec;
                    DataTree.NotebookRecordRefersToThisText(m_obj as IText, out notebookRec);
                    var recHvo   = notebookRec.Hvo;
                    var values   = (from obj in chooser.ChosenObjects select obj.Hvo).ToArray();
                    var listFlid = m_flid;
                    if (m_flid == RnGenericRecTags.kflidParticipants)
                    {
                        var defaultRoledParticipant = notebookRec.MakeDefaultRoledParticipant();
                        recHvo   = defaultRoledParticipant.Hvo;
                        listFlid = RnRoledParticTags.kflidParticipants;
                    }
                    m_cache.DomainDataByFlid.Replace(recHvo, listFlid, 0, 0, values, values.Length);
                    // We don't do anything about updating the display because creating the real object
                    // will typically destroy this slice altogether and replace it with a real one.
                });
                // Structure has changed drastically, start over.
                var index    = Slice.IndexInContainer;
                var dataTree = Slice.ContainingDataTree;
                dataTree.RefreshList(false);                 // Slice will be destroyed!!
                if (index <= dataTree.Slices.Count - 1)
                {
                    dataTree.CurrentSlice = dataTree.FieldAt(index);
                }
            }
        }