fix(ribbon): invalidate "שמור קבצים" on SelectionChange (button stays disabled)
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) <noreply@anthropic.com>
This commit is contained in:
@@ -36,7 +36,7 @@
|
|||||||
<PublishUrl>C:\Users\Chaim\source\repos\OutlookAddin\Publish\</PublishUrl>
|
<PublishUrl>C:\Users\Chaim\source\repos\OutlookAddin\Publish\</PublishUrl>
|
||||||
<InstallUrl>\\192.168.10.97\Projects\LegalCRM\Add-in\</InstallUrl>
|
<InstallUrl>\\192.168.10.97\Projects\LegalCRM\Add-in\</InstallUrl>
|
||||||
<TargetCulture>en</TargetCulture>
|
<TargetCulture>en</TargetCulture>
|
||||||
<ApplicationVersion>1.0.0.4</ApplicationVersion>
|
<ApplicationVersion>1.0.0.5</ApplicationVersion>
|
||||||
<AutoIncrementApplicationRevision>true</AutoIncrementApplicationRevision>
|
<AutoIncrementApplicationRevision>true</AutoIncrementApplicationRevision>
|
||||||
<UpdateEnabled>true</UpdateEnabled>
|
<UpdateEnabled>true</UpdateEnabled>
|
||||||
<UpdateInterval>7</UpdateInterval>
|
<UpdateInterval>7</UpdateInterval>
|
||||||
@@ -270,9 +270,6 @@
|
|||||||
<EmbeddedResource Include="Images\klear-compose.png">
|
<EmbeddedResource Include="Images\klear-compose.png">
|
||||||
<LogicalName>OutlookAddin.Images.klear-compose.png</LogicalName>
|
<LogicalName>OutlookAddin.Images.klear-compose.png</LogicalName>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Images\klear-attach.png">
|
|
||||||
<LogicalName>OutlookAddin.Images.klear-attach.png</LogicalName>
|
|
||||||
</EmbeddedResource>
|
|
||||||
<Compile Include="Services\AddInHost.cs">
|
<Compile Include="Services\AddInHost.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -19,7 +19,15 @@ namespace OutlookAddin.Ribbon
|
|||||||
{
|
{
|
||||||
private const string ExplorerResource = "OutlookAddin.Ribbon.ExplorerRibbon.xml";
|
private const string ExplorerResource = "OutlookAddin.Ribbon.ExplorerRibbon.xml";
|
||||||
private const string InspectorResource = "OutlookAddin.Ribbon.InspectorRibbon.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? _explorerRibbon;
|
||||||
private IRibbonUI? _inspectorRibbon;
|
private IRibbonUI? _inspectorRibbon;
|
||||||
@@ -45,7 +53,7 @@ namespace OutlookAddin.Ribbon
|
|||||||
var explorer = Globals.ThisAddIn.Application.ActiveExplorer();
|
var explorer = Globals.ThisAddIn.Application.ActiveExplorer();
|
||||||
if (explorer != null)
|
if (explorer != null)
|
||||||
{
|
{
|
||||||
explorer.SelectionChange += () => _explorerRibbon?.InvalidateControl(FileButtonId);
|
explorer.SelectionChange += InvalidateSelectionDependentButtons;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
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)
|
public void OnInspectorRibbonLoad(IRibbonUI ribbon)
|
||||||
{
|
{
|
||||||
_inspectorRibbon = ribbon;
|
_inspectorRibbon = ribbon;
|
||||||
|
|||||||
Reference in New Issue
Block a user