Пример #1
0
        public void TestOrderInRibbonXml()
        {
            var _startMeasureCommand = new ToggleButtonCommand();
            var callbacks            = new CallbackRegsMock();
            var builder = new RibbonBuilder()
            {
                CallbackRegister = callbacks
            };

            builder.CustomUi.Ribbon.Tabs(ts => ts.AddTab("测量管理工具")
                                         .Groups(g => g.AddGroup("测量管理工具")
                                                 .Items(items => {
                //<toggleButton id="Id_StartMeasuring" description="开始测量" getLabel="GetLabel" getPressed = "GetPressed" size = "large" onAction = "OnToggleButtonAction" getImage = "GetImage" getEnabled = "GetEnabled" />
                items.AddToggleButton("开始测量").LargeSize().Callback(_startMeasureCommand);
                items.AddSeparator();
                items.AddCheckbox("跟踪测量单元格")
                .Supertip("如果选中此项,在测量时会选中正在进行的 测量数据单元格,用来指示当前测量的位置")
                .Callback(chk => chk.GetChecked(() => true).OnChecked(b => Console.WriteLine("跟踪测量单元格" + b)));
                //<toggleButton id="Id_SpeechValue" imageMso="SpeakCells" label = "语音报读" supertip = "选中此项,会朗读测量读数,需要系统语音支持" onAction = "OnToggleButtonAction"getPressed = "GetPressed" />
                items.AddToggleButton("语音报读").Supertip("选中此项,会朗读测量读数,需要系统语音支持").Callback(t => t.OnPressed((b) => Console.WriteLine(t.ControlId + " " + b)));
                //button id="SetMeasureValuesRange" label="测量数据区域" imageMso="ImportSharePointList" supertip = "设置当前工作表的数据采集区域" onAction = "OnButtonAction" getEnabled = "GetEnabled" />
                items.AddButton("测量数据区域").ImageMso("ImportSharePointList").Supertip("设置当前工作表的数据采集区域")
                .Callback(t => t.OnAction(() => Console.WriteLine($"{t.ControlId} Action")));
            }
                                                        )));
            Console.WriteLine(builder.GetXmlString());
            TestCallback(callbacks.Commands);
        }
Пример #2
0
        /// <summary>
        /// Создание палитры и показ
        /// </summary>
        public static void Start(Guid paletteGuid)
        {
            try
            {
                var paletteUserGroup = _paletteSets.FirstOrDefault(p => p.Guid.Equals(paletteGuid));
                if (paletteUserGroup == null)
                {
                    return;
                }
                if (paletteUserGroup.Palette == null)
                {
                    paletteUserGroup.Palette = new PaletteSetCommands(paletteUserGroup.Name, paletteUserGroup.Guid,
                                                                      paletteUserGroup.CommandStartPalette, paletteUserGroup.Commands, paletteUserGroup.VersionPalette);
                }

                paletteUserGroup.Palette.Visible = true;
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex, "PaletteSetCommands.Start().");
            }

            try
            {
                // Построение ленты (бывает автоматом не создается при старте)
                RibbonBuilder.CreateRibbon();
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex, "Start CreateRibbon.");
            }
        }
Пример #3
0
        private void BuildUi(RibbonBuilder builder)
        {
            builder.CustomUi.AddNamespace("acme", "acme.addin.sync").Ribbon.Tabs(c => {
                c.AddTab("My Tab").IdQ("acme", MyTabId)
                .Groups(g => {
                    g.AddGroup("Data").IdQ("acme", DataGroupId)
                    .Items(d => {
                        d.AddButton("My Save").IdMso("FileSave")
                        .NormalSize().ImageMso("FileSave");
                        d.AddButton("Button").Id("buttonOne");
                        d.AddComboBox("numbers")
                        .Id(BookmarksComboId)
                        .ShowLabel().NoImage()
                        .DynamicItems();

                        d.AddDropDown("With Image")
                        .Id(BookmarksDropDownId)
                        .ShowLabel().NoImage()
                        .ShowItemLabel().ShowItemImage().DynamicItems()
                        .Buttons(b => b.AddButton("Button...").Id(ButtonMore));
                        d.AddToggleButton("Toggle Button")
                        .Id(ToggleButtonId);
                    });
                });
            });
        }
