Exemplo n.º 1
0
		/// <summary>
		/// Construct one, using the "part ref" element (caller) that
		/// invoked the "slice" node that specified this editor.
		/// </summary>
		/// <param name="caller"></param>
		/// <param name="node"></param>
		public SummarySlice(ICmObject obj, XmlNode caller, XmlNode node, StringTable stringTbl)
			: base()
		{
			string paramType = XmlUtils.GetOptionalAttributeValue(node.ParentNode, "paramType");
			if (paramType == "LiteralString")
			{
				// Instead of the parameter being a layout name, it is literal text which will be
				// the whole contents of the slice, with standard properties.
				string text = XmlUtils.GetManditoryAttributeValue(caller, "label");
				if (stringTbl != null)
					text = stringTbl.LocalizeAttributeValue(text);
				m_view = new LiteralLabelView(text, this);
				m_fLiteralString = true;
			}
			else
			{
				string layout = XmlUtils.GetOptionalAttributeValue(caller, "param");
				if (layout == null)
					layout = XmlUtils.GetManditoryAttributeValue(node, "layout");
				m_view = new SummaryXmlView(obj.Hvo, layout, stringTbl, this);
			}
			UserControl mainControl = new UserControl();
			m_view.Dock = DockStyle.Left;
			m_view.LayoutSizeChanged += new EventHandler(m_view_LayoutSizeChanged);
			mainControl.Height = m_view.Height;
			Control = mainControl;

			m_commandControl = new SummaryCommandControl(this);
			m_commandControl.Dock = DockStyle.Fill;
			m_commandControl.Visible = XmlUtils.GetOptionalBooleanAttributeValue(caller, "commandVisible", false);
			mainControl.Controls.Add(m_commandControl);
			mainControl.Dock = DockStyle.Fill;
			mainControl.Controls.Add(m_view);
		}
Exemplo n.º 2
0
        /// <summary>
        /// Get an optional attribute value from an XmlNode, and look up its localized value in the
        /// given StringTable.
        /// </summary>
        /// <param name="tbl"></param>
        /// <param name="node"></param>
        /// <param name="attrName"></param>
        /// <param name="defaultString"></param>
        /// <returns></returns>
        public static string GetLocalizedAttributeValue(StringTable tbl, XmlNode node,
                                                        string attrName, string defaultString)
        {
            string sValue = GetOptionalAttributeValue(node, attrName, defaultString);

            if (tbl == null)
            {
                return(sValue);
            }
            return(tbl.LocalizeAttributeValue(sValue));
        }
