Ejemplo n.º 1
0
        public static void onCreateFolder(Object sender, ClickEventArgs e)
        {
            NlmTreeListView listView = e.ListView;

            // Calculate unique name in current level.
            IEnumerable <FolderTreeNode> folderNodes = listView.NodeControl.Query.FolderNodes;

            String folderName = "Folder";
            Int32  index      = 1;

            while (folderNodes.Any(x => x.Name == folderName + index.ToString("000")))
            {
                index += 1;
            }
            folderName += index.ToString("000");

            // Create folder node.
            FolderTreeNode folderTreeNode = new FolderTreeNode(folderName);

            // Get parent node.
            BaseTreeNode parentTreeNode = null;

            if (listView.SelectedObjects.Count > 0)
            {
                BaseTreeNode treeNode = listView.SelectedObjects[0] as BaseTreeNode;
                if (treeNode is FolderTreeNode)
                {
                    parentTreeNode = treeNode;
                }
                if (treeNode is LayerTreeNode)
                {
                    parentTreeNode = treeNode.Parent;
                }
            }

            // Add folder to listview, ensure is visible by expanding parents.
            listView.AddObject(folderTreeNode, parentTreeNode);
            if (parentTreeNode != null)
            {
                listView.Expand(parentTreeNode);
            }

            // Scroll to new item.
            Int32 parentIndex = listView.IndexOf(folderTreeNode);

            if (parentIndex != -1)
            {
                listView.EnsureVisible(parentIndex);
            }

            // Sort, select, and begin edit.
            listView.Sort(listView.NlmColumns.NameColumn, SortOrder.Ascending);
            listView.SelectedObjects = new List <Object> {
                folderTreeNode
            };
            listView.EditModel(folderTreeNode);
        }
Ejemplo n.º 2
0
        private static void onCreateLayer(Object sender, ClickEventArgs e, Boolean addSelection)
        {
            NlmTreeListView listView = e.ListView;

            listView.NodeControl.MaxEvents.LayerEvents.LayerCreated.UnregisterNotification();

            IILayer layer  = MaxLayers.CreateLayer(true, addSelection);
            UIntPtr handle = MaxAnimatable.GetHandleByAnim(layer);

            LayerTreeNode layerTreeNode = new LayerTreeNode(handle, listView.NodeControl.HandleMap);

            // Get parent node.
            BaseTreeNode parentTreeNode = null;

            if (listView.SelectedObjects.Count > 0)
            {
                BaseTreeNode treeNode = listView.SelectedObjects[0] as BaseTreeNode;
                if (treeNode is FolderTreeNode)
                {
                    parentTreeNode = treeNode;
                }
                if (treeNode is LayerTreeNode)
                {
                    parentTreeNode = treeNode.Parent;
                }
            }

            // Add folder to listview, ensure is visible by expanding parents.
            listView.AddObject(layerTreeNode, parentTreeNode);
            if (parentTreeNode != null)
            {
                listView.Expand(parentTreeNode);
            }

            // Scroll to new item.
            Int32 parentIndex = listView.IndexOf(layerTreeNode);

            if (parentIndex != -1)
            {
                listView.EnsureVisible(parentIndex);
            }

            // Sort, select
            listView.Sort(listView.NlmColumns.NameColumn, SortOrder.Ascending);
            listView.SelectedObjects = new List <Object> {
                layerTreeNode
            };

            // Focus on the listview to ensure text entry goes to the edit box, and begin edit.
            listView.Focus();
            listView.EditModel(layerTreeNode);

            // Register notification.
            listView.NodeControl.MaxEvents.LayerEvents.LayerCreated.RegisterNotification();
        }
Ejemplo n.º 3
0
        public static void onInstanceSelectedLayers(Object sender, ClickEventArgs e)
        {
            NlmTreeListView listView = e.ListView;

            // Multiple items are being added, so let's use BeginUpdate.
            try
            {
                listView.BeginUpdate();

                foreach (BaseTreeNode treeNode in listView.SelectedObjects)
                {
                    LayerTreeNode layerTreeNode = treeNode as LayerTreeNode;
                    if (layerTreeNode != null)
                    {
                        LayerTreeNode newLayerTreeNode = new LayerTreeNode(layerTreeNode.Handle, listView.NodeControl.HandleMap);

                        foreach (ObjectTreeNode objectTreeNode in treeNode.Children)
                        {
                            ObjectTreeNode newObjectTreeNode = new ObjectTreeNode(objectTreeNode.Class, objectTreeNode.Handle, listView.NodeControl.HandleMap);
                            newObjectTreeNode.Parent = newLayerTreeNode;
                            newLayerTreeNode.Children.Add(newObjectTreeNode);
                        }

                        //foreach (LayerTreeNode instanceNode in layerTreeNode.Instances)
                        //{
                        //    instanceNode.Instances.Add(newLayerTreeNode);
                        //    newLayerTreeNode.Instances.Add(instanceNode);
                        //}
                        //layerTreeNode.Instances.Add(newLayerTreeNode);
                        //newLayerTreeNode.Instances.Add(layerTreeNode);

                        listView.AddObject(newLayerTreeNode, treeNode.Parent);
                    }
                }

                listView.Sort(listView.NlmColumns.NameColumn, SortOrder.Ascending);
            }
            catch
            {
                throw new Exception();
            }
            finally
            {
                listView.EndUpdate();
            }
        }