1 //this file is part of notepad++ 2 //Copyright (C)2003 Don HO <donho@altern.org> 3 // 4 //This program is free software; you can redistribute it and/or 5 //modify it under the terms of the GNU General Public License 6 //as published by the Free Software Foundation; either 7 //version 2 of the License, or (at your option) any later version. 8 // 9 //This program is distributed in the hope that it will be useful, 10 //but WITHOUT ANY WARRANTY; without even the implied warranty of 11 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 //GNU General Public License for more details. 13 // 14 //You should have received a copy of the GNU General Public License 15 //along with this program; if not, write to the Free Software 16 //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 /** 18 * ショートカットをいろいろする 19 * 20 * Author: dokutoku, https://twitter.com/dokutoku3 21 * License: GPL-2.0 or later 22 */ 23 module npp_api.pluginfunc.shortcut; 24 25 26 version (Windows): 27 28 private static import core.sys.windows.windef; 29 private static import core.sys.windows.winuser; 30 private static import npp_api.powereditor.misc.pluginsmanager.plugininterface; 31 private static import npp_api.pluginfunc.menu; 32 33 pure nothrow @safe @nogc 34 void set_ACCEL(ref core.sys.windows.winuser.ACCEL HACCEL_shortcut, const ref npp_api.powereditor.misc.pluginsmanager.plugininterface.ShortcutKey npp_shortcut, core.sys.windows.windef.WORD cmd = 0) 35 36 do 37 { 38 HACCEL_shortcut.cmd = cmd; 39 HACCEL_shortcut.key = npp_shortcut._key; 40 HACCEL_shortcut.fVirt = 41 ((npp_shortcut._isCtrl) ? (core.sys.windows.winuser.FCONTROL) : (0)) 42 | ((npp_shortcut._isAlt) ? (core.sys.windows.winuser.FALT) : (0)) 43 | ((npp_shortcut._isShift) ? (core.sys.windows.winuser.FSHIFT) : (0)) 44 | (core.sys.windows.winuser.FVIRTKEY); 45 } 46 47 version (Not_betterC): 48 49 pure nothrow @safe @nogc 50 size_t sub_menu_shortcuts_length(const npp_api.pluginfunc.menu.sub_menu_index[] menu_list) 51 52 do 53 { 54 size_t length; 55 56 for (size_t i = 0; i < menu_list.length; i++) { 57 if ((menu_list[i].depth > 1) && (menu_list[i].func_item._pShKey != null)) { 58 length++; 59 } 60 } 61 62 return length; 63 } 64 65 pure nothrow @safe @nogc 66 core.sys.windows.winuser.ACCEL[shortcut_length] create_sub_menu_shortcuts(size_t shortcut_length)(const ref npp_api.pluginfunc.menu.sub_menu_index[] menu_list) 67 68 in 69 { 70 assert(shortcut_length == sub_menu_shortcuts_length(menu_list)); 71 } 72 73 do 74 { 75 core.sys.windows.winuser.ACCEL[shortcut_length] output; 76 77 size_t length = 0; 78 79 for (size_t i = 0; i < menu_list.length; i++) { 80 if ((menu_list[i].depth > 1) && (menu_list[i].func_item._pShKey != null)) { 81 .set_ACCEL(output[length], *(menu_list[i].func_item._pShKey)); 82 length++; 83 } 84 } 85 86 return output; 87 }