From 59070aeea527abbac82f3f42b99cb75928c67802 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 13 Jan 2022 20:33:51 -0300 Subject: [PATCH 1/9] - Add RibbonItem Set - Add RibbonDescriptionExtension --- CHANGELOG.md | 4 + ricaun.Revit.UI.Example/Revit/App.cs | 10 +- .../Revit/Commands/Command.cs | 2 +- ricaun.Revit.UI/RibbonDescriptionExtension.cs | 171 ++++++++++++++++++ ricaun.Revit.UI/RibbonPanelExtension.cs | 4 +- ricaun.Revit.UI/ricaun.Revit.UI.csproj | 2 +- 6 files changed, 188 insertions(+), 5 deletions(-) create mode 100644 ricaun.Revit.UI/RibbonDescriptionExtension.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index de639c0..4943ef8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.0.5] / 2022-01-13 +- Add RibbonItem Set +- Add RibbonDescriptionExtension + ## [0.0.4] / 2022-01-12 - Add NugetApiUrl & NugetApiKey - Update Readme diff --git a/ricaun.Revit.UI.Example/Revit/App.cs b/ricaun.Revit.UI.Example/Revit/App.cs index b6989c1..c866722 100644 --- a/ricaun.Revit.UI.Example/Revit/App.cs +++ b/ricaun.Revit.UI.Example/Revit/App.cs @@ -12,7 +12,7 @@ public class App : IExternalApplication public Result OnStartup(UIControlledApplication application) { ribbonPanel = application.CreatePanel("Example"); - ribbonPanel.AddPushButton(); + var button = ribbonPanel.AddPushButton(); ribbonPanel.CreatePulldownButton(new[] { ribbonPanel.NewPushButtonData(), @@ -85,6 +85,14 @@ public Result OnStartup(UIControlledApplication application) } } + button.SetDescription(new RibbonDescription() + { + Text = "-", + LongDescription = "LongDescription", + ToolTip = "ToolTip", + LargeImage = Proprieties.Resource.icon.GetBitmapSource() + }); + return Result.Succeeded; } diff --git a/ricaun.Revit.UI.Example/Revit/Commands/Command.cs b/ricaun.Revit.UI.Example/Revit/Commands/Command.cs index 46e50ce..e52c89f 100644 --- a/ricaun.Revit.UI.Example/Revit/Commands/Command.cs +++ b/ricaun.Revit.UI.Example/Revit/Commands/Command.cs @@ -14,7 +14,7 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme Console.WriteLine(typeof(Command).Assembly); - //System.Windows.MessageBox.Show(AutodeskExtension.GetAutodeskOwner(), $"Hello Revit\n{DateTime.Now}"); + System.Windows.MessageBox.Show(AutodeskExtension.GetAutodeskOwner(), $"Hello Revit\n{DateTime.Now}"); return Result.Succeeded; } diff --git a/ricaun.Revit.UI/RibbonDescriptionExtension.cs b/ricaun.Revit.UI/RibbonDescriptionExtension.cs new file mode 100644 index 0000000..1343b13 --- /dev/null +++ b/ricaun.Revit.UI/RibbonDescriptionExtension.cs @@ -0,0 +1,171 @@ +using Autodesk.Revit.UI; +using System.Collections.Generic; +using System.Windows.Media; + +namespace ricaun.Revit.UI +{ + /// + /// RibbonDescription + /// + public class RibbonDescription + { + /// + /// Text + /// + public string Text { get; set; } + /// + /// ToolTip + /// + public string ToolTip { get; set; } + /// + /// LongDescription + /// + public string LongDescription { get; set; } + /// + /// Help + /// + public string Help { get; set; } + /// + /// Image + /// + public ImageSource Image { get; set; } + /// + /// LargeImage + /// + public ImageSource LargeImage { get; set; } + /// + /// ToolTipImage + /// + public ImageSource ToolTipImage { get; set; } + } + + /// + /// RibbonDescriptionExtension + /// + public static class RibbonDescriptionExtension + { + + /// + /// Get Each RibbonItem + /// + /// + /// + public static IList GetRibbonItems(this RibbonPanel ribbonPanel) + { + var ribbonItems = new List(); + foreach (var ribbonItem in ribbonPanel.GetItems()) + { + ribbonItems.Add(ribbonItem); + if (ribbonItem is SplitButton splitButton) + ribbonItems.AddRange(splitButton.GetItems()); + if (ribbonItem is PulldownButton pulldownButton) + ribbonItems.AddRange(pulldownButton.GetItems()); + } + return ribbonItems; + } + + + /// + /// Set Description + /// + /// + /// + /// + public static RibbonItem SetDescription(this RibbonItem ribbonItem, RibbonDescription description) + { + ribbonItem.SetText(description.Text); + ribbonItem.ToolTip = description.ToolTip; + ribbonItem.LongDescription = description.LongDescription; + ribbonItem.ToolTipImage = description.ToolTipImage; + ribbonItem.SetContextualHelp(GetContextualHelp(description.Help)); + + if (ribbonItem is RibbonButton ribbonButton) + { + ribbonButton.LargeImage = description.LargeImage; + ribbonButton.Image = description.Image; + } + return ribbonItem; + } + + #region Set RibbonItem + + + /// + /// Sets the contextual help bound with this RibbonItem. + /// + /// + /// + /// + public static RibbonItem SetContextualHelp(this RibbonItem ribbonItem, string helpPath) + { + ribbonItem.SetContextualHelp(GetContextualHelp(helpPath)); + return ribbonItem; + } + + /// + /// Enable / Disable Show Text + /// + /// + /// + /// + public static RibbonItem SetShowText(this RibbonItem ribbonItem, bool showText = false) + { + ribbonItem.GetRibbonItem().ShowText = showText; + return ribbonItem; + } + + /// + /// Set RibbonItemSize + /// + /// + /// + /// + public static RibbonItem SetItemSize(this RibbonItem ribbonItem, Autodesk.Windows.RibbonItemSize itemSize = Autodesk.Windows.RibbonItemSize.Large) + { + ribbonItem.GetRibbonItem().Size = itemSize; + return ribbonItem; + } + + /// + /// Set RibbonItem Text + /// + /// + /// + /// + public static RibbonItem SetText(this RibbonItem ribbonItem, string text = null) + { + if (text == null || text.Trim() == string.Empty) + return ribbonItem.SetShowText(false); + + ribbonItem.ItemText = text; + return ribbonItem; + } + + #endregion + + #region ContextualHelp + /// + /// Get ContextualHelp by + /// + /// + /// + private static ContextualHelp GetContextualHelp(string helpPath) + { + ContextualHelp contextHelp = null; + try + { + if (helpPath.StartsWith("http")) + { + contextHelp = new ContextualHelp(ContextualHelpType.Url, helpPath); + } + else + { + contextHelp = new ContextualHelp(ContextualHelpType.ChmFile, helpPath); + } + } + catch { } + return contextHelp; + } + #endregion + } +} diff --git a/ricaun.Revit.UI/RibbonPanelExtension.cs b/ricaun.Revit.UI/RibbonPanelExtension.cs index a6d0110..0813b43 100644 --- a/ricaun.Revit.UI/RibbonPanelExtension.cs +++ b/ricaun.Revit.UI/RibbonPanelExtension.cs @@ -270,7 +270,7 @@ private static string SafeButtonName(string buttonName) /// private static string SafeRibbonPanelName(string panelName) { - return $"{TickNumber}%{panelName}"; + return $"{System.DateTime.Now.Ticks}%{panelName}"; } /// @@ -280,7 +280,7 @@ private static string SafeRibbonPanelName(string panelName) /// /// TickNumber ++ /// - private static long TickNumber => _TickNumber++; // System.DateTime.Now.Ticks + private static long TickNumber => _TickNumber++; /// /// Verify if Panel has Name diff --git a/ricaun.Revit.UI/ricaun.Revit.UI.csproj b/ricaun.Revit.UI/ricaun.Revit.UI.csproj index 64d7ec7..eaf3271 100644 --- a/ricaun.Revit.UI/ricaun.Revit.UI.csproj +++ b/ricaun.Revit.UI/ricaun.Revit.UI.csproj @@ -77,7 +77,7 @@ ricaun.Revit.UI - 0.0.4 + 0.0.5 {2064ba4d-5527-41e9-8b76-0cbfefa35900} From 39d0006ed9c6a66b2c5700ecce11edd2bb1fb958 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Fri, 14 Jan 2022 17:28:11 -0300 Subject: [PATCH 2/9] - Change to Now.Tick --- CHANGELOG.md | 1 + ricaun.Revit.UI/RibbonPanelExtension.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4943ef8..0da053d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [0.0.5] / 2022-01-13 +- Change to Now.Tick - Add RibbonItem Set - Add RibbonDescriptionExtension diff --git a/ricaun.Revit.UI/RibbonPanelExtension.cs b/ricaun.Revit.UI/RibbonPanelExtension.cs index 0813b43..eea4782 100644 --- a/ricaun.Revit.UI/RibbonPanelExtension.cs +++ b/ricaun.Revit.UI/RibbonPanelExtension.cs @@ -270,7 +270,7 @@ private static string SafeButtonName(string buttonName) /// private static string SafeRibbonPanelName(string panelName) { - return $"{System.DateTime.Now.Ticks}%{panelName}"; + return $"{System.DateTime.Now.Ticks + TickNumber}%{panelName}"; } /// From a9e68cd271dbf3b4d50d73bc967ff2fd52a19afb Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Sat, 15 Jan 2022 11:50:18 -0300 Subject: [PATCH 3/9] - Clear Code - Change to Now.Tick - Add ConsoleAttribute - Add RibbonItem Set - Add RibbonDescriptionExtension --- CHANGELOG.md | 2 + ricaun.Revit.UI.Example/Revit/App.cs | 97 ++++++++++++++++++- .../ricaun.Revit.UI.Example.csproj | 1 - ricaun.Revit.UI/ConsoleAttribute.cs | 11 +++ ricaun.Revit.UI/RibbonDescriptionExtension.cs | 12 ++- ricaun.Revit.UI/RibbonItemExtension.cs | 33 ++++++- ricaun.Revit.UI/RibbonPanelExtension.cs | 6 +- 7 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 ricaun.Revit.UI/ConsoleAttribute.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 0da053d..35eec2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [0.0.5] / 2022-01-13 +- Clear Code - Change to Now.Tick +- Add ConsoleAttribute - Add RibbonItem Set - Add RibbonDescriptionExtension diff --git a/ricaun.Revit.UI.Example/Revit/App.cs b/ricaun.Revit.UI.Example/Revit/App.cs index c866722..c03c234 100644 --- a/ricaun.Revit.UI.Example/Revit/App.cs +++ b/ricaun.Revit.UI.Example/Revit/App.cs @@ -1,7 +1,7 @@ using Autodesk.Revit.DB; using Autodesk.Revit.UI; -using ricaun.Revit.UI; using System; +using System.Threading.Tasks; namespace ricaun.Revit.UI.Example.Revit { @@ -93,6 +93,16 @@ public Result OnStartup(UIControlledApplication application) LargeImage = Proprieties.Resource.icon.GetBitmapSource() }); + ribbonPanel.AddSlideOut(); + + AddRadioGroup(ribbonPanel); + AddStackedButtons(ribbonPanel); + + foreach (var item in ribbonPanel.GetRibbonItems()) + { + Console.WriteLine($"{item} {item.Name}"); + } + return Result.Succeeded; } @@ -101,9 +111,88 @@ public Result OnShutdown(UIControlledApplication application) ribbonPanel.Close(); return Result.Succeeded; } - } - internal class ConsoleAttribute : Attribute - { + private void AddRadioGroup(RibbonPanel panel) + { + // add radio button group + RadioButtonGroupData radioData = new RadioButtonGroupData("radioGroup"); + RadioButtonGroup radioButtonGroup = panel.AddItem(radioData) as RadioButtonGroup; + + var commandType = typeof(Commands.Command); + var targetName = commandType.Name; + var targetText = commandType.Name; + var assemblyName = commandType.Assembly.Location; + var className = commandType.FullName; + + // create toggle buttons and add to radio button group + ToggleButtonData tb1 = new ToggleButtonData("toggleButton1", "Red", assemblyName, className); + ToggleButtonData tb2 = new ToggleButtonData("toggleButton2", "Green"); + ToggleButtonData tb3 = new ToggleButtonData("toggleButton3", "Blue"); + radioButtonGroup.AddItem(tb1); + radioButtonGroup.AddItem(tb2); + radioButtonGroup.AddItem(tb3); + } + + private void AddStackedButtons(RibbonPanel panel) + { + ComboBoxData cbData = new ComboBoxData("comboBox"); + + TextBoxData textData = new TextBoxData("Text Box"); + textData.Name = "Text Box"; + textData.ToolTip = "Enter some text here"; + textData.LongDescription = "This is text that will appear next to the image" + + "when the user hovers the mouse over the control"; + + var stackedItems = panel.AddStackedItems(textData, cbData); + if (stackedItems.Count > 1) + { + TextBox tBox = stackedItems[0] as TextBox; + if (tBox != null) + { + tBox.PromptText = "Enter a comment"; + tBox.ShowImageAsButton = true; + tBox.ToolTip = "Enter some text"; + // Register event handler ProcessText + tBox.EnterPressed += (s, e) => + { + TextBox textBox = s as TextBox; + string strText = textBox.Value as string; + Console.WriteLine(strText); + }; + } + + ComboBox cBox = stackedItems[1] as ComboBox; + if (cBox != null) + { + cBox.ItemText = "ComboBox"; + cBox.ToolTip = "Select an Option"; + cBox.LongDescription = "Select a number or letter"; + + ComboBoxMemberData cboxMemDataA = new ComboBoxMemberData("A", "Option A"); + + cboxMemDataA.GroupName = "Letters"; + cBox.AddItem(cboxMemDataA); + + ComboBoxMemberData cboxMemDataB = new ComboBoxMemberData("B", "Option B"); + + cboxMemDataB.GroupName = "Letters"; + cBox.AddItem(cboxMemDataB); + + ComboBoxMemberData cboxMemData = new ComboBoxMemberData("One", "Option 1"); + + cboxMemData.GroupName = "Numbers"; + cBox.AddItem(cboxMemData); + ComboBoxMemberData cboxMemData2 = new ComboBoxMemberData("Two", "Option 2"); + + cboxMemData2.GroupName = "Numbers"; + cBox.AddItem(cboxMemData2); + ComboBoxMemberData cboxMemData3 = new ComboBoxMemberData("Three", "Option 3"); + + cboxMemData3.GroupName = "Numbers"; + cBox.AddItem(cboxMemData3); + } + } + } + } } \ No newline at end of file diff --git a/ricaun.Revit.UI.Example/ricaun.Revit.UI.Example.csproj b/ricaun.Revit.UI.Example/ricaun.Revit.UI.Example.csproj index ced764e..55eb1b1 100644 --- a/ricaun.Revit.UI.Example/ricaun.Revit.UI.Example.csproj +++ b/ricaun.Revit.UI.Example/ricaun.Revit.UI.Example.csproj @@ -120,7 +120,6 @@ - diff --git a/ricaun.Revit.UI/ConsoleAttribute.cs b/ricaun.Revit.UI/ConsoleAttribute.cs new file mode 100644 index 0000000..f94dcd5 --- /dev/null +++ b/ricaun.Revit.UI/ConsoleAttribute.cs @@ -0,0 +1,11 @@ +using System; + +namespace ricaun.Revit.UI +{ + /// + /// Console Attribute for ricaun.Console + /// + public class ConsoleAttribute : Attribute + { + } +} diff --git a/ricaun.Revit.UI/RibbonDescriptionExtension.cs b/ricaun.Revit.UI/RibbonDescriptionExtension.cs index 1343b13..92369e2 100644 --- a/ricaun.Revit.UI/RibbonDescriptionExtension.cs +++ b/ricaun.Revit.UI/RibbonDescriptionExtension.cs @@ -56,10 +56,18 @@ public static IList GetRibbonItems(this RibbonPanel ribbonPanel) foreach (var ribbonItem in ribbonPanel.GetItems()) { ribbonItems.Add(ribbonItem); - if (ribbonItem is SplitButton splitButton) - ribbonItems.AddRange(splitButton.GetItems()); if (ribbonItem is PulldownButton pulldownButton) ribbonItems.AddRange(pulldownButton.GetItems()); + if (ribbonItem is SplitButton splitButton) + ribbonItems.AddRange(splitButton.GetItems()); + if (ribbonItem is ToggleButton) { } + if (ribbonItem is RadioButtonGroup radioButtonGroup) + { + ribbonItems.AddRange(radioButtonGroup.GetItems()); + } + if (ribbonItem is ComboBoxMember) { } + if (ribbonItem is ComboBox) { } + if (ribbonItem is TextBox) { } } return ribbonItems; } diff --git a/ricaun.Revit.UI/RibbonItemExtension.cs b/ricaun.Revit.UI/RibbonItemExtension.cs index 5da510c..16de640 100644 --- a/ricaun.Revit.UI/RibbonItemExtension.cs +++ b/ricaun.Revit.UI/RibbonItemExtension.cs @@ -16,7 +16,7 @@ public static class RibbonItemExtension /// /// /// - public static string GetId(this RibbonItem ribbonItem) + private static string GetId(this RibbonItem ribbonItem) { var type = typeof(RibbonItem); @@ -61,6 +61,37 @@ public static Autodesk.Windows.RibbonTab GetRibbonTab(string tabId) return null; } + /// + /// GetRibbonPanel + /// + /// + /// + public static Autodesk.Windows.RibbonPanel GetRibbonPanel(this RibbonPanel ribbonPanel) + { + return GetRibbonPanel(ribbonPanel.Name); + } + + /// + /// GetRibbonPanel + /// + /// + /// + public static Autodesk.Windows.RibbonPanel GetRibbonPanel(string panelEndWithId) + { + var ribbon = Autodesk.Windows.ComponentManager.Ribbon; + foreach (Autodesk.Windows.RibbonTab tab in ribbon.Tabs) + { + foreach (Autodesk.Windows.RibbonPanel panel in tab.Panels) + { + if (panel.Source.Id.EndsWith(panelEndWithId)) + { + return panel; + } + } + } + return null; + } + /// /// GetRibbonPanel /// diff --git a/ricaun.Revit.UI/RibbonPanelExtension.cs b/ricaun.Revit.UI/RibbonPanelExtension.cs index eea4782..27c5148 100644 --- a/ricaun.Revit.UI/RibbonPanelExtension.cs +++ b/ricaun.Revit.UI/RibbonPanelExtension.cs @@ -84,8 +84,8 @@ public static RibbonPanel Close(this RibbonPanel ribbonPanel) var commandType = typeof(TExternalCommand); var targetName = commandType.Name; var targetText = commandType.Name; - var location = commandType.Assembly.Location; - var fullName = commandType.FullName; + var assemblyName = commandType.Assembly.Location; + var className = commandType.FullName; if (text != null && text != "") targetText = text; @@ -94,7 +94,7 @@ public static RibbonPanel Close(this RibbonPanel ribbonPanel) targetName = SafeButtonName(targetText); } - PushButtonData currentBtn = new PushButtonData(targetName, targetText, location, fullName); + PushButtonData currentBtn = new PushButtonData(targetName, targetText, assemblyName, className); if (text == "") currentBtn.Text = "-"; From 76ba3626ab47f082735652a47f9713bcfed2471b Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 20 Jan 2022 18:01:57 -0300 Subject: [PATCH 4/9] - Add Move RibbonPanelTo - Add Remove RibbonTab - Add `GetRibbonPanel` using `m_RibbonPanel` - Remove Panel - Add OrderPanels - Clear Code - Change to Now.Tick - Add ConsoleAttribute - Add RibbonItem Set - Add RibbonDescriptionExtension --- CHANGELOG.md | 5 + ricaun.Revit.UI.Example/Revit/App.cs | 101 ++-------------- .../Revit/Commands/Command.cs | 3 + .../Services/ReflectionService.cs | 37 ++++++ ricaun.Revit.UI/RibbonItemExtension.cs | 109 +++++++++++++++--- ricaun.Revit.UI/RibbonPanelExtension.cs | 17 ++- 6 files changed, 168 insertions(+), 104 deletions(-) create mode 100644 ricaun.Revit.UI.Example/Services/ReflectionService.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 35eec2d..de162b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [0.0.5] / 2022-01-13 +- Add Move RibbonPanelTo +- Add Remove RibbonTab +- Add `GetRibbonPanel` using `m_RibbonPanel` +- Remove Panel +- Add OrderPanels - Clear Code - Change to Now.Tick - Add ConsoleAttribute diff --git a/ricaun.Revit.UI.Example/Revit/App.cs b/ricaun.Revit.UI.Example/Revit/App.cs index c03c234..78240a5 100644 --- a/ricaun.Revit.UI.Example/Revit/App.cs +++ b/ricaun.Revit.UI.Example/Revit/App.cs @@ -1,17 +1,23 @@ using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; +using System.Windows.Media; namespace ricaun.Revit.UI.Example.Revit { [Console] public class App : IExternalApplication { + private const string TabName = "ricaun"; + private const string PanelName = "Example"; private static RibbonPanel ribbonPanel; + public Result OnStartup(UIControlledApplication application) { - ribbonPanel = application.CreatePanel("Example"); + ribbonPanel = application.CreatePanel(TabName, PanelName); var button = ribbonPanel.AddPushButton(); ribbonPanel.CreatePulldownButton(new[] { @@ -93,14 +99,14 @@ public Result OnStartup(UIControlledApplication application) LargeImage = Proprieties.Resource.icon.GetBitmapSource() }); - ribbonPanel.AddSlideOut(); - - AddRadioGroup(ribbonPanel); - AddStackedButtons(ribbonPanel); + ribbonPanel.GetRibbonPanel().Tab.SetOrderPanels(); + var ric = ribbonPanel.GetRibbonPanel().Tab.Panels.ToList().FirstOrDefault(e => e.Source.Title == "ricaun"); + ric?.MoveRibbonPanel(); + ric?.MoveRibbonPanel(); foreach (var item in ribbonPanel.GetRibbonItems()) { - Console.WriteLine($"{item} {item.Name}"); + //Console.WriteLine($"{item} {item.Name}"); } return Result.Succeeded; @@ -111,88 +117,5 @@ public Result OnShutdown(UIControlledApplication application) ribbonPanel.Close(); return Result.Succeeded; } - - private void AddRadioGroup(RibbonPanel panel) - { - // add radio button group - RadioButtonGroupData radioData = new RadioButtonGroupData("radioGroup"); - RadioButtonGroup radioButtonGroup = panel.AddItem(radioData) as RadioButtonGroup; - - var commandType = typeof(Commands.Command); - var targetName = commandType.Name; - var targetText = commandType.Name; - var assemblyName = commandType.Assembly.Location; - var className = commandType.FullName; - - // create toggle buttons and add to radio button group - ToggleButtonData tb1 = new ToggleButtonData("toggleButton1", "Red", assemblyName, className); - ToggleButtonData tb2 = new ToggleButtonData("toggleButton2", "Green"); - ToggleButtonData tb3 = new ToggleButtonData("toggleButton3", "Blue"); - radioButtonGroup.AddItem(tb1); - radioButtonGroup.AddItem(tb2); - radioButtonGroup.AddItem(tb3); - } - - private void AddStackedButtons(RibbonPanel panel) - { - ComboBoxData cbData = new ComboBoxData("comboBox"); - - TextBoxData textData = new TextBoxData("Text Box"); - textData.Name = "Text Box"; - textData.ToolTip = "Enter some text here"; - textData.LongDescription = "This is text that will appear next to the image" - + "when the user hovers the mouse over the control"; - - var stackedItems = panel.AddStackedItems(textData, cbData); - if (stackedItems.Count > 1) - { - TextBox tBox = stackedItems[0] as TextBox; - if (tBox != null) - { - tBox.PromptText = "Enter a comment"; - tBox.ShowImageAsButton = true; - tBox.ToolTip = "Enter some text"; - // Register event handler ProcessText - tBox.EnterPressed += (s, e) => - { - TextBox textBox = s as TextBox; - string strText = textBox.Value as string; - Console.WriteLine(strText); - }; - } - - ComboBox cBox = stackedItems[1] as ComboBox; - if (cBox != null) - { - cBox.ItemText = "ComboBox"; - cBox.ToolTip = "Select an Option"; - cBox.LongDescription = "Select a number or letter"; - - ComboBoxMemberData cboxMemDataA = new ComboBoxMemberData("A", "Option A"); - - cboxMemDataA.GroupName = "Letters"; - cBox.AddItem(cboxMemDataA); - - ComboBoxMemberData cboxMemDataB = new ComboBoxMemberData("B", "Option B"); - - cboxMemDataB.GroupName = "Letters"; - cBox.AddItem(cboxMemDataB); - - ComboBoxMemberData cboxMemData = new ComboBoxMemberData("One", "Option 1"); - - cboxMemData.GroupName = "Numbers"; - cBox.AddItem(cboxMemData); - ComboBoxMemberData cboxMemData2 = new ComboBoxMemberData("Two", "Option 2"); - - cboxMemData2.GroupName = "Numbers"; - cBox.AddItem(cboxMemData2); - ComboBoxMemberData cboxMemData3 = new ComboBoxMemberData("Three", "Option 3"); - - cboxMemData3.GroupName = "Numbers"; - cBox.AddItem(cboxMemData3); - } - } - } - } } \ No newline at end of file diff --git a/ricaun.Revit.UI.Example/Revit/Commands/Command.cs b/ricaun.Revit.UI.Example/Revit/Commands/Command.cs index e52c89f..6f9129b 100644 --- a/ricaun.Revit.UI.Example/Revit/Commands/Command.cs +++ b/ricaun.Revit.UI.Example/Revit/Commands/Command.cs @@ -12,7 +12,10 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme { UIApplication uiapp = commandData.Application; + //new Services.ReflectionService().GetFields(); Console.WriteLine(typeof(Command).Assembly); + //new Services.ReflectionService().GetMethods(); + System.Windows.MessageBox.Show(AutodeskExtension.GetAutodeskOwner(), $"Hello Revit\n{DateTime.Now}"); diff --git a/ricaun.Revit.UI.Example/Services/ReflectionService.cs b/ricaun.Revit.UI.Example/Services/ReflectionService.cs new file mode 100644 index 0000000..45cbda0 --- /dev/null +++ b/ricaun.Revit.UI.Example/Services/ReflectionService.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace ricaun.Revit.UI.Example.Services +{ + public class ReflectionService + { + public void GetFields() + { + var type = typeof(T); + var fieldInfos = type.GetFields(BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); + foreach (var fieldInfo in fieldInfos) + { + Console.WriteLine($"{fieldInfo.Name} {fieldInfo.FieldType}"); + } + } + + public void GetMethods() + { + var type = typeof(T); + var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); + foreach (var method in methods) + { + Console.WriteLine($"{method.Name} {method.DeclaringType}"); + foreach (var parameterInfo in method.GetParameters()) + { + Console.WriteLine($" {parameterInfo.Name} {parameterInfo.ParameterType}"); + } + } + } + + } +} diff --git a/ricaun.Revit.UI/RibbonItemExtension.cs b/ricaun.Revit.UI/RibbonItemExtension.cs index 16de640..46f46d4 100644 --- a/ricaun.Revit.UI/RibbonItemExtension.cs +++ b/ricaun.Revit.UI/RibbonItemExtension.cs @@ -43,6 +43,30 @@ public static Autodesk.Windows.RibbonItem GetRibbonItem(this RibbonItem ribbonIt return revitRibbonItem; } + /// + /// GetRibbonPanel + /// + /// + /// + public static Autodesk.Windows.RibbonPanel GetRibbonPanel(this RibbonPanel ribbonPanel) + { + var type = typeof(RibbonPanel); + var _ribbonPanel = type.GetField("m_RibbonPanel", + BindingFlags.Instance | BindingFlags.NonPublic) + ?.GetValue(ribbonPanel) as Autodesk.Windows.RibbonPanel; + return _ribbonPanel; + } + + /// + /// GetRibbonTab + /// + /// + /// + public static Autodesk.Windows.RibbonTab GetRibbonTab(this RibbonPanel ribbonPanel) + { + return ribbonPanel.GetRibbonPanel().Tab; + } + /// /// GetRibbonTab /// @@ -61,29 +85,26 @@ public static Autodesk.Windows.RibbonTab GetRibbonTab(string tabId) return null; } - /// - /// GetRibbonPanel - /// - /// - /// - public static Autodesk.Windows.RibbonPanel GetRibbonPanel(this RibbonPanel ribbonPanel) - { - return GetRibbonPanel(ribbonPanel.Name); - } - /// /// GetRibbonPanel /// /// /// - public static Autodesk.Windows.RibbonPanel GetRibbonPanel(string panelEndWithId) + public static Autodesk.Windows.RibbonPanel GetRibbonPanel(string panelEndWithId, string panelTitle) { + if (panelEndWithId == null) return null; + if (panelTitle == null) return null; + var ribbon = Autodesk.Windows.ComponentManager.Ribbon; foreach (Autodesk.Windows.RibbonTab tab in ribbon.Tabs) { foreach (Autodesk.Windows.RibbonPanel panel in tab.Panels) { - if (panel.Source.Id.EndsWith(panelEndWithId)) + var id = panel.Source.Id; + var title = panel.Source.Title; + if (id == null) continue; + if (title == null) continue; + if (id.EndsWith(panelEndWithId) && title.EndsWith(panelTitle)) { return panel; } @@ -98,7 +119,7 @@ public static Autodesk.Windows.RibbonPanel GetRibbonPanel(string panelEndWithId) /// /// /// - public static Autodesk.Windows.RibbonPanel GetRibbonPanel(string tabId, string panelEndWithId) + public static Autodesk.Windows.RibbonPanel GetTabRibbonPanel(string tabId, string panelEndWithId) { var ribbon = Autodesk.Windows.ComponentManager.Ribbon; foreach (Autodesk.Windows.RibbonTab tab in ribbon.Tabs) @@ -187,5 +208,67 @@ public static bool MoveRibbonPanel(string tabId, string panelEndWithId, int newI } return false; } + + #region Autodesk.Windows.RibbonTab + + #region Order + + /// + /// MoveRibbonPanel to Position + /// + /// + /// + public static void MoveRibbonPanel(this Autodesk.Windows.RibbonPanel ribbonPanel, int newIndex = 0) + { + var ribbonTab = ribbonPanel.Tab; + var panels = ribbonTab.Panels; + var length = panels.Count; + for (int i = 0; i < length; i++) + { + if (i == newIndex) continue; + if (panels[i] == ribbonPanel) + { + ribbonTab.Panels.Move(i, newIndex); + return; + } + } + } + + /// + /// Set Order of Panels by Title + /// + /// + public static void SetOrderPanels(this Autodesk.Windows.RibbonTab ribbonTab) + { + var order = ribbonTab.Panels.OrderBy(e => e.Source.Title).ToList(); + var length = order.Count; + if (length <= 1) return; + for (int i = 0; i < length; i++) + { + var o = order[i]; + for (int j = i; j < length; j++) + { + if (j == i) continue; + if (o == ribbonTab.Panels[j]) + { + ribbonTab.Panels.Move(j, i); + } + } + } + } + + #endregion + + /// + /// Remove Tab + /// + /// + public static void Remove(this Autodesk.Windows.RibbonTab ribbonTab) + { + var ribbon = Autodesk.Windows.ComponentManager.Ribbon; + ribbon.Tabs.Remove(ribbonTab); + } + + #endregion } } diff --git a/ricaun.Revit.UI/RibbonPanelExtension.cs b/ricaun.Revit.UI/RibbonPanelExtension.cs index 27c5148..3ef15c4 100644 --- a/ricaun.Revit.UI/RibbonPanelExtension.cs +++ b/ricaun.Revit.UI/RibbonPanelExtension.cs @@ -60,15 +60,28 @@ public static RibbonPanel CreatePanel(this UIControlledApplication application, } /// - /// Close Setting Visible off + /// Remove RibbonPanel from Tab /// /// /// - public static RibbonPanel Close(this RibbonPanel ribbonPanel) + public static RibbonPanel Remove(this RibbonPanel ribbonPanel) { ribbonPanel.Visible = false; + ribbonPanel.Enabled = false; + var panel = ribbonPanel.GetRibbonPanel(); + panel.Tab.Panels.Remove(panel); return ribbonPanel; } + + /// + /// Remove RibbonPanel from Tab + /// + /// + /// + public static RibbonPanel Close(this RibbonPanel ribbonPanel) + { + return ribbonPanel.Remove(); + } #endregion #region PushButtonData From 7836481acabae419c82855e993c3e50c79b3b1ea Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Thu, 20 Jan 2022 18:02:13 -0300 Subject: [PATCH 5/9] Update Changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de162b4..fd3a227 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [0.0.5] / 2022-01-13 +## [0.0.5] / 2022-01-20 - Add Move RibbonPanelTo - Add Remove RibbonTab - Add `GetRibbonPanel` using `m_RibbonPanel` From 057be2e7d10547f3c65ce6b5beded41db0c97965 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Mon, 24 Jan 2022 12:32:55 -0300 Subject: [PATCH 6/9] - Add UpdateRibbonDescription - Add RibbonDescription --- CHANGELOG.md | 4 + ricaun.Revit.UI.Example/Revit/App.cs | 38 ++++++- ricaun.Revit.UI/RibbonDescriptionExtension.cs | 105 ++++++++++++++++-- 3 files changed, 135 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd3a227..4d90642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.0.5] / 2022-01-24 +- Add UpdateRibbonDescription +- Add RibbonDescription + ## [0.0.5] / 2022-01-20 - Add Move RibbonPanelTo - Add Remove RibbonTab diff --git a/ricaun.Revit.UI.Example/Revit/App.cs b/ricaun.Revit.UI.Example/Revit/App.cs index 78240a5..a31b4be 100644 --- a/ricaun.Revit.UI.Example/Revit/App.cs +++ b/ricaun.Revit.UI.Example/Revit/App.cs @@ -1,5 +1,6 @@ using Autodesk.Revit.DB; using Autodesk.Revit.UI; +using Autodesk.Revit.ApplicationServices; using System; using System.Collections.Generic; using System.Linq; @@ -20,7 +21,7 @@ public Result OnStartup(UIControlledApplication application) ribbonPanel = application.CreatePanel(TabName, PanelName); var button = ribbonPanel.AddPushButton(); - ribbonPanel.CreatePulldownButton(new[] { + ribbonPanel.CreatePulldownButton("PulldownButton", new[] { ribbonPanel.NewPushButtonData(), ribbonPanel.NewPushButtonData(), ribbonPanel.NewPushButtonData(), @@ -29,7 +30,7 @@ public Result OnStartup(UIControlledApplication application) ribbonPanel.NewPushButtonData(), ribbonPanel.NewPushButtonData() }); - ribbonPanel.CreateSplitButton(new[] { + ribbonPanel.CreateSplitButton("SplitButton", new[] { ribbonPanel.NewPushButtonData(), ribbonPanel.NewPushButtonData(), ribbonPanel.NewPushButtonData(), @@ -109,6 +110,39 @@ public Result OnStartup(UIControlledApplication application) //Console.WriteLine($"{item} {item.Name}"); } + ribbonPanel.UpdateRibbonDescription(setting => + { + setting.Add( + new RibbonDescription() + { + Text = "Hello", + ToolTip = "This is a Tool Tip", + LongDescription = "This is a Long Description", + Image = Proprieties.Resource.icon.GetBitmapSource().Scale(0.5), + LargeImage = Proprieties.Resource.icon.GetBitmapSource(), + Help = "https://ricaun.com" + }, + new RibbonDescription(LanguageType.Brazilian_Portuguese) + { + Text = "Ola", + ToolTip = "Este é um Tool Tip", + LongDescription = "Este é um Long Description", + } + ); + + setting.Add("PulldownButton", new RibbonDescription() + { + Text = "PulldownButton", + Help = "https://ricaun.com" + }); + + setting.Add("SplitButton", new RibbonDescription() + { + Text = "SplitButton", + Help = "https://ricaun.com" + }); + }); + return Result.Succeeded; } diff --git a/ricaun.Revit.UI/RibbonDescriptionExtension.cs b/ricaun.Revit.UI/RibbonDescriptionExtension.cs index 92369e2..6d58512 100644 --- a/ricaun.Revit.UI/RibbonDescriptionExtension.cs +++ b/ricaun.Revit.UI/RibbonDescriptionExtension.cs @@ -1,14 +1,61 @@ -using Autodesk.Revit.UI; +using Autodesk.Revit.ApplicationServices; +using Autodesk.Revit.UI; +using System; using System.Collections.Generic; +using System.Linq; using System.Windows.Media; namespace ricaun.Revit.UI { + public class RibbonSettings + { + internal readonly Dictionary> valuePairs; + + public RibbonSettings() + { + valuePairs = new Dictionary>(); + } + + public void Add(params RibbonDescription[] ribbonDescriptions) + { + var name = typeof(T).Name; + Add(name, ribbonDescriptions); + } + + public void Add(string name, RibbonDescription ribbonDescription) + { + if (valuePairs.TryGetValue(name, out List value)) + { + value.Add(ribbonDescription); + return; + } + valuePairs[name] = new List(); + valuePairs[name].Add(ribbonDescription); + } + + public void Add(string name, params RibbonDescription[] ribbonDescriptions) + { + foreach (var ribbonDescription in ribbonDescriptions) + Add(name, ribbonDescription); + } + + public int Count => valuePairs.Count; + } + /// /// RibbonDescription /// public class RibbonDescription { + public RibbonDescription(LanguageType LanguageType = LanguageType.Unknown) + { + this.LanguageType = LanguageType; + } + + /// + /// LanguageType + /// + public LanguageType LanguageType { get; private set; } /// /// Text /// @@ -45,6 +92,26 @@ public class RibbonDescription public static class RibbonDescriptionExtension { + + public static RibbonPanel UpdateRibbonDescription(this RibbonPanel ribbonPanel, Action setting) + { + RibbonSettings ribbonSettings = new RibbonSettings(); + setting?.Invoke(ribbonSettings); + + var language = LanguageExtension.GetLanguageType(); + + foreach (var item in ribbonPanel.GetRibbonItems()) + { + if (ribbonSettings.valuePairs.TryGetValue(item.Name, out List value)) + { + item.SetDescription(value.First()); + item.SetDescription(value.FirstOrDefault(v => v.LanguageType == language)); + } + } + + return ribbonPanel; + } + /// /// Get Each RibbonItem /// @@ -81,16 +148,29 @@ public static IList GetRibbonItems(this RibbonPanel ribbonPanel) /// public static RibbonItem SetDescription(this RibbonItem ribbonItem, RibbonDescription description) { + if (description == null) + return ribbonItem; + ribbonItem.SetText(description.Text); - ribbonItem.ToolTip = description.ToolTip; - ribbonItem.LongDescription = description.LongDescription; - ribbonItem.ToolTipImage = description.ToolTipImage; - ribbonItem.SetContextualHelp(GetContextualHelp(description.Help)); + + if (description.ToolTip != null) + ribbonItem.ToolTip = description.ToolTip; + + if (description.LongDescription != null) + ribbonItem.LongDescription = description.LongDescription; + + if (description.ToolTipImage != null) + ribbonItem.ToolTipImage = description.ToolTipImage; + + ribbonItem.SetContextualHelp(description.Help); if (ribbonItem is RibbonButton ribbonButton) { - ribbonButton.LargeImage = description.LargeImage; - ribbonButton.Image = description.Image; + if (description.LargeImage != null) + ribbonButton.LargeImage = description.LargeImage; + + if (description.Image != null) + ribbonButton.Image = description.Image; } return ribbonItem; } @@ -106,7 +186,9 @@ public static RibbonItem SetDescription(this RibbonItem ribbonItem, RibbonDescri /// public static RibbonItem SetContextualHelp(this RibbonItem ribbonItem, string helpPath) { - ribbonItem.SetContextualHelp(GetContextualHelp(helpPath)); + if (helpPath != null) + ribbonItem.SetContextualHelp(GetContextualHelp(helpPath)); + return ribbonItem; } @@ -140,9 +222,12 @@ public static RibbonItem SetItemSize(this RibbonItem ribbonItem, Autodesk.Window /// /// /// - public static RibbonItem SetText(this RibbonItem ribbonItem, string text = null) + public static RibbonItem SetText(this RibbonItem ribbonItem, string text = "") { - if (text == null || text.Trim() == string.Empty) + if (text == null) + return ribbonItem; + + if (text.Trim() == string.Empty) return ribbonItem.SetShowText(false); ribbonItem.ItemText = text; From d6aef91045b229e9cad61baae37b3929a0219c59 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Mon, 24 Jan 2022 15:59:43 -0300 Subject: [PATCH 7/9] - Add SetImage / SetLongDescription --- CHANGELOG.md | 1 + .../Proprieties/Resource.Designer.cs | 4 +- .../Proprieties/Resource.resx | 2 +- ricaun.Revit.UI.Example/Revit/App.cs | 51 +++-- ricaun.Revit.UI/RibbonDescriptionExtension.cs | 174 +++++++++++++++--- 5 files changed, 174 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d90642..8611c5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [0.0.5] / 2022-01-24 +- Add SetImage / SetLongDescription - Add UpdateRibbonDescription - Add RibbonDescription diff --git a/ricaun.Revit.UI.Example/Proprieties/Resource.Designer.cs b/ricaun.Revit.UI.Example/Proprieties/Resource.Designer.cs index 7493315..6c78d82 100644 --- a/ricaun.Revit.UI.Example/Proprieties/Resource.Designer.cs +++ b/ricaun.Revit.UI.Example/Proprieties/Resource.Designer.cs @@ -63,9 +63,9 @@ internal Resource() { /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// - internal static System.Drawing.Bitmap icon { + internal static System.Drawing.Bitmap LargeImage { get { - object obj = ResourceManager.GetObject("icon", resourceCulture); + object obj = ResourceManager.GetObject("LargeImage", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } diff --git a/ricaun.Revit.UI.Example/Proprieties/Resource.resx b/ricaun.Revit.UI.Example/Proprieties/Resource.resx index 36cbcd7..f70cb1a 100644 --- a/ricaun.Revit.UI.Example/Proprieties/Resource.resx +++ b/ricaun.Revit.UI.Example/Proprieties/Resource.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + ..\resources\icon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/ricaun.Revit.UI.Example/Revit/App.cs b/ricaun.Revit.UI.Example/Revit/App.cs index a31b4be..c1bf631 100644 --- a/ricaun.Revit.UI.Example/Revit/App.cs +++ b/ricaun.Revit.UI.Example/Revit/App.cs @@ -40,7 +40,7 @@ public Result OnStartup(UIControlledApplication application) ribbonPanel.NewPushButtonData(), ribbonPanel.NewPushButtonData() }); - ribbonPanel.AddPushButton(""); + var button2 = ribbonPanel.AddPushButton(""); var items = ribbonPanel.AddStackedItems( ribbonPanel.NewPushButtonData("Item1"), @@ -48,9 +48,8 @@ public Result OnStartup(UIControlledApplication application) foreach (var item in items) { - var ri = item.GetRibbonItem(); - ri.ShowText = false; - ri.Size = Autodesk.Windows.RibbonItemSize.Large; + item.SetItemSize(); + item.SetText(); } var item3s = ribbonPanel.AddStackedItems( @@ -60,23 +59,22 @@ public Result OnStartup(UIControlledApplication application) foreach (var item in item3s) { - var ri = item.GetRibbonItem(); - ri.ShowText = false; + item.SetText(); } - + /* foreach (var item in ribbonPanel.GetItems()) { if (item is PushButton pushButton) { - pushButton.LargeImage = Proprieties.Resource.icon.GetBitmapSource(); - pushButton.Image = Proprieties.Resource.icon.GetBitmapSource().Scale(0.5); - pushButton.ToolTipImage = Proprieties.Resource.icon.GetBitmapSource().Scale(2); + pushButton.LargeImage = Proprieties.Resource.LargeImage.GetBitmapSource(); + pushButton.Image = Proprieties.Resource.LargeImage.GetBitmapSource().Scale(0.5); + pushButton.ToolTipImage = Proprieties.Resource.LargeImage.GetBitmapSource().Scale(2); } if (item is PulldownButton pulldownButton) { - pulldownButton.LargeImage = Proprieties.Resource.icon.GetBitmapSource(); - pulldownButton.Image = Proprieties.Resource.icon.GetBitmapSource().Scale(0.5); - pulldownButton.ToolTipImage = Proprieties.Resource.icon.GetBitmapSource().Scale(2); + pulldownButton.LargeImage = Proprieties.Resource.LargeImage.GetBitmapSource(); + pulldownButton.Image = Proprieties.Resource.LargeImage.GetBitmapSource().Scale(0.5); + pulldownButton.ToolTipImage = Proprieties.Resource.LargeImage.GetBitmapSource().Scale(2); } if (item is SplitButton splitButton) { @@ -84,26 +82,18 @@ public Result OnStartup(UIControlledApplication application) { if (i is PushButton pb) { - pb.LargeImage = Proprieties.Resource.icon.GetBitmapSource(); - pb.Image = Proprieties.Resource.icon.GetBitmapSource().Scale(0.5); - pb.ToolTipImage = Proprieties.Resource.icon.GetBitmapSource().Scale(2); + pb.LargeImage = Proprieties.Resource.LargeImage.GetBitmapSource(); + pb.Image = Proprieties.Resource.LargeImage.GetBitmapSource().Scale(0.5); + pb.ToolTipImage = Proprieties.Resource.LargeImage.GetBitmapSource().Scale(2); } } } } - - button.SetDescription(new RibbonDescription() - { - Text = "-", - LongDescription = "LongDescription", - ToolTip = "ToolTip", - LargeImage = Proprieties.Resource.icon.GetBitmapSource() - }); + */ ribbonPanel.GetRibbonPanel().Tab.SetOrderPanels(); var ric = ribbonPanel.GetRibbonPanel().Tab.Panels.ToList().FirstOrDefault(e => e.Source.Title == "ricaun"); ric?.MoveRibbonPanel(); - ric?.MoveRibbonPanel(); foreach (var item in ribbonPanel.GetRibbonItems()) { @@ -112,14 +102,21 @@ public Result OnStartup(UIControlledApplication application) ribbonPanel.UpdateRibbonDescription(setting => { + setting.Add("", + new RibbonDescription() + { + LargeImage = Proprieties.Resource.LargeImage.GetBitmapSource(), + Help = "https://ricaun.com" + } + ); + setting.Add( new RibbonDescription() { Text = "Hello", ToolTip = "This is a Tool Tip", LongDescription = "This is a Long Description", - Image = Proprieties.Resource.icon.GetBitmapSource().Scale(0.5), - LargeImage = Proprieties.Resource.icon.GetBitmapSource(), + LargeImage = Proprieties.Resource.LargeImage.GetBitmapSource(), Help = "https://ricaun.com" }, new RibbonDescription(LanguageType.Brazilian_Portuguese) diff --git a/ricaun.Revit.UI/RibbonDescriptionExtension.cs b/ricaun.Revit.UI/RibbonDescriptionExtension.cs index 6d58512..529e468 100644 --- a/ricaun.Revit.UI/RibbonDescriptionExtension.cs +++ b/ricaun.Revit.UI/RibbonDescriptionExtension.cs @@ -7,39 +7,74 @@ namespace ricaun.Revit.UI { + /// + /// RibbonSettings + /// public class RibbonSettings { - internal readonly Dictionary> valuePairs; + private readonly Dictionary> nameRibbonDescriptions; + /// + /// RibbonSettings + /// public RibbonSettings() { - valuePairs = new Dictionary>(); + nameRibbonDescriptions = new Dictionary>(); + } + + /// + /// Get Value + /// + /// + /// + /// + public bool TryGetValue(string name, out List ribbonDescriptions) + { + return nameRibbonDescriptions.TryGetValue(name, out ribbonDescriptions); } + /// + /// Add + /// + /// + /// public void Add(params RibbonDescription[] ribbonDescriptions) { var name = typeof(T).Name; Add(name, ribbonDescriptions); } + /// + /// Add + /// + /// + /// public void Add(string name, RibbonDescription ribbonDescription) { - if (valuePairs.TryGetValue(name, out List value)) + if (nameRibbonDescriptions.TryGetValue(name, out List value)) { value.Add(ribbonDescription); return; } - valuePairs[name] = new List(); - valuePairs[name].Add(ribbonDescription); + nameRibbonDescriptions[name] = new List(); + nameRibbonDescriptions[name].Add(ribbonDescription); } + /// + /// Add + /// + /// + /// public void Add(string name, params RibbonDescription[] ribbonDescriptions) { foreach (var ribbonDescription in ribbonDescriptions) Add(name, ribbonDescription); } - public int Count => valuePairs.Count; + /// + /// Get Count + /// + public int Count => nameRibbonDescriptions.Count; } /// @@ -47,6 +82,10 @@ public void Add(string name, params RibbonDescription[] ribbonDescriptions) /// public class RibbonDescription { + /// + /// RibbonDescription with LanguageType + /// + /// public RibbonDescription(LanguageType LanguageType = LanguageType.Unknown) { this.LanguageType = LanguageType; @@ -91,8 +130,12 @@ public RibbonDescription(LanguageType LanguageType = LanguageType.Unknown) /// public static class RibbonDescriptionExtension { - - + /// + /// Update RibbonPanel RibbonSettings + /// + /// + /// + /// public static RibbonPanel UpdateRibbonDescription(this RibbonPanel ribbonPanel, Action setting) { RibbonSettings ribbonSettings = new RibbonSettings(); @@ -100,12 +143,21 @@ public static RibbonPanel UpdateRibbonDescription(this RibbonPanel ribbonPanel, var language = LanguageExtension.GetLanguageType(); + if (ribbonSettings.TryGetValue("", out List valueDefault)) + { + foreach (var item in ribbonPanel.GetRibbonItems()) + { + item.UpdateRibbonDescription(valueDefault.First()); + item.UpdateRibbonDescription(valueDefault.FirstOrDefault(v => v.LanguageType == language)); + } + } + foreach (var item in ribbonPanel.GetRibbonItems()) { - if (ribbonSettings.valuePairs.TryGetValue(item.Name, out List value)) + if (ribbonSettings.TryGetValue(item.Name, out List value)) { - item.SetDescription(value.First()); - item.SetDescription(value.FirstOrDefault(v => v.LanguageType == language)); + item.UpdateRibbonDescription(value.First()); + item.UpdateRibbonDescription(value.FirstOrDefault(v => v.LanguageType == language)); } } @@ -141,36 +193,26 @@ public static IList GetRibbonItems(this RibbonPanel ribbonPanel) /// - /// Set Description + /// Update RibbonDescription /// /// /// /// - public static RibbonItem SetDescription(this RibbonItem ribbonItem, RibbonDescription description) + public static RibbonItem UpdateRibbonDescription(this RibbonItem ribbonItem, RibbonDescription description) { if (description == null) return ribbonItem; ribbonItem.SetText(description.Text); - - if (description.ToolTip != null) - ribbonItem.ToolTip = description.ToolTip; - - if (description.LongDescription != null) - ribbonItem.LongDescription = description.LongDescription; - - if (description.ToolTipImage != null) - ribbonItem.ToolTipImage = description.ToolTipImage; - + ribbonItem.SetToolTip(description.ToolTip); + ribbonItem.SetLongDescription(description.LongDescription); + ribbonItem.SetToolTipImage(description.ToolTipImage); ribbonItem.SetContextualHelp(description.Help); if (ribbonItem is RibbonButton ribbonButton) { - if (description.LargeImage != null) - ribbonButton.LargeImage = description.LargeImage; - - if (description.Image != null) - ribbonButton.Image = description.Image; + ribbonButton.SetImage(description.Image); + ribbonButton.SetLargeImage(description.LargeImage); } return ribbonItem; } @@ -234,6 +276,82 @@ public static RibbonItem SetText(this RibbonItem ribbonItem, string text = "") return ribbonItem; } + /// + /// Set RibbonItem ToolTip + /// + /// + /// + /// + public static RibbonItem SetToolTip(this RibbonItem ribbonItem, string toolTip) + { + if (toolTip != null) + ribbonItem.ToolTip = toolTip; + + return ribbonItem; + } + + /// + /// Set RibbonItem LongDescription + /// + /// + /// + /// + public static RibbonItem SetLongDescription(this RibbonItem ribbonItem, string longDescription) + { + if (longDescription != null) + ribbonItem.LongDescription = longDescription; + + return ribbonItem; + } + + /// + /// Set RibbonItem ToolTipImage + /// + /// + /// + /// + public static RibbonItem SetToolTipImage(this RibbonItem ribbonItem, ImageSource toolTipImage) + { + if (toolTipImage != null) + ribbonItem.ToolTipImage = toolTipImage; + + return ribbonItem; + } + + #endregion + + #region Set RibbonButton + /// + /// Set RibbonButton Image + /// + /// + /// + /// + public static RibbonButton SetImage(this RibbonButton ribbonButton, ImageSource image) + { + if (image != null) + ribbonButton.Image = image; + + return ribbonButton; + } + + /// + /// Set RibbonButton LargeImage + /// + /// + /// + /// + public static RibbonButton SetLargeImage(this RibbonButton ribbonButton, ImageSource largeImage) + { + if (largeImage != null) + { + ribbonButton.LargeImage = largeImage; + if (ribbonButton.Image == null) + ribbonButton.Image = largeImage.Scale(0.5); + } + + return ribbonButton; + } #endregion #region ContextualHelp From 66fd1aa0b9fcc526e188e9d992d18159a5ea2579 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Mon, 24 Jan 2022 16:44:51 -0300 Subject: [PATCH 8/9] Update Command --- ricaun.Revit.UI.Example/Revit/Commands/Command.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ricaun.Revit.UI.Example/Revit/Commands/Command.cs b/ricaun.Revit.UI.Example/Revit/Commands/Command.cs index 6f9129b..8552eec 100644 --- a/ricaun.Revit.UI.Example/Revit/Commands/Command.cs +++ b/ricaun.Revit.UI.Example/Revit/Commands/Command.cs @@ -13,10 +13,9 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme UIApplication uiapp = commandData.Application; //new Services.ReflectionService().GetFields(); - Console.WriteLine(typeof(Command).Assembly); //new Services.ReflectionService().GetMethods(); - + //Console.WriteLine(typeof(Command).Assembly); System.Windows.MessageBox.Show(AutodeskExtension.GetAutodeskOwner(), $"Hello Revit\n{DateTime.Now}"); return Result.Succeeded; From 0bd11b08d2a4b4f487f0d3a44ca85f2be1677dbb Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Tue, 25 Jan 2022 11:42:16 -0300 Subject: [PATCH 9/9] Update ChangeLog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8611c5d..342b649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Add SetImage / SetLongDescription - Add UpdateRibbonDescription - Add RibbonDescription - -## [0.0.5] / 2022-01-20 +-- [0.0.5] / 2022-01-20 - Add Move RibbonPanelTo - Add Remove RibbonTab - Add `GetRibbonPanel` using `m_RibbonPanel`