Пример #4
0
        /// <summary>
        /// Создание палитры и показ
        /// </summary>
        public static void Start()
        {
            try
            {
                if (_paletteSets == null)
                {
                    _paletteSets = LoadPaletteGroup();
                }

                if (_paletteSets.Palette == null)
                {
                    _paletteSets.Palette = new PaletteSetCommands(_paletteSets.Name, _paletteSets.Guid,
                                                                  _paletteSets.CommandStartPalette, _paletteSets.Commands);
                }

                _paletteSets.Palette.Visible = true;
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex, "PaletteSetCommands.Start().");
            }

            try
            {
                // Построение ленты (бывает автоматом не создается при старте)
                RibbonBuilder.CreateRibbon();
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex, "Start CreateRibbon.");
            }
        }
        public string GetRibbonXml()
        {
            RibbonBuilder builder;

            if (ExcelDnaUtil.ExcelVersion >= 14.0)
            {
                builder = new RibbonBuilder(NamespaceCustomUI2010)
                {
                    CallbackRegister = _callbackRegister
                };
                CreateFluentRibbon(builder);
            }

            if (ExcelDnaUtil.ExcelVersion < 12.0)
            {
                throw new InvalidOperationException("Not expected to provide CustomUI string for Excel version < 12.0");
            }
            else
            {
                builder = new RibbonBuilder(NamespaceCustomUI2007)
                {
                    CallbackRegister = _callbackRegister
                };
                CreateFluentRibbon(builder);
            }

            return(builder.GetXmlString());
        }
Пример #6
0
 public override ICommand GetCommand()
 {
     return(new RelayCommand(() =>
     {
         Execute();
         RibbonBuilder.ChangeToggleState(Command);
     }));
 }
Пример #7
0
        public void TestAddControl()
        {
            var builder = new RibbonBuilder();

            builder.CustomUi.Ribbon.Tabs(t => t.AddTab("table")
                                         .Groups(g => g.AddGroup("group1").Items(gc => gc.AddButton("测试"))
                                                 )
                                         );
        }
Пример #8
0
        private IRibbonBuilder BuildInGroup(Action <IGroupControls> buildAction)
        {
            var builder = new RibbonBuilder();

            builder.CustomUi.Ribbon.Tabs(
                c => c.AddTab("test").Id("item1")
                .Groups(g1 => g1.AddGroup("group").Id("id")
                        .Items(buildAction)));
            return(builder);
        }
Пример #9
0
 private static void RibbonOnBackgroundRenderFinished(object sender, EventArgs e)
 {
     if (ModPlusAPI.Variables.Ribbon)
     {
         RibbonBuilder.BuildRibbon();
     }
     else
     {
         RibbonBuilder.RemoveRibbon();
     }
 }
Пример #10
0
        public PaletteModel([NotNull] IEnumerable <IPaletteCommand> commands)
        {
            PaletteCommands = new ObservableCollection <IPaletteCommand>();
            foreach (var item in commands)
            {
                if (RibbonBuilder.IsAccess(item.Access))
                {
                    PaletteCommands.Add(item);
                }
            }

            ChangeContent(Settings.Default.PaletteStyle);
        }
Пример #11
0
        public void BuildCheckBox()
        {
            var builder = new RibbonBuilder();

            builder.CustomUi.Ribbon.Tabs(
                c => c.AddTab("test").Id("item1")
                .Groups(g1 => g1.AddGroup("group").Id("id")
                        .Items(g => g.AddCheckbox("checkbox")
                               .Callback(cb =>
                                         cb.OnChecked(b => { Console.WriteLine("Test Checkbox press:" + b); }
                                                      )))));
            Console.WriteLine(builder.GetXmlString());
        }
Пример #12
0
        public void Validate2010()
        {
            var builder = new RibbonBuilder(NamespaceCustomUI2010);

            BuildUi(builder);
            var          xdoc    = XDocument.Parse(builder.GetXmlString());
            XmlSchemaSet schemas = new XmlSchemaSet();

            schemas.Add(GetSchema2010());
            xdoc.Validate(schemas, (s, e) => {
                Console.WriteLine(e);
            });
        }
Пример #13
0
        public void TestGalleiesAndMenu()
        {
            const string HappyButtonId    = "HappyButton1";
            const string ShowNumberId     = "ShowNumberId1";
            const string HappyButtonId2   = "HappyButton2";
            const string ShowNumberId2    = "ShowNumberId2";
            const string MyTabId          = "MyTabId";
            const string DataGroupId      = "DataGroupId";
            const string OptionId         = "OptionId";
            const string GalleryId        = "GalleryId";
            const string DynamicGalleryId = "DynamicGalleryId";
            const string ButtonMore       = "buttonMoreId";

            var builder = new RibbonBuilder();

            builder.CustomUi.Ribbon.Tabs(c => {
                c.AddTab("My Tab").Id(MyTabId)
                .Groups(g => {
                    g.AddGroup("Data").Id(DataGroupId)
                    .Items(d => {
                        d.AddMenu("Option").Id(OptionId).ShowLabel()
                        .ImageMso("FileNew").LargeSize()
                        .ItemLargeSize().Items(
                            v => {
                            v.AddCheckbox("Show numbers").Id(ShowNumberId);
                            v.AddSeparator().SetTitle("Mood");
                            v.AddButton("Happy")
                            .Id(HappyButtonId)
                            .ImageMso("HappyFace");
                            v.AddGallery("Dynamic Option").Id(DynamicGalleryId)
                            .ShowLabel().NoImage().ShowItemLabel().ShowItemImage()
                            //.DynamicItems()
                            .Buttons(b => b.AddButton("Button...").Id(ButtonMore))
                            .NumberRows(6).NumberColumns(1);
                        });
                        d.AddGallery("Multi Option").Id(GalleryId)
                        .ShowLabel().LargeSize().NoImage().ShowItemLabel().ShowItemImage()
                        .Items(v => {
                            v.AddItem("Show numbers").Id(ShowNumberId2);
                            v.AddItem("Happy").Id(HappyButtonId2).ImageMso("HappyFace");
                        });
                    });
                });
            });

            var str = builder.GetXmlString();

            Console.WriteLine(str);

            Assert.True(ValidateHelper.Validate(str));
        }
