Skip to content

Commit cde7dc0

Browse files
committed
MSGTOPLUGIN implemented for other plugins to call Python functions
- Changes to allow synchronous scripts to be run (although no interface, other than using MSGTOPLUGIN) - Starts to documentation for Npp and Notepad objects (Editor/Scintilla object will be most auto-generated)
1 parent bc0e9c6 commit cde7dc0

File tree

17 files changed

+2031
-24
lines changed

17 files changed

+2031
-24
lines changed

NppPlugin/include/keys.h

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
See winuser.h
3+
Altered list to support VK_0-9 and VK_A-Z
4+
*/
5+
6+
#define VK_NULL 0x00
7+
8+
#define VK_CANCEL 0x03
9+
10+
#define VK_BACK 0x08
11+
#define VK_TAB 0x09
12+
13+
#define VK_CLEAR 0x0C
14+
#define VK_RETURN 0x0D
15+
16+
#define VK_SHIFT 0x10
17+
#define VK_CONTROL 0x11
18+
#define VK_MENU 0x12
19+
#define VK_PAUSE 0x13
20+
#define VK_CAPITAL 0x14
21+
22+
#define VK_KANA 0x15
23+
#define VK_HANGUL 0x15
24+
#define VK_JUNJA 0x17
25+
#define VK_FINAL 0x18
26+
#define VK_HANJA 0x19
27+
#define VK_KANJI 0x19
28+
29+
#define VK_ESCAPE 0x1B
30+
31+
#define VK_CONVERT 0x1C
32+
#define VK_NONCONVERT 0x1D
33+
#define VK_ACCEPT 0x1E
34+
#define VK_MODECHANGE 0x1F
35+
36+
#define VK_SPACE 0x20
37+
#define VK_PRIOR 0x21
38+
#define VK_NEXT 0x22
39+
#define VK_END 0x23
40+
#define VK_HOME 0x24
41+
#define VK_LEFT 0x25
42+
#define VK_UP 0x26
43+
#define VK_RIGHT 0x27
44+
#define VK_DOWN 0x28
45+
#define VK_SELECT 0x29
46+
#define VK_PRINT 0x2A
47+
#define VK_EXECUTE 0x2B
48+
#define VK_SNAPSHOT 0x2C
49+
#define VK_INSERT 0x2D
50+
#define VK_DELETE 0x2E
51+
#define VK_HELP 0x2F
52+
53+
#define VK_0 0x30
54+
#define VK_1 0x31
55+
#define VK_2 0x32
56+
#define VK_3 0x33
57+
#define VK_4 0x34
58+
#define VK_5 0x35
59+
#define VK_6 0x36
60+
#define VK_7 0x37
61+
#define VK_8 0x38
62+
#define VK_9 0x39
63+
#define VK_A 0x41
64+
#define VK_B 0x42
65+
#define VK_C 0x43
66+
#define VK_D 0x44
67+
#define VK_E 0x45
68+
#define VK_F 0x46
69+
#define VK_G 0x47
70+
#define VK_H 0x48
71+
#define VK_I 0x49
72+
#define VK_J 0x4A
73+
#define VK_K 0x4B
74+
#define VK_L 0x4C
75+
#define VK_M 0x4D
76+
#define VK_N 0x4E
77+
#define VK_O 0x4F
78+
#define VK_P 0x50
79+
#define VK_Q 0x51
80+
#define VK_R 0x52
81+
#define VK_S 0x53
82+
#define VK_T 0x54
83+
#define VK_U 0x55
84+
#define VK_V 0x56
85+
#define VK_W 0x57
86+
#define VK_X 0x58
87+
#define VK_Y 0x59
88+
#define VK_Z 0x5A
89+
90+
#define VK_LWIN 0x5B
91+
#define VK_RWIN 0x5C
92+
#define VK_APPS 0x5D
93+
94+
95+
#define VK_SLEEP 0x5F
96+
97+
#define VK_NUMPAD0 0x60
98+
#define VK_NUMPAD1 0x61
99+
#define VK_NUMPAD2 0x62
100+
#define VK_NUMPAD3 0x63
101+
#define VK_NUMPAD4 0x64
102+
#define VK_NUMPAD5 0x65
103+
#define VK_NUMPAD6 0x66
104+
#define VK_NUMPAD7 0x67
105+
#define VK_NUMPAD8 0x68
106+
#define VK_NUMPAD9 0x69
107+
#define VK_MULTIPLY 0x6A
108+
#define VK_ADD 0x6B
109+
#define VK_SEPARATOR 0x6C
110+
#define VK_SUBTRACT 0x6D
111+
#define VK_DECIMAL 0x6E
112+
#define VK_DIVIDE 0x6F
113+
#define VK_F1 0x70
114+
#define VK_F2 0x71
115+
#define VK_F3 0x72
116+
#define VK_F4 0x73
117+
#define VK_F5 0x74
118+
#define VK_F6 0x75
119+
#define VK_F7 0x76
120+
#define VK_F8 0x77
121+
#define VK_F9 0x78
122+
#define VK_F10 0x79
123+
#define VK_F11 0x7A
124+
#define VK_F12 0x7B
125+
#define VK_F13 0x7C
126+
#define VK_F14 0x7D
127+
#define VK_F15 0x7E
128+
#define VK_F16 0x7F
129+
#define VK_F17 0x80
130+
#define VK_F18 0x81
131+
#define VK_F19 0x82
132+
#define VK_F20 0x83
133+
#define VK_F21 0x84
134+
#define VK_F22 0x85
135+
#define VK_F23 0x86
136+
#define VK_F24 0x87
137+
138+
#define VK_NUMLOCK 0x90
139+
#define VK_SCROLL 0x91
140+
141+
#define VK_OEM_1 0xBA // ';:' for US
142+
#define VK_OEM_PLUS 0xBB // '+' any country
143+
#define VK_OEM_COMMA 0xBC // ',' any country
144+
#define VK_OEM_MINUS 0xBD // '-' any country
145+
#define VK_OEM_PERIOD 0xBE // '.' any country
146+
#define VK_OEM_2 0xBF // '/?' for US
147+
#define VK_OEM_3 0xC0 // '`~' for US
148+
149+
#define VK_OEM_4 0xDB // '[{' for US
150+
#define VK_OEM_5 0xDC // '\|' for US
151+
#define VK_OEM_6 0xDD // ']}' for US
152+
#define VK_OEM_7 0xDE // ''"' for US
153+
#define VK_OEM_8 0xDF
154+
155+
#define VK_OEM_102 0xE2 // "<>" or "\|" on RT 102-key kbd.
156+
157+
#define VK_OEM_RESET 0xE9
158+
#define VK_OEM_JUMP 0xEA
159+
#define VK_OEM_PA1 0xEB
160+
#define VK_OEM_PA2 0xEC
161+
#define VK_OEM_PA3 0xED
162+
#define VK_OEM_WSCTRL 0xEE
163+
#define VK_OEM_CUSEL 0xEF
164+
#define VK_OEM_ATTN 0xF0
165+
#define VK_OEM_FINISH 0xF1
166+
#define VK_OEM_COPY 0xF2
167+
#define VK_OEM_AUTO 0xF3
168+
#define VK_OEM_ENLW 0xF4
169+
#define VK_OEM_BACKTAB 0xF5
170+
#define VK_ATTN 0xF6
171+
#define VK_CRSEL 0xF7
172+
#define VK_EXSEL 0xF8
173+
#define VK_EREOF 0xF9
174+
#define VK_PLAY 0xFA
175+
#define VK_ZOOM 0xFB
176+
#define VK_NONAME 0xFC
177+
#define VK_PA1 0xFD
178+
#define VK_OEM_CLEAR 0xFE
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#ifndef _NPPPYTHONSCRIPT_H
2+
#define _NPPPYTHONSCRIPT_H
3+
4+
5+
6+
#define WIN32_LEAN_AND_MEAN
7+
#include <Windows.h>
8+
#undef WIN32_LEAN_AND_MEAN
9+
10+
#include <tchar.h>
11+
12+
#define PYSCR_START (WM_USER + 3500)
13+
14+
/** Execute a script in a file
15+
* (wParam = 0, PythonScript_Exec *pse)
16+
*/
17+
#define PYSCR_EXECSCRIPT (PYSCR_START+0)
18+
19+
20+
21+
/** Execute a script as a statement
22+
* (wParam = 0, PythonScript_Exec *pse)
23+
*/
24+
#define PYSCR_EXECSTATEMENT (PYSCR_START+1)
25+
26+
27+
/** Use PYSCRF_SYNC in the flags member to run the script or statement
28+
* synchronously (i.e. within the same thread). The SendMessage() call
29+
* will return when the script or statement has completed.
30+
*
31+
* Note that the completedEvent is NOT signalled if PYSCRF_SYNC is used.
32+
* Also bear in mind, that running scripts synchronously runs the script on the
33+
* UI thread, so everything is blocked - in a long running script, it will look like
34+
* N++ has frozen - short scripts may just cause a jitter. You have been warned :)
35+
* Better is to use the completedEvent of the struct to wait on a separate thread for
36+
* the script to finish.
37+
*/
38+
#define PYSCRF_SYNC (0x0001)
39+
40+
41+
struct PythonScript_Exec
42+
{
43+
/// PythonScript_Exec structure version - must always be 1
44+
int structVersion;
45+
46+
/// Python Script (for PYSCR_EXECSTATEMENT) or absolute filename (for PYSCR_EXECSCRIPT)
47+
TCHAR *script;
48+
49+
/** HANDLE to an event created with CreateEvent. This event is signalled (with SetEvent)
50+
* when the script has completed.
51+
* This can be NULL, in which case no event is signalled
52+
*
53+
* Important: Do NOT wait on the handle on the thread that Notepad++ runs on
54+
* (ie. the plugin default thread) unless you really know what you are doing :)
55+
* It will almost certainly deadlock (as Scintilla or N++ may need to process a message)
56+
*/
57+
58+
HANDLE completedEvent;
59+
60+
/** Flags for running the script
61+
* Combination of PYSCRF_xxxxx constants
62+
*/
63+
int flags;
64+
65+
/** PythonScripts sets this to TRUE when the PythonScript plugin
66+
* has successfully received the message.
67+
* Note that a TRUE here does NOT mean the script has run, or ran without
68+
* errors, merely that the script has been added to the queue to run
69+
*
70+
* You should set this to FALSE initially, and check for TRUE when SendMessage() returns.
71+
*/
72+
BOOL deliverySuccess;
73+
};
74+
75+
76+
#endif

