public void CheckIfNeedsClosing() { if (IsShowing && !simple && lastMethodStartPos.HasValue) { int methodStartPos = lastMethodStartPos.Value; string text; popupForm.ProcessMethodOverloadHint(NppEditor.GetMethodOverloadHint(methodStartPos, out text)); int currentPos = Npp.GetCurrentDocument().GetCurrentPos(); if (currentPos <= methodStartPos) //user removed/substituted method token as the result of keyboard input { base.Close(); } else if (text != null && text[text.Length - 1] == ')') { string typedArgs = text; if (NRefactoryExtensions.AreBracketsClosed(typedArgs)) { base.Close(); } } } }
public void TriggerPopup(bool simple, int methodStartPos, string[] data) { try { this.simple = simple; lastMethodStartPos = methodStartPos; base.Popup( form => //on opening { if (!simple) { form.LeftBottomCorner = Npp.GetCurrentDocument().GetCaretScreenLocation(); } else { form.LeftBottomCorner = Cursor.Position; } form.Simple = simple; form.AddData(data); KeyInterceptor.Instance.Add(Keys.Escape); KeyInterceptor.Instance.KeyDown += Instance_KeyDown; if (!simple) { KeyInterceptor.Instance.Add(Keys.Down, Keys.Up, Keys.Escape, Keys.Enter, Keys.Delete, Keys.Back); form.KeyPress += (sender, e) => { NppEditor.ProcessKeyPress(e.KeyChar); Plugin.OnCharTyped(e.KeyChar); CheckIfNeedsClosing(); }; form.KeyDown += (sender, e) => { if (e.KeyCode == Keys.Delete) { NppEditor.ProcessDeleteKeyDown(); } }; form.ProcessMethodOverloadHint(NppEditor.GetMethodOverloadHint(methodStartPos)); Task.Factory.StartNew(() => { Rectangle rect = npp.GetClientRect(); while (popupForm != null) { try { Npp.GetCurrentDocument().GrabFocus(); var newRect = npp.GetClientRect(); if (rect != newRect) //if NPP moved, resized close the popup { base.Close(); return; } Thread.Sleep(500); } catch { base.Close(); return; } } }); } }, form => //on closing { KeyInterceptor.Instance.KeyDown -= Instance_KeyDown; }); } catch { } }