Beispiel #1
0
		public bool OnMoveReversalPOS(object cmd)
		{
			FdoCache cache = Cache;
			ObjectLabelCollection labels = new ObjectLabelCollection();
			foreach (IPartOfSpeech pos in MergeOrMoveCandidates)
				labels.Add(ObjectLabel.CreateObjectLabelOnly(cache, pos.Hvo, "ShortNameTSS", "best analysis"));
			using (SimpleListChooser dlg = new SimpleListChooser(cache, null, labels, 0,
				LexEdStrings.ksCategoryToMoveTo, null))
			{
				if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
				{
					IPartOfSpeech currentPOS = POS;
					IPartOfSpeech newOwner = PartOfSpeech.CreateFromDBObject(cache, dlg.ChosenOne.Hvo);
					cache.BeginUndoTask(LexEdStrings.ksUndoMoveRevCategory,
						LexEdStrings.ksRedoMoveRevCategory);
					ICmObject newOwningObj = newOwner.MoveIfNeeded(currentPOS);
					newOwner.SubPossibilitiesOS.Append(currentPOS);
					cache.EndUndoTask();
					// Note: PropChanged should happen on the old owner and the new in the 'Add" method call.
					// Have to jump to a main PartOfSpeech, as RecordClerk doesn't know anything about subcategories.
					m_mediator.BroadcastMessageUntilHandled("JumpToRecord", newOwner.MainPossibility.Hvo);
				}
			}

			return true;
		}
		/// <summary>
		/// Get the SimpleListChooser/
		/// </summary>
		/// <param name="labels">List of objects to show in the chooser.</param>
		/// <returns>The SimpleListChooser.</returns>
		protected new MorphTypeChooser GetChooser(ObjectLabelCollection labels)
		{
			string sShowAllTypes = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeShowAllTypes", m_ksPath);
			MorphTypeChooser x = new MorphTypeChooser(m_persistProvider, labels, m_fieldName, m_obj, m_displayNameProperty,
				m_flid, sShowAllTypes);
			x.Cache = m_cache;
			x.NullLabel.DisplayName  = XmlUtils.GetOptionalAttributeValue(m_configurationNode, "nullLabel", "<EMPTY>");
			return x;
		}
Beispiel #3
0
		/// <summary>
		/// constructor for use with adding a new value
		/// </summary>
		/// <param name="labels"></param>
		/// <param name="fieldName">the user-readable name of the field that is being edited
		/// </param>
		public MorphTypeChooser(IPersistenceProvider persistProvider,
			ObjectLabelCollection labels, string fieldName, ICmObject obj, string displayNameProperty,
			int flid, string sShowAllTypes) :
			base(persistProvider, labels, fieldName)
		{
			m_obj = obj;
			m_displayNameProperty = displayNameProperty;
			m_flid = flid;
			InitMorphTypeForm(sShowAllTypes);
		}
		/// <summary>
		/// constructor for use with changing or setting multiple values.
		/// </summary>
		/// <param name="persistProvider">optional, if you want to preserve the size and
		/// location</param>
		/// <param name="labels"></param>
		/// <param name="fieldName">the user-readable name of the field that is being edited
		/// </param>
		/// <param name="cache"></param>
		/// <param name="rghvoChosen">use null or int[0] if empty</param>
		public ReallySimpleListChooser(IPersistenceProvider persistProvider,
			ObjectLabelCollection labels, string fieldName, FdoCache cache, int[] rghvoChosen) :
			this(persistProvider, labels, fieldName, cache, rghvoChosen, IsListSorted(labels, cache))
		{
		}
		/// <summary>
		/// Overridden to provide a chooser with multiple selections (checkboxes and all).
		/// </summary>
		protected override SimpleListChooser GetChooser(ObjectLabelCollection labels)
		{
			return new SimpleListChooser(m_persistProvider, labels, m_fieldName, m_cache,
				m_cache.GetVectorProperty(m_obj.Hvo, m_flid, false));
		}
