本文整理汇总了C#中ScintillaNet.GetLine方法的典型用法代码示例。如果您正苦于以下问题:C# ScintillaNet.GetLine方法的具体用法?C# ScintillaNet.GetLine怎么用?C# ScintillaNet.GetLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScintillaNet
的用法示例。
在下文中一共展示了ScintillaNet.GetLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateMarkers
/// <summary>
/// Update document bookmarks
/// </summary>
/// <param name="sender"></param>
private void UpdateMarkers( ScintillaNet.ScintillaControl sender )
{
ITabbedDocument document = (ITabbedDocument)sender.Parent;
List<int> markers = GetMarkers(sender);
ListViewGroup group = FindGroup(document);
if (group != null)
{
if (true)
{
this.RemoveItemsFromGroup(group);
ListViewItem[] items = new ListViewItem[markers.Count];
ListViewItem item;
int index = 0;
foreach (int marker in markers)
{
item = new ListViewItem(new string[]{
(marker+1).ToString(), sender.GetLine(marker).TrimStart() },
-1);
item.Group = group;
item.Tag = marker;
item.Name = (string)((Hashtable)group.Tag)["FileName"];
items[index] = item;
index++;
}
this.listView1.BeginUpdate();
this.listView1.Items.AddRange(items);
((Hashtable)group.Tag)["Markers"] = markers;
this.listView1.EndUpdate();
}
else
{
}
}
}
示例2: HandleStructureCompletion
static private bool HandleStructureCompletion(ScintillaNet.ScintillaControl Sci)
{
try
{
int position = Sci.CurrentPos;
int line = Sci.LineFromPosition(position);
if (line == 0)
return false;
string txt = Sci.GetLine(line-1);
int style = Sci.BaseStyleAt(position);
int eolMode = Sci.EOLMode;
// box comments
if (IsCommentStyle(style) && (Sci.BaseStyleAt(position+1) == style))
{
txt = txt.Trim();
if (txt.StartsWith("/*") || txt.StartsWith("*"))
{
Sci.ReplaceSel("* ");
position = Sci.LineIndentPosition(line)+2;
Sci.SetSel(position,position);
return true;
}
}
// braces
else if (txt.TrimEnd().EndsWith("{") && (line > 1))
{
// find matching brace
int bracePos = Sci.LineEndPosition(line-1)-1;
while ((bracePos > 0) && (Sci.CharAt(bracePos) != '{')) bracePos--;
if (bracePos == 0 || Sci.BaseStyleAt(bracePos) != 10) return true;
int match = Sci.SafeBraceMatch(bracePos);
DebugConsole.Trace("match "+bracePos+" "+match);
int start = line;
int indent = Sci.GetLineIndentation(start-1);
if (match > 0)
{
int endIndent = Sci.GetLineIndentation(Sci.LineFromPosition(match));
if (endIndent+Sci.TabWidth > indent)
return false;
}
// find where to include the closing brace
int startIndent = indent;
int newIndent = indent+Sci.TabWidth;
int count = Sci.LineCount;
int lastLine = line;
line++;
while (line < count-1)
{
txt = Sci.GetLine(line).TrimEnd();
if (txt.Length != 0) {
indent = Sci.GetLineIndentation(line);
DebugConsole.Trace("indent "+(line+1)+" "+indent+" : "+txt);
if (indent <= startIndent) break;
lastLine = line;
}
else break;
line++;
}
if (line >= count-1) lastLine = start;
// insert closing brace
DebugConsole.Trace("Insert at "+position);
position = Sci.LineEndPosition(lastLine);
Sci.InsertText(position, ASContext.MainForm.GetNewLineMarker(eolMode)+"}");
Sci.SetLineIndentation(lastLine+1, startIndent);
return false;
}
}
catch (Exception ex)
{
ErrorHandler.ShowError(ex.Message, ex);
}
return false;
}
示例3: LineIndentPosition
private string LineIndentPosition(ScintillaNet.ScintillaControl sci, int line)
{
string txt = sci.GetLine(line);
for (int i = 0; i < txt.Length; i++)
if (txt[i] > 32) return txt.Substring(0, i);
return "";
}
示例4: MakePrivate
public static bool MakePrivate(ScintillaNet.ScintillaControl Sci, MemberModel member)
{
ContextFeatures features = ASContext.Context.Features;
string visibility = GetPrivateKeyword();
if (features.publicKey == null || visibility == null) return false;
Regex rePublic = new Regex(String.Format(@"\s*({0})\s+", features.publicKey));
string line;
Match m;
int index, position;
for (int i = member.LineFrom; i <= member.LineTo; i++)
{
line = Sci.GetLine(i);
m = rePublic.Match(line);
if (m.Success)
{
index = Sci.MBSafeTextLength(line.Substring(0, m.Groups[1].Index));
position = Sci.PositionFromLine(i) + index;
Sci.SetSel(position, position + features.publicKey.Length);
Sci.ReplaceSel(visibility);
UpdateLookupPosition(position, features.publicKey.Length - visibility.Length);
return true;
}
}
return false;
}
示例5: GenerateOverride
static public void GenerateOverride(ScintillaNet.ScintillaControl Sci, ClassModel ofClass, MemberModel member, int position)
{
ContextFeatures features = ASContext.Context.Features;
List<string> typesUsed = new List<string>();
bool isProxy = (member.Namespace == "flash_proxy");
if (isProxy) typesUsed.Add("flash.utils.flash_proxy");
bool isAS2Event = ASContext.Context.Settings.LanguageId == "AS2" && member.Name.StartsWith("on");
bool isObjectMethod = ofClass.QualifiedName == "Object";
int line = Sci.LineFromPosition(position);
string currentText = Sci.GetLine(line);
int startPos = currentText.Length;
GetStartPos(currentText, ref startPos, features.privateKey);
GetStartPos(currentText, ref startPos, features.protectedKey);
GetStartPos(currentText, ref startPos, features.internalKey);
GetStartPos(currentText, ref startPos, features.publicKey);
GetStartPos(currentText, ref startPos, features.staticKey);
GetStartPos(currentText, ref startPos, features.overrideKey);
startPos += Sci.PositionFromLine(line);
FlagType flags = member.Flags;
string acc = "";
string decl = "";
if (features.hasNamespaces && !string.IsNullOrEmpty(member.Namespace) && member.Namespace != "internal")
acc = member.Namespace;
else if ((member.Access & Visibility.Public) > 0) acc = features.publicKey;
else if ((member.Access & Visibility.Internal) > 0) acc = features.internalKey;
else if ((member.Access & Visibility.Protected) > 0) acc = features.protectedKey;
else if ((member.Access & Visibility.Private) > 0 && features.methodModifierDefault != Visibility.Private)
acc = features.privateKey;
bool isStatic = (flags & FlagType.Static) > 0;
if (isStatic) acc = features.staticKey + " " + acc;
if (!isAS2Event && !isObjectMethod)
acc = features.overrideKey + " " + acc;
acc = Regex.Replace(acc, "[ ]+", " ").Trim();
if ((flags & (FlagType.Getter | FlagType.Setter)) > 0)
{
string type = member.Type;
string name = member.Name;
if (member.Parameters != null && member.Parameters.Count == 1)
type = member.Parameters[0].Type;
type = FormatType(type);
if (type == null && !features.hasInference) type = features.objectKey;
bool genGetter = ofClass.Members.Search(name, FlagType.Getter, 0) != null;
bool genSetter = ofClass.Members.Search(name, FlagType.Setter, 0) != null;
if (isHaxe)
{
// property is public but not the methods
acc = features.overrideKey;
}
if (genGetter)
{
string tpl = TemplateUtils.GetTemplate("OverrideGetter", "Getter");
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Modifiers", acc);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Name", name);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Type", type);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Member", "super." + name);
decl += tpl;
}
if (genSetter)
{
string tpl = TemplateUtils.GetTemplate("OverrideSetter", "Setter");
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Modifiers", acc);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Name", name);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Type", type);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Member", "super." + name);
tpl = TemplateUtils.ReplaceTemplateVariable(tpl, "Void", ASContext.Context.Features.voidKey ?? "void");
if (decl.Length > 0)
{
tpl = "\n\n" + tpl.Replace("$(EntryPoint)", "");
}
decl += tpl;
}
decl = TemplateUtils.ReplaceTemplateVariable(decl, "BlankLine", "");
}
else
{
string type = FormatType(member.Type);
//if (type == null) type = features.objectKey;
decl = acc + features.functionKey + " ";
bool noRet = type == null || type.Equals("void", StringComparison.OrdinalIgnoreCase);
type = (noRet && type != null) ? ASContext.Context.Features.voidKey : type;
if (!noRet)
{
string qType = getQualifiedType(type, ofClass);
typesUsed.Add(qType);
if (qType == type)
{
ClassModel rType = ASContext.Context.ResolveType(type, ofClass.InFile);
if (!rType.IsVoid()) type = rType.Name;
}
}
//.........这里部分代码省略.........
示例6: EventMetatag
private static void EventMetatag(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member)
{
ASResult resolve = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(Sci.CurrentPos, true));
string line = Sci.GetLine(inClass.LineFrom);
int position = Sci.PositionFromLine(inClass.LineFrom) + (line.Length - line.TrimStart().Length);
string value = resolve.Member.Value;
if (value != null)
{
if (value.StartsWith("\""))
{
value = value.Trim(new char[] { '"' });
}
else if (value.StartsWith("'"))
{
value = value.Trim(new char[] { '\'' });
}
}
else value = resolve.Member.Type;
if (value == "" || value == null)
return;
Regex re1 = new Regex("'(?:[^'\\\\]|(?:\\\\\\\\)|(?:\\\\\\\\)*\\\\.{1})*'");
Regex re2 = new Regex("\"(?:[^\"\\\\]|(?:\\\\\\\\)|(?:\\\\\\\\)*\\\\.{1})*\"");
Match m1 = re1.Match(value);
Match m2 = re2.Match(value);
if (m1.Success || m2.Success)
{
Match m = null;
if (m1.Success && m2.Success) m = m1.Index > m2.Index ? m2 : m1;
else if (m1.Success) m = m1;
else m = m2;
value = value.Substring(m.Index + 1, m.Length - 2);
}
string template = TemplateUtils.GetTemplate("EventMetatag");
template = TemplateUtils.ReplaceTemplateVariable(template, "Name", value);
template = TemplateUtils.ReplaceTemplateVariable(template, "Type", contextParam);
template += "\n$(Boundary)";
AddLookupPosition();
Sci.CurrentPos = position;
Sci.SetSel(position, position);
InsertCode(position, template);
}
示例7: FindNewVarPosition
private static int FindNewVarPosition(ScintillaNet.ScintillaControl Sci, ClassModel inClass, MemberModel latest)
{
firstVar = false;
// found a var?
if ((latest.Flags & FlagType.Variable) > 0)
return Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1);
// add as first member
int line = 0;
int maxLine = Sci.LineCount;
if (inClass != null)
{
line = inClass.LineFrom;
maxLine = inClass.LineTo;
}
else if (ASContext.Context.InPrivateSection) line = ASContext.Context.CurrentModel.PrivateSectionIndex;
else maxLine = ASContext.Context.CurrentModel.PrivateSectionIndex;
while (line < maxLine)
{
string text = Sci.GetLine(line++);
if (text.IndexOf('{') >= 0)
{
firstVar = true;
return Sci.PositionFromLine(line) - ((Sci.EOLMode == 0) ? 2 : 1);
}
}
return -1;
}
示例8: GenerateOverride
static public void GenerateOverride(ScintillaNet.ScintillaControl Sci, ClassModel ofClass, MemberModel member, int position)
{
ContextFeatures features = ASContext.Context.Features;
List<string> typesUsed = new List<string>();
bool isProxy = (member.Namespace == "flash_proxy");
if (isProxy) typesUsed.Add("flash.utils.flash_proxy");
bool isAS2Event = ASContext.Context.Settings.LanguageId == "AS2" && member.Name.StartsWith("on");
bool isObjectMethod = ofClass.QualifiedName == "Object";
int line = Sci.LineFromPosition(position);
string currentText = Sci.GetLine(line);
int startPos = currentText.Length;
GetStartPos(currentText, ref startPos, features.privateKey);
GetStartPos(currentText, ref startPos, features.protectedKey);
GetStartPos(currentText, ref startPos, features.internalKey);
GetStartPos(currentText, ref startPos, features.publicKey);
GetStartPos(currentText, ref startPos, features.staticKey);
GetStartPos(currentText, ref startPos, features.overrideKey);
startPos += Sci.PositionFromLine(line);
FlagType flags = member.Flags;
string acc = "";
string decl = "";
if (features.hasNamespaces && member.Namespace != null
&& member.Namespace.Length > 0 && member.Namespace != "internal")
acc = member.Namespace;
else if ((member.Access & Visibility.Public) > 0) acc = features.publicKey;
else if ((member.Access & Visibility.Internal) > 0) acc = features.internalKey;
else if ((member.Access & Visibility.Protected) > 0) acc = features.protectedKey;
else if ((member.Access & Visibility.Private) > 0) acc = features.privateKey;
bool isStatic = (flags & FlagType.Static) > 0;
if (isStatic) acc = features.staticKey + " " + acc;
if (!isAS2Event && !isObjectMethod)
acc = features.overrideKey + " " + acc;
if ((flags & (FlagType.Getter | FlagType.Setter)) > 0)
{
string type = member.Type;
string name = member.Name;
if (member.Parameters != null && member.Parameters.Count > 0)
type = member.Parameters[0].Type;
type = FormatType(type);
if (type == null)
{
string message = String.Format(TextHelper.GetString("Info.TypeDeclMissing"), member.Name);
ErrorManager.ShowInfo(message);
return;
}
if (ofClass.Members.Search(name, FlagType.Getter, 0) != null)
{
decl += String.Format(GetTemplate("Getter"),
acc, name, type, "super." + name);
}
if (ofClass.Members.Search(name, FlagType.Setter, 0) != null)
{
string tpl = GetTemplate("Setter");
if (decl.Length > 0)
{
decl += "\n\n";
tpl = tpl.Replace("$(EntryPoint)", "");
}
decl += String.Format(tpl,
acc, name, type, "super." + name, ASContext.Context.Features.voidKey ?? "void");
}
}
else
{
string type = FormatType(member.Type);
if (type == null)
{
string message = String.Format(TextHelper.GetString("Info.TypeDeclMissing"), member.Name);
ErrorManager.ShowInfo(message);
return;
}
if (acc.Length > 0) acc += " ";
decl = acc + features.functionKey + " ";
bool noRet = type.Equals("void", StringComparison.OrdinalIgnoreCase);
type = (noRet) ? ASContext.Context.Features.voidKey : type;
if (!noRet) typesUsed.Add(getQualifiedType(type, ofClass));
string action = (isProxy || isAS2Event) ? "" : GetSuperCall(member, typesUsed, ofClass);
decl += member.Name
+ String.Format(GetTemplate("MethodOverride"), member.ParametersString(true), type, action);
}
Sci.BeginUndoAction();
try
{
if (ASContext.Context.Settings.GenerateImports && typesUsed.Count > 0)
{
int offset = AddImportsByName(typesUsed, line);
position += offset;
startPos += offset;
}
Sci.SetSel(startPos, position + member.Name.Length);
InsertCode(startPos, decl);
}
//.........这里部分代码省略.........
示例9: ContextualGenerator
static public void ContextualGenerator(ScintillaNet.ScintillaControl Sci)
{
if (ASContext.Context is ASContext)
(ASContext.Context as ASContext).UpdateCurrentFile(false); // update model
lookupPosition = -1;
int position = Sci.CurrentPos;
if (Sci.BaseStyleAt(position) == 19) // on keyword
return;
int line = Sci.LineFromPosition(position);
contextToken = Sci.GetWordFromPosition(position);
contextMatch = null;
FoundDeclaration found = GetDeclarationAtLine(Sci, line);
string text = Sci.GetLine(line);
bool suggestItemDeclaration = false;
if (!String.IsNullOrEmpty(contextToken) && Char.IsDigit(contextToken[0]))
{
ShowConvertToConst(found);
return;
}
ASResult resolve = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(position, true));
// ignore automatic vars (MovieClip members)
if (resolve.Member != null &&
(((resolve.Member.Flags & FlagType.AutomaticVar) > 0)
|| (resolve.inClass != null && resolve.inClass.QualifiedName == "Object")))
{
resolve.Member = null;
resolve.Type = null;
}
if (found.inClass != ClassModel.VoidClass && contextToken != null)
{
if (resolve.Member == null && resolve.Type != null
&& (resolve.Type.Flags & FlagType.Interface) > 0) // implement interface
{
contextParam = resolve.Type.Type;
ShowImplementInterface(found);
return;
}
if (resolve.Member != null && !ASContext.Context.CurrentClass.IsVoid()
&& (resolve.Member.Flags & FlagType.LocalVar) > 0) // promote to class var
{
contextMember = resolve.Member;
ShowPromoteLocalAndAddParameter(found);
return;
}
if (resolve.Member == null && resolve.Type == null) // import declaration
{
if (CheckAutoImport(found))
{
return;
}
else
{
int stylemask = (1 << Sci.StyleBits) - 1;
if (ASComplete.IsTextStyle(Sci.StyleAt(position - 1) & stylemask))
{
suggestItemDeclaration = true;
}
}
}
}
if (found.member != null)
{
// private var -> property
if ((found.member.Flags & FlagType.Variable) > 0 && (found.member.Flags & FlagType.LocalVar) == 0)
{
// maybe we just want to import the member's non-imported type
Match m = Regex.Match(text, String.Format(patternVarDecl, found.member.Name, contextToken));
if (m.Success)
{
contextMatch = m;
ClassModel type = ASContext.Context.ResolveType(contextToken, ASContext.Context.CurrentModel);
if (type.IsVoid() && CheckAutoImport(found))
return;
}
// create property
ShowGetSetList(found);
return;
}
// inside a function
else if ((found.member.Flags & (FlagType.Function | FlagType.Getter | FlagType.Setter)) > 0
&& resolve.Member == null && resolve.Type == null)
{
if (contextToken != null)
{
// "generate event handlers" suggestion
Match m = Regex.Match(text, String.Format(patternEvent, contextToken), RegexOptions.IgnoreCase);
if (m.Success)
{
contextMatch = m;
contextParam = CheckEventType(m.Groups["event"].Value);
ShowEventList(found);
return;
//.........这里部分代码省略.........
示例10: HandleDocTagCompletion
static private bool HandleDocTagCompletion(ScintillaNet.ScintillaControl Sci)
{
if (ASContext.CommonSettings.JavadocTags == null || ASContext.CommonSettings.JavadocTags.Length == 0)
return false;
string txt = Sci.GetLine(Sci.LineFromPosition(Sci.CurrentPos)).TrimStart();
if (!Regex.IsMatch(txt, "^\\*[\\s]*\\@"))
return false;
// build tag list
if (docVariables == null)
{
docVariables = new List<ICompletionListItem>();
TagItem item;
foreach (string tag in ASContext.CommonSettings.JavadocTags)
{
item = new TagItem(tag);
docVariables.Add(item);
}
}
// show
CompletionList.Show(docVariables, true, "");
return true;
}
示例11: AssignStatementToVar
private static void AssignStatementToVar(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member)
{
int lineNum = Sci.LineFromPosition(Sci.CurrentPos);
string line = Sci.GetLine(lineNum);
StatementReturnType returnType = GetStatementReturnType(Sci, inClass, line, Sci.PositionFromLine(lineNum));
if (returnType == null)
{
return;
}
IASContext cntx = inClass.InFile.Context;
bool isAs3 = cntx.Settings.LanguageId == "AS3";
string voidWord = isAs3 ? "void" : "Void";
string type = null;
string varname = null;
string cleanType = null;
ASResult resolve = returnType.resolve;
int pos = returnType.position;
string word = returnType.word;
if (resolve != null && !resolve.IsNull())
{
if (resolve.Member != null && resolve.Member.Type != null)
{
type = resolve.Member.Type;
}
else if (resolve.Type != null && resolve.Type.Name != null)
{
type = returnType.resolve.Type.QualifiedName;
}
if (resolve.Member != null && resolve.Member.Name != null)
{
varname = GuessVarName(resolve.Member.Name, type);
}
}
if (word != null && Char.IsDigit(word[0])) word = null;
if (type == voidWord) type = null;
if (varname == null) varname = GuessVarName(word, type);
if (varname != null && varname == word)
varname = varname.Length == 1 ? varname + "1" : varname[0] + "";
if (type != null) cleanType = FormatType(GetShortType(type));
string template = TemplateUtils.GetTemplate("AssignVariable");
if (varname != null)
template = TemplateUtils.ReplaceTemplateVariable(template, "Name", varname);
else
template = TemplateUtils.ReplaceTemplateVariable(template, "Name", null);
if (cleanType != null)
template = TemplateUtils.ReplaceTemplateVariable(template, "Type", cleanType);
else
template = TemplateUtils.ReplaceTemplateVariable(template, "Type", null);
int indent = Sci.GetLineIndentation(lineNum);
pos = Sci.PositionFromLine(lineNum) + indent / Sci.Indent;
Sci.CurrentPos = pos;
Sci.SetSel(pos, pos);
InsertCode(pos, template);
if (type != null)
{
ClassModel inClassForImport = null;
if (resolve.InClass != null)
{
inClassForImport = resolve.InClass;
}
else if (resolve.RelClass != null)
{
inClassForImport = resolve.RelClass;
}
else
{
inClassForImport = inClass;
}
List<string> l = new List<string>();
l.Add(getQualifiedType(type, inClassForImport));
pos += AddImportsByName(l, Sci.LineFromPosition(pos));
}
}
示例12: HandleDocTagCompletion
static private bool HandleDocTagCompletion(ScintillaNet.ScintillaControl Sci)
{
string txt = Sci.GetLine(Sci.LineFromPosition(Sci.CurrentPos)).TrimStart();
if (!Regex.IsMatch(txt, "^\\*[\\s]*\\@"))
return false;
DebugConsole.Trace("Documentation tag completion");
// build tag list
if (docVariables == null)
{
docVariables = new ArrayList();
TagItem item;
string[] tags = ASContext.DocumentationTags.Split(' ');
foreach(string tag in tags)
{
item = new TagItem(tag);
docVariables.Add(item);
}
}
// show
CompletionList.Show(docVariables, true, "");
return true;
}
示例13: OnCompletionInsert
public override bool OnCompletionInsert(ScintillaNet.ScintillaControl sci, int position, string text)
{
bool isVector = false;
if (text == "Vector")
{
isVector = true;
}
if (isVector)
{
string insert = null;
string line = sci.GetLine(sci.LineFromPosition(position));
Match m = Regex.Match(line, @"\svar\s+(?<varname>.+)\s*:\s*Vector\.<(?<indextype>.+)(?=(>\s*=))");
if (m.Success)
{
insert = String.Format(".<{0}>()", m.Groups["indextype"].Value);
sci.InsertText(position + text.Length, insert);
sci.CurrentPos = position + text.Length + insert.Length;
sci.SetSel(sci.CurrentPos, sci.CurrentPos);
}
else
{
m = Regex.Match(line, @"\s*=");
if (m.Success)
{
ASResult result = ASComplete.GetExpressionType(sci, sci.PositionFromLine(sci.LineFromPosition(position)) + m.Index);
if (result != null && !result.IsNull() && result.Member != null && result.Member.Type != null)
{
m = Regex.Match(result.Member.Type, @"(?<=<).+(?=>)");
if (m.Success)
{
insert = String.Format(".<{0}>()", m.Value);
sci.InsertText(position + text.Length, insert);
sci.CurrentPos = position + text.Length + insert.Length;
sci.SetSel(sci.CurrentPos, sci.CurrentPos);
return true;
}
}
}
insert = ".<>";
sci.InsertText(position + text.Length, insert);
sci.CurrentPos = position + text.Length + 2;
sci.SetSel(sci.CurrentPos, sci.CurrentPos);
ASComplete.HandleAllClassesCompletion(sci, "", false, true);
}
return true;
}
return false;
}
示例14: GetExpression
/// <summary>
/// Find Actionscript expression at cursor position
/// </summary>
/// <param name="sci">Scintilla Control</param>
/// <param name="position">Cursor position</param>
/// <param name="ignoreWhiteSpace">Skip whitespace at position</param>
/// <returns></returns>
private static ASExpr GetExpression(ScintillaNet.ScintillaControl Sci, int position, bool ignoreWhiteSpace)
{
ASExpr expression = new ASExpr();
expression.Position = position;
expression.Separator = ' ';
// file's member declared at this position
expression.ContextMember = ASContext.Context.CurrentMember;
int minPos = 0;
string body = null;
if (expression.ContextMember != null)
{
minPos = Sci.PositionFromLine(expression.ContextMember.LineFrom);
StringBuilder sbBody = new StringBuilder();
for (int i = expression.ContextMember.LineFrom; i <= expression.ContextMember.LineTo; i++)
sbBody.Append(Sci.GetLine(i)).Append('\n');
body = sbBody.ToString();
//int tokPos = body.IndexOf(expression.ContextMember.Name);
//if (tokPos >= 0) minPos += tokPos + expression.ContextMember.Name.Length;
if ((expression.ContextMember.Flags & (FlagType.Function | FlagType.Constructor | FlagType.Getter | FlagType.Setter)) > 0)
{
expression.ContextFunction = expression.ContextMember;
expression.FunctionOffset = expression.ContextMember.LineFrom;
Match mStart = Regex.Match(body, "(\\)|[a-z0-9*.,-<>])\\s*{", RegexOptions.IgnoreCase);
if (mStart.Success)
{
// cleanup function body & offset
int pos = mStart.Index + mStart.Length;
expression.BeforeBody = (position < Sci.PositionFromLine(expression.ContextMember.LineFrom) + pos);
string pre = body.Substring(0, pos);
for (int i = 0; i < pre.Length - 1; i++)
if (pre[i] == '\r') { expression.FunctionOffset++; if (pre[i + 1] == '\n') i++; }
else if (pre[i] == '\n') expression.FunctionOffset++;
body = body.Substring(pos);
}
expression.FunctionBody = body;
}
else
{
int eqPos = body.IndexOf('=');
expression.BeforeBody = (eqPos < 0 || position < Sci.PositionFromLine(expression.ContextMember.LineFrom) + eqPos);
}
}
// get the word characters from the syntax definition
string characterClass = ScintillaNet.ScintillaControl.Configuration.GetLanguage(Sci.ConfigurationLanguage).characterclass.Characters;
// get expression before cursor
ContextFeatures features = ASContext.Context.Features;
int stylemask = (1 << Sci.StyleBits) - 1;
int style = (position >= minPos) ? Sci.StyleAt(position) & stylemask : 0;
StringBuilder sb = new StringBuilder();
StringBuilder sbSub = new StringBuilder();
int subCount = 0;
char c = ' ';
char c2;
int startPos = position;
int braceCount = 0;
int sqCount = 0;
int genCount = 0;
bool hasGenerics = features.hasGenerics;
bool hadWS = false;
bool hadDot = ignoreWhiteSpace;
bool inRegex = false;
char dot = features.dot[features.dot.Length - 1];
while (position > minPos)
{
position--;
style = Sci.StyleAt(position) & stylemask;
if (style == 14) // regex literal
{
inRegex = true;
}
else if (!ASComplete.IsCommentStyle(style))
{
c2 = c;
c = (char)Sci.CharAt(position);
// end of regex literal
if (inRegex)
{
inRegex = false;
if (expression.SubExpressions == null) expression.SubExpressions = new List<string>();
expression.SubExpressions.Add("");
sb.Insert(0, "RegExp.#" + (subCount++) + "~");
}
// array access
if (c == '[')
{
sqCount--;
if (sqCount == 0)
{
//.........这里部分代码省略.........
示例15: OnCompletionInsert
public override bool OnCompletionInsert(ScintillaNet.ScintillaControl sci, int position, string text, char trigger)
{
if (text == "Dictionary")
{
string insert = null;
string line = sci.GetLine(sci.LineFromPosition(position));
Match m = Regex.Match(line, @"\svar\s+(?<varname>.+)\s*:\s*Dictionary\.<(?<indextype>.+)(?=(>\s*=))");
if (m.Success)
{
insert = String.Format(".<{0}>", m.Groups["indextype"].Value);
}
else
{
m = Regex.Match(line, @"\s*=\s*new");
if (m.Success)
{
ASResult result = ASComplete.GetExpressionType(sci, sci.PositionFromLine(sci.LineFromPosition(position)) + m.Index);
if (result != null && !result.IsNull() && result.Member != null && result.Member.Type != null)
{
m = Regex.Match(result.Member.Type, @"(?<=<).+(?=>)");
if (m.Success)
{
insert = String.Format(".<{0}>", m.Value);
}
}
}
if (insert == null)
{
if (trigger == '.' || trigger == '(') return true;
insert = ".<>";
sci.InsertText(position + text.Length, insert);
sci.CurrentPos = position + text.Length + 2;
sci.SetSel(sci.CurrentPos, sci.CurrentPos);
ASComplete.HandleAllClassesCompletion(sci, "", false, true);
return true;
}
}
if (insert == null) return false;
if (trigger == '.')
{
sci.InsertText(position + text.Length, insert.Substring(1));
sci.CurrentPos = position + text.Length;
}
else
{
sci.InsertText(position + text.Length, insert);
sci.CurrentPos = position + text.Length + insert.Length;
}
sci.SetSel(sci.CurrentPos, sci.CurrentPos);
return true;
}
return base.OnCompletionInsert(sci, position, text, trigger);
}