[NEW_FEATURE] Enhance ShortcutMapper - all the commands can be assigned to a shortcut, including the unmapped ones.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@118 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2008-01-30 00:31:11 +00:00
parent d88fa6236d
commit eedb31193b
20 changed files with 1956 additions and 1161 deletions

View File

@ -91,8 +91,6 @@ bool PluginsManager::loadPlugins(const char *dir)
if ((!pi->_funcItems) || (pi->_nbFuncItem <= 0)) if ((!pi->_funcItems) || (pi->_nbFuncItem <= 0))
throw string("Missing \"FuncItems\" array, or the nb of Function Item is not set correctly"); throw string("Missing \"FuncItems\" array, or the nb of Function Item is not set correctly");
getCustomizedShortcuts(pi->_moduleName, pi->_funcItems, pi->_nbFuncItem);
for (int c = 0 ; c < pi->_nbFuncItem ; c++) for (int c = 0 ; c < pi->_nbFuncItem ; c++)
if (!pi->_funcItems[c]._pFunc) if (!pi->_funcItems[c]._pFunc)
throw string("\"FuncItems\" array is not set correctly"); throw string("\"FuncItems\" array is not set correctly");
@ -219,6 +217,11 @@ void PluginsManager::setMenu(HMENU hMenu, const char *menuName)
itemName += "\t"; itemName += "\t";
itemName += pcs.toString(); itemName += pcs.toString();
} }
else
{ //no ShortcutKey is provided, add an disabled shortcut (so it can still be mapped, Paramaters class can still index any changes and the toolbar wont funk out
PluginCmdShortcut pcs(Shortcut(itemName.c_str(), false, false, false, 0x00), cmdID, _pluginInfos[i]->_moduleName, j); //VK_NULL and everything disabled, the menu name is left alone
pluginCmdSCList.push_back(pcs);
}
::InsertMenu(_pluginInfos[i]->_pluginMenu, j, MF_BYPOSITION, cmdID, itemName.c_str()); ::InsertMenu(_pluginInfos[i]->_pluginMenu, j, MF_BYPOSITION, cmdID, itemName.c_str());
if (_pluginInfos[i]->_funcItems[j]._init2Check) if (_pluginInfos[i]->_funcItems[j]._init2Check)
::CheckMenuItem(_hPluginsMenu, cmdID, MF_BYCOMMAND | MF_CHECKED); ::CheckMenuItem(_hPluginsMenu, cmdID, MF_BYCOMMAND | MF_CHECKED);

View File

@ -124,7 +124,7 @@ public:
HMENU getMenuHandle() { HMENU getMenuHandle() {
return _hPluginsMenu; return _hPluginsMenu;
}; };
/*
void getCustomizedShortcuts(char *pluginName, FuncItem *funcItems, int nbFuncItem) { void getCustomizedShortcuts(char *pluginName, FuncItem *funcItems, int nbFuncItem) {
vector<PluginCmdShortcut> & pluginCustomizedCmds = (NppParameters::getInstance())->getPluginCustomizedCmds(); vector<PluginCmdShortcut> & pluginCustomizedCmds = (NppParameters::getInstance())->getPluginCustomizedCmds();
@ -143,6 +143,7 @@ public:
} }
} }
}; };
*/
void disable() {_isDisabled = true;}; void disable() {_isDisabled = true;};
private: private:

View File

@ -1318,17 +1318,17 @@ void Notepad_plus::checkLangsMenu(int id) const
for (int i = IDM_LANG_USER + 1 ; i <= IDM_LANG_USER_LIMIT ; i++) for (int i = IDM_LANG_USER + 1 ; i <= IDM_LANG_USER_LIMIT ; i++)
{ {
if (::GetMenuString(::GetMenu(_hSelf), i, menuLangName, sizeof(menuLangName), MF_BYCOMMAND)) if (::GetMenuString(_mainMenuHandle, i, menuLangName, sizeof(menuLangName), MF_BYCOMMAND))
if (!strcmp(userLangName, menuLangName)) if (!strcmp(userLangName, menuLangName))
{ {
::CheckMenuRadioItem(::GetMenu(_hSelf), IDM_LANG_C, IDM_LANG_USER_LIMIT, i, MF_BYCOMMAND); ::CheckMenuRadioItem(_mainMenuHandle, IDM_LANG_C, IDM_LANG_USER_LIMIT, i, MF_BYCOMMAND);
return; return;
} }
} }
} }
} }
} }
::CheckMenuRadioItem(::GetMenu(_hSelf), IDM_LANG_C, IDM_LANG_USER_LIMIT, id, MF_BYCOMMAND); ::CheckMenuRadioItem(_mainMenuHandle, IDM_LANG_C, IDM_LANG_USER_LIMIT, id, MF_BYCOMMAND);
} }
string Notepad_plus::getLangDesc(LangType langType, bool shortDesc) string Notepad_plus::getLangDesc(LangType langType, bool shortDesc)
@ -1853,7 +1853,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
::ScreenToClient(_pDocTab->getHSelf(), &clientPoint); ::ScreenToClient(_pDocTab->getHSelf(), &clientPoint);
::SendMessage(_pDocTab->getHSelf(), WM_LBUTTONDOWN, 2, MAKELONG(clientPoint.x, clientPoint.y)); ::SendMessage(_pDocTab->getHSelf(), WM_LBUTTONDOWN, 2, MAKELONG(clientPoint.x, clientPoint.y));
bool isEnable = ((::GetMenuState(::GetMenu(_hSelf), IDM_FILE_SAVE, MF_BYCOMMAND)&MF_DISABLED) == 0); bool isEnable = ((::GetMenuState(_mainMenuHandle, IDM_FILE_SAVE, MF_BYCOMMAND)&MF_DISABLED) == 0);
_tabPopupMenu.enableItem(IDM_FILE_SAVE, isEnable); _tabPopupMenu.enableItem(IDM_FILE_SAVE, isEnable);
bool isUserReadOnly = _pEditView->isCurrentBufUserReadOnly(); bool isUserReadOnly = _pEditView->isCurrentBufUserReadOnly();
@ -2099,7 +2099,7 @@ void Notepad_plus::addHotSpot(bool docIsModifing)
_pEditView->execute(SCI_SETTARGETSTART, startPos); _pEditView->execute(SCI_SETTARGETSTART, startPos);
_pEditView->execute(SCI_SETTARGETEND, endPos); _pEditView->execute(SCI_SETTARGETEND, endPos);
vector<pair<int, int>> hotspotStylers; vector<pair<int, int> > hotspotStylers;
//char *regExprStr0 = "http://[a-z0-9_-+.:?=/%]*";//"http://[^ \\t\\\"]*"; //char *regExprStr0 = "http://[a-z0-9_-+.:?=/%]*";//"http://[^ \\t\\\"]*";
//char *regExprStr1 = "[a-zA-Z0-9._]+@[a-zA-Z0-9_]+.[a-zA-Z0-9_]+"; //char *regExprStr1 = "[a-zA-Z0-9._]+@[a-zA-Z0-9_]+.[a-zA-Z0-9_]+";
@ -2388,7 +2388,7 @@ void Notepad_plus::command(int id)
case IDM_EDIT_PASTE: case IDM_EDIT_PASTE:
{ {
int eolMode = int(_pEditView->execute(SCI_GETEOLMODE)); int eolMode = int(_pEditView->execute(SCI_GETEOLMODE));
_pEditView->execute(WM_PASTE); _pEditView->execute(SCI_PASTE);
//if (!(_pEditView->getCurrentBuffer()).isBin()) //if (!(_pEditView->getCurrentBuffer()).isBin())
_pEditView->execute(SCI_CONVERTEOLS, eolMode); _pEditView->execute(SCI_CONVERTEOLS, eolMode);
} }
@ -3315,6 +3315,7 @@ void Notepad_plus::command(int id)
{ {
ShortcutMapper shortcutMapper; ShortcutMapper shortcutMapper;
shortcutMapper.init(_hInst, _hSelf); shortcutMapper.init(_hInst, _hSelf);
changeShortcutmapperLang(&shortcutMapper);
shortcutMapper.doDialog(_isRTL); shortcutMapper.doDialog(_isRTL);
shortcutMapper.destroy(); shortcutMapper.destroy();
break; break;
@ -3685,7 +3686,7 @@ void Notepad_plus::command(int id)
for (int i = IDM_FILEMENU_LASTONE + 1 ; i < (IDM_FILEMENU_LASTONE + _lastRecentFileList.getMaxNbLRF() + 1) ; i++) for (int i = IDM_FILEMENU_LASTONE + 1 ; i < (IDM_FILEMENU_LASTONE + _lastRecentFileList.getMaxNbLRF() + 1) ; i++)
{ {
char fn[MAX_PATH]; char fn[MAX_PATH];
int res = ::GetMenuString(::GetMenu(_hSelf), i, fn, sizeof(fn), MF_BYCOMMAND); int res = ::GetMenuString(_mainMenuHandle, i, fn, sizeof(fn), MF_BYCOMMAND);
if (res) if (res)
{ {
doOpen(fn); doOpen(fn);
@ -3697,7 +3698,7 @@ void Notepad_plus::command(int id)
for (int i = IDM_FILEMENU_LASTONE + 1 ; i < (IDM_FILEMENU_LASTONE + _lastRecentFileList.getMaxNbLRF() + 1) ; i++) for (int i = IDM_FILEMENU_LASTONE + 1 ; i < (IDM_FILEMENU_LASTONE + _lastRecentFileList.getMaxNbLRF() + 1) ; i++)
{ {
char fn[MAX_PATH]; char fn[MAX_PATH];
int res = ::GetMenuString(::GetMenu(_hSelf), i, fn, sizeof(fn), MF_BYCOMMAND); int res = ::GetMenuString(_mainMenuHandle, i, fn, sizeof(fn), MF_BYCOMMAND);
if (res) if (res)
{ {
_lastRecentFileList.remove(fn); _lastRecentFileList.remove(fn);
@ -3733,7 +3734,7 @@ void Notepad_plus::command(int id)
//changeDlgLang(_windowsDlg.getHSelf(), "Window"); //changeDlgLang(_windowsDlg.getHSelf(), "Window");
} }
break; break;
/*
case IDC_KEY_HOME : case IDC_KEY_HOME :
_pEditView->execute(SCI_VCHOMEWRAP); _pEditView->execute(SCI_VCHOMEWRAP);
break; break;
@ -3749,12 +3750,12 @@ void Notepad_plus::command(int id)
case IDC_KEY_SELECT_2_END : case IDC_KEY_SELECT_2_END :
_pEditView->execute(SCI_LINEENDWRAPEXTEND); _pEditView->execute(SCI_LINEENDWRAPEXTEND);
break; break;
*/
default : default :
if (id > IDM_FILE_EXIT && id < (IDM_FILE_EXIT + _lastRecentFileList.getMaxNbLRF() + 1)) if (id > IDM_FILE_EXIT && id < (IDM_FILE_EXIT + _lastRecentFileList.getMaxNbLRF() + 1))
{ {
char fn[MAX_PATH]; char fn[MAX_PATH];
int res = ::GetMenuString(::GetMenu(_hSelf), id, fn, sizeof(fn), MF_BYCOMMAND); int res = ::GetMenuString(_mainMenuHandle, id, fn, sizeof(fn), MF_BYCOMMAND);
if (res) if (res)
{ {
if (doOpen(fn)) if (doOpen(fn))
@ -3766,7 +3767,7 @@ void Notepad_plus::command(int id)
else if ((id > IDM_LANG_USER) && (id < IDM_LANG_USER_LIMIT)) else if ((id > IDM_LANG_USER) && (id < IDM_LANG_USER_LIMIT))
{ {
char langName[langNameLenMax]; char langName[langNameLenMax];
::GetMenuString(::GetMenu(_hSelf), id, langName, sizeof(langName), MF_BYCOMMAND); ::GetMenuString(_mainMenuHandle, id, langName, sizeof(langName), MF_BYCOMMAND);
_pEditView->setCurrentDocUserType(langName); _pEditView->setCurrentDocUserType(langName);
setLangStatus(L_USER); setLangStatus(L_USER);
checkLangsMenu(id); checkLangsMenu(id);
@ -3849,9 +3850,9 @@ void Notepad_plus::command(int id)
case IDM_EDIT_STREAM_COMMENT: case IDM_EDIT_STREAM_COMMENT:
case IDM_EDIT_TRIMTRAILING: case IDM_EDIT_TRIMTRAILING:
case IDM_EDIT_SETREADONLY : case IDM_EDIT_SETREADONLY :
case IDM_EDIT_FULLPATHTOCLIP : case IDM_EDIT_FULLPATHTOCLIP :
case IDM_EDIT_FILENAMETOCLIP : case IDM_EDIT_FILENAMETOCLIP :
case IDM_EDIT_CURRENTDIRTOCLIP : case IDM_EDIT_CURRENTDIRTOCLIP :
case IDM_EDIT_CLEARREADONLY : case IDM_EDIT_CLEARREADONLY :
case IDM_EDIT_RTL : case IDM_EDIT_RTL :
case IDM_EDIT_LTR : case IDM_EDIT_LTR :
@ -4607,7 +4608,7 @@ void Notepad_plus::checkUnicodeMenuItems(UniMode um) const
default : default :
id = IDM_FORMAT_ANSI; id = IDM_FORMAT_ANSI;
} }
::CheckMenuRadioItem(::GetMenu(_hSelf), IDM_FORMAT_ANSI, IDM_FORMAT_AS_UTF_8, id, MF_BYCOMMAND); ::CheckMenuRadioItem(_mainMenuHandle, IDM_FORMAT_ANSI, IDM_FORMAT_AS_UTF_8, id, MF_BYCOMMAND);
} }
static bool isInList(string word, const vector<string> & wordArray) static bool isInList(string word, const vector<string> & wordArray)
@ -5076,6 +5077,100 @@ void Notepad_plus::changePrefereceDlgLang()
} }
void Notepad_plus::changeShortcutLang()
{
if (!_nativeLang) return;
NppParameters * pNppParam = NppParameters::getInstance();
vector<CommandShortcut> & mainshortcuts = pNppParam->getUserShortcuts();
vector<ScintillaKeyMap> & scinshortcuts = pNppParam->getScintillaKeyList();
int mainSize = (int)mainshortcuts.size();
int scinSize = (int)scinshortcuts.size();
TiXmlNode *shortcuts = _nativeLang->FirstChild("Shortcuts");
if (!shortcuts) return;
shortcuts = shortcuts->FirstChild("Main");
if (!shortcuts) return;
TiXmlNode *entriesRoot = shortcuts->FirstChild("Entries");
if (!entriesRoot) return;
for (TiXmlNode *childNode = entriesRoot->FirstChildElement("Item");
childNode ;
childNode = childNode->NextSibling("Item") )
{
TiXmlElement *element = childNode->ToElement();
int index, id;
if (element->Attribute("index", &index) && element->Attribute("id", &id))
{
if (index > -1 && index < mainSize) { //valid index only
const char *name = element->Attribute("name");
CommandShortcut csc = mainshortcuts[index];
if (csc.getID() == id) {
strncpy(csc._name, name, 64);
mainshortcuts[index] = csc;
}
}
}
}
//Scintilla
shortcuts = _nativeLang->FirstChild("Shortcuts");
if (!shortcuts) return;
shortcuts = shortcuts->FirstChild("Scintilla");
if (!shortcuts) return;
entriesRoot = shortcuts->FirstChild("Entries");
if (!entriesRoot) return;
for (TiXmlNode *childNode = entriesRoot->FirstChildElement("Item");
childNode ;
childNode = childNode->NextSibling("Item") )
{
TiXmlElement *element = childNode->ToElement();
int index;
if (element->Attribute("index", &index))
{
if (index > -1 && index < scinSize) { //valid index only
const char *name = element->Attribute("name");
ScintillaKeyMap skm = scinshortcuts[index];
strncpy(skm._name, name, 64);
scinshortcuts[index] = skm;
}
}
}
}
void Notepad_plus::changeShortcutmapperLang(ShortcutMapper * sm)
{
if (!_nativeLang) return;
TiXmlNode *shortcuts = _nativeLang->FirstChild("Dialog");
if (!shortcuts) return;
shortcuts = shortcuts->FirstChild("ShortcutMapper");
if (!shortcuts) return;
for (TiXmlNode *childNode = shortcuts->FirstChildElement("Item");
childNode ;
childNode = childNode->NextSibling("Item") )
{
TiXmlElement *element = childNode->ToElement();
int index;
if (element->Attribute("index", &index))
{
if (index > -1 && index < 5) { //valid index only
const char *name = element->Attribute("name");
sm->translateTab(index, name);
}
}
}
}
TiXmlNode * searchDlgNode(TiXmlNode *node, const char *dlgTagName) TiXmlNode * searchDlgNode(TiXmlNode *node, const char *dlgTagName)
{ {
TiXmlNode *dlgNode = node->FirstChild(dlgTagName); TiXmlNode *dlgNode = node->FirstChild(dlgTagName);
@ -5394,21 +5489,26 @@ bool Notepad_plus::addCurrentMacro()
{ {
vector<MacroShortcut> & theMacros = (NppParameters::getInstance())->getMacroList(); vector<MacroShortcut> & theMacros = (NppParameters::getInstance())->getMacroList();
MacroShortcut ms(_macro); int nbMacro = theMacros.size();
int cmdID = ID_MACRO + nbMacro;
MacroShortcut ms(Shortcut(), _macro, cmdID);
ms.init(_hInst, _hSelf); ms.init(_hInst, _hSelf);
ms._canModifyName = true;
if (ms.doDialog() != -1) if (ms.doDialog() != -1)
{ {
HMENU hMacroMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_MACRO);
int const posBase = 6; //separator at index 5
if (nbMacro == 0)
{
::InsertMenu(hMacroMenu, posBase-1, MF_BYPOSITION, (unsigned int)-1, 0); //no separator yet, add one
}
theMacros.push_back(ms); theMacros.push_back(ms);
HMENU hMacroMenu = ::GetSubMenu(::GetMenu(_hSelf), MENUINDEX_MACRO); ::InsertMenu(hMacroMenu, posBase + nbMacro, MF_BYPOSITION, cmdID, ms.toMenuItemString().c_str());
int const posBase = 3;
int nbMacro = theMacros.size();
if (nbMacro == 1)
::InsertMenu(hMacroMenu, posBase + 1, MF_BYPOSITION, (unsigned int)-1, 0);
//char menuString[64];
//sprintf(menuString, "%s%s%s", ms._name, "\t", ms.toString().c_str());
::InsertMenu(hMacroMenu, posBase + 1 + nbMacro, MF_BYPOSITION, ID_MACRO + nbMacro - 1, ms.toMenuItemString().c_str());
_isMacrosScModified = true; _isMacrosScModified = true;
_accelerator.uptdateShortcuts(); _accelerator.updateShortcuts();
return true; return true;
} }
return false; return false;
@ -5622,19 +5722,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
// Menu // Menu
_mainMenuHandle = ::GetMenu(_hSelf); _mainMenuHandle = ::GetMenu(_hSelf);
string pluginsTrans, windowTrans;
changeMenuLang(pluginsTrans, windowTrans);
_windowsMenu.init(_hInst, GetMenu(_hSelf), windowTrans.c_str());
vector<CommandShortcut> & shortcuts = pNppParam->getUserShortcuts();
for (size_t i = 0 ; i < shortcuts.size() ; i++)
{
changeMenuShortcut(shortcuts[i].getID(), shortcuts[i].toString().c_str());
}
//::DrawMenuBar(_hSelf);
_pDocTab = &_mainDocTab; _pDocTab = &_mainDocTab;
_pEditView = &_mainEditView; _pEditView = &_mainEditView;
@ -5693,10 +5780,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_mainEditView.showWrapSymbol(svp1._wrapSymbolShow); _mainEditView.showWrapSymbol(svp1._wrapSymbolShow);
_subEditView.showWrapSymbol(svp2._wrapSymbolShow); _subEditView.showWrapSymbol(svp2._wrapSymbolShow);
//checkMenuItem(IDM_SETTING_HISTORY_DONT_CHECK, !nppGUI._checkHistoryFiles);
//checkMenuItem(IDM_SETTING_TRAYICON, nppGUI._isMinimizedToTray);
//checkMenuItem(IDM_SETTING_REMEMBER_LAST_SESSION, nppGUI._rememberLastSession);
_mainEditView.performGlobalStyles(); _mainEditView.performGlobalStyles();
_subEditView.performGlobalStyles(); _subEditView.performGlobalStyles();
@ -5743,7 +5826,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
TabBarPlus::setDbClk2Close((tabBarStatus & TAB_DBCLK2CLOSE) != 0); TabBarPlus::setDbClk2Close((tabBarStatus & TAB_DBCLK2CLOSE) != 0);
TabBarPlus::setVertical((tabBarStatus & TAB_VERTICAL) != 0); TabBarPlus::setVertical((tabBarStatus & TAB_VERTICAL) != 0);
TabBarPlus::setMultiLine((tabBarStatus & TAB_MULTILINE) != 0); TabBarPlus::setMultiLine((tabBarStatus & TAB_MULTILINE) != 0);
//TabBarPlus::setNoTabBar((tabBarStatus & TAB_NOTABBAR) != 0);
//--Splitter Section--// //--Splitter Section--//
bool isVertical = (nppGUI._splitterPos == POS_VERTICAL); bool isVertical = (nppGUI._splitterPos == POS_VERTICAL);
@ -5760,8 +5842,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_statusBar.setPartWidth(STATUSBAR_UNICODE_TYPE, 100); _statusBar.setPartWidth(STATUSBAR_UNICODE_TYPE, 100);
_statusBar.setPartWidth(STATUSBAR_TYPING_MODE, 30); _statusBar.setPartWidth(STATUSBAR_TYPING_MODE, 30);
_statusBar.display(willBeShown); _statusBar.display(willBeShown);
//
//checkMenuItem(IDM_VIEW_STATUSBAR, willBeShown);
_findReplaceDlg.init(_hInst, hwnd, &_pEditView); _findReplaceDlg.init(_hInst, hwnd, &_pEditView);
_incrementFindDlg.init(_hInst, hwnd, &_findReplaceDlg); _incrementFindDlg.init(_hInst, hwnd, &_findReplaceDlg);
@ -5770,8 +5850,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_aboutDlg.init(_hInst, hwnd); _aboutDlg.init(_hInst, hwnd);
_runDlg.init(_hInst, hwnd); _runDlg.init(_hInst, hwnd);
_runMacroDlg.init(_hInst, hwnd); _runMacroDlg.init(_hInst, hwnd);
//checkMenuItem(IDM_SETTING_TAB_REPLCESPACE, nppGUI._tabReplacedBySpace);
_pMainWindow = &_mainDocTab; _pMainWindow = &_mainDocTab;
@ -5811,7 +5889,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
//dynamicCheckMenuAndTB(); //dynamicCheckMenuAndTB();
_mainEditView.defineDocType(L_TXT); _mainEditView.defineDocType(L_TXT);
HMENU hMenu = ::GetSubMenu(::GetMenu(_hSelf), MENUINDEX_FILE); HMENU hMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_FILE);
int nbLRFile = pNppParam->getNbLRFile(); int nbLRFile = pNppParam->getNbLRFile();
@ -5839,73 +5917,57 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
checkSyncState(); checkSyncState();
// Macro Menu
std::vector<MacroShortcut> & macros = pNppParam->getMacroList();
HMENU hMacroMenu = ::GetSubMenu(::GetMenu(_hSelf), MENUINDEX_MACRO);
size_t const posBase = 4;
size_t nbMacro = macros.size();
if (nbMacro >= 1)
::InsertMenu(hMacroMenu, posBase + 1, MF_BYPOSITION, (unsigned int)-1, 0);
for (size_t i = 0 ; i < nbMacro ; i++)
{
::InsertMenu(hMacroMenu, posBase + i + 2, MF_BYPOSITION, ID_MACRO + i, macros[i].toMenuItemString().c_str());
}
// Run Menu
std::vector<UserCommand> & userCommands = pNppParam->getUserCommandList();
HMENU hRunMenu = ::GetSubMenu(::GetMenu(_hSelf), MENUINDEX_RUN);
int const runPosBase = 1;
size_t nbUserCommand = userCommands.size();
if (nbUserCommand >= 1)
::InsertMenu(hRunMenu, runPosBase + 1, MF_BYPOSITION, (unsigned int)-1, 0);
for (size_t i = 0 ; i < nbUserCommand ; i++)
{
::InsertMenu(hRunMenu, runPosBase + i + 2, MF_BYPOSITION, ID_USER_CMD + i, userCommands[i].toMenuItemString().c_str());
}
_scintillaCtrls4Plugins.init(_hInst, hwnd);
// Updater menu item
if (!nppGUI._doesExistUpdater)
{
//::MessageBox(NULL, "pas de updater", "", MB_OK);
::DeleteMenu(::GetMenu(_hSelf), IDM_UPDATE_NPP, MF_BYCOMMAND);
::DrawMenuBar(hwnd);
}
// Plugin Manager // Plugin Manager
NppData nppData; NppData nppData;
nppData._nppHandle = _hSelf; nppData._nppHandle = _hSelf;
nppData._scintillaMainHandle = _mainEditView.getHSelf(); nppData._scintillaMainHandle = _mainEditView.getHSelf();
nppData._scintillaSecondHandle = _subEditView.getHSelf(); nppData._scintillaSecondHandle = _subEditView.getHSelf();
_scintillaCtrls4Plugins.init(_hInst, hwnd);
_pluginsManager.init(nppData); _pluginsManager.init(nppData);
//if (!pNppParam->isNoPlugin())
_pluginsManager.loadPlugins(); _pluginsManager.loadPlugins();
const char *appDataNpp = pNppParam->getAppDataNppDir(); const char *appDataNpp = pNppParam->getAppDataNppDir();
if (appDataNpp[0]) if (appDataNpp[0])
_pluginsManager.loadPlugins(appDataNpp); _pluginsManager.loadPlugins(appDataNpp);
_pluginsManager.setMenu(::GetMenu(_hSelf), pluginsTrans.c_str()); // Menu
string pluginsTrans, windowTrans;
changeMenuLang(pluginsTrans, windowTrans);
// To notify plugins that toolbar icons can be registered // Macro Menu
SCNotification scnN; std::vector<MacroShortcut> & macros = pNppParam->getMacroList();
scnN.nmhdr.code = NPPN_TBMODIFICATION; HMENU hMacroMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_MACRO);
scnN.nmhdr.hwndFrom = _hSelf; size_t const posBase = 6;
scnN.nmhdr.idFrom = 0; size_t nbMacro = macros.size();
_pluginsManager.notify(&scnN); if (nbMacro >= 1)
::InsertMenu(hMacroMenu, posBase - 1, MF_BYPOSITION, (unsigned int)-1, 0);
for (size_t i = 0 ; i < nbMacro ; i++)
{
::InsertMenu(hMacroMenu, posBase + i, MF_BYPOSITION, ID_MACRO + i, macros[i].toMenuItemString().c_str());
}
// Run Menu
std::vector<UserCommand> & userCommands = pNppParam->getUserCommandList();
HMENU hRunMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_RUN);
int const runPosBase = 2;
size_t nbUserCommand = userCommands.size();
if (nbUserCommand >= 1)
::InsertMenu(hRunMenu, runPosBase - 1, MF_BYPOSITION, (unsigned int)-1, 0);
for (size_t i = 0 ; i < nbUserCommand ; i++)
{
::InsertMenu(hRunMenu, runPosBase + i, MF_BYPOSITION, ID_USER_CMD + i, userCommands[i].toMenuItemString().c_str());
}
// Shortcut Accelerator : should be the last one since it will cacpture all the shortcut // Updater menu item
_accelerator.init(::LoadAccelerators(_hInst, MAKEINTRESOURCE(IDR_NPP_ACCELERATORS))); if (!nppGUI._doesExistUpdater)
{
if (_accelerator.uptdateShortcuts(hwnd)) //::MessageBox(NULL, "pas de updater", "", MB_OK);
_isCmdScModified = true; ::DeleteMenu(_mainMenuHandle, IDM_UPDATE_NPP, MF_BYCOMMAND);
::DrawMenuBar(hwnd);
pNppParam->setAccelerator(&_accelerator); }
//Languages Menu //Languages Menu
hMenu = ::GetSubMenu(::GetMenu(_hSelf), MENUINDEX_LANGUAGE); hMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_LANGUAGE);
// Add external languages to menu // Add external languages to menu
for (int i = 0 ; i < pNppParam->getNbExternalLang() ; i++) for (int i = 0 ; i < pNppParam->getNbExternalLang() ; i++)
@ -5947,6 +6009,14 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
::InsertMenu(hMenu, pos + i, MF_BYPOSITION, IDM_LANG_USER + i + 1, userLangContainer.getName()); ::InsertMenu(hMenu, pos + i, MF_BYPOSITION, IDM_LANG_USER + i + 1, userLangContainer.getName());
} }
//Plugin menu
_pluginsManager.setMenu(_mainMenuHandle, pluginsTrans.c_str());
//Windows menu
_windowsMenu.init(_hInst, _mainMenuHandle, windowTrans.c_str());
//The menu is loaded, add in all the accelerators
// Update context menu strings // Update context menu strings
vector<MenuItemUnit> & tmp = pNppParam->getContextMenuItems(); vector<MenuItemUnit> & tmp = pNppParam->getContextMenuItems();
size_t len = tmp.size(); size_t len = tmp.size();
@ -5975,8 +6045,73 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
} }
} }
//Input all the menu item names into shortcut list
//This will automatically do all translations, since menu translation has been done already
vector<CommandShortcut> & shortcuts = pNppParam->getUserShortcuts();
len = shortcuts.size();
int readI, writeI;
for(size_t i = 0; i < len; i++) {
CommandShortcut csc = shortcuts[i];
if (!csc._name[0]) {
if (::GetMenuString(_mainMenuHandle, csc.getID(), csc._name, 64, MF_BYCOMMAND)) {
readI = 0; writeI = 0;
while(csc._name[readI] != 0)
{
if (csc._name[readI] == '&')
{
readI++;
continue;
}
if (csc._name[readI] == '\t')
{
csc._name[writeI] = 0;
break;
}
csc._name[writeI] = csc._name[readI];
writeI++;
readI++;
}
csc._name[writeI] = 0;
}
}
shortcuts[i] = csc;
}
//Translate non-menu shortcuts
changeShortcutLang();
//Update plugin shortcuts, all plugin commands should be available now
pNppParam->reloadPluginCmds();
// Shortcut Accelerator : should be the last one since it will capture all the shortcuts
_accelerator.init(::LoadAccelerators(_hInst, MAKEINTRESOURCE(IDR_NPP_ACCELERATORS)), _mainMenuHandle, _hSelf);
pNppParam->setAccelerator(&_accelerator);
if (_accelerator.updateShortcuts())
_isCmdScModified = true;
// Scintilla key accelerator
vector<HWND> scints;
scints.push_back(_mainEditView.getHSelf());
scints.push_back(_subEditView.getHSelf());
_scintaccelerator.init(&scints, _mainMenuHandle, _hSelf);
pNppParam->setScintillaAccelerator(&_scintaccelerator);
_scintaccelerator.updateKeys();
::DrawMenuBar(_hSelf);
//-- Tool Bar Section --// //-- Tool Bar Section --//
toolBarStatusType tbStatus = nppGUI._toolBarStatus; toolBarStatusType tbStatus = nppGUI._toolBarStatus;
// To notify plugins that toolbar icons can be registered
SCNotification scnN;
scnN.nmhdr.code = NPPN_TBMODIFICATION;
scnN.nmhdr.hwndFrom = _hSelf;
scnN.nmhdr.idFrom = 0;
_pluginsManager.notify(&scnN);
// TB_LARGE par default // TB_LARGE par default
int iconSize = 32; int iconSize = 32;
@ -6745,9 +6880,9 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
&& (deltaLastLine >= 0)) // and no lines removed? && (deltaLastLine >= 0)) // and no lines removed?
break; // exit break; // exit
// Update the line count, but only if the number of lines is shrinking. // Update the line count, but only if the number of lines remaining is shrinking.
// Otherwise, the macro playback may never end. // Otherwise, the macro playback may never end.
if (deltaLastLine < 0) if (deltaLastLine < deltaCurrLine)
lastLine += deltaLastLine; lastLine += deltaLastLine;
// save current line // save current line
@ -6859,7 +6994,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case NPPM_INTERNAL_CMDLIST_MODIFIED : case NPPM_INTERNAL_CMDLIST_MODIFIED :
{ {
_isCmdScModified = true; _isCmdScModified = true;
changeMenuShortcut(lParam, (const char *)wParam); //changeMenuShortcut(lParam, (const char *)wParam);
::DrawMenuBar(_hSelf); ::DrawMenuBar(_hSelf);
return TRUE; return TRUE;
} }
@ -7547,6 +7682,7 @@ bool Notepad_plus::getIntegralDockingData(tTbData & dockData, int & iCont, bool
return false; return false;
} }
/*
void Notepad_plus::changeMenuShortcut(unsigned long cmdID, const char *shortcutStr) void Notepad_plus::changeMenuShortcut(unsigned long cmdID, const char *shortcutStr)
{ {
char cmdName[64]; char cmdName[64];
@ -7563,7 +7699,7 @@ void Notepad_plus::changeMenuShortcut(unsigned long cmdID, const char *shortcutS
itemStr += shortcutStr; itemStr += shortcutStr;
::ModifyMenu(_mainMenuHandle, cmdID, MF_BYCOMMAND, cmdID, itemStr.c_str()); ::ModifyMenu(_mainMenuHandle, cmdID, MF_BYCOMMAND, cmdID, itemStr.c_str());
} }
*/
void Notepad_plus::getCurrentOpenedFiles(Session & session) void Notepad_plus::getCurrentOpenedFiles(Session & session)
{ {
@ -7826,3 +7962,5 @@ winVer getWindowsVersion()
return WV_UNKNOWN; return WV_UNKNOWN;
} }

