/// <summary> /// called when the user changes its selection in npp (the carret moves) /// </summary> public static void OnUpdateSelection() { Npp.UpdateScintilla(); // close popup windows ClosePopups(); Snippets.FinalizeCurrent(); // update scope of code explorer (the selection img) CodeExplorer.RedrawCodeExplorerList(); }
/// <summary> /// Called when the user presses a key /// </summary> // ReSharper disable once RedundantAssignment private static bool KeyDownHandler(Keys key, KeyModifiers keyModifiers) { // if set to true, the keyinput is completly intercepted, otherwise npp sill does its stuff bool handled = false; MenuItem menuItem = null; try { // Since it's a keydown message, we can receive this a lot if the user let a button pressed var isSpamming = Utils.IsSpamming(key.ToString(), 100, true); //HACK: // Ok so... when we open a form in notepad++, we can't use the overrides PreviewKeyDown / KeyDown // like we normally can, for some reasons, they don't react to certain keys (like enter!) // It only works "almost normally" if we ShowDialog() the form?! Wtf right? // So i gave up and handle things here! if (Appli.IsFocused()) { handled = Appli.Form.HandleKeyPressed(key, keyModifiers); } else { // same shit for the YamuiMenu var curMenu = (Control.FromHandle(WinApi.GetForegroundWindow())); var menu = curMenu as YamuiMenu; if (menu != null) { menu.OnKeyDown(key); } } // check if the user triggered a 3P function defined in the AppliMenu menuItem = TriggeredMenuItem(AppliMenu.Instance.ShortcutableItemList, isSpamming, key, keyModifiers, ref handled); if (handled) { return(true); } // The following is specific to 3P so don't go further if we are not on a valid file if (!IsCurrentFileProgress) { return(false); } // Close interfacePopups if (key == Keys.PageDown || key == Keys.PageUp || key == Keys.Next || key == Keys.Prior) { ClosePopups(); } // Autocompletion if (AutoComplete.IsVisible) { if (key == Keys.Up || key == Keys.Down || key == Keys.Tab || key == Keys.Return || key == Keys.Escape) { handled = AutoComplete.OnKeyDown(key); } else { if ((key == Keys.Right || key == Keys.Left) && keyModifiers.IsAlt) { handled = AutoComplete.OnKeyDown(key); } } } else { // snippet ? if (key == Keys.Tab || key == Keys.Escape || key == Keys.Return) { if (!keyModifiers.IsCtrl && !keyModifiers.IsAlt && !keyModifiers.IsShift) { if (!Snippets.InsertionActive) { //no snippet insertion in progress if (key == Keys.Tab) { if (Snippets.TriggerCodeSnippetInsertion()) { handled = true; } } } else { //there is a snippet insertion in progress if (key == Keys.Tab) { if (Snippets.NavigateToNextParam()) { handled = true; } } else if (key == Keys.Escape || key == Keys.Return) { Snippets.FinalizeCurrent(); if (key == Keys.Return) { handled = true; } } } } } } // next tooltip if (keyModifiers.IsCtrl && InfoToolTip.IsVisible && (key == Keys.Up || key == Keys.Down)) { if (key == Keys.Up) { InfoToolTip.IndexToShow--; } else { InfoToolTip.IndexToShow++; } InfoToolTip.TryToShowIndex(); handled = true; } } catch (Exception e) { ErrorHandler.ShowErrors(e, "Occured in : " + (menuItem == null ? (new ShortcutKey(keyModifiers.IsCtrl, keyModifiers.IsAlt, keyModifiers.IsShift, key)).ToString() : menuItem.ItemId)); } return(handled); }