Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs79
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs5
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/ExpansionObject.cs5
3 files changed, 50 insertions, 39 deletions
diff --git a/main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs b/main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
index fa155f691c..50188e197b 100644
--- a/main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
+++ b/main/src/core/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
@@ -173,45 +173,54 @@ namespace Mono.TextEditor
Replace (offset, count, null);
}
- public int Replace (int offset, int count, string value)
+ public string FormatString (DocumentLocation loc, string str)
{
+ if (string.IsNullOrEmpty (str))
+ return "";
StringBuilder sb = new StringBuilder ();
- if (value != null) {
- bool convertTabs = Options.TabsToSpaces;
- DocumentLocation loc = Document.OffsetToLocation (offset);
- for (int i = 0; i < value.Length; i++) {
- char ch = value[i];
- switch (ch) {
- case '\u00A0': // convert non breaking spaces to standard spaces.
- sb.Append (' ');
- break;
- case '\t':
- if (convertTabs) {
- int tabWidth = TextViewMargin.GetNextTabstop (this, loc.Column) - loc.Column;
- sb.Append (new string (' ', tabWidth));
- loc.Column += tabWidth;
- } else
- goto default;
- break;
- case '\r':
- if (i + 1 < value.Length && value[i + 1] == '\n')
- i++;
- goto case '\n';
- case '\n':
- sb.Append (EolMarker);
- loc.Line++;
- loc.Column = 0;
- break;
- default:
- sb.Append (ch);
- loc.Column++;
- break;
- }
+ bool convertTabs = Options.TabsToSpaces;
+ for (int i = 0; i < str.Length; i++) {
+ char ch = str[i];
+ switch (ch) {
+ case '\u00A0': // convert non breaking spaces to standard spaces.
+ sb.Append (' ');
+ break;
+ case '\t':
+ if (convertTabs) {
+ int tabWidth = TextViewMargin.GetNextTabstop (this, loc.Column) - loc.Column;
+ sb.Append (new string (' ', tabWidth));
+ loc.Column += tabWidth;
+ } else
+ goto default;
+ break;
+ case '\r':
+ if (i + 1 < str.Length && str[i + 1] == '\n')
+ i++;
+ goto case '\n';
+ case '\n':
+ sb.Append (EolMarker);
+ loc.Line++;
+ loc.Column = 0;
+ break;
+ default:
+ sb.Append (ch);
+ loc.Column++;
+ break;
}
}
-
- ((IBuffer)document).Replace (offset, count, sb.ToString ());
- return sb.Length;
+ return sb.ToString ();
+ }
+
+ public string FormatString (int offset, string str)
+ {
+ return FormatString (Document.OffsetToLocation (offset), str);
+ }
+
+ public int Replace (int offset, int count, string value)
+ {
+ string formattedString = FormatString (offset, value);
+ ((IBuffer)document).Replace (offset, count, formattedString);
+ return formattedString.Length;
}
public void InsertAtCaret (string text)
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs
index c627598c3e..fbfc339ad0 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs
@@ -209,7 +209,8 @@ namespace MonoDevelop.Ide.CodeTemplates
TemplateResult result = new TemplateResult ();
StringBuilder sb = new StringBuilder ();
int lastOffset = 0;
- string code = context.TemplateCode;
+ string code = context.Document.Editor.FormatString (context.InsertPosition, context.TemplateCode);
+
result.TextLinks = new List<TextLink> ();
foreach (Match match in variableRegEx.Matches (code)) {
string name = match.Groups[1].Value;
@@ -364,7 +365,7 @@ namespace MonoDevelop.Ide.CodeTemplates
Document = document,
ProjectDom = dom,
ParsedDocument = doc,
- InsertPosition = new DomLocation (data.Caret.Line + 1, data.Caret.Column + 1),
+ InsertPosition = data.Caret.Location,
LineIndent = data.Document.GetLineIndent (data.Caret.Line),
TemplateCode = IndentCode (Code, document.Editor.EolMarker, data.Document.GetLineIndent (data.Caret.Line))
};
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/ExpansionObject.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/ExpansionObject.cs
index 47063eee26..57fdcfcc6d 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/ExpansionObject.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/ExpansionObject.cs
@@ -34,6 +34,7 @@ using MonoDevelop.Projects.Dom;
using MonoDevelop.Projects.Dom.Parser;
using MonoDevelop.Projects.Dom.Output;
using Mono.TextEditor.PopupWindow;
+using Mono.TextEditor;
namespace MonoDevelop.Ide.CodeTemplates
{
@@ -53,7 +54,7 @@ namespace MonoDevelop.Ide.CodeTemplates
set;
}
- public DomLocation InsertPosition {
+ public DocumentLocation InsertPosition {
get;
set;
}
@@ -183,7 +184,7 @@ namespace MonoDevelop.Ide.CodeTemplates
if (CurrentContext.ParsedDocument == null)
return fullTypeName;
- return CurrentContext.ParsedDocument.CompilationUnit.ShortenTypeName (new DomReturnType (fullTypeName), CurrentContext.InsertPosition).FullName;
+ return CurrentContext.ParsedDocument.CompilationUnit.ShortenTypeName (new DomReturnType (fullTypeName), CurrentContext.InsertPosition.Line + 1, CurrentContext.InsertPosition.Column + 1).FullName;
}
static Regex functionRegEx = new Regex ("([^(]*)\\(([^(]*)\\)", RegexOptions.Compiled);