View File

@ -290,8 +290,7 @@ public:
}; };
void saveShortcuts() { void saveShortcuts() {
if (_isCmdScModified || _isMacrosScModified || _isUserCmdScModified || _isScintillaKeyModified || _isPluginCmdScModified) NppParameters::getInstance()->writeShortcuts();
(NppParameters::getInstance())->writeShortcuts(_isCmdScModified, _isMacrosScModified, _isUserCmdScModified, _isScintillaKeyModified, _isPluginCmdScModified);
}; };
void saveSession(const Session & session){ void saveSession(const Session & session){
@ -310,6 +309,8 @@ public:
void changeUserDefineLang(); void changeUserDefineLang();
void changeMenuLang(string & pluginsTrans, string & windowTrans); void changeMenuLang(string & pluginsTrans, string & windowTrans);
void changePrefereceDlgLang(); void changePrefereceDlgLang();
void changeShortcutLang();
void changeShortcutmapperLang(ShortcutMapper * sm);
const char * getNativeTip(int btnID); const char * getNativeTip(int btnID);
void changeToolBarIcons(); void changeToolBarIcons();
@ -451,6 +452,7 @@ private:
int _zoomOriginalValue; int _zoomOriginalValue;
Accelerator _accelerator; Accelerator _accelerator;
ScintillaAccelerator _scintaccelerator;
bool _isCmdScModified; bool _isCmdScModified;
bool _isMacrosScModified; bool _isMacrosScModified;
@ -507,7 +509,7 @@ private:
HWND _hParent; HWND _hParent;
} _scintillaCtrls4Plugins; } _scintillaCtrls4Plugins;
vector<pair<int, int>> _hideLinesMarks; vector<pair<int, int> > _hideLinesMarks;
static LRESULT CALLBACK Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
@ -833,7 +835,6 @@ private:
void getMatchedFileNames(const char *dir, const vector<string> & patterns, vector<string> & fileNames, bool isRecursive); void getMatchedFileNames(const char *dir, const vector<string> & patterns, vector<string> & fileNames, bool isRecursive);
void doSynScorll(HWND hW); void doSynScorll(HWND hW);
void changeMenuShortcut(unsigned long cmdID, const char *shortcutStr);
void setWorkingDir(char *dir) { void setWorkingDir(char *dir) {
if (NppParameters::getInstance()->getNppGUI()._saveOpenKeepInSameDir) if (NppParameters::getInstance()->getNppGUI()._saveOpenKeepInSameDir)
return; return;

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,293 @@
#include "ScintillaEditView.h" #include "ScintillaEditView.h"
#include <shlobj.h> #include <shlobj.h>
//#include <windows.h> #include "keys.h"
struct WinMenuKeyDefinition { //more or less matches accelerator table definition, easy copy/paste
//const char * name; //name retrieved from menu?
int vKey;
int functionId;
bool isCtrl;
bool isAlt;
bool isShift;
char * specialName; //Used when no real menu name exists (in case of toggle for example)
};
struct ScintillaKeyDefinition {
const char * name;
int functionId;
bool isCtrl;
bool isAlt;
bool isShift;
int vKey;
int redirFunctionId; //this gets set when a function is being redirected through Notepad++ if Scintilla doesnt do it properly :)
};
WinMenuKeyDefinition winKeyDefs[] = { //array of accelerator keys for all std menu items, values can be 0 for vKey, which means its unused
{VK_N, IDM_FILE_NEW, true, false, false, NULL},
{VK_O, IDM_FILE_OPEN, true, false, false, NULL},
{VK_NULL, IDM_FILE_RELOAD, false, false, false, NULL},
{VK_S, IDM_FILE_SAVE, true, false, false, NULL},
{VK_S, IDM_FILE_SAVEAS, true, true, false, NULL},
{VK_S, IDM_FILE_SAVEALL, true, false, true, NULL},
{VK_W, IDM_FILE_CLOSE, true, false, false, NULL},
{VK_NULL, IDM_FILE_CLOSEALL, false, false, false, NULL},
{VK_NULL, IDM_FILE_CLOSEALL_BUT_CURRENT, false, false, false, NULL},
{VK_NULL, IDM_FILE_LOADSESSION, false, false, false, NULL},
{VK_NULL, IDM_FILE_SAVESESSION, false, false, false, NULL},
{VK_P, IDM_FILE_PRINT, true, false, false, NULL},
{VK_NULL, IDM_FILE_PRINTNOW, false, false, false, NULL},
{VK_NULL, IDM_OPEN_ALL_RECENT_FILE, false, false, false, "Open All Recent Files"},
{VK_NULL, IDM_CLEAN_RECENT_FILE_LIST, false, false, false, "Clean Recent Files List"},
{VK_F4, IDM_FILE_EXIT, false, true, false, NULL},
// {VK_NULL, IDM_EDIT_UNDO, false, false, false, NULL},
// {VK_NULL, IDM_EDIT_REDO, false, false, false, NULL},
// {VK_NULL, IDM_EDIT_CUT, false, false, false, NULL},
// {VK_NULL, IDM_EDIT_COPY, false, false, false, NULL},
// {VK_NULL, IDM_EDIT_PASTE, false, false, false, NULL},
// {VK_NULL, IDM_EDIT_DELETE, false, false, false, NULL},
// {VK_NULL, IDM_EDIT_SELECTALL, false, false, false, NULL},
{VK_NULL, IDM_EDIT_FULLPATHTOCLIP, false, false, false, NULL},
{VK_NULL, IDM_EDIT_FILENAMETOCLIP, false, false, false, NULL},
{VK_NULL, IDM_EDIT_CURRENTDIRTOCLIP, false, false, false, NULL},
// {VK_NULL, IDM_EDIT_INS_TAB, false, false, false, NULL},
// {VK_NULL, IDM_EDIT_RMV_TAB, false, false, false, NULL},
// {VK_NULL, IDM_EDIT_DUP_LINE, false, false, false, NULL},
{VK_I, IDM_EDIT_SPLIT_LINES, true, false, false, NULL},
{VK_J, IDM_EDIT_JOIN_LINES, true, false, false, NULL},
{VK_UP, IDM_EDIT_LINE_UP, true, false, true, NULL},
{VK_DOWN, IDM_EDIT_LINE_DOWN, true, false, true, NULL},
{VK_NULL, IDM_EDIT_TRIMTRAILING, false, false, false, NULL},
{VK_C, IDM_EDIT_COLUMNMODE, false, true, false, NULL},
{VK_U, IDM_EDIT_UPPERCASE, true, false, true, NULL},
{VK_U, IDM_EDIT_LOWERCASE, true, false, false, NULL},
{VK_Q, IDM_EDIT_BLOCK_COMMENT, true, false, false, NULL},
{VK_K, IDM_EDIT_BLOCK_COMMENT_SET, true, false, false, NULL},
{VK_K, IDM_EDIT_BLOCK_UNCOMMENT, true, false, true, NULL},
{VK_Q, IDM_EDIT_STREAM_COMMENT, true, false, true, NULL},
{VK_SPACE, IDM_EDIT_AUTOCOMPLETE, true, false, false, NULL},
{VK_SPACE, IDM_EDIT_AUTOCOMPLETE_CURRENTFILE, true, false, true, NULL},
{VK_R, IDM_EDIT_RTL, true, true, false, NULL},
{VK_L, IDM_EDIT_LTR, true, true, false, NULL},
{VK_F, IDM_SEARCH_FIND, true, false, false, NULL},
{VK_F, IDM_SEARCH_FINDINFILES, true, false, true, NULL},
{VK_F3, IDM_SEARCH_FINDNEXT, false, false, false, NULL},
{VK_F3, IDM_SEARCH_FINDPREV, false, false, true, NULL},
{VK_F3, IDM_SEARCH_VOLATILE_FINDNEXT, true, false, false, NULL},
{VK_F3, IDM_SEARCH_VOLATILE_FINDPREV, true, false, true, NULL},
{VK_M, IDM_SEARCH_MARKALL, true, false, false, NULL},
{VK_M, IDM_SEARCH_UNMARKALL, true, false, true, NULL},
{VK_H, IDM_SEARCH_REPLACE, true, false, false, NULL},
{VK_I, IDM_SEARCH_FINDINCREMENT, true, true, false, NULL},
{VK_G, IDM_SEARCH_GOTOLINE, true, false, false, NULL},
{VK_B, IDM_SEARCH_GOTOMATCHINGBRACE, true, false, false, NULL},
{VK_F2, IDM_SEARCH_TOGGLE_BOOKMARK, true, false, false, NULL},
{VK_F2, IDM_SEARCH_NEXT_BOOKMARK, false, false, false, NULL},
{VK_F2, IDM_SEARCH_PREV_BOOKMARK, false, false, true, NULL},
{VK_NULL, IDM_SEARCH_CLEAR_BOOKMARKS, false, false, false, NULL},
{VK_F11, IDM_VIEW_FULLSCREENTOGGLE, false, false, false, NULL},
{VK_NULL, IDM_VIEW_ALWAYSONTOP, false, false, false, NULL},
{VK_NULL, IDM_VIEW_TAB_SPACE, false, false, false, NULL},
{VK_NULL, IDM_VIEW_EOL, false, false, false, NULL},
{VK_NULL, IDM_VIEW_ALL_CHARACTERS, false, false, false, NULL},
{VK_NULL, IDM_VIEW_INDENT_GUIDE, false, false, false, NULL},
{VK_NULL, IDM_VIEW_WRAP, false, false, false, NULL},
{VK_NULL, IDM_VIEW_WRAP_SYMBOL, false, false, false, NULL},
{VK_NULL, IDM_VIEW_USER_DLG, false, false, false, NULL},
//{VK_NULL, IDM_VIEW_ZOOMIN, false, false, false, NULL},
//{VK_NULL, IDM_VIEW_ZOOMOUT, false, false, false, NULL},
{VK_NULL, IDM_VIEW_ZOOMRESTORE, false, false, false, NULL},
{VK_0, IDM_VIEW_TOGGLE_FOLDALL, false, true, false, NULL},
{VK_F, IDM_VIEW_FOLD_CURRENT, true, true, false, NULL},
{VK_1, IDM_VIEW_FOLD_1, false, true, false, NULL},
{VK_2, IDM_VIEW_FOLD_2, false, true, false, NULL},
{VK_3, IDM_VIEW_FOLD_3, false, true, false, NULL},
{VK_4, IDM_VIEW_FOLD_4, false, true, false, NULL},
{VK_5, IDM_VIEW_FOLD_5, false, true, false, NULL},
{VK_6, IDM_VIEW_FOLD_6, false, true, false, NULL},
{VK_7, IDM_VIEW_FOLD_7, false, true, false, NULL},
{VK_8, IDM_VIEW_FOLD_8, false, true, false, NULL},
{VK_F, IDM_VIEW_UNFOLD_CURRENT, true, true, true, NULL},
{VK_1, IDM_VIEW_UNFOLD_1, false, true, true, NULL},
{VK_2, IDM_VIEW_UNFOLD_2, false, true, true, NULL},
{VK_3, IDM_VIEW_UNFOLD_3, false, true, true, NULL},
{VK_4, IDM_VIEW_UNFOLD_4, false, true, true, NULL},
{VK_5, IDM_VIEW_UNFOLD_5, false, true, true, NULL},
{VK_6, IDM_VIEW_UNFOLD_6, false, true, true, NULL},
{VK_7, IDM_VIEW_UNFOLD_7, false, true, true, NULL},
{VK_8, IDM_VIEW_UNFOLD_8, false, true, true, NULL},
{VK_0, IDM_VIEW_TOGGLE_UNFOLDALL, false, true, true, NULL},
{VK_H, IDM_VIEW_HIDELINES, false, true, false, NULL},
{VK_NULL, IDM_VIEW_GOTO_ANOTHER_VIEW, false, false, false, NULL},
{VK_NULL, IDM_VIEW_CLONE_TO_ANOTHER_VIEW, false, false, false, NULL},
{VK_NULL, IDM_VIEW_SYNSCROLLV, false, false, false, NULL},
{VK_NULL, IDM_VIEW_SYNSCROLLH, false, false, false, NULL},
{VK_NULL, IDM_FORMAT_TODOS, false, false, false, NULL},
{VK_NULL, IDM_FORMAT_TOUNIX, false, false, false, NULL},
{VK_NULL, IDM_FORMAT_TOMAC, false, false, false, NULL},
{VK_NULL, IDM_FORMAT_ANSI, false, false, false, NULL},
{VK_NULL, IDM_FORMAT_UTF_8, false, false, false, NULL},
{VK_NULL, IDM_FORMAT_AS_UTF_8, false, false, false, NULL},
{VK_NULL, IDM_FORMAT_UCS_2BE, false, false, false, NULL},
{VK_NULL, IDM_FORMAT_UCS_2LE, false, false, false, NULL},
{VK_NULL, IDM_SETTING_PREFERECE, false, false, false, NULL},
{VK_NULL, IDM_LANGSTYLE_CONFIG_DLG, false, false, false, NULL},
{VK_NULL, IDM_SETTING_SHORTCUT_MAPPER, false, false, false, NULL},
{VK_R, IDC_EDIT_TOGGLEMACRORECORDING, true, false, true, "Toggle macro record"},
{VK_P, IDM_MACRO_PLAYBACKRECORDEDMACRO, true, false, true, NULL},
{VK_NULL, IDM_MACRO_SAVECURRENTMACRO, false, false, false, NULL},
{VK_NULL, IDM_MACRO_RUNMULTIMACRODLG, false, false, false, NULL},
{VK_F5, IDM_EXECUTE, false, false, false, NULL},
// {VK_NULL, IDM_WINDOW_WINDOWS, false, false, false, NULL},
{VK_NULL, IDM_HOMESWEETHOME, false, false, false, NULL},
{VK_NULL, IDM_PROJECTPAGE, false, false, false, NULL},
{VK_NULL, IDM_ONLINEHELP, false, false, false, NULL},
{VK_NULL, IDM_FORUM, false, false, false, NULL},
{VK_NULL, IDM_PLUGINSHOME, false, false, false, NULL},
{VK_F1, IDM_ABOUT, false, false, false, NULL},
{VK_TAB, IDC_PREV_DOC, true, false, true, "Switch to previous document"},
{VK_TAB, IDC_NEXT_DOC, true, false, false, "Switch to next document"},
};
ScintillaKeyDefinition scintKeyDefs[] = { //array of accelerator keys for all possible scintilla functions, values can be 0 for vKey, which means its unused
{"SCI_CUT", SCI_CUT, true, false, false, VK_X, IDM_EDIT_CUT},
{"SCI_COPY", SCI_COPY, true, false, false, VK_C, IDM_EDIT_COPY},
{"SCI_PASTE", SCI_PASTE, true, false, false, VK_V, IDM_EDIT_PASTE},
{"SCI_SELECTALL", SCI_SELECTALL, true, false, false, VK_A, IDM_EDIT_SELECTALL},
{"SCI_CLEAR", SCI_CLEAR, false, false, false, VK_DELETE, IDM_EDIT_DELETE},
{"SCI_CLEARALL", SCI_CLEARALL, false, false, false, 0, 0},
{"SCI_UNDO", SCI_UNDO, true, false, false, VK_Z, IDM_EDIT_UNDO},
{"SCI_REDO", SCI_REDO, true, false, false, VK_Y, IDM_EDIT_REDO},
{"SCI_NEWLINE", SCI_NEWLINE, false, false, false, VK_RETURN, 0},
{"SCI_TAB", SCI_TAB, false, false, false, VK_TAB, IDM_EDIT_INS_TAB},
{"SCI_BACKTAB", SCI_BACKTAB, false, false, true, VK_TAB, IDM_EDIT_RMV_TAB},
{"SCI_FORMFEED", SCI_FORMFEED, false, false, false, 0, 0},
{"SCI_ZOOMIN", SCI_ZOOMIN, true, false, false, VK_ADD, IDM_VIEW_ZOOMIN},
{"SCI_ZOOMOUT", SCI_ZOOMOUT, true, false, false, VK_SUBTRACT,IDM_VIEW_ZOOMOUT},
{"SCI_SETZOOM", SCI_SETZOOM, true, false, false, VK_DIVIDE, 0},
{"SCI_SELECTIONDUPLICATE", SCI_SELECTIONDUPLICATE, true, false, false, VK_D, IDM_EDIT_DUP_LINE},
{"SCI_LINESJOIN", SCI_LINESJOIN, false, false, false, 0, 0},
{"SCI_SCROLLCARET", SCI_SCROLLCARET, false, false, false, 0, 0},
{"SCI_EDITTOGGLEOVERTYPE", SCI_EDITTOGGLEOVERTYPE, false, false, false, VK_INSERT, 0},
{"SCI_MOVECARETINSIDEVIEW", SCI_MOVECARETINSIDEVIEW, false, false, false, 0, 0},
{"SCI_LINEDOWN", SCI_LINEDOWN, false, false, false, VK_DOWN, 0},
{"SCI_LINEDOWNEXTEND", SCI_LINEDOWNEXTEND, false, false, true, VK_DOWN, 0},
{"SCI_LINEDOWNRECTEXTEND", SCI_LINEDOWNRECTEXTEND, false, true, true, VK_DOWN, 0},
{"SCI_LINESCROLLDOWN", SCI_LINESCROLLDOWN, true, false, false, VK_DOWN, 0},
{"SCI_LINEUP", SCI_LINEUP, false, false, false, VK_UP, 0},
{"SCI_LINEUPEXTEND", SCI_LINEUPEXTEND, false, false, true, VK_UP, 0},
{"SCI_LINEUPRECTEXTEND", SCI_LINEUPRECTEXTEND, false, true, true, VK_UP, 0},
{"SCI_LINESCROLLUP", SCI_LINESCROLLUP, true, false, false, VK_UP, 0},
{"SCI_PARADOWN", SCI_PARADOWN, true, false, false, VK_OEM_6, 0},
{"SCI_PARADOWNEXTEND", SCI_PARADOWNEXTEND, true, false, true, VK_OEM_6, 0},
{"SCI_PARAUP", SCI_PARAUP, true, false, false, VK_OEM_4, 0},
{"SCI_PARAUPEXTEND", SCI_PARAUPEXTEND, true, false, true, VK_OEM_4, 0},
{"SCI_CHARLEFT", SCI_CHARLEFT, false, false, false, VK_LEFT, 0},
{"SCI_CHARLEFTEXTEND", SCI_CHARLEFTEXTEND, false, false, true, VK_LEFT, 0},
{"SCI_CHARLEFTRECTEXTEND", SCI_CHARLEFTRECTEXTEND, false, true, true, VK_LEFT, 0},
{"SCI_CHARRIGHT", SCI_CHARRIGHT, false, false, false, VK_RIGHT, 0},
{"SCI_CHARRIGHTEXTEND", SCI_CHARRIGHTEXTEND, false, false, true, VK_RIGHT, 0},
{"SCI_CHARRIGHTRECTEXTEND", SCI_CHARRIGHTRECTEXTEND, false, true, true, VK_RIGHT, 0},
{"SCI_WORDLEFT", SCI_WORDLEFT, true, false, false, VK_LEFT, 0},
{"SCI_WORDLEFTEXTEND", SCI_WORDLEFTEXTEND, true, false, true, VK_LEFT, 0},
{"SCI_WORDRIGHT", SCI_WORDRIGHT, true, false, false, VK_RIGHT, 0},
{"SCI_WORDRIGHTEXTEND", SCI_WORDRIGHTEXTEND, false, false, false, 0, 0},
{"SCI_WORDLEFTEND", SCI_WORDLEFTEND, false, false, false, 0, 0},
{"SCI_WORDLEFTENDEXTEND", SCI_WORDLEFTENDEXTEND, false, false, false, 0, 0},
{"SCI_WORDRIGHTEND", SCI_WORDRIGHTEND, false, false, false, 0, 0},
{"SCI_WORDRIGHTEXTEND", SCI_WORDRIGHTEXTEND, true, false, true, VK_RIGHT, 0},
{"SCI_WORDPARTLEFT", SCI_WORDPARTLEFT, true, false, false, VK_OEM_2, 0},
{"SCI_WORDPARTLEFTEXTEND", SCI_WORDPARTLEFTEXTEND, true, false, true, VK_OEM_2, 0},
{"SCI_WORDPARTRIGHT", SCI_WORDPARTRIGHT, true, false, false, VK_OEM_5, 0},
{"SCI_WORDPARTRIGHTEXTEND", SCI_WORDPARTRIGHTEXTEND, true, false, true, VK_OEM_5, 0},
{"SCI_HOME", SCI_HOME, false, false, false, 0, 0},
{"SCI_HOMEEXTEND", SCI_HOMEEXTEND, false, false, false, 0, 0},
{"SCI_HOMERECTEXTEND", SCI_HOMERECTEXTEND, false, false, false, 0, 0},
{"SCI_HOMEDISPLAY", SCI_HOMEDISPLAY, false, true, false, VK_HOME, 0},
{"SCI_HOMEDISPLAYEXTEND", SCI_HOMEDISPLAYEXTEND, false, false, false, 0, 0},
{"SCI_HOMEWRAP", SCI_HOMEWRAP, false, false, false, 0, 0},
{"SCI_HOMEWRAPEXTEND", SCI_HOMEWRAPEXTEND, false, false, false, 0, 0},
{"SCI_VCHOME", SCI_VCHOME, false, false, false, VK_HOME, 0},
{"SCI_VCHOMEEXTEND", SCI_VCHOMEEXTEND, false, false, true, VK_HOME, 0},
{"SCI_VCHOMERECTEXTEND", SCI_VCHOMERECTEXTEND, false, true, true, VK_HOME, 0},
{"SCI_VCHOMEWRAP", SCI_VCHOMEWRAP, false, false, false, 0, 0},
{"SCI_VCHOMEWRAPEXTEND", SCI_VCHOMEWRAPEXTEND, false, false, false, 0, 0},
{"SCI_LINEEND", SCI_LINEEND, false, false, false, VK_END, 0},
{"SCI_LINEENDEXTEND", SCI_LINEENDEXTEND, false, false, true, VK_END, 0},
{"SCI_LINEENDRECTEXTEND", SCI_LINEENDRECTEXTEND, false, true, true, VK_END, 0},
{"SCI_LINEENDDISPLAY", SCI_LINEENDDISPLAY, false, true, false, VK_END, 0},
{"SCI_LINEENDDISPLAYEXTEND", SCI_LINEENDDISPLAYEXTEND, false, false, false, 0, 0},
{"SCI_LINEENDWRAP", SCI_LINEENDWRAP, false, false, false, 0, 0},
{"SCI_LINEENDWRAPEXTEND", SCI_LINEENDWRAPEXTEND, false, false, false, 0, 0},
{"SCI_DOCUMENTSTART", SCI_DOCUMENTSTART, true, false, false, VK_HOME, 0},
{"SCI_DOCUMENTSTARTEXTEND", SCI_DOCUMENTSTARTEXTEND, true, false, true, VK_HOME, 0},
{"SCI_DOCUMENTEND", SCI_DOCUMENTEND, true, false, false, VK_END, 0},
{"SCI_DOCUMENTENDEXTEND", SCI_DOCUMENTENDEXTEND, true, false, true, VK_END, 0},
{"SCI_PAGEUP", SCI_PAGEUP, false, false, false, VK_PRIOR, 0},
{"SCI_PAGEUPEXTEND", SCI_PAGEUPEXTEND, false, false, true, VK_PRIOR, 0},
{"SCI_PAGEUPRECTEXTEND", SCI_PAGEUPRECTEXTEND, false, true, true, VK_PRIOR, 0},
{"SCI_PAGEDOWN", SCI_PAGEDOWN, false, false, false, VK_NEXT, 0},
{"SCI_PAGEDOWNEXTEND", SCI_PAGEDOWNEXTEND, false, false, true, VK_NEXT, 0},
{"SCI_PAGEDOWNRECTEXTEND", SCI_PAGEDOWNRECTEXTEND, false, true, true, VK_NEXT, 0},
{"SCI_STUTTEREDPAGEUP", SCI_STUTTEREDPAGEUP, false, false, false, 0, 0},
{"SCI_STUTTEREDPAGEUPEXTEND", SCI_STUTTEREDPAGEUPEXTEND, false, false, false, 0, 0},
{"SCI_STUTTEREDPAGEDOWN", SCI_STUTTEREDPAGEDOWN, false, false, false, 0, 0},
{"SCI_STUTTEREDPAGEDOWNEXTEND", SCI_STUTTEREDPAGEDOWNEXTEND,false, false, false, 0, 0},
{"SCI_DELETEBACK", SCI_DELETEBACK, false, false, false, VK_BACK, 0},
{"SCI_DELETEBACKNOTLINE", SCI_DELETEBACKNOTLINE, false, false, false, 0, 0},
{"SCI_DELWORDLEFT", SCI_DELWORDLEFT, true, false, false, VK_BACK, 0},
{"SCI_DELWORDRIGHT", SCI_DELWORDRIGHT, true, false, false, VK_DELETE, 0},
{"SCI_DELLINELEFT", SCI_DELLINELEFT, true, false, true, VK_BACK, 0},
{"SCI_DELLINERIGHT", SCI_DELLINERIGHT, true, false, true, VK_DELETE, 0},
{"SCI_LINEDELETE", SCI_LINEDELETE, true, false, true, VK_L, 0},
{"SCI_LINECUT", SCI_LINECUT, true, false, false, VK_L, 0},
{"SCI_LINECOPY", SCI_LINECOPY, true, false, true, VK_T, 0},
{"SCI_LINETRANSPOSE", SCI_LINETRANSPOSE, true, false, false, VK_T, 0},
{"SCI_LINEDUPLICATE", SCI_LINEDUPLICATE, false, false, false, 0, 0},
{"SCI_CANCEL", SCI_CANCEL, false, false, false, VK_ESCAPE, 0}
//{"SCI_EMPTYUNDOBUFFER", SCI_EMPTYUNDOBUFFER, false, false, false, 0, 0},
//{"SCI_TOGGLECARETSTICKY", SCI_TOGGLECARETSTICKY, false, false, false, 0, 0},
//{"SCI_CALLTIPCANCEL", SCI_CALLTIPCANCEL, false, false, false, 0, 0},
//{"SCI_SETSAVEPOINT", SCI_SETSAVEPOINT, false, false, false, 0, 0},
//{"SCI_CLEARDOCUMENTSTYLE", SCI_CLEARDOCUMENTSTYLE, false, false, false, 0, 0},
//{"SCI_CUT", SCI_CUT, false, false, true, VK_DELETE, 0},
//{"SCI_COPY", SCI_COPY, true, false, false, VK_INSERT, 0},
//{"SCI_PASTE", SCI_PASTE, false, false, true, VK_INSERT, 0},
//{"SCI_CHOOSECARETX", SCI_CHOOSECARETX, false, false, false, 0, 0},
//{"SCI_AUTOCCOMPLETE", SCI_AUTOCCOMPLETE, false, false, false, 0, 0},
//{"SCI_AUTOCCANCEL", SCI_AUTOCCANCEL, false, false, false, 0, 0},
//{"SCI_CLEARREGISTEREDIMAGES", SCI_CLEARREGISTEREDIMAGES, false, false, false, 0, 0},
//{"SCI_HOMEDISPLAYEXTEND", SCI_HOMEDISPLAYEXTEND, false, true, true, VK_HOME, 0},
//{SCI_LINEENDDISPLAYEXTEND, SCI_LINEENDDISPLAYEXTEND, false, true, true, VK_END, 0},
//{"SCI_DELETEBACK", SCI_DELETEBACK, false, false, true, VK_BACK, 0},
//{"SCI_DELWORDRIGHTEND", SCI_DELWORDRIGHTEND, false, false, false, 0, 0},
//{"SCI_LOWERCASE", SCI_LOWERCASE, false, false, false, 0, 0},
//{"SCI_UPPERCASE", SCI_UPPERCASE, false, false, false, 0, 0},
//{"SCI_LOWERCASE", SCI_LOWERCASE, true, false, false, VK_U, 0},
//{"SCI_UPPERCASE", SCI_UPPERCASE, true, false, true, VK_U, 0},
//{"SCI_NEWLINE", SCI_NEWLINE, false, false, true, VK_RETURN, 0},
//{"SCI_FORMFEED", SCI_FORMFEED, true, false, false, VK_L, 0},
//{"SCI_CLEARALLCMDKEYS", SCI_CLEARALLCMDKEYS, false, false, false, 0, 0},
//{"SCI_STARTRECORD", SCI_STARTRECORD, false, false, false, 0, 0},
//{"SCI_STOPRECORD", SCI_STOPRECORD, false, false, false, 0, 0},
//{"SCI_SEARCHANCHOR", SCI_SEARCHANCHOR, false, false, false, 0, 0},
//{"SCI_TARGETFROMSELECTION", SCI_TARGETFROMSELECTION, false, false, false, 0, 0},
//{"SCI_STYLERESETDEFAULT", SCI_STYLERESETDEFAULT, false, false, false, 0, 0},
//{"SCI_STYLECLEARALL", SCI_STYLECLEARALL, false, false, false, 0, 0},
//{"SCI_UNDO", SCI_UNDO, false, true, false, VK_BACK, 0}
};
NppParameters * NppParameters::_pSelf = new NppParameters; NppParameters * NppParameters::_pSelf = new NppParameters;
@ -45,6 +331,10 @@ NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserSty
PathAppend(notepadStylePath, notepadStyleFile); PathAppend(notepadStylePath, notepadStyleFile);
_asNotepadStyle = (PathFileExists(notepadStylePath) == TRUE); _asNotepadStyle = (PathFileExists(notepadStylePath) == TRUE);
//Load initial accelerator key definitions
initMenuKeys();
initScintillaKeys();
} }
void cutString(const char *str2cut, vector<string> & patternVect) void cutString(const char *str2cut, vector<string> & patternVect)
@ -316,14 +606,10 @@ bool NppParameters::load(/*bool noUserPath*/)
getShortcutsFromXmlTree(); getShortcutsFromXmlTree();
getMacrosFromXmlTree(); getMacrosFromXmlTree();
getUserCmdsFromXmlTree(); getUserCmdsFromXmlTree();
getPluginCmdsFromXmlTree();
// fill out _scintillaModifiedKeys : // fill out _scintillaModifiedKeys :
// those user defined Scintilla key will be used remap Scintilla Key Array // those user defined Scintilla key will be used remap Scintilla Key Array
getScintKeysFromXmlTree(); getScintKeysFromXmlTree();
// initialize entire Scintilla Key Array
initScintillaKeys();
} }
//---------------------------------// //---------------------------------//
@ -570,31 +856,29 @@ bool NppParameters::getScintKeysFromXmlTree()
return true; return true;
} }
void NppParameters::initScintillaKeys() void NppParameters::initMenuKeys()
{ {
// Cut/Copy/Paste int nrCommands = sizeof(winKeyDefs)/sizeof(WinMenuKeyDefinition);
_scintillaKeyCommands.push_back(ScintillaKeyMap("CUT", IDSCINTILLA_KEY_CUT, SCI_CUT, true, false, false, 0x58/*VK_X*/, IDM_EDIT_CUT)); WinMenuKeyDefinition wkd;
_scintillaKeyCommands.push_back(ScintillaKeyMap("COPY", IDSCINTILLA_KEY_COPY, SCI_COPY, true, false, false, 0x43/*VK_C*/, IDM_EDIT_COPY)); for(int i = 0; i < nrCommands; i++)
_scintillaKeyCommands.push_back(ScintillaKeyMap("PASTE", IDSCINTILLA_KEY_PASTE, SCI_PASTE, true, false, false, 0x56/*VK_V*/, IDM_EDIT_PASTE)); {
_scintillaKeyCommands.push_back(ScintillaKeyMap("DEL", IDSCINTILLA_KEY_DEL, SCI_CLEAR, false, false, false, VK_DELETE, IDM_EDIT_DELETE)); wkd = winKeyDefs[i];
_scintillaKeyCommands.push_back(ScintillaKeyMap("SELECT ALL", IDSCINTILLA_KEY_SELECTALL, SCI_SELECTALL, true, false, false, 0x41/*VK_A*/, IDM_EDIT_SELECTALL)); Shortcut sc( (wkd.specialName?wkd.specialName:""), wkd.isCtrl, wkd.isAlt, wkd.isShift, wkd.vKey);
_scintillaKeyCommands.push_back(ScintillaKeyMap("OUTDENT", IDSCINTILLA_KEY_OUTDENT, SCI_BACKTAB, false, false, true, VK_TAB, IDM_EDIT_RMV_TAB)); _shortcuts.push_back( CommandShortcut(sc, wkd.functionId) );
_scintillaKeyCommands.push_back(ScintillaKeyMap("UNDO", IDSCINTILLA_KEY_UNDO, SCI_UNDO, true, false, false, 0x5A/*VK_Z*/, IDM_EDIT_UNDO)); }
_scintillaKeyCommands.push_back(ScintillaKeyMap("REDO", IDSCINTILLA_KEY_REDO, SCI_REDO, true, false, false, 0x59/*VK_Y*/, IDM_EDIT_REDO)); }
void NppParameters::initScintillaKeys() {
int nrCommands = sizeof(scintKeyDefs)/sizeof(ScintillaKeyDefinition);
ScintillaKeyDefinition skd;
for(int i = 0; i < nrCommands; i++) {
skd = scintKeyDefs[i];
_scintillaKeyCommands.push_back(ScintillaKeyMap(Shortcut(skd.name, skd.isCtrl, skd.isAlt, skd.isShift, skd.vKey), skd.functionId, skd.redirFunctionId));
}
// Line operation
_scintillaKeyCommands.push_back(ScintillaKeyMap("DUPLICATE LINE", IDSCINTILLA_KEY_LINE_DUP, SCI_LINEDUPLICATE, true, false, false, 0x44/*VK_D*/, IDM_EDIT_DUP_LINE));
_scintillaKeyCommands.push_back(ScintillaKeyMap("CUT LINE", IDSCINTILLA_KEY_LINE_CUT, SCI_LINECUT, true, false, false, 0x4C/*VK_L*/));
_scintillaKeyCommands.push_back(ScintillaKeyMap("DELETE LINE", IDSCINTILLA_KEY_LINE_DEL, SCI_LINEDELETE, true, false, true, 0x4C/*VK_L*/));
_scintillaKeyCommands.push_back(ScintillaKeyMap("TRANSPOSE LINE", IDSCINTILLA_KEY_LINE_TRANS, SCI_LINETRANSPOSE, true, false, false, 0x54/*VK_T*/));
_scintillaKeyCommands.push_back(ScintillaKeyMap("COPY LINE", IDSCINTILLA_KEY_LINE_COPY, SCI_LINECOPY, true, false, true, 0x54/*VK_T*/));
//SCI_DELETEBACK
//SCI_DELETEBACKNOTLINE
//SCI_DELWORDLEFT
//SCI_DELWORDRIGHT
//SCI_DELLINELEFT
//SCI_DELLINERIGHT
} }
bool NppParameters::getContextMenuFromXmlTree() bool NppParameters::getContextMenuFromXmlTree()
@ -799,9 +1083,20 @@ void NppParameters::feedShortcut(TiXmlNode *node)
if (idStr) if (idStr)
{ {
Shortcut sc; Shortcut sc;
if (getShortcuts(childNode, sc) && sc.isValid()) if (getShortcuts(childNode, sc))// && sc.isValid()) //do not validate
{ {
_shortcuts.push_back(CommandShortcut(id, sc)); //find the commandid that matches this Shortcut sc and alter it, push back its index in the modified list, if not present
int len = (int)_shortcuts.size();
for(int i = 0; i < len; i++)
{
if (_shortcuts[i].getID() == id)
{ //found our match
CommandShortcut csc = CommandShortcut(sc, id);
strncpy(csc._name, _shortcuts[i]._name, nameLenMax);
_shortcuts[i] = csc;
addUserModifiedIndex(i);
}
}
} }
} }
} }
@ -817,18 +1112,20 @@ void NppParameters::feedMacros(TiXmlNode *node)
childNode = childNode->NextSibling("Macro") ) childNode = childNode->NextSibling("Macro") )
{ {
Shortcut sc; Shortcut sc;
if (getShortcuts(childNode, sc) && sc.isValid()) if (getShortcuts(childNode, sc))// && sc.isValid())
{ {
MacroShortcut ms(sc); Macro macro;
getActions(childNode, ms); getActions(childNode, macro);
if (ms.isValid()) int cmdID = ID_MACRO + _macros.size();
_macros.push_back(ms); MacroShortcut ms(sc, macro, cmdID);
//if (ms.isValid())
_macros.push_back(ms);
} }
} }
} }
void NppParameters::getActions(TiXmlNode *node, MacroShortcut & macroShortcut) void NppParameters::getActions(TiXmlNode *node, Macro & macro)
{ {
for (TiXmlNode *childNode = node->FirstChildElement("Action"); for (TiXmlNode *childNode = node->FirstChildElement("Action");
childNode ; childNode ;
@ -853,7 +1150,7 @@ void NppParameters::getActions(TiXmlNode *node, MacroShortcut & macroShortcut)
sParam = ""; sParam = "";
recordedMacroStep step(type, msg, wParam, lParam, sParam); recordedMacroStep step(type, msg, wParam, lParam, sParam);
if (step.isValid()) if (step.isValid())
(macroShortcut.getMacro()).push_back(step); macro.push_back(step);
} }
} }
@ -868,18 +1165,18 @@ void NppParameters::feedUserCmds(TiXmlNode *node)
childNode = childNode->NextSibling("Command") ) childNode = childNode->NextSibling("Command") )
{ {
Shortcut sc; Shortcut sc;
if (getShortcuts(childNode, sc) && sc.isValid()) if (getShortcuts(childNode, sc))// && sc.isValid())
{ {
UserCommand uc(sc);
TiXmlNode *aNode = childNode->FirstChild(); TiXmlNode *aNode = childNode->FirstChild();
if (aNode) if (aNode)
{ {
const char *cmdStr = aNode->Value(); const char *cmdStr = aNode->Value();
if (cmdStr) if (cmdStr)
{ {
uc._cmd = cmdStr; int cmdID = ID_USER_CMD + _userCommands.size();
if (uc.isValid()) UserCommand uc(sc, cmdStr, cmdID);
_userCommands.push_back(uc); //if (uc.isValid())
_userCommands.push_back(uc);
} }
} }
} }
@ -896,18 +1193,33 @@ void NppParameters::feedPluginCustomizedCmds(TiXmlNode *node)
childNode = childNode->NextSibling("PluginCommand") ) childNode = childNode->NextSibling("PluginCommand") )
{ {
Shortcut sc; Shortcut sc;
if (getShortcuts(childNode, sc) && sc.isValid()) if (getShortcuts(childNode, sc))// && sc.isValid())
{ {
const char *moduleName = (childNode->ToElement())->Attribute("moduleName"); const char *moduleName = (childNode->ToElement())->Attribute("moduleName");
if (!moduleName) if (!moduleName)
moduleName = ""; continue;
int internalID = -1; int internalID = -1;
const char *internalIDStr = (childNode->ToElement())->Attribute("internalID", &internalID); const char *internalIDStr = (childNode->ToElement())->Attribute("internalID", &internalID);
PluginCmdShortcut pcs(sc, -1, moduleName, internalID); if (!internalIDStr)
if (pcs.isValid()) continue;
_pluginCustomizedCmds.push_back(pcs);
//Find the corresponding plugincommand and alter it, put the index in the list
int len = (int)_pluginCommands.size();
for(int i = 0; i < len; i++)
{
PluginCmdShortcut pscOrig = _pluginCommands[i];
if (!_strnicmp(pscOrig.getModuleName(), moduleName, strlen(moduleName)) && pscOrig.getInternalID() == internalID)
{
//Found matching command
PluginCmdShortcut pcs(sc, _pluginCommands[i].getID(), moduleName, internalID);
strncpy(pcs._name, pscOrig._name, 64);
_pluginCommands[i] = pcs;
addPluginModifiedIndex(i);
break;
}
}
} }
} }
} }
@ -921,14 +1233,33 @@ void NppParameters::feedScintKeys(TiXmlNode *node)
childNode ; childNode ;
childNode = childNode->NextSibling("ScintKey") ) childNode = childNode->NextSibling("ScintKey") )
{ {
int id; Shortcut sc;
const char *idStr = (childNode->ToElement())->Attribute("id", &id); if (getShortcuts(childNode, sc))
if (idStr)
{ {
ScintillaKeyMap skmm(id); int scintKey;
if (getScintKey(childNode, skmm) && skmm.isValid()) const char *keyStr = (childNode->ToElement())->Attribute("ScintID", &scintKey);
if (!keyStr)
continue;
int menuID;
keyStr = (childNode->ToElement())->Attribute("menuCmdID", &menuID);
if (!keyStr)
continue;
//Find the corresponding scintillacommand and alter it, put the index in the list
size_t len = _scintillaKeyCommands.size();
for(size_t i = 0; i < len; i++)
{ {
_scintillaModifiedKeys.push_back(skmm); ScintillaKeyMap skmOrig = _scintillaKeyCommands[i];
if (skmOrig.getScintillaKeyID() == scintKey &&skmOrig.getMenuCmdID() == menuID)
{
//Found matching command
ScintillaKeyMap skm(sc, scintKey, menuID);
strncpy(skm._name, skmOrig._name, 64);
_scintillaKeyCommands[i] = skm;
addScintillaModifiedIndex(i);
break;
}
} }
} }
} }
@ -962,7 +1293,7 @@ bool NppParameters::getShortcuts(TiXmlNode *node, Shortcut & sc)
if (!keyStr) if (!keyStr)
return false; return false;
strcpy(sc._name, name); strncpy(sc._name, name, 64);
sc._isCtrl = isCtrl; sc._isCtrl = isCtrl;
sc._isAlt = isAlt; sc._isAlt = isAlt;
sc._isShift = isShift; sc._isShift = isShift;
@ -970,25 +1301,6 @@ bool NppParameters::getShortcuts(TiXmlNode *node, Shortcut & sc)
return true; return true;
} }
bool NppParameters::getScintKey(TiXmlNode *node, ScintillaKeyMap & skm)
{
if (getShortcuts(node, skm))
{
int scintKey;
const char *keyStr = (node->ToElement())->Attribute("ScintID", &scintKey);
if (!keyStr)
return false;
int menuID;
keyStr = (node->ToElement())->Attribute("menuCmdID", &menuID);
if (!keyStr)
return false;
skm.setScintKey(scintKey);
skm.setMenuID(menuID);
return true;
}
return false;
}
const int loadFailed = 100; const int loadFailed = 100;
const int missingName = 101; const int missingName = 101;
@ -1057,7 +1369,6 @@ void NppParameters::writeUserDefinedLang()
void NppParameters::insertCmd(TiXmlNode *shortcutsRoot, const CommandShortcut & cmd) void NppParameters::insertCmd(TiXmlNode *shortcutsRoot, const CommandShortcut & cmd)
{ {
TiXmlNode *sc = shortcutsRoot->InsertEndChild(TiXmlElement("Shortcut")); TiXmlNode *sc = shortcutsRoot->InsertEndChild(TiXmlElement("Shortcut"));
sc->ToElement()->SetAttribute("name", cmd._name);
sc->ToElement()->SetAttribute("id", cmd.getID()); sc->ToElement()->SetAttribute("id", cmd.getID());
sc->ToElement()->SetAttribute("Ctrl", cmd._isCtrl?"yes":"no"); sc->ToElement()->SetAttribute("Ctrl", cmd._isCtrl?"yes":"no");
sc->ToElement()->SetAttribute("Alt", cmd._isAlt?"yes":"no"); sc->ToElement()->SetAttribute("Alt", cmd._isAlt?"yes":"no");
@ -1112,14 +1423,12 @@ void NppParameters::insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMa
{ {
TiXmlNode *keyRoot = scintKeyRoot->InsertEndChild(TiXmlElement("ScintKey")); TiXmlNode *keyRoot = scintKeyRoot->InsertEndChild(TiXmlElement("ScintKey"));
keyRoot->ToElement()->SetAttribute("name", scintKeyMap._name); keyRoot->ToElement()->SetAttribute("ScintID", scintKeyMap.getScintillaKeyID());
keyRoot->ToElement()->SetAttribute("id", scintKeyMap.getID()); keyRoot->ToElement()->SetAttribute("menuCmdID", scintKeyMap.getMenuCmdID());
keyRoot->ToElement()->SetAttribute("Ctrl", scintKeyMap._isCtrl?"yes":"no"); keyRoot->ToElement()->SetAttribute("Ctrl", scintKeyMap._isCtrl?"yes":"no");
keyRoot->ToElement()->SetAttribute("Alt", scintKeyMap._isAlt?"yes":"no"); keyRoot->ToElement()->SetAttribute("Alt", scintKeyMap._isAlt?"yes":"no");
keyRoot->ToElement()->SetAttribute("Shift", scintKeyMap._isShift?"yes":"no"); keyRoot->ToElement()->SetAttribute("Shift", scintKeyMap._isShift?"yes":"no");
keyRoot->ToElement()->SetAttribute("Key", scintKeyMap._key); keyRoot->ToElement()->SetAttribute("Key", scintKeyMap._key);
keyRoot->ToElement()->SetAttribute("ScintID", scintKeyMap.getScintillaKey());
keyRoot->ToElement()->SetAttribute("menuCmdID", scintKeyMap.getMenuCmdID());
} }
void NppParameters::writeSession(const Session & session, const char *fileName) void NppParameters::writeSession(const Session & session, const char *fileName)
@ -1182,7 +1491,7 @@ void NppParameters::writeSession(const Session & session, const char *fileName)
} }
void NppParameters::writeShortcuts(bool rewriteCmdSc, bool rewriteMacrosSc, bool rewriteUserCmdSc, bool rewriteScintillaKey, bool rewritePluginCmdSc) void NppParameters::writeShortcuts()
{ {
if (!_pXmlShortcutDoc) if (!_pXmlShortcutDoc)
{ {
@ -1197,75 +1506,60 @@ void NppParameters::writeShortcuts(bool rewriteCmdSc, bool rewriteMacrosSc, bool
//root = _pXmlShortcutDoc->FirstChild("NotepadPlus"); //root = _pXmlShortcutDoc->FirstChild("NotepadPlus");
} }
if (rewriteCmdSc) TiXmlNode *cmdRoot = root->FirstChild("InternalCommands");
if (cmdRoot)
root->RemoveChild(cmdRoot);
cmdRoot = root->InsertEndChild(TiXmlElement("InternalCommands"));
for (size_t i = 0 ; i < _customizedShortcuts.size() ; i++)
{ {
TiXmlNode *cmdRoot = root->FirstChild("InternalCommands"); int index = _customizedShortcuts[i];
if (cmdRoot) CommandShortcut csc = _shortcuts[index];
root->RemoveChild(cmdRoot); insertCmd(cmdRoot, csc);
cmdRoot = root->InsertEndChild(TiXmlElement("InternalCommands"));
for (size_t i = 0 ; i < _shortcuts.size() ; i++)
{
insertCmd(cmdRoot, _shortcuts[i]);
}
} }
if (rewriteMacrosSc) TiXmlNode *macrosRoot = root->FirstChild("Macros");
{ if (macrosRoot)
TiXmlNode *macrosRoot = root->FirstChild("Macros"); root->RemoveChild(macrosRoot);
if (macrosRoot)
root->RemoveChild(macrosRoot);
macrosRoot = root->InsertEndChild(TiXmlElement("Macros")); macrosRoot = root->InsertEndChild(TiXmlElement("Macros"));
for (size_t i = 0 ; i < _macros.size() ; i++) for (size_t i = 0 ; i < _macros.size() ; i++)
{ {
insertMacro(macrosRoot, _macros[i]); insertMacro(macrosRoot, _macros[i]);
}
} }
if (rewriteUserCmdSc) TiXmlNode *userCmdRoot = root->FirstChild("UserDefinedCommands");
if (userCmdRoot)
root->RemoveChild(userCmdRoot);
userCmdRoot = root->InsertEndChild(TiXmlElement("UserDefinedCommands"));
for (size_t i = 0 ; i < _userCommands.size() ; i++)
{ {
TiXmlNode *userCmdRoot = root->FirstChild("UserDefinedCommands"); insertUserCmd(userCmdRoot, _userCommands[i]);
if (userCmdRoot)
root->RemoveChild(userCmdRoot);
userCmdRoot = root->InsertEndChild(TiXmlElement("UserDefinedCommands"));
for (size_t i = 0 ; i < _userCommands.size() ; i++)
{
insertUserCmd(userCmdRoot, _userCommands[i]);
}
} }
if (rewriteScintillaKey) TiXmlNode *pluginCmdRoot = root->FirstChild("PluginCommands");
{ if (pluginCmdRoot)
TiXmlNode *scitillaKeyRoot = root->FirstChild("ScintillaKeys"); root->RemoveChild(pluginCmdRoot);
if (scitillaKeyRoot)
root->RemoveChild(scitillaKeyRoot);
scitillaKeyRoot = root->InsertEndChild(TiXmlElement("ScintillaKeys")); pluginCmdRoot = root->InsertEndChild(TiXmlElement("PluginCommands"));
for (size_t i = 0 ; i < _scintillaModifiedKeys.size() ; i++) for (size_t i = 0 ; i < _pluginCustomizedCmds.size() ; i++)
{ {
insertScintKey(scitillaKeyRoot, _scintillaModifiedKeys[i]); insertPluginCmd(pluginCmdRoot, _pluginCommands[_pluginCustomizedCmds[i]]);
}
} }
if (rewritePluginCmdSc) TiXmlNode *scitillaKeyRoot = root->FirstChild("ScintillaKeys");
{ if (scitillaKeyRoot)
TiXmlNode *pluginCmdRoot = root->FirstChild("PluginCommands"); root->RemoveChild(scitillaKeyRoot);
if (pluginCmdRoot)
root->RemoveChild(pluginCmdRoot);
pluginCmdRoot = root->InsertEndChild(TiXmlElement("PluginCommands")); scitillaKeyRoot = root->InsertEndChild(TiXmlElement("ScintillaKeys"));
for (size_t i = 0 ; i < _pluginCustomizedCmds.size() ; i++) for (size_t i = 0 ; i < _scintillaModifiedKeyIndices.size() ; i++)
{ {
insertPluginCmd(pluginCmdRoot, _pluginCustomizedCmds[i]); insertScintKey(scitillaKeyRoot, _scintillaKeyCommands[_scintillaModifiedKeyIndices[i]]);
}
} }
if (rewriteCmdSc || rewriteMacrosSc || rewriteUserCmdSc || rewriteScintillaKey || rewritePluginCmdSc) _pXmlShortcutDoc->SaveFile();
_pXmlShortcutDoc->SaveFile();
} }
int NppParameters::addUserLangToEnd(const UserLangContainer & userLang, const char *newName) int NppParameters::addUserLangToEnd(const UserLangContainer & userLang, const char *newName)
@ -3546,3 +3840,57 @@ void NppParameters::stylerStrOp(bool op)
} }
} }
void NppParameters::addUserModifiedIndex(int index)
{
size_t len = _customizedShortcuts.size();
bool found = false;
for(size_t i = 0; i < len; i++)
{
if (_customizedShortcuts[i] == index)
{
found = true;
break;
}
}
if (!found)
{
_customizedShortcuts.push_back(index);
}
}
void NppParameters::addPluginModifiedIndex(int index)
{
size_t len = _pluginCustomizedCmds.size();
bool found = false;
for(size_t i = 0; i < len; i++)
{
if (_pluginCustomizedCmds[i] == index)
{
found = true;
break;
}
}
if (!found)
{
_pluginCustomizedCmds.push_back(index);
}
}
void NppParameters::addScintillaModifiedIndex(int index)
{
size_t len = _scintillaModifiedKeyIndices.size();
bool found = false;
for(size_t i = 0; i < len; i++)
{
if (_scintillaModifiedKeyIndices[i] == index)
{
found = true;
break;
}
}
if (!found)
{
_scintillaModifiedKeyIndices.push_back(index);
}
}

