Наследование: AbstractCompletionWindow
 /// <summary>
 /// Return true to handle the keypress, return false to let the text area handle the keypress
 /// </summary>
 void TextAreaKeyEventHandler(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.OemOpenBrackets && e.Shift)
     {
         ICompletionDataProvider snippetDataProvider = new SnippetDataProvider(mainForm.AutoCompleteImageList);
         codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(
             mainForm,					// The parent window for the completion window
             editor, 					// The text editor to show the window for
             "",		// Filename - will be passed back to the provider
             snippetDataProvider,		// Provider to get the list of possible completions
             Convert.ToChar(e.KeyCode)	    					// Key pressed - will be passed to the provider
         );
     }
     else
     {
         ICompletionDataProvider completionDataProvider = new CodeCompletionProvider(mainForm.AutoCompleteImageList);
         codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(
             mainForm,					// 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
             Convert.ToChar(e.KeyCode)	    					// 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;
 }
        /// <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;
        }
Пример #3
0
 void CloseCodeCompletionWindow(object sender, EventArgs e)
 {
     if (codeCompletionWindow != null) {
         codeCompletionWindow.Closed -= new EventHandler(CloseCodeCompletionWindow);
         codeCompletionWindow.Dispose();
         codeCompletionWindow = null;
     }
 }
Пример #4
0
 void CompletionWindowClosed(object source, EventArgs e)
 {
     if (completionWindow != null) {
         completionWindow.Closed -= CompletionWindowClosed;
         completionWindow.Dispose();
         completionWindow = null;
     }
 }
 private CodeCompletionWindow(ICompletionDataProvider completionDataProvider, ICompletionData[] completionData, Form parentForm, TextEditorControl control, bool showDeclarationWindow, bool fixedListViewWidth) : base(parentForm, control)
 {
     this.dataProvider          = completionDataProvider;
     this.completionData        = completionData;
     this.document              = control.Document;
     this.showDeclarationWindow = showDeclarationWindow;
     this.fixedListViewWidth    = fixedListViewWidth;
     this.workingScreen         = Screen.GetWorkingArea(base.Location);
     this.startOffset           = control.ActiveTextAreaControl.Caret.Offset + 1;
     this.endOffset             = this.startOffset;
     if (completionDataProvider.PreSelection != null)
     {
         CodeCompletionWindow length = this;
         length.startOffset = length.startOffset - (completionDataProvider.PreSelection.Length + 1);
         this.endOffset--;
     }
     this.codeCompletionListView = new CodeCompletionListView(completionData)
     {
         ImageList = completionDataProvider.ImageList,
         Dock      = DockStyle.Fill
     };
     this.codeCompletionListView.SelectedItemChanged += new EventHandler(this.CodeCompletionListViewSelectedItemChanged);
     this.codeCompletionListView.DoubleClick         += new EventHandler(this.CodeCompletionListViewDoubleClick);
     this.codeCompletionListView.Click += new EventHandler(this.CodeCompletionListViewClick);
     base.Controls.Add(this.codeCompletionListView);
     if ((int)completionData.Length > 10)
     {
         this.vScrollBar.Dock        = DockStyle.Right;
         this.vScrollBar.Minimum     = 0;
         this.vScrollBar.Maximum     = (int)completionData.Length - 1;
         this.vScrollBar.SmallChange = 1;
         this.vScrollBar.LargeChange = 10;
         this.codeCompletionListView.FirstItemChanged += new EventHandler(this.CodeCompletionListViewFirstItemChanged);
         base.Controls.Add(this.vScrollBar);
     }
     this.drawingSize = this.GetListViewSize();
     this.SetLocation();
     if (this.declarationViewWindow == null)
     {
         this.declarationViewWindow = new DeclarationViewWindow(parentForm);
     }
     this.SetDeclarationViewLocation();
     this.declarationViewWindow.ShowDeclarationViewWindow();
     this.declarationViewWindow.MouseMove += new MouseEventHandler(this.ControlMouseMove);
     control.Focus();
     this.CodeCompletionListViewSelectedItemChanged(this, EventArgs.Empty);
     if (completionDataProvider.DefaultIndex >= 0)
     {
         this.codeCompletionListView.SelectIndex(completionDataProvider.DefaultIndex);
     }
     if (completionDataProvider.PreSelection != null)
     {
         this.CaretOffsetChanged(this, EventArgs.Empty);
     }
     this.vScrollBar.ValueChanged           += new EventHandler(this.VScrollBarValueChanged);
     this.document.DocumentAboutToBeChanged += new DocumentEventHandler(this.DocumentAboutToBeChanged);
 }
