/// <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); } } Set <int> candidates = m_obj.ReferenceTargetCandidates(m_flid); ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates, 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.InitializeExtras(m_configurationNode, Mediator); } System.Windows.Forms.DialogResult res = chooser.ShowDialog(); if (System.Windows.Forms.DialogResult.Cancel == res) { return; } if (m_configurationNode != null) { chooser.HandleAnyJump(); } if (chooser.ChosenOne != null) { AddItem(chooser.ChosenOne.Hvo); } else if (chooser.ChosenHvos != null) { SetItems(chooser.ChosenHvos); } } //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()); } }
private SimpleListChooser MakeChooserWithExtantSlots(bool fIsPrefixSlot) { int slotFlid; if (fIsPrefixSlot) slotFlid = MoInflAffixTemplateTags.kflidPrefixSlots; else slotFlid = MoInflAffixTemplateTags.kflidSuffixSlots; var labels = ObjectLabel.CreateObjectLabels(Cache, m_template.ReferenceTargetCandidates(slotFlid), null); PersistenceProvider persistProvider = new PersistenceProvider(m_mediator.PropertyTable); SimpleListChooser chooser = new SimpleListChooser(persistProvider, labels, m_ChooseSlotHelpTopic, m_mediator.HelpTopicProvider); chooser.SetHelpTopic("khtpChoose-Grammar-InflAffixTemplateControl"); chooser.Cache = Cache; chooser.TextParamHvo = m_template.Owner.Hvo; chooser.Title = m_sSlotChooserTitle; chooser.InstructionalText = m_sSlotChooserInstructionalText; string sTopPOS; var pos = GetHighestPOS(m_template.OwnerOfClass<IPartOfSpeech>(), out sTopPOS); string sLabel = String.Format(m_sObligatorySlot, sTopPOS); chooser.AddLink(sLabel, SimpleListChooser.LinkType.kSimpleLink, new MakeInflAffixSlotChooserCommand(Cache, true, sLabel, pos.Hvo, false, m_mediator)); sLabel = String.Format(m_sOptionalSlot, sTopPOS); chooser.AddLink(sLabel, SimpleListChooser.LinkType.kSimpleLink, new MakeInflAffixSlotChooserCommand(Cache, true, sLabel, pos.Hvo, true, m_mediator)); chooser.SetObjectAndFlid(pos.Hvo, MoInflAffixTemplateTags.kflidSlots); return chooser; }
private SimpleListChooser MakeChooserWithExtantMsas(IMoInflAffixSlot slot, XCore.Command cmd) { // Want the list of all lex entries which have an infl affix Msa // Do not want to list the infl affix Msas that are already assigned to the slot. var candidates = new HashSet<ICmObject>(); bool fIsPrefixSlot = m_template.PrefixSlotsRS.Contains(slot); foreach (var lex in slot.OtherInflectionalAffixLexEntries) { bool fInclude = EntryHasAffixThatMightBeInSlot(lex, fIsPrefixSlot); if (fInclude) { foreach (var msa in lex.MorphoSyntaxAnalysesOC) { if (msa is IMoInflAffMsa) { candidates.Add(msa); break; } } } } var labels = ObjectLabel.CreateObjectLabels(Cache, candidates.OrderBy(iafmsa => iafmsa.Owner.ShortName), null); XCore.PersistenceProvider persistProvider = new PersistenceProvider(m_mediator.PropertyTable); var aiForceMultipleChoices = new ICmObject[0]; var chooser = new SimpleListChooser(persistProvider, labels, m_ChooseInflectionalAffixHelpTopic, Cache, aiForceMultipleChoices, m_mediator.HelpTopicProvider); chooser.SetHelpTopic("khtpChoose-Grammar-InflAffixTemplateControl"); chooser.SetFontForDialog(new int[] { Cache.DefaultVernWs, Cache.DefaultAnalWs }, StyleSheet, WritingSystemFactory); chooser.Cache = Cache; // We don't want the ()'s indicating optionality since the text spells it out. chooser.TextParam = slot.Name.AnalysisDefaultWritingSystem.Text; chooser.Title = m_sInflAffixChooserTitle; if (slot.Optional) chooser.InstructionalText = m_sInflAffixChooserInstructionalTextOpt; else chooser.InstructionalText = m_sInflAffixChooserInstructionalTextReq; chooser.AddLink(m_sInflAffix, SimpleListChooser.LinkType.kDialogLink, new MakeInflAffixEntryChooserCommand(Cache, true, m_sInflAffix, fIsPrefixSlot, slot, m_mediator)); chooser.SetObjectAndFlid(slot.Hvo, slot.OwningFlid); string sGuiControl = XmlUtils.GetOptionalAttributeValue(cmd.ConfigurationNode, "guicontrol"); if (!String.IsNullOrEmpty(sGuiControl)) { chooser.ReplaceTreeView(m_mediator, sGuiControl); } return chooser; }
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); } } }
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); } }
private SimpleListChooser MakeChooserWithExtantSlots(bool fIsPrefixSlot) { int slotFlid; if (fIsPrefixSlot) slotFlid = (int)MoInflAffixTemplate.MoInflAffixTemplateTags.kflidPrefixSlots; else slotFlid = (int) MoInflAffixTemplate.MoInflAffixTemplateTags.kflidSuffixSlots; ObjectLabelCollection labels = new ObjectLabelCollection( Cache, m_template.ReferenceTargetCandidates(slotFlid), null); PersistenceProvider persistProvider = new PersistenceProvider(m_mediator.PropertyTable); SimpleListChooser chooser = new SimpleListChooser(persistProvider, labels, m_ChooseSlotHelpTopic); chooser.Cache = Cache; chooser.TextParamHvo = m_template.OwnerHVO; chooser.Title = m_sSlotChooserTitle; chooser.InstructionalText = m_sSlotChooserInstructionalText; string sTopPOS; int posHvo = GetHvoOfHighestPOS(m_template.OwnerHVO, out sTopPOS); string sLabel = String.Format(m_sObligatorySlot, sTopPOS); chooser.AddLink(sLabel, SimpleListChooser.LinkType.kSimpleLink, new MakeInflAffixSlotChooserCommand(Cache, true, sLabel, posHvo, false, m_mediator)); sLabel = String.Format(m_sOptionalSlot, sTopPOS); chooser.AddLink(sLabel, SimpleListChooser.LinkType.kSimpleLink, new MakeInflAffixSlotChooserCommand(Cache, true, sLabel, posHvo, true, m_mediator)); chooser.SetObjectAndFlid(posHvo, (int)FDO.Ling.MoInflAffixTemplate.MoInflAffixTemplateTags.kflidSlots); return chooser; }