View File

@ -899,7 +899,7 @@ public:
vector<TiXmlDocument *> * getExternalLexerDoc() { return &_pXmlExternalLexerDoc;}; vector<TiXmlDocument *> * getExternalLexerDoc() { return &_pXmlExternalLexerDoc;};
void writeUserDefinedLang(); void writeUserDefinedLang();
void writeShortcuts(bool rewriteCmdSc, bool rewriteMacrosSc, bool rewriteUserCmdSc, bool rewriteScintillaKey, bool rewritePluginCmdSc); void writeShortcuts();
void writeSession(const Session & session, const char *fileName = NULL); void writeSession(const Session & session, const char *fileName = NULL);
@ -977,15 +977,18 @@ public:
bool isRemappingShortcut() const {return _shortcuts.size() != 0;}; bool isRemappingShortcut() const {return _shortcuts.size() != 0;};
vector<CommandShortcut> & getUserShortcuts() {return _shortcuts;}; vector<CommandShortcut> & getUserShortcuts() {return _shortcuts;};
vector<int> & getUserModifiedShortcuts() {return _customizedShortcuts;};
void addUserModifiedIndex(int index);
vector<MacroShortcut> & getMacroList() {return _macros;}; vector<MacroShortcut> & getMacroList() {return _macros;};
vector<UserCommand> & getUserCommandList() {return _userCommands;}; vector<UserCommand> & getUserCommandList() {return _userCommands;};
vector<PluginCmdShortcut> & getPluginCommandList() {return _pluginCommands;}; vector<PluginCmdShortcut> & getPluginCommandList() {return _pluginCommands;};
vector<PluginCmdShortcut> & getPluginCustomizedCmds() {return _pluginCustomizedCmds;}; vector<int> & getPluginModifiedKeyIndices() {return _pluginCustomizedCmds;};
void addPluginModifiedIndex(int index);
vector<ScintillaKeyMap> & getScintillaKeyList() {return _scintillaKeyCommands;}; vector<ScintillaKeyMap> & getScintillaKeyList() {return _scintillaKeyCommands;};
vector<ScintillaKeyMap> & getScintillaModifiedKeys() {return _scintillaModifiedKeys;}; vector<int> & getScintillaModifiedKeyIndices() {return _scintillaModifiedKeyIndices;};
void addScintillaModifiedIndex(int index);
//vector<string> & getNoMenuCmdNames() {return _noMenuCmdNames;};
vector<MenuItemUnit> & getContextMenuItems() {return _contextMenuItems;}; vector<MenuItemUnit> & getContextMenuItems() {return _contextMenuItems;};
const Session & getSession() const {return _session;}; const Session & getSession() const {return _session;};
@ -993,6 +996,9 @@ public:
void setAccelerator(Accelerator *pAccel) {_pAccelerator = pAccel;}; void setAccelerator(Accelerator *pAccel) {_pAccelerator = pAccel;};
Accelerator * getAccelerator() {return _pAccelerator;}; Accelerator * getAccelerator() {return _pAccelerator;};
void setScintillaAccelerator(ScintillaAccelerator *pScintAccel) {_pScintAccelerator = pScintAccel;};
ScintillaAccelerator * getScintillaAccelerator() {return _pScintAccelerator;};
const char * getNppPath() const {return _nppPath;}; const char * getNppPath() const {return _nppPath;};
const char * getAppDataNppDir() const {return _appdataNppDir;}; const char * getAppDataNppDir() const {return _appdataNppDir;};
@ -1047,6 +1053,9 @@ public:
}; };
bool asNotepadStyle() const {return _asNotepadStyle;}; bool asNotepadStyle() const {return _asNotepadStyle;};
bool reloadPluginCmds() {
return getPluginCmdsFromXmlTree();
}
private: private:
NppParameters(); NppParameters();
~NppParameters() { ~NppParameters() {
@ -1101,14 +1110,16 @@ private:
WNDPROC _enableThemeDialogTextureFuncAddr; WNDPROC _enableThemeDialogTextureFuncAddr;
vector<CommandShortcut> _shortcuts; vector<CommandShortcut> _shortcuts; //main menu shortuts. Static size
vector<MacroShortcut> _macros; vector<int> _customizedShortcuts; //altered main menu shortcuts. Indices static. Needed when saving alterations
vector<UserCommand> _userCommands; vector<MacroShortcut> _macros; //macro shortcuts, dynamic size, defined on loading macros and adding/deleting them
vector<PluginCmdShortcut> _pluginCommands; vector<UserCommand> _userCommands; //run shortcuts, dynamic size, defined on loading run commands and adding/deleting them
vector<PluginCmdShortcut> _pluginCustomizedCmds; vector<PluginCmdShortcut> _pluginCommands; //plugin commands, dynamic size, defined on loading plugins
vector<int> _pluginCustomizedCmds; //plugincommands that have been altered. Indices determined after loading ALL plugins. Needed when saving alterations
vector<ScintillaKeyMap> _scintillaKeyCommands; //scintilla keycommands. Static size
vector<int> _scintillaModifiedKeyIndices; //modified scintilla keys. Indices static, determined by searching for commandId. Needed when saving alterations
vector<ScintillaKeyMap> _scintillaKeyCommands;
vector<ScintillaKeyMap> _scintillaModifiedKeys;
//vector<string> _noMenuCmdNames; //vector<string> _noMenuCmdNames;
vector<MenuItemUnit> _contextMenuItems; vector<MenuItemUnit> _contextMenuItems;
@ -1121,6 +1132,7 @@ private:
char _appdataNppDir[MAX_PATH]; // sentinel of the absence of "doLocalConf.xml" : (_appdataNppDir == "")?"doLocalConf.xml present":"doLocalConf.xml absent" char _appdataNppDir[MAX_PATH]; // sentinel of the absence of "doLocalConf.xml" : (_appdataNppDir == "")?"doLocalConf.xml present":"doLocalConf.xml absent"
Accelerator *_pAccelerator; Accelerator *_pAccelerator;
ScintillaAccelerator * _pScintAccelerator;
FindDlgTabTitiles _findDlgTabTitiles; FindDlgTabTitiles _findDlgTabTitiles;
bool _asNotepadStyle; bool _asNotepadStyle;
@ -1144,7 +1156,6 @@ private:
bool getUserStylersFromXmlTree(); bool getUserStylersFromXmlTree();
bool getUserDefineLangsFromXmlTree(); bool getUserDefineLangsFromXmlTree();
bool getShortcutsFromXmlTree(); bool getShortcutsFromXmlTree();
void initScintillaKeys();
bool getMacrosFromXmlTree(); bool getMacrosFromXmlTree();
bool getUserCmdsFromXmlTree(); bool getUserCmdsFromXmlTree();
@ -1174,9 +1185,8 @@ private:
void feedPluginCustomizedCmds(TiXmlNode *node); void feedPluginCustomizedCmds(TiXmlNode *node);
void feedScintKeys(TiXmlNode *node); void feedScintKeys(TiXmlNode *node);
void getActions(TiXmlNode *node, MacroShortcut & macroShortcut); void getActions(TiXmlNode *node, Macro & macro);
bool getShortcuts(TiXmlNode *node, Shortcut & sc); bool getShortcuts(TiXmlNode *node, Shortcut & sc);
bool getScintKey(TiXmlNode *node, ScintillaKeyMap & skm);
void writeStyle2Element(Style & style2Wite, Style & style2Sync, TiXmlElement *element); void writeStyle2Element(Style & style2Wite, Style & style2Sync, TiXmlElement *element);
void insertUserLang2Tree(TiXmlNode *node, UserLangContainer *userLang); void insertUserLang2Tree(TiXmlNode *node, UserLangContainer *userLang);
@ -1190,6 +1200,8 @@ private:
void insertDockingParamNode(TiXmlNode *GUIRoot); void insertDockingParamNode(TiXmlNode *GUIRoot);
void writeExcludedLangList(TiXmlElement *element); void writeExcludedLangList(TiXmlElement *element);
void writePrintSetting(TiXmlElement *element); void writePrintSetting(TiXmlElement *element);
void initMenuKeys(); //initialise menu keys and scintilla keys. Other keys are initialized on their own
void initScintillaKeys(); //these functions have to be called first before any modifications are loaded
}; };
#endif //PARAMETERS_H #endif //PARAMETERS_H

