Beispiel #1
0
 private void DrawTreeNodeRecursive(Graphics g, LayoutTreeNode node)
 {
     g.DrawRectangle(Pens.Black, Rectangle.Round(node.Extent));
     node.Draw(g);
     foreach (LayoutTreeNode childNode in node.Children)
     {
         DrawTreeNodeRecursive(g, childNode);
     }
 }
Beispiel #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            LayoutTree lTree = new LayoutTree();
            lTree.VerticalSpacer = 20.0f;
            lTree.HorizontalSpacer = 30.0f;
            TextLayoutTreeNode root = lTree.CreateNode<TextLayoutTreeNode>(null);
            root.Text = "root";
            TextLayoutTreeNode c0 = lTree.CreateNode<TextLayoutTreeNode>(root);
            c0.Text = "c0";
            TextLayoutTreeNode c1 = lTree.CreateNode<TextLayoutTreeNode>(root);
            c1.Text = "aaaaaaaaaaaaa\naaaaaaaaaaaaa";
            TextLayoutTreeNode c2 = lTree.CreateNode<TextLayoutTreeNode>(c1);
            c2.Text = "c2";
            TextLayoutTreeNode c3 = lTree.CreateNode<TextLayoutTreeNode>(c1);
            c3.Text = "bbbbbbbbbbbb";

            rootNode = root;
        }
		private void AddUnspecifiedTypes(bool fstemBased, int cvarTypes, LayoutTreeNode ltn)
		{
			int index;
			if (!fstemBased)
			{
				if (!ListContainsGuid(ltn.EntryTypeList, m_unspecComplexFormType, out index))
				{
					var unspecified = new ItemTypeInfo(true, m_unspecComplexFormType);
					ltn.EntryTypeList.Insert(cvarTypes, unspecified);
					index = cvarTypes;
				}
				ltn.EntryTypeList[index].Name = m_noComplexEntryTypeLabel;
			}
			if (!ListContainsGuid(ltn.EntryTypeList, m_unspecVariantType, out index))
			{
				var unspecified = new ItemTypeInfo(true, m_unspecVariantType);
				ltn.EntryTypeList.Insert(0, unspecified);
				index = 0;
			}
			ltn.EntryTypeList[index].Name = m_noVariantTypeLabel;
		}
		private void SetActiveNode(LayoutTreeNode ltn, string className, string layoutName, string partRef)
		{
			if (XmlUtils.GetOptionalAttributeValue(ltn.Configuration, "ref") == partRef
				&& ltn.ParentLayout != null // is this ever possible?
				&& XmlUtils.GetOptionalAttributeValue(ltn.ParentLayout, "class") == className
				&& XmlUtils.GetOptionalAttributeValue(ltn.ParentLayout, "name") == layoutName)
			{
				m_tvParts.SelectedNode = ltn;
				return;
			}
			foreach (LayoutTreeNode ltnChild in ltn.Nodes)
				SetActiveNode(ltnChild, className, layoutName, partRef);
		}
		private void FixEntryTypeList(LayoutTreeNode ltn, string parentLayoutName)
		{
			// Add any new types to our ordered list (or fill in an empty list).
			var setGuidsFromXml = new Set<Guid>(ltn.EntryTypeList.Select(info => info.ItemGuid));
			Dictionary<Guid, ICmPossibility> mapGuidType;
			int index;
			switch (ltn.EntryType)
			{
				case "complex":
					// Get the canonical list from the project if needed.
					if (m_rgComplexFormTypes == null)
						m_rgComplexFormTypes = GetSortedFlattenedComplexFormTypeList();

					mapGuidType = m_rgComplexFormTypes.ToDictionary(poss => poss.Guid);
					foreach (var info in
						from poss in m_rgComplexFormTypes
						where !setGuidsFromXml.Contains(poss.Guid)
						select new ItemTypeInfo(true, poss.Guid))
					{
						ltn.EntryTypeList.Add(info);
					}
					if (!ListContainsGuid(ltn.EntryTypeList, m_unspecComplexFormType, out index))
					{
						var unspecified = new ItemTypeInfo(true, m_unspecComplexFormType);
						ltn.EntryTypeList.Insert(0, unspecified);
						index = 0;
					}
					ltn.EntryTypeList[index].Name = m_noComplexEntryTypeLabel;
					break;
				case "variant":
					// Get the canonical list from the project if needed.
					if (m_rgVariantTypes == null)
						m_rgVariantTypes = GetSortedFlattenedVariantTypeList();

					mapGuidType = m_rgVariantTypes.ToDictionary(poss => poss.Guid);
					foreach (var info in
						from poss in m_rgVariantTypes
						where !setGuidsFromXml.Contains(poss.Guid)
						select new ItemTypeInfo(true, poss.Guid))
					{
						ltn.EntryTypeList.Add(info);
					}
					if (!ListContainsGuid(ltn.EntryTypeList, m_unspecVariantType, out index))
					{
						var unspecified = new ItemTypeInfo(true, m_unspecVariantType);
						ltn.EntryTypeList.Insert(0, unspecified);
						index = 0;
					}
					ltn.EntryTypeList[index].Name = m_noVariantTypeLabel;
					break;
				//case "minor":
				default:
					// Should be 'minor', but treat any unknown entrytype as 'minor'
					var fstemBased = parentLayoutName.Contains(sdefaultStemBasedLayout);
					// Get the canonical Variant Type list from the project if needed.
					if (m_rgVariantTypes == null)
						m_rgVariantTypes = GetSortedFlattenedVariantTypeList();

					mapGuidType = m_rgVariantTypes.ToDictionary(poss => poss.Guid);
					// Root-based views have Complex Forms as Minor Entries too.
					if (!fstemBased)
					{
						// Get the canonical Complex Form Type list from the project if needed.
						if (m_rgComplexFormTypes == null)
							m_rgComplexFormTypes = GetSortedFlattenedComplexFormTypeList();
						// Add them to the map
						foreach (var poss in m_rgComplexFormTypes)
							mapGuidType.Add(poss.Guid, poss);
					}

					// Now make sure the LayoutTreeNode has the right entries
					foreach (var info in
						from kvp in mapGuidType
						where !setGuidsFromXml.Contains(kvp.Key)
						select new ItemTypeInfo(true, kvp.Key))
					{
						ltn.EntryTypeList.Add(info);
					}
					AddUnspecifiedTypes(fstemBased, fstemBased ? 0 : m_rgVariantTypes.Count, ltn);
					break;
			}
			// Remove any obsolete types from our ordered list.
			var obsoleteItems = ltn.EntryTypeList.Where(info => !IsUnspecifiedPossibility(info) &&
				!mapGuidType.ContainsKey(info.ItemGuid)).ToList();
			foreach (var info in obsoleteItems)
				ltn.EntryTypeList.Remove(info);
			// Add the names to the items in the ordered list.
			foreach (var info in ltn.EntryTypeList)
			{
				if (IsUnspecifiedPossibility(info))
					continue;
				var poss = mapGuidType[info.ItemGuid];
				info.Name = poss.Name.BestAnalysisVernacularAlternative.Text;
			}
		}
		private void AddChildNodes(XmlNode layout, LayoutTreeNode ltnParent, int iStart)
		{
			m_stackLayouts.Insert(0, layout);		// push this layout onto the stack.
			try
			{
				bool fMerging = iStart < ltnParent.Nodes.Count;
				int iNode = iStart;
				string className = XmlUtils.GetManditoryAttributeValue(layout, "class");
				List<XmlNode> nodes = PartGenerator.GetGeneratedChildren(layout, m_mdc,
					new string[] { "ref", "label" });
				foreach (XmlNode node in nodes)
				{
					XmlNode subLayout;
					if (node.Name == "sublayout")
					{
						Debug.Assert(!fMerging);
						string subLayoutName = XmlUtils.GetOptionalAttributeValue(node, "name", null);
						if (subLayoutName == null)
						{
							subLayout = node; // a sublayout lacking a name contains the part refs directly.
						}
						else
						{
							subLayout = m_layouts.GetElement("layout",
								new string[] { className, "jtview", subLayoutName });
						}
						if (subLayout != null)
							AddChildNodes(subLayout, ltnParent, ltnParent.Nodes.Count);
					}
					else if (node.Name == "part")
					{
						// Check whether this node has already been added to this parent.  Don't add
						// it if it's already there!
						LayoutTreeNode ltnOld = FindMatchingNode(ltnParent, node);
						if (ltnOld != null)
							continue;
						string sRef = XmlUtils.GetManditoryAttributeValue(node, "ref");
						XmlNode part = m_parts.GetElement("part",
							new string[] { className + "-Jt-" + sRef });
						if (part == null && sRef != "$child")
							continue;
						bool fHide = XmlUtils.GetOptionalBooleanAttributeValue(node, "hideConfig", false);
						LayoutTreeNode ltn;
						if (!fHide)
						{
							ltn = new LayoutTreeNode(node, m_stringTbl, className);
							ltn.OriginalIndex = ltnParent.Nodes.Count;
							ltn.CallingLayout = m_stackLayouts[0];
							ltn.ParentLayout = layout;
							ltn.HiddenNode = m_hidden.Part;
							ltn.HiddenParent = m_hidden.Layout;
							ltn.HiddenCallingLayout = m_hidden.Caller;
							if (fMerging)
								(ltnParent.Nodes[iNode] as LayoutTreeNode).MergedNodes.Add(ltn);
							else
								ltnParent.Nodes.Add(ltn);
						}
						else
						{
							Debug.Assert(!fMerging);
							ltn = ltnParent;
							m_hidden.Push(node, layout, m_stackLayouts[0]);
						}
						if (part != null)
							ProcessChildNodes(part.ChildNodes, className, ltn);
						ltn.OriginalNumberOfSubnodes = ltn.Nodes.Count;
						m_hidden.Pop();
						++iNode;
					}
				}
			}
			finally
			{
				m_stackLayouts.RemoveAt(0);	// pop this layout off the stack.
			}
		}
		/// <summary>
		/// Walk the tree of child nodes, storing information for each &lt;obj&gt; or &lt;seq&gt;
		/// node.
		/// </summary>
		/// <param name="xmlNodeList"></param>
		/// <param name="className"></param>
		/// <param name="ltn"></param>
		private void ProcessChildNodes(XmlNodeList xmlNodeList, string className, LayoutTreeNode ltn)
		{
			foreach (XmlNode xn in xmlNodeList)
			{
				if (xn is XmlComment)
					continue;
				if (xn.Name == "obj" || xn.Name == "seq" || xn.Name == "objlocal")
				{
					StoreChildNodeInfo(xn, className, ltn);
				}
				else
				{
					ProcessChildNodes(xn.ChildNodes, className, ltn);
				}
			}
		}
		private void StoreComplexFormData(LayoutTreeNode ltn)
		{
			ltn.ShowComplexFormPara = m_chkComplexFormsAsParagraphs.Checked;
		}
			private void CopyValuesTo(LayoutTreeNode ltn)
			{
				// Review: might be difficult to keep this up-to-date! How do we know we've got
				// everything in here that needs to be here?! --gjm
				ltn.m_cSubnodes = m_cSubnodes;
				ltn.m_fAllowBeforeStyle = m_fAllowBeforeStyle;
				ltn.m_fAllowCharStyle = m_fAllowCharStyle;
				ltn.m_fAllowDivParaStyle = m_fAllowDivParaStyle;
				ltn.m_fAllowParaStyle = m_fAllowParaStyle;
				ltn.m_fContentVisible = m_fContentVisible;
				ltn.m_fDuplicate = m_fDuplicate;
				//ltn.m_fHiddenChildDirty = m_fHiddenChildDirty;
				ltn.m_fNumSingle = m_fNumSingle;
				//ltn.m_fPreventNullStyle = m_fPreventNullStyle;
				ltn.m_fSenseIsPara = m_fSenseIsPara;
				ltn.m_fShowComplexFormPara = m_fShowComplexFormPara;
				ltn.m_fShowComplexFormParaConfig = m_fShowComplexFormParaConfig;
				ltn.m_fShowGramInfoConfig = m_fShowGramInfoConfig;
				ltn.m_fShowSenseConfig = m_fShowSenseConfig;
				ltn.m_fShowWsLabels = m_fShowWsLabels;
				ltn.m_fSingleGramInfoFirst = m_fSingleGramInfoFirst;
				ltn.m_fStyleFromHiddenChild = m_fStyleFromHiddenChild;
				ltn.m_fUseParentConfig = m_fUseParentConfig;
				ltn.m_idxOrig = m_idxOrig;
				//ltn.m_rgltnMerged = m_rgltnMerged;
				ltn.m_sAfter = m_sAfter;
				ltn.m_sBefore = m_sBefore;
				ltn.m_sBeforeStyleName = m_sBeforeStyleName;
				ltn.m_sClassName = m_sClassName;
				ltn.m_sDup = m_sDup;
				ltn.m_sFlowType = m_sFlowType;
				ltn.m_sLabel = m_sLabel;
				ltn.m_sLayoutName = m_sLayoutName;
				ltn.m_sNumber = m_sNumber;
				ltn.m_sNumFont = m_sNumFont;
				ltn.m_sNumStyle = m_sNumStyle;
				ltn.m_sParam = m_sParam;
				ltn.m_sPartName = m_sPartName;
				ltn.m_sSenseParaStyle = m_sSenseParaStyle;
				ltn.m_sSep = m_sSep;
				ltn.m_sStyleName = m_sStyleName;
				ltn.m_sVisibility = m_sVisibility;
				ltn.m_sWsLabel = m_sWsLabel;
				ltn.m_sWsType = m_sWsType;
				ltn.m_xnCallingLayout = m_xnCallingLayout;
				ltn.m_xnConfig = m_xnConfig;
				ltn.m_xnHiddenChild = m_xnHiddenChild;
				ltn.m_xnHiddenChildLayout = m_xnHiddenChildLayout;
				ltn.m_xnHiddenNode = m_xnHiddenNode;
				ltn.m_xnHiddenParentLayout = m_xnHiddenParentLayout;
				ltn.m_xnParentLayout = m_xnParentLayout;
				ltn.LexRelType = LexRelType;
				ltn.RelTypeList = RelTypeList;
				ltn.EntryType = EntryType;
				ltn.EntryTypeList = EntryTypeList;
			}
		private void StoreSenseConfigData(LayoutTreeNode ltn)
		{
			if (m_cfgSenses.NumberStyleCombo.SelectedIndex == 0)
			{
				ltn.Number = "";
			}
			else
			{
				ltn.Number = m_cfgSenses.BeforeNumber +
					((NumberStyleComboItem)m_cfgSenses.NumberStyleCombo.SelectedItem).FormatString +
					m_cfgSenses.AfterNumber;
				ltn.NumStyle = GenerateNumStyleFromCheckBoxes();
				ltn.NumFont = m_cfgSenses.NumberFontCombo.SelectedItem.ToString();	// item is a string actually...
				if (ltn.NumFont == xWorksStrings.ksUnspecified)
					ltn.NumFont = String.Empty;
				ltn.NumberSingleSense = m_cfgSenses.NumberSingleSense;
			}
			ltn.ShowSingleGramInfoFirst = m_chkShowSingleGramInfoFirst.Checked;
			// Set the information on the child grammatical info node as well.
			foreach (TreeNode n in ltn.Nodes)
			{
				LayoutTreeNode tn = n as LayoutTreeNode;
				if (tn != null && tn.ShowGramInfoConfig)
				{
					tn.ShowSingleGramInfoFirst = m_chkShowSingleGramInfoFirst.Checked;
					break;
				}
			}
			ltn.ShowSenseAsPara = m_cfgSenses.DisplaySenseInPara;
			ltn.SenseParaStyle = m_cfgSenses.SenseParaStyle;
			//ltn.SingleSenseStyle = m_cfgSenses.SingleSenseStyle;
		}
		private void StoreGramInfoData(LayoutTreeNode ltn)
		{
			if (m_cfgSenses.Visible)
				return;
			ltn.ShowSingleGramInfoFirst = m_chkShowSingleGramInfoFirst.Checked;
			// Set the information on the parent sense node as well.
			var ltnParent = ltn.Parent as LayoutTreeNode;
			if (ltnParent != null && ltnParent.ShowSenseConfig)
				ltnParent.ShowSingleGramInfoFirst = m_chkShowSingleGramInfoFirst.Checked;
		}
		private void MakeDivInParaChildNotVisible(LayoutTreeNode ltn, object sender)
		{
			// applies to Root dictionary ltn=Senses when ShowSenseAsPara=false
			var lts = sender as ConfigSenseLayout;
			if (lts == null) return;
			if (lts.DisplaySenseInPara) return;
			// find Stem: Main Entry-Senses-Visible Complex Forms ltn
			foreach (TreeNode n in ltn.Nodes) // iterate over child nodes
			{
				LayoutTreeNode tn = n as LayoutTreeNode;
				if (tn != null)
				{
					// meant for tn.Label == "Subentries" in root dictionary
					if (tn.Checked && tn.FlowType == "divInPara")
					{
						var resources = new ComponentResourceManager(typeof(XmlDocConfigureDlg));

						MessageBox.Show(resources.GetString("k_RootSenseOnSubentriesGoneDlgText"),
							resources.GetString("k_RootSenseOnSubentriesGoneDlgLabel"),
							MessageBoxButtons.OK, MessageBoxIcon.Information);

						tn.Checked = false;
						break;
					}
					// meant for tn.Label.Contains("Referenced Complex Form") in stem dictionary
					if (tn.Checked && tn.FlowType == "span" &&
							 tn.Label.Contains(xWorksStrings.ksReferencedComplexForm) &&
							 tn.ShowComplexFormPara)
					{
						tn.ShowComplexFormPara = false;
						break;
					}
				}
			}
		}
		private void MakeParentParaIfDivInParaVisible(LayoutTreeNode ltn)
		{
			if (ltn.Checked && ltn.FlowType == "divInPara")
			{
				var ltnParent = ltn.Parent as LayoutTreeNode;
				if (ltnParent != null)
				{
					ltnParent.ShowSenseAsPara = true;
					if (ltnParent == m_current)
					{
						DisplayCurrentNodeDetails();
					}
				}
			}
		}
		private void StoreNodeData(LayoutTreeNode ltn)
		{
			ltn.ContentVisible = ltn.Checked;
			if (m_tbBefore.Visible && m_tbBefore.Enabled)
				ltn.Before = m_tbBefore.Text;
			else
				ltn.Before = ""; // if it's invisible don't let any non-empty value be saved.
			if (m_tbBetween.Visible && m_tbBetween.Enabled)
				ltn.Between = m_tbBetween.Text;
			else
				ltn.Between = ""; // if it's invisible don't let any non-empty value be saved.
			if (m_tbAfter.Visible && m_tbAfter.Enabled)
				ltn.After = m_tbAfter.Text;
			else
				ltn.After = ""; // if it's invisible don't let any non-empty value be saved.
			if (m_chkDisplayWsAbbrs.Visible)
				ltn.ShowWsLabels = m_chkDisplayWsAbbrs.Checked && m_chkDisplayWsAbbrs.Enabled;
			if (m_cfgSenses.Visible)
				StoreSenseConfigData(ltn);
			if (m_chkShowSingleGramInfoFirst.Visible)
				StoreGramInfoData(ltn);
			if (m_chkComplexFormsAsParagraphs.Visible)
				StoreComplexFormData(ltn);
			if (m_cbCharStyle.Visible && m_cbCharStyle.Enabled)
			{
				var sci = m_cbCharStyle.SelectedItem as StyleComboItem;
				if (sci != null && sci.Style != null)
					ltn.StyleName = sci.Style.Name;
				else
					ltn.StyleName = String.Empty;
			}
			if (m_cbBeforeStyle.Visible && m_cbBeforeStyle.Enabled)
			{
				var sci = m_cbBeforeStyle.SelectedItem as StyleComboItem;
				if (sci != null && sci.Style != null)
					ltn.BeforeStyleName = sci.Style.Name;
				else
					ltn.BeforeStyleName = String.Empty;
			}
			if (m_lvItems.Visible && m_lvItems.Enabled)
				ltn.WsLabel = GenerateWsLabelFromListView();
			MakeParentParaIfDivInParaVisible(ltn);
		}
