예제 #1
0
        private static IRibbonElement ConvertToRibbonElement([NotNull] IPaletteCommand c, string paletteName)
        {
            if (c is SplitCommand splitCommand)
            {
                return(new SplitElement
                {
                    Items = splitCommand.Commands.Select(s => ConvertPaletteCommand(s, paletteName)).ToList(),
                    Tab = paletteName,
                    Panel = c.Group
                });
            }
            if (c is ToggleButton toggleBtn)
            {
                return(new ToggleElement
                {
                    Name = c.Name,
                    Command = toggleBtn.Command,
                    Image = c.Image,
                    LargeImage = c.Image,
                    Tab = paletteName,
                    Panel = c.Group,
                    Description = c.Description,
                    IsChecked = toggleBtn.IsChecked,
                });
            }

            return(ConvertPaletteCommand(c, paletteName));
        }
예제 #2
0
 private static RibbonElement ConvertPaletteCommand([NotNull] IPaletteCommand c, string paletteName)
 {
     return(new RibbonElement
     {
         Command = new RelayCommand(c.Execute),
         Image = c.Image,
         LargeImage = c.Image,
         Name = c.Name,
         Tab = paletteName,
         Panel = c.Group,
         Description = c.Description
     });
 }
예제 #3
0
        private object GenerateCommandParameter(IPaletteCommand paletteCommand, IList <InputParameter> inputParameterList)
        {
            var parameterList = new List <object>();

            foreach (var inputParameter in inputParameterList)
            {
                parameterList.Add(inputParameter.Input);
            }

            if (paletteCommand.CreateCommandParameter == null)
            {
                return(null);
            }
            return(paletteCommand.CreateCommandParameter(parameterList));
        }
예제 #4
0
        private void SaveImage(IPaletteCommand com)
        {
            if (com.Name.IsNullOrEmpty())
            {
                return;
            }
            var imageName = RibbonGroupData.GetImageName(com.Name);
            var file      = Path.Combine(imagesDir, imageName);
            var fi        = new FileInfo(file);

            using (var fileStream = fi.Create())
            {
                var encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create((BitmapSource)com.Image));
                encoder.Save(fileStream);
            }
        }
예제 #5
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);
        }
예제 #6
0
        private RibbonItemData GetItem(IPaletteCommand com)
        {
            RibbonItemData item;

            switch (com)
            {
            case PaletteInsertBlock paletteInsertBlock:
                item = new RibbonInsertBlock
                {
                    Name       = paletteInsertBlock.blName,
                    File       = GetBlockFile(paletteInsertBlock.file),
                    Explode    = paletteInsertBlock.explode,
                    Layer      = paletteInsertBlock.Layer?.Name,
                    BlockName  = paletteInsertBlock.blName,
                    Properties = paletteInsertBlock.props
                };
                break;

            case PaletteVisualInsertBlocks paletteVisualInsertBlocks:
                item = new RibbonVisualInsertBlock
                {
                    Name    = paletteVisualInsertBlocks.Name ?? paletteVisualInsertBlocks.CommandName,
                    File    = GetBlockFile(paletteVisualInsertBlocks.file),
                    Explode = paletteVisualInsertBlocks.explode,
                    Layer   = paletteVisualInsertBlocks.Layer?.Name,
                };
                break;

            case SplitCommand splitCommand:
                item = new RibbonSplit
                {
                    Items = splitCommand.Commands?.Select(GetItem).ToList()
                };
                break;

            case ToggleButton toggleButton:
                item = new RibbonToggle
                {
                    Name      = toggleButton.Name ?? toggleButton.CommandName,
                    IsChecked = toggleButton.IsChecked,
                    Command   = toggleButton.CommandName
                };
                break;

            case PaletteCommand paletteCommand:
                item = new RibbonCommand
                {
                    Name    = paletteCommand.Name ?? paletteCommand.CommandName,
                    Command = paletteCommand.CommandName,
                };
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(com));
            }

            item.Name        = com.Name;
            item.Access      = com.Access;
            item.Description = com.Description;
            item.IsTest      = com.IsTest;
            SaveImage(com);
            return(item);
        }
