internal static void AddPanelButton(RibbonPanel panel, LinkedScript script, LinkedScriptAssembly lsa)
 {
     if (panel.AddItem(NewScriptButton(script, lsa.FilePath)) is PushButton pushButton)
     {
         // do stuff with button?
     }
 }
        public static bool CreateUI(ScriptPkg pkg, RibbonHandler ribbon)
        {
            // --------------------------------------------------------------------
            // FIND SCRIPTS
            // --------------------------------------------------------------------
            var items = pkg.FindLinkedItems();

            // --------------------------------------------------------------------
            // CREATE ASSEMBLY
            // --------------------------------------------------------------------
            // generate assembly containing script command types
            var lsa = new LinkedScriptAssembly();

            // create types for all the scripts in the structure
            ProcessLinkedScripts(items, (script) =>
            {
                script.ScriptCommandType = lsa.MakeScriptCommandType(script);
            });

            // save and load the created assembly
            lsa.SaveAndLoad();

            // --------------------------------------------------------------------
            // CREATE UI
            // --------------------------------------------------------------------
            RibbonPanel panel;

            try { panel = ribbon.CreateAddinPanel(pkg.Name); }
            catch { return(false); }

            // Currently only supporting two levels in the UI:
            // 1) Pushbuttons on panel for every LinkedScript at the root level
            // 2) Pulldowns containing pushbuttons for all the LinkedScripts recursively found under their directory
            // Lets make the pulldowns first so they are first on the panel
            items.OfType <LinkedItemGroup>().ToList().ForEach((group) =>
            {
                var pullDownData = new PulldownButtonData(group.Name, group.Name)
                {
                    Image      = ImageBuilder.LoadRibbonButtonImage("Ribbon.Grasshopper.GhFolder.png", true),
                    LargeImage = ImageBuilder.LoadRibbonButtonImage("Ribbon.Grasshopper.GhFolder.png"),
                    ToolTip    = group.Tooltip,
                };
                if (panel.AddItem(pullDownData) is PulldownButton pulldown)
                {
                    ProcessLinkedScripts(group.Items, (script) =>
                    {
                        AddPullDownButton(pulldown, script, lsa);
                    });
                }
            });
            // now make pushbuttons
            items.OfType <LinkedScript>().ToList().ForEach((script) =>
            {
                AddPanelButton(panel, script, lsa);
            });

            return(true);
        }
 internal static void AddPullDownButton(PulldownButton pulldown, LinkedScript script, LinkedScriptAssembly lsa)
 {
     if (pulldown.AddPushButton(NewScriptButton(script, lsa.FilePath)) is PushButton pushButton)
     {
         // do stuff with button?
     }
 }