Esempio n. 1
0
        private void ShowRepeatableOption(ISyntaxNodeViewModel repetableNode)
        {
            if (!repetableNode.IsVisible)
            {
                repetableNode.IsVisible = true;
            }

            RepeatableOptionViewModel option = null;

            foreach (var line in repetableNode.Lines)
            {
                foreach (var node in line.Nodes)
                {
                    if (node is RepeatableOptionViewModel)
                    {
                        option = (RepeatableOptionViewModel)node;
                        option.ResetHideOptionAnimation();
                    }
                }
            }
            if (option != null)
            {
                return;
            }

            option = new RepeatableOptionViewModel((RepeatableViewModel)repetableNode)
            {
                Presentation = $"[{repetableNode.PropertyBinding}]"
            };
            repetableNode.Add(option);
            option.StartHideOptionAnimation();
        }
        public static ConceptNodeViewModel Keyword(this ConceptNodeViewModel @this, string keyword)
        {
            if (string.IsNullOrWhiteSpace(keyword))
            {
                throw new ArgumentNullException(nameof(keyword));
            }

            ISyntaxNodeViewModel syntaxNode = @this.LastSyntaxNode();

            if (syntaxNode is PropertyViewModel property)
            {
                property.Nodes.Add(new KeywordNodeViewModel(property)
                {
                    Keyword         = keyword,
                    PropertyBinding = property.PropertyBinding
                });
            }
            else
            {
                ICodeLineViewModel codeLine = @this.BottomCodeLine();
                codeLine.Nodes.Add(new KeywordNodeViewModel(@this)
                {
                    Keyword = keyword
                });
            }
            return(@this);
            //ICodeLineViewModel codeLine = @this.BottomCodeLine();
            //codeLine.Nodes.Add(new KeywordNodeViewModel(@this) { Keyword = keyword });
        }
        private ISyntaxNode GetConceptFromPropertyBinding(ISyntaxNodeViewModel conceptViewModel)
        {
            if (conceptViewModel.Owner == null)
            {
                return(conceptViewModel.SyntaxNode); // it is syntax tree root node
            }
            ISyntaxNodeViewModel parentNode = conceptViewModel.Owner;
            string      propertyBinding     = conceptViewModel.PropertyBinding;
            ISyntaxNode parentConcept       = parentNode.SyntaxNode;

            PropertyInfo property = parentConcept.GetPropertyInfo(propertyBinding);
            IOptional    optional = null;

            if (property.IsOptional())
            {
                optional = (IOptional)property.GetValue(parentConcept);
            }
            ISyntaxNode concept = null;

            if (optional == null)
            {
                concept = (ISyntaxNode)property.GetValue(parentConcept);
            }
            else if (optional.HasValue)
            {
                concept = (ISyntaxNode)optional.Value;
            }
            return(concept);
        }
        public static ConceptNodeViewModel Literal(this ConceptNodeViewModel @this, string literal)
        {
            if (string.IsNullOrWhiteSpace(literal))
            {
                throw new ArgumentNullException(nameof(literal));
            }

            ISyntaxNodeViewModel syntaxNode = @this.LastSyntaxNode();

            if (syntaxNode is PropertyViewModel property)
            {
                property.Nodes.Add(new LiteralNodeViewModel(property)
                {
                    Literal         = literal,
                    PropertyBinding = property.PropertyBinding
                });
            }
            else
            {
                ICodeLineViewModel codeLine = @this.BottomCodeLine();
                codeLine.Nodes.Add(new LiteralNodeViewModel(@this)
                {
                    Literal = literal
                });
            }
            return(@this);

            //ICodeLineViewModel codeLine = @this.BottomCodeLine();
            //codeLine.Nodes.Add(new LiteralNodeViewModel(@this) { Literal = literal });
        }
 private void InitializeChildrenSyntaxNodes(ISyntaxNodeViewModel conceptViewModel, ObservableCollection <ISyntaxNodeViewModel> nodes)
 {
     for (int i = 0; i < nodes.Count; i++)
     {
         ISyntaxNodeViewModel currentNode = nodes[i];
         if (currentNode is ConceptNodeViewModel) // recursion
         {
             ISyntaxNode concept = GetConceptFromPropertyBinding(currentNode);
             if (concept == null)
             {
                 continue;
             }
             string propertyBinding = currentNode.PropertyBinding;
             currentNode = CreateSyntaxNode(conceptViewModel, concept);
             if (currentNode != null)
             {
                 // replace layout node with newly created initialized node
                 nodes[i] = currentNode;
                 currentNode.PropertyBinding = propertyBinding;
             }
         }
         else if (currentNode is PropertyViewModel)
         {
             InitializeChildrenSyntaxNodes(currentNode, ((PropertyViewModel)currentNode).Nodes);
         }
         else if (currentNode is RepeatableViewModel)
         {
             InitializeRepeatableViewModel(currentNode);
         }
         else if (currentNode is SelectorViewModel)
         {
             InitializeSelectorViewModel(currentNode);
         }
     }
 }
 private void InitializeConceptViewModel(ISyntaxNodeViewModel conceptViewModel)
 {
     foreach (ICodeLineViewModel line in conceptViewModel.Lines)
     {
         // PropertyViewModel does not have Lines collection
         InitializeChildrenSyntaxNodes(conceptViewModel, line.Nodes);
     }
 }
        public override void Add(ISyntaxNodeViewModel node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            ICodeLineViewModel line = new CodeLineViewModel(this);

            if (string.IsNullOrEmpty(OpeningLiteral))
            {
                line.Nodes.Add(new IndentNodeViewModel(this));
            }
            else
            {
                line.Nodes.Add(new IndentNodeViewModel(this));
                line.Nodes.Add(new IndentNodeViewModel(this));
            }
            if (!string.IsNullOrEmpty(Delimiter))
            {
                int count = 0;
                count += (string.IsNullOrEmpty(OpeningLiteral) ? 0 : 1);
                count += (string.IsNullOrEmpty(ClosingLiteral) ? 0 : 1);
                count  = Lines.Count - count;
                if (count > 0)
                {
                    line.Nodes.Add(new LiteralNodeViewModel(this)
                    {
                        Literal = Delimiter
                    });
                }
            }

            line.Nodes.Add(node);
            if (node is RepeatableOptionViewModel)
            {
                if (string.IsNullOrEmpty(OpeningLiteral))
                {
                    Lines.Insert(0, line);
                }
                else
                {
                    Lines.Insert(1, line);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(ClosingLiteral))
                {
                    Lines.Add(line);
                }
                else
                {
                    Lines.Insert(Lines.Count - 1, line);
                }
            }
        }
        public static ISyntaxNodeViewModel LastSyntaxNode(this ISyntaxNodeViewModel @this)
        {
            ICodeLineViewModel codeLine = @this.BottomCodeLine();
            int count = codeLine.Nodes.Count;

            if (count == 0)
            {
                return(null);
            }
            return(codeLine.Nodes[count - 1]);
        }
        public static ConceptNodeViewModel Delimiter(this ConceptNodeViewModel @this, string delimiterLiteral)
        {
            ISyntaxNodeViewModel syntaxNode = @this.LastSyntaxNode();

            if (syntaxNode == null)
            {
                throw new ArgumentNullException(nameof(syntaxNode));
            }
            if (!(syntaxNode is RepeatableViewModel repeatable))
            {
                return(@this);
            }

            repeatable.Delimiter = delimiterLiteral;
            return(@this);
        }