Exemplo n.º 3
0
			public LayoutTreeNode(XmlNode config, StringTable stringTbl, string classParent)
			{
				m_xnConfig = config;
				m_sLabel = XmlUtils.GetLocalizedAttributeValue(stringTbl, config, "label", null);
				if (config.Name == "configure")
				{
					m_sClassName = XmlUtils.GetManditoryAttributeValue(config, "class");
					m_sLayoutName = XmlUtils.GetManditoryAttributeValue(config, "layout");
					m_sPartName = String.Empty;
					m_sVisibility = "required";
				}
				else if (config.Name == "part")
				{
					m_sClassName = classParent;
					string sRef = XmlUtils.GetManditoryAttributeValue(config, "ref");
					if (m_sLabel == null && stringTbl != null)
						m_sLabel = stringTbl.LocalizeAttributeValue(sRef);
					if (config.ParentNode != null && config.ParentNode.Name == "layout")
						m_sLayoutName = XmlUtils.GetManditoryAttributeValue(config.ParentNode, "name");
					else
						m_sLayoutName = String.Empty;
					m_sPartName = String.Format("{0}-Jt-{1}", classParent, sRef);
					m_sVisibility = XmlUtils.GetOptionalAttributeValue(config, "visibility", "always");
					m_fContentVisible = m_sVisibility.ToLowerInvariant() != "never";
					m_sParam = XmlUtils.GetOptionalAttributeValue(config, "param");

					m_sWsLabel = XmlUtils.GetOptionalAttributeValue(config, "ws");
					if (m_sWsLabel != null)
					{
						if (m_sWsLabel.StartsWith(LangProject.WsParamLabel))
							m_sWsLabel = m_sWsLabel.Substring(LangProject.WsParamLabel.Length);
					}
					m_sWsType = XmlUtils.GetOptionalAttributeValue(config, "wsType");
					if (m_sWsLabel != null && String.IsNullOrEmpty(m_sWsType))
					{
						// Try to calculate a WS type from the WS label.
						int ichVern = m_sWsLabel.ToLowerInvariant().IndexOf("vern");
						int ichAnal = m_sWsLabel.ToLowerInvariant().IndexOf("anal");
						int ichPronun = m_sWsLabel.ToLowerInvariant().IndexOf("pronun");
						int ichRevers = m_sWsLabel.ToLowerInvariant().IndexOf("revers");
						if (ichVern >= 0 && ichAnal >= 0 && ichVern > ichAnal)
							m_sWsType = "analysis vernacular";
						else if (ichVern >= 0 && ichAnal >= 0 && ichAnal > ichVern)
							m_sWsType = "vernacular analysis";
						else if (ichVern >= 0)
							m_sWsType = "vernacular";
						else if (ichAnal >= 0)
							m_sWsType = "analysis";
						else if (ichPronun >= 0)
							m_sWsType = "pronunciation";
						else if (ichRevers >= 0)
							m_sWsType = "reversal";
						else
						{
							Debug.Fail(String.Format("This layout node ({0}) does not specify @wsType "
								+ "and we couldn't compute something reasonable from @ws='{1}' "
								+ "so we're setting @wsType to 'vernacular analysis'",
								config.Attributes["ref"].Value, config.Attributes["ws"].Value));
							m_sWsType = "vernacular analysis";	// who knows???
						}
						// store the wsType attribute on the node, so that if 'ws' changes to something
						// specific, we still know what type of wss to provide options for in the m_lvWritingSystems.
						XmlAttribute xa = config.OwnerDocument.CreateAttribute("wsType");
						xa.Value = m_sWsType;
						config.Attributes.Append(xa);
					}
					if (m_sWsType != null)
					{
						if (m_sWsType.StartsWith(LangProject.WsParamLabel))
							m_sWsType = m_sWsType.Substring(LangProject.WsParamLabel.Length);
						if (m_sWsLabel == null)
							m_sWsLabel = "";
					}
					string sSep = null;
					// By default, if we have a ws type or ws label we should be able to show multiple wss,
					// and thus need a separator between them.
					if (!String.IsNullOrEmpty(m_sWsLabel) || !String.IsNullOrEmpty(m_sWsType))
						sSep = " ";
					m_sBefore = XmlUtils.GetOptionalAttributeValue(config, "before", "");
					m_sSep = XmlUtils.GetOptionalAttributeValue(config, "sep", sSep);
					m_sAfter = XmlUtils.GetOptionalAttributeValue(config, "after", " ");

					m_sStyleName = XmlUtils.GetOptionalAttributeValue(config, "style");
					string sFlowType = XmlUtils.GetOptionalAttributeValue(config, "flowType", "span");
					if (sFlowType == "span")
					{
						m_fAllowCharStyle = true;
						if (m_sBefore == null)
							m_sBefore = "";
						if (m_sAfter == null)
							m_sAfter = "";
					}
					m_sNumber = XmlUtils.GetOptionalAttributeValue(config, "number");
					m_sNumStyle = XmlUtils.GetOptionalAttributeValue(config, "numstyle");
					m_fNumSingle = XmlUtils.GetOptionalBooleanAttributeValue(config, "numsingle", false);
					m_sNumFont = XmlUtils.GetOptionalAttributeValue(config, "numfont");
					m_fSingleGramInfoFirst = XmlUtils.GetOptionalBooleanAttributeValue(config, "singlegraminfofirst", false);
					m_fShowComplexFormPara = XmlUtils.GetOptionalBooleanAttributeValue(config, "showasindentedpara", false);
					m_fShowWsLabels = XmlUtils.GetOptionalBooleanAttributeValue(config, "showLabels", false);
					m_sDup = XmlUtils.GetOptionalAttributeValue(config, "dup");
					m_fDuplicate = !String.IsNullOrEmpty(m_sDup);
				}
				this.Checked = m_sVisibility.ToLowerInvariant() != "never";
				this.Text = m_sLabel;
				this.Name = String.Format("{0}/{1}/{2}", m_sClassName, m_sLayoutName, m_sPartName);
			}
