public EditorScript(ITextEditor editor, SDRefactoringContext context, AlFormattingOptions formattingOptions)
     : base(editor.Document, formattingOptions, context.TextEditorOptions)
 {
     this.editor  = editor;
     this.context = context;
     this.textSegmentCollection = new TextSegmentCollection <TextSegment>((TextDocument)editor.Document);
 }
Exemple #2
0
 private AlFormattingOptionsContainer(AlFormattingOptionsContainer parent, HashSet <string> activeOptions)
 {
     this.parent = parent;
     if (parent != null)
     {
         parent.PropertyChanged += HandlePropertyChanged;
     }
     this.activeOptions = activeOptions;
     Reset();
     cachedOptions = CreateCachedOptions();
 }
Exemple #3
0
 /// <summary>
 /// Clones all properties from another options container.
 /// </summary>
 /// <returns>Clone of options container.</returns>
 public void CloneFrom(AlFormattingOptionsContainer options)
 {
     activeOptions.Clear();
     foreach (var activeOption in options.activeOptions)
     {
         activeOptions.Add(activeOption);
     }
     cachedOptions       = options.cachedOptions.Clone();
     indentationSize     = options.indentationSize;
     convertTabsToSpaces = options.convertTabsToSpaces;
     OnPropertyChanged(null);
 }
Exemple #4
0
 /// <summary>
 /// Resets all container's options to given <see cref="ICSharpCode.NRefactory.Al.AlFormattingOptions"/> instance.
 /// </summary>
 /// <param name="options">Option values to set in container. <c>null</c> (default) to use empty options.</param>
 public void Reset(AlFormattingOptions options = null)
 {
     activeOptions.Clear();
     cachedOptions = options ?? CreateCachedOptions();
     if ((options != null) || (parent == null))
     {
         // Activate all options
         foreach (var property in typeof(AlFormattingOptions).GetProperties())
         {
             activeOptions.Add(property.Name);
         }
     }
     OnPropertyChanged(null);
 }
Exemple #5
0
 private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if ((e.PropertyName == "Parent") || (e.PropertyName == null))
     {
         // All properties might have changed -> update everything
         cachedOptions = CreateCachedOptions();
     }
     else if (e.PropertyName == IndentationSizePropertyName)
     {
         if (!indentationSize.HasValue)
         {
             indentationSize = GetEffectiveIndentationSize();
         }
     }
     else if (e.PropertyName == ConvertTabsToSpacesPropertyName)
     {
         if (!convertTabsToSpaces.HasValue)
         {
             convertTabsToSpaces = GetEffectiveConvertTabsToSpaces();
         }
     }
     else
     {
         // Some other property has changed, check if we have our own value for it
         if (!activeOptions.Contains(e.PropertyName))
         {
             // We rely on property value from some of the parents and have to update it from there
             PropertyInfo propertyInfo = typeof(AlFormattingOptions).GetProperty(e.PropertyName);
             if (propertyInfo != null)
             {
                 var val = GetEffectiveOption(e.PropertyName);
                 propertyInfo.SetValue(cachedOptions, val);
             }
         }
     }
 }
Exemple #6
0
        public static IReadOnlyDictionary <AstNode, ISegment> WriteNode(StringWriter writer, AstNode node, AlFormattingOptions policy, ITextEditorOptions editorOptions)
        {
            var formatter = new SegmentTrackingOutputFormatter(writer);

            formatter.IndentationString = editorOptions.IndentationString;
            var visitor = new AlOutputVisitor(formatter, policy);

            node.AcceptVisitor(visitor);
            return(formatter.Segments);
        }