PythonScript/project/PythonScript2010.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Optimization>Disabled</Optimization>
6161
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;PYTHONSCRIPT2010_EXPORTS;BOOST_PYTHON_STATIC_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
6262
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
63+
<AdditionalIncludeDirectories>../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
6364
</ClCompile>
6465
<Link>
6566
<SubSystem>Windows</SubSystem>
@@ -79,6 +80,7 @@
7980
<IntrinsicFunctions>true</IntrinsicFunctions>
8081
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;PYTHONSCRIPT2010_EXPORTS;BOOST_PYTHON_STATIC_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
8182
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
83+
<AdditionalIncludeDirectories>../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
8284
</ClCompile>
8385
<Link>
8486
<SubSystem>Windows</SubSystem>
@@ -136,6 +138,7 @@
136138
<ClCompile Include="..\src\WcharMbcsConverter.cpp" />
137139
</ItemGroup>
138140
<ItemGroup>
141+
<ClInclude Include="..\include\PythonScript\NppPythonScript.h" />
139142
<ClInclude Include="..\src\AboutDialog.h" />
140143
<ClInclude Include="..\src\ConfigFile.h" />
141144
<ClInclude Include="..\src\ConsoleDialog.h" />

PythonScript/project/PythonScript2010.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@
203203
<ClInclude Include="..\src\resource1.h">
204204
<Filter>Header Files</Filter>
205205
</ClInclude>
206+
<ClInclude Include="..\include\PythonScript\NppPythonScript.h">
207+
<Filter>Header Files</Filter>
208+
</ClInclude>
206209
</ItemGroup>
207210
<ItemGroup>
208211
<ResourceCompile Include="..\src\PythonScript.rc">