Beispiel #6
0
		/// <summary>
		/// Get the SimpleListChooser/
		/// </summary>
		/// <param name="labels">List of objects to show in the chooser.</param>
		/// <returns>The SimpleListChooser.</returns>
		protected virtual SimpleListChooser GetChooser(ObjectLabelCollection labels)
		{
			SimpleListChooser x = new SimpleListChooser(m_persistProvider, labels, m_fieldName);
			x.NullLabel.DisplayName  = XmlUtils.GetOptionalAttributeValue(m_configurationNode, "nullLabel", "<EMPTY>");
			return x;
		}
		protected override SimpleListChooser GetChooser(ObjectLabelCollection labels)
		{
			string nullLabel = DetailControlsStrings.ksNullLabel;
			if (m_configurationNode != null)
			{
				System.Xml.XmlNode node = m_configurationNode.SelectSingleNode("deParams");
				nullLabel = XmlUtils.GetOptionalAttributeValue(node, "nullLabel", nullLabel);
			}
			SimpleListChooser c = new SimpleListChooser(m_cache, m_persistProvider, labels, TargetHvo,
				m_fieldName, nullLabel, m_atomicRefView.StyleSheet);
			return c;
		}
		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;
		}
Beispiel #9
0
		private static void FindChosenHvos(ObjectLabelCollection labels, List<string> chosenLabels, ref List<int> chosenHvos)
		{
			foreach (ObjectLabel label in labels)
			{
				// go through the labels, and build of list of matching labels.
				if (chosenLabels.Contains(label.DisplayName))
					chosenHvos.Add(label.Hvo);
				// do the same for subitems
				if (label.SubItems.Count != 0)
					FindChosenHvos(label.SubItems, chosenLabels, ref chosenHvos);
			}
		}
Beispiel #10
0
		void m_launcher_Click(object sender, EventArgs e)
		{
			// Show a wait cursor (LT-4673)
			using (new SIL.FieldWorks.Common.Utils.WaitCursor(this.Control))
			{
				ICmPossibilityList list = CmPossibilityList.CreateFromDBObject(m_cache, m_hvoList);
				List<int> candidates = new List<int>(list.PossibilitiesOS.HvoArray);
				XCore.PersistenceProvider persistProvider =
					new PersistenceProvider(m_mediator.PropertyTable);
				ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates,
					m_displayNameProperty, m_displayWs);
				//m_cache.MetaDataCacheAccessor.GetFieldName((uint)m_flid, out fieldName);
				using (ReallySimpleListChooser chooser = new ReallySimpleListChooser(persistProvider,
					labels, m_fieldName, m_cache, m_chosenHvos))
				{
					chooser.Cache = m_cache;
					chooser.SetObjectAndFlid(0, m_flid);
					chooser.ShowFuncButtons();
					chooser.SetHelpTopic("khtpBulkEdit" + m_fieldName.Replace(" ", ""));
					System.Windows.Forms.DialogResult res = chooser.ShowDialog((sender as Control).TopLevelControl);
					if (System.Windows.Forms.DialogResult.Cancel == res)
						return;
					m_chosenHvos = chooser.ChosenHvos.ToArray();
					m_fReplace = chooser.ReplaceMode;
					m_fRemove = chooser.RemoveMode;

					// Tell the parent control that we may have changed the selected item so it can
					// enable or disable the Apply and Preview buttons based on the selection.
					// We are just checking here if any item was selected by the user in the dialog
					if (ValueChanged != null)
					{
						int itemCount = m_chosenHvos.Length;
						int hvo = 0;
						if (itemCount > 0)
							hvo = m_chosenHvos[0];
						ValueChanged(sender, new FwObjectSelectionEventArgs(hvo));
					}
				}
			}
		}
Beispiel #11
0
		//private System.ComponentModel.IContainer components = null;

		/// <summary>
		/// constructor for use with adding a new value
		/// </summary>
		/// <param name="labels"></param>
		/// <param name="fieldName">the user-readable name of the field that is being edited
		/// </param>
		public MorphTypeChooser(IPersistenceProvider persistProvider,
			ObjectLabelCollection labels, string fieldName) :
			base(persistProvider, labels, fieldName)
		{
			InitMorphTypeForm(null);
		}
