From 58a49721a4ec0567481558c244890e4f3d447b19 Mon Sep 17 00:00:00 2001 From: Kazuhiro Fujieda Date: Fri, 8 Jul 2011 10:25:39 +0900 Subject: [PATCH] Use LPCSTR instead of CString in arguments of SaveKeyBind, SaveCommand and AddKeyBind2C_ of CProfile. Change the return type of CCommands::GetCommandName to LPCSTR. Shorten variable names in these functions. --- xkeymacs/profile.cpp | 43 ++++++++++++++++--------------------------- xkeymacs/profile.h | 12 ++++++------ xkeymacsdll/Commands.cpp | 5 ++--- xkeymacsdll/Commands.h | 2 +- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/xkeymacs/profile.cpp b/xkeymacs/profile.cpp index d003ae4..923ff43 100644 --- a/xkeymacs/profile.cpp +++ b/xkeymacs/profile.cpp @@ -734,50 +734,39 @@ BOOL CProfile::IsCommandType(const int nType, LPCTSTR szKeyBind) return FALSE; } -void CProfile::SaveKeyBind(const CString szApplicationName, const int nComID, const int nType, const int nKey) +void CProfile::SaveKeyBind(const LPCSTR szAppName, const int nComID, const int nType, const int nKey) { - if (!nComID) { + if (!nComID) return; - } - - CString szCommandName = CCommands::GetCommandName(nComID); - if (szCommandName.IsEmpty()) { + const LPCSTR szComName = CCommands::GetCommandName(nComID); + if (!szComName[0]) return; - } - - SaveKeyBind(szApplicationName, szCommandName, nType, nKey); + SaveKeyBind(szAppName, szComName, nType, nKey); } -void CProfile::SaveKeyBind(const CString szApplicationName, const CString szCommandName, const int nType, const int nKey) +void CProfile::SaveKeyBind(const LPCSTR szAppName, const LPCSTR szComName, const int nType, const int nKey) { - CString szKeyBind = WriteKeyBind(nType, nKey); - CString szSubKey(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)); - szSubKey += _T("\\") + szApplicationName + _T("\\") + szCommandName; - if (!szKeyBind.IsEmpty()) { + const CString szKeyBind = WriteKeyBind(nType, nKey); + CString szSubKey = CString(MAKEINTRESOURCE(IDS_REGSUBKEY_DATA)) + _T("\\") + szAppName + _T("\\") + szComName; + if (!szKeyBind.IsEmpty()) szSubKey += _T("\\") + szKeyBind; - } - HKEY hKey = NULL; - if (RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS) { + if (RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS) RegCloseKey(hKey); - } } -void CProfile::SaveCommand(const CString szApplicationName, const int nComID) +void CProfile::SaveCommand(const LPCSTR szAppName, const int nComID) { - SaveKeyBind(szApplicationName, nComID, 0, 0); + SaveKeyBind(szAppName, nComID, 0, 0); } -void CProfile::AddKeyBind2C_(const CString szApplicationName, const BYTE bVk) +void CProfile::AddKeyBind2C_(const LPCSTR szAppName, const BYTE bVk) { int nComID; - for (nComID = 0; nComID < MAX_COMMAND; ++nComID) { - if (Commands[nComID].fCommand == CCommands::C_) { + for (nComID = 0; nComID < MAX_COMMAND; ++nComID) + if (Commands[nComID].fCommand == CCommands::C_) break; - } - } - - SaveKeyBind(szApplicationName, nComID, NONE, bVk); + SaveKeyBind(szAppName, nComID, NONE, bVk); } void CProfile::LevelUp() diff --git a/xkeymacs/profile.h b/xkeymacs/profile.h index 6b4b4dc..2adfc4d 100644 --- a/xkeymacs/profile.h +++ b/xkeymacs/profile.h @@ -64,12 +64,12 @@ public: static void SaveData(); private: - static void SaveKeyBind(CString szApplicationName, CString szCommandName, int nType, int nKey); + static void SaveKeyBind(const LPCSTR szAppName, const LPCSTR szComName, int nType, int nKey); static BOOL DiableTokenPrivileges(); static BOOL AdjustTokenPrivileges(LPCTSTR lpName); - static void SaveCommand(CString szApplicationName, int nComID); - static void SaveKeyBind(CString szApplicationName, int nComID, int nType, int nKey); - static void AddKeyBind2C_(CString szApplicationName, BYTE bVk); + static void SaveCommand(const LPCSTR szAppName, int nComID); + static void SaveKeyBind(const LPCSTR szAppName, int nComID, int nType, int nKey); + static void AddKeyBind2C_(const LPCSTR szApplicationName, BYTE bVk); static void LevelUp(); static void Item2AppName(CString *sz); static int IsNotSameString(CComboBox *pApplication, CString szListItem); @@ -86,8 +86,8 @@ private: static DWORD m_dwTasks; static void GetTaskList(); static BOOL IsCommandType(int nType, LPCTSTR szKeyBind); - static int KeyBind2Key(LPCTSTR szKey); - static int KeyBind2CommandType(LPCTSTR szKeyBind); + static int KeyBind2Key(const LPCTSTR szKey); + static int KeyBind2CommandType(const LPCTSTR szKeyBind); static CString WriteKeyBind(int nType, int nKey); static void LoadRegistry(); static void SaveRegistry(); diff --git a/xkeymacsdll/Commands.cpp b/xkeymacsdll/Commands.cpp index d4342df..9c937c7 100644 --- a/xkeymacsdll/Commands.cpp +++ b/xkeymacsdll/Commands.cpp @@ -4020,10 +4020,9 @@ int CCommands::ExecuteExtendedCommand() return Reset(GOTO_HOOKX); } -CString CCommands::GetCommandName(int nComID) +LPCSTR CCommands::GetCommandName(int nComID) { - CString szCommandName(Commands[nComID].szCommandName); - return szCommandName; + return Commands[nComID].szCommandName; } int CCommands::GetCategoryID(int nComID) diff --git a/xkeymacsdll/Commands.h b/xkeymacsdll/Commands.h index 540296f..1e929c6 100644 --- a/xkeymacsdll/Commands.h +++ b/xkeymacsdll/Commands.h @@ -169,7 +169,7 @@ public: static int BackwardChar(); static int BeginningOfLine(); static int ForwardChar(); - static CString GetCommandName(int nComID); + static LPCSTR GetCommandName(int nComID); static int GetCategoryID(int nComID); static int GetDescriptionID(int nComID); static int GetToolTipID(int nComID); -- 2.11.0