From 1a9ca2d2ad309de387743f8a5d7eb34f8ce7164d Mon Sep 17 00:00:00 2001 From: PointStar Date: Tue, 12 May 2026 20:26:50 +0300 Subject: [PATCH] =?UTF-8?q?fix(ribbon):=20invalidate=20"=D7=A9=D7=9E=D7=95?= =?UTF-8?q?=D7=A8=20=D7=A7=D7=91=D7=A6=D7=99=D7=9D"=20on=20SelectionChange?= =?UTF-8?q?=20(button=20stays=20disabled)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new SaveAttachments button rendered but stayed greyed out. Cause: getEnabled callbacks are evaluated once when the ribbon loads and the result is cached — Office only re-asks if you explicitly invalidate the control. The previous SelectionChange handler invalidated only FileToEspoCrm. Collected the selection-dependent button IDs into a static array and made the SelectionChange handler invalidate all of them. Adding more context-sensitive buttons in the future is now a one-line edit. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/OutlookAddin/OutlookAddin.csproj | 5 +---- src/OutlookAddin/Ribbon/ExplorerRibbon.cs | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/OutlookAddin/OutlookAddin.csproj b/src/OutlookAddin/OutlookAddin.csproj index 228a50d..f80fc66 100644 --- a/src/OutlookAddin/OutlookAddin.csproj +++ b/src/OutlookAddin/OutlookAddin.csproj @@ -36,7 +36,7 @@ C:\Users\Chaim\source\repos\OutlookAddin\Publish\ \\192.168.10.97\Projects\LegalCRM\Add-in\ en - 1.0.0.4 + 1.0.0.5 true true 7 @@ -270,9 +270,6 @@ OutlookAddin.Images.klear-compose.png - - OutlookAddin.Images.klear-attach.png - Code diff --git a/src/OutlookAddin/Ribbon/ExplorerRibbon.cs b/src/OutlookAddin/Ribbon/ExplorerRibbon.cs index 261b990..0ff3267 100644 --- a/src/OutlookAddin/Ribbon/ExplorerRibbon.cs +++ b/src/OutlookAddin/Ribbon/ExplorerRibbon.cs @@ -19,7 +19,15 @@ namespace OutlookAddin.Ribbon { private const string ExplorerResource = "OutlookAddin.Ribbon.ExplorerRibbon.xml"; private const string InspectorResource = "OutlookAddin.Ribbon.InspectorRibbon.xml"; - private const string FileButtonId = "FileToEspoCrm"; + + // Every button whose `getEnabled` depends on the current Explorer + // selection must be re-evaluated on every SelectionChange — Office + // caches the initial result otherwise and the button stays stuck. + private static readonly string[] SelectionDependentButtons = + { + "FileToEspoCrm", + "SaveAttachments" + }; private IRibbonUI? _explorerRibbon; private IRibbonUI? _inspectorRibbon; @@ -45,7 +53,7 @@ namespace OutlookAddin.Ribbon var explorer = Globals.ThisAddIn.Application.ActiveExplorer(); if (explorer != null) { - explorer.SelectionChange += () => _explorerRibbon?.InvalidateControl(FileButtonId); + explorer.SelectionChange += InvalidateSelectionDependentButtons; } } catch @@ -54,6 +62,16 @@ namespace OutlookAddin.Ribbon } } + private void InvalidateSelectionDependentButtons() + { + var ribbon = _explorerRibbon; + if (ribbon == null) return; + foreach (var id in SelectionDependentButtons) + { + try { ribbon.InvalidateControl(id); } catch { /* ignore */ } + } + } + public void OnInspectorRibbonLoad(IRibbonUI ribbon) { _inspectorRibbon = ribbon;