Skip to content

Commit

Permalink
Update MoveToRibbonTab to move to Modify tab.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Nov 8, 2023
1 parent 50fe3d5 commit 3d72f79
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 24 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Update Remove and QuickAccess
### Updated
- Update `QuickAccessToolBarExtension` with internal methods.
- Update `MoveToRibbonTab` to move to `Modify` tab.
### Tests
- Add Tests for `QuickAccessToolBarExtension`
- Add Tests for `RibbonHelp` and `RibbonItem`
- Add Tests for `AppLoader`

- Add Tests for `MoveToRibbonTab`

## [0.5.5] / 2023-11-03
### Features
Expand Down
3 changes: 0 additions & 3 deletions ricaun.Revit.UI.Example/Revit/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,6 @@ private void AddNewPanelToMove(UIControlledApplication application)
.SetLargeImage("/UIFrameworkRes;component/ribbon/images/revit.ico");
}




//Console.WriteLine($">> {split}");

//var ribbonItem = button.GetRibbonItem();
Expand Down
2 changes: 2 additions & 0 deletions ricaun.Revit.UI.Example/Revit/AppExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public Result OnStartup(UIControlledApplication application)
.SetLongDescription("Esta é uma descrição.");
}

//ribbonPanel.MoveToRibbonTab();

return Result.Succeeded;
}

Expand Down
2 changes: 1 addition & 1 deletion ricaun.Revit.UI.Tests/Base/BaseCreatePanelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void SetUp(UIControlledApplication application)
}

[TearDown]
public void TearDown(UIControlledApplication application)
public void TearDown()
{
ribbonPanel?.Remove(true);
}
Expand Down
2 changes: 1 addition & 1 deletion ricaun.Revit.UI.Tests/Extensions/RevitRibbonHelpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void ContextualHelp_ShouldBe_Url(string helpPath)

