/// <summary>
        /// Gets the service and device class names for
        /// the checked nodes in the tree.
        /// </summary>
        /// <param name="services">The dictionary to contain the ClassNames, and Services.</param>
        /// <param name="devices">The dictionary to contain the ClassNames, and Devices.</param>
        /// <param name="nodes">The nodes to add the service and device class names for.</param>
        private void GetServiceDeviceClassNames(
            Dictionary <string, Service> services,
            Dictionary <string, Device> devices,
            TreeNodeCollection nodes)
        {
            foreach (TreeNode lnNode in nodes)
            {
                if (lnNode.Checked)
                {
                    IUPnPTreeItem liItem = (IUPnPTreeItem)(lnNode.Tag);

                    if (liItem is UPnPServiceTreeItem)
                    {
                        services[liItem.VisibleItemText] = (Service)(liItem.LinkedObject);
                    }

                    if (liItem is UPnPDeviceTreeItem)
                    {
                        devices[liItem.VisibleItemText] = (Device)(liItem.LinkedObject);
                    }
                }
            }

            foreach (TreeNode lnNode in nodes)
            {
                GetServiceDeviceClassNames(services, devices, lnNode.Nodes);
            }
        }
 /// <summary>
 /// Handles when the user changes a label in the treeview.
 /// </summary>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="e">The event arguments.</param>
 private void tbSelection_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
 {
     if (!e.CancelEdit && e.Label != null)
     {
         IUPnPTreeItem liItem = (IUPnPTreeItem)(e.Node.Tag);
         liItem.VisibleItemText = e.Label;
         tbSelection.UpdateNode(e.Node);
     }
 }
Пример #3
0
        /// <summary>
        /// Adds a UPnP tree item to the tree view.
        /// </summary>
        /// <param name="nodes">The nodes collection to add the item to.</param>
        /// <param name="item">The item to add.</param>
        /// <returns>The new tree node containing the item.</returns>
        protected TreeNode AddUPnPItem(TreeNodeCollection nodes, IUPnPTreeItem item)
        {
            TreeNode ltnNode = nodes.Add(item.ItemKey, item.VisibleItemText);

            // Get custom icon
            Image liImage = item.ItemIcon;
            int   liIndex = 0;

            // If custom icon is available
            if (liImage != null)
            {
                // Then use its index
                liIndex = ilIcons.Images.Add(liImage, Color.White);
            }
            else
            {
                // Otherwise, set the index based on its type
                if (item is UPnPDeviceTreeItem)
                {
                    liIndex = miDeviceImage;
                }
                if (item is UPnPServiceTreeItem)
                {
                    liIndex = miServiceImage;
                }
                if (item is UPnPStateVarTreeItem)
                {
                    liIndex = miStateVarImage;
                }
                if (item is UPnPActionTreeItem)
                {
                    liIndex = miActionImage;
                }
            }

            // Set the image indexes
            ltnNode.ImageIndex         = liIndex;
            ltnNode.SelectedImageIndex = liIndex;
            ltnNode.StateImageIndex    = liIndex;

            // Set the tag
            ltnNode.Tag = item;

            // Return the node
            return(ltnNode);
        }
Пример #4
0
        /// <summary>
        /// Occurs after an item in the UPnP browser tree view is selected.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">The event arguments.</param>
        private void tvUPnP_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // Get the selection tree item.
            IUPnPTreeItem liItem = tvUPnP.SelectedItem;

            // Save the currently showed control
            ctlUPnPInfo liPrev = miInfo;

            // Default to no new control
            miInfo = null;

            try
            {
                // If the new item is available
                if (liItem != null)
                {
                    // Get the control
                    miInfo = liItem.InfoControl;

                    // If the control is available
                    if (miInfo != null)
                    {
                        // Dock it and add it
                        miInfo.Dock = DockStyle.Fill;
                        pnlInfo.Controls.Add(miInfo);
                    }
                }
            }
            finally
            {
                // If the old control was available
                if (liPrev != null)
                {
                    // Remove it and dispose it
                    pnlInfo.Controls.Remove(liPrev);
                    liPrev.Dispose();
                }
            }
        }
        /// <summary>
        /// Defaults all the values for the nodes including class names.
        /// </summary>
        /// <param name="nodes">The nodes to default.</param>
        private void DefaultNodes(TreeNodeCollection nodes)
        {
            foreach (TreeNode lnNode in nodes)
            {
                IUPnPTreeItem liItem = (IUPnPTreeItem)(lnNode.Tag);

                if (liItem.LinkedObject is Service)
                {
                    liItem.VisibleItemText = ((Service)(liItem.LinkedObject)).DefaultCodeGenClassName(CodeGenProvider);
                }

                if (liItem.LinkedObject is Device)
                {
                    liItem.VisibleItemText = ((Device)(liItem.LinkedObject)).DefaultCodeGenClassName(CodeGenProvider);
                }

                tbSelection.UpdateNode(lnNode);
                lnNode.Checked = true;

                DefaultNodes(lnNode.Nodes);
            }
        }
Пример #6
0
        /// <summary>
        /// Updates a nodes details from its item.
        /// </summary>
        /// <param name="node">The node to update.</param>
        public void UpdateNode(TreeNode node)
        {
            IUPnPTreeItem liItem = (IUPnPTreeItem)(node.Tag);

            node.Text = liItem.VisibleItemText;
        }
        /// <summary>
        /// Adds a UPnP tree item to the tree view.
        /// </summary>
        /// <param name="nodes">The nodes collection to add the item to.</param>
        /// <param name="item">The item to add.</param>
        /// <returns>The new tree node containing the item.</returns>
        protected TreeNode AddUPnPItem(TreeNodeCollection nodes, IUPnPTreeItem item)
        {
            TreeNode ltnNode = nodes.Add(item.ItemKey, item.VisibleItemText);

            // Get custom icon
            Image liImage = item.ItemIcon;
            int liIndex = 0;

            // If custom icon is available
            if (liImage != null)
                // Then use its index
                liIndex = ilIcons.Images.Add(liImage, Color.White);
            else
            {
                // Otherwise, set the index based on its type
                if (item is UPnPDeviceTreeItem) liIndex = miDeviceImage;
                if (item is UPnPServiceTreeItem) liIndex = miServiceImage;
                if (item is UPnPStateVarTreeItem) liIndex = miStateVarImage;
                if (item is UPnPActionTreeItem) liIndex = miActionImage;
            }

            // Set the image indexes
            ltnNode.ImageIndex = liIndex;
            ltnNode.SelectedImageIndex = liIndex;
            ltnNode.StateImageIndex = liIndex;

            // Set the tag
            ltnNode.Tag = item;

            // Return the node
            return ltnNode;
        }