public static void GenerateDelegateMethods(ScintillaNet.ScintillaControl Sci, MemberModel member, Dictionary<MemberModel, ClassModel> selectedMembers, ClassModel classModel, ClassModel inClass) { Sci.BeginUndoAction(); try { string result = TemplateUtils.ReplaceTemplateVariable( TemplateUtils.GetTemplate("DelegateMethodsHeader"), "Class", classModel.Type); int position = -1; ClassModel type; List<string> importsList = new List<string>(); bool isStaticMember = false; if ((member.Flags & FlagType.Static) > 0) isStaticMember = true; inClass.ResolveExtends(); Dictionary<MemberModel, ClassModel>.KeyCollection selectedMemberKeys = selectedMembers.Keys; foreach (MemberModel m in selectedMemberKeys) { MemberModel mCopy = (MemberModel) m.Clone(); string methodTemplate = NewLine; bool overrideFound = false; ClassModel baseClassType = inClass; while (baseClassType != null && !baseClassType.IsVoid()) { MemberList inClassMembers = baseClassType.Members; foreach (MemberModel inClassMember in inClassMembers) { if ((inClassMember.Flags & FlagType.Function) > 0 && m.Name.Equals(inClassMember.Name)) { mCopy.Flags |= FlagType.Override; overrideFound = true; break; } } if (overrideFound) break; baseClassType = baseClassType.Extends; } if (isStaticMember && (m.Flags & FlagType.Static) == 0) mCopy.Flags |= FlagType.Static; if ((m.Flags & FlagType.Setter) > 0) { methodTemplate += TemplateUtils.GetTemplate("Setter"); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Modifiers", (TemplateUtils.GetStaticExternOverride(m) + TemplateUtils.GetModifiers(m)).Trim()); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Name", m.Name); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "EntryPoint", ""); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Type", m.Parameters[0].Type); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Member", member.Name + "." + m.Name); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Void", ASContext.Context.Features.voidKey ?? "void"); } else if ((m.Flags & FlagType.Getter) > 0) { methodTemplate += TemplateUtils.GetTemplate("Getter"); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Modifiers", (TemplateUtils.GetStaticExternOverride(m) + TemplateUtils.GetModifiers(m)).Trim()); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Name", m.Name); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "EntryPoint", ""); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Type", FormatType(m.Type)); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Member", member.Name + "." + m.Name); } else { methodTemplate += TemplateUtils.GetTemplate("Function"); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Body", "<<$(Return) >>$(Body)"); methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "EntryPoint", null); methodTemplate = TemplateUtils.ToDeclarationWithModifiersString(mCopy, methodTemplate); if (m.Type != null && m.Type.ToLower() != "void") methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Return", "return"); else methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Return", null); // check for varargs bool isVararg = false; if (m.Parameters != null && m.Parameters.Count > 0) { MemberModel mm = m.Parameters[m.Parameters.Count - 1]; if (mm.Name.StartsWith("...")) isVararg = true; } string callMethodTemplate = TemplateUtils.GetTemplate("CallFunction"); if (!isVararg) { callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Name", member.Name + "." + m.Name); callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Arguments", TemplateUtils.CallParametersString(m)); callMethodTemplate += ";"; } else { List<MemberModel> pseudoParamsList = new List<MemberModel>(); pseudoParamsList.Add(new MemberModel("null", null, FlagType.ParameterVar, 0)); pseudoParamsList.Add(new MemberModel("[$(Subarguments)].concat($(Lastsubargument))", null, FlagType.ParameterVar, 0)); MemberModel pseudoParamsOwner = new MemberModel(); pseudoParamsOwner.Parameters = pseudoParamsList; callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Name", member.Name + "." + m.Name + ".apply"); callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Arguments", TemplateUtils.CallParametersString(pseudoParamsOwner)); callMethodTemplate += ";"; List<MemberModel> arrayParamsList = new List<MemberModel>(); for (int i = 0; i < m.Parameters.Count - 1; i++) { MemberModel param = m.Parameters[i]; arrayParamsList.Add(param); } pseudoParamsOwner.Parameters = arrayParamsList; callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Subarguments", TemplateUtils.CallParametersString(pseudoParamsOwner)); callMethodTemplate = TemplateUtils.ReplaceTemplateVariable(callMethodTemplate, "Lastsubargument", m.Parameters[m.Parameters.Count - 1].Name.TrimStart(new char[] { '.', ' '})); } methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "Body", callMethodTemplate); } methodTemplate = TemplateUtils.ReplaceTemplateVariable(methodTemplate, "BlankLine", NewLine); result += methodTemplate; if (m.Parameters != null) { for (int i = 0; i < m.Parameters.Count; i++) { MemberModel param = m.Parameters[i]; if (param.Type != null) { type = ASContext.Context.ResolveType(param.Type, selectedMembers[m].InFile); importsList.Add(type.QualifiedName); } } } if (position < 0) { MemberModel latest = GetLatestMemberForFunction(inClass, mCopy.Access, mCopy); if (latest == null) { position = Sci.WordStartPosition(Sci.CurrentPos, true); Sci.SetSel(position, Sci.WordEndPosition(position, true)); } else { position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1); Sci.SetSel(position, position); } } else { position = Sci.CurrentPos; } if (m.Type != null) { type = ASContext.Context.ResolveType(m.Type, selectedMembers[m].InFile); importsList.Add(type.QualifiedName); } } if (importsList.Count > 0 && position > -1) { int o = AddImportsByName(importsList, Sci.LineFromPosition(position)); position += o; Sci.SetSel(position, position); } InsertCode(position, result); } finally { Sci.EndUndoAction(); } }
private static void GenerateDefaultHandlerName(ScintillaNet.ScintillaControl Sci, int position, int targetPos, string eventName, bool closeBrace) { string target = null; int contextOwnerPos = GetContextOwnerEndPos(Sci, Sci.WordStartPosition(targetPos, true)); if (contextOwnerPos != -1) { ASResult contextOwnerResult = ASComplete.GetExpressionType(Sci, contextOwnerPos); if (contextOwnerResult != null && !contextOwnerResult.IsNull() && contextOwnerResult.Member != null) { if (contextOwnerResult.Member.Name == "contentLoaderInfo" && Sci.CharAt(contextOwnerPos) == '.') { // we want to name the event from the loader var and not from the contentLoaderInfo parameter contextOwnerPos = GetContextOwnerEndPos(Sci, Sci.WordStartPosition(contextOwnerPos - 1, true)); if (contextOwnerPos != -1) { contextOwnerResult = ASComplete.GetExpressionType(Sci, contextOwnerPos); if (contextOwnerResult != null && !contextOwnerResult.IsNull() && contextOwnerResult.Member != null) { target = contextOwnerResult.Member.Name; } } } else { target = contextOwnerResult.Member.Name; } } } eventName = Camelize(eventName.Substring(eventName.LastIndexOf('.') + 1)); if (target != null) target = target.TrimStart(new char[] { '_' }); switch (ASContext.CommonSettings.HandlerNamingConvention) { case HandlerNamingConventions.handleTargetEventName: if (target == null) contextToken = "handle" + Capitalize(eventName); else contextToken = "handle" + Capitalize(target) + Capitalize(eventName); break; case HandlerNamingConventions.onTargetEventName: if (target == null) contextToken = "on" + Capitalize(eventName); else contextToken = "on" + Capitalize(target) + Capitalize(eventName); break; case HandlerNamingConventions.target_eventNameHandler: if (target == null) contextToken = eventName + "Handler"; else contextToken = target + "_" + eventName + "Handler"; break; default: //HandlerNamingConventions.target_eventName if (target == null) contextToken = eventName; else contextToken = target + "_" + eventName; break; } char c = (char)Sci.CharAt(position - 1); if (c == ',') InsertCode(position, "$(Boundary) " + contextToken + "$(Boundary)"); else InsertCode(position, contextToken); position = Sci.WordEndPosition(position + 1, true); Sci.SetSel(position, position); c = (char)Sci.CharAt(position); if (c <= 32) if (closeBrace) Sci.ReplaceSel(");"); else Sci.ReplaceSel(";"); Sci.SetSel(position, position); }
private static void GenerateFunctionJob(GeneratorJobType job, ScintillaNet.ScintillaControl Sci, MemberModel member, bool detach, ClassModel inClass) { int position = 0; MemberModel latest = null; bool isOtherClass = false; Visibility funcVisi = job.Equals(GeneratorJobType.FunctionPublic) ? Visibility.Public : GetDefaultVisibility(); int wordPos = Sci.WordEndPosition(Sci.CurrentPos, true); List<FunctionParameter> functionParameters = ParseFunctionParameters(Sci, wordPos); // evaluate, if the function should be generated in other class ASResult funcResult = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(Sci.CurrentPos, true)); int contextOwnerPos = GetContextOwnerEndPos(Sci, Sci.WordStartPosition(Sci.CurrentPos, true)); MemberModel isStatic = new MemberModel(); if (contextOwnerPos != -1) { ASResult contextOwnerResult = ASComplete.GetExpressionType(Sci, contextOwnerPos); if (contextOwnerResult != null) { if (contextOwnerResult.Member == null && contextOwnerResult.Type != null) { isStatic.Flags |= FlagType.Static; } } } else if (member != null && (member.Flags & FlagType.Static) > 0) { isStatic.Flags |= FlagType.Static; } if (funcResult.RelClass != null && !funcResult.RelClass.IsVoid() && !funcResult.RelClass.Equals(inClass)) { AddLookupPosition(); lookupPosition = -1; DockContent dc = ASContext.MainForm.OpenEditableDocument(funcResult.RelClass.InFile.FileName, true); Sci = ASContext.CurSciControl; isOtherClass = true; FileModel fileModel = new FileModel(); fileModel.Context = ASContext.Context; ASFileParser parser = new ASFileParser(); parser.ParseSrc(fileModel, Sci.Text); foreach (ClassModel cm in fileModel.Classes) { if (cm.QualifiedName.Equals(funcResult.RelClass.QualifiedName)) { funcResult.RelClass = cm; break; } } inClass = funcResult.RelClass; ASContext.Context.UpdateContext(inClass.LineFrom); } string blockTmpl = null; if ((isStatic.Flags & FlagType.Static) > 0) { blockTmpl = TemplateUtils.GetBoundary("StaticMethods"); } else if ((funcVisi & Visibility.Public) > 0) { blockTmpl = TemplateUtils.GetBoundary("PublicMethods"); } else { blockTmpl = TemplateUtils.GetBoundary("PrivateMethods"); } latest = TemplateUtils.GetTemplateBlockMember(Sci, blockTmpl); if (latest == null || (!isOtherClass && member == null)) { latest = GetLatestMemberForFunction(inClass, funcVisi, isStatic); // if we generate function in current class.. if (!isOtherClass) { MethodsGenerationLocations location = ASContext.CommonSettings.MethodsGenerationLocations; if (member == null) { detach = false; lookupPosition = -1; position = Sci.WordStartPosition(Sci.CurrentPos, true); Sci.SetSel(position, Sci.WordEndPosition(position, true)); } else if (latest != null && location == MethodsGenerationLocations.AfterSimilarAccessorMethod) { position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1); Sci.SetSel(position, position); } else { position = Sci.PositionFromLine(member.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1); Sci.SetSel(position, position); } } else // if we generate function in another class.. { if (latest != null) { position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1); } else { position = GetBodyStart(inClass.LineFrom, inClass.LineTo, Sci); detach = false; } Sci.SetSel(position, position); } } else { position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1); Sci.SetSel(position, position); } // add imports to function argument types if (functionParameters.Count > 0) { List<string> l = new List<string>(); foreach (FunctionParameter fp in functionParameters) { try { l.Add(fp.paramQualType); } catch (Exception) { } } int o = AddImportsByName(l, Sci.LineFromPosition(position)); position += o; if (latest == null) Sci.SetSel(position, Sci.WordEndPosition(position, true)); else Sci.SetSel(position, position); } List<MemberModel> parameters = new List<MemberModel>(); for (int i = 0; i < functionParameters.Count; i++) { string name = functionParameters[i].paramName; string type = functionParameters[i].paramType; parameters.Add(new MemberModel(name, type, FlagType.ParameterVar, 0)); } MemberModel newMember = NewMember(contextToken, isStatic, FlagType.Function, funcVisi); newMember.Parameters = parameters; GenerateFunction(newMember, position, detach, inClass); }
private static void GenerateVariableJob(GeneratorJobType job, ScintillaNet.ScintillaControl Sci, MemberModel member, bool detach, ClassModel inClass) { int position = 0; MemberModel latest = null; bool isOtherClass = false; Visibility varVisi = job.Equals(GeneratorJobType.Variable) ? GetDefaultVisibility() : Visibility.Public; FlagType ft = job.Equals(GeneratorJobType.Constant) ? FlagType.Constant : FlagType.Variable; // evaluate, if the variable (or constant) should be generated in other class ASResult varResult = ASComplete.GetExpressionType(Sci, Sci.WordEndPosition(Sci.CurrentPos, true)); int contextOwnerPos = GetContextOwnerEndPos(Sci, Sci.WordStartPosition(Sci.CurrentPos, true)); MemberModel isStatic = new MemberModel(); if (contextOwnerPos != -1) { ASResult contextOwnerResult = ASComplete.GetExpressionType(Sci, contextOwnerPos); if (contextOwnerResult != null) { if (contextOwnerResult.Member == null && contextOwnerResult.Type != null) { isStatic.Flags |= FlagType.Static; } } } else if (member != null && (member.Flags & FlagType.Static) > 0) { isStatic.Flags |= FlagType.Static; } ASResult returnType = null; int lineNum = Sci.CurrentLine; string line = Sci.GetLine(lineNum); Match m = Regex.Match(line, "\\b" + Regex.Escape(contextToken) + "\\("); if (m.Success) { returnType = new ASResult(); returnType.Type = ASContext.Context.ResolveType("Function", null); } else { m = Regex.Match(line, @"=\s*[^;\n\r}}]+"); if (m.Success) { int posLineStart = Sci.PositionFromLine(lineNum); if (posLineStart + m.Index >= Sci.CurrentPos) { line = line.Substring(m.Index); StatementReturnType rType = GetStatementReturnType(Sci, inClass, line, posLineStart + m.Index); if (rType != null) { returnType = rType.resolve; } } } } if (varResult.RelClass != null && !varResult.RelClass.IsVoid() && !varResult.RelClass.Equals(inClass)) { AddLookupPosition(); lookupPosition = -1; ASContext.MainForm.OpenEditableDocument(varResult.RelClass.InFile.FileName, false); Sci = ASContext.CurSciControl; isOtherClass = true; FileModel fileModel = new FileModel(); fileModel.Context = ASContext.Context; ASFileParser parser = new ASFileParser(); parser.ParseSrc(fileModel, Sci.Text); foreach (ClassModel cm in fileModel.Classes) { if (cm.QualifiedName.Equals(varResult.RelClass.QualifiedName)) { varResult.RelClass = cm; break; } } inClass = varResult.RelClass; ASContext.Context.UpdateContext(inClass.LineFrom); } latest = GetLatestMemberForVariable(job, inClass, varVisi, isStatic); // if we generate variable in current class.. if (!isOtherClass && member == null) { detach = false; lookupPosition = -1; position = Sci.WordStartPosition(Sci.CurrentPos, true); Sci.SetSel(position, Sci.WordEndPosition(position, true)); } else // if we generate variable in another class { 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); } // if this is a constant, we assign a value to constant string returnTypeStr = null; string eventValue = null; if (job == GeneratorJobType.Constant && returnType == null) { isStatic.Flags |= FlagType.Static; eventValue = "String = \"" + Camelize(contextToken) + "\""; } else if (returnType != null) { ClassModel inClassForImport = null; if (returnType.InClass != null) { inClassForImport = returnType.InClass; } else if (returnType.RelClass != null) { inClassForImport = returnType.RelClass; } else { inClassForImport = inClass; } List<String> imports = new List<string>(); if (returnType.Member != null) { if (returnType.Member.Type != ASContext.Context.Features.voidKey) { returnTypeStr = FormatType(GetShortType(returnType.Member.Type)); imports.Add(getQualifiedType(returnType.Member.Type, inClassForImport)); } } else if (returnType != null && returnType.Type != null) { returnTypeStr = FormatType(GetShortType(returnType.Type.QualifiedName)); imports.Add(getQualifiedType(returnType.Type.QualifiedName, inClassForImport)); } if (imports.Count > 0) { position += AddImportsByName(imports, Sci.LineFromPosition(position)); Sci.SetSel(position, position); } } MemberModel newMember = NewMember(contextToken, isStatic, ft, varVisi); if (returnTypeStr != null) { newMember.Type = returnTypeStr; } else if (eventValue != null) { newMember.Type = eventValue; } GenerateVariable(newMember, position, detach); }
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); }
public static void GenerateDelegateMethods(ScintillaNet.ScintillaControl Sci, MemberModel member, Dictionary<MemberModel, ClassModel> selectedMembers, ClassModel classModel, ClassModel inClass) { Sci.BeginUndoAction(); try { StringBuilder sb = new StringBuilder( String.Format(GetTemplate("DelegateMethodsHeader", "$(Boundary)\n\n/* DELEGATE {0} */"), classModel.Type)); MemberModel latest; int position = -1; List<MemberModel> methodParams; ClassModel type; List<string> importsList = new List<string>(); bool isStaticMember = false; if ((member.Flags & FlagType.Static) > 0) { isStaticMember = true; } inClass.ResolveExtends(); Dictionary<MemberModel, ClassModel>.KeyCollection selectedMemberKeys = selectedMembers.Keys; foreach (MemberModel m in selectedMemberKeys) { sb.Append("$(Boundary)\n\n"); bool overrideFound = false; ClassModel aType = inClass; while (aType != null && !aType.IsVoid()) { MemberList inClassMembers = aType.Members; foreach (MemberModel inClassMember in inClassMembers) { if ((inClassMember.Flags & FlagType.Function) > 0 && m.Name.Equals(inClassMember.Name)) { sb.Append("override "); overrideFound = true; break; } } if (overrideFound) { break; } aType = aType.Extends; } if (isStaticMember) { sb.Append("static "); } sb.Append(GetDeclaration(m)) .Append(" $(CSLB){\n\t"); if (m.Type != null && m.Type.ToLower() != "void") { sb.Append("return "); } methodParams = m.Parameters; // check for varargs bool isVararg = false; if (methodParams != null && methodParams.Count > 0) { MemberModel mm = methodParams[methodParams.Count - 1]; if (mm.Name.StartsWith("...")) { isVararg = true; } } if (!isVararg) { sb.Append(member.Name) .Append(".") .Append(m.Name) .Append("("); if (methodParams != null) { for (int i = 0; i < methodParams.Count; i++) { MemberModel param = methodParams[i]; sb.Append(param.Name); if (i + 1 < methodParams.Count) { sb.Append(", "); } } } sb.Append(");"); } else { sb.Append(member.Name) .Append(".") .Append(m.Name) .Append(".apply(null, ["); for (int i = 0; i < methodParams.Count; i++) { MemberModel param = methodParams[i]; if (i + 1 < methodParams.Count) { sb.Append(param.Name); if (i + 2 < methodParams.Count) { sb.Append(", "); } } else { sb.Append("].concat(") .Append(param.Name.Substring(3)) .Append(")"); } } sb.Append(");"); } sb.Append("\n}"); if (methodParams != null) { for (int i = 0; i < methodParams.Count; i++) { MemberModel param = methodParams[i]; if (param.Type != null) { type = ASContext.Context.ResolveType(param.Type, selectedMembers[m].InFile); importsList.Add(type.QualifiedName); } } } if (position < 0) { latest = FindLatest(FlagType.Function, inClass); if (latest == null) { position = Sci.WordStartPosition(Sci.CurrentPos, true); Sci.SetSel(position, Sci.WordEndPosition(position, true)); } else { position = Sci.PositionFromLine(latest.LineTo + 1) - ((Sci.EOLMode == 0) ? 2 : 1); Sci.SetSel(position, position); } } else { position = Sci.CurrentPos; } if (m.Type != null) { type = ASContext.Context.ResolveType(m.Type, selectedMembers[m].InFile); importsList.Add(type.QualifiedName); } } if (importsList.Count > 0 && position > -1) { int o = AddImportsByName(importsList, Sci.LineFromPosition(position)); position += o; Sci.SetSel(position, position); } InsertCode(position, sb.ToString()); } finally { Sci.EndUndoAction(); } }
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); }