bool TextArea_KeyEventHandler(char ch) { if (provider != null) { if (codeCompletionWindow != null) { if (char.IsLetterOrDigit(ch) || ch == '_' || ch == '$') { if (codeCompletionWindow.ProcessKeyEvent(ch)) { return(true); } } else { codeCompletionWindow.Close(); } } if (codeCompletionWindow == null && char.IsLetterOrDigit(ch) || ch == '_') { codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(mainForm, editor, editor.FileName, provider, ch); if (codeCompletionWindow != null) { codeCompletionWindow.FormClosed += new System.Windows.Forms.FormClosedEventHandler(codeCompletionWindow_FormClosed); } } } return(false); }
private bool TextAreaKeyEventHandler(char key) { if (codeCompletionWindow != null) { if (codeCompletionWindow.ProcessKeyEvent(key)) { return(true); } } if (key == '.') { ICompletionDataProvider completionDataProvider = new CodeCompletionProvider(this); codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( this, // The parent window for the completion window _textEditor, // The text editor to show the window for this.ContentFile.FullName, // Filename - will be passed back to the provider completionDataProvider, // Provider to get the list of possible completions key // Key pressed - will be passed to the provider ); if (codeCompletionWindow != null) { codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } } return(false); }
/// <summary> /// Return true to handle the keypress, return false to let the text area handle the keypress /// </summary> bool TextAreaKeyEventHandler(char key) { if (codeCompletionWindow != null) { // If completion window is open and wants to handle the key, don't let the text area // handle it if (codeCompletionWindow.ProcessKeyEvent(key)) { return(true); } } if (key == '.') { ICompletionDataProvider completionDataProvider = new CodeCompletionProvider(mainForm); codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( mainForm, // The parent window for the completion window editor, // The text editor to show the window for MainForm.DummyFileName, // Filename - will be passed back to the provider completionDataProvider, // Provider to get the list of possible completions key // Key pressed - will be passed to the provider ); if (codeCompletionWindow != null) { // ShowCompletionWindow can return null when the provider returns an empty list codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } } return(false); }
public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider) { completionWindow = CodeCompletionWindow.ShowCompletionWindow(textEditorControl.ParentForm, textEditorControl, String.Empty, completionDataProvider, ' '); if (completionWindow != null) { completionWindow.Closed += CompletionWindowClosed; } }
public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider, char ch) { codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(this.FindForm(), this, this.FileName, completionDataProvider, ch); if (codeCompletionWindow != null) { codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } }
public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider, char ch) { codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(WorkbenchSingleton.MainForm, this, this.FileName, completionDataProvider, ch); if (codeCompletionWindow != null) { codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } }
public override void ShowCompletionWindow(ICompletionDataProvider completionDataProvider, char firstChar) { completionWindow = CodeCompletionWindow.ShowCompletionWindow(textEditorControl.ParentForm, textEditorControl, String.Empty, completionDataProvider, firstChar); if (completionWindow != null) { completionWindow.Width = 250; completionWindow.Closed += CompletionWindowClosed; } }
public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider, char ch) { _codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( ParentForm, this, FileName, completionDataProvider, ch); if (_codeCompletionWindow != null) { _codeCompletionWindow.Closed += CloseCodeCompletionWindow; } }
/// <summary> /// Displays the code completion window. /// </summary> /// <param name="p_chrChar">The character that was typed that caused the code window to display.</param> public void ShowCodeCompletionWindow(char p_chrChar) { m_ccwCodeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(this.FindForm(), this, null, m_cdpXmlCompletionProvider, p_chrChar, true, false); //m_ccwCodeCompletionWindow is null if there are no valid completions if (m_ccwCodeCompletionWindow != null) { m_ccwCodeCompletionWindow.Closed += new EventHandler(DisposeCodeCompletionWindow); } }
// Was part of the CodeCompletionKeyHandler file /// <summary> /// Return true to handle the keypress, return false to let the text area handle the keypress /// </summary> public bool TextAreaKeyEventHandler(char key) { if (codeCompletionWindow != null) { // If completion window is open and wants to handle the key, don't let the text area // handle it if (codeCompletionWindow != null) { if (codeCompletionWindow.ProcessKeyEvent(key)) { return(true); } } } // "key pressed:{0}".format(key).info(); if (key == '.') { //O2Thread.mtaThread( //I really want to run this on a separate thread but It is causing a weird problem where the codecomplete only happens after the 2nd char //() => //{ currentExpression = FindExpression(); //var o2Timer = new O2Timer("Code Completion").start(); //textEditor.invokeOnThread(()=> textEditor.textArea().Caret.Column ++ ); try { //startOffset = textEditor.currentOffset() + 1; // it was +1 before we made this run on an mta thread ICompletionDataProvider completionDataProvider = this; //new CodeCompletionProvider(this); codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( textEditor.ParentForm, // The parent window for the completion window textEditor, // The text editor to show the window for DummyFileName, // Filename - will be passed back to the provider completionDataProvider, // Provider to get the list of possible completions key // Key pressed - will be passed to the provider ); if (codeCompletionWindow != null) { // ShowCompletionWindow can return null when the provider returns an empty list codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } //textEditor.insertTextAtCurrentCaretLocation("."); } catch (Exception ex) { ex.log("in O2CodeCompletion.TextAreaKeyEventHandler"); } // o2Timer.stop(); //}); // return true; } return(false); }
private void ShowSync(char value) { if (_editor.IsReadOnly || !_editor.Enabled) { return; } if (_codeCompletionWindow != null) { _codeCompletionWindow.Close(); } ICompletionDataProvider completionDataProvider = new CompletionProviderImpl(_intellisenseImageList); _codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( _editor.FindForm(), // The parent window for the completion window _editor, // The text editor to show the window for "", // Filename - will be passed back to the provider completionDataProvider, // Provider to get the list of possible completions value // Key pressed - will be passed to the provider ); // ShowCompletionWindow can return null when the provider returns an empty list if (_codeCompletionWindow == null) { return; } _codeCompletionWindow.Closed += OnClose; var completions = completionDataProvider.GenerateCompletionData("", _editor.ActiveTextAreaControl.TextArea, value) ?? new ICompletionData[0]; if (!completions.Any()) { return; } _codeCompletionWindow.MouseWheel += CodeCompletionWindowOnMouseWheel; using (var g = _codeCompletionWindow.CreateGraphics()) { var width = (int)completions.Select(data => g.MeasureString(data.Text, _codeCompletionWindow.Font).Width).Max(); width += 16; // Icon size width += SystemInformation.VerticalScrollBarWidth; if (width > _codeCompletionWindow.Width) { _codeCompletionWindow.Width = width; } } }
public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider, char ch) { #if ModifiedForAltaxo Form active = Form.ActiveForm; codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(active, this, this.FileName, completionDataProvider, ch); #else codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow((Form)WorkbenchSingleton.Workbench, this, this.FileName, completionDataProvider, ch); #endif if (codeCompletionWindow != null) { codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } }
private CodeCompletionWindow ShowAttributeList(CodeCompletionWindow window, EditorControl editor, char keyChar, string tagName) { if (window != null && !window.Visible) { return(CodeCompletionWindow.ShowCompletionWindow(MainForm.mainForm, editor, global.htmlDef, htmlDataProvider, keyChar, tagName)); } else if (window == null) { return(CodeCompletionWindow.ShowCompletionWindow(MainForm.mainForm, editor, global.htmlDef, htmlDataProvider, keyChar, tagName)); } return(window); }
private void InitializeCodeCompletion() { _textEdit.ActiveTextAreaControl.TextArea.KeyEventHandler += ( AKey => { // Send the command to the existing code completion window if there is one if (_codeCompletionWindow != null) { if (_codeCompletionWindow.ProcessKeyEvent(AKey)) { return(true); } } // Handle the request to show code completion if (AKey == ' ' && ModifierKeys == Keys.Control) { var completionDataProvider = new D4CompletionDataProvider(this.Dataphoria); _codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow ( this, _textEdit, Text, completionDataProvider, AKey ); if (_codeCompletionWindow != null) { _codeCompletionWindow.Closed += ( (ASender, AE) => { if (_codeCompletionWindow != null) { _codeCompletionWindow.Dispose(); _codeCompletionWindow = null; } } ); } return(true); } return(false); } ); }
void TextArea_KeyPress(object sender, KeyPressEventArgs e) { if (handleKey) { if (e.KeyChar == '<') { e.KeyChar = '\0'; editor.Document.Insert(editor.Caret.Offset, "<"); editor.Caret.Position = editor.Document.OffsetToPosition(editor.Caret.Offset + 1); string html = GetHTMLTag(editor.ActiveTextAreaControl.TextArea); if (html == String.Empty) { windowHtml = CodeCompletionWindow.ShowCompletionWindow(MainForm.mainForm, editor, global.htmlDef, htmlDataProvider, '<'); } } else if (Char.IsWhiteSpace(e.KeyChar)) { string html = GetHTMLTag(editor.ActiveTextAreaControl.TextArea); string attribute = String.Empty; attribute = GetAttribute(editor.ActiveTextAreaControl.TextArea); e.KeyChar = '\0'; editor.Document.Insert(editor.Caret.Offset, " "); editor.Caret.Position = editor.Document.OffsetToPosition(editor.Caret.Offset + 1); if ((html != String.Empty) && (attribute == string.Empty)) { windowHtml = ShowAttributeList(windowHtml, editor, ' ', html); } } else if (e.KeyChar == '"') { string html = GetHTMLTag(editor.ActiveTextAreaControl.TextArea); string attribute = String.Empty; if (html != String.Empty) { attribute = GetAttribute(editor.ActiveTextAreaControl.TextArea); html += "|" + attribute; } e.KeyChar = '\0'; editor.Document.Insert(editor.Caret.Offset, "\""); editor.Caret.Position = editor.Document.OffsetToPosition(editor.Caret.Offset + 1); if (attribute != string.Empty) { windowHtml = ShowAttributeList(windowHtml, editor, '"', html); } } } }
/// <summary> /// KAGファイルでキー入力イベントが発生したとき /// </summary> /// <param name="ch"></param> private void kagKeyEventHandler(char ch) { switch (ch) { case '[': //タグ呼び出しの時 case '@': //タグ呼び出しの時 case ' ': //属性名呼び出しの時 case '=': //属性値呼び出しの時 m_codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(GlobalStatus.FormManager.MainForm , this, this.FileName, KagCompDataPrv, ch); break; default: break; } }
public override void Execute(ICSharpCode.TextEditor.TextArea textArea) { TextEditorEx editor = (TextEditorEx)textArea.MotherTextEditorControl; switch (FileType.GetKrkrType(editor.FileName)) { case FileType.KrkrType.Kag: //KAG入力補完 editor.m_codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(GlobalStatus.FormManager.MainForm , editor, editor.FileName, editor.KagCompDataPrv, '\0'); break; case FileType.KrkrType.Tjs: //未実装 break; } }
private bool TextAreaKeyEventHandler(char key) { if (_codeCompletionWindow != null) { // If completion window is open and wants to handle the key, don't let the text area // handle it if (_codeCompletionWindow.ProcessKeyEvent(key)) { return(true); } } if (key == '.') { ICompletionDataProvider completionDataProvider = new CodeCompletionProvider(_iForm); _codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( _iForm, // The parent window for the completion window _editor, // The text editor to show the window for IntellisenseForm.DummyFileName, // Filename - will be passed back to the provider completionDataProvider, // Provider to get the list of possible completions key // Key pressed - will be passed to the provider ); if (_codeCompletionWindow != null) { // ShowCompletionWindow can return null when the provider returns an empty list _codeCompletionWindow.Closed += CloseCodeCompletionWindow; } } else if (key == '(') { if (_insightWindow != null && (!_insightWindow.IsDisposed)) { // provider returned an empty list, so the window never been opened CloseInsightWindow(this, EventArgs.Empty); } IInsightDataProvider insightdataprovider = new MethodInsightDataProvider(_iForm); _insightWindow = new InsightWindow(_iForm, _editor); _insightWindow.Closed += CloseInsightWindow; _insightWindow.AddInsightDataProvider(insightdataprovider, IntellisenseForm.DummyFileName); _insightWindow.ShowInsightWindow(); } return(false); }
public bool TextArea_DoProcessDialogKey(Keys keyData) { if (keyData == (Keys.Space | Keys.Control)) { string tagBeforeCaret = getHtmlTagAtCaret(editor.ActiveTextAreaControl.TextArea); string html = GetHTMLTag(editor.ActiveTextAreaControl.TextArea); string attribute = String.Empty; //string html = GetHTMLTag(editor.ActiveTextAreaControl.TextArea); if (tagBeforeCaret != String.Empty && tagBeforeCaret != "<") { windowHtml = CodeCompletionWindow.ShowCompletionWindow(MainForm.mainForm, editor, global.htmlDef, htmlDataProvider, '<', tagBeforeCaret); } else if (tagBeforeCaret == "<") { windowHtml = CodeCompletionWindow.ShowCompletionWindow(MainForm.mainForm, editor, global.htmlDef, htmlDataProvider, '<'); } else if (html != String.Empty) { attribute = GetAttribute(editor.ActiveTextAreaControl.TextArea); string attributeAtCaret = getWordBeforeCaret(); char charTyped = '\0'; if (attribute != string.Empty) { html += "|" + attribute; charTyped = '"'; } else if (attributeAtCaret != string.Empty) { html += "|" + attributeAtCaret; charTyped = ' '; } else { charTyped = ' '; } windowHtml = ShowAttributeList(windowHtml, editor, charTyped, html); } return(true); } return(false); }
private void ShowCompletionWindow(char ch) { if (IsCodeCompletionWindowOpen) { codeCompletionWindow.Close(); } if (IsCodeCompletionEnabled) { XmlCompletionDataProvider completionDataProvider = new XmlCompletionDataProvider(schemaCompletionDataItems, defaultSchemaCompletionData, string.Empty /* defaultNamespacePrefix */); codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(ParentForm, this, FileName, completionDataProvider, ch, true /* showDeclarationWindow */, false); if (codeCompletionWindow != null) { codeCompletionWindow.Closed += new EventHandler(CodeCompletionWindowClosed); } } }
void ShowCompletionWindow(char ch) { if (IsCodeCompletionWindowOpen) { codeCompletionWindow.Close(); } if (IsCodeCompletionEnabled) { XmlCompletionDataProvider completionDataProvider = new XmlCompletionDataProvider(schemaCompletionDataItems, defaultSchemaCompletionData, defaultNamespacePrefix); codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(ParentForm, this, FileName, completionDataProvider, ch, XmlEditorAddInOptions.ShowSchemaAnnotation, false); if (codeCompletionWindow != null) { codeCompletionWindow.Closed += new EventHandler(CodeCompletionWindowClosed); } } }
public void showCodeCompleteWindow(char key) { // CodeCompleteTargetText = textEditor.get_Text(); // update this text so that we are working with the latest version of the code/snippet //var key = '.'; //O2Thread.mtaThread( //I really want to run this on a separate thread but It is causing a weird problem where the codecomplete only happens after the 2nd char //() => //{ currentExpression = FindExpression(); //"[O2CodeComplete] Current Expression: {0}".info(currentExpression); //var o2Timer = new O2Timer("Code Completion").start(); //textEditor.invokeOnThread(()=> textEditor.textArea().Caret.Column ++ ); try { //startOffset = textEditor.currentOffset() + 1; // it was +1 before we made this run on an mta thread completionDataProvider = this;//new CodeCompletionProvider(this); codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( TextEditor.ParentForm, // The parent window for the completion window TextEditor, // The text editor to show the window for dummyFileName, // Filename - will be passed back to the provider completionDataProvider, // Provider to get the list of possible completions key // Key pressed - will be passed to the provider ); if (codeCompletionWindow != null) { // ShowCompletionWindow can return null when the provider returns an empty list codeCompletionWindow.Closed += CloseCodeCompletionWindow; codeCompletionWindow.AfterLoadGui = () => { codeCompletionWindow.AfterLoadGui = null; //so that we only invoke this once after_CodeCompletionWindow_IsAvailable.invoke(codeCompletionWindow); }; } } catch (Exception ex) { ex.log("in O2CodeCompletion.TextAreaKeyEventHandler"); } // o2Timer.stop(); }
public void SetUpFixture() { Form parentForm = new Form(); parentForm.CreateControl(); XmlSchemaCompletionData schema = new XmlSchemaCompletionData(ResourceManager.GetXhtmlStrictSchema()); XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); schemas.Add(schema); provider = new XmlCompletionDataProvider(schemas, schema, String.Empty); TextEditorControl textEditor = new TextEditorControl(); completionDataItems = provider.GenerateCompletionData(@"C:\Test.xml", textEditor.ActiveTextAreaControl.TextArea, '<'); using (CodeCompletionWindow completionWindow = CodeCompletionWindow.ShowCompletionWindow(parentForm, textEditor, @"C:\Test.xml", provider, '<')) { CodeCompletionListView listView = (CodeCompletionListView)completionWindow.Controls[0]; selectedCompletionData = listView.SelectedCompletionData; completionWindow.Close(); } }
public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider, char key) { try { FCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( FParentForm, // The parent window for the completion window this, // The text editor to show the window for TextDocument.LocalPath, // Filename - will be passed back to the provider completionDataProvider, // Provider to get the list of possible completions key // Key pressed - will be passed to the provider ); if (FCompletionWindow != null) { // ShowCompletionWindow can return null when the provider returns an empty list FCompletionWindow.Closed += CloseCodeCompletionWindow; } } catch (Exception e) { Logger.Log(e); } }
private void ShowCodeCompleteWindow(char key) { try { _completionDataProvider = this; _codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( _editor.ParentForm, _editor, "file.sql", _completionDataProvider, key ); if (_codeCompletionWindow != null) { _codeCompletionWindow.Closed += CloseCodeCompletionWindow; } } catch (Exception) { } }
void TextArea_KeyPress(object sender, KeyPressEventArgs e) { //Console.WriteLine(e.KeyChar); if (e.KeyChar == '<') { string html = GetHTMLTag(textArea.TextArea); if (html == String.Empty) { window = CodeCompletionWindow.ShowCompletionWindow(this, textEditorControl1, "html4.01_def.xml", test, '<'); } } else if (Char.IsLetter(e.KeyChar) || Char.IsWhiteSpace(e.KeyChar)) { string html = GetHTMLTag(textEditorControl1.ActiveTextAreaControl.TextArea); if (html != String.Empty) { if (window != null && !window.Visible) { window = CodeCompletionWindow.ShowCompletionWindow(this, textEditorControl1, "html4.01_def.xml", test, e.KeyChar, html); } } } }
private void ShowIntellisense(char value) { CodeCompletionWindow completionWindow = CodeCompletionWindow.ShowCompletionWindow( ((Form)Parent.Parent), Editor, "", mCompletionDataProvider, value ); // created a new window if (completionWindow != null) { completionWindow.Closed += new EventHandler(CompletionWindow_Closed); mCompletionWindow = completionWindow; } else if (mCompletionWindow != null) { // Window creation failed because provider returns null // Close previous window too mCompletionWindow.Close(); } }
void ShowCompletationWindow(char key) { var anal = m_anal; if (anal == null) { return; } ICompletionDataProvider completionDataProvider = new CodeCompletionProvider(m_parentForm, m_editor.Connection, anal, m_editor.ImageCache, key, m_editor.ActiveTextAreaControl, m_editor.Connection.Settings.CodeCompletion()); m_codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( m_parentForm, // The parent window for the completion window m_editor, // The text editor to show the window for "", // Filename - will be passed back to the provider completionDataProvider, // Provider to get the list of possible completions key // Key pressed - will be passed to the provider ); if (m_codeCompletionWindow != null) { // ShowCompletionWindow can return null when the provider returns an empty list m_codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } }
/// <summary> /// Return true to handle the keypress, return false to let the text area handle the keypress /// </summary> bool TextAreaKeyEventHandler(char key) { try { if (codeCompletionWindow != null) { // If completion window is open and wants to handle the key, don't let the text area // handle it System.Diagnostics.Debug.WriteLine("---" + key); if (codeCompletionWindow.ProcessKeyEvent(key)) { System.Diagnostics.Debug.WriteLine("---" + key + "==="); return(true); } else { if (codeCompletionWindow != null && codeCompletionWindow.dataProvider is CodeCompletionProvider) { System.Diagnostics.Debug.WriteLine("---" + key + "===inin"); ICompletionData[] data = (codeCompletionWindow.dataProvider as CodeCompletionProvider).GenerateCompletionList(key); if (data == null) { System.Diagnostics.Debug.WriteLine("---" + key + "===close"); codeCompletionWindow.Close(); //codeCompletionWindow = null; } return(false); } } } //bool insideMoScript = false; //List<KeyValuePair<int, int>> values = new List<KeyValuePair<int, int>>(); //int index = editor.Document.TextContent.IndexOf("<moscript>", 0, StringComparison.CurrentCultureIgnoreCase); //while (index != -1) //{ // int endindex = editor.Document.TextContent.IndexOf("</moscript>", index + 1, StringComparison.CurrentCultureIgnoreCase); // if (endindex != -1) // { // KeyValuePair<int, int> pair = new KeyValuePair<int, int>(index, endindex); // values.Add(pair); // } // index = editor.Document.TextContent.IndexOf("<moscript>", index + 1, StringComparison.CurrentCultureIgnoreCase); //} //foreach (KeyValuePair<int, int> pair in values) //{ // if (editor.ActiveTextAreaControl.Caret.Offset > pair.Key && editor.ActiveTextAreaControl.Caret.Offset < pair.Value) // { // insideMoScript = true; // break; // } //} //if (insideMoScript) //{ //if (key == '.') //{ // ICompletionDataProvider completionDataProvider = new CodeCompletionProviderDot(mainForm); // codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( // mainForm, // The parent window for the completion window // editor, // The text editor to show the window for // "x.cs", // Filename - will be passed back to the provider // completionDataProvider, // Provider to get the list of possible completions // key // Key pressed - will be passed to the provider // ); // if (codeCompletionWindow != null) // { // // ShowCompletionWindow can return null when the provider returns an empty list // codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); // } //} try { var seg = editor.Document.GetLineSegment(editor.ActiveTextAreaControl.Caret.Line); string textline = editor.Document.GetText(seg); int index = textline.IndexOf("//"); if (index != -1 && index < editor.ActiveTextAreaControl.Caret.Offset) { return(false); } } catch (Exception) { } if (char.IsLetter(key) || key == '#') { ICompletionDataProvider completionDataProvider = new CodeCompletionProvider(mainForm, key.ToString()); codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow( mainForm, // The parent window for the completion window editor, // The text editor to show the window for "x.cs", // Filename - will be passed back to the provider completionDataProvider, // Provider to get the list of possible completions key // Key pressed - will be passed to the provider ); if (codeCompletionWindow != null) { // ShowCompletionWindow can return null when the provider returns an empty list codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); codeCompletionWindow.SetPre(); //return true; } } else if (key == '(' && mainForm.Specification != null) { //if (EnableMethodInsight && CodeCompletionOptions.InsightEnabled) { mainForm.CodeEditor.ShowInsightWindow(new MethodInsightDataProvider(mainForm)); return(false); } } if (key == ',') //&& CodeCompletionOptions.InsightRefreshOnComma && CodeCompletionOptions.InsightEnabled { mainForm.CodeEditor.ShowInsightWindow(new MethodInsightDataProvider(mainForm)); return(false); } // } } catch (Exception ex) { string msg = ex.Message; } return(false); }
bool TextArea_KeyEventHandler(char key) { var doc = _area.Document; int row = _area.Caret.Line; int col = _area.Caret.Column; if (completionWindow != null) { // If completion window is open and wants to handle the key, don't let the text area // handle it if (completionWindow.ProcessKeyEvent(key)) { return(true); } } else if (char.IsLetter(key) || key == '_') { LineSegment seg = doc.GetLineSegment(row); TextWord word = seg.GetWord(col); if (!IsNullWord(word) && IsVariateOrDigit(word.Word)) { return(false); } //获取前一个单词 while (IsNullWord(word) && col > 0) { word = seg.GetWord(--col); } //如果有单词,将本句的单词加入队列 Queue <TextWord> allWords = new Queue <TextWord>(); if (!IsNullWord(word)) { for (int i = seg.Words.IndexOf(word); i > -1; i--) { word = seg.Words[i]; if (!string.IsNullOrEmpty(word.Word)) { allWords.Enqueue(word); } } } //加入之前的所有单词 for (int i = row - 1; i > -1; i--) { seg = doc.GetLineSegment(i); for (int j = seg.Words.Count - 1; j > -1; j--) { word = seg.Words[j]; if (!string.IsNullOrEmpty(word.Word)) { allWords.Enqueue(word); } } } List <TextWord> pWords = new List <TextWord>(); List <TextWord> cWords = new List <TextWord>(); //找到当前语句 while (allWords.Count > 0) { if (IsRangeEnd(allWords.Peek())) { break; } cWords.Add(allWords.Dequeue()); } //找到之前的所有语句 while (allWords.Count > 0) { pWords.Insert(0, allWords.Dequeue()); } _vars.Clear(); int num; //确定当前单词的类型 string typeName = null; bool isDataType = false; if (cWords.Count == 0 || (cWords[0].Word == "(" && cWords[1].Word == "for")) { isDataType = true; } else { List <TextWord> words = new List <TextWord>(); bool hasDataType = false; for (int i = 0; i < cWords.Count; i++) { words.Add(cWords[i]); if (IsKeyWord("DataType", cWords[i])) { typeName = cWords[i].Word; hasDataType = true; break; } } //如果当前句有声明语句,在变量表中加入声明过的变量 if (hasDataType) { num = 0; for (int i = 0; i < words.Count; i++) { string s = words[i].Word; if (s == "(") { num++; } else if (s == ")") { num--; } if (num == 0 && IsDataType(words[i])) { if (i != words.Count - 1) { AddVariate(words[i + 1], typeName); } } } if (num == 0 && (IsDataType(words[0]) || IsDataType(words[1]))) { return(false); } } } //找到之前的所有语句中搜索变量声明,并加入变量表 num = 0; bool atDataType = false; for (int i = 0; i < pWords.Count; i++) { string s = pWords[i].Word; if (IsKeyWord("DataType", pWords[i])) { typeName = pWords[i].Word; atDataType = true; num = 0; } else if (s == "(") { num++; } else if (s == ")") { num--; } else if (IsRange(pWords[i])) { atDataType = false; } if (atDataType && num == 0 && IsDataType(pWords[i])) { AddVariate(pWords[i + 1], typeName); } } //为智能提示准备单词 _datas.Clear(); if (isDataType) { _datas.AddRange(_words["DataType"]); } _datas.AddRange(_args); _datas.AddRange(_vars); _datas.AddRange(_words["KeyWord"]); _datas.AddRange(_words["Method"]); _datas.AddRange(_words["Constant"]); //显示智能提示窗口 completionWindow = CodeCompletionWindow.ShowCompletionWindow( _form, _area.MotherTextEditorControl, "", this, key); if (completionWindow != null) { // ShowCompletionWindow can return null when the provider returns an empty list completionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } } return(false); }