[TestCase("file")]
[TestCase("help.pdf")]
[TestCase("C:\\help.pdf")]
[TestCase("ricaun.com")]
public void ContextualHelp_ShouldBe_ChmFile(string helpPath)
{
var contextualHelp = RibbonHelpExtension.GetContextualHelp(helpPath);
Expand Down
57 changes: 57 additions & 0 deletions ricaun.Revit.UI.Tests/Panels/RevitPanelMoveTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using NUnit.Framework;
using System.Linq;

namespace ricaun.Revit.UI.Tests.Panels
{
public class RevitPanelMoveTests : BaseCreatePanelTests
{
private const string TabIdAddIns = "Add-Ins";
private const string TabIdModify = "Modify";

[Test]
public void CreatePanel_ShouldBe_AddIns()
{
Assert.AreEqual(TabIdAddIns, ribbonPanel.GetRibbonTab().Id);
}

[Test]
public void MovePanelTo_Modify()
{
ribbonPanel.MoveToRibbonTab();
Assert.AreEqual(TabIdModify, ribbonPanel.GetRibbonTab().Id);
}

[Test]
public void MovePanelWithId_Modify()
{
ribbonPanel.MoveToRibbonTab(TabIdModify);
Assert.AreEqual(TabIdModify, ribbonPanel.GetRibbonTab().Id);
}

[Test]
public void MovePanelWithId_AddIns()
{
ribbonPanel.MoveToRibbonTab(TabIdModify);
ribbonPanel.MoveToRibbonTab(TabIdAddIns);
Assert.AreEqual(TabIdAddIns, ribbonPanel.GetRibbonTab().Id);
}

[Test]
public void MovePanelWithTab_First()
{
var ribbonTab = RibbonTabExtension.GetRibbonTabs().FirstOrDefault();
ribbonPanel.MoveToRibbonTab(ribbonTab);
Assert.AreEqual(ribbonTab, ribbonPanel.GetRibbonTab());
}

[Test]
public void MovePanelWithTab_ForEach()
{
foreach (var ribbonTab in RibbonTabExtension.GetRibbonTabs())
{
ribbonPanel.MoveToRibbonTab(ribbonTab);
Assert.AreEqual(ribbonTab, ribbonPanel.GetRibbonTab());
}
}
}
}
37 changes: 29 additions & 8 deletions ricaun.Revit.UI.Tests/Panels/RevitPanelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,48 @@ public class RevitPanelTests
{
private const string PanelName = "Example";

UIControlledApplication application;

[SetUp]
public void SetUp(UIControlledApplication application)
{
this.application = application;
var panel = application.GetRibbonPanels().FirstOrDefault();
System.Console.WriteLine($"RibbonTab: {panel?.GetRibbonTab().Id}");
}

private bool ContainPanel(UIControlledApplication application, RibbonPanel panel)
private bool ContainPanel(RibbonPanel panel)
{
return application.GetRibbonPanels().Contains(panel);
}

[Test]
public void CreatePanel(UIControlledApplication application)
public void CreatePanel()
{
var panel = application.CreatePanel(PanelName);
foreach (var item in RibbonTabExtension.GetRibbonTabsDictionary(panel.GetRibbonTab()))
{
System.Console.WriteLine(item);
}
Assert.IsTrue(ContainPanel(application, panel), "Contain Panel");
Assert.IsTrue(ContainPanel(panel), "Contain Panel");
panel?.Remove();
Assert.IsFalse(ContainPanel(application, panel), "Not Contain Panel");
Assert.IsFalse(ContainPanel(panel), "Not Contain Panel");
}

[Test]
public void CreatePanel_10Times(UIControlledApplication application)
public void CreatePanel_10Times()
{
for (int i = 0; i < 10; i++)
{
var panel = application.CreatePanel(PanelName);
Assert.IsTrue(ContainPanel(application, panel), "Contain Panel");
Assert.IsTrue(ContainPanel(panel), "Contain Panel");
panel?.Remove();
Assert.IsFalse(ContainPanel(application, panel), "Not Contain Panel");
Assert.IsFalse(ContainPanel(panel), "Not Contain Panel");
}
}

[Test]
public void RemovePanel_DisableFloating(UIControlledApplication application)
public void RemovePanel_DisableFloating()
{
var panel = application.CreatePanel(PanelName);
panel.GetRibbonPanel().IsFloating = true;
Expand All @@ -56,6 +59,24 @@ public void RemovePanel_DisableFloating(UIControlledApplication application)
Assert.IsFalse(panel.GetRibbonPanel().IsFloating, "Panel Should not be Floating");
}

[Test]
public void RemovePanel_ShouldBe_NotEnable()
{
var panel = application.CreatePanel(PanelName);
Assert.IsTrue(panel.Enabled, "Panel Should be Enabled");
panel.Remove();
Assert.IsFalse(panel.Enabled, "Panel Should be not Enabled");
}

[Test]
public void RemovePanel_ShouldBe_NotVisible()
{
var panel = application.CreatePanel(PanelName);
Assert.IsTrue(panel.Visible, "Panel Should be Visible");
panel.Remove();
Assert.IsFalse(panel.Visible, "Panel Should be not Visible");
}

[Test]
public void RemovePanel_IgnoreIfNull()
{
Expand Down
18 changes: 10 additions & 8 deletions ricaun.Revit.UI.Tests/Panels/RevitTabPanelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,50 @@ public class RevitTabPanelTests
private const string TabName = "RevitTabPanelTests";
private const string PanelName = "Example";
private static RibbonPanel ribbonPanel;
private UIControlledApplication application;

[SetUp]
public void SetUp(UIControlledApplication application)
{
this.application = application;
ribbonPanel = application.CreatePanel(TabName, PanelName);
ribbonPanel.Remove();
System.Console.WriteLine($"RibbonTab: {ribbonPanel.GetRibbonTab().Id}");
}

private bool ContainPanel(UIControlledApplication application, RibbonPanel panel)
private bool ContainPanel(RibbonPanel panel)
{
var tabName = panel.GetRibbonTab().Id;
return application.GetRibbonPanels(tabName).Contains(panel);
}

[Test]
public void CreatePanel(UIControlledApplication application)
public void CreatePanel()
{
var panel = application.CreatePanel(TabName, PanelName);
foreach (var item in RibbonTabExtension.GetRibbonTabsDictionary(panel.GetRibbonTab()))
{
System.Console.WriteLine(item);
}
Assert.IsTrue(ContainPanel(application, panel), "Contain Panel");
Assert.IsTrue(ContainPanel(panel), "Contain Panel");
panel?.Remove();
Assert.IsFalse(ContainPanel(application, panel), "Not Contain Panel");
Assert.IsFalse(ContainPanel(panel), "Not Contain Panel");
}

[Test]
public void CreatePanel_10Times(UIControlledApplication application)
public void CreatePanel_10Times()
{
for (int i = 0; i < 10; i++)
{
var panel = application.CreatePanel(TabName, PanelName);
Assert.IsTrue(ContainPanel(application, panel), "Contain Panel");
Assert.IsTrue(ContainPanel(panel), "Contain Panel");
panel?.Remove();
Assert.IsFalse(ContainPanel(application, panel), "Not Contain Panel");
Assert.IsFalse(ContainPanel(panel), "Not Contain Panel");
}
}

[TearDown]
public void TearDown(UIControlledApplication application)
public void TearDown()
{
if (!string.IsNullOrEmpty(TabName))
ribbonPanel.GetRibbonTab().Remove();
Expand Down
10 changes: 10 additions & 0 deletions ricaun.Revit.UI/RibbonPanelExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ public static RibbonPanel Remove(this RibbonPanel ribbonPanel)
return ribbonPanel;
}

/// <summary>
/// Move RibbonPanel to RibbonTab 'Modify'/>
/// </summary>
/// <param name="ribbonPanel"></param>
/// <returns></returns>
public static RibbonPanel MoveToRibbonTab(this RibbonPanel ribbonPanel)
{
return ribbonPanel.MoveToRibbonTab("Modify");
}

/// <summary>
/// Move RibbonPanel to RibbonTab with <paramref name="ribbonTabId"/>
/// <code>'Modify' | 'Add-Ins'</code>
Expand Down
13 changes: 11 additions & 2 deletions ricaun.Revit.UI/Utils/RibbonModifyUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ internal static class RibbonModifyUtils
{
private const string MODIFY_PANEL_ID = "Modify";

/// <summary>
/// Get RibbonTab of Modify
/// </summary>
/// <returns></returns>
public static Autodesk.Windows.RibbonTab RibbonTab()
{
return RibbonTabExtension.GetRibbonTab(MODIFY_PANEL_ID);
}

/// <summary>
/// Create Panel with <paramref name="panelName"/> to Modify Tab. And add the <paramref name="ribbonItems"/> to the Panel.
/// </summary>
Expand Down Expand Up @@ -46,7 +55,7 @@ public static Autodesk.Windows.RibbonPanel CreateRibbonPanel(string panelName, p
/// <returns></returns>
public static Autodesk.Windows.RibbonPanel CreateRibbonPanel(string panelName)
{
var modifyTab = Autodesk.Windows.ComponentManager.Ribbon.FindTab(MODIFY_PANEL_ID);
var modifyTab = RibbonTab();
var modifyPanel = modifyTab.CreateRibbonPanel(panelName);
return modifyPanel;
}
Expand All @@ -58,7 +67,7 @@ public static Autodesk.Windows.RibbonPanel CreateRibbonPanel(string panelName)
/// <returns></returns>
public static Autodesk.Windows.RibbonPanel RemoveRibbonPanel(string panelName)
{
var modifyTab = Autodesk.Windows.ComponentManager.Ribbon.FindTab(MODIFY_PANEL_ID);
var modifyTab = RibbonTab();
var modifyPanel = modifyTab.RemoveRibbonPanel(panelName);
return modifyPanel;
}
Expand Down

0 comments on commit 3d72f79

Please sign in to comment.