/// <summary> /// Control compisition of the text /// </summary> /// <param name="abbr"></param> private void ScanAbbreviation(AbbrevationSnippet abbr) { MatchCollection mc = vocabularyArgument.regArguments.Matches(abbr.Snippet); if (mc.Count == 0) return; abbr.Arguments = new WordTypes[mc.Count]; int index = 0; bool hasNeedSpace = false; int previousIndex = 0; List<int> indexSpace = new List<int>(); foreach (Match item in mc) { IMatch match = vocabularyArgument.SearchInfoByText(item.Value, 2); if (match != null) { InfoArguments info = match.Match(item.Value,0); if (info != null) { abbr.Arguments[index] |= info.regplace; switch (info.regplace) { case WordTypes.import: abbr.HasImport = true; break; case WordTypes.EventHandler: abbr.HasEventHandler = true; break; case WordTypes.AfterCurrentMember: abbr.HasAfterCurrentMember = true; break; default: break; } index++; if (info.hasNeedSpace) previousIndex = CheckNeedSpace(hasNeedSpace, previousIndex, indexSpace, item); hasNeedSpace = info.hasNeedSpace; } } } if (indexSpace.Count > 0) { StringBuilder sb = new StringBuilder(abbr.Snippet, abbr.Snippet.Length + indexSpace.Count); for (int i = indexSpace.Count - 1; i > -1; i--) { int indexs = indexSpace[i]; sb.Insert(indexs, " "); } abbr.Snippet = sb.ToString(); } }
//public bool checkTooMuchCursor() //{ // // for moment disable it // // for use future // return false; // //int ind = txtExpandesText.Text.IndexOf(cursor); // //if (ind!=-1) // //{ // // ind = txtExpandesText.Text.IndexOf(cursor, ind + cursor.Length); // // if (ind != -1) // // return true; // //} // //return false; //} private void btnConfirm_Click(object sender, EventArgs e) { if (!ControlField()) return; if (isAdd) { if (AbbrevationExist(txtAbbrevation.Text.Trim())) { MessageBox.Show("Abbrevation already present!!"); return; } if (ErrorCreateParameters()) { MessageBox.Show("No surround bracket on ${createParameters}!!!"); return; } ListViewItem item = new ListViewItem(txtAbbrevation.Text.Trim()); ListViewItem.ListViewSubItem sub = new ListViewItem.ListViewSubItem(); //if (checkTooMuchCursor()) //{ // MessageBox.Show("Only a ${cursor} is permitted!!!"); // return; //} AbbrevationSnippet abr = new AbbrevationSnippet(txtExpandesText.Text.Trim()); ScanAbbreviation( abr); sub.Text = abr.Snippet ; item.SubItems.Add(sub); lsvCodeTemplate.Items.Add(item); //sub = testo _settings.AbbrevationDictionary["." +(string) cmbLanguage.SelectedItem].Add(item.Text, abr); txtExpandesText.Text = abr.Snippet; isAdd = false; EnabledControl(); item.Selected = true; CompletionListAbbreviations = null; } else if (isModify) { if (ErrorCreateParameters()) { MessageBox.Show("No surround bracket on ${createParameters}!!!"); return; } foreach (ListViewItem item in lsvCodeTemplate.SelectedItems) { if (item != null) { string text = txtAbbrevation.Text.Trim(); foreach (ListViewItem itm in lsvCodeTemplate.Items) { if (itm.Text == text && item.Index != itm.Index) { MessageBox.Show("Abbrevation already present!!"); return; } } string oldValue = item.Text; item.Text = text; AbbrevationSnippet abr = new AbbrevationSnippet(txtExpandesText.Text.Trim()); _settings.AbbrevationDictionary["." + (string)cmbLanguage.SelectedItem].Remove(oldValue); ScanAbbreviation( abr); _settings.AbbrevationDictionary["." + (string)cmbLanguage.SelectedItem].Add(item.Text,abr); if (item.SubItems.Count > 0) item.SubItems[1].Text = abr.Snippet; txtExpandesText.Text = abr.Snippet; // .Add(item.Text, abr); item.Selected = true; CompletionListAbbreviations = null; } } isModify = false; EnabledControl(); } }
/// <summary> /// Loads the plugin settings /// </summary> public void LoadSettings() { this.settingsQuickGenerator = new Settings(); if (!File.Exists(this.settingFilename)) { this.SaveSettings(); } else { Object obj = ObjectSerializer.Deserialize(this.settingFilename, this.settingsQuickGenerator); this.settingsQuickGenerator = (Settings)obj; } if (settingsQuickGenerator.abbrevationDictList == null) { settingsQuickGenerator.abbrevationDictList = new Dictionary<string, Dictionary<string, AbbrevationSnippet>>(); settingsQuickGenerator.abbrevationDictList.Add(".as", new Dictionary<string, AbbrevationSnippet>()); settingsQuickGenerator.abbrevationDictList.Add(".other", new Dictionary<string, AbbrevationSnippet>()); AbbrevationSnippet abr = new AbbrevationSnippet("for(var ${var=\"i\" list=\"ls3\"}:int=0; ${var=\"i\"} < ${\"length\"}; ${var=\"i\"}++)\r\n{\r\n\t${SafeZone}\r\n}"); abr.Arguments = new WordTypes[5]; abr.Arguments[0] = WordTypes.var; abr.Arguments[1] = WordTypes.var; abr.Arguments[2] = WordTypes.place; abr.Arguments[3] = WordTypes.var; abr.Arguments[4] = WordTypes.SafeZone; settingsQuickGenerator.abbrevationDictList[".as"].Add("fori", abr); abr = new AbbrevationSnippet("${list=\"ls1\"} function ${var=\"name\"}(${\"\"}):void\r\n{\r\n\t${SafeZone}\r\n}"); abr.Arguments = new WordTypes[4]; abr.Arguments[0] = WordTypes.list; abr.Arguments[1] = WordTypes.var; abr.Arguments[2] = WordTypes.place; abr.Arguments[3] = WordTypes.SafeZone; settingsQuickGenerator.abbrevationDictList[".as"].Add("fnc", abr); abr = new AbbrevationSnippet("var ${var=\"request\"}:${Import=\"URLRequest\"} = new URLRequest(${browser});\r\nvar ${var=\"loader\"}:Loader = new ${Import=\"Loader\"}();\r\n${var=\"loader\"}.contentLoaderInfo.addEventListener(${Import=\"Event\"}.COMPLETE, ${EventHandler=\"completeHandler\"});\r\n${var=\"loader\"}.load(${var=\"request\"});"); abr.Arguments = new WordTypes[10]; abr.Arguments[0] = WordTypes.var; abr.Arguments[1] = WordTypes.import; abr.Arguments[2] = WordTypes.browser; abr.Arguments[3] = WordTypes.var; abr.Arguments[4] = WordTypes.import; abr.Arguments[5] = WordTypes.var; abr.Arguments[6] = WordTypes.import; abr.Arguments[7] = WordTypes.EventHandler; abr.Arguments[8] = WordTypes.var; abr.Arguments[9] = WordTypes.var; abr.HasImport = true; abr.HasEventHandler = true; settingsQuickGenerator.abbrevationDictList[".as"].Add("load", abr); //dictAbbrevations[".as"].Add("vr", new AbbrevationSnippet("${list=0}var ${cursor}:${showCompType};")); abr = new AbbrevationSnippet("${list=\"ls2\"} ${\"a\"}:${cmp=\"Number\"} = ${\"0\"};"); abr.Arguments = new WordTypes[4]; abr.Arguments[0] = WordTypes.list; abr.Arguments[1] = WordTypes.place; abr.Arguments[2] = WordTypes.cmp; abr.Arguments[3] = WordTypes.place; settingsQuickGenerator.abbrevationDictList[".as"].Add("vr", abr); abr = new AbbrevationSnippet("var ${\"mc\"}:${var=\"MovieClip\" showCmp} = new ${var=\"MovieClip\"}(${createParameters});"); abr.Arguments = new WordTypes[4]; abr.Arguments[0] = WordTypes.place; abr.Arguments[1] = WordTypes.var; abr.Arguments[2] = WordTypes.var; abr.Arguments[3] = WordTypes.createParameters; settingsQuickGenerator.abbrevationDictList[".as"].Add("nw", abr); abr = new AbbrevationSnippet("${var=\"name\"}(${createParameters});${AfterCurrentMember=\"fnc\"}"); abr.Arguments = new WordTypes[3]; abr.Arguments[0] = WordTypes.var; abr.Arguments[1] = WordTypes.createParameters; abr.Arguments[2] = WordTypes.AfterCurrentMember; abr.HasAfterCurrentMember = true; settingsQuickGenerator.abbrevationDictList[".as"].Add("out", abr); if (settingsQuickGenerator.Abbreviations.CustomList == null) { settingsQuickGenerator.Abbreviations.CustomList = new Dictionary<string, List<string>>(); List<string> ls = new List<string>(); ls.Add("public"); ls.Add("private"); ls.Add("protected"); settingsQuickGenerator.Abbreviations.CustomList.Add("ls1", ls); ls = new List<string>(); ls.Add("var"); ls.Add("public var"); ls.Add("private var"); settingsQuickGenerator.Abbreviations.CustomList.Add("ls2", ls); ls = new List<string>(); ls.Add("x"); ls.Add("y"); ls.Add("z"); settingsQuickGenerator.Abbreviations.CustomList.Add("ls3", ls); } } }
public string MakeTextFromSnippet(ScintillaControl sci, AbbrevationSnippet abbrSnippet) { StringBuilder sbSnippet = new StringBuilder(abbrSnippet.Snippet); if (isMonitoring) DeactiveMonitorWords(); if(abbrSnippet.HasImport) imports = new List<string>(); if (abbrSnippet.HasEventHandler) eventsHandler = new List<int>(); if (abbrSnippet.HasAfterCurrentMember) AfterCurrentMember = new List<string>(); _dictCustomList = _setting.customList; int pos = sci.CurrentPos; int CodePage = sci.CodePage; string nl = ASCompletion.Completion.ASComplete.GetNewLineMarker(sci.EOLMode); int curLine = sci.LineFromPosition(pos); int startLine = sci.PositionFromLine(curLine); char ch = (char) sci.CharAt(startLine); string tabString = String.Empty; while ( Char.IsWhiteSpace( ch)) { if(ch=='\n' || ch=='\r') break; tabString += ch; ch = (char)sci.CharAt(++startLine); } sbSnippet.Replace("\r",""); sbSnippet.Replace("\n", nl + tabString); if (abbrSnippet.Arguments == null) return sbSnippet.ToString(); previousLenPlace = 0; indexArgument = 0; numCursors = 0; MatchCollection mtc = _vocabularyArgument.regArguments.Matches(sbSnippet.ToString()); int lenght = mtc.Count; Match m =null; Match var; string textClipBoard = ""; int valueTextClipBoard = 0; char[] chars = null; int previousPos=0; for (int i = 0; i < lenght; i++) { m = mtc[i]; /// if CodePage is 65001... pos= is position in scintilla text /// and previousLen is position on abbrSnippet if (indexArgument == abbrSnippet.Arguments.Length) { indexArgument = 0; lsVar.Clear(); } switch (abbrSnippet.Arguments[indexArgument]) { #region Place case WordTypes.place: var = _vocabularyArgument.regPlace.Match(m.Value); if (var.Success) { WordRegion wr = new WordRegion(); int correctPosString = m.Index - previousLenPlace; int count = correctPosString - previousPos; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); previousLenPlace += m.Length - var.Length; sbSnippet.Remove(correctPosString, m.Length); sbSnippet.Insert(correctPosString, var.Value); previousPos = correctPosString + var.Length; if (CodePage != 65001) { wr.startWord = pos + chars.Length; wr.endWord = wr.startWord + var.Length; pos += chars.Length + var.Length; } else { int strLen = Encoding.UTF8.GetByteCount( chars ); int valueLen = Encoding.UTF8.GetByteCount(var.Value); wr.startWord = pos + strLen; wr.endWord = wr.startWord + valueLen; pos += strLen + valueLen; } wr.type = WordRegion.kind.place; if (curWord != null) { curWord.NextWord = wr; secondLastWord = curWord; } Words.Add(wr); curWord = wr; curIndWord++; numCursors++; indexArgument++; // sb.Append(var.Value); } break; #endregion #region cursor case WordTypes.SafeZone: if (m.Value == VocabularyArgument.SafeZone) { WordRegion wr = new WordRegion(); wr.type = WordRegionBase.kind.cursor; //string previousTest = textSnippet.Substring(previousLenPlace, m.Index - previousLenPlace); //sb.Append(previousTest); int correctPosString = m.Index - previousLenPlace; int count = correctPosString - previousPos; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); previousLenPlace += m.Length; sbSnippet.Remove(correctPosString, m.Length); previousPos = correctPosString; if (CodePage != 65001) { wr.startWord = pos + chars.Length; wr.endWord = wr.startWord; pos += chars.Length; } else { int strLen = Encoding.UTF8.GetByteCount( chars ); // int valueLen = Encoding.UTF8.GetByteCount(var.Value); wr.startWord = pos + strLen; wr.endWord = wr.startWord ; pos += strLen ; } if (curWord != null) { curWord.NextWord = wr; secondLastWord = curWord; } Words.Add(wr); curWord = wr; curIndWord++; numCursors++; indexArgument++; } break; #endregion #region createParameters case WordTypes.createParameters: if (m.Value == VocabularyArgument.CREATEPARAMATERS) { WordRegion wr = new WordRegion(); wr.type = WordRegionBase.kind.createParameters; int correctPosString = m.Index - previousLenPlace; int count = correctPosString - previousPos; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); previousLenPlace += m.Length; sbSnippet.Remove(correctPosString, m.Length); previousPos = correctPosString; if (CodePage != 65001) { wr.startWord = pos + chars.Length; wr.endWord = wr.startWord; pos += chars.Length; } else { int strLen = Encoding.UTF8.GetByteCount( chars ); wr.startWord = pos + strLen; wr.endWord = wr.startWord; pos += strLen; } if (curWord != null) { curWord.NextWord = wr; secondLastWord = curWord; } Words.Add(wr); curWord = wr; curIndWord++; numCursors++; indexArgument++; } break; #endregion #region clipboard case WordTypes.Clipboard: if (m.Value == VocabularyArgument.CLIPBOARD) { if (textClipBoard.Length==0) { textClipBoard = System.Windows.Forms.Clipboard.GetText().Trim(); valueTextClipBoard = Encoding.UTF8.GetByteCount(textClipBoard); } int correctPosString = m.Index - previousLenPlace; previousLenPlace += m.Length - textClipBoard.Length; sbSnippet.Remove(correctPosString, m.Length); sbSnippet.Insert(correctPosString, textClipBoard); if (CodePage != 65001) { pos += chars.Length + textClipBoard.Length; } else { int count = correctPosString - previousPos; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); int strLen = Encoding.UTF8.GetByteCount( chars ); pos += strLen + valueTextClipBoard; } previousPos = correctPosString + textClipBoard.Length; indexArgument++; } break; #endregion #region showcomp case WordTypes.cmp: var = _vocabularyArgument.regCompType.Match(m.Value); //if (var.Value.Length!=0) if(var.Success) { WordRegion wr = new WordRegion(); wr.type = WordRegion.kind.showCompType; int correctPosString = m.Index - previousLenPlace; int count = correctPosString - previousPos; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); previousLenPlace += m.Length - var.Length; sbSnippet.Remove(correctPosString, m.Length); sbSnippet.Insert(correctPosString, var.Value); previousPos = correctPosString + var.Length; if (CodePage != 65001) { wr.startWord = pos + chars.Length; wr.endWord = wr.startWord + var.Length; pos += chars.Length + var.Length; } else { int strLen = Encoding.UTF8.GetByteCount( chars ); int valueLen = Encoding.UTF8.GetByteCount(var.Value); wr.startWord = pos + strLen; wr.endWord = wr.startWord + valueLen; pos += strLen + valueLen; } if (curWord != null) { curWord.NextWord = wr; secondLastWord = curWord; } Words.Add(wr); curWord = wr; curIndWord++; numCursors++; indexArgument++; } break; #endregion #region variable link case WordTypes.var: var = _vocabularyArgument.regVar.Match(m.Value); if (var.Value.Length!=0) { VarWordRegion varRootWR = null; VarDuplicateWordRegion vdwr = null; VarWordRegion vwr = null; WordRegionBase wr; // there is a root? if (lsVar.TryGetValue(var.Value, out varRootWR)) { vdwr = new VarDuplicateWordRegion(); wr = vdwr; vdwr.type = WordRegionBase.kind.VarLink; } else { vwr = new VarWordRegion(); vwr.ValueVar = var.Value; curIndWord++; string option = m.Value.Substring(var.Index + var.Length); Match mc = _vocabularyArgument.regList.Match(option); if (mc.Value.Length!=0) { vwr.indList = mc.Value; vwr.type = WordRegionBase.kind.customList; } else if (option.IndexOf("showCmp") != -1) vwr.type = WordRegion.kind.VarLinkAndComp; else vwr.type = WordRegionBase.kind.VarLink; wr = vwr; vwr.ChangeVarWord += new VarWordRegion.ChangeVarEventHandler(vwr_ChangeVarWord); } //string previousTest = textSnippet.Substring(previousLenPlace, m.Index - previousLenPlace); //sb.Append(previousTest); // questo serve per cancellare index int correctPosString = m.Index - previousLenPlace; int count = correctPosString - previousPos; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); previousLenPlace += m.Length - var.Length; sbSnippet.Remove(correctPosString, m.Length); sbSnippet.Insert(correctPosString, var.Value); previousPos = correctPosString + var.Length; if (CodePage != 65001) { wr.startWord = pos + chars.Length; wr.endWord = wr.startWord + var.Length; pos += chars.Length + var.Length; } else { int strLen = Encoding.UTF8.GetByteCount( chars ); int valueLen = Encoding.UTF8.GetByteCount(var.Value); wr.startWord = pos + strLen; wr.endWord = wr.startWord + valueLen; pos += strLen + valueLen; } if (curWord != null) { curWord.NextWord = wr; secondLastWord = curWord; } curWord = wr; if (varRootWR != null) { varRootWR.InsertVarDuplicate(vdwr); //varRootWR.lstWords.Add(vdwr); } else { lsVar.Add(var.Value, vwr); Words.Add(wr); } indexArgument++; numCursors++; // sb.Append(var.Value); } break; #endregion #region mbrname case WordTypes.mbrname: if (m.Value == VocabularyArgument.MbrName) { string strMbrName = ""; if (ASContext.Context.CurrentMember != null) { strMbrName = ASContext.Context.CurrentMember.Name; } int correctPosString = m.Index - previousLenPlace; previousLenPlace += m.Length - strMbrName.Length; sbSnippet.Remove(correctPosString, m.Length); sbSnippet.Insert(correctPosString, strMbrName); if (CodePage != 65001) { pos += chars.Length + strMbrName.Length; } else { int count = correctPosString - previousPos; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); int strLen = Encoding.UTF8.GetByteCount( chars ); pos += strLen + strMbrName.Length; } previousPos = correctPosString + strMbrName.Length; indexArgument++; } break; #endregion #region "Browser" case WordTypes.browser: // -------------- browser if (m.Value == VocabularyArgument.BROWSER) { WordRegion wr = new WordRegion(); wr.type = WordRegion.kind.browser; int correctPosString = m.Index - previousLenPlace; int count = correctPosString - previousPos; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); previousLenPlace += m.Length; sbSnippet.Remove(correctPosString, m.Length); previousPos = correctPosString; if (CodePage != 65001) { wr.startWord = pos + chars.Length; wr.endWord = wr.startWord; pos += chars.Length; } else { int strLen = Encoding.UTF8.GetByteCount( chars ); wr.startWord = pos + strLen; wr.endWord = wr.startWord; pos += strLen ; } // wr.lineNumber = lineNumber; if (curWord != null) { curWord.NextWord = wr; secondLastWord = curWord; } Words.Add(wr); curWord = wr; curIndWord++; // wr.index = curIndWord; numCursors++; indexArgument++; } break; #endregion #region AfterCurrentMember case WordTypes.AfterCurrentMember: var = _vocabularyArgument.regAfterCurrentMember.Match(m.Value); if (var.Value.Length!=0) { if (ASContext.Context.CurrentMember != null) { if (!AfterCurrentMember.Contains(var.Value)) { AfterCurrentMember.Add(var.Value); dontCreateLastWord = true; } //strMbrName = ASContext.Context.CurrentMember.Name; } int correctPosString = m.Index - previousLenPlace; int count = correctPosString - previousPos; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); previousLenPlace += m.Length; sbSnippet.Remove(correctPosString, m.Length); previousPos = correctPosString; if (CodePage != 65001) { pos += chars.Length; } else { int strLen = Encoding.UTF8.GetByteCount( chars ); pos += strLen; } indexArgument++; } break; #endregion #region Custom list case WordTypes.list: //-------- CUSTOM LIST COMPLETITION var = _vocabularyArgument.regList.Match(m.Value); if (var.Value.Length!=0) { WordCustomList wr = new WordCustomList(); wr.type = WordRegion.kind.customList; string value = ""; List<string> ls; if (_dictCustomList.TryGetValue(var.Value, out ls)) { if(ls.Count>0) value = ls[0]; } int correctPosString = m.Index - previousLenPlace; int count = correctPosString - previousPos; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); previousLenPlace += m.Length - value.Length; sbSnippet.Remove(correctPosString, m.Length); sbSnippet.Insert(correctPosString, value); previousPos = correctPosString + value.Length; if (CodePage != 65001) { wr.startWord = pos + chars.Length; wr.endWord = wr.startWord + value.Length; pos += chars.Length + value.Length; } else { int strLen = Encoding.UTF8.GetByteCount( chars ); int valueLen = Encoding.UTF8.GetByteCount(value); wr.startWord = pos + strLen; wr.endWord = wr.startWord + valueLen; pos += strLen + valueLen; } // wr.lineNumber = lineNumber; wr.indList = var.Value; if (curWord != null) { curWord.NextWord = wr; secondLastWord = curWord; } Words.Add(wr); curWord = wr; curIndWord++; // wr.index = curIndWord; numCursors++; indexArgument++; } break; #endregion #region import case WordTypes.import: var = _vocabularyArgument.regImport.Match(m.Value); if (var.Value.Length!=0) { int correctPosString = m.Index - previousLenPlace; previousLenPlace += m.Length - var.Length; sbSnippet.Remove(correctPosString, m.Length); sbSnippet.Insert(correctPosString, var.Value); if (CodePage != 65001) { pos += chars.Length + var.Length; } else { int count = correctPosString - previousPos + var.Value.Length; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); int strLen = Encoding.UTF8.GetByteCount( chars ); pos += strLen ; } previousPos = correctPosString + var.Length; if (!imports.Contains(var.Value)) imports.Add(var.Value); indexArgument++; } break; #endregion #region EventHandler case WordTypes.EventHandler: var = _vocabularyArgument.regEventHandler.Match(m.Value); if (var.Value.Length!=0) { int correctPosString = m.Index - previousLenPlace; previousLenPlace += m.Length - var.Length; sbSnippet.Remove(correctPosString, m.Length); sbSnippet.Insert(correctPosString, var.Value); if (CodePage != 65001) { pos += chars.Length + var.Length; } else { int count = correctPosString - previousPos + var.Value.Length; chars = new char[count]; sbSnippet.CopyTo(previousPos, chars, 0, count); int strLen = Encoding.UTF8.GetByteCount( chars ); pos += strLen; } eventsHandler.Add(pos); previousPos = correctPosString + var.Length; indexArgument++; } break; #endregion } } if (!dontCreateLastWord) ConvertLastWord(); return sbSnippet.ToString(); }
private void GenerateAfterCurrentMember() { AbbrevationSnippet abbrevationSnippet; int TotalLenghtArray = 0; int index = 0; QuickGenerator.Abbreviation.WordTypes[] regPlace = null; System.Text.StringBuilder sb = null; ScintillaControl sci = ASCompletion.Context.ASContext.CurSciControl; string nl = ASCompletion.Completion.ASComplete.GetNewLineMarker(sci.EOLMode); bool hasImport = false; bool hasAfterCurrentMember =false; bool hasEvent = false; foreach (String afterName in currentCreateWords.AfterCurrentMember) { if (dictAbbreviations.TryGetValue(afterName, out abbrevationSnippet)) { if (abbrevationSnippet.HasAfterCurrentMember) hasAfterCurrentMember = true; if (abbrevationSnippet.HasEventHandler) hasEvent = true; if (abbrevationSnippet.HasImport) hasImport = true; if (abbrevationSnippet.Arguments == null) TotalLenghtArray += 0; else TotalLenghtArray += abbrevationSnippet.Arguments.Length; if (regPlace == null) { if(abbrevationSnippet.Arguments==null) regPlace = new WordTypes[0]; else regPlace = new WordTypes[abbrevationSnippet.Arguments.Length]; sb = new System.Text.StringBuilder(abbrevationSnippet.Snippet.Length); sb.Append(abbrevationSnippet.Snippet); } else { sb.Append(nl); sb.Append(abbrevationSnippet.Snippet); index = regPlace.Length; Array.Resize(ref regPlace, TotalLenghtArray); } if (abbrevationSnippet.Arguments != null) abbrevationSnippet.Arguments.CopyTo(regPlace, index); } } if (sb == null) { currentCreateWords.ConvertLastWord(); return; } AbbrevationSnippet newAbbreviation = new AbbrevationSnippet(sb.ToString()); if(regPlace.Length!=0) newAbbreviation.Arguments = regPlace; else newAbbreviation.Arguments = null; newAbbreviation.HasImport = hasImport; newAbbreviation.HasEventHandler = hasEvent; newAbbreviation.HasAfterCurrentMember = hasAfterCurrentMember; MemberModel mm = ASContext.Context.CurrentMember; ClassModel cm =ASContext.Context.CurrentClass; int numBraces = 0; if (cm.LineTo == mm.LineTo) numBraces++; MemberModel item; int length = cm.Members.Count; for (int i = 0; i < length; i++) { item = cm.Members[i]; if (item.Name != mm.Name) { if (item.LineTo == mm.LineTo) numBraces++; } } int pos = 0; int currentPos = sci.CurrentPos; if (numBraces > 0) { string linestr = sci.GetLine(mm.LineTo); int indexBrace = 0; for (int i = 0; i < numBraces; i++) { indexBrace = linestr.LastIndexOf('}'); } pos = sci.PositionFromLine(mm.LineTo); pos += indexBrace ; } else { pos = sci.PositionFromLine(mm.LineTo + 1); } string tabString = new string('\t', sci.GetLineIndentation(mm.LineFrom) / sci.Indent); sci.InsertText(pos, nl + tabString + nl); pos = pos + tabString.Length + nl.Length; // sci.GotoPos(pos + tabString.Length +nl.Length ); sci.GotoPos(pos); // sci.MBSafeGotoPos(pos + tabString.Length + nl.Length); // string tabString2 = new string('\t', sci.GetLineIndentation(sci.LineFromPosition(pos)) / sci.Indent); string newSnippet = currentCreateWords.MakeTextFromSnippet(sci, newAbbreviation); sci.InsertText(pos, newSnippet); //sci.MBSafeInsertText(sci.CurrentPos, newSnippet); sci.GotoPos(currentPos); currentCreateWords.ConvertLastWord(); }
public void EventKey(PluginCore.KeyEvent k) { if (k.Value == settings.AbbrevationPlusFormatterShortCut) { if (reformatterCode == null) { System.Windows.Forms.MessageBox.Show("Reformat Code must be enable!!!"); return; } if (settings.abbrevationDictList == null) { System.Windows.Forms.MessageBox.Show("Insert abbreviations before!!"); return; } ScintillaControl sci = ASCompletion.Context.ASContext.CurSciControl; if (sci == null) return; if (dictionaryCreateWords.TryGetValue(sci.Handle, out currentCreateWords)) { if (currentCreateWords.IsMonitoring) { ControlCaretPosition(); return; } } int linePos = sci.LineFromPosition(sci.CurrentPos); string lineText = sci.GetLine(linePos); string[] str = reformatterCode.DivideStringCode(lineText); insertOnly = true; // Nothing Divisor ; so do a normal abbrevation if (str == null) { ProcessAbbrevation(sci); return; } bool hasOperator = reformatterCode.SearchForOperators(str[1], true); if (!hasOperator) { ProcessAbbrevation(sci); return; } int startLine = sci.PositionFromLine(linePos); int pos = startLine + str[0].TrimEnd().Length; int start = 0; int end = 0; // sci.CurrentPos = pos; //string word = sci.GetWordFromPosition(pos); string word = GetWordFromPosition(sci, pos, ref start,ref end); // string expandeText = ""; AbbrevationSnippet abbrSnippet = null; if (word !=null ) { String ext = System.IO.Path.GetExtension(ASContext.Context.CurrentFile).ToLower(); ; dictAbbreviations = null; if (!settings.abbrevationDictList.TryGetValue(ext, out dictAbbreviations)) { dictAbbreviations = settings.abbrevationDictList[".other"]; } dictAbbreviations.TryGetValue(word,out abbrSnippet); } if (abbrSnippet != null) { //string reformatterString = reformatterCode.Reformat(abbrSnippet.Snippet); AbbrevationSnippet reformatAbbreviation = new AbbrevationSnippet(reformatterCode.Reformat(abbrSnippet.Snippet)); reformatAbbreviation.Arguments = abbrSnippet.Arguments; reformatAbbreviation.HasAfterCurrentMember = abbrSnippet.HasAfterCurrentMember; reformatAbbreviation.HasEventHandler = abbrSnippet.HasEventHandler; reformatAbbreviation.HasImport = abbrSnippet.HasImport; sci.GotoPos(start); sci.BeginUndoAction(); if (currentCreateWords != null) cw_MonitorOnWordsDeactive(currentCreateWords); CreateWords cwNew = CreateNewWords(); string elaborateText = currentCreateWords.MakeTextFromSnippet(sci, reformatAbbreviation); sci.SetSel(start, end); sci.ReplaceSel( elaborateText); sci.DelLineRight(); if (abbrSnippet.Arguments == null) { sci.EndUndoAction(); return; } DoBeforeMonitor(); if (!currentCreateWords.TryActivateMonitor()) { cwNew.MonitorOnWordsActive -= new OnMonitorActiveEventHanlder(cw_MonitorOnWordsActive); cwNew.MonitorOnWordsDeactive -= new OnMonitorActiveEventHanlder(cw_MonitorOnWordsDeactive); } else { currentCreateWords = cwNew; } sci.EndUndoAction(); return; } else { string newString = reformatterCode.Reformat(str[0] + ";"); sci.GotoPos(startLine); sci.BeginUndoAction(); sci.DelLineRight(); sci.InsertText(sci.CurrentPos, newString); sci.EndUndoAction(); sci.GotoPos(startLine + newString.Length); } } else if (k.Value == settings.AbbrevationShortCut) { ScintillaControl sci = ASCompletion.Context.ASContext.CurSciControl; if (sci == null) return; if (dictionaryCreateWords.TryGetValue(sci.Handle, out currentCreateWords)) { if (currentCreateWords.IsMonitoring) { ControlCaretPosition(); return; } } if (sci != null) if (sci.Focused) ProcessAbbrevation(sci); } else if (k.Value == settings.GotoAbbreviationShortCut) { if (dictionaryCreateWords != null && dictionaryCreateWords.Count>0) { if (dictionaryCreateWords.Count == 1) { Dictionary<IntPtr, CreateWords>.ValueCollection.Enumerator enumerator = dictionaryCreateWords.Values.GetEnumerator(); enumerator.MoveNext(); CreateWords currentCreateWords = enumerator.Current; if (currentCreateWords != null) { currentCreateWords.GoToCurrentWord(); } } else { List<PluginCore.ICompletionListItem> lcomp = new List<PluginCore.ICompletionListItem>(); foreach (KeyValuePair<IntPtr,CreateWords> data in dictionaryCreateWords) { lcomp.Add(new GotoAbbreviationCmd(data.Value.FileName ,data.Value.SciMonitor.FileName, ManagerResources.GoToAbbreviationBitmap, data.Value)); } PluginMain.custCompletion.Show(lcomp, false); } } } else if (k.Value == settings.GenerateSensibleAreaShortCut) { if (PathExplorer.IsWorking) { WaitFinishPathExplorer(); } if (ASContext.Context.CurrentMember != null) { MemberModel currentMember = ASContext.Context.CurrentMember; if (currentMember.Parameters == null || currentMember.Parameters.Count == 0) return; ScintillaControl sci= ASContext.CurSciControl; string declaration = sci.GetLine(currentMember.LineFrom); int startPos = declaration.IndexOf('('); int startLine = sci.PositionFromLine(currentMember.LineFrom); if (currentMember.Parameters.Count == 1) { int index = declaration.IndexOf(currentMember.Parameters[0].Name, startPos); int pos = startPos + startLine +1; sci.SetSel(pos, pos + currentMember.Parameters[0].Name.Length); return; } int j = -1; int[] positionsSensibleArea = new int[currentMember.Parameters.Count * 2]; int length = positionsSensibleArea.Length; for (int i = 0; i < length; i+=2) { j++; int index = declaration.IndexOf(currentMember.Parameters[j].Name, startPos); positionsSensibleArea[i] = index; positionsSensibleArea[i + 1] = index + currentMember.Parameters[j].Name.Length; } CreateWords cw; if (dictionaryCreateWords.TryGetValue(sci.Handle, out cw)) { cw_MonitorOnWordsDeactive(cw); currentSci = ASContext.CurSciControl; } currentCreateWords = CreateNewWords(); currentCreateWords.GenerateSensibleArea(startLine, positionsSensibleArea, sci); } } }