Beispiel #15
0
		private void m_tvParts_AfterSelect(object sender, TreeViewEventArgs e)
		{
			// Save the data for the old node before displaying the data for the new node.
			if (m_current != null && m_current.Level > 0)
				StoreNodeData();

			// Set up the dialog for editing the current node's layout.
			m_current = e.Node as LayoutTreeNode;
			DisplayCurrentNodeDetails();
		}
			internal LayoutTreeNode CreateCopy()
			{
				var ltn = new LayoutTreeNode();
				CopyValuesTo(ltn);
				ltn.m_xnConfig = m_xnConfig.Clone();
				ltn.IsDuplicate = true;
				ltn.m_cSubnodes = 0;
				if (ltn.RelTypeList != null && ltn.RelTypeList.Count > 0)
				{
					ltn.RelTypeList = LexReferenceInfo.CreateListFromStorageString(ltn.LexRelTypeSequence);
				}
				if (ltn.EntryTypeList != null && ltn.EntryTypeList.Count > 0)
				{
					ltn.EntryTypeList = ItemTypeInfo.CreateListFromStorageString(ltn.EntryTypeSequence);
				}
				return ltn;
			}
Beispiel #17
0
		private LayoutTreeNode BuildMainLayout(XmlNode config)
		{
			LayoutTreeNode ltn = new LayoutTreeNode(config, m_stringTbl, null);
			ltn.OriginalIndex = m_tvParts.Nodes.Count;
			string className = ltn.ClassName;
			string layoutName = ltn.LayoutName;
			XmlNode layout = m_layouts.GetElement("layout", new string[] { className, "jtview", layoutName });
			if (layout == null)
				throw new Exception("Cannot configure layout " + layoutName + " of class " + className + " because it does not exist");
			ltn.ParentLayout = layout;	// not really the parent layout, but the parent of this node's children
			string sVisible = XmlUtils.GetAttributeValue(layout, "visibility");
			ltn.Checked = sVisible != "never";
			AddChildNodes(layout, ltn, ltn.Nodes.Count);
			ltn.OriginalNumberOfSubnodes = ltn.Nodes.Count;
			return ltn;
		}
		private void AddChildNodes(XmlNode layout, LayoutTreeNode ltnParent, int iStart)
		{
			bool fMerging = iStart < ltnParent.Nodes.Count;
			int iNode = iStart;
			string className = XmlUtils.GetManditoryAttributeValue(layout, "class");
			List<XmlNode> nodes = PartGenerator.GetGeneratedChildren(layout, m_cache,
				new[] { "ref", "label" });
			foreach (XmlNode node in nodes)
			{
				XmlNode subLayout;
				if (node.Name == "sublayout")
				{
					Debug.Assert(!fMerging);
					string subLayoutName = XmlUtils.GetOptionalAttributeValue(node, "name", null);
					if (subLayoutName == null)
					{
						subLayout = node; // a sublayout lacking a name contains the part refs directly.
					}
					else
					{
						subLayout = m_layouts.GetElement("layout",
							new[] { className, "jtview", subLayoutName, null });
					}
					if (subLayout != null)
						AddChildNodes(subLayout, ltnParent, ltnParent.Nodes.Count);
				}
				else if (node.Name == "part")
				{
					// Check whether this node has already been added to this parent.  Don't add
					// it if it's already there!
					LayoutTreeNode ltnOld = FindMatchingNode(ltnParent, node);
					if (ltnOld != null)
						continue;
					string sRef = XmlUtils.GetManditoryAttributeValue(node, "ref");
					XmlNode part = m_parts.GetElement("part",
					new[] { className + "-Jt-" + sRef });
					if (part == null && sRef != "$child")
						continue;
					bool fHide = XmlUtils.GetOptionalBooleanAttributeValue(node, "hideConfig", false);
					LayoutTreeNode ltn;
					var cOrig = 0;
					if (!fHide)
					{
						ltn = new LayoutTreeNode(node, m_stringTbl, className)
							{
								OriginalIndex = ltnParent.Nodes.Count,
								ParentLayout = layout,
								HiddenNode = m_levels.HiddenPartRef,
								HiddenNodeLayout = m_levels.HiddenLayout
							};
						if (!String.IsNullOrEmpty(ltn.LexRelType))
							FixLexRelationTypeList(ltn);
						if (!String.IsNullOrEmpty(ltn.EntryType))
							FixEntryTypeList(ltn, ltnParent.LayoutName);
						//if (fMerging)
							//((LayoutTreeNode)ltnParent.Nodes[iNode]).MergedNodes.Add(ltn);
						//else
							ltnParent.Nodes.Add(ltn);
					}
					else
					{
						Debug.Assert(!fMerging);
						ltn = ltnParent;
						cOrig = ltn.Nodes.Count;
						if (className == "StTxtPara")
						{
							ltnParent.HiddenChildLayout = layout;
							ltnParent.HiddenChild = node;
						}
					}
					try
					{
						m_levels.Push(node, layout);
						var fOldAdding = ltn.AddingSubnodes;
						ltn.AddingSubnodes = true;
						if (part != null)
							ProcessChildNodes(part.ChildNodes, className, ltn);
						ltn.OriginalNumberOfSubnodes = ltn.Nodes.Count;
						ltn.AddingSubnodes = fOldAdding;
						if (fHide)
						{
							var cNew = ltn.Nodes.Count - cOrig;
							var msg = String.Format("{0} nodes for a hidden PartRef ({1})!", cNew, node.OuterXml);
							//Debug.Assert(cNew <= 1, msg);
							//if (cNew > 1)
							//    Debug.WriteLine(msg);
						}
					}
					finally
					{
						m_levels.Pop();
					}
					++iNode;
				}
			}
		}