Beispiel #12
0
		private void cbShowAllTypes_CheckedChanged(object sender, System.EventArgs e)
		{
			// If a node is selected, try selecting again when we get through.
			int hvoSelected = SelectedHvo;
			Set<int> candidates = null;
			string displayWs = "best analorvern";
			if (cbShowAllTypes.Checked)
			{
				MoForm form = m_obj as MoForm;
				candidates = form.GetAllMorphTypeReferenceTargetCandidates();
			}
			else
			{
				candidates = m_obj.ReferenceTargetCandidates(m_flid);
			}
			ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates,
				m_displayNameProperty, displayWs);
			LoadTree(labels, 0, false);
			MakeSelection(hvoSelected);
		}
		/// <summary>
		/// Check whether the list should be sorted.  See LT-5149.
		/// </summary>
		/// <param name="labels"></param>
		/// <param name="cache"></param>
		/// <returns></returns>
		private static bool IsListSorted(ObjectLabelCollection labels, FdoCache cache)
		{
			if (labels.Count > 0 && cache != null)
			{
				int hvoList = cache.GetOwnerOfObject(labels[0].Hvo);
				ICmObject co = CmObject.CreateFromDBObject(cache, hvoList);
				if (co is ICmPossibilityList)
					return (co as ICmPossibilityList).IsSorted;
			}
			return true;
		}
		/// <summary>
		/// Tail end of typical constructor, isolated for calling after subclass constructor
		/// has done some of its own initialization.
		/// </summary>
		/// <param name="labels"></param>
		protected void FinishConstructor(ObjectLabelCollection labels)
		{
			// Note: anything added here might need to be added to the LeafChooser constructor also.
			LoadTree(labels, 0, false);
			InitHelp();
		}
		/// <summary>
		/// constructor for use with changing or setting multiple values.
		/// </summary>
		/// <param name="persistProvider">optional, if you want to preserve the size and
		/// location</param>
		/// <param name="labels"></param>
		/// <param name="fieldName">the user-readable name of the field that is being edited
		/// </param>
		/// <param name="cache"></param>
		/// <param name="rghvoChosen">use null or int[0] if empty</param>
		/// <param name="fSortLabels">if true, sort the labels alphabetically. if false, keep the order of given labels.</param>
		public ReallySimpleListChooser(IPersistenceProvider persistProvider,
			ObjectLabelCollection labels, string fieldName, FdoCache cache, int[] rghvoChosen, bool fSortLabels)
			: this(persistProvider, fieldName, cache, rghvoChosen)
		{
			if (labels.Count > 0 && labels.IsFlatList())
				m_fFlatList = true;
			m_fSortLabels = fSortLabels;
			m_fSortLabelsSet = true;
			FinishConstructor(labels);
		}
		/// <summary>
		/// Override method to handle launching of a chooser for selecting lexical entries.
		/// </summary>
		protected override void HandleChooser()
		{
			string displayWs = "analysis vernacular";
			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);

			using (MorphTypeChooser chooser = GetChooser(labels))
			{
				bool fMadeMorphTypeChange = false;
				ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, m_obj.OwnerHVO);
				chooser.InitializeExtras(m_configurationNode, Mediator);
				chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);
				int hvoType = m_cache.GetObjProperty(m_obj.Hvo, m_flid);
				chooser.MakeSelection(hvoType);
				// 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)
				{
					ObjectLabel selected = chooser.ChosenOne;
					int hvoOriginal = TargetHvo;
					string sUndo = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeUndo", m_ksPath);
					string sRedo = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeRedo", m_ksPath);

					bool fRemoveComponents = false;
					if (selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphRoot))
						|| selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphBoundRoot)))
					{
						// changing to root...not allowed to have complex forms.
						foreach (LexEntryRef ler in entry.EntryRefsOS)
						{
							if (ler.RefType == LexEntryRef.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)
								{
									if (MessageBox.Show(FindForm(), DetailControlsStrings.ksRootNoComponentsMessage,
										DetailControlsStrings.ksRootNoComponentsCaption, MessageBoxButtons.YesNo,
										MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0, FwApp.App.HelpFile,
										HelpNavigator.Topic, "khtRootCannotHaveComponents") != DialogResult.Yes)
									{
										return;
									}
									break;
								}
							}
						}
					}

					using (new UndoRedoTaskHelper(entry.Cache, sUndo, sRedo))
					{
						if (fRemoveComponents)
						{
							Set<int> delObjs = new Set<int>();
							foreach (LexEntryRef ler in entry.EntryRefsOS)
							{
								if (ler.RefType == LexEntryRef.krtComplexForm)
									delObjs.Add(ler.Hvo);
							}
							CmObject.DeleteObjects(delObjs, m_cache);
						}

						if (IsStemType(hvoOriginal) || m_obj is MoStemAllomorph)
						{
							if (IsStemType(selected.Hvo))
							{
								TargetHvo = selected.Hvo;
							}
							else
							{
								//have to switch from stem to affix
								fMadeMorphTypeChange = ChangeStemToAffix(entry, selected.Hvo, sUndo, sRedo);
							}
						}
						else
						{
							// original is affix variety
							if (IsStemType(selected.Hvo))
							{
								//have to switch from affix to stem
								fMadeMorphTypeChange = ChangeAffixToStem(entry, selected.Hvo, sUndo, sRedo);
							}
							else
							{
								TargetHvo = selected.Hvo;
							}
						}
						if (selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphPhrase)))
						{
							ILexEntryRef ler = new LexEntryRef();
							entry.EntryRefsOS.Append(ler);
							ler.RefType = LexEntryRef.krtComplexForm;
							ler.HideMinorEntry = 1;
							// No automatic propchanged for new objects, need to let the view see it.
							// At that point our slice will be disposed, so don't do anything after this.
							entry.Cache.PropChanged(entry.Hvo, (int) LexEntry.LexEntryTags.kflidEntryRefs, 0, 1, 0);
						}
					}
				}
			}
		}
