123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- using EsPy.Python.Jedi;
- using ScintillaNET;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace EsPy.Components
- {
- public partial class CompletionForm : Form
- {
- public event EventHandler FormDisposing = null;
- public CompletionForm()
- {
- InitializeComponent();
- //this.Capture = true;
- this.listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged;
-
-
- }
- protected override bool ShowWithoutActivation
- {
- get { return true; }
- }
- protected override CreateParams CreateParams
- {
- get
- {
- CreateParams baseParams = base.CreateParams;
- const int WS_EX_NOACTIVATE = 0x08000000;
- const int WS_EX_TOOLWINDOW = 0x00000080;
- baseParams.ExStyle |= (int)(WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW);
- return baseParams;
- }
- }
- protected override void Dispose(bool disposing)
- {
- if (this.ToolTip != null)
- {
- this.ToolTip.Dispose();
- }
- Globals.MainForm.Deactivate -= MainForm_Deactivate;
- Globals.MainForm.Resize -= MainForm_Resize;
- if (this.FormDisposing != null)
- this.FormDisposing(this, new EventArgs());
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- private Scintilla FScintilla = null;
- public Scintilla Scintilla
- {
- get { return this.FScintilla; }
- set
- {
- this.FScintilla = value;
- if (this.FScintilla != null)
- {
- this.listBox.Font = this.Scintilla.Font;
- }
- }
- }
- public void Clear()
- {
- this.listBox.Items.Clear();
- }
- public void Add(Completion item)
- {
- this.listBox.Items.Add(item);
- }
- public void AddRange(List<Completion> list)
- {
- this.listBox.Items.AddRange(list.ToArray());
- }
- public int Count
- { get { return this.listBox.Items.Count; } }
- public int SelectedIndex
- {
- get { return this.listBox.SelectedIndex; }
- set {
- if (this.ToolTip != null)
- {
- this.ToolTip.Dispose();
- this.ToolTip = null;
- }
- this.listBox.SelectedIndex = value;
- }
- }
- //public void Home()
- //{
- // this.SelectedIndex = 0;
- //}
- //public void End()
- //{
- // this.SelectedIndex = this.listBox.Items.Count - 1;
- //}
- public BaseDefinition SelectedItem
- { get { return this.listBox.SelectedItem as BaseDefinition; } }
- public void SelectPrevious()
- {
- if (this.SelectedIndex < 0)
- {
- this.SelectedIndex = 0;
- }
- else if (this.SelectedIndex > 0)
- {
- this.SelectedIndex--;
- }
- }
- public void SelectNext()
- {
- if (this.SelectedIndex < 0)
- {
- this.SelectedIndex = 0;
- }
- else if (this.SelectedIndex < this.listBox.Items.Count - 1)
- {
- this.SelectedIndex++;
- }
- }
- //public void PageUp()
- //{
- //}
- //public void PageDown()
- //{
- //}
- private ToolTip ToolTip = null;
- private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.listBox.SelectedItem != null)
- {
- BaseDefinition def = (this.listBox.SelectedItem as BaseDefinition);
- string doc = string.IsNullOrEmpty(def.docstring) ? "No documentation" : def.docstring;
- string module = string.IsNullOrEmpty(def.module_name) ? "" : "module: " + def.module_name + "\r\n";
- string type = string.IsNullOrEmpty(def.type) ? "" : def.type + " ";
- string parm = def.parameters != null ? "(" + string.Join(", ", def.parameters) + ")" : "";
- string title = type + def.name + parm;
- if (ToolTip == null)
- {
- //ToolTip.Hide(this);
- //ToolTip.Dispose();
- this.ToolTip = new ToolTip();
- }
- //ToolTip = new ToolTip();
- if (!ToolTip.Equals(ToolTip.Tag))
- {
- ToolTip.ShowAlways = true;
- ToolTip.ToolTipTitle = title;
- Point p = this.Scintilla.PointToClient(new Point(this.Right + 2, this.Top + 2));
- ToolTip.Tag = this.listBox.SelectedItem;
- ToolTip.Show(module + doc, this.Scintilla, p);
- }
- }
- else if (this.ToolTip != null)
- {
- this.ToolTip.Dispose();
- this.ToolTip = null;
- }
- }
- //private void listBox_MouseDown(object sender, MouseEventArgs e)
- //{
-
- //}
- private void CompletionForm_Shown(object sender, EventArgs e)
- {
- Globals.MainForm.Deactivate += MainForm_Deactivate;
- Globals.MainForm.Resize += MainForm_Resize;
- }
- private void MainForm_Resize(object sender, EventArgs e)
- {
- this.Close();
- }
- private void MainForm_Deactivate(object sender, EventArgs e)
- {
- this.Close();
- }
- private void CompletionForm_Load(object sender, EventArgs e)
- {
- this.Height = this.listBox.Height + 2;
- }
- }
- }
|