diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f13c7f..aca61cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update `SetImage` to work with `ComboBoxMember` - Add `CreateComboBoxMember` to create `ComboBoxMember`. - Add `RibbonThemeBitmapUtils` to change theme for `BitmapSource`. +- Add `RibbonThemePanelUtils` to update the theme for itens in the `RibbonPanel`. +- Update `RibbonPanel` create and remove to update the theme of the itens. ### Tests - Add `RibbonThemeUtilsTests` to test the theme change event. - Add `ComboBoxMember` tests for `Image`, `Group` and `Current`. diff --git a/ricaun.Revit.UI.Example/Resources/Box-Grey-Dark.ico b/ricaun.Revit.UI.Example/Resources/Box-Grey-Dark.ico new file mode 100644 index 0000000..c41c70e Binary files /dev/null and b/ricaun.Revit.UI.Example/Resources/Box-Grey-Dark.ico differ diff --git a/ricaun.Revit.UI.Example/Resources/Box-Grey-Light.ico b/ricaun.Revit.UI.Example/Resources/Box-Grey-Light.ico new file mode 100644 index 0000000..83bba94 Binary files /dev/null and b/ricaun.Revit.UI.Example/Resources/Box-Grey-Light.ico differ diff --git a/ricaun.Revit.UI.Example/Revit/AppTheme.cs b/ricaun.Revit.UI.Example/Revit/AppTheme.cs index 2b91d99..689d7bd 100644 --- a/ricaun.Revit.UI.Example/Revit/AppTheme.cs +++ b/ricaun.Revit.UI.Example/Revit/AppTheme.cs @@ -8,27 +8,66 @@ namespace ricaun.Revit.UI.Example.Revit [AppLoader] public class AppTheme : IExternalApplication { - const string LIGHT = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Blue-Light.ico"; - const string DARK = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Blue-Dark.ico"; + const string LIGHT = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Grey-Light.ico"; + const string DARK = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Grey-Dark.ico"; + const string LIGHT_RED = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Red-Light.ico"; + const string DARK_RED = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Red-Dark.ico"; + const string LIGHT_GREEN = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Green-Light.ico"; + const string DARK_GREEN = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Green-Dark.ico"; + const string LIGHT_BLUE = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Blue-Light.ico"; + const string DARK_BLUE = "https://github.com/ricaun-io/Autodesk.Icon.Example/releases/download/1.0.1-alpha/Box-Blue-Dark.ico"; + const string REVIT = "/UIFrameworkRes;component/ribbon/images/revit.ico"; + const string Base64Image = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAHYcAAB2HAY/l8WUAAABOSURBVEhLtccxDQAwDMCw8odRdIWxP7cn+fHM3l8913M913M913M913M913M913M913M913M913M913M913M913M913M913M913O9tfcAG98oW3bd33wAAAAASUVORK5CYII="; private RibbonPanel ribbonPanel; public Result OnStartup(UIControlledApplication application) { ribbonPanel = application.CreatePanel("Theme"); + //ribbonPanel.CreatePushButton("Revit") + // .SetLargeImage(REVIT); + + //ribbonPanel.CreatePushButton("Base64") + // .SetLargeImage(Base64Image); + ribbonPanel.CreatePushButton("Light") .SetLargeImage(LIGHT); ribbonPanel.CreatePushButton("Dark") - .SetLargeImage(DARK); - string stringNull = null; - ribbonPanel.CreatePushButton("Null") - .SetLargeImage(LIGHT) - .SetLargeImage(stringNull); + .SetLargeImage(LIGHT); + + ribbonPanel.CreatePushButton(".") + .SetLargeImage(LIGHT_GREEN) + .SetImage(LIGHT_RED); + + ribbonPanel.CreatePushButton(".") + .SetLargeImage(LIGHT_GREEN) + .SetImage(LIGHT_RED) + .SetItemSize(Autodesk.Windows.RibbonItemSize.Standard); + + ribbonPanel.RowStackedItems( + ribbonPanel.CreatePushButton("Grey") + .SetLargeImage("Resources/Box-Grey-Light.ico"), + ribbonPanel.CreatePushButton("Grey") + .SetLargeImage("Resources/Box-Grey-Light.ico"), + ribbonPanel.CreatePushButton("Grey") + .SetLargeImage("Resources/Box-Grey-Light.ico") + ); + ribbonPanel.RowLargeStackedItems( + ribbonPanel.CreatePushButton("Grey") + .SetLargeImage("Resources/Box-Grey-Light.ico"), + ribbonPanel.CreatePushButton("Grey") + .SetLargeImage("Resources/Box-Grey-Light.ico") + ); + + ribbonPanel.AddSeparator(); ribbonPanel.FlowStackedItems( - ribbonPanel.CreatePushButton("1").SetLargeImage(LIGHT), - ribbonPanel.CreatePushButton("2").SetLargeImage(DARK), - ribbonPanel.CreatePushButton("3").SetLargeImage(LIGHT) + ribbonPanel.CreatePushButton("1").SetLargeImage(LIGHT_RED), + ribbonPanel.CreatePushButton("2").SetLargeImage(DARK_RED), + ribbonPanel.CreatePushButton("3").SetLargeImage(LIGHT_BLUE), + ribbonPanel.CreatePushButton("4").SetLargeImage(DARK_GREEN), + ribbonPanel.CreatePushButton("5").SetLargeImage(LIGHT_GREEN), + ribbonPanel.CreatePushButton("6").SetLargeImage(DARK_BLUE) ); ribbonPanel.AddSeparator(); @@ -44,6 +83,12 @@ public Result OnStartup(UIControlledApplication application) .SetLargeImage(LIGHT); comboBox.CreateComboBoxMember("ComboBox") .SetLargeImage(LIGHT); + comboBox.CreateComboBoxMember("Red") + .SetLargeImage(LIGHT_RED); + comboBox.CreateComboBoxMember("Green") + .SetLargeImage(LIGHT_GREEN); + comboBox.CreateComboBoxMember("Blue") + .SetLargeImage(LIGHT_BLUE); ribbonPanel.RowStackedItems(pushButton, textBox, comboBox); diff --git a/ricaun.Revit.UI.Example/ricaun.Revit.UI.Example.csproj b/ricaun.Revit.UI.Example/ricaun.Revit.UI.Example.csproj index 910951c..cb6fb12 100644 --- a/ricaun.Revit.UI.Example/ricaun.Revit.UI.Example.csproj +++ b/ricaun.Revit.UI.Example/ricaun.Revit.UI.Example.csproj @@ -84,6 +84,8 @@ + + @@ -112,6 +114,8 @@ + + diff --git a/ricaun.Revit.UI/RibbonPanelExtension.cs b/ricaun.Revit.UI/RibbonPanelExtension.cs index 0e23734..38f2e25 100644 --- a/ricaun.Revit.UI/RibbonPanelExtension.cs +++ b/ricaun.Revit.UI/RibbonPanelExtension.cs @@ -1,4 +1,5 @@ using Autodesk.Revit.UI; +using ricaun.Revit.UI.Utils; using System; using System.Collections.Generic; using System.Linq; @@ -29,7 +30,7 @@ public static RibbonPanel CreatePanel(this UIControlledApplication application, ribbonPanel = application.CreateRibbonPanel(RibbonSafeExtension.SafeRibbonPanelName(panelName)); ribbonPanel.Title = panelName; } - return ribbonPanel; + return ribbonPanel.ThemeChangeEnable(); } /// @@ -72,7 +73,7 @@ public static RibbonPanel CreatePanel(this UIControlledApplication application, ribbonPanel.Title = panelName; } } - return ribbonPanel; + return ribbonPanel.ThemeChangeEnable(); } /// @@ -118,6 +119,7 @@ public static RibbonPanel Remove(this RibbonPanel ribbonPanel) if (ribbonPanel is null) return ribbonPanel; + ribbonPanel.ThemeChangeDisable(); ribbonPanel.Visible = false; ribbonPanel.Enabled = false; diff --git a/ricaun.Revit.UI/Utils/RibbonThemePanelUtils.cs b/ricaun.Revit.UI/Utils/RibbonThemePanelUtils.cs new file mode 100644 index 0000000..ca6bfaf --- /dev/null +++ b/ricaun.Revit.UI/Utils/RibbonThemePanelUtils.cs @@ -0,0 +1,70 @@ +using Autodesk.Revit.UI; +using System.Collections.Generic; + +namespace ricaun.Revit.UI.Utils +{ + internal static class RibbonThemePanelUtils + { + private static List RibbonThemePanels = new List(); + static RibbonThemePanelUtils() + { + RibbonThemeUtils.ThemeChanged += RibbonThemeUtils_ThemeChanged; + } + internal static void Dispose() + { + RibbonThemeUtils.ThemeChanged -= RibbonThemeUtils_ThemeChanged; + RibbonThemePanels.Clear(); + } + internal static RibbonPanel ThemeChangeDisable(this RibbonPanel ribbonPanel) => ThemeChangeEnable(ribbonPanel, false); + internal static RibbonPanel ThemeChangeEnable(this RibbonPanel ribbonPanel, bool enable = true) + { + if (ribbonPanel is null) return ribbonPanel; + + RibbonThemePanels.Remove(ribbonPanel); + + if (enable) + { + RibbonThemePanels.Add(ribbonPanel); + } + + return ribbonPanel; + } + + private static void RibbonThemeUtils_ThemeChanged(object sender, ThemeChangedEventArgs e) + { + foreach (var ribbonPanel in RibbonThemePanels) + { + foreach (var ribbonItem in ribbonPanel.GetRibbonItems()) + { + var isLight = e.IsLight; + UpdateImageThemes(ribbonItem, isLight); + } + } + } + + private static void UpdateImageThemes(RibbonItem ribbonItem, bool isLight) + { + try + { + switch (ribbonItem) + { + case RibbonButton ribbonButton: + var image = ribbonButton.Image; + ribbonButton.SetLargeImage(ribbonButton.LargeImage); + if (image is not null) ribbonButton.SetImage(image); + break; + case ComboBox comboBox: + comboBox.SetImage(comboBox.Image); + break; + case ComboBoxMember comboBoxMember: + comboBoxMember.SetImage(comboBoxMember.Image); + break; + case TextBox textBox: + textBox.SetImage(textBox.Image); + break; + } + } + catch { } + } + } +}