View File

@ -79,7 +79,7 @@ const bool fold_collapse = false;
const bool UPPERCASE = true; const bool UPPERCASE = true;
const bool LOWERCASE = false; const bool LOWERCASE = false;
typedef vector<pair<int, int>> ColumnModeInfo; typedef vector<pair<int, int> > ColumnModeInfo;
const unsigned char MASK_FORMAT = 0x03; const unsigned char MASK_FORMAT = 0x03;
const unsigned char MASK_ZERO_LEADING = 0x04; const unsigned char MASK_ZERO_LEADING = 0x04;
const unsigned char BASE_10 = 0x00; // Dec const unsigned char BASE_10 = 0x00; // Dec

View File

@ -20,12 +20,35 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "ShortcutMapper.h" #include "ShortcutMapper.h"
#include "Notepad_plus.h" #include "Notepad_plus.h"
void ShortcutMapper::initTabs() {
HWND hTab = _hTabCtrl = ::GetDlgItem(_hSelf, IDC_BABYGRID_TABBAR);
TCITEM tie;
tie.mask = TCIF_TEXT;
tie.pszText = tabNames[0];
::SendMessage(hTab, TCM_INSERTITEM, 0, (LPARAM)(&tie) );
tie.pszText = tabNames[1];
::SendMessage(hTab, TCM_INSERTITEM, 1, (LPARAM)(&tie) );
tie.pszText = tabNames[2];
::SendMessage(hTab, TCM_INSERTITEM, 2, (LPARAM)(&tie) );
tie.pszText = tabNames[3];
::SendMessage(hTab, TCM_INSERTITEM, 3, (LPARAM)(&tie) );
tie.pszText = tabNames[4];
::SendMessage(hTab, TCM_INSERTITEM, 4, (LPARAM)(&tie) );
}
void ShortcutMapper::translateTab(int index, const char * newname) {
if (index < 0 || index > 4)
return;
strncpy(tabNames[index], newname, maxTabName);
}
void ShortcutMapper::initBabyGrid() { void ShortcutMapper::initBabyGrid() {
RECT rect; RECT rect;
getClientRect(rect); getClientRect(rect);
_babygrid.init(_hInst, _hSelf, IDD_BABYGRID_ID1); _babygrid.init(_hInst, _hSelf, IDD_BABYGRID_ID1);
_babygrid.reSizeTo(rect); //_babygrid.reSizeTo(rect);
_babygrid.reSizeToWH(rect);
_babygrid.hideCursor(); _babygrid.hideCursor();
_babygrid.makeColAutoWidth(); _babygrid.makeColAutoWidth();
_babygrid.setColsNumbered(false); _babygrid.setColsNumbered(false);
@ -36,34 +59,72 @@ void ShortcutMapper::initBabyGrid() {
void ShortcutMapper::fillOutBabyGrid() void ShortcutMapper::fillOutBabyGrid()
{ {
NppParameters *nppParam = NppParameters::getInstance(); NppParameters *nppParam = NppParameters::getInstance();
vector<ScintillaKeyMap> &skms = nppParam->getScintillaKeyList(); _babygrid.clear();
int nbScitillaMsg = skms.size();
_pAccel = nppParam->getAccelerator(); size_t nrItems = 0;
_babygrid.setLineColNumber(_pAccel->_nbAccelItems + nbScitillaMsg, 2);
switch(_currentState) {
case STATE_MENU: {
nrItems = nppParam->getUserShortcuts().size();
_babygrid.setLineColNumber(nrItems, 2);
break; }
case STATE_MACRO: {
nrItems = nppParam->getMacroList().size();
_babygrid.setLineColNumber(nrItems, 2);
break; }
case STATE_USER: {
nrItems = nppParam->getUserCommandList().size();
_babygrid.setLineColNumber(nrItems, 2);
break; }
case STATE_PLUGIN: {
nrItems = nppParam->getPluginCommandList().size();
_babygrid.setLineColNumber(nrItems, 2);
break; }
case STATE_SCINTILLA: {
nrItems = nppParam->getScintillaKeyList().size();
_babygrid.setLineColNumber(nrItems, 2);
break; }
}
_babygrid.setText(0, 1, "Name"); _babygrid.setText(0, 1, "Name");
_babygrid.setText(0, 2, "Shortcut"); _babygrid.setText(0, 2, "Shortcut");
int i = 0 ; switch(_currentState) {
for ( ; i < _pAccel->_nbAccelItems ; i++) case STATE_MENU: {
{ vector<CommandShortcut> & cshortcuts = nppParam->getUserShortcuts();
unsigned char vFlg = _pAccel->_pAccelArray[i].fVirt; for(size_t i = 0; i < nrItems; i++) {
string shortcut = (vFlg & FCONTROL)?"Ctrl+":""; _babygrid.setText(i+1, 1, cshortcuts[i]._name);
shortcut += (vFlg & FALT)?"Alt+":""; _babygrid.setText(i+1, 2, cshortcuts[i].toString().c_str());
shortcut += (vFlg & FSHIFT)?"Shift+":""; }
string key; break; }
getKeyStrFromVal((unsigned char)_pAccel->_pAccelArray[i].key, key); case STATE_MACRO: {
shortcut += key; vector<MacroShortcut> & cshortcuts = nppParam->getMacroList();
_babygrid.setText(i+1, 2, shortcut.c_str()); for(size_t i = 0; i < nrItems; i++) {
_babygrid.setText(i+1, 1, cshortcuts[i]._name);
string shortcutName; _babygrid.setText(i+1, 2, cshortcuts[i].toString().c_str());
getNameStrFromCmd(_pAccel->_pAccelArray[i].cmd, shortcutName); }
_babygrid.setText(i+1, 1, shortcutName.c_str()); break; }
} case STATE_USER: {
vector<UserCommand> & cshortcuts = nppParam->getUserCommandList();
for (size_t j = 0 ; i < _pAccel->_nbAccelItems + nbScitillaMsg ; i++, j++) for(size_t i = 0; i < nrItems; i++) {
{ _babygrid.setText(i+1, 1, cshortcuts[i]._name);
_babygrid.setText(i+1, 1, skms[j]._name); _babygrid.setText(i+1, 2, cshortcuts[i].toString().c_str());
_babygrid.setText(i+1, 2, skms[j].toString().c_str()); }
break; }
case STATE_PLUGIN: {
vector<PluginCmdShortcut> & cshortcuts = nppParam->getPluginCommandList();
for(size_t i = 0; i < nrItems; i++) {
_babygrid.setText(i+1, 1, cshortcuts[i]._name);
_babygrid.setText(i+1, 2, cshortcuts[i].toString().c_str());
}
break; }
case STATE_SCINTILLA: {
vector<ScintillaKeyMap> & cshortcuts = nppParam->getScintillaKeyList();
for(size_t i = 0; i < nrItems; i++) {
_babygrid.setText(i+1, 1, cshortcuts[i]._name);
_babygrid.setText(i+1, 2, cshortcuts[i].toString().c_str());
}
break; }
} }
} }
@ -73,16 +134,45 @@ BOOL CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
{ {
case WM_INITDIALOG : case WM_INITDIALOG :
{ {
initBabyGrid(); initBabyGrid();
initTabs();
fillOutBabyGrid(); fillOutBabyGrid();
_babygrid.display(); _babygrid.display();
goToCenter(); goToCenter();
return TRUE; return TRUE;
} }
case WM_NOTIFY: {
NMHDR nmh = *((NMHDR*)lParam);
if (nmh.hwndFrom == _hTabCtrl) {
if (nmh.code == TCN_SELCHANGE) {
int index = TabCtrl_GetCurSel(_hTabCtrl);
switch (index) {
case 0:
_currentState = STATE_MENU;
break;
case 1:
_currentState = STATE_MACRO;
break;
case 2:
_currentState = STATE_USER;
break;
case 3:
_currentState = STATE_PLUGIN;
break;
case 4:
_currentState = STATE_SCINTILLA;
break;
}
fillOutBabyGrid();
}
}
break; }
case WM_COMMAND : case WM_COMMAND :
{ {
switch (wParam) switch (LOWORD(wParam))
{ {
case IDCANCEL : case IDCANCEL :
{ {
@ -100,256 +190,201 @@ BOOL CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
NppParameters *nppParam = NppParameters::getInstance(); NppParameters *nppParam = NppParameters::getInstance();
int row = _babygrid.getSelectedRow(); int row = _babygrid.getSelectedRow();
if (row <= _pAccel->_nbAccelItems) switch(_currentState) {
{ case STATE_MENU: {
ACCEL accel = _pAccel->_pAccelArray[row-1]; //Get CommandShortcut corresponding to row
string shortcutName; vector<CommandShortcut> & shortcuts = nppParam->getUserShortcuts();
DWORD cmdID = _pAccel->_pAccelArray[row-1].cmd; CommandShortcut csc = shortcuts[row - 1], prevcsc = shortcuts[row - 1];
ShortcutType st = getNameStrFromCmd(cmdID, shortcutName); csc.init(_hInst, _hSelf);
if (csc.doDialog() != -1 && prevcsc != csc) { //shortcut was altered
Shortcut shortcut(shortcutName.c_str(), (accel.fVirt & FCONTROL) != 0, (accel.fVirt & FALT) != 0, (accel.fVirt & FSHIFT) != 0, (unsigned char)accel.key); nppParam->addUserModifiedIndex(row-1);
shortcut.init(_hInst, _hSelf); shortcuts[row - 1] = csc;
shortcut.setNameReadOnly((st != TYPE_CMD) && (st != TYPE_PLUGINCMD)); _babygrid.setText(row, 2, csc.toString().c_str());
//Notify current Accelerator class to update everything
Shortcut oldSc = shortcut; nppParam->getAccelerator()->updateShortcuts();
//::SendMessage(_hParent, NPPM_INTERNAL_CMDLIST_MODIFIED, (WPARAM)sc.c_str(), cmdID);
if ((shortcut.doDialog() != -1) && (oldSc != shortcut))
{
// Update the key map
_pAccel->_pAccelArray[row-1].fVirt = FVIRTKEY | (shortcut._isCtrl?FCONTROL:0) | (shortcut._isAlt?FALT:0) | (shortcut._isShift?FSHIFT:0);
_pAccel->_pAccelArray[row-1].key = shortcut._key;
_pAccel->reNew();
// Update the GUI
string sc = shortcut.toString();
_babygrid.setText(row, 2, sc.c_str());
// Add (or update) shortcut to vector in order to save what we have done
if (st == TYPE_CMD)
{
int index = -1;
vector<CommandShortcut> & shortcutList = nppParam->getUserShortcuts();
for (size_t i = 0 ; i < shortcutList.size() ; i++)
{
if (cmdID == shortcutList[i].getID())
{
index = i;
break;
}
}
if (index != -1)
shortcutList[index].copyShortcut(shortcut);
else
shortcutList.push_back(CommandShortcut(cmdID, shortcut));
::SendMessage(_hParent, NPPM_INTERNAL_CMDLIST_MODIFIED, (WPARAM)sc.c_str(), cmdID);
} }
else if (st == TYPE_MACRO) break; }
{ case STATE_MACRO: {
vector<MacroShortcut> & theMacros = nppParam->getMacroList(); //Get MacroShortcut corresponding to row
const int i = cmdID - ID_MACRO; vector<MacroShortcut> & shortcuts = nppParam->getMacroList();
theMacros[i].copyShortcut(shortcut); MacroShortcut msc = shortcuts[row - 1], prevmsc = shortcuts[row - 1];
msc.init(_hInst, _hSelf);
if (msc.doDialog() != -1 && prevmsc != msc) { //shortcut was altered
shortcuts[row - 1] = msc;
_babygrid.setText(row, 1, msc._name);
_babygrid.setText(row, 2, msc.toString().c_str());
HMENU hMenu = ::GetSubMenu(::GetMenu(_hParent), MENUINDEX_MACRO); //Notify current Accelerator class to update everything
::ModifyMenu(hMenu, cmdID, MF_BYCOMMAND, cmdID, theMacros[i].toMenuItemString().c_str()); nppParam->getAccelerator()->updateShortcuts();
//::SendMessage(_hParent, NPPM_INTERNAL_MACROLIST_MODIFIED, 0, 0);
::SendMessage(_hParent, NPPM_INTERNAL_MACROLIST_MODIFIED, 0, 0);
} }
else if (st == TYPE_USERCMD) break; }
{ case STATE_USER: {
vector<UserCommand> & theUserCmds = nppParam->getUserCommandList(); //Get UserCommand corresponding to row
const int i = cmdID - ID_USER_CMD; vector<UserCommand> & shortcuts = nppParam->getUserCommandList();
theUserCmds[i].copyShortcut(shortcut); UserCommand ucmd = shortcuts[row - 1], prevucmd = shortcuts[row - 1];
ucmd.init(_hInst, _hSelf);
prevucmd = ucmd;
if (ucmd.doDialog() != -1 && prevucmd != ucmd) { //shortcut was altered
shortcuts[row - 1] = ucmd;
_babygrid.setText(row, 1, ucmd._name);
_babygrid.setText(row, 2, ucmd.toString().c_str());
HMENU hMenu = ::GetSubMenu(::GetMenu(_hParent), MENUINDEX_RUN); //Notify current Accelerator class to update everything
::ModifyMenu(hMenu, cmdID, MF_BYCOMMAND, cmdID, theUserCmds[i].toMenuItemString().c_str()); nppParam->getAccelerator()->updateShortcuts();
//::SendMessage(_hParent, NPPM_INTERNAL_USERCMDLIST_MODIFIED, 0, 0);
::SendMessage(_hParent, NPPM_INTERNAL_USERCMDLIST_MODIFIED, 0, 0);
} }
break; }
else if (st == TYPE_PLUGINCMD) case STATE_PLUGIN: {
{ //Get PluginCmdShortcut corresponding to row
vector<PluginCmdShortcut> & thePluginCmds = (NppParameters::getInstance())->getPluginCommandList(); vector<PluginCmdShortcut> & shortcuts = nppParam->getPluginCommandList();
int i = -1; PluginCmdShortcut pcsc = shortcuts[row - 1], prevpcsc = shortcuts[row - 1];
for (size_t j = 0 ; j < thePluginCmds.size() ; j++) pcsc.init(_hInst, _hSelf);
{ prevpcsc = pcsc;
if (cmdID == thePluginCmds[j].getID()) if (pcsc.doDialog() != -1 && prevpcsc != pcsc) { //shortcut was altered
{ nppParam->addPluginModifiedIndex(row-1);
i = j; shortcuts[row - 1] = pcsc;
break; _babygrid.setText(row, 2, pcsc.toString().c_str());
}
}
thePluginCmds[i].copyShortcut(shortcut); //Notify current Accelerator class to update everything
nppParam->getAccelerator()->updateShortcuts();
HMENU hMenu = ::GetMenu(_hParent); //::SendMessage(_hParent, NPPM_INTERNAL_PLUGINCMDLIST_MODIFIED, 0, 0);
::ModifyMenu(hMenu, cmdID, MF_BYCOMMAND, cmdID, thePluginCmds[i].toMenuItemString().c_str());
vector<PluginCmdShortcut> & theModifyedPluginCmds = (NppParameters::getInstance())->getPluginCustomizedCmds();
int k = -1;
for (size_t j = 0 ; j < theModifyedPluginCmds.size() ; j++)
{
if (cmdID == theModifyedPluginCmds[j].getID())
{
k = j;
break;
}
}
if (k != -1)
theModifyedPluginCmds[k].copyShortcut(thePluginCmds[i]);
else
theModifyedPluginCmds.push_back(thePluginCmds[i]);
::SendMessage(_hParent, NPPM_INTERNAL_PLUGINCMDLIST_MODIFIED, 0, 0);
} }
_babygrid.setText(row, 1, shortcut._name); break; }
} case STATE_SCINTILLA: {
} //Get ScintillaKeyMap corresponding to row
else // Scintilla Key shortcut vector<ScintillaKeyMap> & shortcuts = nppParam->getScintillaKeyList();
{ ScintillaKeyMap skm = shortcuts[row - 1], prevskm = shortcuts[row - 1];
vector<ScintillaKeyMap> & scintillaShortcuts = nppParam->getScintillaKeyList(); skm.init(_hInst, _hSelf);
const int index = row - _pAccel->_nbAccelItems - 1; if (skm.doDialog() != -1 && prevskm != skm) { //shortcut was altered
ScintillaKeyMap scintillaSc = scintillaShortcuts[index]; nppParam->addScintillaModifiedIndex(row-1);
scintillaSc.init(_hInst, _hSelf); shortcuts[row - 1] = skm;
scintillaSc.setNameReadOnly(false); _babygrid.setText(row, 2, skm.toString().c_str());
if (scintillaSc.doDialog() != -1) //Notify current Accelerator class to update key
{ //nppParam->getScintillaAccelerator()->updateKeys();
// Add this modification into the list to save it later nppParam->getScintillaAccelerator()->updateKey(prevskm, skm);
bool found = false;
vector<ScintillaKeyMap> & userDefScintillaKeys = nppParam->getScintillaModifiedKeys(); //::SendMessage(_hParent, NPPM_INTERNAL_BINDSCINTILLAKEY, scintillaSc.toKeyDef(), scintillaSc.getScintillaKey());
for (size_t i = 0 ; i < userDefScintillaKeys.size() ; i++) //::SendMessage(_hParent, NPPM_INTERNAL_CLEARSCINTILLAKEY, scintillaShortcuts[index].toKeyDef(), 0);
{ //::SendMessage(_hParent, NPPM_INTERNAL_SCINTILLAKEYMODIFIED, 0, 0);
if (scintillaSc.getID() == userDefScintillaKeys[i].getID())
{
userDefScintillaKeys[i].copyShortcut(scintillaSc);
found = true;
}
} }
if (!found) break; }
userDefScintillaKeys.push_back(scintillaSc);
// remap the key
::SendMessage(_hParent, NPPM_INTERNAL_BINDSCINTILLAKEY, scintillaSc.toKeyDef(), scintillaSc.getScintillaKey());
::SendMessage(_hParent, NPPM_INTERNAL_CLEARSCINTILLAKEY, scintillaShortcuts[index].toKeyDef(), 0);
// update the key in the scintilla key list
scintillaShortcuts[index].copyShortcut(scintillaSc);
// if this shortcut is linked to a menu item, change to shortcut string in menu item
if (int cmdID = scintillaShortcuts[index].getMenuCmdID())
{
HMENU hMenu = ::GetMenu(_hParent);
::ModifyMenu(hMenu, cmdID, MF_BYCOMMAND, cmdID, scintillaShortcuts[index].toMenuItemString(cmdID).c_str());
}
// Update UI
_babygrid.setText(row, 2, scintillaSc.toString().c_str());
::SendMessage(_hParent, NPPM_INTERNAL_SCINTILLAKEYMODIFIED, 0, 0);
}
} }
return TRUE; return TRUE;
} }
case IDM_BABYGRID_DELETE : case IDM_BABYGRID_DELETE :
{ {
NppParameters *nppParam = NppParameters::getInstance(); NppParameters *nppParam = NppParameters::getInstance();
if (::MessageBox(_hSelf, "Are you sure to delete this shortcut?", "Are you sure?", MB_OKCANCEL) == IDOK) if (::MessageBox(_hSelf, "Are you sure you want to delete this shortcut?", "Are you sure?", MB_OKCANCEL) == IDOK)
{ {
const int row = _babygrid.getSelectedRow(); const int row = _babygrid.getSelectedRow();
DWORD cmdID = _pAccel->_pAccelArray[row-1].cmd; int shortcutIndex = row-1;
DWORD cmdID;// = _pAccel->_pAccelArray[row-1].cmd;
// Menu data // Menu data
int erasePos;
size_t posBase; size_t posBase;
size_t nbElem; size_t nbElem;
HMENU hMenu; HMENU hMenu;
if ((cmdID >= ID_MACRO) && (cmdID < ID_MACRO_LIMIT)) switch(_currentState) {
{ case STATE_MENU:
vector<MacroShortcut> & theMacros = nppParam->getMacroList(); case STATE_PLUGIN:
vector<MacroShortcut>::iterator it = theMacros.begin(); case STATE_SCINTILLA: {
erasePos = cmdID - ID_MACRO; return FALSE; //this is bad
theMacros.erase(it + erasePos); break; }
_pAccel->uptdateShortcuts(); case STATE_MACRO: {
_babygrid.clear(); vector<MacroShortcut> & theMacros = nppParam->getMacroList();
fillOutBabyGrid(); vector<MacroShortcut>::iterator it = theMacros.begin();
cmdID = theMacros[shortcutIndex].getID();
theMacros.erase(it + shortcutIndex);
fillOutBabyGrid();
// preparing to remove from menu
posBase = 6;
nbElem = theMacros.size();
hMenu = ::GetSubMenu(::GetMenu(_hParent), MENUINDEX_MACRO);
for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining items so there are no gaps
{
MacroShortcut ms = theMacros[i];
ms.setID(ms.getID() - 1); //shift all IDs
theMacros[i] = ms;
}
//::SendMessage(_hParent, NPPM_INTERNAL_MACROLIST_MODIFIED, 0, 0);
break; }
case STATE_USER: {
vector<UserCommand> & theUserCmds = nppParam->getUserCommandList();
vector<UserCommand>::iterator it = theUserCmds.begin();
cmdID = theUserCmds[shortcutIndex].getID();
theUserCmds.erase(it + shortcutIndex);
fillOutBabyGrid();
// preparing to remove from menu // preparing to remove from menu
posBase = 3; posBase = 2;
nbElem = theMacros.size(); nbElem = theUserCmds.size();
hMenu = ::GetSubMenu(::GetMenu(_hParent), MENUINDEX_MACRO); hMenu = ::GetSubMenu(::GetMenu(_hParent), MENUINDEX_RUN);
for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining items so there are no gaps
::SendMessage(_hParent, NPPM_INTERNAL_MACROLIST_MODIFIED, 0, 0); {
} UserCommand uc = theUserCmds[i];
else if ((cmdID >= ID_USER_CMD) && (cmdID < ID_USER_CMD_LIMIT)) uc.setID(uc.getID() - 1); //shift all IDs
{ theUserCmds[i] = uc;
vector<UserCommand> & theUserCmds = nppParam->getUserCommandList(); }
vector<UserCommand>::iterator it = theUserCmds.begin();
erasePos = cmdID - ID_USER_CMD; //::SendMessage(_hParent, NPPM_INTERNAL_USERCMDLIST_MODIFIED, 0, 0);
theUserCmds.erase(it + erasePos); break; }
_pAccel->uptdateShortcuts();
_babygrid.clear();
fillOutBabyGrid();
// preparing to remove from menu
posBase = 0;
nbElem = theUserCmds.size();
hMenu = ::GetSubMenu(::GetMenu(_hParent), MENUINDEX_RUN);
::SendMessage(_hParent, NPPM_INTERNAL_USERCMDLIST_MODIFIED, 0, 0);
}
else // should never happen
{
return FALSE;
} }
// remove from menu // remove from menu
::RemoveMenu(hMenu, cmdID++, MF_BYCOMMAND); ::RemoveMenu(hMenu, cmdID, MF_BYCOMMAND);
cmdID++;
for (size_t i = erasePos ; i < nbElem ; i++) if (nbElem == 0) {
{ ::RemoveMenu(hMenu, posBase-1, MF_BYPOSITION); //remove separator
char cmdName[64]; } else {
::GetMenuString(hMenu, cmdID, cmdName, sizeof(cmdName), MF_BYCOMMAND); for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining menu items so there are no gaps
::ModifyMenu(hMenu, cmdID, MF_BYCOMMAND, cmdID-1, cmdName); {
cmdID++; char cmdName[64];
::GetMenuString(hMenu, cmdID, cmdName, sizeof(cmdName), MF_BYCOMMAND);
::ModifyMenu(hMenu, cmdID, MF_BYCOMMAND, cmdID-1, cmdName); //update commandID
}
} }
if (nbElem == 0)
::RemoveMenu(hMenu, posBase + 1, MF_BYPOSITION);
nppParam->getAccelerator()->updateShortcuts();
} }
return TRUE; return TRUE;
} }
default : case IDD_BABYGRID_ID1: {
if (LOWORD(wParam) == IDD_BABYGRID_ID1) if(HIWORD(wParam) == BGN_CELLDBCLICKED) //a cell was clicked in the properties grid
{ {
if(HIWORD(wParam) == BGN_CELLDBCLICKED) //a cell was clicked in the properties grid return ::SendMessage(_hSelf, WM_COMMAND, IDM_BABYGRID_MODIFY, LOWORD(lParam));
{
return ::SendMessage(_hSelf, WM_COMMAND, IDM_BABYGRID_MODIFY, LOWORD(lParam));
}
else if(HIWORD(wParam) == BGN_CELLRCLICKED) //a cell was clicked in the properties grid
{
int row = LOWORD(lParam);
DWORD cmdID = _pAccel->_pAccelArray[row-1].cmd;
POINT p;
::GetCursorPos(&p);
if (!_rightClickMenu.isCreated())
{
vector<MenuItemUnit> itemUnitArray;
itemUnitArray.push_back(MenuItemUnit(IDM_BABYGRID_MODIFY, "Modify"));
itemUnitArray.push_back(MenuItemUnit(IDM_BABYGRID_DELETE, "Delete"));
_rightClickMenu.create(_hSelf, itemUnitArray);
}
bool b = (!((cmdID >= ID_MACRO) && (cmdID < ID_MACRO_LIMIT))) && (!((cmdID >= ID_USER_CMD) && (cmdID < ID_USER_CMD_LIMIT)));
_rightClickMenu.enableItem(IDM_BABYGRID_DELETE, !b);
_rightClickMenu.display(p);
return TRUE;
}
} }
else if(HIWORD(wParam) == BGN_CELLRCLICKED) //a cell was clicked in the properties grid
{
POINT p;
::GetCursorPos(&p);
if (!_rightClickMenu.isCreated())
{
vector<MenuItemUnit> itemUnitArray;
itemUnitArray.push_back(MenuItemUnit(IDM_BABYGRID_MODIFY, "Modify"));
itemUnitArray.push_back(MenuItemUnit(IDM_BABYGRID_DELETE, "Delete"));
_rightClickMenu.create(_hSelf, itemUnitArray);
}
switch(_currentState) {
case STATE_MACRO:
case STATE_USER: {
_rightClickMenu.enableItem(IDM_BABYGRID_DELETE, true);
break; }
case STATE_MENU:
case STATE_PLUGIN:
case STATE_SCINTILLA: {
_rightClickMenu.enableItem(IDM_BABYGRID_DELETE, false);
break; }
}
_rightClickMenu.display(p);
return TRUE;
}
}
} }
} }
default: default:

View File

@ -25,9 +25,17 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "shortcut.h" #include "shortcut.h"
#include "ContextMenu.h" #include "ContextMenu.h"
enum GridState {STATE_MENU, STATE_MACRO, STATE_USER, STATE_PLUGIN, STATE_SCINTILLA};
class ShortcutMapper : public StaticDialog { class ShortcutMapper : public StaticDialog {
public: public:
ShortcutMapper() : StaticDialog() {}; ShortcutMapper() : _currentState(STATE_MENU), StaticDialog() {
strncpy(tabNames[0], "Main menu", maxTabName);
strncpy(tabNames[1], "Macros", maxTabName);
strncpy(tabNames[2], "Run commands", maxTabName);
strncpy(tabNames[3], "Plugin commands", maxTabName);
strncpy(tabNames[4], "Scintilla commands", maxTabName);
};
~ShortcutMapper() {}; ~ShortcutMapper() {};
//void init(HINSTANCE hInst, HWND parent) {}; //void init(HINSTANCE hInst, HWND parent) {};
void destroy() {}; void destroy() {};
@ -44,17 +52,27 @@ public:
}; };
void getClientRect(RECT & rc) const { void getClientRect(RECT & rc) const {
Window::getClientRect(rc); Window::getClientRect(rc);
rc.top += 40;
rc.bottom -= 20; rc.bottom -= 20;
rc.left += 5;
}; };
void translateTab(int index, const char * newname);
protected : protected :
BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
private: private:
static const int maxTabName = 64;
BabyGridWrapper _babygrid; BabyGridWrapper _babygrid;
Accelerator *_pAccel;
ContextMenu _rightClickMenu; ContextMenu _rightClickMenu;
GridState _currentState;
HWND _hTabCtrl;
char tabNames[5][maxTabName];
void initTabs();
void initBabyGrid(); void initBabyGrid();
void fillOutBabyGrid(); void fillOutBabyGrid();
}; };

View File

@ -33,4 +33,6 @@ CAPTION "Shortcut mapper"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
DEFPUSHBUTTON "Close",IDOK,172,319,47,14 DEFPUSHBUTTON "Close",IDOK,172,319,47,14
CONTROL "",IDC_BABYGRID_TABBAR,"SysTabControl32",TCS_BUTTONS,6,6,372,
12
END END

View File

@ -21,3 +21,4 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define IDD_BABYGRID_ID1 (IDD_SHORTCUTMAPPER_DLG + 1) #define IDD_BABYGRID_ID1 (IDD_SHORTCUTMAPPER_DLG + 1)
#define IDM_BABYGRID_MODIFY (IDD_SHORTCUTMAPPER_DLG + 2) #define IDM_BABYGRID_MODIFY (IDD_SHORTCUTMAPPER_DLG + 2)
#define IDM_BABYGRID_DELETE (IDD_SHORTCUTMAPPER_DLG + 3) #define IDM_BABYGRID_DELETE (IDD_SHORTCUTMAPPER_DLG + 3)
#define IDC_BABYGRID_TABBAR (IDD_SHORTCUTMAPPER_DLG + 4)

View File

@ -688,12 +688,16 @@ BOOL CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
if ((LangType)i != L_USER) if ((LangType)i != L_USER)
{ {
int cmdID = pNppParam->langTypeToCommandID((LangType)i); int cmdID = pNppParam->langTypeToCommandID((LangType)i);
if ((cmdID != -1) && (getNameStrFromCmd(cmdID, str) == TYPE_CMD)) if ((cmdID != -1))
{ {
_langList.push_back(LangID_Name((LangType)i, str)); getNameStrFromCmd(cmdID, str);
::SendDlgItemMessage(_hSelf, IDC_COMBO_DEFAULTLANG, CB_ADDSTRING, 0, (LPARAM)str.c_str()); if (str.length() > 0)
if (ndds._lang == i) {
index = _langList.size() - 1; _langList.push_back(LangID_Name((LangType)i, str));
::SendDlgItemMessage(_hSelf, IDC_COMBO_DEFAULTLANG, CB_ADDSTRING, 0, (LPARAM)str.c_str());
if (ndds._lang == i)
index = _langList.size() - 1;
}
} }
} }
} }
@ -764,11 +768,14 @@ BOOL CALLBACK LangMenuDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPara
if ((LangType)i != L_USER) if ((LangType)i != L_USER)
{ {
int cmdID = pNppParam->langTypeToCommandID((LangType)i); int cmdID = pNppParam->langTypeToCommandID((LangType)i);
if (getNameStrFromCmd(cmdID, str) == TYPE_CMD) if ((cmdID != -1))
{ {
_langList.push_back(LangMenuItem((LangType)i, cmdID, str)); getNameStrFromCmd(cmdID, str);
::SendDlgItemMessage(_hSelf, IDC_LIST_ENABLEDLANG, LB_ADDSTRING, 0, (LPARAM)str.c_str()); if (str.length() > 0)
//printStr(str.c_str()); {
_langList.push_back(LangMenuItem((LangType)i, cmdID, str));
::SendDlgItemMessage(_hSelf, IDC_LIST_ENABLEDLANG, LB_ADDSTRING, 0, (LPARAM)str.c_str());
}
} }
} }
} }
@ -1420,4 +1427,4 @@ void BackupDlg::updateBackupGUI()
::EnableWindow(::GetDlgItem(_hSelf, IDD_BACKUPDIR_STATIC), isEnableLocalCheck); ::EnableWindow(::GetDlgItem(_hSelf, IDD_BACKUPDIR_STATIC), isEnableLocalCheck);
::EnableWindow(::GetDlgItem(_hSelf, IDC_BACKUPDIR_EDIT), isEnableLocalCheck); ::EnableWindow(::GetDlgItem(_hSelf, IDC_BACKUPDIR_EDIT), isEnableLocalCheck);
::EnableWindow(::GetDlgItem(_hSelf, IDD_BACKUPDIR_BROWSE_BUTTON), isEnableLocalCheck); ::EnableWindow(::GetDlgItem(_hSelf, IDD_BACKUPDIR_BROWSE_BUTTON), isEnableLocalCheck);
} }