Esempio n. 10
0
        private void ShowProperty(ISyntaxNodeViewModel propertyNode)
        {
            if (!(propertyNode is PropertyViewModel property))
            {
                return;
            }

            if (property.IsTemporallyVisible)
            {
                property.ResetHideOptionAnimation();
            }
            else
            {
                property.StartHideOptionAnimation();
            }
        }
        public IdentifierNodeViewModel(ISyntaxNodeViewModel owner, ISyntaxNode model) : base(owner, model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            Type metadata = model.GetType();

            if (!metadata.GetInterfaces().Contains(typeof(IIdentifiable)))
            {
                throw new InvalidOperationException("Interface \"IIdentifiable\" is not found!");
            }

            _identifiable = (IIdentifiable)model;
        }
        public static ICodeLineViewModel BottomCodeLine(this ISyntaxNodeViewModel @this)
        {
            ICodeLineViewModel codeLine;
            int count = @this.Lines.Count;

            if (count == 0)
            {
                codeLine = new CodeLineViewModel(@this);
                @this.Lines.Add(codeLine);
            }
            else
            {
                codeLine = @this.Lines[count - 1];
            }
            return(codeLine);
        }
        public static ConceptNodeViewModel Decorate(this ConceptNodeViewModel @this, string openingLiteral, string closingLiteral)
        {
            ISyntaxNodeViewModel syntaxNode = @this.LastSyntaxNode();

            if (syntaxNode == null)
            {
                throw new ArgumentNullException(nameof(syntaxNode));
            }
            if (!(syntaxNode is RepeatableViewModel repeatable))
            {
                return(@this);
            }

            repeatable.OpeningLiteral = openingLiteral;
            repeatable.ClosingLiteral = closingLiteral;
            return(@this);
        }
        public static ConceptNodeViewModel Bind(this ConceptNodeViewModel @this, string propertyName)
        {
            if (string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException(nameof(propertyName));
            }

            ISyntaxNodeViewModel syntaxNode = @this.LastSyntaxNode();

            if (syntaxNode == null)
            {
                throw new ArgumentNullException(nameof(syntaxNode));
            }

            syntaxNode.PropertyBinding = propertyName;
            return(@this);
        }
        private void InitializeSelectorViewModel(ISyntaxNodeViewModel selectorViewModel)
        {
            ISyntaxNodeViewModel parentNode = selectorViewModel.Owner;
            string       propertyBinding    = selectorViewModel.PropertyBinding;
            ISyntaxNode  parentConcept      = parentNode.SyntaxNode;
            PropertyInfo property           = parentConcept.GetPropertyInfo(propertyBinding);

            IOptional optional = null;

            if (property.IsOptional())
            {
                optional = (IOptional)property.GetValue(parentConcept);
            }
            object propertyValue = null;

            if (optional == null)
            {
                propertyValue = property.GetValue(parentConcept);
            }
            else if (optional.HasValue)
            {
                propertyValue = optional.Value;
            }
            if (propertyValue is Assembly)
            {
                selectorViewModel.SyntaxNode     = parentConcept;
                selectorViewModel.SyntaxNodeType = null;
            }
            else if (propertyValue is Type)
            {
                selectorViewModel.SyntaxNode     = null;
                selectorViewModel.SyntaxNodeType = (Type)propertyValue;
            }
            else if (propertyValue is SyntaxNode)
            {
                selectorViewModel.SyntaxNode     = (ISyntaxNode)propertyValue;
                selectorViewModel.SyntaxNodeType = null;
            }
            else
            {
                selectorViewModel.SyntaxNode     = null;
                selectorViewModel.SyntaxNodeType = null;
            }
            _ = ((SelectorViewModel)selectorViewModel).Presentation;
        }
        public static ISyntaxNodeViewModel Ancestor <T>(this ISyntaxNodeViewModel @this)
        {
            Type ancestorType             = typeof(T);
            ISyntaxNodeViewModel ancestor = @this.Owner;

            while (ancestor != null)
            {
                if (ancestor.GetType() != ancestorType)
                {
                    ancestor = ancestor.Owner;
                }
                else
                {
                    break;
                }
            }
            return(ancestor);
        }
