From: <net...@us...> - 2003-01-09 21:19:25
|
Update of /cvsroot/cpptool/rfta/src/rftavc6addin In directory sc8-pr-cvs1:/tmp/cvs-serv31628/src/rftavc6addin Modified Files: How-To-Add-Commands.txt DSAddIn.h DSAddIn.cpp Log Message: -- some code refactoring Index: How-To-Add-Commands.txt =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/How-To-Add-Commands.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** How-To-Add-Commands.txt 9 Jan 2003 19:43:05 -0000 1.2 --- How-To-Add-Commands.txt 9 Jan 2003 21:19:20 -0000 1.3 *************** *** 34,75 **** Insert the following code for your addin function: ! ! { ! // ENTER HERE the ICommand function name you have choosen in Step 1) ! LPCTSTR szCommand = _T(" xxxxxxxxxxxxxxxx "); ! ! VARIANT_BOOL bRet; ! CString strCmdString; ! ! // ENTER HERE the StringTable Indentifier you have created in Step 2c) ! strCmdString.LoadString( xxxxxxxxxxxxxxxxx ); ! strCmdString = szCommand + strCmdString; ! CComBSTR bszCmdString(strCmdString); ! ! // ENTER HERE the ICommand function name you have choosen in Step 1) ! CComBSTR bszMethod(_T("RftaRenameLocaleVariable")); ! CComBSTR bszCmdName(szCommand); ! ! // ENTER HERE the correct index position of the icon in the toolbar ! VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, xxxxxx , m_dwCookie, &bRet)); ! if (bRet == VARIANT_FALSE) ! { ! // AddCommand failed because a command with this name already ! // exists. You may try adding your command under a different name. ! // Or, you can fail to load as we will do here. ! *OnConnection = VARIANT_FALSE; ! return S_OK; ! } ! ! // Add toolbar buttons only if this is the first time the add-in ! // is being loaded. Toolbar buttons are automatically remembered ! // by Developer Studio from session to session, so we should only ! // add the toolbar buttons once. ! if (bFirstTime == VARIANT_TRUE) ! { ! VERIFY_OK(pApplication-> ! AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie)); ! } } Step 5) --- 34,52 ---- Insert the following code for your addin function: ! --------------------------------------------------------------------- ! // COMMAND '>>> PLACE YOUR COMMENT HERE <<<' ! if (initAddinCommand( ! ! _T("RftaInlineLocaleVariable"), // <--- place your command name (of step1) here ! IDS_INLINELOCAL_INFO, // <--- place your command description (StringTable step 2) here ! 1, // <--- place the icon position in tool bar here ! ! pApplication, bFirstTime ! ) == S_FALSE) ! { ! *OnConnection = VARIANT_FALSE; ! return S_OK; } + --------------------------------------------------------------------- Step 5) Index: DSAddIn.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/DSAddIn.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DSAddIn.h 18 Dec 2002 22:53:27 -0000 1.1 --- DSAddIn.h 9 Jan 2003 21:19:20 -0000 1.2 *************** *** 39,42 **** --- 39,44 ---- CCommandsObj* m_pCommands; DWORD m_dwCookie; + + STDMETHOD(initAddinCommand)(THIS_ _TCHAR* _szCommand,UINT cmdInfoRes,UINT buttonIdx, IApplication* pApplication, VARIANT_BOOL bFirstTime ); }; Index: DSAddIn.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftavc6addin/DSAddIn.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DSAddIn.cpp 30 Dec 2002 10:43:26 -0000 1.2 --- DSAddIn.cpp 9 Jan 2003 21:19:20 -0000 1.3 *************** *** 44,152 **** (LPDISPATCH) m_pCommands, IDR_TOOLBAR_REFACTORING, IDR_TOOLBAR_REFACTORING, m_dwCookie)); ! // Inform DevStudio of the commands we implement ! ! // TODO: Replace the AddCommand call below with a series of calls, ! // one for each command your add-in will add. ! // The command name should not be localized to other languages. The ! // tooltip, command description, and other strings related to this ! // command are stored in the string table (IDS_CMD_STRING) and should ! // be localized. { ! LPCTSTR szCommand = _T("RftaRenameLocaleVariable"); ! VARIANT_BOOL bRet; ! CString strCmdString; ! strCmdString.LoadString(IDS_RENAMELOCAL_INFO); ! strCmdString = szCommand + strCmdString; ! CComBSTR bszCmdString(strCmdString); ! CComBSTR bszMethod(_T("RftaRenameLocaleVariable")); ! CComBSTR bszCmdName(szCommand); ! VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, 0, m_dwCookie, &bRet)); ! if (bRet == VARIANT_FALSE) ! { ! // AddCommand failed because a command with this name already ! // exists. You may try adding your command under a different name. ! // Or, you can fail to load as we will do here. ! *OnConnection = VARIANT_FALSE; ! return S_OK; ! } ! ! // Add toolbar buttons only if this is the first time the add-in ! // is being loaded. Toolbar buttons are automatically remembered ! // by Developer Studio from session to session, so we should only ! // add the toolbar buttons once. ! if (bFirstTime == VARIANT_TRUE) ! { ! VERIFY_OK(pApplication-> ! AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie)); ! } } ! // The command name should not be localized to other languages. The ! // tooltip, command description, and other strings related to this ! // command are stored in the string table (IDS_CMD_STRING) and should ! // be localized. { ! LPCTSTR szCommand = _T("RftaInlineLocaleVariable"); ! VARIANT_BOOL bRet; ! CString strCmdString; ! strCmdString.LoadString(IDS_INLINELOCAL_INFO); ! strCmdString = szCommand + strCmdString; ! CComBSTR bszCmdString(strCmdString); ! CComBSTR bszMethod(_T("RftaInlineLocaleVariable")); ! CComBSTR bszCmdName(szCommand); ! VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, 1, m_dwCookie, &bRet)); ! if (bRet == VARIANT_FALSE) ! { ! // AddCommand failed because a command with this name already ! // exists. You may try adding your command under a different name. ! // Or, you can fail to load as we will do here. ! *OnConnection = VARIANT_FALSE; ! return S_OK; ! } ! ! // Add toolbar buttons only if this is the first time the add-in ! // is being loaded. Toolbar buttons are automatically remembered ! // by Developer Studio from session to session, so we should only ! // add the toolbar buttons once. ! if (bFirstTime == VARIANT_TRUE) ! { ! VERIFY_OK(pApplication-> ! AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie)); ! } } ! // The command name should not be localized to other languages. The ! // tooltip, command description, and other strings related to this ! // command are stored in the string table (IDS_CMD_STRING) and should ! // be localized. { ! LPCTSTR szCommand = _T("RftaSplitLocaleVariable"); ! VARIANT_BOOL bRet; ! CString strCmdString; ! strCmdString.LoadString(IDS_SPLITLOCAL_INFO); ! strCmdString = szCommand + strCmdString; ! CComBSTR bszCmdString(strCmdString); ! CComBSTR bszMethod(_T("RftaSplitLocaleVariable")); ! CComBSTR bszCmdName(szCommand); ! VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, 2, m_dwCookie, &bRet)); ! if (bRet == VARIANT_FALSE) ! { ! // AddCommand failed because a command with this name already ! // exists. You may try adding your command under a different name. ! // Or, you can fail to load as we will do here. ! *OnConnection = VARIANT_FALSE; ! return S_OK; ! } ! ! // Add toolbar buttons only if this is the first time the add-in ! // is being loaded. Toolbar buttons are automatically remembered ! // by Developer Studio from session to session, so we should only ! // add the toolbar buttons once. ! if (bFirstTime == VARIANT_TRUE) ! { ! VERIFY_OK(pApplication-> ! AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie)); ! } } --- 44,74 ---- (LPDISPATCH) m_pCommands, IDR_TOOLBAR_REFACTORING, IDR_TOOLBAR_REFACTORING, m_dwCookie)); ! // Inform DevStudio of the commands we implement ! // COMMAND 'RENAME-LOCAL' ! if (initAddinCommand( ! _T("RftaRenameLocaleVariable"), IDS_RENAMELOCAL_INFO, 0, pApplication, bFirstTime ! ) == S_FALSE) { ! *OnConnection = VARIANT_FALSE; ! return S_OK; } ! // COMMAND 'INLINE-LOCAL' ! if (initAddinCommand( ! _T("RftaInlineLocaleVariable"), IDS_INLINELOCAL_INFO, 1, pApplication, bFirstTime ! ) == S_FALSE) { ! *OnConnection = VARIANT_FALSE; ! return S_OK; } ! // COMMAND 'SPLIT-LOCAL' ! if (initAddinCommand( ! _T("RftaSplitLocaleVariable"), IDS_SPLITLOCAL_INFO, 2, pApplication, bFirstTime ! ) == S_FALSE) { ! *OnConnection = VARIANT_FALSE; ! return S_OK; } *************** *** 168,169 **** --- 90,128 ---- return S_OK; } + + STDMETHODIMP CDSAddIn::initAddinCommand(_TCHAR* _szCommand,UINT cmdInfoRes,UINT buttonIdx, IApplication* pApplication, VARIANT_BOOL bFirstTime) + { + // The command name should not be localized to other languages. The + // tooltip, command description, and other strings related to this + // command are stored in the string table (IDS_CMD_STRING) and should + // be localized. + LPCTSTR szCommand = _T(_szCommand); + VARIANT_BOOL bRet; + CString strCmdString; + strCmdString.LoadString(cmdInfoRes); + strCmdString = szCommand + strCmdString; + CComBSTR bszCmdString(strCmdString); + CComBSTR bszMethod(_T(_szCommand)); + CComBSTR bszCmdName(szCommand); + VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, buttonIdx, m_dwCookie, &bRet)); + if (bRet == VARIANT_FALSE) + { + // AddCommand failed because a command with this name already + // exists. You may try adding your command under a different name. + // Or, you can fail to load as we will do here. + return S_FALSE; + } + + // Add toolbar buttons only if this is the first time the add-in + // is being loaded. Toolbar buttons are automatically remembered + // by Developer Studio from session to session, so we should only + // add the toolbar buttons once. + if (bFirstTime == VARIANT_TRUE) + { + VERIFY_OK(pApplication-> + AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie)); + } + + return S_OK; + + } \ No newline at end of file |