예제 #7
0
        public CommandPalette()
        {
            InitializeComponent();
            ExecuteCommand = new DelegateCommand((obj) =>
            {
                if (SearchIndex == -1)
                {
                    _paletteCommand = GetCommandResultListView().SelectedItem as IPaletteCommand;
                }

                if (_paletteCommand == null)
                {
                    SearchIndex = -1;
                    commandPaletteSearchPopup.IsOpen = false;
                    return;
                }

                if (SearchIndex == -1)
                {
                    commandFindTextBox.ReplaceCurrentTextToToken(_paletteCommand);
                    commandFindTextBox.FocusToLast();
                }
                else if (SearchIndex != _paletteCommand.Parameters.Count())
                {
                    var focusParameter = _paletteCommand.Parameters.ElementAt(SearchIndex);
                    if (focusParameter is IPaletteSearchParameter)
                    {
                        var resultParameter = GetParameterResultListView().SelectedItem as IPaletteSearchItem;
                        if (!focusParameter.ValidateInput(resultParameter))
                        {
                            return;
                        }
                        var inputParameter = new InputParameter(focusParameter.Name, focusParameter.CreateInput(resultParameter), focusParameter.CreateInputExplanation(resultParameter));
                        commandFindTextBox.ReplaceCurrentTextToToken(inputParameter);
                        _inputParameterList.Add(inputParameter);
                    }
                    else
                    {
                        if (!focusParameter.ValidateInput(SearchText))
                        {
                            return;
                        }
                        var inputParameter = new InputParameter(focusParameter.Name, focusParameter.CreateInput(SearchText), focusParameter.CreateInputExplanation(SearchText));
                        commandFindTextBox.ReplaceCurrentTextToToken(inputParameter);
                        _inputParameterList.Add(inputParameter);
                    }


                    commandFindTextBox.FocusToLast();
                }

                SearchIndex++;

                if (_paletteCommand.Parameters.Count() != SearchIndex)
                {
                    FocusedItem = _paletteCommand.Parameters.ElementAt(SearchIndex);
                    return;
                }

                var commandParameter = GenerateCommandParameter(_paletteCommand, _inputParameterList);

                if (_paletteCommand.Command.CanExecute(commandParameter))
                {
                    _paletteCommand.Command.Execute(commandParameter);
                }
                else
                {
                }

                SearchIndex = -1;
                commandFindTextBox.Clear();
                _inputParameterList.Clear();
                _paletteCommand          = null;
                IsCommandResultPopupOpen = false;
                SearchText = string.Empty;
                IsOpen     = false;
            });
            SelectPrevItemCommand = new DelegateCommand(_ =>
            {
                var resultListView = GetResultListView();
                if (resultListView == null)
                {
                    return;
                }
                var count = resultListView.Items.Count;
                if (count == 0)
                {
                    return;
                }
                if (resultListView.SelectedIndex == -1 || resultListView.SelectedIndex == 0)
                {
                    resultListView.SelectedIndex = count - 1;
                    return;
                }
                resultListView.SelectedIndex--;
            });
            SelectNextItemCommand = new DelegateCommand(_ =>
            {
                var resultListView = GetResultListView();
                if (resultListView == null)
                {
                    return;
                }
                var count = resultListView.Items.Count;
                if (count == 0)
                {
                    return;
                }
                if (resultListView.SelectedIndex == -1 || resultListView.SelectedIndex == count - 1)
                {
                    resultListView.SelectedIndex = 0;
                    return;
                }
                resultListView.SelectedIndex++;
            });
            commandPaletteSearchPopup.Opened += OnOpen;
            commandPaletteSearchPopup.Closed += OnClose;
        }