Esempio n. 17
0
        private void ShowConceptOption(ISyntaxNodeViewModel conceptNode)
        {
            int lineIndex = 0;
            int nodeIndex = 0;
            ConceptOptionViewModel option = null;

            for (int l = 0; l < conceptNode.Owner.Lines.Count; l++)
            {
                var line = conceptNode.Owner.Lines[l];
                for (int n = 0; n < line.Nodes.Count; n++)
                {
                    var node = line.Nodes[n];
                    if (node == conceptNode)
                    {
                        if (n > 0)
                        {
                            if (line.Nodes[n - 1] is ConceptOptionViewModel)
                            {
                                option = (ConceptOptionViewModel)line.Nodes[n - 1];
                                option.ResetHideOptionAnimation();
                            }
                        }
                        else
                        {
                            lineIndex = l;
                            nodeIndex = n;
                        }
                    }
                }
            }
            if (option != null)
            {
                return;
            }

            option = new ConceptOptionViewModel((ConceptNodeViewModel)conceptNode.Owner)
            {
                PropertyBinding = conceptNode.PropertyBinding
            };
            conceptNode.Owner.Lines[lineIndex].Nodes.Insert(nodeIndex, option);
            option.StartHideOptionAnimation();
        }
        public static ConceptNodeViewModel Selector(this ConceptNodeViewModel @this)
        {
            ISyntaxNodeViewModel syntaxNode = @this.LastSyntaxNode();

            if (syntaxNode is PropertyViewModel property)
            {
                property.Nodes.Add(new SelectorViewModel(property)
                {
                    PropertyBinding = property.PropertyBinding
                });
            }
            else
            {
                ICodeLineViewModel codeLine = @this.BottomCodeLine();
                codeLine.Nodes.Add(new SelectorViewModel(@this));
            }
            return(@this);

            //ICodeLineViewModel codeLine = @this.BottomCodeLine();
            //codeLine.Nodes.Add(new SelectorViewModel(@this));
        }
        public ConceptNodeViewModel CreateSyntaxNode(ISyntaxNodeViewModel parentNode, ISyntaxNode model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            IConceptLayout layout = GetLayout(model);

            if (layout == null)
            {
                return(null);
            }

            ConceptNodeViewModel node = layout.Layout(model) as ConceptNodeViewModel;

            node.Owner = parentNode;
            InitializeConceptViewModel(node);

            return(node);
        }
        private void InitializeRepeatableViewModel(ISyntaxNodeViewModel repeatableNode)
        {
            ISyntaxNodeViewModel parentNode = repeatableNode.Owner;
            ISyntaxNode          concept    = parentNode.SyntaxNode;
            string propertyBinding          = repeatableNode.PropertyBinding;

            IList        conceptChildren;
            PropertyInfo property = concept.GetPropertyInfo(propertyBinding);

            if (property.IsOptional())
            {
                IOptional optional = (IOptional)property.GetValue(concept);
                if (optional == null || !optional.HasValue)
                {
                    return;
                }
                conceptChildren = (IList)optional.Value;
            }
            else
            {
                conceptChildren = (IList)property.GetValue(concept);
            }
            if (conceptChildren == null || conceptChildren.Count == 0)
            {
                return;
            }
            foreach (var child in conceptChildren)
            {
                if (!(child is SyntaxNode))
                {
                    continue;
                }
                ConceptNodeViewModel conceptViewModel = CreateSyntaxNode(repeatableNode, (ISyntaxNode)child);
                if (conceptViewModel == null)
                {
                    continue;
                }
                repeatableNode.Add(conceptViewModel);
            }
        }
        public override void Remove(ISyntaxNodeViewModel node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            for (int l = 0; l < Lines.Count; l++)
            {
                var line = Lines[l];
                for (int i = 0; i < line.Nodes.Count; i++)
                {
                    if (line.Nodes[i] == node)
                    {
                        line.Nodes.Remove(node);
                        if (line.Nodes.Where(n => !(n is IndentNodeViewModel)).Count() == 0)
                        {
                            Lines.Remove(line);
                        }
                        return;
                    }
                }
            }
        }
        public static NodePosition GetPosition(this ISyntaxNodeViewModel @this, ISyntaxNodeViewModel node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            NodePosition position = new NodePosition();

            for (int l = 0; l < @this.Lines.Count; l++)
            {
                var line = @this.Lines[l];
                for (int p = 0; p < line.Nodes.Count; p++)
                {
                    if (line.Nodes[p] == node)
                    {
                        position.Line     = l;
                        position.Position = p;
                        return(position);
                    }
                }
            }
            return(position);
        }
 public SyntaxNodeViewModel(ISyntaxNodeViewModel owner) : this()
 {
     Owner = owner;
 }
 public LiteralNodeViewModel(ISyntaxNodeViewModel owner) : base(owner)
 {
 }
 public CodeLineViewModel(ISyntaxNodeViewModel owner)
 {
     Owner = owner;
 }
Esempio n. 26
0
 public ConceptNodeViewModel(ISyntaxNodeViewModel owner, ISyntaxNode model) : base(owner, model)
 {
 }
Esempio n. 27
0
 //private Brush _textColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#A31515"));
 //private Brush _defaultColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#A31515"));
 //private Brush _temporallyVisibleColor = Brushes.LightGray;
 //private Brush _selectedValueBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2B91AF"));
 public SelectorViewModel(ISyntaxNodeViewModel owner) : base(owner)
 {
 }
 public KeywordNodeViewModel(ISyntaxNodeViewModel owner) : base(owner)
 {
 }
 public RepeatableViewModel(ISyntaxNodeViewModel owner) : base(owner)
 {
 }
 public SyntaxNodeViewModel(ISyntaxNodeViewModel owner, ISyntaxNode model) : this(owner) { SyntaxNode = model; }