Beispiel #17
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
			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);
			}
		}
Beispiel #18
0
		/// <summary>
		/// Show a dialog to allow the user to select/unselect multiple writing systems
		/// at a time, whether or not to display them (if they don't have data)
		/// If they do have data, we show the fields anyhow.
		/// </summary>
		/// <param name="args"></param>
		/// <returns></returns>
		public bool OnDataTreeWritingSystemsConfigureDlg(object args)
		{
			CheckDisposed();

			Set<int> wsSet = new Set<int>(HvosFromWss(WritingSystemOptionsForDisplay));
			ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, wsSet);
			ReloadWssToDisplayForPart();
			List<int> wssToDisplay = HvosFromWss(WritingSystemsSelectedForDisplay);
			using (ReallySimpleListChooser chooser = new ReallySimpleListChooser(null, labels, "DataTreeWritingSystems", m_cache, wssToDisplay.ToArray(), false))
			{
				chooser.ForbidNoItemChecked = true;
				IVwStylesheet stylesheet = (Control as LabeledMultiStringView).StyleSheet;
				chooser.SetFontForDialog(new int[] { Cache.DefaultVernWs, Cache.DefaultAnalWs }, stylesheet, Cache.LanguageWritingSystemFactoryAccessor);
				chooser.InitializeExtras(ConfigurationNode, Mediator);
				chooser.Text = String.Format(DetailControlsStrings.ksSliceConfigureWssDlgTitle, this.Label);
				chooser.InstructionalText = DetailControlsStrings.ksSliceConfigureWssDlgInstructionalText;
				if (chooser.ShowDialog() == DialogResult.OK)
				{
					PersistAndRedisplayWssToDisplayForPart(chooser.ChosenHvos);
				}
			}
			return true;
		}
Beispiel #19
0
		private ObjectLabelCollection GetObjectLabelsForList()
		{
			ICmPossibilityList list = CmPossibilityList.CreateFromDBObject(m_cache, m_hvoList);
			List<int> candidates = new List<int>(list.PossibilitiesOS.HvoArray);
			bool fShowEmpty = XmlUtils.GetOptionalBooleanAttributeValue(m_colSpec, "canChooseEmpty", false);
			ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates,
				GetDisplayPropertyName, m_bestWS, fShowEmpty); //analysis vernacular //best analorvern //best analysis
			return labels;
		}
Beispiel #20
0
		/// <summary>
		/// constructor for use with adding a new value
		/// </summary>
		/// <param name="labels"></param>
		/// <param name="fieldName">the user-readable name of the field that is being edited
		/// </param>
		public SimpleListChooser(IPersistenceProvider persistProvider,
			ObjectLabelCollection labels, string fieldName, IVwStylesheet stylesheet)
			: base(persistProvider, labels, fieldName, stylesheet)
		{
		}
Beispiel #21
0
		private ReallySimpleListChooser MakeChooser(ObjectLabelCollection labels, int[] oldTargets)
		{
			XCore.PersistenceProvider persistProvider =
				new PersistenceProvider(m_mediator.PropertyTable);
			if (m_leafFlid == 0)
				return new ReallySimpleListChooser(persistProvider,
								labels, "Items", m_cache, oldTargets);
			else
				return new LeafChooser(persistProvider,
								labels, "Items", m_cache, oldTargets, m_leafFlid);
		}
Beispiel #22
0
		/// <summary>
		/// constructor for use with changing or setting multiple values.
		/// </summary>
		/// <param name="persistProvider">optional, if you want to preserve the size and
		/// location</param>
		/// <param name="labels"></param>
		/// <param name="fieldName">the user-readable name of the field that is being edited
		/// </param>
		/// <param name="cache"></param>
		/// <param name="rghvoChosen">use null or int[0] if empty</param>
		public SimpleListChooser(IPersistenceProvider persistProvider,
			ObjectLabelCollection labels, string fieldName, FdoCache cache, int[] rghvoChosen)
			: base(persistProvider, labels, fieldName, cache, rghvoChosen)
		{
		}
