Example #1
0
        private void AddContextMenuItems(ILayer addedLayer)
        {
            IMapGroup grp = addedLayer as IMapGroup;
            if (grp != null)
            {
                // map.layerAdded event doesn't fire for groups. Therefore, it's necessary
                // to handle this event separately for groups.
                grp.LayerAdded += Map_LayerAdded;
            }

            if (addedLayer.ContextMenuItems.Exists(item => item.Name == contextMenuItemName))
            {
                // assume menu item already exists. Do nothing.
                return;
            }

            // add context menu item.
            var menuItem = new SymbologyMenuItem(contextMenuItemName, delegate { ShowAttributes(addedLayer as IFeatureLayer); });
            menuItem.Image = Resources.table_16x16;
            var cmi = addedLayer.ContextMenuItems;
            if (cmi.Count > 2)
            {
                addedLayer.ContextMenuItems.Insert(2, menuItem);
            }
            else
            {
                addedLayer.ContextMenuItems.Add(menuItem);
            }
       }
Example #2
0
        private void SerializationManagerDeserializing(object sender, SerializingEventArgs e)
        {
            // context menu items are added to layers when opening a project
            // this call is necessary because the LayerAdded event doesn't fire when a project is opened.
            foreach (ILayer layer in App.Map.MapFrame.GetAllLayers())
            {
                IFeatureLayer fl = layer as IFeatureLayer;
                if (fl != null)
                {
                    if (!fl.ContextMenuItems.Exists(item => item.Name == Resources.AttributeTableEditor))
                    {
                        // add context menu item.
                        var menuItem = new SymbologyMenuItem(Resources.AttributeTableEditor, (o, args) => ShowAttributes(fl))
                        {
                            Image = Resources.table_16x16
                        };
                        fl.ContextMenuItems.Insert(2, menuItem);
                    }
                }
            }

            // attach layer added events to existing groups
            foreach (IMapGroup grp in App.Map.MapFrame.GetAllGroups())
            {
                grp.LayerAdded += MapLayerAdded;
            }
        }
Example #3
0
        private void AddContextMenuItems(ILayer addedLayer)
        {
            if (addedLayer is null)
            {
                return;
            }

            if (addedLayer is IMapGroup grp)
            {
                // map.layerAdded event doesn't fire for groups. Therefore, it's necessary
                // to handle this event separately for groups.
                grp.LayerAdded += MapLayerAdded;

                foreach (ILayer layer in grp.Layers)
                {
                    AddContextMenuItems(layer);
                }
            }
            else if (addedLayer is IFeatureLayer fl)
            {
                if (addedLayer.ContextMenuItems.Exists(item => item.Name == Resources.AttributeTableEditor))
                {
                    // assume menu item already exists. Do nothing.
                    return;
                }

                // add context menu item.
                var menuItem = new SymbologyMenuItem(Resources.AttributeTableEditor, (sender, args) => ShowAttributes(fl))
                {
                    Image = Resources.table_16x16
                };
                addedLayer.ContextMenuItems.Insert(0, menuItem);
            }
        }
Example #4
0
        /// <summary>
        /// Add sub-menu item into parent menu item.
        /// </summary>
        /// <param name="parent">Parent menu item.</param>
        /// <param name="menuItemName">Menu item to add.</param>
        /// <param name="handler">Click event handler.</param>
        public static void AddMenuItem(this SymbologyMenuItem parent, string menuItemName, EventHandler handler)
        {
            if (parent.MenuItems.Exists(item => item.Name == menuItemName))
            {
                return;
            }
            var menuItem = new SymbologyMenuItem(menuItemName, handler);

            parent.MenuItems.Add(menuItem);
        }
Example #5
0
        /// <summary>
        /// Recursive add method to handle nesting of menu items.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="mi"></param>
        private static void AddMenuItem(Menu.MenuItemCollection parent, SymbologyMenuItem mi)
        {
            MenuItem m;

            if (mi.Icon != null)
            {
                m = new IconMenuItem(mi.Name, mi.Icon, mi.ClickHandler);
            }
            else if (mi.Image != null)
            {
                m = new IconMenuItem(mi.Name, mi.Image, mi.ClickHandler);
            }
            else
            {
                m = new IconMenuItem(mi.Name, mi.ClickHandler);
            }

            parent.Add(m);
            foreach (SymbologyMenuItem child in mi.MenuItems)
            {
                AddMenuItem(m.MenuItems, child);
            }
        }
Example #6
0
 private void SerializationManager_Deserializing(object sender, SerializingEventArgs e)
 {
     // context menu items are added to layers when opening a project
     // this call is necessary because the LayerAdded event doesn't fire when a project is opened.
     foreach (ILayer layer in App.Map.MapFrame.GetAllLayers())
     {
         IFeatureLayer fl = layer as IFeatureLayer;
         if (fl != null)
         {
             if (!fl.ContextMenuItems.Exists(item => item.Name == contextMenuItemName))
             {
                 // add context menu item.
                 var menuItem = new SymbologyMenuItem(contextMenuItemName, delegate { ShowAttributes(fl); });
                 menuItem.Image = Resources.CatalogShowTree16;
                 fl.ContextMenuItems.Insert(2, menuItem);
             }
         }
     }
     //attach layer added events to existing groups
     foreach (IGroup grp in App.Map.MapFrame.GetAllGroups())
     {
         grp.LayerAdded += Map_LayerAdded;
     }
 }
Example #7
0
        /// <summary>
        /// Recursive add method to handle nesting of menu items.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="mi"></param>
        private void AddMenuItem(System.Windows.Forms.Menu.MenuItemCollection parent, SymbologyMenuItem mi)
        {
            MenuItem m;

            //if (mi.Icon != null)
            //{
            //    m = new IconMenuItem(mi.Name, mi.Icon, mi.ClickHandler);
            //}
            //else if (mi.Image != null)
            //{
            //    m = new IconMenuItem(mi.Name, mi.Image, mi.ClickHandler);
            //}
            //else
            //{
            //    m = new IconMenuItem(mi.Name, mi.ClickHandler);
            //}

            m = new IconMenuItem(mi.Name, mi.ClickHandler);

            parent.Add(m);
            foreach (SymbologyMenuItem child in mi.MenuItems)
            {
                AddMenuItem(m.MenuItems, child);
            }
        }