Пример #6
0
 void CloseCodeCompletionWindow(object sender, EventArgs e)
 {
     if (m_code_complete != null)
     {
         m_code_complete.Closed -= new EventHandler(CloseCodeCompletionWindow);
         m_code_complete.Dispose();
         m_code_complete = null;
     }
 }
Пример #7
0
		public static CodeCompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar)
		{
			ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(fileName, control.ActiveTextAreaControl.TextArea, firstChar);
			if (completionData == null || completionData.Length == 0) {
				return null;
			}
			CodeCompletionWindow codeCompletionWindow = new CodeCompletionWindow(completionDataProvider, completionData, parent, control);
			codeCompletionWindow.ShowCompletionWindow();
			return codeCompletionWindow;
		}
		public static CodeCompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar, bool showDeclarationWindow, bool fixedListViewWidth)
		{
			ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(fileName, control.ActiveTextAreaControl.TextArea, firstChar);
			if (completionData == null || completionData.Length == 0) {
				return null;
			}
			CodeCompletionWindow codeCompletionWindow = new CodeCompletionWindow(completionDataProvider, completionData, parent, control, showDeclarationWindow, fixedListViewWidth);
			codeCompletionWindow.CloseWhenCaretAtBeginning = firstChar == '\0';
			codeCompletionWindow.ShowCompletionWindow();
			return codeCompletionWindow;
		}
Пример #9
0
		public static CodeCompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar, bool showDeclarationWindow, bool fixedListViewWidth)
		{
			ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(fileName, control.ActiveTextAreaControl.TextArea, firstChar);
			if (completionData == null || completionData.Length == 0) {
				return null;
			}
			CodeCompletionWindow codeCompletionWindow = new CodeCompletionWindow(completionDataProvider, completionData, parent, control, showDeclarationWindow, fixedListViewWidth);
			codeCompletionWindow.CloseWhenCaretAtBeginning = firstChar == '\0';
			codeCompletionWindow.ShowCompletionWindow();
			return codeCompletionWindow;
		}
Пример #10
0
        public static CodeCompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar)
        {
            ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(fileName, control.ActiveTextAreaControl.TextArea, firstChar);
            if (completionData == null || completionData.Length == 0)
            {
                return(null);
            }
            CodeCompletionWindow codeCompletionWindow = new CodeCompletionWindow(completionDataProvider, completionData, parent, control, fileName);

            codeCompletionWindow.ShowCompletionWindow();
            return(codeCompletionWindow);
        }
		public static CodeCompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar, bool showDeclarationWindow, bool fixedListViewWidth)
		{
            if (busy)  // DC to prevent multiple calls
            {
                "CodeCompletionWindow.ShowCompletionWindow was busy, skipping ShowCompletionWindow calculation".info();
                return null;
            }

                busy = true;
                return (CodeCompletionWindow)parent.invokeOnThread(
                    () =>
                    {
                        try
                        {

                            var tempCompletionData = new ICompletionData[] { };
                            CodeCompletionWindow codeCompletionWindow = new CodeCompletionWindow(completionDataProvider, tempCompletionData, parent, control, showDeclarationWindow, fixedListViewWidth);
                            codeCompletionWindow.CloseWhenCaretAtBeginning = firstChar == '\0';
                            codeCompletionWindow.ShowCompletionWindow();

                            O2Thread.mtaThread(         // run in on a separate thread for performance reasons
                                () =>
                                {
                                    try
                                    {
                                        ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(fileName, control.ActiveTextAreaControl.TextArea, firstChar);
                                        if (completionData == null || completionData.Length == 0)
                                        {
                                            //return null;
                                        }
                                        else
                                            codeCompletionWindow.setCodeCompletionData(completionData);
                                        busy = false;
                                    }
                                    catch (Exception ex)
                                    {
                                        ex.log("in CodeCompletionWindow.ShowCompletionWindow ");
                                    }
                                });

                            return codeCompletionWindow;
                        }
                        catch (Exception ex)
                        {
                            busy = false;
                            return null;
                        }
                    });
            
		}     
