📄 addincommandmanager.cpp
字号:
352, // Use a red lightbulb to indicate there's a problem!
NULL,
lStatus);
}
// IfNullIssueError(ptrCommand);
if (!sKeyBinding.IsEmpty() )
{
ptrCommand->PutBindings( CComVariant(sKeyBinding) );
}
}
catch (const _com_error& e)
{
UNREFERENCED_PARAMETER(e);
}
try
{
if (ptrCommand == NULL)
{
EnvDTE::CommandsPtr ptrCommands = m_pDTE->GetCommands();
ptrCommand = ptrCommands->Item( _variant_t( _T("VisualLint.") + sCmd), 0);
}
}
catch (const _com_error& e)
{
UNREFERENCED_PARAMETER(e);
}
return ptrCommand;
} //lint !e1762: (Info -- Member function could be made const)
// Load a newline delimited specification for a command
bool CAddInCommandManager::LoadCommandSpec( UINT uResourceID,
CString& rsCmd,
CString& rsButtonText,
CString& rsToolTip,
CString& rsKeyBinding,
bool& rbHasBitmap) const
{
CString sSpecification;
sSpecification.LoadString(uResourceID);
if (!sSpecification.IsEmpty() )
{
rsCmd = ::Chomp( sSpecification,_T("\n") );
rsButtonText = ::Chomp( sSpecification,_T("\n") );
rsToolTip = ::Chomp( sSpecification,_T("\n") );
rsKeyBinding = ::Chomp( sSpecification,_T("\n") );
// Work out whether this command has a bitmap icon
WTL::CBitmap bitmap;
rbHasBitmap = (NULL != bitmap.LoadBitmap(uResourceID) );
rbHasBitmap = true;
//rbHasBitmap = ::LoadBitmap(hInstance, MAKEINTRESOURCE(uResourceID) );
return !rsCmd.IsEmpty();
}
return false;
}
IDispatchPtr CAddInCommandManager::GetCommandBar(const CString& sTitle) const
{
IDispatchPtr ptrCommandBar;
try
{
//Microsoft_VisualStudio_CommandBars::_CommandBarsPtr ptrCommandBars2 = m_pDTE->GetCommandBars();
//if (ptrCommandBars2 != NULL)
//{
// ptrCommandBar = ptrCommandBars2->GetItem(CComVariant( (LPCTSTR)sTitle) );
//}
//else
{
Office::_CommandBarsPtr ptrCommandBars = m_pDTE->GetCommandBars();
//IfNullIssueError(ptrCommandBars);
ptrCommandBar = ptrCommandBars->GetItem(CComVariant( (LPCTSTR)sTitle) );
}
}
catch (const _com_error& e)
{
UNREFERENCED_PARAMETER(e);
}
return ptrCommandBar;
}
IDispatchPtr CAddInCommandManager::AddCommandBar( const CString& sTitle,
EnvDTE::vsCommandBarType eType,
const IDispatchPtr& ptrParent,
long lPosition)
{
IDispatchPtr ptrCommandBar;
try
{
EnvDTE::CommandsPtr ptrCommands = m_pDTE->GetCommands();
//IfNullIssueError(ptrCommands);
ptrCommandBar = ptrCommands->AddCommandBar( _bstr_t(sTitle),
eType,
(Office::CommandBarPtr)ptrParent,
lPosition);
}
catch (const _com_error& e)
{
UNREFERENCED_PARAMETER(e);
}
return ptrCommandBar;
} //lint !e1762 (Info -- Member function could be made const)
HRESULT CAddInCommandManager::RemoveCommandBar(const IDispatchPtr& ptrCommandBar)
{
HRESULT hr = E_FAIL;
if (ptrCommandBar != NULL) //lint !e1561 (Warning -- Reference initialization causes loss of const/volatile integrity (arg. no. 1))
{
try
{
EnvDTE::CommandsPtr ptrCommands = m_pDTE->GetCommands();
//Office::CommandBarPtr ptrMsoCommandBar;
//ptrCommandBar->QueryInterface(&ptrMsoCommandBar);
//if (ptrMsoCommandBar != NULL)
//{
// hr = ptrCommands->RemoveCommandBar(ptrMsoCommandBar);
//}
//else
{
hr = ptrCommands->RemoveCommandBar( (Office::CommandBarPtr)ptrCommandBar);
}
}
catch (const _com_error& e)
{
UNREFERENCED_PARAMETER(e);
}
}
return hr;
} //lint !e1762 (Info -- Member function could be made const)
HRESULT CAddInCommandManager::AddCommandToCommandBar( const IDispatchPtr& ptrCommandBar,
const EnvDTE::CommandPtr& ptrCommand,
LONG lPos,
bool bBeginGroupBefore /*= false*/)
{
try
{
//EnvDTE80::Commands2Ptr ptrCommands2 = m_pDTE->GetCommands();
//if (ptrCommands2 != NULL)
//{
// Microsoft_VisualStudio_CommandBars::CommandBarControlPtr ptrControl80 = ptrCommand->AddControl(ptrCommandBar, lPos);
// ATLASSERT(ptrControl80 != NULL);
// IfNullIssueError(ptrControl80);
// if (bBeginGroupBefore)
// {
// ptrControl80->PutBeginGroup(VARIANT_TRUE);
// }
// Microsoft_VisualStudio_CommandBars::_CommandBarButtonPtr ptrButton(ptrControl80);
// ATLASSERT(ptrButton != NULL);
// if (ptrButton != NULL)
// {
// // This is temporary code to deal with the fact that VS2005 Beta 2 doesn't handle
// // images properly. For now, add them directly - although they will have a green
// // background as I haven't been able to get the mask working properly [Anna 19.6.2005].
// DoVs2005Beta2CommandBitmapBodge(ptrCommand, ptrButton);
// ptrButton->PutStyle(Microsoft_VisualStudio_CommandBars::msoButtonAutomatic);
// }
//}
//else
{
// VS2002 and 2003
Office::CommandBarControlPtr ptrControl = ptrCommand->AddControl(ptrCommandBar, lPos);
if (bBeginGroupBefore)
{
ptrControl->PutBeginGroup(VARIANT_TRUE);
}
Office::_CommandBarButtonPtr ptrButton(ptrControl);
if (ptrButton != NULL)
{
ptrButton->PutStyle(Office::msoButtonAutomatic);
}
}
}
catch (const _com_error& e)
{
HRESULT hr = e.Error();
return hr;
}
return S_OK;
} //lint !e1762: (Info -- Member function could be made const)
HRESULT CAddInCommandManager::RemoveCommands(void)
{
HRESULT hr = S_OK;
// Find our named commands and remove them
for (CAddInCommandHandlerMap::const_iterator it = m_mapCmdHandlers.begin();
it != m_mapCmdHandlers.end();
it++)
{
RemoveCommand(it->first);
}
CString sTitle;
ATLVERIFY( sTitle.LoadString(IDS_PROJNAME) );
// Find our menu bar & toolbar and remove them
// TODO: Change the way we locate these so we don't have to search on name alone
IDispatchPtr ptrAddInMenubar = GetCommandBar(sTitle);
if (ptrAddInMenubar != NULL)
{
RemoveCommandBar(ptrAddInMenubar);
}
IDispatchPtr ptrAddInToolbar = GetCommandBar(sTitle);
if (ptrAddInToolbar != NULL)
{
RemoveCommandBar(ptrAddInToolbar);
}
return hr;
}
HRESULT CAddInCommandManager::RemoveCommand(_bstr_t bsCommandName)
{
try
{
EnvDTE::CommandsPtr ptrCommands = m_pDTE->GetCommands();
EnvDTE::CommandPtr ptrCommand = ptrCommands->Item( CComVariant( CComBSTR(bsCommandName.GetBSTR() ) ), 0);
// IfNullIssueError(ptrCommand);
ptrCommand->Delete();
}
catch (const _com_error& e)
{
return e.Error();
}
return S_OK;
} //lint !e1762: (Info -- Member function could be made const)
/// This is temporary code to deal with the fact that VS2005 Beta 2 doesn't handle
/// images properly. For now, add them directly - via the CommandBarButton interface.
///
/// A mask is also set to ensure that the background of the bitmap images are
/// displayed correctly [Anna 16.8.2005].
///
//HRESULT CAddInCommandManager::DoVs2005Beta2CommandBitmapBodge(
// const EnvDTE::CommandPtr& ptrCommand,
// const Microsoft_VisualStudio_CommandBars::_CommandBarButtonPtr& ptrButton)
//{
// LOG_METHOD();
//
// if (ptrButton != NULL) //lint !e1561 (Warning -- Reference initialization causes loss of const/volatile integrity (arg. no. 1))
// {
// // This is temporary code to deal with the fact that VS2005 Beta 2 doesn't handle
// // images properly. For now, add them directly - although they will have a green
// // background as I haven't been able to get the mask working properly [Anna 19.6.2005].
// UINT uID = 0;
// UINT uMaskID = 0;
// CString sCommand = (LPCTSTR)ptrCommand->GetName();
//
// if ( _T("VisualLint.ConfigWizard") == sCommand)
// {
// uID = IDR_CMD_CONFIG_WIZARD;
// uMaskID = IDB_CMD_CONFIG_WIZARD_MASK;
// }
// else if ( _T("VisualLint.EditStdLnt") == sCommand)
// {
// uID = IDR_CMD_EDIT_STD_LNT;
// uMaskID = IDB_CMD_EDIT_STD_LNT_MASK;
// }
// else if ( _T("VisualLint.EditLintOptions") == sCommand)
// {
// uID = IDR_CMD_EDIT_PCLINT_OPTIONS;
// uMaskID = IDB_CMD_EDIT_PCLINT_OPTIONS_MASK;
// }
// else if ( _T("VisualLint.AnalyseCurrentFile") == sCommand)
// {
// uID = IDR_CMD_ANALYSE_CURRENT_FILE;
// uMaskID = IDB_CMD_ANALYSE_CURRENT_FILE_MASK;
// }
// else if ( _T("VisualLint.ViewLintAnalysisStatusDisplay") == sCommand)
// {
// uID = IDR_CMD_VIEW_ANALYSIS_STATUS_TOOLWINDOW;
// uMaskID = IDB_CMD_VIEW_ANALYSIS_STATUS_TOOLWINDOW_MASK;
// }
// else if ( _T("VisualLint.ViewLintAnalysisResultsDisplay") == sCommand)
// {
// uID = IDR_CMD_VIEW_ANALYSIS_RESULTS_TOOLWINDOW;
// uMaskID = IDB_CMD_VIEW_ANALYSIS_RESULTS_TOOLWINDOW_MASK;
// }
// else if ( _T("VisualLint.ViewLintWarningLookupDisplay") == sCommand)
// {
// uID = IDR_CMD_VIEW_WARNING_LOOKUP_TOOLWINDOW;
// uMaskID = IDB_CMD_VIEW_WARNING_LOOKUP_TOOLWINDOW_MASK;
// }
// else if ( _T("VisualLint.ViewLintManual") == sCommand)
// {
// uID = IDR_CMD_VIEW_PCLINT_MANUAL;
// uMaskID = IDB_CMD_VIEW_PCLINT_MANUAL_MASK;
// }
// else if ( _T("VisualLint.LintAnalysisReport") == sCommand)
// {
// uID = IDR_CMD_VIEW_REPORT;
// uMaskID = IDB_CMD_VIEW_REPORT_MASK;
// }
// else if ( _T("VisualLint.StopBackgroundAnalysis") == sCommand)
// {
// uID = IDR_CMD_ANALYSIS_STOP;
// uMaskID = IDB_CMD_ANALYSIS_STOP_MASK;
// }
// else if ( _T("VisualLint.PauseBackgroundAnalysis") == sCommand)
// {
// uID = IDR_CMD_ANALYSIS_PAUSE;
// uMaskID = IDB_CMD_ANALYSIS_PAUSE_MASK;
// }
// else if ( _T("VisualLint.RunBackgroundAnalysis") == sCommand)
// {
// uID = IDR_CMD_ANALYSIS_RUN;
// uMaskID = IDB_CMD_ANALYSIS_RUN_MASK;
// }
// else if ( _T("VisualLint.CleanAnalysisResults") == sCommand)
// {
// uID = IDR_CMD_ANALYSIS_CLEAN;
// uMaskID = IDB_CMD_ANALYSIS_CLEAN_MASK;
// }
// else if ( _T("VisualLint.ViewReadme") == sCommand)
// {
// uID = IDR_CMD_VIEW_README;
// uMaskID = IDB_CMD_VIEW_README_MASK;
// }
// else if ( _T("VisualLint.AboutBox") == sCommand)
// {
// uID = IDR_CMD_ABOUTBOX;
// uMaskID = IDB_CMD_ABOUTBOX_MASK;
// }
//
// if (uID > 0)
// {
// // Most of the following is temporary code to handle the fact that VS2005 Beta 2
// // doesn't allow custom images to be associated with commands.
// //
// // First retrieve the path of the satellite DLL, which holds the command bitmaps
// _bstr_t bsUIPath;
// HRESULT hr = m_pAddInInstance->get_SatelliteDllPath(&bsUIPath.GetBSTR());
// ATLASSERT( SUCCEEDED(hr) );
//
// HINSTANCE hResInstance = ::LoadLibrary( (LPCTSTR)bsUIPath );
// ATLASSERT( NULL != hResInstance);
//
// // Load and set the command bitmap
// PICTDESC pd;
// pd.cbSizeofstruct = sizeof(PICTDESC);
// pd.picType = PICTYPE_BITMAP;
//
// pd.bmp.hbitmap = ::LoadResourceBitmap( hResInstance,
// MAKEINTRESOURCE(uID),
// &pd.bmp.hpal);
//
// //lint -save -e929 (Note -- cast from pointer to pointer)
// Picture* pPictureDisp;
// ::OleCreatePictureIndirect(&pd, IID_IPictureDisp, FALSE, (LPVOID*)&pPictureDisp);
// //lint -restore
//
// ptrButton->PutPicture(pPictureDisp);
// pPictureDisp->Release();
//
// // We no longer need the original copies of the bitmap and palette so close the handles [IMS ID 18]
// ::DeleteObject(pd.bmp.hbitmap);
// ::DeleteObject(pd.bmp.hpal);
//
// // If we have a mask bitmap, set that too
// if (uMaskID > 0)
// {
// PICTDESC pdMask;
// pdMask.cbSizeofstruct = sizeof(PICTDESC);
// pdMask.picType = PICTYPE_BITMAP;
//
// pdMask.bmp.hbitmap = ::LoadResourceBitmap( hResInstance,
// MAKEINTRESOURCE(uMaskID),
// &pdMask.bmp.hpal);
//
// //lint -save -e929 (Note -- cast from pointer to pointer)
// Picture* pPictureDispMask;
// ::OleCreatePictureIndirect(&pdMask, IID_IPictureDisp, FALSE, (LPVOID*)&pPictureDispMask);
// //lint -restore
//
// ptrButton->PutMask(pPictureDispMask);
// pPictureDispMask->Release();
//
// ::DeleteObject(pdMask.bmp.hbitmap);
// ::DeleteObject(pdMask.bmp.hpal);
// }
// ::FreeLibrary(hResInstance);
// }
// }
// return S_OK;
//} //lint !e1762 (Info -- Member function could be made const)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -