Ejemplo n.º 1
0
        private void ButtonControl_OnClick(object sender, RoutedEventArgs e)
        {
            // Jumping through hoops to determine if the sender RegexRulePart is
            // of the CustomText kind
            if (!(sender is Button editButton))
            {
                return;
            }
            if (!(editButton.DataContext is IRegexRulePart regexRulePart))
            {
                return;
            }
            if (regexRulePart.RuleType != RuleType.CustomText)
            {
                return;
            }
            Grid grid = VisualTreeUtils.FindParent <Grid>(editButton);
            UIElementCollection uiElementCollection = grid.Children;
            TextBox             textBox             = uiElementCollection
                                                      .OfType <TextBox>()
                                                      .FirstOrDefault(x => x.Name == "RawUserInputValueTextBox");

            if (textBox == null)
            {
                return;
            }

            // Sets focus to the textbox and highlights and text found in it
            textBox.IsEnabled = true;
            textBox.Focus();
            textBox.Select(0, textBox.Text.Length);
        }
Ejemplo n.º 2
0
        private void OnLayoutUpdated(object sender, EventArgs eventArgs)
        {
            var compositeNodeEditor = VisualTreeUtils.FindParent <CompositeNodeEditor>(this);
            var nodeEditor          = VisualTreeUtils.FindParent <NodeEditor>(this);

            ViewModel.Point.Point = (Vector)compositeNodeEditor.TranslatePosition(nodeEditor.GetPinPoint(this, compositeNodeEditor));
        }
