예제 #1
0
        // Заполнение списка функций
        private void FillFunctions()
        {
            try
            {
                var confCuiXel = ModPlusAPI.RegistryData.Adaptation.GetCuiAsXElement("AutoCAD");

                // Проходим по группам
                if (confCuiXel == null)
                {
                    return;
                }

                foreach (var group in confCuiXel.Elements("Group"))
                {
                    var exp = new Expander
                    {
                        Header     = ModPlusAPI.Language.TryGetCuiLocalGroupName(group.Attribute("GroupName")?.Value),
                        IsExpanded = false,
                        Margin     = new Thickness(1)
                    };
                    var grid = new Grid {
                        HorizontalAlignment = HorizontalAlignment.Stretch
                    };
                    var index = 0;

                    // Проходим по функциям группы
                    foreach (var func in group.Elements("Function"))
                    {
                        var funcNameAttr = func.Attribute("Name")?.Value;
                        if (string.IsNullOrEmpty(funcNameAttr))
                        {
                            continue;
                        }

                        var loadedFunction =
                            LoadPluginsHelper.LoadedFunctions.FirstOrDefault(x => x.Name.Equals(funcNameAttr));
                        if (loadedFunction == null)
                        {
                            continue;
                        }
                        grid.RowDefinitions.Add(new RowDefinition {
                            Height = GridLength.Auto
                        });
                        var btn = WPFMenuHelper.AddButton(
                            this,
                            loadedFunction.Name,
                            ModPlusAPI.Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.LName),
                            loadedFunction.BigIconUrl,
                            ModPlusAPI.Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.Description),
                            ModPlusAPI.Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.FullDescription),
                            loadedFunction.ToolTipHelpImage, false);

                        btn.SetValue(Grid.RowProperty, index);
                        grid.Children.Add(btn);

                        index++;

                        if (loadedFunction.SubPluginsNames.Any())
                        {
                            for (int i = 0; i < loadedFunction.SubPluginsNames.Count; i++)
                            {
                                btn = WPFMenuHelper.AddButton(
                                    this,
                                    loadedFunction.SubPluginsNames[i],
                                    ModPlusAPI.Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.SubPluginsNames[i], i + 1),
                                    loadedFunction.SubBigIconsUrl[i],
                                    ModPlusAPI.Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.SubDescriptions[i], i + 1),
                                    ModPlusAPI.Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.SubFullDescriptions[i], i + 1),
                                    loadedFunction.SubHelpImages[i], false);
                                grid.RowDefinitions.Add(new RowDefinition {
                                    Height = GridLength.Auto
                                });
                                btn.SetValue(Grid.RowProperty, index);
                                grid.Children.Add(btn);
                                index++;
                            }
                        }

                        foreach (var subFunc in func.Elements("SubFunction"))
                        {
                            var subFuncNameAttr = subFunc.Attribute("Name")?.Value;
                            if (string.IsNullOrEmpty(subFuncNameAttr))
                            {
                                continue;
                            }
                            var loadedSubFunction =
                                LoadPluginsHelper.LoadedFunctions.FirstOrDefault(x => x.Name.Equals(subFuncNameAttr));
                            if (loadedSubFunction == null)
                            {
                                continue;
                            }
                            btn = WPFMenuHelper.AddButton(
                                this,
                                loadedSubFunction.Name,
                                ModPlusAPI.Language.GetFunctionLocalName(loadedSubFunction.Name, loadedSubFunction.LName),
                                loadedSubFunction.BigIconUrl,
                                ModPlusAPI.Language.GetFunctionShortDescription(loadedSubFunction.Name, loadedSubFunction.Description),
                                ModPlusAPI.Language.GetFunctionFullDescription(loadedSubFunction.Name, loadedSubFunction.FullDescription),
                                loadedSubFunction.ToolTipHelpImage, false);
                            grid.RowDefinitions.Add(new RowDefinition {
                                Height = GridLength.Auto
                            });
                            btn.SetValue(Grid.RowProperty, index);
                            grid.Children.Add(btn);
                            index++;
                        }
                    }

                    exp.Content = grid;

                    // Добавляем группу, если заполнились функции!
                    if (grid.Children.Count > 0)
                    {
                        FunctionsPanel.Children.Add(exp);
                    }
                }
            }
            catch (Exception exception)
            {
                ExceptionBox.Show(exception);
            }
        }
        // Заполнение списка функций
        private void FillFunctions()
        {
            try
            {
                var confCuiXel = ModPlusAPI.RegistryData.Adaptation.GetCuiAsXElement("AutoCAD");

                // Проходим по группам
                if (confCuiXel == null)
                {
                    return;
                }
                foreach (var group in confCuiXel.Elements("Group"))
                {
                    var exp = new Expander
                    {
                        Header     = ModPlusAPI.Language.TryGetCuiLocalGroupName(group.Attribute("GroupName")?.Value),
                        IsExpanded = false,
                        Margin     = new Thickness(1)
                    };

                    var expStck = new StackPanel {
                        Orientation = Orientation.Vertical
                    };

                    // Проходим по функциям группы
                    foreach (var func in group.Elements("Function"))
                    {
                        var funcNameAttr = func.Attribute("Name")?.Value;
                        if (string.IsNullOrEmpty(funcNameAttr))
                        {
                            continue;
                        }

                        var loadedFunction = LoadPluginsHelper.LoadedFunctions.FirstOrDefault(x => x.Name.Equals(funcNameAttr));
                        if (loadedFunction == null)
                        {
                            continue;
                        }

                        expStck.Children.Add(
                            WPFMenuHelper.AddButton(
                                this,
                                loadedFunction.Name,
                                ModPlusAPI.Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.LName),
                                loadedFunction.BigIconUrl,
                                ModPlusAPI.Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.Description),
                                ModPlusAPI.Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.FullDescription),
                                loadedFunction.ToolTipHelpImage, true));
                        if (loadedFunction.SubPluginsNames.Any())
                        {
                            for (int i = 0; i < loadedFunction.SubPluginsNames.Count; i++)
                            {
                                expStck.Children.Add(WPFMenuHelper.AddButton(
                                                         this,
                                                         loadedFunction.SubPluginsNames[i],
                                                         ModPlusAPI.Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.SubPluginsLNames[i], i + 1),
                                                         loadedFunction.SubBigIconsUrl[i],
                                                         ModPlusAPI.Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.SubDescriptions[i], i + 1),
                                                         ModPlusAPI.Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.SubFullDescriptions[i], i + 1),
                                                         loadedFunction.SubHelpImages[i], true));
                            }
                        }

                        foreach (var subFunc in func.Elements("SubFunction"))
                        {
                            var subFuncNameAttr = subFunc.Attribute("Name")?.Value;
                            if (string.IsNullOrEmpty(subFuncNameAttr))
                            {
                                continue;
                            }
                            var loadedSubFunction = LoadPluginsHelper.LoadedFunctions.FirstOrDefault(x => x.Name.Equals(subFuncNameAttr));
                            if (loadedSubFunction == null)
                            {
                                continue;
                            }
                            expStck.Children.Add(
                                WPFMenuHelper.AddButton(
                                    this,
                                    loadedSubFunction.Name,
                                    ModPlusAPI.Language.GetFunctionLocalName(loadedSubFunction.Name, loadedSubFunction.LName),
                                    loadedSubFunction.BigIconUrl,
                                    ModPlusAPI.Language.GetFunctionShortDescription(loadedSubFunction.Name, loadedSubFunction.Description),
                                    ModPlusAPI.Language.GetFunctionFullDescription(loadedSubFunction.Name, loadedSubFunction.FullDescription),
                                    loadedSubFunction.ToolTipHelpImage, true));
                        }
                    }

                    exp.Content = expStck;

                    // Добавляем группу, если заполнились функции!
                    if (expStck.Children.Count > 0)
                    {
                        FunctionsPanel.Children.Add(exp);
                    }
                }
            }
            catch (Exception exception)
            {
                ExceptionBox.Show(exception);
            }
        }