Пример #12
0
        public static CodeCompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar, bool showDeclarationWindow, bool fixedListViewWidth)
        {
            if (busy)  // DC to prevent multiple calls
            {
                "CodeCompletionWindow.ShowCompletionWindow was busy, skipping ShowCompletionWindow calculation".info();
                return(null);
            }

            busy = true;
            return((CodeCompletionWindow)parent.invokeOnThread(
                       () =>
            {
                try
                {
                    var tempCompletionData = new ICompletionData[] { };
                    CodeCompletionWindow codeCompletionWindow = new CodeCompletionWindow(completionDataProvider, tempCompletionData, parent, control, showDeclarationWindow, fixedListViewWidth);
                    codeCompletionWindow.CloseWhenCaretAtBeginning = firstChar == '\0';
                    codeCompletionWindow.ShowCompletionWindow();

                    O2Thread.mtaThread(                 // run in on a separate thread for performance reasons
                        () =>
                    {
                        try
                        {
                            ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(fileName, control.ActiveTextAreaControl.TextArea, firstChar);
                            if (completionData == null || completionData.Length == 0)
                            {
                                //return null;
                            }
                            else
                            {
                                codeCompletionWindow.setCodeCompletionData(completionData);
                            }
                            busy = false;
                        }
                        catch (Exception ex)
                        {
                            ex.log("in CodeCompletionWindow.ShowCompletionWindow ");
                        }
                    });

                    return codeCompletionWindow;
                }
                catch (Exception ex)
                {
                    busy = false;
                    return null;
                }
            }));
        }
Пример #13
0
        public static CodeCompletionWindow ShowCompletionWindow_Thread(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar, bool showDeclarationWindow, bool fixedListViewWidth)
        {
            try
            {
                var tempCompletionData = new ICompletionData[] { };
                CodeCompletionWindow codeCompletionWindow = new CodeCompletionWindow(completionDataProvider, tempCompletionData, parent, control, showDeclarationWindow, fixedListViewWidth);
                codeCompletionWindow.CloseWhenCaretAtBeginning = firstChar == '\0';
                codeCompletionWindow.ShowCompletionWindow();

                codeCompletionWindow.AfterWindowOpen.invoke();

                O2Thread.mtaThread(             // run in on a separate thread for performance reasons
                    () =>
                {
                    try
                    {
                        ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(fileName, control.ActiveTextAreaControl.TextArea, firstChar);
                        if (completionData == null || completionData.Length == 0)
                        {
                            //"There was no CompleteData".error();
                            //return null;
                        }
                        else
                        {
                            codeCompletionWindow.setCodeCompletionData(completionData);
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.log("in CodeCompletionWindow.ShowCompletionWindow ");
                    }
                    busy = false;
                });

                return(codeCompletionWindow);
            }
            catch    // (Exception ex)
            {
                busy = false;
                return(null);
            }
        }
		/// <summary>
		/// Return true to handle the keypress, return false to let the text area handle the keypress
		/// </summary>
		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 static CodeCompletionWindow ShowCompletionWindow_Thread(Form parent,TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar, bool showDeclarationWindow, bool fixedListViewWidth)
        { 
            try
                {

                    var tempCompletionData = new ICompletionData[] { };
                    CodeCompletionWindow codeCompletionWindow = new CodeCompletionWindow(completionDataProvider, tempCompletionData, parent, control, showDeclarationWindow, fixedListViewWidth);
	                codeCompletionWindow.CloseWhenCaretAtBeginning = firstChar == '\0';
                    codeCompletionWindow.ShowCompletionWindow();

					codeCompletionWindow.AfterWindowOpen.invoke();

                    O2Thread.mtaThread(         // run in on a separate thread for performance reasons
                        () =>
                        {
                            try
                            {
                                ICompletionData[] completionData = completionDataProvider.GenerateCompletionData(fileName, control.ActiveTextAreaControl.TextArea, firstChar);
                                if (completionData == null || completionData.Length == 0)
                                {
                                    //"There was no CompleteData".error();
                                    //return null;
                                }
                                else
                                    codeCompletionWindow.setCodeCompletionData(completionData);                                
                            }
                            catch (Exception ex)
                            {
                                ex.log("in CodeCompletionWindow.ShowCompletionWindow ");
                            }
                            busy = false;
                        });

                    return codeCompletionWindow;
                }
                catch// (Exception ex)
                {
                    busy = false;
                    return null;
                }
        }
        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();
        }        
Пример #17
0
        private void ShowCompletionWindow(char first)
        {
            if (_completionWindow == null || _completionWindow.IsDisposed)
            {
                KeywordCompletionDataProvider provider = new KeywordCompletionDataProvider();
                provider.ImageList = imgCompletion;

                _completionWindow = CodeCompletionWindow.ShowCompletionWindow(this.ParentForm, scriptEditor, null, provider, first);

                if (_completionWindow != null)
                {
                    _completionWindow.Closed += new EventHandler(_completionWindow_Closed);
                }
            }
        }
