示例#1
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));
        }
示例#2
0
        protected override void OnMouseDown(object parameter)
        {
            if (!(parameter is MouseButtonEventArgs args))
            {
                return;
            }
            if (args.ChangedButton == MouseButton.Right)
            {
                return;
            }
            args.Handled = true;

            var concept = this.Ancestor <ConceptNodeViewModel>();

            if (concept == null)
            {
                return;
            }
            if (concept.SyntaxNode == null)
            {
                return;
            }

            ScriptConcept script;

            if (concept.SyntaxNode is ScriptConcept)
            {
                script = (ScriptConcept)concept.SyntaxNode;
            }
            else
            {
                script = concept.SyntaxNode.Ancestor <ScriptConcept>() as ScriptConcept;
            }
            string         propertyName = Owner.PropertyBinding;
            TypeConstraint constraints  = SyntaxTreeManager.GetTypeConstraints(script?.Languages, concept.SyntaxNode, propertyName);

            // if selection is obvious then just create the node ...
            if (constraints.Concepts.Count == 1 && constraints.DataTypes.Count == 0)
            {
                CreateRepetableOption(constraints.Concepts[0], concept.SyntaxNode, propertyName);
                return;
            }
            if (constraints.DataTypes.Count == 1 && constraints.Concepts.Count == 0)
            {
                CreateRepetableOption(constraints.DataTypes[0], concept.SyntaxNode, propertyName);
                return;
            }

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

            // open dialog window
            Visual      control = args.Source as Visual;
            PopupWindow dialog  = new PopupWindow(control, viewModel);

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

            // get result
            Type selectedType = dialog.Result.NodePayload as Type;

            if (selectedType == null)
            {
                return;
            }

            // create concept option, its view model and add it to syntax tree
            CreateRepetableOption(selectedType, concept.SyntaxNode, propertyName);
        }