From d7d78db3b7366f20a49cc3a952235727bfe26c16 Mon Sep 17 00:00:00 2001 From: donho Date: Sun, 11 Jan 2009 19:01:30 +0000 Subject: [PATCH] [NEW_FEATURE] Add 2 plugin messages : NPPN_SHORTCUTREMAPPED notification and NPPM_GETSHORTCUTBYCMDID message. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@393 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 18 +++++++++++ .../MISC/PluginsManager/PluginsManager.cpp | 27 +++++++++++++++++ .../src/MISC/PluginsManager/PluginsManager.h | 1 + PowerEditor/src/Notepad_plus.cpp | 18 +++++++++++ .../src/WinControls/Grid/ShortcutMapper.cpp | 30 +++++++++++-------- PowerEditor/src/resource.h | 4 +-- 6 files changed, 84 insertions(+), 14 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 14b2bab0a..1b7b5b2b7 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -316,6 +316,13 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV // BOOL NPPM_ISSTATUSBARHIDDEN(0, 0) // returned value : TRUE if STATUSBAR is hidden, otherwise FALSE + #define NPPM_GETSHORTCUTBYCMDID (NPPMSG + 76) + // BOOL NPPM_GETSHORTCUTBYCMDID(int cmdID, ShortcutKey *sk) + // get your plugin command current mapped shortcut into sk via cmdID + // You may need it after getting NPPN_READY notification + // returned value : TRUE if this function call is successful and shorcut is enable, otherwise FALSE + + #define RUNCOMMAND_USER (WM_USER + 3000) #define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH) #define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY) @@ -412,5 +419,16 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = currentBufferID; + #define NPPN_SHORTCUTREMAPPED (NPPN_FIRST + 13) // To notify plugins that plugin command shortcut is remapped. + //scnNotification->nmhdr.code = NPPN_SHORTCUTSREMAPPED; + //scnNotification->nmhdr.hwndFrom = ShortcutKeyStructurePointer; + //scnNotification->nmhdr.idFrom = cmdID; + //where ShortcutKeyStructurePointer is pointer of struct ShortcutKey: + //struct ShortcutKey { + // bool _isCtrl; + // bool _isAlt; + // bool _isShift; + // UCHAR _key; + //}; #endif //NOTEPAD_PLUS_MSGS_H diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index a50bcf798..9a429b23b 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -213,6 +213,33 @@ bool PluginsManager::loadPlugins(const TCHAR *dir) return true; } +// return true if cmdID found and its shortcut is enable +// false otherwise +bool PluginsManager::getShortcutByCmdID(int cmdID, ShortcutKey *sk) +{ + if (cmdID == 0 || !sk) + return false; + + const vector & pluginCmdSCList = (NppParameters::getInstance())->getPluginCommandList(); + + for (size_t i = 0 ; i < pluginCmdSCList.size() ; i++) + { + if (pluginCmdSCList[i].getID() == cmdID) + { + const KeyCombo & kc = pluginCmdSCList[i].getKeyCombo(); + if (kc._key == 0x00) + return false; + + sk->_isAlt = kc._isAlt; + sk->_isCtrl = kc._isCtrl; + sk->_isShift = kc._isShift; + sk->_key = kc._key; + return true; + } + } + return false; +} + void PluginsManager::setMenu(HMENU hMenu, const TCHAR *menuName) { if (hasPlugins()) diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h index ba1849682..66770e09d 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h @@ -94,6 +94,7 @@ public: }; void setMenu(HMENU hMenu, const TCHAR *menuName); + bool getShortcutByCmdID(int cmdID, ShortcutKey *sk); void notify(SCNotification *notification) { for (size_t i = 0 ; i < _pluginInfos.size() ; i++) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 46e10ccbb..dd3dc81fa 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -7355,6 +7355,24 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa } return TRUE; + case NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED: + { + SCNotification scnN; + scnN.nmhdr.code = NPPN_SHORTCUTREMAPPED; + scnN.nmhdr.hwndFrom = (void *)lParam; // ShortcutKey structure + scnN.nmhdr.idFrom = (uptr_t)wParam; // cmdID + _pluginsManager.notify(&scnN); + } + return TRUE; + + case NPPM_GETSHORTCUTBYCMDID: + { + int cmdID = wParam; // cmdID + ShortcutKey *sk = (ShortcutKey *)lParam; // ShortcutKey structure + + return _pluginsManager.getShortcutByCmdID(cmdID, sk); + } + case NPPM_MENUCOMMAND : command(lParam); return TRUE; diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp index feff9b3f2..3ccfca402 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp @@ -202,7 +202,7 @@ BOOL CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP _babygrid.setText(row, 2, csc.toString().c_str()); //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); - //::SendMessage(_hParent, NPPM_INTERNAL_CMDLIST_MODIFIED, (WPARAM)sc.c_str(), cmdID); + } break; } case STATE_MACRO: { @@ -217,7 +217,7 @@ BOOL CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); - //::SendMessage(_hParent, NPPM_INTERNAL_MACROLIST_MODIFIED, 0, 0); + } break; } case STATE_USER: { @@ -233,7 +233,7 @@ BOOL CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); - //::SendMessage(_hParent, NPPM_INTERNAL_USERCMDLIST_MODIFIED, 0, 0); + } break; } case STATE_PLUGIN: { @@ -249,27 +249,33 @@ BOOL CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); - //::SendMessage(_hParent, NPPM_INTERNAL_PLUGINCMDLIST_MODIFIED, 0, 0); + unsigned long cmdID = pcsc.getID(); + ShortcutKey shortcut; + shortcut._isAlt = pcsc.getKeyCombo()._isAlt; + shortcut._isCtrl = pcsc.getKeyCombo()._isCtrl; + shortcut._isShift = pcsc.getKeyCombo()._isShift; + shortcut._key = pcsc.getKeyCombo()._key; + + ::SendMessage(_hParent, NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED, cmdID, (LPARAM)&shortcut); } break; } case STATE_SCINTILLA: { //Get ScintillaKeyMap corresponding to row vector & shortcuts = nppParam->getScintillaKeyList(); - ScintillaKeyMap skm = shortcuts[row - 1], prevskm = shortcuts[row - 1]; + ScintillaKeyMap skm = shortcuts[row - 1], prevskm = shortcuts[row-1]; skm.init(_hInst, _hSelf); - if (skm.doDialog() != -1 && prevskm != skm) { //shortcut was altered + if (skm.doDialog() != -1 && prevskm != skm) + { + //shortcut was altered nppParam->addScintillaModifiedIndex(row-1); - shortcuts[row - 1] = skm; + shortcuts[row-1] = skm; _babygrid.setText(row, 2, skm.toString().c_str()); //Notify current Accelerator class to update key nppParam->getScintillaAccelerator()->updateKeys(); - - //::SendMessage(_hParent, NPPM_INTERNAL_BINDSCINTILLAKEY, scintillaSc.toKeyDef(), scintillaSc.getScintillaKey()); - //::SendMessage(_hParent, NPPM_INTERNAL_CLEARSCINTILLAKEY, scintillaShortcuts[index].toKeyDef(), 0); - //::SendMessage(_hParent, NPPM_INTERNAL_SCINTILLAKEYMODIFIED, 0, 0); } - break; } + break; + } } return TRUE; } diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index 74f71c801..c07e46a8d 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -300,8 +300,8 @@ #define NPPM_INTERNAL_SWITCHVIEWFROMHWND (NOTEPADPLUS_USER_INTERNAL + 22) #define NPPM_INTERNAL_UPDATETITLEBAR (NOTEPADPLUS_USER_INTERNAL + 23) #define NPPM_INTERNAL_CANCEL_FIND_IN_FILES (NOTEPADPLUS_USER_INTERNAL + 24) - #define NPPM_INTERNAL_RELOADNATIVELANG (NOTEPADPLUS_USER_INTERNAL + 24) - + #define NPPM_INTERNAL_RELOADNATIVELANG (NOTEPADPLUS_USER_INTERNAL + 25) + #define NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED (NOTEPADPLUS_USER_INTERNAL + 26) // See Notepad_plus_msgs.h //#define NOTEPADPLUS_USER (WM_USER + 1000) #define SCINTILLA_USER (WM_USER + 2000)