public GoToAll(AsmProject project, Events events) { _completionProvider = new AllCompletion(project, events); var dummyControl = new TextEditor(); // TODO: Create own, improved auto-completion window to remove reliance on texteditor InitializeComponent(); _searchQuery.TextChanged += (s, a) => { if (_searchQuery.Text.Length == 0) { if (_completionWindow != null) { _completionWindow.Close(); } _completionWindow = null; return; } _completionProvider.PreSelection = _searchQuery.Text; if (_completionWindow != null && !_completionWindow.IsDisposed) { _completionWindow.RefreshCompletionData(null, ' '); return; } _completionWindow = CompletionWindow.ShowCompletionWindow(this, dummyControl, _completionProvider, PointToScreen(new Point(_searchQuery.Left, _searchQuery.Bounds.Bottom))); if (_completionWindow != null) { _completionWindow.InsertCompleted += Close; } }; }
public static CompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, ICompletionDataProvider completionDataProvider, Point location) { CompletionDataProvider = completionDataProvider; var completionData = CompletionDataProvider.GenerateCompletionData(null, null, ' '); if (completionData.Length == 0) { return(null); } var window = new CompletionWindow(parent, control); window.RefreshList(completionData); //window.SetLocation(); window.Location = location; window.ShowCompletionWindow(); return(window); }
public static CompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar) { CompletionDataProvider = completionDataProvider; var completionData = CompletionDataProvider.GenerateCompletionData(fileName, control.ActiveTextAreaControl.TextArea, firstChar); if (completionData.Length == 0) { return(null); } var window = new CompletionWindow(parent, control); window.RefreshList(completionData); window.SetLocation(); window.ShowCompletionWindow(); return(window); }
private void ShowIntellisense(char keyValue, int wordLengthLimit) { if (_completionDataProvider == null) { return; } if (ActiveTextAreaControl.SelectionManager.HasSomethingSelected) { return; } var caretPosition = ActiveTextAreaControl.Caret; var line = Document.GetLineSegment(caretPosition.Line); var word = line.GetWord(caretPosition.Column - 1); var wordType = (word as AsmWord)?.WordType; if (wordType == AsmWord.AsmWordType.Comment) { if (_codeCompletionWindow != null) { _codeCompletionWindow.Close(); } return; } if (wordType == AsmWord.AsmWordType.Opcode && wordLengthLimit > 0 && !_forcedAutoCompleteWindow) { if (_codeCompletionWindow != null) { _codeCompletionWindow.Close(); } return; } if ((wordType == AsmWord.AsmWordType.NumberByte || wordType == AsmWord.AsmWordType.NumberWord) && wordLengthLimit > 0 && !_forcedAutoCompleteWindow) { if (_codeCompletionWindow != null) { _codeCompletionWindow.Close(); } return; } if (word.Word.Trim().Length < wordLengthLimit) { if ((word.IsWhiteSpace || string.IsNullOrWhiteSpace(word.Word)) && !_forcedAutoCompleteWindow && _codeCompletionWindow != null) { _codeCompletionWindow.Close(); } return; } var provider = _completionDataProvider; if (IsIncludeLine(line) && caretPosition.Column > 0) { // Auto-complete file names for include statements var fullLine = Document.GetText(line); var stringStart = fullLine.LastIndexOf("\"", caretPosition.Column - 1); if (stringStart > 0 && stringStart == fullLine.IndexOf("\"")) { // Open file completion if caret is after the first " of the line provider = _fileCompletionDataProvider; provider.PreSelection = fullLine.Substring(stringStart, caretPosition.Column - stringStart); } } if (provider == _completionDataProvider) { // Regular auto-complete for symbols if (word.Offset + word.Length != caretPosition.Column) { if (_codeCompletionWindow != null) { _codeCompletionWindow.Close(); } return; } provider.PreSelection = word.Word; } if (_codeCompletionWindow != null) { _codeCompletionWindow.RefreshCompletionData(File.File.FullName, keyValue); return; } try { _codeCompletionWindow = CompletionWindow.ShowCompletionWindow( ParentForm, // The parent window for the completion window this, // The text editor to show the window for File.File.FullName, // Filename - will be passed back to the provider provider, // Provider to get the list of possible completions keyValue // Key pressed - will be passed to the provider ); } catch (ArgumentOutOfRangeException) { _codeCompletionWindow = null; } if (_codeCompletionWindow != null) // ShowCompletionWindow can return null when the provider returns an empty list { _codeCompletionWindow.CloseWhenCaretAtBeginning = false; _codeCompletionWindow.Closed += CloseCodeCompletionWindow; } }