Add new plugin API NPPM_REMOVESHORTCUTBYCMDID to allows plugins to remove unneeded shortcuts

Fix #4674, close #4687
This commit is contained in:
CFrank 2018-07-22 01:39:56 +02:00 committed by Don HO
parent efbc3b2160
commit 84938b7b0f
4 changed files with 37 additions and 0 deletions

View File

@ -414,6 +414,11 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
#define NPPM_DISABLEAUTOUPDATE (NPPMSG + 95) // 2119 in decimal
// VOID NPPM_DISABLEAUTOUPDATE(0, 0)
#define NPPM_REMOVESHORTCUTBYCMDID (NPPMSG + 96) // 2120 in decimal
// BOOL NPPM_REMOVESHORTCUTASSIGNMENT(int cmdID)
// removes the assigned shortcut mapped to cmdID
// returned value : TRUE if function call is successful, otherwise FALSE
#define RUNCOMMAND_USER (WM_USER + 3000)
#define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH)
#define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY)

View File

@ -452,6 +452,31 @@ bool PluginsManager::getShortcutByCmdID(int cmdID, ShortcutKey *sk)
return false;
}
// returns false if cmdID not provided, true otherwise
bool PluginsManager::removeShortcutByCmdID(int cmdID)
{
if (cmdID == 0) { return false; }
NppParameters *nppParam = NppParameters::getInstance();
vector<PluginCmdShortcut> & pluginCmdSCList = nppParam->getPluginCommandList();
for (size_t i = 0, len = pluginCmdSCList.size(); i < len; ++i)
{
if (pluginCmdSCList[i].getID() == (unsigned long)cmdID)
{
//remove shortcut
pluginCmdSCList[i].clear();
// inform accelerator instance
nppParam->getAccelerator()->updateShortcuts();
// set dirty flag to force writing shortcuts.xml on shutdown
nppParam->setShortcutDirty();
break;
}
}
return true;
}
void PluginsManager::addInMenuFromPMIndex(int i)
{

View File

@ -111,6 +111,7 @@ public:
void addInMenuFromPMIndex(int i);
HMENU setMenu(HMENU hMenu, const TCHAR *menuName, bool enablePluginAdmin = false);
bool getShortcutByCmdID(int cmdID, ShortcutKey *sk);
bool removeShortcutByCmdID(int cmdID);
void notify(const SCNotification *notification);
void relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam);

View File

@ -2299,6 +2299,12 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
return FALSE;
}
case NPPM_REMOVESHORTCUTBYCMDID:
{
int cmdID = static_cast<int32_t>(wParam);
return _pluginsManager.removeShortcutByCmdID(cmdID);
}
//
// These are sent by Preferences Dialog
//