Пример #1
0
        /// <summary>
        /// Updates the TreeView tree nodes of the color tree.
        /// </summary>
        /// <param name="rootNode">The root node of the color tree.</param>
        /// <param name="showPlotColorsOnly">if set to <c>true</c>, the tree will show plot colors only.</param>
        /// <param name="currentSelectedObject">The current selected object. Can either be a <see cref="IColorSet"/> or a <see cref="NamedColor"/>.</param>
        /// <exception cref="System.InvalidProgramException"></exception>
        public static void UpdateColorTreeViewTreeNodes(NGTreeNode rootNode, bool showPlotColorsOnly, object currentSelectedObject)
        {
            var manager = ColorSetManager.Instance;

            var builtIn = new NGTreeNode()
            {
                Text = "Builtin", Tag = Altaxo.Main.ItemDefinitionLevel.Builtin
            };
            var app = new NGTreeNode()
            {
                Text = "Application", Tag = Altaxo.Main.ItemDefinitionLevel.Application
            };
            var user = new NGTreeNode()
            {
                Text = "User", Tag = Altaxo.Main.ItemDefinitionLevel.UserDefined
            };
            var proj = new NGTreeNode()
            {
                Text = "Project", Tag = Altaxo.Main.ItemDefinitionLevel.Project
            };

            IColorSet  parentColorSetOfColor = null;
            NamedColor selectedColor;

            if (currentSelectedObject is NamedColor)
            {
                selectedColor         = (NamedColor)currentSelectedObject;
                parentColorSetOfColor = selectedColor.ParentColorSet;
            }
            else
            {
                selectedColor = NamedColors.Black;
            }

            foreach (var set in manager.GetEntryValues())
            {
                if (showPlotColorsOnly && !set.IsPlotColorSet)
                {
                    continue;
                }

                NGTreeNode newNode;

                switch (set.Level)
                {
                case Altaxo.Main.ItemDefinitionLevel.Builtin:
                    builtIn.Nodes.Add(newNode = new NGTreeNodeForColorSet(set.List));
                    break;

                case Altaxo.Main.ItemDefinitionLevel.Application:
                    app.Nodes.Add(newNode = new NGTreeNodeForColorSet(set.List));
                    break;

                case Altaxo.Main.ItemDefinitionLevel.UserDefined:
                    user.Nodes.Add(newNode = new NGTreeNodeForColorSet(set.List));
                    break;

                case Altaxo.Main.ItemDefinitionLevel.Project:
                    proj.Nodes.Add(newNode = new NGTreeNodeForColorSet(set.List));
                    break;

                default:
                    throw new InvalidProgramException(string.Format("Unknown level {0}. Please report this error to the forum.", set.Level));
                }

                if (currentSelectedObject is IColorSet)
                {
                    bool isCurrentlySelected = object.ReferenceEquals(set, currentSelectedObject);
                    newNode.IsSelected = isCurrentlySelected;
                    if (isCurrentlySelected)
                    {
                        newNode.IsExpanded = true;
                    }
                }
                else if (parentColorSetOfColor != null && object.ReferenceEquals(set, parentColorSetOfColor))
                {
                    newNode.IsExpanded = true;

                    foreach (var node in newNode.Nodes)
                    {
                        if ((node.Tag is NamedColor) && ((NamedColor)node.Tag) == selectedColor)
                        {
                            node.IsSelected = true;
                        }
                    }
                }
            }

            rootNode.Nodes.Clear();
            rootNode.Nodes.Add(builtIn);
            rootNode.Nodes.Add(app);
            rootNode.Nodes.Add(user);
            rootNode.Nodes.Add(proj);
        }
Пример #2
0
		/// <summary>
		/// Updates the TreeView tree nodes of the color tree.
		/// </summary>
		/// <param name="rootNode">The root node of the color tree.</param>
		/// <param name="showPlotColorsOnly">if set to <c>true</c>, the tree will show plot colors only.</param>
		/// <param name="currentSelectedObject">The current selected object. Can either be a <see cref="IColorSet"/> or a <see cref="NamedColor"/>.</param>
		/// <exception cref="System.InvalidProgramException"></exception>
		public static void UpdateColorTreeViewTreeNodes(NGTreeNode rootNode, bool showPlotColorsOnly, object currentSelectedObject)
		{
			var manager = ColorSetManager.Instance;

			var builtIn = new NGTreeNode() { Text = "Builtin", Tag = Altaxo.Main.ItemDefinitionLevel.Builtin };
			var app = new NGTreeNode() { Text = "Application", Tag = Altaxo.Main.ItemDefinitionLevel.Application };
			var user = new NGTreeNode() { Text = "User", Tag = Altaxo.Main.ItemDefinitionLevel.UserDefined };
			var proj = new NGTreeNode() { Text = "Project", Tag = Altaxo.Main.ItemDefinitionLevel.Project };

			IColorSet parentColorSetOfColor = null;
			NamedColor selectedColor;
			if (currentSelectedObject is NamedColor)
			{
				selectedColor = (NamedColor)currentSelectedObject;
				parentColorSetOfColor = selectedColor.ParentColorSet;
			}
			else
			{
				selectedColor = NamedColors.Black;
			}

			foreach (var set in manager.GetEntryValues())
			{
				if (showPlotColorsOnly && !set.IsPlotColorSet)
					continue;

				NGTreeNode newNode;

				switch (set.Level)
				{
					case Altaxo.Main.ItemDefinitionLevel.Builtin:
						builtIn.Nodes.Add(newNode = new NGTreeNodeForColorSet(set.List));
						break;

					case Altaxo.Main.ItemDefinitionLevel.Application:
						app.Nodes.Add(newNode = new NGTreeNodeForColorSet(set.List));
						break;

					case Altaxo.Main.ItemDefinitionLevel.UserDefined:
						user.Nodes.Add(newNode = new NGTreeNodeForColorSet(set.List));
						break;

					case Altaxo.Main.ItemDefinitionLevel.Project:
						proj.Nodes.Add(newNode = new NGTreeNodeForColorSet(set.List));
						break;

					default:
						throw new InvalidProgramException(string.Format("Unknown level {0}. Please report this error to the forum.", set.Level));
				}

				if (currentSelectedObject is IColorSet)
				{
					bool isCurrentlySelected = object.ReferenceEquals(set, currentSelectedObject);
					newNode.IsSelected = isCurrentlySelected;
					if (isCurrentlySelected)
						newNode.IsExpanded = true;
				}
				else if (parentColorSetOfColor != null && object.ReferenceEquals(set, parentColorSetOfColor))
				{
					newNode.IsExpanded = true;

					foreach (var node in newNode.Nodes)
					{
						if ((node.Tag is NamedColor) && ((NamedColor)node.Tag) == selectedColor)
							node.IsSelected = true;
					}
				}
			}

			rootNode.Nodes.Clear();
			rootNode.Nodes.Add(builtIn);
			rootNode.Nodes.Add(app);
			rootNode.Nodes.Add(user);
			rootNode.Nodes.Add(proj);
		}