问题描述
我正在编写一个Outlook加载项,它具有自己的功能区,并在xml清单中定义了按钮。除了Outlook主窗口(浏览器)以外,还可以打开单独的窗口(检查器),并且所有窗口都具有相同的功能区。我想独立控制功能区按钮的属性。但是在我的getpressed
按钮处理程序中,我总是得到相同的功能区对象。 OnRibbonLoad
始终仅被调用一次。因此,我想假设地看到的是,功能区的数量与那里的检查员(+资源管理器)的数量一样多。就行为而言:假设一个浏览器显示了一封电子邮件,并且其中还有一个检查器,其中有另一封电子邮件。两个窗口都具有相同的功能区,但是我希望能够分别启用/禁用每个窗口中的按钮。
这是我的清单:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnRibbonLoad">
<ribbon>
<tabs>
<tab idMso="%1">
<group id="addin_group" label="Title" getimage="GetAddinGroupImage">
<toggleButton id="addin-enable-toggle"
size="large"
getLabel="GetAddinEnabledStatusLabel"
onAction="OnAddinToggled"
getpressed="GetAddinEnabled"
getimage="GetAddinEnabledImage"
getEnabled="GetAddinTogglePermission"
/>
<button id="ButtonSetting"
getimage="GetSettingButtonImage"
size="large"
label="Configure"
screentip="Configure"
supertip="Opens the configuration dialog."
onAction="OnSettingButtonClicked"
getEnabled="GetAddinValid"
/>
<button id="ButtonRefresh"
getimage="GetRefreshButtonImage"
size="large"
label="Refresh"
screentip="Refresh scan result"
supertip="Remeasure the threat level of the current item."
onAction="OnRefreshMailResults"
getEnabled="GetAddinValid"
/>
<button id="ButtonReport"
getimage="GetButtonReportimage"
size="large"
label="Report"
screentip="Report mail"
supertip="Reports the opened mail."
onAction="OnButtonReportpressed"
getEnabled="GetEmailReportingEnabled"
/>
<button id="ButtonUnlock"
getimage="GetButtonUnlockImage"
size="large"
label="Unlock"
screentip="Unlock mail"
supertip="Unlocks the opened mail."
onAction="OnButtonUnlockpressed"
getEnabled="GetEmailUnlockingEnabled"
/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
根据我在IRibbonExtensibility :: getCustomUI函数中得到的%1
值,在<tab idMso="%1">
或TabReadMessage
上替换了TabMail
中的 ribbonId
:
//IRibbonExtensibility Methods
STDMETHODIMP CConnect::GetCustomUI(BSTR RibbonID,BSTR *RibbonXml)
{
if(!RibbonXml)
{
return E_POINTER;
}
//Get the ID of the ribbon that a custom UI is being requested for
QString ribbonIdStr = BSTR2QString(RibbonID);
static QMap<QString,QString> ribbonViews;
if(ribbonViews.isEmpty()) { //initialize
ribbonViews["Microsoft.Outlook.Mail.Read"] = "TabReadMessage";
ribbonViews["Microsoft.Outlook.Explorer"] = "TabMail";
}
if(ribbonViews.contains(ribbonIdStr)) {
*RibbonXml = XmlResource2ComBSTR(ASSET_RIBBON_MANIFEST,&ribbonViews[ribbonIdStr]);
}
return S_OK;
}
解决方法
触发控件回调(onAction,getImage,getEnabled等)时,您将收到IRibbonControl
作为参数。 IRibbonControl.Context
属性将是Explorer
或Inspector
对象,从那里您可以进入Inspector.CurrentItem
或Explorer.Selection
以逐项执行操作。