Skip to content

Commit

Permalink
improving ribbon command name creation
Browse files Browse the repository at this point in the history
  • Loading branch information
salaros committed Jul 17, 2018
1 parent f041803 commit 55d02a2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Ribbon/RibbonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using Autodesk.Revit.UI;
Expand Down Expand Up @@ -107,6 +108,16 @@ public RibbonButton()
/// <seealso cref="RibbonButton" />
public abstract class RibbonButton
{
private static Regex commandNonWordChars;

/// <summary>
/// Initializes the <see cref="RibbonButton"/> class.
/// </summary>
static RibbonButton()
{
commandNonWordChars = new Regex(@"\W", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase);
}

/// <summary>
/// Gets the text.
/// </summary>
Expand Down Expand Up @@ -182,7 +193,7 @@ public static implicit operator PushButtonData(RibbonButton item)
{
return new PushButtonData
(
$"cmd{item.Text.Replace(" ", string.Empty)}",
$"cmd{commandNonWordChars.Replace(item.Text, string.Empty)}",
item.Text,
item.AssemblyPath,
$"{nameof(RevitAddin)}.{nameof(RibbonCommand)}"
Expand Down

0 comments on commit 55d02a2

Please sign in to comment.