Пример #14
0
        public void Validate2007()
        {
            var builder = new RibbonBuilder(NamespaceCustomUI2007);

            BuildUi(builder);
            var          xdoc    = XDocument.Parse(builder.GetXmlString());
            XmlSchemaSet schemas = new XmlSchemaSet();

            schemas.Add(GetSchema2007());
            xdoc.Validate(schemas, (s, e) => {
                Console.WriteLine(e);
            });
            Console.WriteLine(xdoc.ToString(SaveOptions.OmitDuplicateNamespaces));

            Assert.IsTrue(ValidateHelper.Validate2007(builder.GetXmlString()));
        }
Пример #15
0
        public void BuildButton()
        {
            var builder = new RibbonBuilder();
            var btn     = new Button().Supertip("test").ShowLabel().Description("test button").NoImage()
                          .Id("test_btn");

            btn.Callback(cmd => {
                cmd.OnAction(() => Console.WriteLine("test"));
                cmd.GetLabel(() => "Test Button");
            });

            builder.CustomUi.Ribbon.Tabs(
                c => c.AddTab("test")
                .Groups(g1 => g1.AddGroup("group").Items(g => g.AddButton("b")
                                                         .Callback(cb => cb.OnAction(() => Console.WriteLine("Test Button"))
                                                                   .GetEnabled(() => true).GetLabel(() => "Button Callback")))));
            Console.WriteLine(builder.GetXmlString());
        }
Пример #16
0
        /// <summary>
        /// Обработчик события, который проверяет, что построилась лента
        /// И когда она построилась - уже грузим свою вкладку, если надо
        /// </summary>
        private static void ComponentManager_ItemInitialized(object sender, Autodesk.Windows.RibbonItemEventArgs e)
        {
            if (Autodesk.Windows.ComponentManager.Ribbon == null)
            {
                return;
            }

            Autodesk.Windows.ComponentManager.Ribbon.BackgroundRenderFinished += RibbonOnBackgroundRenderFinished;

            if (ModPlusAPI.Variables.Ribbon)
            {
                RibbonBuilder.BuildRibbon();
            }
            else
            {
                RibbonBuilder.RemoveRibbon();
            }

            Autodesk.Windows.ComponentManager.ItemInitialized -= ComponentManager_ItemInitialized;
        }
