Skip to content

Commit

Permalink
Merge pull request #21 from ricaun-io/develop
Browse files Browse the repository at this point in the history
Version 0.3.1
  • Loading branch information
ricaun authored Aug 10, 2022
2 parents 89b6b9c + 17b49a8 commit c95a5f1
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 42 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ 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.3.1] / 2022-08-09
### Features
- Add `SetPanelsOrderByTitle` and `SetPanelsOrderBy`
### Added
- Add internal `ObservableCollectionExtension`
### Updated
- Update `MoveRibbonPanel`
- Update Order methods
- Update methods to `internal`

## [0.3.0] / 2022-08-08
### Features
- Add `IExternalCommandAvailability` on `NewToggleButtonData` Command
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ The method `GetRibbonItems` allow to select all `RibbonItem` concatenated on the
```C#
IList<RibbonItem> ribbonItems = ribbonPanel.GetRibbonItems();
```
The method `GetRibbonPanel` allow to select `Autodesk.Windows.RibbonPanel`.
```C#
Autodesk.Windows.RibbonPanel awRibbonPanel = ribbonPanel.GetRibbonPanel();
```
The method `Remove` allow to remove the `RibbonPanel` from `Autodesk.Windows` UI.
```C#
ribbonPanel.Remove();
Expand Down Expand Up @@ -219,10 +223,11 @@ Autodesk.Windows.RibbonTab awRibbonTab = ribbonPanel.GetRibbonTab();
Autodesk.Windows.RibbonTab awRibbonTab = RibbonTabExtension.GetRibbonTab("TabId");
IList<Autodesk.Windows.RibbonTab> awRibbonTabs = RibbonTabExtension.GetRibbonTabs();
```
The method `MoveRibbonPanel` and `SetOrderPanels` allow reorder the `RibbonPanel` in the `RibbonTab` UI.
The method `SetPanelsOrderBy` and `SetPanelsOrderByTitle` allow reorder the `RibbonPanel` in the `RibbonTab` UI.
```C#
ribbonPanel.MoveRibbonPanel(newIndex);
ribbonPanel.SetOrderPanels();
Autodesk.Windows.RibbonTab awRibbonTab = ribbonPanel.GetRibbonTab();
awRibbonTab.SetPanelsOrderBy(e => e.Source.Title);
awRibbonTab.SetPanelsOrderByTitle();
```
The method `Remove` allow to remove the `RibbonTab` from `Autodesk.Windows` UI.
```C#
Expand Down
4 changes: 2 additions & 2 deletions ricaun.Revit.UI.Example/Revit/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AppExample : IExternalApplication
private static RibbonPanel ribbonPanel;
public Result OnStartup(UIControlledApplication application)
{
ribbonPanel = application.CreatePanel("PanelName");
ribbonPanel = application.CreatePanel("ricaun", "ricaun");

var ribbonItem = ribbonPanel.CreatePushButton<Commands.Command>()
.SetText("Command")
Expand Down Expand Up @@ -595,7 +595,7 @@ public Result OnShutdown(UIControlledApplication application)

private void OrderPanelAndMove(RibbonPanel ribbonPanel)
{
ribbonPanel.GetRibbonTab().SetOrderPanels();
ribbonPanel.GetRibbonTab().SetPanelsOrderByTitle();
var ric = ribbonPanel.GetRibbonTab().Panels.FirstOrDefault(e => e.Source.Title == "ricaun");
ric?.MoveRibbonPanel();
}
Expand Down
2 changes: 1 addition & 1 deletion ricaun.Revit.UI.Example/ricaun.Revit.UI.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

<PropertyGroup>
<PackageId>ricaun.Revit.UI.Example</PackageId>
<Version>1.2.1</Version>
<Version>1.3.1</Version>
<ProjectGuid>{f736f68f-7101-4640-9093-8715f88ccb95}</ProjectGuid>
</PropertyGroup>

Expand Down
73 changes: 73 additions & 0 deletions ricaun.Revit.UI/ObservableCollectionExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace ricaun.Revit.UI
{
/// <summary>
/// ObservableCollectionExtension
/// </summary>
internal static class ObservableCollectionExtension
{
/// <summary>
/// Sort <paramref name="collection"/>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collection"></param>
/// <param name="comparison"></param>
internal static void Sort<T>(this ObservableCollection<T> collection, Comparison<T> comparison)
{
var sortableList = new List<T>(collection);
sortableList.Sort(comparison);

collection.Move(sortableList);
}

/// <summary>
/// OrderBy <paramref name="collection"/>
/// </summary>
/// <typeparam name="TSource"></typeparam>
/// <typeparam name="TKey"></typeparam>
/// <param name="collection"></param>
/// <param name="keySelector"></param>
internal static void OrderBy<TSource, TKey>(this ObservableCollection<TSource> collection, Func<TSource, TKey> keySelector)
{
var sortableList = new List<TSource>(collection);
sortableList = sortableList.OrderBy(keySelector)
.ToList();

collection.Move(sortableList);
}

/// <summary>
/// OrderByDescending <paramref name="collection"/>
/// </summary>
/// <typeparam name="TSource"></typeparam>
/// <typeparam name="TKey"></typeparam>
/// <param name="collection"></param>
/// <param name="keySelector"></param>
internal static void OrderByDescending<TSource, TKey>(this ObservableCollection<TSource> collection, Func<TSource, TKey> keySelector)
{
var sortableList = new List<TSource>(collection);
sortableList = sortableList.OrderByDescending(keySelector)
.ToList();

collection.Move(sortableList);
}

/// <summary>
/// Move <paramref name="collection"/> based on <paramref name="sortableList"/>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collection"></param>
/// <param name="sortableList"></param>
private static void Move<T>(this ObservableCollection<T> collection, List<T> sortableList)
{
for (int i = 0; i < sortableList.Count; i++)
{
collection.Move(collection.IndexOf(sortableList[i]), i);
}
}
}
}
21 changes: 21 additions & 0 deletions ricaun.Revit.UI/RibbonPanelExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,27 @@ public static RibbonPanel Remove(this RibbonPanel ribbonPanel, RibbonItem ribbon
}
#endregion

#region MoveRibbonPanel
/// <summary>
/// MoveRibbonPanel to Position
/// </summary>
/// <param name="ribbonPanel"></param>
/// <param name="newIndex"></param>
public static void MoveRibbonPanel(this Autodesk.Windows.RibbonPanel ribbonPanel, int newIndex = 0)
{
var ribbonTab = ribbonPanel.Tab;
var panels = ribbonTab.Panels;
var length = panels.Count;
if (length <= 1) return;

var index = panels.IndexOf(ribbonPanel);
if (index == -1) return;

newIndex = Math.Max(0, Math.Min(length - 1, newIndex));
panels.Move(panels.IndexOf(ribbonPanel), newIndex);
}
#endregion

#region Utils Private
private static bool IsTabContains(this RibbonPanel ribbonPanel)
{
Expand Down
2 changes: 1 addition & 1 deletion ricaun.Revit.UI/RibbonSafeExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ricaun.Revit.UI
/// <summary>
/// RibbonSaveExtension
/// </summary>
public static class RibbonSafeExtension
internal static class RibbonSafeExtension
{
/// <summary>
/// Safe Button Name
Expand Down
62 changes: 29 additions & 33 deletions ricaun.Revit.UI/RibbonTabExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -65,52 +66,47 @@ public static bool Remove(this Autodesk.Windows.RibbonTab ribbonTab)
#endregion

#region Order

/// <summary>
/// MoveRibbonPanel to Position
/// Set Panels Order <paramref name="keySelector"/>
/// </summary>
/// <param name="ribbonPanel"></param>
/// <param name="newIndex"></param>
public static void MoveRibbonPanel(this Autodesk.Windows.RibbonPanel ribbonPanel, int newIndex = 0)
/// <typeparam name="TKey"></typeparam>
/// <param name="ribbonTab"></param>
/// <param name="keySelector"></param>
/// <returns></returns>
public static Autodesk.Windows.RibbonTab SetPanelsOrderBy<TKey>(this Autodesk.Windows.RibbonTab ribbonTab, Func<Autodesk.Windows.RibbonPanel, TKey> keySelector)
{
var ribbonTab = ribbonPanel.Tab;
var panels = ribbonTab.Panels;
var length = panels.Count;
if (newIndex < 0) newIndex = length - 1 + newIndex;
if (newIndex >= length) newIndex = length - 1;
for (int i = 0; i < length; i++)
{
if (i == newIndex) continue;
if (panels[i] == ribbonPanel)
{
ribbonTab.Panels.Move(i, newIndex);
return;
}
}
if (ribbonTab.Panels.Count <= 1)
return ribbonTab;

ribbonTab.Panels.OrderBy(keySelector);
return ribbonTab;
}

/// <summary>
/// Set Panels Order By Title
/// </summary>
/// <param name="ribbonTab"></param>
/// <returns></returns>
public static Autodesk.Windows.RibbonTab SetPanelsOrderByTitle(this Autodesk.Windows.RibbonTab ribbonTab)
{
return ribbonTab.SetPanelsOrderBy(ComparationOrderByTitle);
}

/// <summary>
/// Set Order of Panels by Title
/// </summary>
/// <param name="ribbonTab"></param>
[Obsolete("This method gonna be removed, use SetPanelsOrderByTitle")]
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);
}
}
}
ribbonTab.SetPanelsOrderByTitle();
}

private static string ComparationOrderByTitle(Autodesk.Windows.RibbonPanel ribbonPanel)
{
return ribbonPanel.Source.Title;
}
#endregion

#region Util
Expand Down
2 changes: 1 addition & 1 deletion ricaun.Revit.UI/TypeExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ricaun.Revit.UI
/// <summary>
/// TypeExtension
/// </summary>
public static class TypeExtension
internal static class TypeExtension
{
/// <summary>
/// Get Name of the <paramref name="type"/> with GenericArguments
Expand Down
2 changes: 1 addition & 1 deletion ricaun.Revit.UI/ricaun.Revit.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

<PropertyGroup>
<PackageId>ricaun.Revit.UI</PackageId>
<Version>0.3.0</Version>
<Version>0.3.1</Version>
<ProjectGuid>{2064ba4d-5527-41e9-8b76-0cbfefa35900}</ProjectGuid>
</PropertyGroup>

Expand Down

0 comments on commit c95a5f1

Please sign in to comment.