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  * plugin DLL interface
19  *
20  * License: GPL-2.0 or later
21  */
22 module npp_demo.plugin_dll;
23 
24 
25 version (Windows):
26 
27 //pragma(lib, "kernel32");
28 //pragma(lib, "user32");
29 
30 private static import core.runtime;
31 private static import core.stdc.ctype;
32 private static import core.stdc.string;
33 private static import core.sys.windows.basetsd;
34 private static import core.sys.windows.winbase;
35 private static import core.sys.windows.windef;
36 private static import core.sys.windows.winnt;
37 private static import core.sys.windows.winuser;
38 private static import npp_api.pluginfunc.basic_interface;
39 private static import npp_api.pluginfunc.extra_interfece;
40 private static import npp_api.pluginfunc.npp_msgs;
41 private static import npp_api.pluginfunc.scintilla_msg;
42 private static import npp_api.pluginfunc.string;
43 private static import npp_api.powereditor.menucmdid;
44 private static import npp_api.powereditor.misc.pluginsmanager.notepad_plus_msgs;
45 private static import npp_api.powereditor.misc.pluginsmanager.plugininterface;
46 private static import npp_api.powereditor.scitillacomponent.gotolinedlg;
47 private static import npp_api.scintilla.scintilla;
48 private static import npp_demo.commands;
49 private static import npp_demo.config;
50 
51 mixin npp_api.pluginfunc.auto_pFunc.mixin_menu_index_change_check!(`Close_HTML_XML_tag_automatically`) insertHtmlCloseTag;
52 
53 extern (C)
54 __gshared npp_api.powereditor.misc.pluginsmanager.plugininterface.NppData gshared_nppData;
55 
56 /**
57  * Initialization of your plugin data
58  * It will be called while plugin loading
59  */
60 pragma(inline, true)
61 nothrow
62 void pluginInit(core.sys.windows.basetsd.HANDLE hModule)
63 
64 	in
65 	{
66 	}
67 
68 	do
69 	{
70 		static import core.sys.windows.winbase;
71 		static import core.sys.windows.windef;
72 		static import npp_api.powereditor.scitillacomponent.gotolinedlg;
73 		static import npp_demo.gotolinedlg;
74 
75 		// Initialize dockable demo dialog
76 		npp_demo.gotolinedlg._goToLine = new npp_demo.gotolinedlg.demo_dlg();
77 		npp_demo.gotolinedlg._goToLine.initialize(cast(core.sys.windows.windef.HINSTANCE)(hModule), core.sys.windows.windef.NULL);
78 	}
79 
80 pragma(inline, true)
81 nothrow
82 void pluginBeNotified(ref npp_api.scintilla.scintilla.SCNotification notifyCode)
83 
84 	do
85 	{
86 		static import core.stdc.ctype;
87 		static import core.stdc.string;
88 		static import core.sys.windows.windef;
89 		static import core.sys.windows.winuser;
90 		static import npp_api.pluginfunc.npp_msgs;
91 		static import npp_api.pluginfunc.scintilla_msg;
92 		static import npp_api.powereditor.misc.pluginsmanager.notepad_plus_msgs;
93 		static import npp_api.scintilla.scintilla;
94 
95 		switch (notifyCode.nmhdr.code) {
96 			case npp_api.powereditor.misc.pluginsmanager.notepad_plus_msgs.NPPN_SHUTDOWN:
97 				break;
98 
99 			case npp_api.scintilla.scintilla.SCN_CHARADDED:
100 				npp_api.powereditor.misc.pluginsmanager.notepad_plus_msgs.LangType docType;
101 				npp_api.pluginfunc.npp_msgs.send_NPPM_GETCURRENTLANGTYPE(.nppData._nppHandle, docType);
102 				bool isDocTypeHTML = ((docType == npp_api.powereditor.misc.pluginsmanager.notepad_plus_msgs.LangType.L_HTML) || (docType == npp_api.powereditor.misc.pluginsmanager.notepad_plus_msgs.LangType.L_XML) || (docType == npp_api.powereditor.misc.pluginsmanager.notepad_plus_msgs.LangType.L_PHP));
103 
104 				if (.menu_index[.search_index!(`Close_HTML_XML_tag_automatically`)].func_item._init2Check && isDocTypeHTML) {
105 					if (notifyCode.ch == '>') {
106 						char[512] buf;
107 						int currentEdit;
108 						npp_api.pluginfunc.npp_msgs.send_NPPM_GETCURRENTSCINTILLA(.nppData._nppHandle, currentEdit);
109 						core.sys.windows.windef.HWND hCurrentEditView = (currentEdit == 0) ? (.nppData._scintillaMainHandle) : (.nppData._scintillaSecondHandle);
110 						int currentPos = cast(int)(npp_api.pluginfunc.scintilla_msg.send_SCI_GETCURRENTPOS(hCurrentEditView));
111 						int beginPos = currentPos - cast(int)(buf.length - 1);
112 						int startPos = (beginPos > 0) ? (beginPos) : (0);
113 						int size = currentPos - startPos;
114 						char[516] insertString = "</";
115 
116 						if (size >= 3) {
117 							npp_api.scintilla.scintilla.Sci_TextRange tr = {{startPos, currentPos}, &(buf[0])};
118 
119 							npp_api.pluginfunc.scintilla_msg.send_SCI_GETTEXTRANGE(hCurrentEditView, tr);
120 
121 							if (buf[size - 2] != '/') {
122 								const (char)* pBegin = &(buf[0]);
123 								const (char)* pCur = &(buf[size - 2]);
124 								int  insertStringSize = 2;
125 
126 								for (; (pCur > pBegin) && (*pCur != '<') && (*pCur != '>') ;) {
127 									pCur--;
128 								}
129 
130 								if (*pCur == '<') {
131 									++pCur;
132 
133 									while ((core.stdc..string.strchr(":_-.", *pCur) != null) || (core.stdc.ctype.isalnum(*pCur) != 0)) {
134 										insertString[insertStringSize++] = *pCur;
135 										++pCur;
136 									}
137 								}
138 
139 								insertString[insertStringSize++] = '>';
140 								insertString[insertStringSize] = '\0';
141 
142 								if (insertStringSize > 3) {
143 									npp_api.pluginfunc.scintilla_msg.send_SCI_BEGINUNDOACTION(hCurrentEditView);
144 									npp_api.pluginfunc.scintilla_msg.send_SCI_REPLACESEL(hCurrentEditView, &(insertString[0]));
145 									npp_api.pluginfunc.scintilla_msg.send_SCI_SETSEL(hCurrentEditView, currentPos, currentPos);
146 									npp_api.pluginfunc.scintilla_msg.send_SCI_ENDUNDOACTION(hCurrentEditView);
147 								}
148 							}
149 						}
150 					}
151 				}
152 
153 				break;
154 
155 			default:
156 				return;
157 		}
158 	}
159 
160 /*
161  * Notepad++ interface functions
162  */
163 mixin npp_api.pluginfunc.extra_interfece.npp_plugin_interface!(npp_demo.config.plugin_def);