private void BaseForIn(bool aternate) { ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl; sci.BeginUndoAction(); // Settings String setAlt = this.settingObject.AlternateFunction.Trim(); if (setAlt == "") { setAlt = "MyLogger.log"; } Boolean setIns = this.settingObject.InsertNewLine; Boolean setCmp = this.settingObject.CompactMode; String tr0 = "for( var i:String in "; String tr1 = " ) trace( \"key : \" + i + \", value : \" + "; if (aternate) { tr1 = " ) " + setAlt + "( \"key : \" + i + \", value : \" + "; } String tr2 = "[ i ] );"; if (setCmp) { tr0 = "for(var i:String in "; tr1 = ") trace(\"key: \"+i+\", value: \"+"; if (aternate) { tr1 = ") " + setAlt + "(\"key: \"+i+\", value: \"+"; } tr2 = "[i]);"; } PositionInfos t = new PositionInfos(sci, sci.CurrentPos, PluginBase.MainForm.ProcessArgString(sArgsString)); Boolean exec = false; String sel = ""; if (t.HasSelection) { if (!t.SelectionIsMultiline) { sel = t.SelectedText.Trim(); exec = true; } } else { if (t.WordFromPosition != "") { sel = t.WordFromPosition; exec = true; } } if (exec) { HelpTools.SetCaretReadyToTrace(sci, true); String trace = tr0 + sel + tr1 + sel + tr2; sci.InsertText(sci.CurrentPos, trace); HelpTools.GoToLineEnd(sci, setIns); } sci.EndUndoAction(); }
public PositionInfos(ScintillaControl sci, Int32 position, String argString) { // Variables String[] vars = argString.Split('¤'); this.ArgCurWord = vars[0]; this.ArgPackageName = vars[1]; this.ArgClassName = vars[2]; this.ArgClassType = vars[3]; this.ArgMemberName = vars[4]; this.ArgMemberType = vars[5]; // Selection Int32 ss = sci.SelectionStart; Int32 se = sci.SelectionEnd; if (se != ss) { this.SelectionStart = ss; this.SelectionEnd = se; this.HasSelection = true; if (sci.LineFromPosition(ss) != sci.LineFromPosition(se)) { this.SelectionIsMultiline = true; } else { SelectedText = sci.SelText; } } // Current this.CurrentPosition = position; this.CurrentCharCode = sci.CharAt(position); this.CurrentIsWhiteChar = (HelpTools.IsWhiteChar(this.CurrentCharCode)); this.CurrentIsDotChar = (this.CurrentCharCode == 46); this.CurrentIsActionScriptChar = HelpTools.IsActionScriptChar(this.CurrentCharCode); this.CurrentIsWordChar = HelpTools.IsWordChar((byte)this.CurrentCharCode); Int32 s = sci.StyleAt(position); this.CurrentIsInsideComment = (s == 1 || s == 2 || s == 3 || s == 17); // Next Int32 np = sci.PositionAfter(position); if (np != position) { this.NextPosition = np; } else { this.CaretIsAtEndOfDocument = true; } // Word this.CodePage = sci.CodePage; // (UTF-8|Big Endian|Little Endian : 65001) (8 Bits|UTF-7 : 0) if (this.CurrentIsInsideComment == false && this.SelectionIsMultiline == false) { Int32 wsp = sci.WordStartPosition(position, true); // Attention (WordEndPosition n'est pas estimé comme par defaut) Int32 wep = sci.PositionBefore(sci.WordEndPosition(position, true)); if (this.CodePage != 65001) { wsp = HelpTools.GetWordStartPositionByWordChar(sci, position); // Attention (WordEndPosition n'est pas estimé comme par defaut) wep = sci.PositionBefore(HelpTools.GetWordEndPositionByWordChar(sci, position)); } this.WordStartPosition = wsp; this.WordEndPosition = wep; if (this.CodePage == 65001) { this.WordFromPosition = this.ArgCurWord; } else { this.WordFromPosition = HelpTools.GetText(sci, wsp, sci.PositionAfter(wep)); } if (position > wep) { this.CaretIsAfterLastLetter = true; } } // Previous if (this.CurrentPosition > 0) { this.PreviousPosition = sci.PositionBefore(position); this.PreviousCharCode = sci.CharAt(this.PreviousPosition); this.PreviousIsWhiteChar = HelpTools.IsWhiteChar(this.PreviousCharCode); this.PreviousIsDotChar = (this.PreviousCharCode == 46); this.PreviousIsActionScriptChar = HelpTools.IsActionScriptChar(this.PreviousCharCode); } // Line this.CurrentLineIdx = sci.LineFromPosition(position); if (this.CurrentPosition > 0) { this.PreviousLineIdx = sci.LineFromPosition(this.PreviousPosition); } this.LineIdxMax = sci.LineCount - 1; this.LineStartPosition = HelpTools.LineStartPosition(sci, this.CurrentLineIdx); this.LineEndPosition = sci.LineEndPosition(this.CurrentLineIdx); this.NewLineMarker = LineEndDetector.GetNewLineMarker(sci.EOLMode); // Previous / Next if (this.WordStartPosition != -1) { this.PreviousNonWhiteCharPosition = HelpTools.PreviousNonWhiteCharPosition(sci, this.WordStartPosition); this.PreviousWordIsFunction = (sci.GetWordFromPosition(this.PreviousNonWhiteCharPosition) == "function"); this.NextNonWhiteCharPosition = HelpTools.NextNonWhiteCharPosition(sci, this.WordEndPosition); } // Function if (this.PreviousWordIsFunction) { Int32 nobp = HelpTools.NextCharPosition(sci, position, "("); Int32 ncbp = HelpTools.NextCharPosition(sci, position, ")"); Int32 nlbp = HelpTools.NextCharPosition(sci, position, "{"); if ((nobp < ncbp) && (ncbp < nlbp)) { this.NextOpenBracketPosition = nobp; this.NextCloseBracketPosition = ncbp; this.NextLeftBracePosition = nlbp; } // Arguments String args = HelpTools.GetText(sci, sci.PositionAfter(this.NextOpenBracketPosition), this.NextCloseBracketPosition).Trim(); if (args.Length > 0) { this.HasArguments = true; this.Arguments = HelpTools.ExtractArguments(sci, args); } } }
private void BaseSimple(bool aternate) { ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl; sci.BeginUndoAction(); // Settings String setAlt = this.settingObject.AlternateFunction.Trim(); if (setAlt == "") { setAlt = "MyLogger.log"; } Boolean setIns = this.settingObject.InsertNewLine; Boolean setCmp = this.settingObject.CompactMode; Boolean setPkg = this.settingObject.ShowPackageName; Boolean setCls = this.settingObject.ShowClassName; PositionInfos t = new PositionInfos(sci, sci.CurrentPos, PluginBase.MainForm.ProcessArgString(sArgsString)); String trace = ""; Boolean exec = false; if (t.HasSelection) { if (!t.SelectionIsMultiline) { String sel1 = t.SelectedText.Trim(); if (sel1.EndsWith(";")) { sel1 = sel1.Substring(0, sel1.Length - 1); } String sel0 = sel1; if (sel0.IndexOf('"') > -1) { sel0 = sel0.Replace("\"", "\\\""); } String tr0 = "trace( \""; if (aternate) { tr0 = setAlt + "( \""; } String tr1 = " : \" + "; String tr2 = " );"; if (setCmp) { tr0 = "trace(\""; if (aternate) { tr0 = setAlt + "(\""; } tr1 = ": \"+"; tr2 = ");"; } trace = tr0 + sel0 + tr1 + sel1 + tr2; exec = true; } } else { if (t.PreviousWordIsFunction) { String pckg = ""; String clas = ""; if (!t.HasArguments) { String tr0 = "trace( \""; if (aternate) { tr0 = setAlt + "( \""; } String tr1 = "\" );"; if (setCmp) { tr0 = "trace(\""; if (aternate) { tr0 = setAlt + "(\""; } tr1 = "\");"; } if (setPkg) { pckg = t.ArgPackageName + "."; } if (setCls) { clas = t.ArgClassName + "."; } trace = tr0 + pckg + clas + t.WordFromPosition + tr1; exec = true; } else { String tr0 = "trace( \""; if (aternate) { tr0 = setAlt + "( \""; } String tr1 = " > "; String tr2 = " );"; if (setCmp) { tr0 = "trace(\""; if (aternate) { tr0 = setAlt + "(\""; } tr1 = " > "; tr2 = ");"; } if (setPkg) { pckg = t.ArgPackageName + "."; } if (setCls) { clas = t.ArgClassName + "."; } String args = ""; String a = ""; for (Int32 i = 0; i < t.Arguments.Count; i++) { a = (String)t.Arguments[i]; if (i == 0) { if (!setCmp) { args += a + " : \" + " + a + " + "; } else { args += a + ": \"+" + a + "+"; } } else { if (!setCmp) { args += "\", " + a + " : \" + " + a + " + "; } else { args += "\", " + a + ": \"+" + a + "+"; } } } if (!setCmp) { args = args.Substring(0, args.Length - 3); } else { args = args.Substring(0, args.Length - 1); } trace = tr0 + pckg + clas + t.WordFromPosition + tr1 + args + tr2; exec = true; } } else { if (t.WordFromPosition != "") { String tr0 = "trace( \""; if (aternate) { tr0 = setAlt + "( \""; } String tr1 = " : \" + "; String tr2 = " );"; if (setCmp) { tr0 = "trace(\""; if (aternate) { tr0 = setAlt + "(\""; } tr1 = ": \"+"; tr2 = ");"; } trace = tr0 + t.WordFromPosition + tr1 + t.WordFromPosition + tr2; exec = true; } } } if (exec) { HelpTools.SetCaretReadyToTrace(sci, true); sci.InsertText(sci.CurrentPos, trace); HelpTools.GoToLineEnd(sci, setIns); } sci.EndUndoAction(); }