Пример #17
0
        private static List <IPaletteCommand> LoadCommands()
        {
            var commands = new List <IPaletteCommand>();

            try
            {
                foreach (var group in RibbonBuilder.LoadRibbonTabsFromGroups())
                {
                    foreach (var panel in @group.Item1.Panels)
                    {
                        var panelName = panel.Name;
                        if (panelName.IsNullOrEmpty())
                        {
                            panelName = "Главная";
                        }
                        foreach (var item in panel.Items)
                        {
                            try
                            {
                                var com = GetCommand(item, panelName, group.Item2);
                                if (com != null)
                                {
                                    commands.Add(com);
                                }
                            }
                            catch
                            {
                                // Пофигу
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex);
            }

            return(commands);
        }
Пример #18
0
        /// <summary>
        /// Обработчик события, который проверяет, что построилась лента
        /// И когда она построилась - уже грузим свою вкладку, если надо
        /// </summary>
        private static void ComponentManager_ItemInitialized(object sender, Autodesk.Windows.RibbonItemEventArgs e)
        {
            // now one Ribbon item is initialized, but the Ribbon control
            // may not be available yet, so check if before
            if (Autodesk.Windows.ComponentManager.Ribbon == null)
            {
                return;
            }

            // ok, create Ribbon
            if (ModPlusAPI.Variables.Ribbon)
            {
                RibbonBuilder.BuildRibbon();
            }
            else
            {
                RibbonBuilder.RemoveRibbon();
            }

            // and remove the event handler
            Autodesk.Windows.ComponentManager.ItemInitialized -=
                ComponentManager_ItemInitialized;
        }
Пример #19
0
        public void Initialize()
        {
#if DEBUG
            // Отключение отладочных сообщений биндинга (тормозит сильно)
            PresentationTraceSources.DataBindingSource.Switch.Level = SourceLevels.Off;
#endif
            try
            {
                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
                Logger.Log.Info("start Initialize AcadLib");
                StatusBarEx.AddPaneUserGroup();
                PluginStatisticsHelper.StartAutoCAD();
                if (PikSettings.IsDisabledSettings)
                {
                    Logger.Log.Info("Настройки отключены (PikSettings.IsDisabledSettings) - загрузка прервана.");
                    return;
                }

                Notify.SetScreenSettings(new NotifyOptions(with: 400));

                CheckUpdates.Start();
                if (Settings.Default.UpgradeRequired)
                {
                    Settings.Default.Upgrade();
                    Settings.Default.UpgradeRequired = false;
                    Settings.Default.Save();
                }

                PaletteSetCommands.Init();
                AllCommandsCommon();

                // Автослоиtest
                AutoLayersService.Init();

                // Загрузка сборок из папки ../Script/Net - без вложенных папок
                LoadService.LoadFromFolder(Path.Combine(PikSettings.LocalSettingsFolder, @"Script\NET"), 1);

                // Обработка чертежей
                DocAuto.Start();

                // Лента
                RibbonBuilder.InitRibbon();
                Logger.Log.Info("end Initialize AcadLib");
                AcadLibAssembly.AcadLoadInfo();
                if (AutocadUserService.User == null)
                {
                    Logger.Log.Warn("Настройки группы пользователя не заданы - открытие окна настроек пользователя.");
                    UserSettingsService.Show();
                }

                // Восстановление вкладок чCheckUpdatesNotifyертежей
                //Utils.Tabs.RestoreTabs.Init(); // Фаталит у Черновой
                ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
                Logger.Log.Info("AcadLib Initialize end success.");
            }
            catch (Exception ex)
            {
                $"PIK. Ошибка загрузки AcadLib, версия:{AcadLibVersion} - {ex.Message}.".WriteToCommandLine();
                Logger.Log.Error(ex, "AcadLib Initialize.");
            }
        }
Пример #20
0
 public void PIK_Ribbon()
 {
     CommandStart.Start(d => RibbonBuilder.CreateRibbon());
 }
Пример #21
0
 public void Terminate()
 {
     RibbonBuilder.SaveActiveTab();
     Logger.Log.Info("Terminate AcadLib");
 }
Пример #22
0
        private static IPaletteCommand GetCommand(RibbonItemData item, string panel, string userGroup)
        {
            if (!RibbonBuilder.IsAccess(item.Access))
            {
                return(null);
            }
            IPaletteCommand com = null;

            switch (item)
            {
            case RibbonBreakPanel ribbonBreakPanel:
                break;

            case RibbonToggle ribbonToggle:
                var toggle = new ToggleButton();
                toggle.IsChecked   = ribbonToggle.IsChecked;
                toggle.CommandName = ribbonToggle.Command;
                com = toggle;
                break;

            case RibbonCommand ribbonCommand:
                var c = new PaletteCommand();
                c.CommandName = ribbonCommand.Command;
                com           = c;
                break;

            case RibbonVisualGroupInsertBlock ribbonVisualGroupInsertBlock:
                break;

            case RibbonVisualInsertBlock ribbonVisualInsertBlock:
                var vb = new PaletteVisualInsertBlocks();
                vb.file    = ribbonVisualInsertBlock.File;
                vb.filter  = s => Regex.IsMatch(s, ribbonVisualInsertBlock.Filter);
                vb.explode = ribbonVisualInsertBlock.Explode;
                vb.Layer   = new LayerInfo(ribbonVisualInsertBlock.Layer);
                com        = vb;
                break;

            case RibbonInsertBlock ribbonInsertBlock:
                var ib = new PaletteInsertBlock();
                ib.file    = ribbonInsertBlock.File;
                ib.blName  = ribbonInsertBlock.BlockName;
                ib.explode = ribbonInsertBlock.Explode;
                ib.Layer   = new LayerInfo(ribbonInsertBlock.Layer);
                ib.props   = ribbonInsertBlock.Properties;
                com        = ib;
                break;

            case RibbonSplit ribbonSplit:
                var coms = ribbonSplit.Items.Select(s => GetCommand(s, panel, userGroup))
                           .Where(w => w != null).ToList();
                var split = new SplitCommand(coms);
                com = split;
                break;
            }

            if (com != null)
            {
                com.Name        = item.Name;
                com.Description = item.Description;
                com.Image       = RibbonBuilder.GetImage(item, userGroup);
                com.Access      = item.Access;
                com.Command     = item.GetCommand();
                com.IsTest      = item.IsTest;
                com.Group       = panel;
            }

            return(com);
        }