Exemplo n.º 4
0
		/// <summary>
		/// This is invoked (using reflection) by an XmlRDEBrowseView when the user presses
		/// "Enter" in an RDE view that is displaying lexeme form and definition.
		/// (Maybe also on loss of focus, switch domain, etc?)
		/// It creates a new entry, lexeme form, and sense that are linked to the specified domain.
		/// Typically, later, a call to RDEMergeSense will be made to see whether this
		/// new entry should be merged into some existing sense.
		/// Note that this method is NOT responsible to insert the new sense into
		/// the fake property tagList of hvoDomain. (The caller will do that.)
		/// </summary>
		/// <param name="hvoDomain">database id of the semantic domain</param>
		/// <param name="tagList">id of the inverse relation for the senses that belong to the
		/// domain</param>
		/// <param name="columns"></param>
		/// <param name="rgtss"></param>
		/// <param name="cache"></param>
		/// <param name="stringTbl"></param>
		public static int RDENewSense(int hvoDomain, int tagList,
			List<XmlNode> columns, ITsString[] rgtss, FdoCache cache, StringTable stringTbl)
		{
			Debug.Assert(hvoDomain != 0);
			Debug.Assert(rgtss.Length == columns.Count);

			// Make a new sense in a new entry.
			ILexEntry le = cache.LangProject.LexDbOA.EntriesOC.Add(
				new LexEntry());
			IMoForm morph = null;

			// create a LexSense that has the given definition and semantic domain
			// Needs to be LexSense, since later calls use non-interface methods.
			LexSense ls = (LexSense)le.SensesOS.Append(new LexSense());

			ILgWritingSystemFactory wsf = cache.LanguageWritingSystemFactoryAccessor;
			// go through each column and store the appropriate information.
			for (int i = 0; i < columns.Count; ++i)
			{
				// Review: Currently we key off the column labels to determine which columns
				// correspond to CitationForm and which correspond to Definition.
				// Ideally we'd like to get at the flids used to build the column display strings.
				// Instead of passing in only ITsStrings, we could pass in a structure containing
				// an index of strings with any corresponding flids.  Here we'd expect strings
				// based upon either LexemeForm.Form or LexSense.Definition. We could probably
				// do this as part of the solution to handling duplicate columns in LT-3763.
				XmlNode column = columns[i] as XmlNode;
				string columnLabel = XmlUtils.GetManditoryAttributeValue(column, "label");
				string[] columnLabelComponents = columnLabel.Split(new char[] {' ', ':'});
				// get column label without writing system or extraneous information.
				string columnBasicLabel = columnLabelComponents[0];
				if (!String.IsNullOrEmpty(columnBasicLabel) && stringTbl != null)
					columnBasicLabel = stringTbl.LocalizeAttributeValue(columnBasicLabel);
				ITsTextProps ttp = rgtss[i].get_PropertiesAt(0);
				int var;
				int ws = ttp.GetIntPropValues((int)FwTextPropType.ktptWs, out var);
				Debug.Assert(ws != 0);

				ITsString tssStr = rgtss[i];
				string sStr = tssStr.Text;
				if (sStr == null)
					sStr = ""; // otherwise Trim below blows up.
				sStr = sStr.Trim();

				if (columnBasicLabel == Strings.ksWord)
				{
					// This is a lexeme form.

					if (morph == null)
						morph = MoForm.MakeMorph(cache, le, tssStr);
					Debug.Assert(le.LexemeFormOAHvo != 0);
					if (morph is IMoStemAllomorph)
					{
						// Make sure we have a proper allomorph and MSA for this new entry and sense.
						// (See LT-1318 for details and justification.)
						MoMorphTypeCollection typesCol = new MoMorphTypeCollection(cache);
						if (sStr.IndexOf(' ') > 0)
							morph.MorphTypeRA = typesCol.Item(MoMorphType.kmtPhrase);
						else
							morph.MorphTypeRA = typesCol.Item(MoMorphType.kmtStem);
						morph.Form.SetAlternative(sStr, ws);
					}
				}
				else if (columnBasicLabel == Strings.ksDefinition)
				{
					// This is a Definition.
					if (sStr != "")
						ls.Definition.SetAlternative(sStr, ws);
				}
				else
				{
					Debug.Fail("column (" + columnLabel + ") not supported.");
				}
			}
			if (morph == null)
				morph = le.LexemeFormOA = new MoStemAllomorph();

			ls.RDEAddDomain(hvoDomain, tagList, cache);

			if (le.MorphoSyntaxAnalysesOC.Count == 0)
			{
				// Commonly, it's a new entry with no MSAs; make sure it has at least one.
				// This way of doing it allows a good bit of code to be shared with the normal
				// creation path, as if the user made a stem but didn't fill in any grammatical
				// information.
				DummyGenericMSA dummyMsa = new DummyGenericMSA();
				if (morph != null && morph is IMoAffixForm)
					dummyMsa.MsaType = MsaType.kUnclassified;
				else
					dummyMsa.MsaType = MsaType.kStem;
				ls.DummyMSA = dummyMsa;
			}

			// We don't want a partial MSA created, so don't bother doing anything
			// about setting ls.MorphoSyntaxAnalysisRA

			// LT-1731: adding to make sure new entries are added to the lexicon
			//	record list (full edit,...)
			cache.PropChanged(null, PropChangeType.kpctNotifyAll,
				cache.LangProject.LexDbOA.Hvo,
				(int)LexDb.LexDbTags.kflidEntries, 0, 1, 0);

			return ls.Hvo;
		}
