Esempio n. 1
0
        private void _pastToPanelAtSimpleRow(RibbonCommandButtonAttribute ribbAttr, CommandMethodAttribute cmdAttr, Type type, string id)
        {
            RibbonButton button = new RibbonButton();

            button.IsToolTipEnabled = true;
            button.Id               = type.FullName + id;
            button.Name             = cmdAttr.GlobalName;
            button.Orientation      = System.Windows.Controls.Orientation.Horizontal;
            button.ShowText         = true;
            button.GroupName        = ribbAttr.GroupName;
            button.CommandHandler   = new RibbonButtonCommandHandler();
            button.CommandParameter = cmdAttr.GlobalName;
            button.Size             = RibbonItemSize.Standard;
            button.Text             = ribbAttr.Name;
            button.GroupLocation    = Autodesk.Private.Windows.RibbonItemGroupLocation.Last;

            string      name  = ribbAttr.GroupName;
            RibbonPanel panel = _ribbonTab.Panels.FirstOrDefault(p => p.Source.Title == name);

            if (panel == null)
            {
                panel = new RibbonPanel();
                RibbonPanelSource source = new RibbonPanelSource();
                source.Id    = ribbAttr.GroupName + "___source_owner";
                source.Title = button.GroupName;
                panel.Source = source;
                _ribbonTab.Panels.Add(panel);
                //panel.Source.IsSlideOutPanelVisible = true;
                panel.CanToggleOrientation = true;
                panel.ResizeStyle          = RibbonResizeStyles.NeverHideText;

                //panel.CustomPanelTitleBarBackground = System.Windows.Media.Brushes.LightYellow;
            }

            RibbonItem row = panel.Source.Items.FirstOrDefault(x =>
            {
                if (x is RibbonRowPanel)
                {
                    if (((RibbonRowPanel)x).Items.Count / 2 < 3)
                    {
                        return(true);
                    }
                }
                return(false);
            });

            if (row == null)
            {
                row      = new RibbonRowPanel();
                row.Id   = panel.Source.Id + "." + type.FullName + "_row";
                row.Name = type.Name;
                panel.Source.Items.Add(row);
            }

            ((RibbonRowPanel)row).Items.Add(button);
            if (row is RibbonRowPanel)
            {
                ((RibbonRowPanel)row).Items.Add(new RibbonRowBreak());
            }
        }
Esempio n. 2
0
        private void _createAutoRibbonPanels()
        {
            string asmName = "IgorKL.ACAD3.Model.dll";
            var    asm     = LoadAssembly(asmName);

            if (asm == null)
            {
                return;
            }

            var types = asm.GetTypes();

            foreach (var t in types)
            {
                var methods = t.GetMethods(System.Reflection.BindingFlags.CreateInstance |
                                           System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);


                foreach (var mi in methods)
                {
                    object[] attrs = mi.GetCustomAttributes(typeof(CommandMethodAttribute), false);
                    foreach (CommandMethodAttribute cmdAttr in attrs)
                    {
                        var objs = mi.GetCustomAttributes(typeof(RibbonCommandButtonAttribute), false);
                        if (objs == null || objs.Length < 1)
                        {
                            continue;
                        }
                        RibbonCommandButtonAttribute ribbAttr = (RibbonCommandButtonAttribute)objs.First();

                        _pastToPanelAtSimpleRow(ribbAttr, cmdAttr, t, mi.Name);
                    }
                }
            }
        }