/// <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()); } }
internal int DisplayChooser(string fieldName, string linkText, string toolName, string guiControl, Set<int> candidates) { int hvo = 0; ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates); using (SimpleListChooser chooser = new SimpleListChooser(m_persistenceProvider, labels, fieldName)) { chooser.Cache = m_cache; chooser.TextParamHvo = m_cache.LangProject.PhonologicalDataOAHvo; chooser.AddLink(linkText, SimpleListChooser.LinkType.kGotoLink, FwLink.Create(toolName, m_cache.GetGuidFromId(chooser.TextParamHvo), m_cache.ServerName, m_cache.DatabaseName)); 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.MetaRuleFormulaControl) chooser.SetHelpTopic("khtpChoose-LexiconEdit-PhonFeats-AffixRuleFormulaControl"); DialogResult res = chooser.ShowDialog(); if (res != DialogResult.Cancel) { chooser.HandleAnyJump(); if (chooser.ChosenOne != null) hvo = chooser.ChosenOne.Hvo; } } return hvo; }
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); } }
/// <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 Set<int> candidates = new Set<int>(); foreach (IPhEnvironment env in m_cache.LangProject.PhonologicalDataOA.EnvironmentsOS) { ConstraintFailure failure; if (env.CheckConstraints((int)PhEnvironment.PhEnvironmentTags.kflidStringRepresentation, out failure)) candidates.Add(env.Hvo); } string displayWs = "analysis vernacular"; int hvo = 0; if (m_configurationNode != null) { XmlNode node = m_configurationNode.SelectSingleNode("deParams"); if (node != null) displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower(); } ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates, null, displayWs); using (SimpleListChooser chooser = new SimpleListChooser(m_persistProvider, labels, m_fieldName)) { chooser.Cache = m_cache; chooser.TextParamHvo = m_cache.LangProject.PhonologicalDataOAHvo; chooser.InitializeExtras(m_configurationNode, m_mediator); DialogResult res = chooser.ShowDialog(); if (res != DialogResult.Cancel) { chooser.HandleAnyJump(); if (chooser.ChosenOne != null) hvo = chooser.ChosenOne.Hvo; } } // return focus to the view m_view.Select(); if (hvo != 0) { int cellId = -1; using (new UndoRedoTaskHelper(m_cache, MEStrings.ksRuleUndoUpdateEnv, MEStrings.ksRuleRedoUpdateEnv)) { cellId = UpdateEnvironment(PhEnvironment.CreateFromDBObject(m_cache, hvo)); } ReconstructView(cellId, -1, true); } }
protected ICmObject DisplayChooser(string fieldName, string linkText, string toolName, string guiControl, IEnumerable<ICmObject> candidates) { ICmObject obj = null; IEnumerable<ObjectLabel> labels = ObjectLabel.CreateObjectLabels(m_cache, candidates); using (var chooser = new SimpleListChooser(m_persistProvider, 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, ReallySimpleListChooser.LinkType.kGotoLink, new FwLinkArgs(toolName, guidTextParam)); chooser.ReplaceTreeView(m_mediator, guiControl); chooser.SetHelpTopic(FeatureChooserHelpTopic); DialogResult res = chooser.ShowDialog(); if (res != DialogResult.Cancel) { chooser.HandleAnyJump(); if (chooser.ChosenOne != null) obj = chooser.ChosenOne.Object; } } return obj; }
/// <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); } }
private void AddParticipants(object sender, EventArgs e) { var item = (ToolStripMenuItem) sender; var role = (ICmPossibility) item.Tag; string roleName = role.Name.BestAnalysisAlternative.Text; 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(); } IEnumerable<ObjectLabel> labels = ObjectLabel.CreateObjectLabels(m_cache, m_cache.LanguageProject.PeopleOA.PossibilitiesOS, DisplayNameProperty, displayWs); using (var chooser = new SimpleListChooser(m_persistenceProvider, labels, m_fieldName, m_cache, null, m_mediator.HelpTopicProvider)) { chooser.TextParamHvo = m_cache.LanguageProject.PeopleOA.Hvo; chooser.SetHelpTopic(GetChooserHelpTopicID()); if (m_configurationNode != null) chooser.InitializeExtras(m_configurationNode, Mediator); DialogResult res = chooser.ShowDialog(); if (DialogResult.Cancel == res) return; if (m_configurationNode != null) chooser.HandleAnyJump(); if (chooser.ChosenObjects != null) { IRnRoledPartic roledPartic = null; UndoableUnitOfWorkHelper.Do(string.Format(LexEdStrings.ksUndoAddParticipants, roleName), string.Format(LexEdStrings.ksRedoAddParticipants, roleName), role, () => { roledPartic = m_cache.ServiceLocator.GetInstance<IRnRoledParticFactory>().Create(); Record.ParticipantsOC.Add(roledPartic); roledPartic.RoleRA = role; foreach (ICmPerson person in chooser.ChosenObjects) roledPartic.ParticipantsRC.Add(person); }); ExpandNewNode(roledPartic); } } }