PythonScript/src/MenuManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool MenuManager::s_menuItemClicked;
2727
void (*MenuManager::s_runScript)(int);
2828

2929

30-
MenuManager* MenuManager::create(HWND hNotepad, HINSTANCE hInst, void(*runScript)(const char *))
30+
MenuManager* MenuManager::create(HWND hNotepad, HINSTANCE hInst, void(*runScript)(const char *, bool, HANDLE, bool))
3131
{
3232
if (NULL == s_menuManager)
3333
{
@@ -53,7 +53,7 @@ MenuManager* MenuManager::getInstance()
5353
}
5454

5555

56-
MenuManager::MenuManager(HWND hNotepad, HINSTANCE hInst, void(*runScript)(const char *))
56+
MenuManager::MenuManager(HWND hNotepad, HINSTANCE hInst, void(*runScript)(const char *, bool, HANDLE, bool))
5757
:
5858
m_hInst (hInst),
5959
m_hNotepad (hNotepad),
@@ -450,12 +450,12 @@ int MenuManager::findScripts(HMENU hBaseMenu, int basePathLength, int startID, s
450450

451451
void MenuManager::menuCommand(int commandID)
452452
{
453-
m_runScript(m_scriptCommands[commandID].c_str());
453+
m_runScript(m_scriptCommands[commandID].c_str(), false, NULL, false);
454454
}
455455

456456
void MenuManager::toolbarCommand(int commandID)
457457
{
458-
m_runScript(m_toolbarCommands[commandID].c_str());
458+
m_runScript(m_toolbarCommands[commandID].c_str(), false, NULL, false);
459459
}
460460

461461

PythonScript/src/MenuManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class MenuManager
2828
typedef std::vector<std::pair<tstring, void (*)()> > ItemVectorTD;
2929

3030

31-
static MenuManager* create(HWND hNotepad, HINSTANCE hInst, void(*runScript)(const char *));
31+
static MenuManager* create(HWND hNotepad, HINSTANCE hInst, void(*runScript)(const char *, bool, HANDLE, bool));
3232
static MenuManager* getInstance();
3333
static void deleteInstance();
3434

@@ -66,15 +66,15 @@ class MenuManager
6666

6767

6868
private:
69-
MenuManager(HWND hNotepad, HINSTANCE hInst, void(*runScript)(const char *));
69+
MenuManager(HWND hNotepad, HINSTANCE hInst, void(*runScript)(const char *, bool, HANDLE, bool));
7070

7171

7272

7373
HMENU getOurMenu();
7474
int findScripts(HMENU hBaseMenu, int basePathLength, int startID, std::string& path);
7575
void subclassNotepadPlusPlus();
7676

77-
void (*m_runScript)(const char*);
77+
void(*m_runScript)(const char *, bool, HANDLE, bool);
7878

7979
typedef std::set<std::string> MachineScriptNamesTD;
8080
typedef std::map<int, std::string> ScriptCommandsTD;

0 commit comments

Comments
 (0)