| 0: | // CommentTagInserter.cs | |
| 1: | // Copyright (c) 2000 Mike Krueger | |
| 2: | // | |
| 3: | // This program is free software; you can redistribute it and/or modify | |
| 4: | // it under the terms of the GNU General Public License as published by | |
| 5: | // the Free Software Foundation; either version 2 of the License, or | |
| 6: | // (at your option) any later version. | |
| 7: | // | |
| 8: | // This program is distributed in the hope that it will be useful, | |
| 9: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11: | // GNU General Public License for more details. | |
| 12: | // | |
| 13: | // You should have received a copy of the GNU General Public License | |
| 14: | // along with this program; if not, write to the Free Software | |
| 15: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 16: | ||
| 17: | using System; | |
| 18: | using System.Drawing; | |
| 19: | ||
| 20: | using SharpDevelop.Tool.Data; | |
| 21: | ||
| 22: | namespace SharpDevelop.Internal.Text { | |
| 23: | ||
| 24: | /// <summary> | |
| 25: | /// This class inserts the auto comments in the textbuffer after return | |
| 26: | /// </summary> | |
| 27: | public class CommentTagInserter | |
| 28: | { | |
| 29: | public static int InsertCommentTag(TextBuffer buffer, int line, int xpos) | |
| 30: | { | |
| 31: | if (line <= 0) | |
| 32: | return buffer[line].Text.Length; | |
| 33: | ||
| 34: | if (buffer[line - 1].Span) { | |
| 35: | if (buffer[line - 1].BlockSpanOn) { // case for /* style comments | |
| 36: | Point p; | |
| 37: | ||
| 38: | int pos = buffer[line].Text.Length - 1; | |
| 39: | int length = pos; | |
| 40: | // insert spaces, if the /* is not in the first column | |
| 41: | // the * must be under the * from /* | |
| 42: | int len = buffer[line - 1].Text.Length; | |
| 43: | for (int i = 0; i < len; ++i) { | |
| 44: | if (i + 1 < len && | |
| 45: | buffer[line - 1].Text[i] == '/' && | |
| 46: | buffer[line - 1].Text[i + 1] == '*') { | |
| 47: | length = i; | |
| 48: | break; | |
| 49: | } | |
| 50: | } | |
| 51: | ||
| 52: | while (pos < length) { | |
| 53: | buffer.Insert(new Point(buffer[line].Text.Length, line), " "); | |
| 54: | ++pos; | |
| 55: | } | |
| 56: | ||
| 57: | // don't insert '*', if the line above doesn't contain a '*' at the beginning | |
| 58: | if (pos + 1 < buffer[line - 1].Text.Length && buffer[line - 1].Text[pos + 1] == '*') { | |
| 59: | p = buffer.Insert(new Point(buffer[line].Text.Length, line), "* "); | |
| 60: | return p.X; | |
| 61: | } else { | |
| 62: | p = buffer.Insert(new Point(buffer[line].Text.Length, line), ""); | |
| 63: | return p.X; | |
| 64: | } | |
| 65: | } else { | |
| 66: | bool foundnext = false; | |
| 67: | // search /// marks in the next line (if any, a /// will be inserted later) | |
| 68: | if (line + 1 < buffer.Length) | |
| 69: | for (int i = 0; i < buffer[line + 1].Text.Length; ++i) { | |
| 70: | if (i + 2 < buffer[line - 1].Text.Length && | |
| 71: | buffer[line + 1].Text[i] == '/' && | |
| 72: | buffer[line + 1].Text[i + 1] == '/' && | |
| 73: | buffer[line + 1].Text[i + 2] == '/') { | |
| 74: | foundnext = true; | |
| 75: | break; | |
| 76: | } | |
| 77: | } | |
| 78: | ||
| 79: | bool foundmark = false; | |
| 80: | int len = buffer[line - 1].Text.Length; | |
| 81: | for (int i = 0; i < len; ++i) { | |
| 82: | if (i + 2 < len && // search if the actual line conains an /// tag | |
| 83: | buffer[line - 1].Text[i] == '/' && | |
| 84: | buffer[line - 1].Text[i + 1] == '/' && | |
| 85: | buffer[line - 1].Text[i + 2] == '/') { | |
| 86: | foundmark = true; | |
| 87: | } | |
| 88: | if (!foundmark && (!Char.IsWhiteSpace(buffer[line - 1].Text[i]))) { | |
| 89: | break; | |
| 90: | } | |
| 91: | // if the actual line contains a /// tag and some text after, or the next line contains | |
| 92: | // a /// tag, a /// tag will be inserted in the newly created line. | |
| 93: | if (foundmark && (!Char.IsWhiteSpace(buffer[line - 1].Text[i]) && buffer[line - 1].Text[i] != '/') || foundnext) { | |
| 94: | Point p = buffer.Insert(new Point(buffer[line].Text.Length, line), "/// "); | |
| 95: | return p.X; | |
| 96: | } | |
| 97: | } | |
| 98: | } | |
| 99: | } | |
| 100: | return xpos; | |
| 101: | } | |
| 102: | } | |
| 103: | } |
This page was automatically generated by SharpDevelop.