View File

@ -29,12 +29,7 @@ void Command::extractArgs(char *cmd2Exec, char *args, const char *cmdEntier)
int i = 0; int i = 0;
bool quoted = false; bool quoted = false;
for ( ; i < int(strlen(cmdEntier)) ; i++) for ( ; i < int(strlen(cmdEntier)) ; i++)
{/* {
if (cmdEntier[i] != ' ')
cmd2Exec[i] = cmdEntier[i];
else
break;
*/
if ((cmdEntier[i] == ' ') && (!quoted)) if ((cmdEntier[i] == ' ') && (!quoted))
break; break;
if (cmdEntier[i]=='"') if (cmdEntier[i]=='"')
@ -202,28 +197,26 @@ BOOL CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{ {
std::vector<UserCommand> & theUserCmds = (NppParameters::getInstance())->getUserCommandList(); std::vector<UserCommand> & theUserCmds = (NppParameters::getInstance())->getUserCommandList();
int nbCmd = theUserCmds.size();
int cmdID = ID_USER_CMD + nbCmd;
char cmd[MAX_PATH]; char cmd[MAX_PATH];
::GetDlgItemText(_hSelf, IDC_COMBO_RUN_PATH, cmd, MAX_PATH); ::GetDlgItemText(_hSelf, IDC_COMBO_RUN_PATH, cmd, MAX_PATH);
UserCommand uc(cmd); UserCommand uc(Shortcut(), cmd, cmdID);
uc.init(_hInst, _hSelf); uc.init(_hInst, _hSelf);
uc._canModifyName = true;
if (uc.doDialog() != -1) if (uc.doDialog() != -1)
{ {
theUserCmds.push_back(uc);
std::vector<UserCommand> & userCommands = (NppParameters::getInstance())->getUserCommandList();
HMENU hRunMenu = ::GetSubMenu(::GetMenu(_hParent), MENUINDEX_RUN); HMENU hRunMenu = ::GetSubMenu(::GetMenu(_hParent), MENUINDEX_RUN);
int const posBase = 0; int const posBase = 2;
int nbCmd = userCommands.size();
if (nbCmd == 1) if (nbCmd == 0)
::InsertMenu(hRunMenu, posBase + 1, MF_BYPOSITION, (unsigned int)-1, 0); ::InsertMenu(hRunMenu, posBase - 1, MF_BYPOSITION, (unsigned int)-1, 0);
//char menuString[64];
//sprintf(menuString, "%s%s%s", uc._name, "\t", uc.toString().c_str()); theUserCmds.push_back(uc);
::InsertMenu(hRunMenu, posBase + 1 + nbCmd, MF_BYPOSITION, ID_USER_CMD + nbCmd - 1, uc.toMenuItemString().c_str()); ::InsertMenu(hRunMenu, posBase + nbCmd, MF_BYPOSITION, cmdID, uc.toMenuItemString().c_str());
(NppParameters::getInstance())->getAccelerator()->updateShortcuts();
Accelerator *pAccel = (NppParameters::getInstance())->getAccelerator();
pAccel->uptdateShortcuts();
::SendMessage(_hParent, NPPM_INTERNAL_USERCMDLIST_MODIFIED, 0, 0);
} }
return TRUE; return TRUE;
} }

View File

@ -21,9 +21,119 @@
#include "resource.h" #include "resource.h"
#include "Notepad_plus.h" #include "Notepad_plus.h"
//const int NB_VKEY = 77; #include "keys.h"
const int KEY_STR_LEN = 16; const int KEY_STR_LEN = 16;
struct KeyIDNAME {
const char * name;
unsigned char id;
};
KeyIDNAME namedKeyArray[] = {
{"None", VK_NULL},
{"Backspace", VK_BACK},
{"Tab", VK_TAB},
{"Enter", VK_RETURN},
{"Esc", VK_ESCAPE},
{"Spacebar", VK_SPACE},
{"Page up", VK_PRIOR},
{"Page down", VK_NEXT},
{"End", VK_END},
{"Home", VK_HOME},
{"Left", VK_LEFT},
{"Up", VK_UP},
{"Right", VK_RIGHT},
{"Down", VK_DOWN},
{"INS", VK_INSERT},
{"DEL", VK_DELETE},
{"0", VK_0},
{"1", VK_1},
{"2", VK_2},
{"3", VK_3},
{"4", VK_4},
{"5", VK_5},
{"6", VK_6},
{"7", VK_7},
{"8", VK_8},
{"9", VK_9},
{"A", VK_A},
{"B", VK_B},
{"C", VK_C},
{"D", VK_D},
{"E", VK_E},
{"F", VK_F},
{"G", VK_G},
{"H", VK_H},
{"I", VK_I},
{"J", VK_J},
{"K", VK_K},
{"L", VK_L},
{"M", VK_M},
{"N", VK_N},
{"O", VK_O},
{"P", VK_P},
{"Q", VK_Q},
{"R", VK_R},
{"S", VK_S},
{"T", VK_T},
{"U", VK_U},
{"V", VK_V},
{"W", VK_W},
{"X", VK_X},
{"Y", VK_Y},
{"Z", VK_Z},
{"Numpad 0", VK_NUMPAD0},
{"Numpad 1", VK_NUMPAD1},
{"Numpad 2", VK_NUMPAD2},
{"Numpad 3", VK_NUMPAD3},
{"Numpad 4", VK_NUMPAD4},
{"Numpad 5", VK_NUMPAD5},
{"Numpad 6", VK_NUMPAD6},
{"Numpad 7", VK_NUMPAD7},
{"Numpad 8", VK_NUMPAD8},
{"Numpad 9", VK_NUMPAD9},
{"Num *", VK_MULTIPLY},
{"Num +", VK_ADD},
//{"Num Enter", VK_SEPARATOR}, //this one doesnt seem to work
{"Num -", VK_SUBTRACT},
{"Num .", VK_DECIMAL},
{"Num /", VK_DIVIDE},
{"F1", VK_F1},
{"F2", VK_F2},
{"F3", VK_F3},
{"F4", VK_F4},
{"F5", VK_F5},
{"F6", VK_F6},
{"F7", VK_F7},
{"F8", VK_F8},
{"F9", VK_F9},
{"F10", VK_F10},
{"F11", VK_F11},
{"F12", VK_F12},
{"~", VK_OEM_3},
{"-", VK_OEM_MINUS},
{"=", VK_OEM_PLUS},
{"[", VK_OEM_4},
{"]", VK_OEM_6},
{";", VK_OEM_1},
{"'", VK_OEM_7},
{"\\", VK_OEM_5},
{",", VK_OEM_COMMA},
{".", VK_OEM_PERIOD},
{"/", VK_OEM_2},
{"<>", VK_OEM_102},
};
#define nrKeys sizeof(namedKeyArray)/sizeof(KeyIDNAME)
/*
char vKeyArray[][KEY_STR_LEN] = \ char vKeyArray[][KEY_STR_LEN] = \
{"", "BACKSPACE", "TAB", "ENTER", "PAUSE", "CAPS LOCK", "ESC", "SPACEBAR", "PAGE UP", "PAGE DOWN",\ {"", "BACKSPACE", "TAB", "ENTER", "PAUSE", "CAPS LOCK", "ESC", "SPACEBAR", "PAGE UP", "PAGE DOWN",\
"END", "HOME", "LEFT ARROW", "UP ARROW", "RIGHT ARROW", "DOWN ARROW", "INS", "DEL",\ "END", "HOME", "LEFT ARROW", "UP ARROW", "RIGHT ARROW", "DOWN ARROW", "INS", "DEL",\
@ -44,12 +154,21 @@ unsigned char vkeyValue[] = {\
0x57, 0x58, 0x59, 0x5A, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65,\ 0x57, 0x58, 0x59, 0x5A, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65,\
0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,\ 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,\
0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B}; 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B};
*/
string Shortcut::toString() const string Shortcut::toString() const
{ {
string sc = _isCtrl?"Ctrl+":""; string sc = "";
sc += _isAlt?"Alt+":""; if (!isEnabled())
sc += _isShift?"Shift+":""; return sc;
if (_isCtrl)
sc += "Ctrl+";
if (_isAlt)
sc += "Alt+";
if (_isShift)
sc += "Shift+";
string key; string key;
getKeyStrFromVal(_key, key); getKeyStrFromVal(_key, key);
sc += key; sc += key;
@ -60,36 +179,32 @@ void getKeyStrFromVal(unsigned char keyVal, string & str)
{ {
str = ""; str = "";
bool found = false; bool found = false;
int i = 0; int i;
for (; i < sizeof(vkeyValue) ; i++) for (i = 0; i < nrKeys; i++) {
{ if (keyVal == namedKeyArray[i].id) {
if (keyVal == vkeyValue[i])
{
found = true; found = true;
break; break;
} }
} }
if (found) if (found)
str = vKeyArray[i]; str = namedKeyArray[i].name;
else
str = "Unlisted";
} }
ShortcutType getNameStrFromCmd(DWORD cmd, string & str) void getNameStrFromCmd(DWORD cmd, string & str)
{ {
ShortcutType st;
if ((cmd >= ID_MACRO) && (cmd < ID_MACRO_LIMIT)) if ((cmd >= ID_MACRO) && (cmd < ID_MACRO_LIMIT))
{ {
vector<MacroShortcut> & theMacros = (NppParameters::getInstance())->getMacroList(); vector<MacroShortcut> & theMacros = (NppParameters::getInstance())->getMacroList();
int i = cmd - ID_MACRO; int i = cmd - ID_MACRO;
str = theMacros[i]._name; str = theMacros[i]._name;
st = TYPE_MACRO;
} }
else if ((cmd >= ID_USER_CMD) && (cmd < ID_USER_CMD_LIMIT)) else if ((cmd >= ID_USER_CMD) && (cmd < ID_USER_CMD_LIMIT))
{ {
vector<UserCommand> & userCommands = (NppParameters::getInstance())->getUserCommandList(); vector<UserCommand> & userCommands = (NppParameters::getInstance())->getUserCommandList();
int i = cmd - ID_USER_CMD; int i = cmd - ID_USER_CMD;
str = userCommands[i]._name; str = userCommands[i]._name;
st = TYPE_USERCMD;
} }
else if ((cmd >= ID_PLUGINS_CMD) && (cmd < ID_PLUGINS_CMD_LIMIT)) else if ((cmd >= ID_PLUGINS_CMD) && (cmd < ID_PLUGINS_CMD_LIMIT))
{ {
@ -104,36 +219,23 @@ ShortcutType getNameStrFromCmd(DWORD cmd, string & str)
} }
} }
str = pluginCmds[i]._name; str = pluginCmds[i]._name;
//printStr(str.c_str());
st = TYPE_PLUGINCMD;
} }
/*else if ((cmd >= IDCMD) && (cmd < IDCMD_LIMIT))
{
vector<string> & cmds = (NppParameters::getInstance())->getNoMenuCmdNames();
size_t idcmdIndex = cmd - IDCMD;
if (idcmdIndex < cmds.size())
str = cmds[idcmdIndex];
st = TYPE_CMD;
}*/
else else
{ {
HWND hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL); HWND hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL);
char cmdName[64]; char cmdName[64];
char filteredCmdName[64];
int nbChar = ::GetMenuString(::GetMenu(hNotepad_plus), cmd, cmdName, sizeof(cmdName), MF_BYCOMMAND); int nbChar = ::GetMenuString(::GetMenu(hNotepad_plus), cmd, cmdName, sizeof(cmdName), MF_BYCOMMAND);
if (!nbChar) if (!nbChar)
return TYPE_INVALID; return;
bool fin = false; bool fin = false;
int j = 0; int j = 0;
for (size_t i = 0 ; i < strlen(cmdName) ; i++) size_t len = strlen(cmdName);
for (size_t i = 0 ; i < len; i++)
{ {
switch(cmdName[i]) switch(cmdName[i])
{ {
case '\t': case '\t':
filteredCmdName[j] = '\0'; cmdName[j] = '\0';
fin = true; fin = true;
break; break;
@ -141,16 +243,15 @@ ShortcutType getNameStrFromCmd(DWORD cmd, string & str)
break; break;
default : default :
filteredCmdName[j++] = cmdName[i]; cmdName[j++] = cmdName[i];
} }
if (fin) if (fin)
break; break;
} }
filteredCmdName[j] = '\0'; cmdName[j] = '\0';
str = filteredCmdName; str = cmdName;
st = TYPE_CMD;
} }
return st; return;
} }
BOOL CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) BOOL CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
@ -163,22 +264,24 @@ BOOL CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
::SetDlgItemText(_hSelf, IDC_NAME_EDIT, _name); ::SetDlgItemText(_hSelf, IDC_NAME_EDIT, _name);
if (!_canModifyName) if (!_canModifyName)
::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, EM_SETREADONLY, TRUE, 0); ::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, EM_SETREADONLY, TRUE, 0);
int textlen = (int)::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0);
::SendDlgItemMessage(_hSelf, IDC_CTRL_CHECK, BM_SETCHECK, _isCtrl?BST_CHECKED:BST_UNCHECKED, 0); ::SendDlgItemMessage(_hSelf, IDC_CTRL_CHECK, BM_SETCHECK, _isCtrl?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_ALT_CHECK, BM_SETCHECK, _isAlt?BST_CHECKED:BST_UNCHECKED, 0); ::SendDlgItemMessage(_hSelf, IDC_ALT_CHECK, BM_SETCHECK, _isAlt?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_SHIFT_CHECK, BM_SETCHECK, _isShift?BST_CHECKED:BST_UNCHECKED, 0); ::SendDlgItemMessage(_hSelf, IDC_SHIFT_CHECK, BM_SETCHECK, _isShift?BST_CHECKED:BST_UNCHECKED, 0);
::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid()); ::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName));
int iFound = -1; int iFound = -1;
for (size_t i = 0 ; i < sizeof(vkeyValue) ; i++) for (size_t i = 0 ; i < nrKeys ; i++)
{ {
::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_ADDSTRING, 0, (LPARAM)vKeyArray[i]); ::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_ADDSTRING, 0, (LPARAM)namedKeyArray[i].name);
if (_key == vkeyValue[i]) if (_key == namedKeyArray[i].id)
iFound = i; iFound = i;
} }
if (iFound != -1) if (iFound != -1)
::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_SETCURSEL, iFound, 0); ::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_SETCURSEL, iFound, 0);
::ShowWindow(::GetDlgItem(_hSelf, IDC_WARNING_STATIC), isEnabled()?SW_HIDE:SW_SHOW);
goToCenter(); goToCenter();
return TRUE; return TRUE;
@ -186,16 +289,17 @@ BOOL CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
case WM_COMMAND : case WM_COMMAND :
{ {
int textlen = (int)::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0);
switch (wParam) switch (wParam)
{ {
case IDC_CTRL_CHECK : case IDC_CTRL_CHECK :
_isCtrl = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0); _isCtrl = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0);
::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid()); ::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName));
return TRUE; return TRUE;
case IDC_ALT_CHECK : case IDC_ALT_CHECK :
_isAlt = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0); _isAlt = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0);
::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid()); ::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName));
return TRUE; return TRUE;
case IDC_SHIFT_CHECK : case IDC_SHIFT_CHECK :
@ -203,6 +307,11 @@ BOOL CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
return TRUE; return TRUE;
case IDOK : case IDOK :
if (!isEnabled()) {
_isCtrl = _isAlt = _isShift = false;
}
if (_canModifyName)
::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, WM_GETTEXT, nameLenMax, (LPARAM)_name);
::EndDialog(_hSelf, 0); ::EndDialog(_hSelf, 0);
return TRUE; return TRUE;
@ -215,7 +324,7 @@ BOOL CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
{ {
if (LOWORD(wParam) == IDC_NAME_EDIT) if (LOWORD(wParam) == IDC_NAME_EDIT)
{ {
::SendDlgItemMessage(_hSelf, LOWORD(wParam), WM_GETTEXT, nameLenMax, (LPARAM)_name); ::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName));
return TRUE; return TRUE;
} }
} }
@ -224,8 +333,9 @@ BOOL CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
if (LOWORD(wParam) == IDC_KEY_COMBO) if (LOWORD(wParam) == IDC_KEY_COMBO)
{ {
int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETCURSEL, 0, 0); int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETCURSEL, 0, 0);
_key = vkeyValue[i]; _key = namedKeyArray[i].id;
::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid()); ::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName));
::ShowWindow(::GetDlgItem(_hSelf, IDC_WARNING_STATIC), isEnabled()?SW_HIDE:SW_SHOW);
return TRUE; return TRUE;
} }
} }
@ -240,7 +350,7 @@ BOOL CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
} }
// return true if one of CommandShortcuts is deleted. Otherwise false. // return true if one of CommandShortcuts is deleted. Otherwise false.
bool Accelerator::uptdateShortcuts(HWND nppHandle) bool Accelerator::updateShortcuts(/*HWND nppHandle*/)
{ {
bool isCmdScModified = false; bool isCmdScModified = false;
NppParameters *pNppParam = NppParameters::getInstance(); NppParameters *pNppParam = NppParameters::getInstance();
@ -250,95 +360,91 @@ bool Accelerator::uptdateShortcuts(HWND nppHandle)
vector<UserCommand> & userCommands = pNppParam->getUserCommandList(); vector<UserCommand> & userCommands = pNppParam->getUserCommandList();
vector<PluginCmdShortcut> & pluginCommands = pNppParam->getPluginCommandList(); vector<PluginCmdShortcut> & pluginCommands = pNppParam->getPluginCommandList();
vector<ScintillaKeyMap> & scintillaScs = pNppParam->getScintillaKeyList(); size_t nbMenu = shortcuts.size();
vector<ScintillaKeyMap> & scintillaModifScs = pNppParam->getScintillaModifiedKeys();
size_t nbMacro = macros.size(); size_t nbMacro = macros.size();
size_t nbUserCmd = userCommands.size(); size_t nbUserCmd = userCommands.size();
size_t nbPluginCmd = pluginCommands.size(); size_t nbPluginCmd = pluginCommands.size();
size_t totalShorcut = copyAccelArray(nbMacro, nbUserCmd, nbPluginCmd); if (_pAccelArray)
delete [] _pAccelArray;
int m = 0; _pAccelArray = new ACCEL[nbMenu+nbMacro+nbUserCmd+nbPluginCmd];
size_t i = totalShorcut - nbMacro - nbUserCmd - nbPluginCmd; int offset = 0;
for (vector<MacroShortcut>::iterator ms = macros.begin() ; i < (totalShorcut - nbUserCmd - nbPluginCmd) ; i++, ms++) size_t i = 0;
{ //no validation performed, it might be that invalid shortcuts are being used by default. Allows user to 'hack', might be a good thing
_pAccelArray[i].cmd = ID_MACRO + m++; for(i = 0; i < nbMenu; i++) {
_pAccelArray[i].fVirt = FVIRTKEY | (ms->_isCtrl?FCONTROL:0) | (ms->_isAlt?FALT:0) | (ms->_isShift?FSHIFT:0); if (shortcuts[i].isEnabled()) {// && shortcuts[i].isValid()) {
_pAccelArray[i].key = ms->_key; _pAccelArray[offset].cmd = (WORD)(shortcuts[i].getID());
} _pAccelArray[offset].fVirt = FVIRTKEY | (shortcuts[i]._isCtrl?FCONTROL:0) | (shortcuts[i]._isAlt?FALT:0) | (shortcuts[i]._isShift?FSHIFT:0);
_pAccelArray[offset].key = shortcuts[i]._key;
m = 0; offset++;
for (vector<UserCommand>::iterator uc = userCommands.begin() ; i < (totalShorcut - nbPluginCmd); i++, uc++)
{
_pAccelArray[i].cmd = ID_USER_CMD + m++;
_pAccelArray[i].fVirt = FVIRTKEY | (uc->_isCtrl?FCONTROL:0) | (uc->_isAlt?FALT:0) | (uc->_isShift?FSHIFT:0);
_pAccelArray[i].key = uc->_key;
}
for (vector<PluginCmdShortcut>::iterator pc = pluginCommands.begin() ; i < totalShorcut; i++, pc++)
{
_pAccelArray[i].cmd = (unsigned short)pc->getID();
_pAccelArray[i].fVirt = FVIRTKEY | (pc->_isCtrl?FCONTROL:0) | (pc->_isAlt?FALT:0) | (pc->_isShift?FSHIFT:0);
_pAccelArray[i].key = pc->_key;
}
// search all the command shortcuts modified by user from xml
for (vector<CommandShortcut>::iterator csc = shortcuts.begin() ; csc != shortcuts.end() ; )
{
bool found = false;
int nbCmdShortcut = totalShorcut - nbMacro - nbUserCmd - nbPluginCmd;
for (int j = 0 ; j < nbCmdShortcut ; j++)
{
if (_pAccelArray[j].cmd == csc->getID())
{
_pAccelArray[j].fVirt = FVIRTKEY | (csc->_isCtrl?FCONTROL:0)\
| (csc->_isAlt?FALT:0) | (csc->_isShift?FSHIFT:0);
_pAccelArray[j].key = csc->_key;
found = true;
break;
}
}
if (!found)
{
csc = shortcuts.erase(csc);
isCmdScModified = true;
}
else
csc++;
}
if (nppHandle)
{
for (vector<ScintillaKeyMap>::iterator skmm = scintillaModifScs.begin() ; skmm != scintillaModifScs.end() ; skmm++)
{
for (vector<ScintillaKeyMap>::iterator skm = scintillaScs.begin() ; skm != scintillaScs.end() ; skm++)
{
if (skmm->getScintillaKey() == skm->getScintillaKey())
{
// remap the key
::SendMessage(nppHandle, NPPM_INTERNAL_BINDSCINTILLAKEY, skmm->toKeyDef(), skmm->getScintillaKey());
::SendMessage(nppHandle, NPPM_INTERNAL_CLEARSCINTILLAKEY, skm->toKeyDef(), 0);
// update the global ScintillaKeyList
skm->copyShortcut(*skmm);
// if this shortcut is linked to a menu item, change to shortcut string in menu item
if (int cmdID = skm->getMenuCmdID())
{
HMENU hMenu = ::GetMenu(nppHandle);
::ModifyMenu(hMenu, cmdID, MF_BYCOMMAND, cmdID, skm->toMenuItemString(cmdID).c_str());
}
break;
}
}
} }
} }
reNew();
for(i = 0; i < nbMacro; i++) {
if (macros[i].isEnabled()) {// && macros[i].isValid()) {
_pAccelArray[offset].cmd = (WORD)(macros[i].getID());
_pAccelArray[offset].fVirt = FVIRTKEY | (macros[i]._isCtrl?FCONTROL:0) | (macros[i]._isAlt?FALT:0) | (macros[i]._isShift?FSHIFT:0);
_pAccelArray[offset].key = macros[i]._key;
offset++;
}
}
for(i = 0; i < nbUserCmd; i++) {
if (userCommands[i].isEnabled()) {// && userCommands[i].isValid()) {
_pAccelArray[offset].cmd = (WORD)(userCommands[i].getID());
_pAccelArray[offset].fVirt = FVIRTKEY | (userCommands[i]._isCtrl?FCONTROL:0) | (userCommands[i]._isAlt?FALT:0) | (userCommands[i]._isShift?FSHIFT:0);
_pAccelArray[offset].key = userCommands[i]._key;
offset++;
}
}
for(i = 0; i < nbPluginCmd; i++) {
if (pluginCommands[i].isEnabled()) {// && pluginCommands[i].isValid()) {
_pAccelArray[offset].cmd = (WORD)(pluginCommands[i].getID());
_pAccelArray[offset].fVirt = FVIRTKEY | (pluginCommands[i]._isCtrl?FCONTROL:0) | (pluginCommands[i]._isAlt?FALT:0) | (pluginCommands[i]._isShift?FSHIFT:0);
_pAccelArray[offset].key = pluginCommands[i]._key;
offset++;
}
}
_nbAccelItems = offset;
updateFullMenu();
reNew(); //update the table
return isCmdScModified; return isCmdScModified;
} }
void Accelerator::updateFullMenu() {
NppParameters * pNppParam = NppParameters::getInstance();
vector<CommandShortcut> commands = pNppParam->getUserShortcuts();
for(size_t i = 0; i < commands.size(); i++) {
updateMenuItemByCommand(commands[i]);
}
vector<MacroShortcut> mcommands = pNppParam->getMacroList();
for(size_t i = 0; i < mcommands.size(); i++) {
updateMenuItemByCommand(mcommands[i]);
}
vector<UserCommand> ucommands = pNppParam->getUserCommandList();
for(size_t i = 0; i < ucommands.size(); i++) {
updateMenuItemByCommand(ucommands[i]);
}
vector<PluginCmdShortcut> pcommands = pNppParam->getPluginCommandList();
for(size_t i = 0; i < pcommands.size(); i++) {
updateMenuItemByCommand(pcommands[i]);
}
::DrawMenuBar(_hMenuParent);
}
void Accelerator::updateMenuItemByCommand(CommandShortcut csc) {
int cmdID = (int)csc.getID();
::ModifyMenu(_hAccelMenu, cmdID, MF_BYCOMMAND, cmdID, csc.toMenuItemString().c_str());
}
recordedMacroStep::recordedMacroStep(int iMessage, long wParam, long lParam) recordedMacroStep::recordedMacroStep(int iMessage, long wParam, long lParam)
: message(iMessage), wParameter(wParam), lParameter(lParam), MacroType(mtUseLParameter) : message(iMessage), wParameter(wParam), lParameter(lParam), MacroType(mtUseLParameter)
{ {
@ -397,3 +503,65 @@ void recordedMacroStep::PlayBack(Window* pNotepad, ScintillaEditView *pEditView)
} }
} }
} }
void ScintillaAccelerator::init(vector<HWND> * vScintillas, HMENU hMenu, HWND menuParent) {
_hAccelMenu = hMenu;
_hMenuParent = menuParent;
size_t nr = vScintillas->size();
for(size_t i = 0; i < nr; i++) {
_vScintillas.push_back(vScintillas->at(i));
}
_nrScintillas = (int)nr;
}
void ScintillaAccelerator::updateKeys() {
NppParameters *pNppParam = NppParameters::getInstance();
vector<ScintillaKeyMap> & map = pNppParam->getScintillaKeyList();
size_t mapSize = map.size();
for(int i = 0; i < _nrScintillas; i++) {
::SendMessage(_vScintillas[i], SCI_CLEARALLCMDKEYS, 0, 0);
for(size_t j = mapSize - 1; j >= 0; j--) { //reverse order, top of the list has highest priority
ScintillaKeyMap skm = map[j];
if (skm.isEnabled()) { //no validating, scintilla accepts more keys
::SendMessage(_vScintillas[i], SCI_ASSIGNCMDKEY, skm.toKeyDef(), skm.getScintillaKeyID());
}
if (skm.getMenuCmdID() != 0) {
updateMenuItemByID(skm, skm.getMenuCmdID());
}
if (j == 0) //j is unsigned, so default method doesnt work
break;
}
}
}
void ScintillaAccelerator::updateKey(ScintillaKeyMap skmOld, ScintillaKeyMap skmNew) {
updateKeys(); //do a full update, double mappings can make this work badly
return;
for(int i = 0; i < _nrScintillas; i++) {
::SendMessage(_vScintillas[i], SCI_CLEARCMDKEY, skmOld.toKeyDef(), 0);
::SendMessage(_vScintillas[i], SCI_ASSIGNCMDKEY, skmNew.toKeyDef(), skmNew.getScintillaKeyID());
}
}
void ScintillaAccelerator::updateMenuItemByID(ScintillaKeyMap skm, int id) {
NppParameters *pNppParam = NppParameters::getInstance();
char cmdName[64];
::GetMenuString(_hAccelMenu, id, cmdName, sizeof(cmdName), MF_BYCOMMAND);
int i = 0;
while(cmdName[i] != 0) {
if (cmdName[i] == '\t') {
cmdName[i] = 0;
break;
}
i++;
}
string menuItem = cmdName;
if (skm.isEnabled()) {
menuItem += "\t";
//menuItem += "Sc:"; //sc: scintilla shortcut
menuItem += skm.toString();
}
::ModifyMenu(_hAccelMenu, id, MF_BYCOMMAND, id, menuItem.c_str());
::DrawMenuBar(_hMenuParent);
}