Beispiel #23
0
		public void RefTargCandOnMoStemMsa()
		{
			CheckDisposed();

			MoStemMsa msa = GetFirstMoStemMsa();
			Set<int> hvos = msa.ReferenceTargetCandidates((int)MoStemMsa.MoStemMsaTags.kflidPartOfSpeech);
			ObjectLabelCollection items = new ObjectLabelCollection(Cache, hvos);
			Assert.AreEqual(items.Count, Cache.LangProject.PartsOfSpeechOA.ReallyReallyAllPossibilities.Count, "Wrong count");
		}
Beispiel #24
0
		/// <summary>
		/// (Deprecated) constructor for use with changing or setting a value
		/// </summary>
		/// <param name="persistProvider">optional, if you want to preserve the size and
		/// location</param>
		/// <param name="labels"></param>
		/// <param name="currentHvo">use zero if empty</param>
		/// <param name="fieldName">the user-readable name of the field that is being edited
		/// </param>
		public SimpleListChooser(IPersistenceProvider persistProvider,
			ObjectLabelCollection labels, int currentHvo, string fieldName)
			: base(persistProvider, labels, currentHvo, fieldName)
		{
		}
Beispiel #25
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);
				}
			}
			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());
		}
Beispiel #26
0
		/// <summary>
		/// constructor for use with changing or setting a value
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="persistProvider">optional, if you want to preserve the size and
		/// location</param>
		/// <param name="labels"></param>
		/// <param name="currentHvo">use zero if empty</param>
		/// <param name="fieldName">the user-readable name of the field that is being edited
		/// </param>
		public SimpleListChooser(FdoCache cache, IPersistenceProvider persistProvider,
			ObjectLabelCollection labels, int currentHvo, string fieldName, string nullLabel, IVwStylesheet stylesheet)
			: base(cache, persistProvider, labels, currentHvo, fieldName, nullLabel, stylesheet)
		{
		}
		/// <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);
				}
			}
		}
		private void DoUpdateDisplayFromDatabase(string displayNameProperty)
		{
			m_processSelectionEvent = false;
			m_currentSelectedIndex = 0;
			m_combo.Items.Clear();
			Set<int> candidates = Object.ReferenceTargetCandidates(m_flid);
			ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates,
				displayNameProperty);
			int currentValue = m_cache.GetObjProperty(Object.Hvo, m_flid);
			int idx = 0;
			foreach(ObjectLabel ol in labels)
			{
				m_combo.Items.Add(ol);
				if (ol.Hvo == currentValue)
				{
					m_combo.SelectedItem = ol;
					m_currentSelectedIndex = idx;
				}
				idx++;
			}
			idx = m_combo.Items.Add(NullItemLabel);
			if (currentValue == 0)
			{
				m_combo.SelectedIndex = idx;
				m_currentSelectedIndex = idx;
			}
			m_processSelectionEvent = true;
		}
		static public SimpleListChooser MakeSenseChooser(FdoCache cache)
		{
			List<int> lexSenses = new List<int>(DbOps.ReadIntArrayFromCommand(cache, "SELECT Dst FROM LexEntry_Senses", null));
			ObjectLabelCollection labels = new ObjectLabelCollection(cache, lexSenses, "LongNameTSS");
			SimpleListChooser chooser = new SimpleListChooser(null, labels, LexEdStrings.ksSenses);
			chooser.Cache = cache;
			return chooser;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// constructor for use with adding a new value (and stylesheet)
		/// </summary>
		/// <param name="persistProvider">The persist provider.</param>
		/// <param name="labels">The labels.</param>
		/// <param name="fieldName">the user-readable name of the field that is being edited</param>
		/// <param name="stylesheet">for getting right height for text</param>
		/// ------------------------------------------------------------------------------------
		public ReallySimpleListChooser(IPersistenceProvider persistProvider,
			ObjectLabelCollection labels, string fieldName, IVwStylesheet stylesheet)
		{
			m_stylesheet = stylesheet;
			m_persistProvider = persistProvider;
			m_fieldName = fieldName;
			if (labels.Count > 0 && labels.IsFlatList())
				m_fFlatList = true;
			InitializeComponent();

			if (m_persistProvider != null)
				m_persistProvider.RestoreWindowSettings("SimpleListChooser", this);

			SetForDefaultExtras();

			// It's easier to localize a format string than code that pieces together a string.
			this.Text = String.Format(XMLViewsStrings.ksChooseX, fieldName);

			LoadTree(labels, 0, false);

			InitHelp();
		}