Beispiel #19
0
		private LayoutTreeNode FindMatchingNode(LayoutTreeNode ltn, XmlNode node)
		{
			if (ltn == null || node == null)
				return null;
			foreach (LayoutTreeNode ltnSub in ltn.Nodes)
			{
				if (ltnSub.Configuration == node)
					return ltnSub;
			}
			return FindMatchingNode(ltn.Parent as LayoutTreeNode, node);
		}
		private void FixLexRelationTypeList(LayoutTreeNode ltn)
		{
			// Get the canonical list from the project.
			if (m_rgRelationTypes == null)
			{
				m_rgRelationTypes = m_cache.LangProject.LexDbOA.ReferencesOA.PossibilitiesOS.ToList();
				m_rgRelationTypes.Sort(ComparePossibilitiesByName);
			}
			// Add any new types to our ordered list (or fill in an empty list).
			var setSortedGuids = new Set<GuidAndSubClass>();
			foreach (var lri in ltn.RelTypeList)
				setSortedGuids.Add(new GuidAndSubClass(lri.ItemGuid, lri.SubClass));
			foreach (var poss in m_rgRelationTypes)
			{
				var lrt = (ILexRefType)poss;
				if (ltn.LexRelType == "sense")
				{
					if (lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryAsymmetricPair ||
						lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryCollection ||
						lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryPair ||
						lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntrySequence ||
						lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryTree)
					{
						continue;
					}
				}
				else
				{
					if (lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseAsymmetricPair ||
						lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseCollection ||
						lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSensePair ||
						lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseSequence ||
						lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseTree)
					{
						continue;
					}
				}
				var gsc = new GuidAndSubClass(poss.Guid, LexReferenceInfo.TypeSubClass.Normal);
				if (lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryAsymmetricPair ||
					lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryOrSenseAsymmetricPair ||
					lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseAsymmetricPair ||
					lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryTree ||
					lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree ||
					lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseTree)
				{
					gsc.SubClass = LexReferenceInfo.TypeSubClass.Forward;
				}
				if (!setSortedGuids.Contains(gsc))
				{
					var lri = new LexReferenceInfo(true, poss.Guid)
						{
							SubClass = gsc.SubClass
						};
					ltn.RelTypeList.Add(lri);
				}
				if (gsc.SubClass == LexReferenceInfo.TypeSubClass.Forward)
				{
					gsc.SubClass = LexReferenceInfo.TypeSubClass.Reverse;
					if (!setSortedGuids.Contains(gsc))
					{
						var lri = new LexReferenceInfo(true, poss.Guid)
							{
								SubClass = gsc.SubClass
							};
						ltn.RelTypeList.Add(lri);
					}
				}
			}
			// Remove any obsolete types from our ordered list.
			var mapGuidType = new Dictionary<GuidAndSubClass, ILexRefType>();
			foreach (var poss in m_rgRelationTypes)
			{
				var lrt = (ILexRefType)poss;
				var gsc = new GuidAndSubClass(lrt.Guid, LexReferenceInfo.TypeSubClass.Normal);
				if (lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryAsymmetricPair ||
					lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryOrSenseAsymmetricPair ||
					lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseAsymmetricPair ||
					lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryTree ||
					lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree ||
					lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseTree)
				{
					gsc.SubClass = LexReferenceInfo.TypeSubClass.Forward;
				}
				mapGuidType.Add(gsc, lrt);
				if (gsc.SubClass == LexReferenceInfo.TypeSubClass.Forward)
				{
					var gsc2 = new GuidAndSubClass(lrt.Guid, LexReferenceInfo.TypeSubClass.Reverse);
					mapGuidType.Add(gsc2, lrt);
				}
			}
			var obsoleteItems = ltn.RelTypeList.Where(
				lri => !mapGuidType.ContainsKey(new GuidAndSubClass(lri.ItemGuid, lri.SubClass))).ToList();
			foreach (var lri in obsoleteItems)
				ltn.RelTypeList.Remove(lri);
			// Add the names to the items in the ordered list.
			foreach (var lri in ltn.RelTypeList)
			{
				var lrt = mapGuidType[new GuidAndSubClass(lri.ItemGuid, lri.SubClass)];
				if (lri.SubClass == LexReferenceInfo.TypeSubClass.Reverse)
					lri.Name = lrt.ReverseName.BestAnalysisVernacularAlternative.Text;
				else
					lri.Name = lrt.Name.BestAnalysisVernacularAlternative.Text;
			}
		}
