本文整理汇总了C#中ScintillaNet.CharAt方法的典型用法代码示例。如果您正苦于以下问题:C# ScintillaNet.CharAt方法的具体用法?C# ScintillaNet.CharAt怎么用?C# ScintillaNet.CharAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScintillaNet
的用法示例。
在下文中一共展示了ScintillaNet.CharAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnChar
static public bool OnChar(ScintillaNet.ScintillaControl Sci, int Value, int position, int style)
{
if (style == 3 || style == 124)
{
switch (Value)
{
// documentation tag
case '@':
return HandleDocTagCompletion(Sci);
// documentation bloc
case '*':
if ((position > 2) && (Sci.CharAt(position-3) == '/') && (Sci.CharAt(position-2) == '*')
&& ((position == 3) || (Sci.BaseStyleAt(position-4) != 3)))
HandleBoxCompletion(Sci, position);
break;
}
}
return false;
}
示例2: ConvertToConst
private static void ConvertToConst(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member, bool detach)
{
String suggestion = "NEW_CONST";
String label = TextHelper.GetString("ASCompletion.Label.ConstName");
String title = TextHelper.GetString("ASCompletion.Title.ConvertToConst");
Hashtable info = new Hashtable();
info["suggestion"] = suggestion;
info["label"] = label;
info["title"] = title;
DataEvent de = new DataEvent(EventType.Command, "LineEntryDialog", info);
EventManager.DispatchEvent(null, de);
if (!de.Handled)
{
return;
}
suggestion = (string)info["suggestion"];
int position = Sci.CurrentPos;
MemberModel latest = null;
int wordPosEnd = Sci.WordEndPosition(position, true);
int wordPosStart = Sci.WordStartPosition(position, true);
char cr = (char)Sci.CharAt(wordPosEnd);
if (cr == '.')
{
wordPosEnd = Sci.WordEndPosition(wordPosEnd + 1, true);
}
else
{
cr = (char)Sci.CharAt(wordPosStart - 1);
if (cr == '.')
{
wordPosStart = Sci.WordStartPosition(wordPosStart - 1, true);
}
}
Sci.SetSel(wordPosStart, wordPosEnd);
string word = Sci.SelText;
Sci.ReplaceSel(suggestion);
if (member == null)
{
detach = false;
lookupPosition = -1;
position = Sci.WordStartPosition(Sci.CurrentPos, true);
Sci.SetSel(position, Sci.WordEndPosition(position, true));
}
else
{
latest = FindLatest(FlagType.Constant, GetDefaultVisibility(), inClass)
?? FindLatest(FlagType.Variable, GetDefaultVisibility(), inClass);
if (latest != null)
{
position = FindNewVarPosition(Sci, inClass, latest);
}
else
{
position = GetBodyStart(inClass.LineFrom, inClass.LineTo, Sci);
detach = false;
}
if (position <= 0) return;
Sci.SetSel(position, position);
}
contextToken = suggestion + ":Number = " + word + "";
GenerateVariable(
NewMember(contextToken, member, FlagType.Variable | FlagType.Constant | FlagType.Static),
position, detach);
}
示例3: ContextualGenerator
//.........这里部分代码省略.........
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
string re = String.Format(patternEvent, contextToken);
Match m = Regex.Match(text, re, RegexOptions.IgnoreCase);
if (m.Success)
{
contextMatch = m;
contextParam = CheckEventType(m.Groups["event"].Value);
ShowEventList(found);
return;
}
m = Regex.Match(text, String.Format(patternAS2Delegate, contextToken), RegexOptions.IgnoreCase);
if (m.Success)
{
contextMatch = m;
ShowDelegateList(found);
return;
}
// suggest delegate
if (ASContext.Context.Features.hasDelegates)
{
m = Regex.Match(text, @"([a-z0-9_.]+)\s*\+=\s*" + contextToken, RegexOptions.IgnoreCase);
if (m.Success)
{
int offset = Sci.PositionFromLine(Sci.LineFromPosition(position))
+ m.Groups[1].Index + m.Groups[1].Length;
char c = (char)Sci.CharAt(offset);
resolve = ASComplete.GetExpressionType(Sci, offset);
if (resolve.Member != null)
contextMember = ResolveDelegate(resolve.Member.Type, resolve.InFile);
contextMatch = m;
ShowDelegateList(found);
return;
}
}
}
else
{
// insert a default handler name, then "generate event handlers" suggestion
Match m = Regex.Match(text, String.Format(patternEvent, ""), RegexOptions.IgnoreCase);
if (m.Success)
{
int regexIndex = m.Index + Sci.PositionFromLine(Sci.LineFromPosition(Sci.CurrentPos));
GenerateDefaultHandlerName(Sci, position, regexIndex, m.Groups["event"].Value, true);
resolve = ASComplete.GetExpressionType(Sci, Sci.CurrentPos);
if (resolve.Member == null || (resolve.Member.Flags & FlagType.AutomaticVar) > 0)
{
contextMatch = m;
contextParam = CheckEventType(m.Groups["event"].Value);
ShowEventList(found);
}
return;
}
// insert default delegate name, then "generate delegate" suggestion
if (ASContext.Context.Features.hasDelegates)
{
m = Regex.Match(text, @"([a-z0-9_.]+)\s*\+=\s*", RegexOptions.IgnoreCase);
if (m.Success)
示例4: GetStatementReturnType
private static StatementReturnType GetStatementReturnType(ScintillaNet.ScintillaControl Sci, ClassModel inClass, string line, int startPos)
{
Regex target = new Regex(@"[;\s\n\r]*", RegexOptions.RightToLeft);
Match m = target.Match(line);
if (!m.Success)
{
return null;
}
line = line.Substring(0, m.Index);
if (line.Length == 0)
{
return null;
}
line = ReplaceAllStringContents(line);
ASResult resolve = null;
int pos = -1;
string word = null;
int stylemask = (1 << Sci.StyleBits) - 1;
ClassModel type = null;
if (line[line.Length - 1] == ')')
{
pos = -1;
int lastIndex = 0;
int bracesBalance = 0;
while (true)
{
int pos1 = line.IndexOf("(", lastIndex);
int pos2 = line.IndexOf(")", lastIndex);
if (pos1 != -1 && pos2 != -1)
{
lastIndex = Math.Min(pos1, pos2);
}
else if (pos1 != -1 || pos2 != -1)
{
lastIndex = Math.Max(pos1, pos2);
}
else
{
break;
}
if (lastIndex == pos1)
{
bracesBalance++;
if (bracesBalance == 1)
{
pos = lastIndex;
}
}
else if (lastIndex == pos2)
{
bracesBalance--;
}
lastIndex++;
}
}
else
{
pos = line.Length;
}
if (pos != -1)
{
line = line.Substring(0, pos);
pos += startPos;
pos -= line.Length - line.TrimEnd().Length + 1;
pos = Sci.WordEndPosition(pos, true);
resolve = ASComplete.GetExpressionType(Sci, pos);
if (resolve.IsNull()) resolve = null;
word = Sci.GetWordFromPosition(pos);
}
IASContext ctx = inClass.InFile.Context;
m = Regex.Match(line, "new\\s+([\\w\\d.<>,_$-]+)+(<[^]]+>)|(<[^]]+>)", RegexOptions.IgnoreCase);
if (m.Success)
{
string m1 = m.Groups[1].Value;
string m2 = m.Groups[2].Value;
string cname;
if (string.IsNullOrEmpty(m1) && string.IsNullOrEmpty(m2))
cname = m.Groups[0].Value;
else
cname = String.Concat(m1, m2);
if (cname.StartsWith("<"))
cname = "Vector." + cname; // literal vector
type = ctx.ResolveType(cname, inClass.InFile);
if (!type.IsVoid()) resolve = null;
}
else
{
char c = (char)Sci.CharAt(pos);
if (c == '"' || c == '\'')
{
type = ctx.ResolveType("String", inClass.InFile);
//.........这里部分代码省略.........
示例5: GetWordLeft
static public string GetWordLeft(ScintillaNet.ScintillaControl Sci, ref int position)
{
string word = "";
string exclude = "(){};,+*/\\=:.%\"<>";
bool skipWS = true;
int style;
int stylemask = (1 << Sci.StyleBits) -1;
char c;
while (position >= 0)
{
style = Sci.StyleAt(position) & stylemask;
if (IsTextStyleEx(style))
{
c = (char)Sci.CharAt(position);
if (c <= ' ')
{
if (!skipWS)
break;
}
else if (exclude.IndexOf(c) >= 0) break;
else if (style != 6)
{
word = c+word;
skipWS = false;
}
}
position--;
}
return word;
}
示例6: ConvertToConst
private static void ConvertToConst(ClassModel inClass, ScintillaNet.ScintillaControl Sci, MemberModel member, bool detach)
{
String suggestion = "NEW_CONST";
String label = TextHelper.GetString("ASCompletion.Label.ConstName");
String title = TextHelper.GetString("ASCompletion.Title.ConvertToConst");
Hashtable info = new Hashtable();
info["suggestion"] = suggestion;
info["label"] = label;
info["title"] = title;
DataEvent de = new DataEvent(EventType.Command, "ProjectManager.LineEntryDialog", info);
EventManager.DispatchEvent(null, de);
if (!de.Handled)
return;
suggestion = (string)info["suggestion"];
int position = Sci.CurrentPos;
MemberModel latest = null;
int wordPosEnd = Sci.WordEndPosition(position, true);
int wordPosStart = Sci.WordStartPosition(position, true);
char cr = (char)Sci.CharAt(wordPosEnd);
if (cr == '.')
{
wordPosEnd = Sci.WordEndPosition(wordPosEnd + 1, true);
}
else
{
cr = (char)Sci.CharAt(wordPosStart - 1);
if (cr == '.')
{
wordPosStart = Sci.WordStartPosition(wordPosStart - 1, true);
}
}
Sci.SetSel(wordPosStart, wordPosEnd);
string word = Sci.SelText;
Sci.ReplaceSel(suggestion);
if (member == null)
{
detach = false;
lookupPosition = -1;
position = Sci.WordStartPosition(Sci.CurrentPos, true);
Sci.SetSel(position, Sci.WordEndPosition(position, true));
}
else
{
latest = GetLatestMemberForVariable(GeneratorJobType.Constant, inClass,
Visibility.Private, new MemberModel("", "", FlagType.Static, 0));
if (latest != null)
{
position = FindNewVarPosition(Sci, inClass, latest);
}
else
{
position = GetBodyStart(inClass.LineFrom, inClass.LineTo, Sci);
detach = false;
}
if (position <= 0) return;
Sci.SetSel(position, position);
}
MemberModel m = NewMember(suggestion, member, FlagType.Variable | FlagType.Constant | FlagType.Static);
m.Type = ASContext.Context.Features.numberKey;
m.Value = word;
GenerateVariable(m, position, detach);
}
示例7: GetContextOwnerEndPos
private static int GetContextOwnerEndPos(ScintillaNet.ScintillaControl Sci, int worsStartPos)
{
int pos = worsStartPos - 1;
bool dotFound = false;
while (pos > 0)
{
char c = (char) Sci.CharAt(pos);
if (c == '.' && !dotFound) dotFound = true;
else if (c == '\t' || c == '\n' || c == '\r' || c == ' ') { /* skip */ }
else return dotFound ? pos + 1 : -1;
pos--;
}
return pos;
}
示例8: HandleColonCompletion
static private bool HandleColonCompletion(ScintillaNet.ScintillaControl Sci, string tail, bool autoHide)
{
DebugConsole.Trace("** Complete: ':'<class>");
// Context
ASClass cClass = ASContext.CurrentClass;
// Valid statement
int position = Sci.CurrentPos-1;
string keyword = null;
int stylemask = (1 << Sci.StyleBits) -1;
char c;
while (position > 0)
{
position--;
c = (char)Sci.CharAt(position);
if ((c == '{') || (c == '=')) return false;
else if ((Sci.StyleAt(position) & stylemask) == 19)
{
keyword = GetWordLeft(Sci, ref position);
DebugConsole.Trace("'"+keyword+"'");
break;
}
}
if (keyword != "var" && keyword != "function" && keyword != "get" && keyword != "set" && keyword != "const")
return false;
// Consolidate known classes
ASMemberList known = new ASMemberList();
known.Merge(cClass.ToASMember());
known.Merge(cClass.Imports);
known.Merge(ASContext.TopLevel.Imports);
known.Merge(ASContext.GetBasePackages());
// show
ArrayList list = new ArrayList();
foreach(ASMember member in known)
list.Add(new MemberItem(member));
CompletionList.Show(list, autoHide, tail);
return true;
}
示例9: DisambiguateComa
/// <summary>
/// Find out in what context is a coma-separated expression
/// </summary>
/// <returns></returns>
private static ComaExpression DisambiguateComa(ScintillaNet.ScintillaControl Sci, int position, int minPos)
{
ContextFeatures features = ASContext.Context.Features;
// find block start '(' or '{'
int parCount = 0;
int braceCount = 0;
int sqCount = 0;
char c = (char)Sci.CharAt(position);
bool wasPar = false;
if (c == '{') { wasPar = true; position--; }
while (position > minPos)
{
c = (char)Sci.CharAt(position);
if (c == ';')
{
return ComaExpression.None;
}
else if ((c == ',' || c == '=') && wasPar)
{
return ComaExpression.AnonymousObject;
}
// var declaration
else if (c == ':')
{
position--;
string word = ASComplete.GetWordLeft(Sci, ref position);
word = ASComplete.GetWordLeft(Sci, ref position);
if (word == features.varKey) return ComaExpression.VarDeclaration;
else continue;
}
// Array values
else if (c == '[')
{
sqCount--;
if (sqCount < 0)
{
return ComaExpression.ArrayValue;
}
}
else if (c == ']')
{
if (wasPar) return ComaExpression.None;
sqCount++;
}
// function declaration or parameter
else if (c == '(')
{
parCount--;
if (parCount < 0)
{
position--;
string word1 = ASComplete.GetWordLeft(Sci, ref position);
if (word1 == features.functionKey) return ComaExpression.FunctionDeclaration; // anonymous function
string word2 = ASComplete.GetWordLeft(Sci, ref position);
if (word2 == features.functionKey || word2 == features.setKey || word2 == features.getKey)
return ComaExpression.FunctionDeclaration; // function declaration
return ComaExpression.FunctionParameter; // function call
}
}
else if (c == ')')
{
if (wasPar) return ComaExpression.None;
parCount++;
}
// code block or anonymous object
else if (c == '{')
{
braceCount--;
if (braceCount < 0)
{
position--;
string word1 = ASComplete.GetWordLeft(Sci, ref position);
c = (word1.Length > 0) ? word1[word1.Length - 1] : (char)Sci.CharAt(position);
if (c != ')' && c != '}' && !char.IsLetterOrDigit(c)) return ComaExpression.AnonymousObject;
break;
}
}
else if (c == '}')
{
if (wasPar) return ComaExpression.None;
braceCount++;
}
else if (c == '?') return ComaExpression.AnonymousObject;
position--;
}
return ComaExpression.None;
}
示例10: HandleFunctionCompletion
/// <summary>
/// Display method signature
/// </summary>
/// <param name="Sci">Scintilla control</param>
/// <returns>Auto-completion has been handled</returns>
static public bool HandleFunctionCompletion(ScintillaNet.ScintillaControl Sci)
{
// find method
int position = Sci.CurrentPos-1;
int parCount = 0;
int braCount = 0;
int comaCount = 0;
int arrCount = 0;
int style = 0;
int stylemask = (1 << Sci.StyleBits) -1;
char c;
while (position >= 0)
{
style = Sci.StyleAt(position) & stylemask;
if (style == 19)
{
string keyword = GetWordLeft(Sci, ref position);
DebugConsole.Trace("Keyword "+keyword);
if (!"new".StartsWith(keyword))
{
position = -1;
break;
}
}
if (IsTextStyleEx(style))
{
c = (char)Sci.CharAt(position);
if (c == ';')
{
position = -1;
break;
}
// skip {} () [] blocks
if ( ((braCount > 0) && (c != '{'))
|| ((arrCount > 0) && (c != '['))
|| ((parCount > 0) && (c != '(')))
{
position--;
continue;
}
// new block
if (c == '}') braCount++;
else if (c == ']') arrCount++;
else if (c == ')') parCount++;
// block closed
else if (c == '{')
{
if (braCount == 0) comaCount = 0;
else braCount--;
}
else if (c == '[')
{
if (arrCount == 0) comaCount = 0;
else arrCount--;
}
else if (c == '(')
{
if (--parCount < 0)
// function start found
break;
}
// new parameter reached
else if (c == ',' && parCount == 0 && Sci.BaseStyleAt(position) != 6)
comaCount++;
}
position--;
}
// continuing calltip ?
if (HasCalltip())
{
if (calltipPos == position)
{
ShowCalltip(Sci, comaCount);
return true;
}
else InfoTip.Hide();
}
else if (position < 0)
return false;
// get expression at cursor position
ASExpr expr = GetExpression(Sci, position);
DebugConsole.Trace("Expr: "+expr.Value);
if (expr.Value == null || expr.Value.Length == 0 || expr.separator == ':'
|| (expr.Keyword == "function" && expr.separator == ' '))
return false;
DebugConsole.Trace("** Display method parameters");
DebugConsole.Trace(expr.Value);
// Context
expr.LocalVars = ParseLocalVars(expr);
ASClass aClass = ASContext.CurrentClass;
// Expression before cursor
ASResult result = EvalExpression(expr.Value, expr, aClass, true);
//.........这里部分代码省略.........
示例11: OnChar
/// <summary>
/// Character written in editor
/// </summary>
/// <param name="Value">Character inserted</param>
static public bool OnChar(ScintillaNet.ScintillaControl Sci, int Value, bool autoHide)
{
if (autoHide && !ASContext.HelpersEnabled)
return false;
try
{
int eolMode = Sci.EOLMode;
// code auto
if (((Value == 10) && (eolMode != 1)) || ((Value == 13) && (eolMode == 1)))
{
DebugConsole.Trace("Struct");
HandleStructureCompletion(Sci);
return false;
}
// ignore repeated characters
int position = Sci.CurrentPos;
if ((Sci.CharAt(position-2) == Value) && (Sci.CharAt(position-1) == Value) && (Value != '*'))
return false;
// ignore text in comments & quoted text
Sci.Colourise(0,-1);
int stylemask = (1 << Sci.StyleBits) -1;
int style = Sci.StyleAt(position-1) & stylemask;
DebugConsole.Trace("style "+style);
if (!IsTextStyle(style) && !IsTextStyle(Sci.StyleAt(position) & stylemask))
{
// documentation completion
if (ASContext.DocumentationCompletionEnabled && IsCommentStyle(style))
return ASDocumentation.OnChar(Sci, Value, position, style);
else if (autoHide) return false;
}
// stop here if the class is not valid
if (!ASContext.IsClassValid()) return false;
// handle
switch (Value)
{
case '.':
return HandleDotCompletion(Sci, autoHide);
case ' ':
position--;
string word = GetWordLeft(Sci, ref position);
DebugConsole.Trace("Word? "+word);
if (word.Length > 0)
switch (word)
{
case "new":
case "extends":
case "implements":
return HandleNewCompletion(Sci, "", autoHide);
case "import":
return HandleImportCompletion(Sci, "", autoHide);
case "public":
return HandleDeclarationCompletion(Sci, "function static var", "", autoHide);
case "private":
return HandleDeclarationCompletion(Sci, "function static var", "", autoHide);
case "static":
return HandleDeclarationCompletion(Sci, "function private public var", "", autoHide);
}
break;
case ':':
ASContext.UnsetOutOfDate();
bool result = HandleColonCompletion(Sci, "", autoHide);
ASContext.SetOutOfDate();
return result;
case '(':
return HandleFunctionCompletion(Sci);
case ')':
if (InfoTip.CallTipActive) InfoTip.Hide();
return false;
case '*':
return CodeAutoOnChar(Sci, Value);
}
}
catch (Exception ex) {
ErrorHandler.ShowError("Completion error", ex);
}
// CodeAuto context
if (!PluginCore.Controls.CompletionList.Active) LastExpression = null;
return false;
}
示例12: HandleDeclarationCompletion
static private bool HandleDeclarationCompletion(ScintillaNet.ScintillaControl Sci, string words, string tail, bool autoHide)
{
DebugConsole.Trace("** Complete: declaration <"+words+">");
if (words.Length == 0)
return false;
int position = Sci.CurrentPos;
// concat current word if DotCompletion sent us the previous word
if (Sci.CharAt(position-1) <= 32)
tail = "";
// does it need a tab?
if ((words != "import") && (words.IndexOf("extends") < 0) && (words.IndexOf("implements") < 0))
{
if (ASContext.CurrentClass.IsAS3 && words.IndexOf("var") > 0) {
words = "const "+words;
}
int curLine = Sci.LineFromPosition(position);
if (Sci.GetLineIndentation(curLine) == 0)
{
Sci.SetLineIndentation(curLine, Sci.TabWidth);
if (Sci.IsUseTabs) position++;
else position += Sci.TabWidth;
Sci.SelectionStart = Sci.CurrentPos = position;
}
}
// remove keywords already set
words = " "+words+" ";
string rem = GetWordLeft(Sci, ref position);
while (rem.Length > 0)
{
if ((rem == "var") || (rem == "function") || (ASContext.CurrentClass.IsAS3 && (rem == "const")))
return true;
else if (rem == "public")
words = words.Replace(" private ", " ");
else if (rem == "private")
words = words.Replace(" public ", " ");
words = words.Replace(" "+rem+" ", " ");
rem = GetWordLeft(Sci, ref position);
}
words = words.Trim();
// build list
string[] items = words.Split(' ');
ArrayList known = new ArrayList();
foreach(string item in items)
known.Add(new TemplateItem(item));
// show
CompletionList.Show(known, autoHide, tail);
return true;
}
示例13: 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;
}
示例14: CodeAutoOnChar
/// <summary>
/// Some characters can fire code generation
/// </summary>
/// <param name="sci">Scintilla control</param>
/// <param name="value">Character</param>
/// <returns>Code was generated</returns>
static private bool CodeAutoOnChar(ScintillaNet.ScintillaControl sci, int value)
{
if (!ASContext.AutoImportsEnabled)
return false;
int position = sci.CurrentPos;
if (value == '*' && position > 1 && sci.CharAt(position-2) == '.' && LastExpression != null)
{
// context
string key = LastExpression.Keyword;
if (key != null && (key == "import" || key == "extends" || key == "implements" || key == "package"))
return false;
ASResult context = EvalExpression(LastExpression.Value, LastExpression, ASContext.CurrentClass, true);
if (context.IsNull() || context.Class.Flags != FlagType.Package)
return false;
string package = LastExpression.Value;
int startPos = LastExpression.Position;
string check = "";
char c;
while (startPos > LastExpression.PositionExpression && check.Length <= package.Length && check != package)
{
c = (char)sci.CharAt(--startPos);
if (c > 32) check = c+check;
}
if (check != package)
return false;
// insert import
string statement = "import "+package+"*;"+ASContext.MainForm.GetNewLineMarker(sci.EOLMode);
int endPos = sci.CurrentPos;
int line = 0;
int curLine = sci.LineFromPosition(position);
int firstLine = 0;
bool found = false;
string txt;
Match mImport;
while (line < curLine)
{
txt = sci.GetLine(line++).TrimStart();
// HACK insert imports after AS3 package declaration
if (txt.StartsWith("package"))
{
statement = '\t'+statement;
firstLine = (txt.IndexOf('{') < 0) ? line+1 : line;
}
else if (txt.StartsWith("import"))
{
found = true;
// insérer dans l'ordre alphabetique
mImport = ASClassParser.re_import.Match(txt);
if (mImport.Success &&
String.Compare(mImport.Groups["package"].Value, package) > 0)
{
line--;
break;
}
}
else if (found) {
line--;
break;
}
}
if (line == curLine) line = firstLine;
position = sci.PositionFromLine(line);
line = sci.FirstVisibleLine;
sci.SetSel(position, position);
sci.ReplaceSel(statement);
// prepare insertion of the term as usual
startPos += statement.Length;
endPos += statement.Length;
sci.SetSel(startPos, endPos);
sci.ReplaceSel("");
sci.LineScroll(0, line-sci.FirstVisibleLine+1);
// create classes list
ASClass cClass = ASContext.CurrentClass;
ArrayList list = new ArrayList();
foreach(ASMember import in cClass.Imports)
if (import.Type.StartsWith(package))
list.Add(new MemberItem(import));
CompletionList.Show(list, false);
return true;
}
return false;
}
示例15: GetContextOwnerEndPos
private static int GetContextOwnerEndPos(ScintillaNet.ScintillaControl Sci, int worsStartPos)
{
int pos = worsStartPos - 1;
bool dotFound = false;
while (pos > 0)
{
char c = (char) Sci.CharAt(pos);
if (c == '.' && !dotFound)
{
dotFound = true;
}
else if (c == '\t' || c == '\n' || c == '\r' || c == ' ')
{
}
else
{
if (dotFound)
{
return pos + 1;
}
else
{
return -1;
}
}
pos--;
}
return pos;
}