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 npp_api.pluginfunc.string;
37 private static import npp_api.PowerEditor.MISC.PluginsManager.PluginInterface;
38 private static import std.traits;
39 private static import std.utf;
40 
41 extern (C):
42 nothrow:
43 
44 extern (C)
45 extern
46 npp_api.PowerEditor.MISC.PluginsManager.PluginInterface.NppData nppData;
47 
48 pure nothrow @safe @nogc
49 void auto_dummy_func()
50 
51 	do
52 	{
53 	}
54 
55 nothrow @nogc
56 void auto_message_box(alias message, alias title)()
57 	if (is(typeof(message) : immutable wstring) && is(typeof(title) : immutable wstring))
58 
59 	in
60 	{
61 		static assert(message.length != 0);
62 		static assert(title.length != 0);
63 	}
64 
65 	do
66 	{
67 		enum message_def = npp_api.pluginfunc..string.c_wstring!(message);
68 		enum title_def = npp_api.pluginfunc..string.c_wstring!(title);
69 
70 		core.sys.windows.winuser.MessageBoxW(.nppData._nppHandle, &(message_def[0]), &(title_def[0]), core.sys.windows.winuser.MB_OK);
71 	}
72 
73 nothrow @nogc
74 void auto_open_uri(alias uri)()
75 	if (is(typeof(uri) : immutable wstring))
76 
77 	in
78 	{
79 		static assert(uri.length != 0);
80 	}
81 
82 	do
83 	{
84 		enum uri_def = npp_api.pluginfunc..string.c_wstring!(uri);
85 
86 		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);
87 	}
88 
89 /**
90  * メインメニューのチェックを変える
91  */
92 mixin template mixin_main_menu_change_check(immutable string change_id, disable_ids...)
93 {
94 	private static import npp_api.pluginfunc.menu;
95 
96 	extern (C)
97 	nothrow @nogc
98 	void auto_change_check()
99 
100 		in
101 		{
102 			assert(.main_menu_def.length == .main_menu.length);
103 
104 			foreach (disable_id; disable_ids) {
105 				static assert(is(typeof(disable_id) : immutable string));
106 			}
107 		}
108 
109 		do
110 		{
111 			enum change_pos = npp_api.pluginfunc.menu.search_menu_index(.menu_index_def, change_id);
112 			static assert(.main_menu_def.length > change_pos);
113 			npp_api.pluginfunc.menu.change_check(.nppData._nppHandle, .main_menu[change_pos]);
114 
115 			static if (disable_ids.length != 0) {
116 				foreach (disable_id; disable_ids) {
117 					enum disable_menu_pos = npp_api.pluginfunc.menu.search_menu_index(.menu_index_def, disable_id);
118 					static assert(change_pos != disable_menu_pos);
119 					static assert(.main_menu_def.length > disable_menu_pos);
120 					npp_api.pluginfunc.menu.disable_check(.nppData._nppHandle, .main_menu[disable_menu_pos]);
121 				}
122 			}
123 		}
124 }
125 
126 /**
127  * メニューのチェックを変える
128  */
129 mixin template mixin_menu_index_change_check(immutable string change_id, disable_ids...)
130 {
131 	private static import npp_api.pluginfunc.menu;
132 
133 	pragma(mangle, change_id ~ "_auto_change_check_item")
134 	extern (C)
135 	nothrow @nogc
136 	void auto_change_check()
137 
138 		in
139 		{
140 			assert(.menu_index_def.length == .menu_index.length);
141 
142 			foreach (disable_id; disable_ids) {
143 				static assert(is(typeof(disable_id) : immutable string));
144 			}
145 		}
146 
147 		do
148 		{
149 			enum change_pos = npp_api.pluginfunc.menu.search_index(.menu_index_def, change_id);
150 			static assert(.menu_index_def.length > change_pos);
151 			npp_api.pluginfunc.menu.change_check(.nppData._nppHandle, .menu_index[change_pos].func_item);
152 
153 			static if (disable_ids.length != 0) {
154 				foreach (disable_id; disable_ids) {
155 					enum disable_menu_pos = npp_api.pluginfunc.menu.search_index(.menu_index_def, disable_id);
156 					static assert(change_pos != disable_menu_pos);
157 					static assert(.menu_index_def.length > disable_menu_pos);
158 					npp_api.pluginfunc.menu.disable_check(.nppData._nppHandle, .menu_index[disable_menu_pos].func_item);
159 				}
160 			}
161 		}
162 }
163 
164 /**
165  * 同階層のメニューのチェックを変える
166  */
167 mixin template mixin_group_menu_checked(immutable string change_id)
168 {
169 	private static import npp_api.pluginfunc.menu;
170 
171 	pragma(mangle, change_id ~ "auto_change_check")
172 	extern (C)
173 	nothrow @nogc
174 	void auto_change_check()
175 
176 		do
177 		{
178 			enum size_t pos = search_index!(change_id);
179 			enum size_t start = npp_api.pluginfunc.menu.same_menu_start_pos(menu_index_def, pos);
180 			enum size_t end = npp_api.pluginfunc.menu.same_menu_end_pos(menu_index_def, pos);
181 
182 			for (size_t i = start; i <= end; i++) {
183 				if (i == pos) {
184 					npp_api.pluginfunc.menu.change_check(.nppData._nppHandle, .menu_index[i].func_item);
185 				} else {
186 					npp_api.pluginfunc.menu.disable_check(.nppData._nppHandle, .menu_index[i].func_item);
187 				}
188 			}
189 		}
190 }