Exemplo n.º 5
0
		/// <summary>
		/// Get an optional attribute value from an XmlNode, and look up its localized value in the
		/// given StringTable.
		/// </summary>
		/// <param name="tbl"></param>
		/// <param name="node"></param>
		/// <param name="attrName"></param>
		/// <param name="defaultString"></param>
		/// <returns></returns>
		public static string GetLocalizedAttributeValue(StringTable tbl, XmlNode node,
			string attrName, string defaultString)
		{
			string sValue = GetOptionalAttributeValue(node, attrName, defaultString);
			if (tbl == null)
				return sValue;
			return tbl.LocalizeAttributeValue(sValue);
		}
Exemplo n.º 6
0
			public LayoutTreeNode(XmlNode config, StringTable stringTbl, string classParent)
			{
				m_xnConfig = config;
				m_sLabel = XmlUtils.GetLocalizedAttributeValue(stringTbl, config, "label", null);
				if (config.Name == "configure")
				{
					m_sClassName = XmlUtils.GetManditoryAttributeValue(config, "class");
					m_sLayoutName = XmlUtils.GetManditoryAttributeValue(config, "layout");
					m_sPartName = String.Empty;
					m_sVisibility = "required";
				}
				else if (config.Name == "part")
				{
					m_sClassName = classParent;
					string sRef = XmlUtils.GetManditoryAttributeValue(config, "ref");
					if (m_sLabel == null && stringTbl != null)
						m_sLabel = stringTbl.LocalizeAttributeValue(sRef);
					if (config.ParentNode != null && config.ParentNode.Name == "layout")
						m_sLayoutName = XmlUtils.GetManditoryAttributeValue(config.ParentNode, "name");
					else
						m_sLayoutName = String.Empty;
					m_sPartName = String.Format("{0}-Jt-{1}", classParent, sRef);
					m_sVisibility = XmlUtils.GetOptionalAttributeValue(config, "visibility", "always");
					m_fContentVisible = m_sVisibility.ToLowerInvariant() != "never";
					m_sParam = XmlUtils.GetOptionalAttributeValue(config, "param");

					m_sWsLabel = StringServices.GetWsSpecWithoutPrefix(config);
					m_sWsType = XmlUtils.GetOptionalAttributeValue(config, "wsType");
					if (m_sWsLabel != null && String.IsNullOrEmpty(m_sWsType))
					{
						// Try to calculate a WS type from the WS label.
						int ichVern = m_sWsLabel.ToLowerInvariant().IndexOf("vern");
						int ichAnal = m_sWsLabel.ToLowerInvariant().IndexOf("anal");
						int ichPronun = m_sWsLabel.ToLowerInvariant().IndexOf("pronun");
						int ichRevers = m_sWsLabel.ToLowerInvariant().IndexOf("revers");
						if (ichVern >= 0 && ichAnal >= 0 && ichVern > ichAnal)
							m_sWsType = "analysis vernacular";
						else if (ichVern >= 0 && ichAnal >= 0 && ichAnal > ichVern)
							m_sWsType = "vernacular analysis";
						else if (ichVern >= 0)
							m_sWsType = "vernacular";
						else if (ichAnal >= 0)
							m_sWsType = "analysis";
						else if (ichPronun >= 0)
							m_sWsType = "pronunciation";
						else if (ichRevers >= 0)
							m_sWsType = "reversal";
						else
						{
							m_sWsType = "vernacular analysis";	// who knows???
							string refValue = String.Empty;
							string wsValue = String.Empty;
							if (config.Attributes != null)
							{
								refValue = config.Attributes["ref"].Value;
								wsValue = config.Attributes["ws"].Value;
							}
							Debug.Fail(String.Format("This layout node ({0}) does not specify @wsType "
								+ "and we couldn't compute something reasonable from @ws='{1}' "
								+ "so we're setting @wsType to 'vernacular analysis'",
								refValue, wsValue));
						}
							// store the wsType attribute on the node, so that if 'ws' changes to something
							// specific, we still know what type of wss to provide options for in the m_lvWritingSystems.
							if (config.OwnerDocument != null)
							{
							XmlAttribute xa = config.OwnerDocument.CreateAttribute("wsType");
							xa.Value = m_sWsType;
								if (config.Attributes != null)
							config.Attributes.Append(xa);
						}
					}
					m_sWsType = StringServices.GetWsSpecWithoutPrefix(m_sWsType);
					if (m_sWsType != null && m_sWsLabel == null)
							m_sWsLabel = "";
					string sSep = null;
					// By default, if we have a ws type or ws label we should be able to show multiple wss,
					// and thus need a separator between them.
					if (!String.IsNullOrEmpty(m_sWsLabel) || !String.IsNullOrEmpty(m_sWsType))
						sSep = " ";
					m_sBeforeStyleName = XmlUtils.GetOptionalAttributeValue(config, "beforeStyle");
					m_fAllowBeforeStyle = !String.IsNullOrEmpty(m_sBeforeStyleName);
					m_sBefore = XmlUtils.GetOptionalAttributeValue(config, "before", "");
					m_sSep = XmlUtils.GetOptionalAttributeValue(config, "sep", sSep);
					m_sAfter = XmlUtils.GetOptionalAttributeValue(config, "after", " ");

					m_sStyleName = XmlUtils.GetOptionalAttributeValue(config, "style");
					m_sFlowType = XmlUtils.GetOptionalAttributeValue(config, "flowType", "span");
					if (m_sFlowType == "span")
					{
						m_fAllowCharStyle = !XmlUtils.GetOptionalBooleanAttributeValue(
							config, "disallowCharStyle", false);
						if (m_sBefore == null)
							m_sBefore = "";
						if (m_sAfter == null)
							m_sAfter = "";
					}
					// Special handling for div flow elements, which can contain a sequence of paragraphs.
					else if (m_sFlowType == "div")
					{
						m_fAllowParaStyle = m_sClassName == "StText";
						m_fAllowDivParaStyle = false;
						if (m_fAllowParaStyle)
						{
							// We'll be getting the style name from a child layout.
							Debug.Assert(String.IsNullOrEmpty(m_sStyleName));
						}
						else
						{
							m_sStyleName = XmlUtils.GetOptionalAttributeValue(config, "parastyle");
							m_fAllowDivParaStyle = !String.IsNullOrEmpty(m_sStyleName);
						}
						m_sSep = null;
						m_sAfter = null;
						// This is subtly differerent: in a div, we will hide or disable the before control (value null) unless the XML
						// explicitly calls for it by including the attribute. Above we provided an empty string default,
						// which enables the empty control.
						m_sBefore = XmlUtils.GetOptionalAttributeValue(config, "before");
					}
					else if (m_sFlowType == "para")
					{
						m_fAllowParaStyle = !String.IsNullOrEmpty(m_sStyleName);
					}
					else if (m_sFlowType == "divInPara")
					{
						m_sBefore = m_sAfter = m_sSep = null; // suppress the whole separators group since each item is a para
						m_sStyleName = XmlUtils.GetOptionalAttributeValue(config, "parastyle");
						m_fAllowDivParaStyle = !String.IsNullOrEmpty(m_sStyleName);
					}
					m_sSenseParaStyle = XmlUtils.GetOptionalAttributeValue(config, "parastyle");
					m_sNumber = XmlUtils.GetOptionalAttributeValue(config, "number");
					m_sNumStyle = XmlUtils.GetOptionalAttributeValue(config, "numstyle");
					m_fNumSingle = XmlUtils.GetOptionalBooleanAttributeValue(config, "numsingle", false);
					m_sNumFont = XmlUtils.GetOptionalAttributeValue(config, "numfont");
					m_fSingleGramInfoFirst = XmlUtils.GetOptionalBooleanAttributeValue(config, "singlegraminfofirst", false);
					if (m_sFlowType == "divInPara" && m_sParam != null && m_sParam.EndsWith("_AsPara"))
						m_fSenseIsPara = true;
					else
						m_fSenseIsPara = false;

					m_fPreventNullStyle = XmlUtils.GetOptionalBooleanAttributeValue(config, "preventnullstyle", false);
					m_fShowComplexFormPara = XmlUtils.GetOptionalBooleanAttributeValue(config, "showasindentedpara", false);
					if (m_fShowComplexFormPara)
						m_fAllowParaStyle = true;
					m_fShowWsLabels = XmlUtils.GetOptionalBooleanAttributeValue(config, "showLabels", false);
					m_sDup = XmlUtils.GetOptionalAttributeValue(config, "dup");
					m_fDuplicate = !String.IsNullOrEmpty(m_sDup);

					LexRelType = XmlUtils.GetOptionalAttributeValue(config, "lexreltype");
					if (!String.IsNullOrEmpty(LexRelType))
					{
						var sRelTypes = XmlUtils.GetOptionalAttributeValue(config, "reltypeseq");
						RelTypeList = LexReferenceInfo.CreateListFromStorageString(sRelTypes);
					}
					EntryType = XmlUtils.GetOptionalAttributeValue(config, "entrytype");
					if (!String.IsNullOrEmpty(EntryType))
					{
						var sTypeseq = XmlUtils.GetOptionalAttributeValue(config, "entrytypeseq");
						EntryTypeList = ItemTypeInfo.CreateListFromStorageString(sTypeseq);
					}
				}
				Checked = m_sVisibility.ToLowerInvariant() != "never";
				Text = m_sLabel;
				Name = String.Format("{0}/{1}/{2}", m_sClassName, m_sLayoutName, m_sPartName);
			}