Beispiel #1
0
        /// <summary>
        /// Loads ribbon xml from the specified string.
        /// </summary>
        public void LoadXml(string xml)
        {
            _tabs.Clear();

            var xmlns     = "http://github.com/SolidEdgeCommunity/SolidEdge/Ribbon";
            var xDocument = XDocument.Parse(xml);
            var xTab      = XName.Get("tab", xmlns);
            var xGroup    = XName.Get("group", xmlns);

            foreach (var tab in xDocument.Root.Descendants(xTab))
            {
                var tabId     = tab.Attribute("name");
                var ribbonTab = AddTab(tabId.Value);

                foreach (var group in tab.Descendants(xGroup))
                {
                    var groupId     = group.Attribute("name");
                    var ribbonGroup = ribbonTab.AddGroup(groupId.Value);

                    foreach (var control in group.Descendants())
                    {
                        var controlType            = control.Name.LocalName;
                        var controlId              = control.Attribute("id");
                        var controlLabel           = control.Attribute("label");
                        var controlDropDownGroup   = control.Attribute("dropDownGroup");
                        var controlScreentip       = control.Attribute("screentip");
                        var controlSupertip        = control.Attribute("supertip");
                        var controlImageId         = control.Attribute("imageId");
                        var controlEnabled         = control.Attribute("enabled");
                        var controlMacro           = control.Attribute("macro");
                        var controlMacroParameters = control.Attribute("macroParameters");
                        var controlShowImage       = control.Attribute("showImage");
                        var controlShowLabel       = control.Attribute("showLabel");
                        var controlWebHelpUrl      = control.Attribute("webHelpUrl");

                        RibbonControl ribbonControl = null;
                        int           commandId     = -1;

                        if (int.TryParse(controlId.Value, out commandId))
                        {
                            if (controlType.Equals("button", StringComparison.OrdinalIgnoreCase))
                            {
                                var ribbonButton = new RibbonButton(commandId);
                                var buttonSize   = control.Attribute("size");

                                if (buttonSize != null)
                                {
                                    ribbonButton.TryParseSize(buttonSize.Value);
                                }

                                if (controlDropDownGroup != null)
                                {
                                    ribbonButton.DropDownGroup = controlDropDownGroup.Value;
                                }

                                ribbonControl = ribbonButton;
                            }
                            else if (controlType.Equals("checkBox", StringComparison.OrdinalIgnoreCase))
                            {
                                var ribbonCheckBox = new RibbonCheckBox(commandId);
                                ribbonControl = ribbonCheckBox;
                            }
                            else if (controlType.Equals("radioButton", StringComparison.OrdinalIgnoreCase))
                            {
                                var ribbonRadioButton = new RibbonRadioButton(commandId);
                                ribbonControl = ribbonRadioButton;
                            }

                            if (ribbonControl != null)
                            {
                                //ribbonControl.Name = controlName.Value;
                                ribbonControl.Label     = controlLabel.Value;
                                ribbonControl.ScreenTip = controlScreentip.Value;
                                ribbonControl.SuperTip  = controlSupertip.Value;

                                if (controlMacro != null)
                                {
                                    ribbonControl.Macro = controlMacro.Value;
                                }

                                if (controlMacroParameters != null)
                                {
                                    ribbonControl.MacroParameters = controlMacroParameters.Value;
                                }

                                if (controlImageId != null)
                                {
                                    ribbonControl.TryParseImageId(controlImageId.Value);
                                }

                                if (controlEnabled != null)
                                {
                                    ribbonControl.TryParseEnabled(controlEnabled.Value);
                                }

                                if (controlShowImage != null)
                                {
                                    ribbonControl.TryParseShowImage(controlShowImage.Value);
                                }

                                if (controlShowLabel != null)
                                {
                                    ribbonControl.TryParseShowLabel(controlShowLabel.Value);
                                }

                                if (controlWebHelpUrl != null)
                                {
                                    ribbonControl.WebHelpURL = controlWebHelpUrl.Value;
                                }

                                ribbonGroup.AddControl(ribbonControl);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
 public void AddControl(RibbonControl control)
 {
     control.Group = this;
     _controls.Add(control);
 }
Beispiel #3
0
 /// <summary>
 /// Called when a user clicks a ribbon control.
 /// </summary>
 /// <param name="control"></param>
 public virtual void OnControlClick(RibbonControl control)
 {
 }