Пример #18
0
        void ShowCompletionWindow(char ch)
        {
            if (IsCodeCompletionWindowOpen)
            {
                codeCompletionWindow.Close();
            }
            codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(ParentForm, this, FileName, new HqlCompletionDataProvider(NHConfigDataProvider), ch, true/*PROPERTY*/, false);

            if (codeCompletionWindow != null)
            {
                codeCompletionWindow.Closed += new EventHandler(CodeCompletionWindowClosed);
            }
        }
Пример #19
0
		/// <summary>
		/// Disposes of the code completion window when it closes.
		/// </summary>
		/// <param name="sender">The object that triggered the event.</param>
		/// <param name="e">An <see cref="EventArgs"/> describing the event arguments.</param>
		private void DisposeCodeCompletionWindow(object sender, EventArgs e)
		{
			if (m_ccwCodeCompletionWindow != null)
			{
				m_ccwCodeCompletionWindow.Closed -= new EventHandler(DisposeCodeCompletionWindow);
				m_ccwCodeCompletionWindow.Dispose();
				m_ccwCodeCompletionWindow = null;
			}
		}
Пример #20
0
		/// <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);
		}
		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);
			}
		}
Пример #22
0
 void ShowCompletionWindow()
 {
     CompletionDataProvider completionDataProvider = new CompletionDataProvider();
     completionWindow = CodeCompletionWindow.ShowCompletionWindow(this, textEditorControl, String.Empty, completionDataProvider, '.');
     if (completionWindow != null) {
         completionWindow.Closed += CompletionWindowClosed;
     }
 }
Пример #23
0
 private void CompletionWindowClosed(object sender, EventArgs e)
 {
     if (_completionWindow != null)
     {
         _completionWindow.Closed -= CompletionWindowClosed;
         _completionWindow.Dispose();
         _completionWindow = null;
     }
 }
 // IdeBridge
 public virtual void ShowCompletionWindow(ICompletionDataProvider completionDataProvider, char ch)
 {
     codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(WorkbenchSingleton.MainForm, this, this.FileName, completionDataProvider, ch);
     if (codeCompletionWindow != null) {
         codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
     }
 }
Пример #25
0
        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);
                }
            }
        }
Пример #26
0
    /// <summary>
    /// Return true to handle the keypress, return false to let the text area handle the keypress
    /// </summary>
    bool TextAreaKeyEventHandler(char key)
    {
      if (m_code_complete != null)
      {
        // If completion window is open and wants to handle the key, don't let the text area
        // handle it
        if (m_code_complete.ProcessKeyEvent(key))
          return true;
      }

      ICSharpCode.TextEditor.Gui.CompletionWindow.ICompletionDataProvider completionDataProvider = CodeComplete.GetCompletionProvider(this, key);
      if (completionDataProvider == null && key == '(')
      {
        ICSharpCode.TextEditor.Document.LineSegment line = this.Document.GetLineSegment(ActiveTextAreaControl.Caret.Line);
        if (null == line)
          return false;

        List<ICSharpCode.TextEditor.Document.TextWord> words = line.Words;
        if (words == null || words.Count < 1)
          return false;

        ICSharpCode.TextEditor.Document.TextWord lastWord = words[words.Count - 1];
        if (lastWord.Type != ICSharpCode.TextEditor.Document.TextWordType.Word)
          return false;
        // Todo: Remove hard coded colors
        if (lastWord.Color == System.Drawing.Color.Green || lastWord.Color == System.Drawing.Color.Red)
          return false;

        // make sure first real word on this line is not "def"
        for (int i = 0; i < words.Count; i++)
        {
          if (words[i].Type != ICSharpCode.TextEditor.Document.TextWordType.Word)
            continue;
          if (words[i].Word.Equals("def", StringComparison.Ordinal))
            return false;
          break;
        }

        char c = lastWord.Word[0];
        if (char.IsLetter(c))
        {
          // Build up a python script to execute
          int line_number = this.ActiveTextAreaControl.TextArea.Caret.Line;
          StringBuilder script = new StringBuilder();
          for (int i = 0; i < line_number; i++)
          {
            line = this.ActiveTextAreaControl.TextArea.Document.GetLineSegment(i);
            if (line != null && line.Words.Count > 2)
            {
              string firstword = line.Words[0].Word;
              if (firstword.Equals("import", StringComparison.Ordinal) || firstword.Equals("from"))
              {
                script.AppendLine(this.ActiveTextAreaControl.TextArea.Document.GetText(line));
              }
            }
          }

          ICSharpCode.TextEditor.Document.LineSegment lastLine = this.ActiveTextAreaControl.TextArea.Document.GetLineSegment(line_number);
          if (null == lastLine)
            return false;

          //walk backward through the line until we hit something that is NOT a word or period
          string evaluation = "";
          for (int i = lastLine.Words.Count - 1; i >= 0; i--)
          {
            ICSharpCode.TextEditor.Document.TextWord word = lastLine.Words[i];
            if (word.Type != ICSharpCode.TextEditor.Document.TextWordType.Word)
              break;
            c = word.Word[0];
            if (c != '.' && !char.IsLetter(c))
              break;
            evaluation = evaluation.Insert(0, word.Word);
          }

          if (evaluation != "if" && evaluation != "while")
          {
            RhinoDLR_Python.Intellisense isense = m_intellisense;
            if (isense == null)
              isense = CodeComplete.Intellisense;
            string rc = isense.EvaluateHelp(script.ToString(), evaluation);
            if (!string.IsNullOrEmpty(rc) && null != m_help_callback)
            {
              m_help_callback(rc);
            }
          }          
        }
      }
      else if( completionDataProvider != null )
      {
        ScriptEditor.Model.ScriptDocument doc = ScriptEditor.Model.Documents.DocumentFromId(DocumentId);
        string path = "none";
        if (doc != null && !string.IsNullOrEmpty(doc.FullPath) )
        {
          path = doc.FullPath;
        }

        m_code_complete = ICSharpCode.TextEditor.Gui.CompletionWindow.CodeCompletionWindow.ShowCompletionWindow(
          m_mainform,					// The parent window for the completion window
          this, 					    // The text editor to show the window for
          path,               // 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_code_complete != null)
        {
          // ShowCompletionWindow can return null when the provider returns an empty list
          m_code_complete.Closed += new EventHandler(CloseCodeCompletionWindow);
        }
      }
      return false;
    }
Пример #27
0
        /// <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;
        }
