internal static void SetMethodNodeInfos(CSharpOutlineNode node, AstNode dataNode) { var methodNode = (MethodDeclaration)dataNode; node.Name = methodNode.Name; node.Name += " " + methodNode.LParToken + (showExtendedInfos ? GetParameterDeclsAsString(methodNode.Parameters) : "") + methodNode.RParToken; if (colorizeNode) node.ForegroundBrush = (methodHighLighting.Foreground as SimpleHighlightingBrush).GetBrush(null); // node.Weight = methodHighLighting.FontWeight != null ? methodHighLighting.FontWeight.Value : FontWeights.Normal; switch(GetAccessModifier(dataNode)) { case Modifiers.Public: node.IconName = "Icons.16x16.Method"; break; case Modifiers.Protected: node.IconName = "Icons.16x16.ProtectedMethod"; break; default: node.IconName = "Icons.16x16.PrivateMethod"; break; } }
internal static void SetFieldNodeInfos(CSharpOutlineNode node, AstNode dataNode) { var fieldNode = (FieldDeclaration)dataNode; var fieldName = new StringBuilder(); int current = 0; foreach (var varInitializer in fieldNode.Variables) { fieldName.Append(varInitializer.Name); if (current < (fieldNode.Variables.Count - 1)) { fieldName.Append(", "); } current++; } node.Name = fieldName.ToString(); if (colorizeNode) node.ForegroundBrush = Brushes.Black; switch(GetAccessModifier(dataNode)) { case Modifiers.Public: node.IconName = "Icons.16x16.Field"; break; case Modifiers.Protected: node.IconName = "Icons.16x16.ProtectedField"; break; default: node.IconName = "Icons.16x16.PrivateField"; break; } }
internal static void SetInterfaceNodeInfos(CSharpOutlineNode node, AstNode dataNode) { var typeNode = (TypeDeclaration)dataNode; node.Name = typeNode.Name; node.IsExpanded = true; if (colorizeNode) node.ForegroundBrush = (interfaceHighLighting.Foreground as SimpleHighlightingBrush).GetBrush(null); switch(GetAccessModifier(dataNode)) { case Modifiers.Public: node.IconName = "Icons.16x16.Interface"; break; case Modifiers.Protected: node.IconName = "Icons.16x16.ProtectedInterface"; break; case Modifiers.Private: node.IconName = "Icons.16x16.PrivateInterface"; break; default: node.IconName = "Icons.16x16.InternalInterface"; break; } }
internal static void SetOperatorNodeInfos(CSharpOutlineNode node, AstNode dataNode) { var operatorNode = (OperatorDeclaration)dataNode; node.Name = operatorNode.OperatorToken + " " + operatorNode.OperatorTypeToken; if (colorizeNode) node.ForegroundBrush = Brushes.Black; if (showExtendedInfos) { node.Name += " " + operatorNode.LParToken + GetParameterDeclsAsString(operatorNode.Parameters) + operatorNode.RParToken; } switch(GetAccessModifier(dataNode)) { case Modifiers.Public: node.IconName = "Icons.16x16.Method"; break; case Modifiers.Protected: node.IconName = "Icons.16x16.ProtectedMethod"; break; default: node.IconName = "Icons.16x16.PrivateMethod"; break; } }
void UpdateNode(CSharpOutlineNode node, AstNode dataNode) { if (dataNode == null || node == null) return; SetNodeInfos(node, null, dataNode); // Filter the children, for only the needed/wanted nodes var dataChildren = dataNode.Children.Where(childNode => AstNodeHelper.IsAllowedNode(childNode)).ToList(); int childrenCount = node.Children.Count; int dataCount = dataChildren.Count; for (int i = 0; i < Math.Max(childrenCount, dataCount); i++) { if (i >= childrenCount) { node.Children.Add(BuildNode(node, dataChildren[i])); } else if (i >= dataCount) { while (node.Children.Count > dataCount) node.Children.RemoveAt(dataCount); } else { // Create new node, the old node doesn´t update (seems to be a bug) node.Children[i] = new CSharpOutlineNode(); UpdateNode(node.Children[i] as CSharpOutlineNode, dataChildren[i]); } } }
internal static void SetEventNodeInfos(CSharpOutlineNode node, AstNode dataNode) { var eventNode = (EventDeclaration)dataNode; var varInitializer = eventNode.Children.FirstOrDefault(x => x is VariableInitializer) as VariableInitializer; node.Name = (varInitializer != null) ? varInitializer.Name : "<unknown>"; if (colorizeNode) node.ForegroundBrush = Brushes.Black; switch(GetAccessModifier(dataNode)) { case Modifiers.Public: node.IconName = "Icons.16x16.Event"; break; case Modifiers.Protected: node.IconName = "Icons.16x16.ProtectedEvent"; break; default: node.IconName = "Icons.16x16.PrivateEvent"; break; } }
internal static void SetDelegateNodeInfos(CSharpOutlineNode node, AstNode dataNode) { var typeNode = (DelegateDeclaration)dataNode; node.Name = typeNode.Name; if (colorizeNode) node.ForegroundBrush = Brushes.Black; // node.Weight = classHighLighting.FontWeight != null ? classHighLighting.FontWeight.Value : FontWeights.Normal; switch(GetAccessModifier(dataNode)) { case Modifiers.Public: node.IconName = "Icons.16x16.Delegate"; break; case Modifiers.Protected: node.IconName = "Icons.16x16.ProtectedDelegate"; break; case Modifiers.Private: node.IconName = "Icons.16x16.PrivateDelegate"; break; default: node.IconName = "Icons.16x16.InternalDelegate"; break; } }
internal static void SetConstructorNodeInfos(CSharpOutlineNode node, AstNode dataNode) { var constructorNode = (ConstructorDeclaration)dataNode; node.Name = constructorNode.Name; if (colorizeNode) node.ForegroundBrush = Brushes.Black; node.Name += " " + constructorNode.LParToken + (showExtendedInfos ? GetParameterDeclsAsString(constructorNode.Parameters) : "") + constructorNode.RParToken; switch(GetAccessModifier(dataNode)) { case Modifiers.Public: node.IconName = "Icons.16x16.Method"; break; case Modifiers.Protected: node.IconName = "Icons.16x16.ProtectedMethod"; break; default: node.IconName = "Icons.16x16.PrivateMethod"; break; } }
void SelectActiveTreeNode() { if (!optionSelectActiveTreeNode) return; // prevent unnecessary looping, when both CaretLocationChanged and ParseUpdateChanged are fired. if (this.lastCaretLocation.HasValue && this.lastCaretLocation == this.editor.Caret.Location) return; this.lastCaretLocation = this.editor.Caret.Location; selectedNode = null; FindNodeFromLocation(this.editor.Caret.Location, treeView.Root as CSharpOutlineNode); if (selectedNode != null && treeView.SelectedItem != selectedNode) { treeView.SelectedItem = selectedNode; if (!scrollToNodeTimer.IsEnabled) { scrollToNodeTimer.Start(); } } }
internal static void SetRegionEndInfos(CSharpOutlineNode node, AstNode dataNode) { var preProcessorNode = (PreProcessorDirective)dataNode; node.Name = "********************"; node.ForegroundBrush = (regionHighLighting.Foreground as SimpleHighlightingBrush).GetBrush(null); // node.Weight = regionHighLighting.FontWeight != null ? regionHighLighting.FontWeight.Value : FontWeights.Normal; }
public void Dispose() { SD.ParserService.ParseInformationUpdated -= ParseInfoUpdated; if (this.editor != null) { if (this.editor.Caret != null) this.editor.Caret.LocationChanged -= CaretLocationChanged; this.editor = null; } this.syntaxTree = null; this.lastCaretLocation = null; this.selectedNode = null; if (this.updateTreeTimer != null) { this.updateTreeTimer.Stop(); this.updateTreeTimer.Tick -= this.UpdateTreeTimer_Tick; this.updateTreeTimer = null; } if (this.scrollToNodeTimer != null) { this.scrollToNodeTimer.Stop(); this.scrollToNodeTimer.Tick -= this.ScrollToNodeTimer_Tick; this.scrollToNodeTimer = null; } }
void SetNodeInfos(CSharpOutlineNode node, CSharpOutlineNode parentNode, AstNode dataNode) { int startOffset = 0; int textLength = Math.Max(editor.Document.TextLength - 1,0); if (!dataNode.StartLocation.IsValid() || dataNode.StartLocation.Line > editor.Document.LineCount) startOffset = 0; else startOffset = editor.Document.GetOffset(dataNode.StartLocation); int endOffset = 0; if (!dataNode.EndLocation.IsValid() || dataNode.EndLocation.Line > editor.Document.LineCount) endOffset = textLength; else endOffset = editor.Document.GetOffset(dataNode.EndLocation); node.AstNodeItem = dataNode; node.StartMarker = editor.Document.CreateAnchor(MinMax(startOffset, 0, textLength)); node.EndMarker = editor.Document.CreateAnchor(MinMax(endOffset, 0, textLength)); node.Editor = editor; node.Parent = parentNode; if (AstNodeHelper.IsDocument(dataNode)) AstNodeHelper.SetDocumentNodeInfos(node, dataNode); if (AstNodeHelper.IsNameSpace(dataNode)) AstNodeHelper.SetNameSpaceNodeInfos(node, dataNode); if (AstNodeHelper.IsRegionStart(dataNode)) AstNodeHelper.SetRegionStartInfos(node, dataNode); if (AstNodeHelper.IsRegionEnd(dataNode)) AstNodeHelper.SetRegionEndInfos(node, dataNode); if (AstNodeHelper.IsClass(dataNode)) AstNodeHelper.SetClassNodeInfos(node, dataNode); if (AstNodeHelper.IsInterface(dataNode)) AstNodeHelper.SetInterfaceNodeInfos(node, dataNode); if (AstNodeHelper.IsConstructor(dataNode)) AstNodeHelper.SetConstructorNodeInfos(node, dataNode); if (AstNodeHelper.IsField(dataNode)) AstNodeHelper.SetFieldNodeInfos(node, dataNode); if (AstNodeHelper.IsProperty(dataNode)) AstNodeHelper.SetPropertyNodeInfos(node, dataNode); if (AstNodeHelper.IsMethod(dataNode)) AstNodeHelper.SetMethodNodeInfos(node, dataNode); if (AstNodeHelper.IsEvent(dataNode)) AstNodeHelper.SetEventNodeInfos(node, dataNode); if (AstNodeHelper.IsDelegate(dataNode)) AstNodeHelper.SetDelegateNodeInfos(node, dataNode); if (AstNodeHelper.IsIndexer(dataNode)) AstNodeHelper.SetIndexerNodeInfos(node, dataNode); if (AstNodeHelper.IsEnum(dataNode)) AstNodeHelper.SetEnumNodeInfos(node, dataNode); if (AstNodeHelper.IsEnumMember(dataNode)) AstNodeHelper.SetEnumMemberNodeInfos(node, dataNode); if (AstNodeHelper.IsStruct(dataNode)) AstNodeHelper.SetStructNodeInfos(node, dataNode); if (AstNodeHelper.IsOperator(dataNode)) AstNodeHelper.SetOperatorNodeInfos(node, dataNode); }
CSharpOutlineNode BuildNode(CSharpOutlineNode parentNode, AstNode dataNode) { var node = new CSharpOutlineNode(); SetNodeInfos(node, parentNode, dataNode); // Filter the children, for only the needed/wanted nodes var dataChildren = dataNode.Children.Where(v => AstNodeHelper.IsAllowedNode(v)).ToList(); foreach (var child in dataChildren) { node.Children.Add(BuildNode(node, child)); } return node; }
internal static void SetIndexerNodeInfos(CSharpOutlineNode node, AstNode dataNode) { var indexerNode = (IndexerDeclaration)dataNode; node.Name = indexerNode.ReturnType.ToString() + " " + indexerNode.ThisToken.ToString() + indexerNode.LBracketToken + GetParameterDeclsAsString(indexerNode.Parameters) + indexerNode.RBracketToken; if (colorizeNode) node.ForegroundBrush = Brushes.Black; if (showExtendedInfos) { node.Name += " " + indexerNode.LBraceToken + " " + indexerNode.Getter.Keyword + (!string.IsNullOrEmpty(indexerNode.Getter.Keyword.ToString()) ? ";" : "") + " " + indexerNode.Setter.Keyword + (!string.IsNullOrEmpty(indexerNode.Setter.Keyword.ToString()) ? ";" : "") + " " + indexerNode.RBraceToken; } switch(GetAccessModifier(dataNode)) { case Modifiers.Public: node.IconName = "Icons.16x16.Property"; break; case Modifiers.Protected: node.IconName = "Icons.16x16.ProtectedProperty"; break; default: node.IconName = "Icons.16x16.PrivateProperty"; break; } }
internal static void SetEnumMemberNodeInfos(CSharpOutlineNode node, AstNode dataNode) { var enumMemberNode = (EnumMemberDeclaration)dataNode; node.Name = enumMemberNode.Name; if (colorizeNode) node.ForegroundBrush = Brushes.Black; node.IconName = "Icons.16x16.Enum"; }
internal static void SetNameSpaceNodeInfos(CSharpOutlineNode node, AstNode dataNode) { var nameSpaceNode = (NamespaceDeclaration)dataNode; node.Name = nameSpaceNode.Name; node.IconName = "Icons.16x16.NameSpace"; node.IsExpanded = true; if (colorizeNode) node.ForegroundBrush = (nameSpaceHighLighting.Foreground as SimpleHighlightingBrush).GetBrush(null); // node.Weight = nameSpaceHighLighting.FontWeight != null ? nameSpaceHighLighting.FontWeight.Value : FontWeights.Normal; }
internal static void SetClassNodeInfos(CSharpOutlineNode node, AstNode dataNode) { var typeNode = (TypeDeclaration)dataNode; node.Name = typeNode.Name + typeNode.LChevronToken + GetTypeParameterDeclsAsString(typeNode.TypeParameters) + typeNode.RChevronToken; node.IsExpanded = true; if (colorizeNode) node.ForegroundBrush = (classHighLighting.Foreground as SimpleHighlightingBrush).GetBrush(null); // node.Weight = classHighLighting.FontWeight != null ? classHighLighting.FontWeight.Value : FontWeights.Normal; switch(GetAccessModifier(dataNode)) { case Modifiers.Public: node.IconName = "Icons.16x16.Class"; break; case Modifiers.Protected: node.IconName = "Icons.16x16.ProtectedClass"; break; case Modifiers.Private: node.IconName = "Icons.16x16.PrivateClass"; break; default: node.IconName = "Icons.16x16.InternalClass"; break; } }
internal static void SetDocumentNodeInfos(CSharpOutlineNode node, AstNode dataNode) { node.Name = Path.GetFileName(((SyntaxTree)dataNode).FileName); node.IconName = "C#.File.FullFile"; node.IsExpanded = true; node.Weight = FontWeights.Bold; if (colorizeNode) node.ForegroundBrush = Brushes.Black; }
void FindNodeFromLocation(TextLocation location, CSharpOutlineNode node) { if (node == null) return; if (node.StartMarker.IsDeleted || node.EndMarker.IsDeleted) return; if (location.IsInside(node.StartMarker.Location, node.EndMarker.Location) && (selectedNode == null || IsRangeInside(selectedNode.AstNodeItem.StartLocation, selectedNode.AstNodeItem.EndLocation, node.AstNodeItem.StartLocation, node.AstNodeItem.EndLocation))) { selectedNode = node; } foreach(var child in node.Children) { FindNodeFromLocation(location, child as CSharpOutlineNode); } }