View File

@ -29,26 +29,26 @@ using namespace std;
const size_t nameLenMax = 64; const size_t nameLenMax = 64;
enum ShortcutType {TYPE_CMD, TYPE_MACRO, TYPE_USERCMD, TYPE_PLUGINCMD, TYPE_INVALID}; class NppParameters;
void getKeyStrFromVal(unsigned char keyVal, string & str); void getKeyStrFromVal(unsigned char keyVal, string & str);
ShortcutType getNameStrFromCmd(DWORD cmd, string & str); void getNameStrFromCmd(DWORD cmd, string & str);
static int keyTranslate(int keyIn) { static int keyTranslate(int keyIn) {
switch (keyIn) { switch (keyIn) {
case VK_DOWN: return SCK_DOWN; case VK_DOWN: return SCK_DOWN;
case VK_UP: return SCK_UP; case VK_UP: return SCK_UP;
case VK_LEFT: return SCK_LEFT; case VK_LEFT: return SCK_LEFT;
case VK_RIGHT: return SCK_RIGHT; case VK_RIGHT: return SCK_RIGHT;
case VK_HOME: return SCK_HOME; case VK_HOME: return SCK_HOME;
case VK_END: return SCK_END; case VK_END: return SCK_END;
case VK_PRIOR: return SCK_PRIOR; case VK_PRIOR: return SCK_PRIOR;
case VK_NEXT: return SCK_NEXT; case VK_NEXT: return SCK_NEXT;
case VK_DELETE: return SCK_DELETE; case VK_DELETE: return SCK_DELETE;
case VK_INSERT: return SCK_INSERT; case VK_INSERT: return SCK_INSERT;
case VK_ESCAPE: return SCK_ESCAPE; case VK_ESCAPE: return SCK_ESCAPE;
case VK_BACK: return SCK_BACK; case VK_BACK: return SCK_BACK;
case VK_TAB: return SCK_TAB; case VK_TAB: return SCK_TAB;
case VK_RETURN: return SCK_RETURN; case VK_RETURN: return SCK_RETURN;
case VK_ADD: return SCK_ADD; case VK_ADD: return SCK_ADD;
case VK_SUBTRACT: return SCK_SUBTRACT; case VK_SUBTRACT: return SCK_SUBTRACT;
case VK_DIVIDE: return SCK_DIVIDE; case VK_DIVIDE: return SCK_DIVIDE;
@ -60,7 +60,9 @@ static int keyTranslate(int keyIn) {
default: return keyIn; default: return keyIn;
} }
}; };
struct Shortcut : public StaticDialog {
class Shortcut : public StaticDialog {
public:
char _name[nameLenMax]; char _name[nameLenMax];
bool _isCtrl; bool _isCtrl;
bool _isAlt; bool _isAlt;
@ -68,19 +70,21 @@ struct Shortcut : public StaticDialog {
unsigned char _key; unsigned char _key;
bool _canModifyName; bool _canModifyName;
Shortcut():_isCtrl(false), _isAlt(false), _isShift(false), _key(0), _canModifyName(true) {_name[0] = '\0';}; Shortcut():_isCtrl(false), _isAlt(false), _isShift(false), _key(0), _canModifyName(false) {_name[0] = '\0';};
Shortcut(const Shortcut & shortcut) { Shortcut(const Shortcut & shortcut) {
this->_isCtrl = shortcut._isCtrl; this->_isCtrl = shortcut._isCtrl;
this->_isAlt = shortcut._isAlt; this->_isAlt = shortcut._isAlt;
this->_isShift = shortcut._isShift; this->_isShift = shortcut._isShift;
this->_key = shortcut._key; this->_key = shortcut._key;
strcpy(this->_name, shortcut._name); strcpy(this->_name, shortcut._name);
this->_canModifyName = shortcut._canModifyName;
}; };
Shortcut(const char *name, bool isCtrl, bool isAlt, bool isShift, unsigned char key) :\ Shortcut(const char *name, bool isCtrl, bool isAlt, bool isShift, unsigned char key) :\
_isCtrl(isCtrl), _isAlt(isAlt), _isShift(isShift), _key(key){ _isCtrl(isCtrl), _isAlt(isAlt), _isShift(isShift), _key(key) {
_name[0] = '\0'; _name[0] = '\0';
if (name) if (name)
strcpy(_name, name); strcpy(_name, name);
this->_canModifyName = false;
}; };
friend inline const bool operator==(const Shortcut & a, const Shortcut & b) { friend inline const bool operator==(const Shortcut & a, const Shortcut & b) {
@ -107,25 +111,29 @@ struct Shortcut : public StaticDialog {
return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUT_DLG), _hParent, (DLGPROC)dlgProc, (LPARAM)this); return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUT_DLG), _hParent, (DLGPROC)dlgProc, (LPARAM)this);
}; };
bool isValid() const { bool isValid() const { //valid should only be used in cases where the shortcut isEnabled().
if (_key == 0) if (_key == 0)
return false; return true; //disabled key always valid, just disabled
// the following keys are always valid (NUMPAD & F1~F12 + ESC + HOME + END)
if (((_key >= 0x60) && (_key <= 0x69)) || ((_key >= 0x70) && (_key <= 0x7B)) || (_key == 0x1B) || (_key == 0x24) || (_key == 0x23)) //These keys need a modifier, else invalid
return true; if ( ((_key >= 'A') && (_key <= 'Z')) || ((_key >= '0') && (_key <= '9')) || _key == VK_SPACE || _key == VK_CAPITAL || _key == VK_BACK || _key == VK_RETURN) {
// the remain keys need at least Ctrl or Alt return ((_isCtrl) || (_isAlt));
if ((_isCtrl) || (_isAlt)) }
return true; // the remaining keys are always valid
return false; return true;
}; };
void setNameReadOnly(bool canBeModified = false) {_canModifyName = canBeModified;}; bool isEnabled() const { //true if key != 0, false if key == 0, in which case no accelerator should be made
string toString() const; return (_key != 0);
string toMenuItemString(int cmdID = 0) { };
string toString() const; //the hotkey part
string toMenuItemString(int cmdID = 0) { //string suitable for menu, uses menu to retrieve name if command is specified
string str = _name; string str = _name;
if (cmdID) if(isEnabled())
getNameStrFromCmd(cmdID, str); {
str += "\t"; str += "\t";
str += toString(); str += toString();
}
return str; return str;
}; };
protected : protected :
@ -135,33 +143,24 @@ protected :
class CommandShortcut : public Shortcut { class CommandShortcut : public Shortcut {
public: public:
CommandShortcut() : _id(0){}; CommandShortcut(Shortcut sc, long id) : Shortcut(sc), _id(id) {};
CommandShortcut(const char *name, unsigned long id, bool isCtrl, bool isAlt, bool isShift, unsigned char key) :\
Shortcut(name, isCtrl, isAlt, isShift, key), _id(id) {};
CommandShortcut(long id, Shortcut sc) : Shortcut(sc), _id(id) {};
unsigned long getID() const {return _id;}; unsigned long getID() const {return _id;};
void setID(unsigned long id) { _id = id;};
protected : protected :
unsigned long _id; unsigned long _id;
}; };
class ScintillaKeyMap : public CommandShortcut { class ScintillaKeyMap : public Shortcut {
public: public:
ScintillaKeyMap():_scintillaKeyID(0), _menuCmdID(0){}; ScintillaKeyMap(Shortcut sc, unsigned long scintillaKeyID, unsigned long id): Shortcut(sc), _menuCmdID(id), _scintillaKeyID(scintillaKeyID) {};
ScintillaKeyMap(unsigned long id): _scintillaKeyID(0), _menuCmdID(0){ _id = id;};
ScintillaKeyMap(const char *name, unsigned long id, unsigned long scintillaKeyID,\
bool isCtrl, bool isAlt, bool isShift, unsigned char key, int cmdID = 0) :\
CommandShortcut(name, id, isCtrl, isAlt, isShift, key), _scintillaKeyID(scintillaKeyID), _menuCmdID(cmdID){};
unsigned long getScintillaKeyID() const {return _scintillaKeyID;}; unsigned long getScintillaKeyID() const {return _scintillaKeyID;};
int getMenuCmdID() const {return _menuCmdID;};
int toKeyDef() const { int toKeyDef() const {
int keymod = (_isCtrl?SCMOD_CTRL:0) | (_isAlt?SCMOD_ALT:0) | (_isShift?SCMOD_SHIFT:0); int keymod = (_isCtrl?SCMOD_CTRL:0) | (_isAlt?SCMOD_ALT:0) | (_isShift?SCMOD_SHIFT:0);
return keyTranslate((int)_key) + (keymod << 16); return keyTranslate((int)_key) + (keymod << 16);
}; };
unsigned long getScintillaKey() const {return _scintillaKeyID;};
int getMenuCmdID() const {return _menuCmdID;};
void setScintKey(int key) {_scintillaKeyID = key;};
void setMenuID(int id) {_menuCmdID = id;};
private: private:
unsigned long _scintillaKeyID; unsigned long _scintillaKeyID;
@ -197,36 +196,30 @@ struct recordedMacroStep {
typedef vector<recordedMacroStep> Macro; typedef vector<recordedMacroStep> Macro;
class MacroShortcut : public Shortcut { class MacroShortcut : public CommandShortcut {
friend class NppParameters; friend class NppParameters;
public: public:
MacroShortcut(Shortcut sc) : Shortcut(sc) {}; MacroShortcut(Shortcut sc, Macro macro, int id) : CommandShortcut(sc, id), _macro(macro) {_canModifyName = true;};
MacroShortcut(Macro macro) : _macro(macro) {};
MacroShortcut(Shortcut sc, Macro macro) : Shortcut(sc), _macro(macro) {};
Macro & getMacro() {return _macro;}; Macro & getMacro() {return _macro;};
private: private:
Macro _macro; Macro _macro;
}; };
class UserCommand : public Shortcut { class UserCommand : public CommandShortcut {
friend class NppParameters; friend class NppParameters;
public: public:
UserCommand(Shortcut sc) : Shortcut(sc) {}; UserCommand(Shortcut sc, const char *cmd, int id) : CommandShortcut(sc, id), _cmd(cmd) {_canModifyName = true;};
UserCommand(char *cmd) : _cmd(cmd) {};
UserCommand(Shortcut sc, char *cmd) : Shortcut(sc), _cmd(cmd) {};
const char* getCmd() const {return _cmd.c_str();}; const char* getCmd() const {return _cmd.c_str();};
private: private:
string _cmd; string _cmd;
}; };
class PluginCmdShortcut : public Shortcut { class PluginCmdShortcut : public CommandShortcut {
friend class NppParameters; friend class NppParameters;
public: public:
PluginCmdShortcut(Shortcut sc) : Shortcut(sc), _id(0), _internalID(-1) {_moduleName[0] = '\0';}; PluginCmdShortcut(Shortcut sc, int id, const char *moduleName, unsigned short internalID) :\
PluginCmdShortcut(Shortcut sc, int cmdID) : Shortcut(sc), _id(cmdID), _internalID(-1) {_moduleName[0] = '\0';}; CommandShortcut(sc, id), _id(id), _internalID(internalID) {
PluginCmdShortcut(Shortcut sc, int cmdID, const char *moduleName, unsigned short internalID) :\
Shortcut(sc), _id(cmdID), _internalID(internalID) {
strcpy(_moduleName, moduleName); strcpy(_moduleName, moduleName);
}; };
bool isValid() const { bool isValid() const {
@ -246,30 +239,29 @@ protected :
int _internalID; int _internalID;
}; };
class Accelerator { class Accelerator { //Handles accelerator keys for Notepad++ menu, including custom commands
friend class ShortcutMapper; friend class ShortcutMapper;
public: public:
Accelerator():_hAccTable(NULL), _didCopy(false), _pAccelArray(NULL), _nbAccelItems(0){ Accelerator():_hAccelMenu(NULL), _hMenuParent(NULL), _hAccTable(NULL), _didCopy(false), _pAccelArray(NULL), _nbAccelItems(0){};
};
~Accelerator(){ ~Accelerator(){
if (_didCopy) if (_didCopy)
::DestroyAcceleratorTable(_hAccTable); ::DestroyAcceleratorTable(_hAccTable);
if (_pAccelArray)
delete [] _pAccelArray;
}; };
void init(HACCEL hAccel) { void init(HACCEL hAccel, HMENU hMenu, HWND menuParent) {
_hAccTable = hAccel; _hAccTable = hAccel;
_hAccelMenu = hMenu;
_hMenuParent = menuParent;
_nbOriginalAccelItem = ::CopyAcceleratorTable(_hAccTable, NULL, 0); _nbOriginalAccelItem = ::CopyAcceleratorTable(_hAccTable, NULL, 0);
}; };
HACCEL getAccTable() const {return _hAccTable;}; HACCEL getAccTable() const {return _hAccTable;};
bool uptdateShortcuts(HWND nppHandle = NULL); bool updateShortcuts(/*HWND nppHandle = NULL*/);
//bool updateCommand(CommandShortcut & csc);
void coloneAccelTable() {
copyAccelArray();
reNew();
};
private: private:
HMENU _hAccelMenu;
HWND _hMenuParent;
HACCEL _hAccTable; HACCEL _hAccTable;
bool _didCopy; bool _didCopy;
@ -277,19 +269,6 @@ private:
int _nbOriginalAccelItem; int _nbOriginalAccelItem;
int _nbAccelItems; int _nbAccelItems;
size_t copyAccelArray(int nbMacro2add = 0, int nbUserCmd2add = 0, int nbPluginCmd2add = 0) {
int newSize = _nbOriginalAccelItem + nbMacro2add + nbUserCmd2add + nbPluginCmd2add;
_nbAccelItems = newSize;
if (_pAccelArray)
delete [] _pAccelArray;
_pAccelArray = new ACCEL[_nbAccelItems];
::CopyAcceleratorTable(_hAccTable, _pAccelArray, _nbOriginalAccelItem);
return newSize;
};
void reNew() { void reNew() {
if (!_didCopy) if (!_didCopy)
_didCopy = true; _didCopy = true;
@ -298,6 +277,24 @@ private:
_hAccTable = ::CreateAcceleratorTable(_pAccelArray, _nbAccelItems); _hAccTable = ::CreateAcceleratorTable(_pAccelArray, _nbAccelItems);
}; };
void updateFullMenu();
void updateMenuItemByCommand(CommandShortcut csc);
};
class ScintillaAccelerator { //Handles accelerator keys for scintilla
public:
ScintillaAccelerator() : _nrScintillas(0) {};
void init(vector<HWND> * vScintillas, HMENU hMenu, HWND menuParent);
void updateKeys();
void updateKey(ScintillaKeyMap skmOld, ScintillaKeyMap skm);
private:
HMENU _hAccelMenu;
HWND _hMenuParent;
vector<HWND> _vScintillas;
int _nrScintillas;
void updateMenuItemByID(ScintillaKeyMap skm, int id);
}; };
#endif //SHORTCUTS_H #endif //SHORTCUTS_H

View File

@ -45,4 +45,6 @@ BEGIN
LTEXT "+",IDC_STATIC,96,42,8,8 LTEXT "+",IDC_STATIC,96,42,8,8
EDITTEXT IDC_NAME_EDIT,56,9,93,14,ES_AUTOHSCROLL EDITTEXT IDC_NAME_EDIT,56,9,93,14,ES_AUTOHSCROLL
LTEXT "Name :",IDC_NAME_STATIC,15,12,34,8,0,WS_EX_RIGHT LTEXT "Name :",IDC_NAME_STATIC,15,12,34,8,0,WS_EX_RIGHT
LTEXT "This will disable the accelerator!",IDC_WARNING_STATIC,
6,90,170,8
END END

View File

@ -27,5 +27,5 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define IDC_KEY_COMBO (IDD_SHORTCUT_DLG + 4) #define IDC_KEY_COMBO (IDD_SHORTCUT_DLG + 4)
#define IDC_NAME_EDIT (IDD_SHORTCUT_DLG + 5) #define IDC_NAME_EDIT (IDD_SHORTCUT_DLG + 5)
#define IDC_NAME_STATIC (IDD_SHORTCUT_DLG + 6) #define IDC_NAME_STATIC (IDD_SHORTCUT_DLG + 6)
#define IDC_WARNING_STATIC (IDD_SHORTCUT_DLG + 7)
#endif //IDD_SHORTCUT_DLG #endif //IDD_SHORTCUT_DLG

View File

@ -18,9 +18,9 @@
#ifndef RESOURCE_H #ifndef RESOURCE_H
#define RESOURCE_H #define RESOURCE_H
#define NOTEPAD_PLUS_VERSION "Notepad++ v4.7.5" #define NOTEPAD_PLUS_VERSION "Notepad++ v4.8"
#define VERSION_VALUE "4.75\0" // should be X.Y : ie. if VERSION_DIGITALVALUE == 4, 7, 1, 0 , then X = 4, Y = 71 #define VERSION_VALUE "4.8\0" // should be X.Y : ie. if VERSION_DIGITALVALUE == 4, 7, 1, 0 , then X = 4, Y = 71
#define VERSION_DIGITALVALUE 4, 7, 5, 0 #define VERSION_DIGITALVALUE 4, 8, 0, 0
#ifndef IDC_STATIC #ifndef IDC_STATIC
#define IDC_STATIC -1 #define IDC_STATIC -1
@ -175,10 +175,10 @@
#define IDC_PREV_DOC (IDCMD+3) #define IDC_PREV_DOC (IDCMD+3)
#define IDC_NEXT_DOC (IDCMD+4) #define IDC_NEXT_DOC (IDCMD+4)
#define IDC_EDIT_TOGGLEMACRORECORDING (IDCMD+5) #define IDC_EDIT_TOGGLEMACRORECORDING (IDCMD+5)
#define IDC_KEY_HOME (IDCMD+6) //#define IDC_KEY_HOME (IDCMD+6)
#define IDC_KEY_END (IDCMD+7) //#define IDC_KEY_END (IDCMD+7)
#define IDC_KEY_SELECT_2_HOME (IDCMD+8) //#define IDC_KEY_SELECT_2_HOME (IDCMD+8)
#define IDC_KEY_SELECT_2_END (IDCMD+9) //#define IDC_KEY_SELECT_2_END (IDCMD+9)
#define IDCMD_LIMIT (IDCMD+20) #define IDCMD_LIMIT (IDCMD+20)

View File

@ -580,10 +580,6 @@
RelativePath="..\src\resource.h" RelativePath="..\src\resource.h"
> >
</File> </File>
<File
RelativePath="..\src\WinControls\Preference\resource.h"
>
</File>
<File <File
RelativePath="..\src\WinControls\StaticDialog\RunDlg\RunDlg.h" RelativePath="..\src\WinControls\StaticDialog\RunDlg\RunDlg.h"
> >