Skip to content

Commit 040fdf3

Browse files
committed
Fix Ctrl held down while clicking
- now checks that menu item has been clicked, and not a ctrl+xxx shortcut been pressed.
1 parent df02c05 commit 040fdf3

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

PythonScript/src/MenuManager.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ WNDPROC MenuManager::s_origWndProc;
1515

1616
int MenuManager::s_startCommandID;
1717
int MenuManager::s_endCommandID;
18+
int MenuManager::s_startFixedID;
19+
int MenuManager::s_endFixedID;
20+
bool MenuManager::s_menuItemClicked;
1821

1922
void (*MenuManager::s_runScript)(int);
2023

@@ -175,6 +178,10 @@ bool MenuManager::populateScriptsMenu()
175178

176179
s_endCommandID = findScripts(hScriptsMenu, userScriptsPath.size(), nextID, userScriptsPath);
177180

181+
// Assume here that the func items are assigned from start to finish
182+
s_startFixedID = m_funcItems[m_dynamicStartIndex]._cmdID;
183+
s_endFixedID = m_funcItems[m_funcItemCount - 1]._cmdID;
184+
178185
subclassNotepadPlusPlus();
179186

180187
}
@@ -300,9 +307,15 @@ LRESULT CALLBACK notepadWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l
300307
{
301308
if (LOWORD(wParam) >= MenuManager::s_startCommandID && LOWORD(wParam) < MenuManager::s_endCommandID && HIWORD(wParam) == 0)
302309
{
310+
MenuManager::s_menuItemClicked = true;
303311
MenuManager::getInstance()->menuCommand(LOWORD(wParam));
304312
return TRUE;
305313
}
314+
else if (LOWORD(wParam) >= MenuManager::s_startFixedID && LOWORD(wParam) < MenuManager::s_endFixedID && HIWORD(wParam) == 0)
315+
{
316+
MenuManager::s_menuItemClicked = true;
317+
}
318+
306319
}
307320

308321
return CallWindowProc(MenuManager::s_origWndProc, hWnd, message, wParam, lParam);
@@ -332,6 +345,8 @@ FuncItem* MenuManager::getFuncItemArray(int *nbF, ItemVectorTD items, void (*run
332345
// Remove one from the count of menu items if the list is empty
333346
// as we'll only have one separator
334347
*nbF = menuItems.size() + items.size() + (menuItems.empty() ? 0 : 1);
348+
349+
m_funcItemCount = *nbF;
335350

336351
m_funcItems = new FuncItem[*nbF];
337352

@@ -379,7 +394,8 @@ FuncItem* MenuManager::getFuncItemArray(int *nbF, ItemVectorTD items, void (*run
379394
}
380395

381396

382-
397+
m_dynamicStartIndex = dynamicStartIndex;
398+
m_dynamicCount = menuItems.size();
383399
m_scriptsMenuIndex = scriptsMenuIndex;
384400
m_stopScriptIndex = stopScriptIndex;
385401

PythonScript/src/MenuManager.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class MenuManager
2929

3030
static int s_startCommandID;
3131
static int s_endCommandID;
32+
static int s_startFixedID;
33+
static int s_endFixedID;
34+
static bool s_menuItemClicked;
3235
static WNDPROC s_origWndProc;
3336

3437

@@ -53,11 +56,13 @@ class MenuManager
5356

5457
HWND m_hNotepad;
5558
HINSTANCE m_hInst;
56-
int m_validCommandID;
59+
int m_dynamicStartIndex;
60+
int m_dynamicCount;
5761
int m_scriptsMenuIndex;
5862
int m_stopScriptIndex;
5963
HMENU m_pythonPluginMenu;
6064
FuncItem* m_funcItems;
65+
int m_funcItemCount;
6166

6267
// Function pointer to the real run script function
6368
static void (*s_runScript)(int);

PythonScript/src/PythonScript.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ FuncItem* getGeneratedFuncItemArray(int *nbF)
186186
items.push_back(pair<tstring, void(*)()>(_T("--"), reinterpret_cast<void(*)()>(NULL)));
187187
scriptsMenuIndex = items.size() - 1;
188188

189-
// items.push_back(pair<tstring, void(*)()>(_T("--"), reinterpret_cast<void(*)()>(NULL)));
190-
191189

192190
items.push_back(pair<tstring, void(*)()>(_T("About"), doAbout));
193191
// Add dynamic scripts right above "About" - a separator will automatically
@@ -348,7 +346,7 @@ void runScript(const char *filename)
348346
::GetKeyboardState(keyState);
349347

350348
// If either control held down, then edit the file
351-
if ((keyState[VK_LCONTROL] & 0x80) || (keyState[VK_RCONTROL] & 0x80))
349+
if (MenuManager::s_menuItemClicked && ((keyState[VK_LCONTROL] & 0x80) || (keyState[VK_RCONTROL] & 0x80)))
352350
{
353351
NotepadPlusWrapper wrapper(nppData._nppHandle);
354352
if (!wrapper.activateFile(filename))
@@ -364,6 +362,9 @@ void runScript(const char *filename)
364362
MessageBox(NULL, _T("Cannot run a script when a script is already running"), _T("Python Script"), 0);
365363
}
366364
}
365+
366+
MenuManager::s_menuItemClicked = false;
367+
367368
}
368369

369370
void showShortcutDlg()

0 commit comments

Comments
 (0)