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 * Notepad++のメニューから呼び出し可能な関数テンプレート。 19 * _pFuncに関数ポインタを渡すのに使う。 20 * 21 * Author: dokutoku, https://twitter.com/dokutoku3 22 * License: GPL-2.0 or later 23 */ 24 module npp_api.pluginfunc.auto_pFunc; 25 26 27 version (Windows): 28 version (Not_betterC): 29 30 pragma(lib, "user32.lib"); 31 //pragma(lib, "Shell32.lib"); 32 33 private static import core.sys.windows.shellapi; 34 private static import core.sys.windows.windef; 35 private static import core.sys.windows.winuser; 36 private static import std.traits; 37 private static import npp_api.powereditor.misc.pluginsmanager.plugininterface; 38 private static import npp_api.pluginfunc.string; 39 40 extern (C): 41 nothrow: 42 43 extern (C) 44 extern 45 npp_api.powereditor.misc.pluginsmanager.plugininterface.NppData nppData; 46 47 pure nothrow @safe @nogc 48 void auto_dummy_func() 49 50 do 51 { 52 } 53 54 nothrow @nogc 55 void auto_message_box(alias message, alias title)() 56 if (is(typeof(message) : immutable wstring) && is(typeof(title) : immutable wstring)) 57 58 in 59 { 60 static assert(message.length != 0); 61 static assert(title.length != 0); 62 } 63 64 do 65 { 66 static import core.sys.windows.winuser; 67 static import std.utf; 68 static import npp_api.pluginfunc.string; 69 70 enum message_def = npp_api.pluginfunc..string.c_wstring!(message); 71 enum title_def = npp_api.pluginfunc..string.c_wstring!(title); 72 73 core.sys.windows.winuser.MessageBoxW(.nppData._nppHandle, &(message_def[0]), &(title_def[0]), core.sys.windows.winuser.MB_OK); 74 } 75 76 nothrow @nogc 77 void auto_open_uri(alias uri)() 78 if (is(typeof(uri) : immutable wstring)) 79 80 in 81 { 82 static assert(uri.length != 0); 83 } 84 85 do 86 { 87 static import core.sys.windows.shellapi; 88 static import core.sys.windows.windef; 89 static import core.sys.windows.winuser; 90 static import std.utf; 91 static import npp_api.pluginfunc.string; 92 93 enum uri_def = npp_api.pluginfunc..string.c_wstring!(uri); 94 95 core.sys.windows.shellapi.ShellExecuteW(.nppData._nppHandle, &(npp_api.pluginfunc..string.c_wstring!(`open`w)[0]), &(uri_def[0]), core.sys.windows.windef.NULL, core.sys.windows.windef.NULL, core.sys.windows.winuser.SW_SHOWNORMAL); 96 } 97 98 /** 99 * メインメニューのチェックを変える 100 */ 101 mixin template mixin_main_menu_change_check(immutable string change_identifier, disable_identifiers...) 102 { 103 private static import npp_api.pluginfunc.menu; 104 105 extern (C) 106 nothrow @nogc 107 void auto_change_check() 108 109 in 110 { 111 assert(.main_menu_def.length == .main_menu.length); 112 113 foreach (disable_identifier; disable_identifiers) { 114 static assert(is(typeof(disable_identifier) : immutable string)); 115 } 116 } 117 118 do 119 { 120 static import npp_api.pluginfunc.menu; 121 122 enum change_pos = npp_api.pluginfunc.menu.search_menu_index(.menu_index_def, change_identifier); 123 static assert(.main_menu_def.length > change_pos); 124 npp_api.pluginfunc.menu.change_check(.nppData._nppHandle, .main_menu[change_pos]); 125 126 static if (disable_identifiers.length != 0) { 127 foreach (disable_identifier; disable_identifiers) { 128 enum disable_menu_pos = npp_api.pluginfunc.menu.search_menu_index(.menu_index_def, disable_identifier); 129 static assert(change_pos != disable_menu_pos); 130 static assert(.main_menu_def.length > disable_menu_pos); 131 npp_api.pluginfunc.menu.disable_check(.nppData._nppHandle, .main_menu[disable_menu_pos]); 132 } 133 } 134 } 135 } 136 137 /** 138 * メニューのチェックを変える 139 */ 140 mixin template mixin_menu_index_change_check(immutable string change_identifier, disable_identifiers...) 141 { 142 private static import npp_api.pluginfunc.menu; 143 144 extern (C) 145 nothrow @nogc 146 void auto_change_check() 147 148 in 149 { 150 assert(.menu_index_def.length == .menu_index.length); 151 152 foreach (disable_identifier; disable_identifiers) { 153 static assert(is(typeof(disable_identifier) : immutable string)); 154 } 155 } 156 157 do 158 { 159 static import npp_api.pluginfunc.menu; 160 161 enum change_pos = npp_api.pluginfunc.menu.search_index(.menu_index_def, change_identifier); 162 static assert(.menu_index_def.length > change_pos); 163 npp_api.pluginfunc.menu.change_check(.nppData._nppHandle, .menu_index[change_pos].func_item); 164 165 static if (disable_identifiers.length != 0) { 166 foreach (disable_identifier; disable_identifiers) { 167 enum disable_menu_pos = npp_api.pluginfunc.menu.search_index(.menu_index_def, disable_identifier); 168 static assert(change_pos != disable_menu_pos); 169 static assert(.menu_index_def.length > disable_menu_pos); 170 npp_api.pluginfunc.menu.disable_check(.nppData._nppHandle, .menu_index[disable_menu_pos].func_item); 171 } 172 } 173 } 174 } 175 176 /** 177 * 同階層のメニューのチェックを変える 178 */ 179 mixin template mixin_group_menu_checked(immutable string change_identifier) 180 { 181 private static import npp_api.pluginfunc.menu; 182 183 extern (C) 184 nothrow @nogc 185 void auto_change_check() 186 187 do 188 { 189 enum size_t pos = search_index!(change_identifier); 190 enum size_t start = npp_api.pluginfunc.menu.same_menu_start_pos(menu_index_def, pos); 191 enum size_t end = npp_api.pluginfunc.menu.same_menu_end_pos(menu_index_def, pos); 192 193 for (size_t i = start; i <= end; i++) { 194 if (i == pos) { 195 npp_api.pluginfunc.menu.change_check(.nppData._nppHandle, .menu_index[i].func_item); 196 } else { 197 npp_api.pluginfunc.menu.disable_check(.nppData._nppHandle, .menu_index[i].func_item); 198 } 199 } 200 } 201 }