// Returns the index of the parameter where the cursor is currently positioned. // -1 means the cursor is outside the method parameter list // 0 means no parameter entered // > 0 is the index of the parameter (1-based) public int GetCurrentParameterIndex(ICompletionWidget widget, CodeCompletionContext ctx) { int cursor = widget.CreateCodeCompletionContext().TriggerOffset; int i = ctx.TriggerOffset; //if (i < 0 || i >= editor.Length || editor.GetCharAt (i) == ')') // return -1; if (i > cursor) return -1; else if (i == cursor) return 0; int parameterIndex = 1; while (i++ < cursor) { if (i >= widget.TextLength) break; char ch = widget.GetChar (i); if (ch == ',') parameterIndex++; else if (ch == ')') return -1; } return parameterIndex; }
public void InsertTemplate(object obj, EventArgs args) { ICompletionDataList completionList = new CompletionDataList(); completionList = ShowCodeTemplatesCommand(); currentCompletionContext = widget.CreateCodeCompletionContext();//this.editor.Caret.Offset CompletionWindowManager.IsTemplateModes = true; CompletionWindowManager.ShowWindow((char)0, completionList, widget, currentCompletionContext, OnCompletionWindowClosed); editor.GrabFocus(); }
public void InsertCompletion(object obj, EventArgs args) { if(widget.BanCompletion){ return; } CompletionWindowManager.IsTemplateModes = false; ICompletionDataList completionList = new CompletionDataList(); currentCompletionContext = widget.CreateCodeCompletionContext(); string writeWord = widget.GetCompletionText(currentCompletionContext,false); string fullWord = widget.GetCompletionText(currentCompletionContext,true); CompletionTyp completiontype = (CompletionTyp)widget.GetCompletionTyp(); if(completiontype == CompletionTyp.includeType){ completionList = editor.GetCompletionData(writeWord,fullWord); }else completionList = editor.GetCompletionData(writeWord,fullWord,completiontype); //ParseString(writeWord,fullWord,completiontype); CompletionWindowManager.ShowWindow((char)0, completionList, widget, currentCompletionContext, OnCompletionWindowClosed); editor.GrabFocus(); }
void OnCompletionWindowClosed() { currentCompletionContext = null; }
public CodeCompletionContextEventArgs(ICompletionWidget widget, CodeCompletionContext codeCompletionContext, string completedWord) { this.Widget = widget; this.CodeCompletionContext = codeCompletionContext; this.CompletedWord = completedWord; }
public static bool ShowWindow(char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext, System.Action closedDelegate) { try { if (wnd == null) { wnd = new CompletionListWindow (); wnd.WordCompleted += HandleWndWordCompleted; } try { if (!wnd.ShowListWindow (firstChar, list, completionWidget, completionContext, closedDelegate)) { if (list is IDisposable) ((IDisposable)list).Dispose (); DestroyWindow (); return false; } if (ForceSuggestionMode) wnd.AutoSelect = false; OnWindowShown (EventArgs.Empty); return true; } catch {//(Exception ex) { //LoggingService.LogError (ex.ToString ()); return false; } } finally { ParameterInformationWindowManager.UpdateWindow (completionWidget); } }
void ICompletionWidget.SetCompletionText(CodeCompletionContext ctx, string partial_word, string complete_word) { TextEditorData data = this.GetTextEditorData (); if (data == null || data.Document == null) return; int triggerOffset = ctx.TriggerOffset; int length = String.IsNullOrEmpty (partial_word) ? 0 : partial_word.Length; bool blockMode = false; if (data.IsSomethingSelected) { blockMode = data.MainSelection.SelectionMode == Mono.TextEditor.SelectionMode.Block; if (blockMode) { data.Caret.PreserveSelection = true; triggerOffset = data.Caret.Offset - length; } else { if (data.SelectionRange.Offset < ctx.TriggerOffset) triggerOffset = ctx.TriggerOffset - data.SelectionRange.Length; data.DeleteSelectedText (); } length = 0; } // | in the completion text now marks the caret position int idx = complete_word.IndexOf ('|'); if (idx >= 0) { complete_word = complete_word.Remove (idx, 1); } else { idx = complete_word.Length; } triggerOffset += data.EnsureCaretIsNotVirtual (); data.Document.EndAtomicUndo (); if (blockMode) { data.Document.BeginAtomicUndo (); int minLine = data.MainSelection.MinLine; int maxLine = data.MainSelection.MaxLine; int column = triggerOffset - data.Document.GetLineByOffset (triggerOffset).Offset; for (int lineNumber = minLine; lineNumber <= maxLine; lineNumber++) { LineSegment lineSegment = data.Document.GetLine (lineNumber); if (lineSegment == null) continue; int offset = lineSegment.Offset + column; data.Replace (offset, length, complete_word); } data.Caret.Offset = triggerOffset + idx; int minColumn = System.Math.Min (data.MainSelection.Anchor.Column, data.MainSelection.Lead.Column); data.MainSelection.Anchor = new DocumentLocation (data.Caret.Line == minLine ? maxLine : minLine, minColumn); data.MainSelection.Lead = new DocumentLocation (data.Caret.Line, this.Caret.Column); data.Document.CommitMultipleLineUpdate (data.MainSelection.MinLine, data.MainSelection.MaxLine); data.Caret.PreserveSelection = false; } else { //string word = GetWordBeforeCaret (editor).Trim (); //if (word.Length > 0) // offset = DeleteWordBeforeCaret (editor); //int triggerOffset2 =FindPrevWordOffset(triggerOffset); int triggerOffset2 =FindPrevWordOffset(this.Caret.Offset); string word = FindPrevWord(this.Caret.Offset); length =word.Length; /*if (triggerOffset2 != triggerOffset){ this.Remove (triggerOffset2, triggerOffset - triggerOffset2); this.Caret.Offset = triggerOffset2; }*/ data.Replace (triggerOffset2, length, complete_word); data.Caret.Offset = triggerOffset2 + idx; //data.Replace (triggerOffset, length, complete_word); //data.Caret.Offset = triggerOffset + idx; data.Document.BeginAtomicUndo (); } data.Document.CommitLineUpdate (data.Caret.Line); }
string ICompletionWidget.GetCompletionText(CodeCompletionContext ctx, bool full) { /*if (ctx == null) return null; int min = System.Math.Min (ctx.TriggerOffset, this.Caret.Offset); int max = System.Math.Max (ctx.TriggerOffset, this.Caret.Offset); return this.Document.GetTextBetween (min, max); */ string str=""; if(full) str = FindPrevWordWithoutDot(ctx.TriggerOffset); else str = FindPrevWord(ctx.TriggerOffset); //string str = FindPrevWord(ctx.TriggerOffset);//this.editor.Caret.Offset return str; }
/* CodeCompletionContext ICompletionWidget.CurrentCodeCompletionContext { get { return ICompletionWidget.CreateCodeCompletionContext (); } }*/ CodeCompletionContext ICompletionWidget.CreateCodeCompletionContext() { int triggerOffset = this.Caret.Offset; CodeCompletionContext result = new CodeCompletionContext (); result.TriggerOffset = triggerOffset; DocumentLocation loc = this.Document.OffsetToLocation (triggerOffset); result.TriggerLine = loc.Line + 1; result.TriggerLineOffset = loc.Column + 1; Gdk.Point p = this.DocumentToVisualLocation (loc); int tx = 0; int ty = 0; this.ParentWindow.GetOrigin (out tx, out ty); tx += this.Allocation.X; ty += this.Allocation.Y; result.TriggerXCoord = tx + p.X + this.TextViewMargin.XOffset - (int)this.HAdjustment.Value; result.TriggerYCoord = ty + p.Y - (int)this.VAdjustment.Value + this.LineHeight; result.TriggerTextHeight = this.LineHeight; return result; }