Пример #1
0
        /// <summary>
        /// Given the string the user typed, generate the best available guess as to which of the options
        /// he intended. Set hvoNew to 0 (and return tssTyped) if it doesn't match any option.
        /// It is assumed that he is setting an object in property m_tag of object m_hvoParent.
        /// </summary>
        /// <param name="tssTyped"></param>
        /// <returns></returns>
        protected virtual ITsString Lookup(ITsString tssTyped, out int hvoNew)
        {
            ICmObject obj    = CmObject.CreateFromDBObject(m_cache, m_hvoParent);
            string    sTyped = tssTyped == null ? "" : tssTyped.Text;

            if (sTyped == null)
            {
                sTyped = "";
            }
            int cchTyped = sTyped.Length;

            if (cchTyped == 0)
            {
                // Otherwise we'd match the first item and arbitrarily insert it when the user backspaces to
                // nothing. Seems better to wait till at least one letter is typed to try to match.
                hvoNew = 0;
                return(tssTyped);
            }
            int ipossibility = -1;

            foreach (int hvo in obj.ReferenceTargetCandidates(m_tag))
            {
                ipossibility++;
                string key = null;
                if (ipossibility < m_shortnames.Count)
                {
                    key = m_shortnames[ipossibility];                     // Use the cache as far as it goes
                }
                else
                {
                    ICmObject item = CmObject.CreateFromDBObject(m_cache, hvo);
                    key = item.ShortName;
                    m_shortnames.Add(key);                     // extend the cache for next time.
                }
                if (sTyped.Length < key.Length && key.Substring(0, cchTyped) == sTyped)
                {
                    hvoNew = hvo;
                    ITsStrBldr bldr = tssTyped.GetBldr();
                    bldr.Replace(0, bldr.Length, key, null);
                    // Clear any underlining left over from previous bad value.
                    bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptUnderline,
                                          -1, -1);
                    bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptUnderColor,
                                          -1, -1);
                    return(bldr.GetString());                    // Same ws as input, contents replaced.
                }
            }
            hvoNew = 0;
            return(tssTyped);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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
        }
		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
		}