5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
using System.Collections.Generic;
29
namespace ICSharpCode.NRefactory.CSharp
31
public enum IndentType {
39
readonly Stack<IndentType> indentStack = new Stack<IndentType> ();
40
readonly TextEditorOptions options;
44
public Indent(TextEditorOptions options)
46
this.options = options;
50
public void Push(IndentType type)
52
indentStack.Push(type);
53
curIndent += GetIndent(type);
59
curIndent -= GetIndent(indentStack.Pop());
63
int GetIndent(IndentType indentType)
66
case IndentType.Block:
67
return options.IndentSize;
68
case IndentType.Continuation:
69
return options.ContinuationIndent;
70
case IndentType.Label:
71
return options.LabelIndent;
73
throw new ArgumentOutOfRangeException();
79
if (options.TabsToSpaces) {
80
indentString = new string(' ', curIndent);
83
indentString = new string('\t', curIndent / options.TabSize) + new string(' ', curIndent % options.TabSize) + new string (' ', ExtraSpaces);
88
public int ExtraSpaces {
99
public string IndentString {
105
public override string ToString()
107
return string.Format("[Indent: curIndent={0}]", curIndent);