Beispiel #21
0
		private void StoreChildNodeInfo(XmlNode xn, string className, LayoutTreeNode ltn)
		{
			string sField = XmlUtils.GetManditoryAttributeValue(xn, "field");
			if (ltn.Level > 0)
			{
				if (sField == "Senses" && (ltn.ClassName == "LexEntry" || ltn.ClassName == "LexSense"))
				{
					ltn.ShowSenseConfig = true;
				}
				else if (sField == "ReferringSenses" && ltn.ClassName == "ReversalIndexEntry")
				{
					ltn.ShowSenseConfig = true;
				}
				if (sField == "MorphoSyntaxAnalysis" && ltn.ClassName == "LexSense")
				{
					ltn.ShowGramInfoConfig = true;
				}
				if (sField == "ComplexFormEntryBackRefs" && ltn.ClassName == "LexEntry")
				{
					string sShowAsIndentedPara = XmlUtils.GetAttributeValue(ltn.Configuration, "showasindentedpara");
					ltn.ShowComplexFormParaConfig = !String.IsNullOrEmpty(sShowAsIndentedPara);
				}
			}
			bool fRecurse = XmlUtils.GetOptionalBooleanAttributeValue(ltn.Configuration, "recurseConfig", true);
			if (!fRecurse)
			{
				// We don't want to recurse forever just because senses have subsenses, which
				// can have subsenses, which can ...
				// Or because entries have subentries (in root type layouts)...
				ltn.UseParentConfig = true;
				return;
			}
			XmlNode xnCaller = m_hidden.Part;
			if (xnCaller == null)
				xnCaller = ltn.Configuration;
			string sLayout = XmlVc.GetLayoutName(xn, xnCaller);
			int flid = 0;
			uint clidDst = 0;
			string sClass = null;
			string sTargetClasses = null;
			try
			{
				flid = m_cache.GetFlid(0, className, sField);
				if ((int)flid == 0)
					return;
				FieldType type = m_cache.GetFieldType(flid);
				Debug.Assert(type >= FieldType.kcptMinObj);
				if (type >= FieldType.kcptMinObj)
				{
					sTargetClasses = XmlUtils.GetOptionalAttributeValue(xn, "targetclasses");
					if (flid < (int)CmObject.SpecialTagValues.ktagMinVp)
					{
						clidDst = m_mdc.GetDstClsId((uint)flid);
						if (clidDst == 0)
							sClass = XmlUtils.GetOptionalAttributeValue(xn, "targetclass");
						else
							sClass = m_mdc.GetClassName(clidDst);
					}
					else
					{
						sClass = XmlUtils.GetOptionalAttributeValue(xn, "targetclass");
					}
				}
			}
			catch
			{
			}
			if (clidDst == (uint)MoForm.kclsidMoForm && !sLayout.StartsWith("publi"))
				return;	// ignore the layouts used by the LexEntry-Jt-Headword part.
			if (String.IsNullOrEmpty(sLayout) || String.IsNullOrEmpty(sClass))
				return;
			if (sTargetClasses == null)
				sTargetClasses = sClass;
			string[] rgsClasses = sTargetClasses.Split(new char[] { ',', ' ' },
				StringSplitOptions.RemoveEmptyEntries);
			XmlNode subLayout = null;
			if (rgsClasses.Length > 0)
				subLayout = m_layouts.GetElement("layout", new string[] { rgsClasses[0], "jtview", sLayout });

			if (subLayout != null)
			{
				int iStart = ltn.Nodes.Count;
				int cNodes = subLayout.ChildNodes.Count;
				AddChildNodes(subLayout, ltn, iStart);

				bool fRepeatedConfig = XmlUtils.GetOptionalBooleanAttributeValue(xn, "repeatedConfig", false);
				if (fRepeatedConfig)
					return;		// repeats an earlier part element (probably as a result of <if>s)
				for (int i = 1; i < rgsClasses.Length; i++)
				{
					XmlNode mergedLayout = m_layouts.GetElement("layout",
						new string[] { rgsClasses[i], "jtview", sLayout });
					if (mergedLayout != null && mergedLayout.ChildNodes.Count == cNodes)
					{
						AddChildNodes(mergedLayout, ltn, iStart);
					}
				}
			}
		}
		private void StoreChildNodeInfo(XmlNode xn, string className, LayoutTreeNode ltn)
		{
			string sField = XmlUtils.GetManditoryAttributeValue(xn, "field");
			XmlNode xnCaller = m_levels.PartRef;
			if (xnCaller == null)
				xnCaller = ltn.Configuration;
			bool hideConfig = xnCaller == null ? false : XmlUtils.GetOptionalBooleanAttributeValue(xnCaller, "hideConfig", false);
			// Insert any special configuration appropriate for this property...unless the caller is hidden, in which case,
			// we don't want to configure it at all.
			if (!ltn.IsTopLevel && !hideConfig)
			{
				if (sField == "Senses" && (ltn.ClassName == "LexEntry" || ltn.ClassName == "LexSense"))
				{
					ltn.ShowSenseConfig = true;
				}
				else if (sField == "ReferringSenses" && ltn.ClassName == "ReversalIndexEntry")
				{
					ltn.ShowSenseConfig = true;
				}
				if (sField == "MorphoSyntaxAnalysis" && ltn.ClassName == "LexSense")
				{
					ltn.ShowGramInfoConfig = true;
				}
				if (sField == "VisibleComplexFormBackRefs" || sField == "ComplexFormsNotSubentries")
				{
					//The existence of the attribute is important for this setting, not its value!
					var sShowAsIndentedPara = XmlUtils.GetAttributeValue(ltn.Configuration, "showasindentedpara");
					ltn.ShowComplexFormParaConfig = !String.IsNullOrEmpty(sShowAsIndentedPara);
				}
			}
			bool fRecurse = XmlUtils.GetOptionalBooleanAttributeValue(ltn.Configuration, "recurseConfig", true);
			if (!fRecurse)
			{
				// We don't want to recurse forever just because senses have subsenses, which
				// can have subsenses, which can ...
				// Or because entries have subentries (in root type layouts)...
				ltn.UseParentConfig = true;
				return;
			}
			string sLayout = XmlVc.GetLayoutName(xn, xnCaller);
			int clidDst = 0;
			string sClass = null;
			string sTargetClasses = null;
			try
			{
				// Failure should be fairly unusual, but, for example, part MoForm-Jt-FormEnvPub attempts to display
				// the property PhoneEnv inside an if that checks that the MoForm is one of the subclasses that has
				// the PhoneEnv property. MoForm itself does not.
				if (!((FDO.Infrastructure.IFwMetaDataCacheManaged)m_cache.DomainDataByFlid.MetaDataCache).FieldExists(className, sField, true))
					return;
				int flid = m_cache.DomainDataByFlid.MetaDataCache.GetFieldId(className, sField, true);
				CellarPropertyType type = (CellarPropertyType)m_cache.DomainDataByFlid.MetaDataCache.GetFieldType(flid);
				Debug.Assert(type >= CellarPropertyType.MinObj);
				if (type >= CellarPropertyType.MinObj)
				{
					sTargetClasses = XmlUtils.GetOptionalAttributeValue(xn, "targetclasses");
					clidDst = m_mdc.GetDstClsId(flid);
					if (clidDst == 0)
						sClass = XmlUtils.GetOptionalAttributeValue(xn, "targetclass");
					else
						sClass = m_mdc.GetClassName(clidDst);
					if (clidDst == StParaTags.kClassId)
					{
						string sClassT = XmlUtils.GetOptionalAttributeValue(xn, "targetclass");
						if (!String.IsNullOrEmpty(sClassT))
							sClass = sClassT;
					}
				}
			}
			catch
			{
				return;
			}
			if (clidDst == MoFormTags.kClassId && !sLayout.StartsWith("publi"))
				return;	// ignore the layouts used by the LexEntry-Jt-Headword part.
			if (String.IsNullOrEmpty(sLayout) || String.IsNullOrEmpty(sClass))
				return;
			if (sTargetClasses == null)
				sTargetClasses = sClass;
			string[] rgsClasses = sTargetClasses.Split(new[] { ',', ' ' },
				StringSplitOptions.RemoveEmptyEntries);
			XmlNode subLayout = null;
			if (rgsClasses.Length > 0)
				subLayout = m_layouts.GetElement("layout", new[] { rgsClasses[0], "jtview", sLayout, null });

			if (subLayout != null)
			{
				int iStart = ltn.Nodes.Count;
				int cNodes = subLayout.ChildNodes.Count;
				AddChildNodes(subLayout, ltn, iStart);

				bool fRepeatedConfig = XmlUtils.GetOptionalBooleanAttributeValue(xn, "repeatedConfig", false);
				if (fRepeatedConfig)
					return;		// repeats an earlier part element (probably as a result of <if>s)
				for (int i = 1; i < rgsClasses.Length; i++)
				{
					XmlNode mergedLayout = m_layouts.GetElement("layout",
						new[] { rgsClasses[i], "jtview", sLayout, null });
					if (mergedLayout != null && mergedLayout.ChildNodes.Count == cNodes)
					{
						AddChildNodes(mergedLayout, ltn, iStart);
					}
				}
			}
			else
			{
				// The "layout" in a part node can actually refer directly to another part, so check
				// for that possibility.
				var subPart = m_parts.GetElement("part", new[] { rgsClasses[0] + "-Jt-" + sLayout }) ??
							  m_parts.GetElement("part", new[] { className + "-Jt-" + sLayout });
				if (subPart == null && !sLayout.EndsWith("-en"))
				{
					// Complain if we can't find either a layout or a part, and the name isn't tagged
					// for a writing system.  (We check only for English, being lazy.)
					var msg = String.Format("Missing jtview layout for class=\"{0}\" name=\"{1}\"",
						rgsClasses[0], sLayout);
					Debug.Assert(subLayout != null, msg);
					//Debug.WriteLine(msg);
				}
			}
		}