【问题标题】:Control ribbon buttons for each opened window separately分别控制每个打开的窗口的功能区按钮
【发布时间】:2020-08-27 07:37:02
【问题描述】:

我正在编写一个 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> 

&lt;tab idMso="%1"&gt; 中的%1TabReadMessageTabMail 替换,具体取决于我在 IRibbonExtensibility::getCustomUI 函数中获得的 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;
}

【问题讨论】:

    标签: vsto outlook-addin


    【解决方案1】:

    当触发控件回调(onAction、getImage、getEnabled 等)时,您将收到IRibbonControl 作为参数。 IRibbonControl.Context 属性将是 ExplorerInspector 对象,从那里您可以访问 Inspector.CurrentItemExplorer.Selection 以针对每个项目执行操作。

    【讨论】:

    • 似乎是我要找的。我错误地认为回调的ribbon 参数属于IRibbonUI,我在加载项初始化期间已经将其保存在其他地方。我还有一个问题。当我调用IRibbonUI::Invalidate 时,它只会使顶级窗口的功能区无效。是否有机会触发不在焦点中的窗口失效?
    • 您是否将任何参数传递给 Invalidate?
    • 我使用不带参数的 Invalidate。刚刚用TabReadMessageTabMail 尝试了InvalidateControlMso,但现在按钮回调getEnabled 甚至没有调用其他函数
    • 当你切换到那个(非活动的)检查器时它会被调用吗?
    • 感谢您的帮助。感谢您提供如此出色的插件!当我处理 Outlook 对象模型时,再好不过了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多