Ejemplo n.º 3
0
        protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseDown(e);

            if (!e.Handled)
            {
                if (e.ChangedButton == MouseButton.Middle)
                {
                    _canvasDragStartPoint = TranslatePosition(e.GetPosition(this));
                    CaptureMouse();
                }
                else if (e.ChangedButton == MouseButton.Left)
                {
                    var originalSource = e.OriginalSource as FrameworkElement;

                    var bullet = VisualTreeUtils.FindParent <Bullet>(originalSource);
                    if (bullet != null)
                    {
                        var pinViewModel = VisualTreeUtils.FindDataContext <PinViewModel>(bullet);

                        if (pinViewModel != null)
                        {
                            OnPreviewPinMouseDown(pinViewModel, e);
                            return;
                        }
                    }

                    var nodeViewModel = VisualTreeUtils.FindDataContext <NodeViewModel>(originalSource);
                    if (nodeViewModel != null && nodeViewModel != ViewModel)
                    {
                        _nodeDragLatestPoint = (Vector)TranslatePosition(e.GetPosition(this));
                        _nodeDraged          = nodeViewModel;
                        ViewModel.BringToFront(nodeViewModel.Node);
                        var ctrlPressed = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);
                        if (ctrlPressed)
                        {
                            nodeViewModel.IsSelected = !ViewModel.SelectedNodeViewModels.Contains(nodeViewModel);
                        }
                        else
                        {
                            nodeViewModel.IsSelected = true;
                            foreach (var viewModel in ViewModel.SelectedNodeViewModels.ToArray())
                            {
                                if (viewModel != nodeViewModel && viewModel.IsSelected)
                                {
                                    viewModel.IsSelected = false;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void ListBoxItem_OnMouseLeave(object sender, MouseEventArgs e)
        {
            if (!(sender is Grid grid))
            {
                return;
            }
            if (!(grid.DataContext is RegexRule gridRegexRule))
            {
                return;
            }

            ListBox listBox = VisualTreeUtils.FindParent <ListBox>(grid);

            if (listBox == null)
            {
                return;
            }

            if (listBox.SelectedItem != null)
            {
                RegexRule regexRule = listBox.SelectedItem as RegexRule;
                if (regexRule.RuleGuid == gridRegexRule.RuleGuid)
                {
                    return;
                }
            }

            UIElementCollection children = grid.Children;

            foreach (UIElement uiElement in children)
            {
                switch (uiElement)
                {
                case Rectangle rectangle:
                {
                    Color rolloutColor = (Color)ColorConverter.ConvertFromString("#E5E5E5");
                    rectangle.Fill = new SolidColorBrush(rolloutColor);
                    break;
                }

                case TextBox textBox:
                {
                    Color rolloutColor = (Color)ColorConverter.ConvertFromString("#E5E5E5");
                    textBox.Background = new SolidColorBrush(rolloutColor);
                    break;
                }
                }
            }
        }
Ejemplo n.º 5
0
 private void RawUserInputValueTextBox_OnTextChanged(object sender, TextChangedEventArgs e)
 {
     if (!(sender is TextBox textBox))
     {
         return;
     }
     // Lets us close the window by hitting the Escape key
     PreviewKeyDown += (s, eventHandler) =>
     {
         if (eventHandler.Key != Key.Escape && eventHandler.Key != Key.Enter)
         {
             return;
         }
         ListBoxItem listBoxItem = VisualTreeUtils.FindParent <ListBoxItem>(textBox);
         listBoxItem?.Focus();
     };
     RuleEditorViewModel.GenerateCompliantExampleCommand.Execute(null);
 }
        public void Execute(object parameter)
        {
            // Lets the user multi-select and multi-deselect items
            if (!(parameter is CheckBox checkBox))
            {
                return;
            }
            DataGrid categoriesDataGrid         = VisualTreeUtils.FindParent <DataGrid>(checkBox);
            List <CategoryObject> selectedItems = categoriesDataGrid.SelectedItems.Cast <CategoryObject>().ToList();

            if (selectedItems.Count > 1)
            {
                foreach (CategoryObject categoryObject in selectedItems)
                {
                    categoryObject.IsChecked = checkBox.IsChecked == true;
                }
            }

            // We update the number of categories ticked
            ruleEditorViewModel.UpdateCheckedCategoriesCount();
        }
        public void Execute(object parameter)
        {
            CheckBox senderCheckBox = (CheckBox)parameter;
            DataGrid dataGrid       = VisualTreeUtils.FindParent <DataGrid>(senderCheckBox);
            IList    selectedListViewItemCollection = dataGrid.SelectedItems;

            if (selectedListViewItemCollection.Count > 1)
            {
                // Filter down to just the selected items which aren't aligned with the sender checkbox
                List <ObservableObject> selectedObservableObjects = selectedListViewItemCollection
                                                                    .Cast <ObservableObject>()
                                                                    .Where(x => x.IsChecked != senderCheckBox.IsChecked)
                                                                    .ToList();

                foreach (ObservableObject observableObject in selectedObservableObjects)
                {
                    bool originalValue = observableObject.IsChecked;
                    observableObject.IsChecked = !(originalValue);
                }
            }

            SelectElementsViewModel.RefreshSelectedElementCount();
        }
Ejemplo n.º 8
0
        protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseUp(e);

            if (_canvasDragStartPoint != null)
            {
                ReleaseMouseCapture();
                _canvasDragStartPoint = null;
            }

            var hitTestResult  = VisualTreeHelper.HitTest(this, e.GetPosition(this));
            var originalSource = hitTestResult.VisualHit;

            if (_endLinkPoint != null)
            {
                ReleaseMouseCapture();
                PinViewModel pinViewModel = null;

                var bullet = VisualTreeUtils.FindParent <Bullet>(originalSource);
                if (bullet != null)
                {
                    pinViewModel = VisualTreeUtils.FindDataContext <PinViewModel>(bullet);
                }

                OnPreviewPinMouseUp(pinViewModel, e);
                _endLinkPoint = null;
            }

            if (_nodeDraged != null)
            {
                ReleaseMouseCapture();
                _nodeDraged = null;
            }

            //            if (_currentRope != null)
            //            {
            //                var hitTestResult = VisualTreeHelper.HitTest(this, e.GetPosition(this));
            //                var pin = VisualTreeUtils.FindParent<Pin>(hitTestResult.VisualHit);
            //                var ropeAdded = false;
            //                if (pin != null)
            //                {
            //                    if (_currentRope.EndPoint == _currentRopeFreePoint)
            //                    {
            //                        if (pin.IsInputPin)
            //                        {
            //                            if (InnerControls.OfType<Rope>().All(rope => rope.EndPoint != _pinLocations[pin]))
            //                            {
            //                                _currentRope.EndPoint = _pinLocations[pin];
            //                                Node.Link(_sourcePin.Node, _sourcePin.NodePin, pin.Node, pin.NodePin);
            //                                pin.Node.Pulse();
            //                                ropeAdded = true;
            //                            }
            //                        }
            //                    }
            //                    else
            //                    {
            //                        if (!pin.IsInputPin)
            //                        {
            //                            _currentRope.BeginPoint = _pinLocations[pin];
            //                            Node.Link(pin.Node, pin.NodePin, _targetPin.Node, _targetPin.NodePin);
            //                            pin.Node.Pulse();
            //                            ropeAdded = true;
            //                        }
            //                    }
            //                }
            //
            //                if (!ropeAdded)
            //                {
            //                    InnerControls.Remove(_currentRope);
            //                }
            //
            //                _currentRope = null;
            //                _currentRopeFreePoint = null;
            //            }
        }
Ejemplo n.º 9
0
        private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (!(sender is Grid senderGrid))
            {
                return;
            }
            if (!(senderGrid.DataContext is RegexRule senderRegexRule))
            {
                return;
            }

            ListBox listBox = VisualTreeUtils.FindParent <ListBox>(senderGrid);

            if (listBox == null)
            {
                return;
            }
            List <Grid> grids = listBox.FindVisualChildren <Grid>().ToList();

            foreach (Grid grid in grids)
            {
                if (!(grid.DataContext is RegexRule regexRule))
                {
                    continue;
                }
                if (regexRule.RuleGuid == senderRegexRule.RuleGuid)
                {
                    UIElementCollection children = grid.Children;
                    foreach (UIElement uiElement in children)
                    {
                        switch (uiElement)
                        {
                        case Rectangle rectangle:
                        {
                            Color rolloverColor = (Color)ColorConverter.ConvertFromString("#7CCEF4");
                            rectangle.Fill = new SolidColorBrush(rolloverColor);
                            break;
                        }

                        case TextBox textBox:
                        {
                            Color rolloverColor = (Color)ColorConverter.ConvertFromString("#7CCEF4");
                            textBox.Background = new SolidColorBrush(rolloverColor);
                            break;
                        }
                        }
                    }
                }
                else
                {
                    UIElementCollection children = grid.Children;
                    foreach (UIElement uiElement in children)
                    {
                        switch (uiElement)
                        {
                        case Rectangle rectangle:
                        {
                            Color rolloutColor = (Color)ColorConverter.ConvertFromString("#E5E5E5");
                            rectangle.Fill = new SolidColorBrush(rolloutColor);
                            break;
                        }

                        case TextBox textBox:
                        {
                            Color rolloutColor = (Color)ColorConverter.ConvertFromString("#E5E5E5");
                            textBox.Background = new SolidColorBrush(rolloutColor);
                            break;
                        }
                        }
                    }
                }
            }
        }