Пример #28
0
        /// <summary>
        /// Return true to handle the keypress, return false to let the text area handle the keypress
        /// </summary>
        bool TextAreaKeyEventHandler(char key)
        {
            if (m_code_complete != null)
            {
                // If completion window is open and wants to handle the key, don't let the text area
                // handle it
                if (m_code_complete.ProcessKeyEvent(key))
                {
                    return(true);
                }
            }

            ICSharpCode.TextEditor.Gui.CompletionWindow.ICompletionDataProvider completionDataProvider = CodeComplete.GetCompletionProvider(this, key);
            if (completionDataProvider == null && key == '(')
            {
                ICSharpCode.TextEditor.Document.LineSegment line = this.Document.GetLineSegment(ActiveTextAreaControl.Caret.Line);
                if (null == line)
                {
                    return(false);
                }

                List <ICSharpCode.TextEditor.Document.TextWord> words = line.Words;
                if (words == null || words.Count < 1)
                {
                    return(false);
                }

                ICSharpCode.TextEditor.Document.TextWord lastWord = words[words.Count - 1];
                if (lastWord.Type != ICSharpCode.TextEditor.Document.TextWordType.Word)
                {
                    return(false);
                }
                // Todo: Remove hard coded colors
                if (lastWord.Color == System.Drawing.Color.Green || lastWord.Color == System.Drawing.Color.Red)
                {
                    return(false);
                }

                // make sure first real word on this line is not "def"
                for (int i = 0; i < words.Count; i++)
                {
                    if (words[i].Type != ICSharpCode.TextEditor.Document.TextWordType.Word)
                    {
                        continue;
                    }
                    if (words[i].Word.Equals("def", StringComparison.Ordinal))
                    {
                        return(false);
                    }
                    break;
                }

                char c = lastWord.Word[0];
                if (char.IsLetter(c))
                {
                    // Build up a python script to execute
                    int           line_number = this.ActiveTextAreaControl.TextArea.Caret.Line;
                    StringBuilder script      = new StringBuilder();
                    for (int i = 0; i < line_number; i++)
                    {
                        line = this.ActiveTextAreaControl.TextArea.Document.GetLineSegment(i);
                        if (line != null && line.Words.Count > 2)
                        {
                            string firstword = line.Words[0].Word;
                            if (firstword.Equals("import", StringComparison.Ordinal) || firstword.Equals("from"))
                            {
                                script.AppendLine(this.ActiveTextAreaControl.TextArea.Document.GetText(line));
                            }
                        }
                    }

                    ICSharpCode.TextEditor.Document.LineSegment lastLine = this.ActiveTextAreaControl.TextArea.Document.GetLineSegment(line_number);
                    if (null == lastLine)
                    {
                        return(false);
                    }

                    //walk backward through the line until we hit something that is NOT a word or period
                    string evaluation = "";
                    for (int i = lastLine.Words.Count - 1; i >= 0; i--)
                    {
                        ICSharpCode.TextEditor.Document.TextWord word = lastLine.Words[i];
                        if (word.Type != ICSharpCode.TextEditor.Document.TextWordType.Word)
                        {
                            break;
                        }
                        c = word.Word[0];
                        if (c != '.' && !char.IsLetter(c))
                        {
                            break;
                        }
                        evaluation = evaluation.Insert(0, word.Word);
                    }

                    if (evaluation != "if" && evaluation != "while")
                    {
                        RhinoDLR_Python.Intellisense isense = m_intellisense;
                        if (isense == null)
                        {
                            isense = CodeComplete.Intellisense;
                        }
                        string rc = isense.EvaluateHelp(script.ToString(), evaluation);
                        if (!string.IsNullOrEmpty(rc) && null != m_help_callback)
                        {
                            m_help_callback(rc);
                        }
                    }
                }
            }
            else if (completionDataProvider != null)
            {
                ScriptEditor.Model.ScriptDocument doc = ScriptEditor.Model.Documents.DocumentFromId(DocumentId);
                string path = "none";
                if (doc != null && !string.IsNullOrEmpty(doc.FullPath))
                {
                    path = doc.FullPath;
                }

                m_code_complete = ICSharpCode.TextEditor.Gui.CompletionWindow.CodeCompletionWindow.ShowCompletionWindow(
                    m_mainform,             // The parent window for the completion window
                    this,                   // The text editor to show the window for
                    path,                   // 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_code_complete != null)
                {
                    // ShowCompletionWindow can return null when the provider returns an empty list
                    m_code_complete.Closed += new EventHandler(CloseCodeCompletionWindow);
                }
            }
            return(false);
        }
 public static CodeCompletionWindow ShowCompletionWindow(Form parent, TextEditorControl control, string fileName, ICompletionDataProvider completionDataProvider, char firstChar)
 {
     return(CodeCompletionWindow.ShowCompletionWindow(parent, control, fileName, completionDataProvider, firstChar, true, true));
 }
Пример #30
0
 void CodeCompletionWindowClosed(object sender, EventArgs e)
 {
     codeCompletionWindow.Closed -= new EventHandler(CodeCompletionWindowClosed);
     codeCompletionWindow.Dispose();
     codeCompletionWindow = null;
 }
 private void CloseCodeCompletionWindow(object sender, EventArgs e)
 {
     if (codeCompletionWindow != null)
     {
         codeCompletionWindow.Closed -= CloseCodeCompletionWindow;
         codeCompletionWindow.Dispose();
         codeCompletionWindow = null;
     }
 }
Пример #32
0
 private void _completionWindow_Closed(object sender, EventArgs e)
 {
     Form senderForm = (Form)sender;
     senderForm.Closed -= new EventHandler(_completionWindow_Closed);
     senderForm.Dispose();
     if (senderForm == _completionWindow)
     {
         _completionWindow = null;
     }
 }
Пример #33
0
        // 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;
        }
Пример #34
0
 void CloseCodeCompletionWindow(object sender, EventArgs e)
 {
   if (m_code_complete != null)
   {
     m_code_complete.Closed -= new EventHandler(CloseCodeCompletionWindow);
     m_code_complete.Dispose();
     m_code_complete = null;
   }
 }
Пример #35
0
        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);
                codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(ParentForm, this, FileName, completionDataProvider, ch, true, false);

                if (codeCompletionWindow != null) {
                    codeCompletionWindow.Closed += new EventHandler(CodeCompletionWindowClosed);
                }
            }
        }
Пример #36
0
 public override void ShowCompletionWindow(ICompletionDataProvider completionDataProvider, char ch)
 {
     completionWindow = CodeCompletionWindow.ShowCompletionWindow(textEditorControl.ParentForm, textEditorControl, String.Empty, completionDataProvider, ch);
     if (completionWindow != null)
     {
         completionWindow.Width = 250;
         completionWindow.Closed += CompletionWindowClosed;
     }
 }