Example #1
0
        protected override void OnMouseDown(object parameter)
        {
            if (!(parameter is MouseButtonEventArgs args))
            {
                return;
            }
            if (args.ChangedButton == MouseButton.Right)
            {
                return;
            }
            args.Handled = true;

            // TODO: move this code to SyntaxTreeManager
            PropertyInfo         property   = Owner.SyntaxNode.GetPropertyInfo(PropertyBinding);
            Type                 optionType = SyntaxTreeManager.GetPropertyType(property);
            ISyntaxNode          concept    = SyntaxTreeManager.CreateConcept(optionType, Owner.SyntaxNode, PropertyBinding);
            ConceptNodeViewModel node       = SyntaxTreeController.Current.CreateSyntaxNode(Owner, concept);

            node.PropertyBinding = PropertyBinding;

            NodePosition position = Owner.GetPosition(this);

            Owner.Lines[position.Line].Nodes.RemoveAt(position.Position + 1); // remove concept view model from layout
            Owner.Lines[position.Line].Nodes.RemoveAt(position.Position);     // remove this concept option command
            Owner.Lines[position.Line].Nodes.Add(node);                       // add newly created concept node
        }
Example #2
0
        protected override void OnMouseDown(object parameter)
        {
            if (!(parameter is MouseButtonEventArgs args))
            {
                return;
            }
            if (args.ChangedButton == MouseButton.Right)
            {
                return;
            }
            args.Handled = true;

            Visual control = args.Source as Visual;

            if (IsTemporallyVisible)
            {
                base.OnMouseDown(parameter);
                return;
            }

            // get parent concept node
            var ancestor = this.Ancestor <ConceptNodeViewModel>();

            if (ancestor == null)
            {
                return;
            }

            // check if property is referencing assembly - special case !
            if (ancestor.SyntaxNode.IsAssemblyReference(PropertyBinding))
            {
                IAssemblyConcept assemblyConcept = SelectAssemblyReference(ancestor.SyntaxNode, PropertyBinding, control);
                if (assemblyConcept == null)
                {
                    return;
                }
                SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, assemblyConcept.Assembly);
                SyntaxNode = ancestor.SyntaxNode;
                OnPropertyChanged(nameof(Presentation));
                return;
            }

            // get hosting script concept
            ScriptConcept script;

            if (ancestor.SyntaxNode is ScriptConcept)
            {
                script = (ScriptConcept)ancestor.SyntaxNode;
            }
            else
            {
                script = ancestor.SyntaxNode.Ancestor <ScriptConcept>() as ScriptConcept;
            }

            // get type constraints of the property
            TypeConstraint constraints = SyntaxTreeManager.GetTypeConstraints(script?.Languages, ancestor.SyntaxNode, PropertyBinding);

            // build tree view
            TreeNodeViewModel viewModel = SyntaxNodeSelector.BuildSelectorTree(constraints);

            // open dialog window
            PopupWindow dialog = new PopupWindow(control, viewModel);

            _ = dialog.ShowDialog();
            if (dialog.Result == null)
            {
                return;
            }

            Type selectedType = dialog.Result.NodePayload as Type;

            if (selectedType == null)
            {
                return;
            }

            // set binded property of the model by selected reference
            PropertyInfo property = ancestor.SyntaxNode.GetPropertyInfo(PropertyBinding);

            if (SyntaxTreeManager.GetPropertyType(property) == typeof(Type))
            {
                selectedType = SelectTypeReference(ancestor.SyntaxNode, selectedType, control);
                SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, selectedType);
                SyntaxNodeType = selectedType;
            }
            else if (selectedType.IsEnum)
            {
                object enumValue = SelectEnumerationValue(selectedType, control);
                if (enumValue == null)
                {
                    return;
                }
                SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, enumValue);
            }
            else
            {
                ISyntaxNode reference;
                if (selectedType.IsSubclassOf(typeof(DataType)))
                {
                    reference = (ISyntaxNode)Activator.CreateInstance(selectedType);
                }
                else
                {
                    // use dialog and scope provider to find reference to the node in the syntax tree
                    reference = SelectSyntaxNodeReference(selectedType, ancestor.SyntaxNode, PropertyBinding, control);
                    if (reference == null)
                    {
                        return;
                    }
                }
                SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, reference);
                SyntaxNode = reference;
            }

            // reset view model's state
            OnPropertyChanged(nameof(Presentation));
        }