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"); 31 //pragma(lib, "Shell32"); 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_id, disable_ids...) 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_id; disable_ids) { 114 static assert(is(typeof(disable_id) : 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_id); 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_ids.length != 0) { 127 foreach (disable_id; disable_ids) { 128 enum disable_menu_pos = npp_api.pluginfunc.menu.search_menu_index(.menu_index_def, disable_id); 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_id, disable_ids...) 141 { 142 private static import npp_api.pluginfunc.menu; 143 144 pragma(mangle, change_id ~ "_auto_change_check_item") 145 extern (C) 146 nothrow @nogc 147 void auto_change_check() 148 149 in 150 { 151 assert(.menu_index_def.length == .menu_index.length); 152 153 foreach (disable_id; disable_ids) { 154 static assert(is(typeof(disable_id) : immutable string)); 155 } 156 } 157 158 do 159 { 160 static import npp_api.pluginfunc.menu; 161 162 enum change_pos = npp_api.pluginfunc.menu.search_index(.menu_index_def, change_id); 163 static assert(.menu_index_def.length > change_pos); 164 npp_api.pluginfunc.menu.change_check(.nppData._nppHandle, .menu_index[change_pos].func_item); 165 166 static if (disable_ids.length != 0) { 167 foreach (disable_id; disable_ids) { 168 enum disable_menu_pos = npp_api.pluginfunc.menu.search_index(.menu_index_def, disable_id); 169 static assert(change_pos != disable_menu_pos); 170 static assert(.menu_index_def.length > disable_menu_pos); 171 npp_api.pluginfunc.menu.disable_check(.nppData._nppHandle, .menu_index[disable_menu_pos].func_item); 172 } 173 } 174 } 175 } 176 177 /** 178 * 同階層のメニューのチェックを変える 179 */ 180 mixin template mixin_group_menu_checked(immutable string change_id) 181 { 182 private static import npp_api.pluginfunc.menu; 183 184 pragma(mangle, change_id ~ "auto_change_check") 185 extern (C) 186 nothrow @nogc 187 void auto_change_check() 188 189 do 190 { 191 enum size_t pos = search_index!(change_id); 192 enum size_t start = npp_api.pluginfunc.menu.same_menu_start_pos(menu_index_def, pos); 193 enum size_t end = npp_api.pluginfunc.menu.same_menu_end_pos(menu_index_def, pos); 194 195 for (size_t i = start; i <= end; i++) { 196 if (i == pos) { 197 npp_api.pluginfunc.menu.change_check(.nppData._nppHandle, .menu_index[i].func_item); 198 } else { 199 npp_api.pluginfunc.menu.disable_check(.nppData._nppHandle, .menu_index[i].func_item); 200 } 201 } 202 } 203 }