152 lines
4.9 KiB
C#
152 lines
4.9 KiB
C#
using Autodesk.Revit.UI;
|
|
using Autodesk.Windows;
|
|
|
|
namespace Sai.RvKits.UIRibbon;
|
|
|
|
public class TabManagerApp
|
|
{
|
|
public TabManagerApp(UIControlledApplication application)
|
|
{
|
|
var tab = RibbonControl.Tabs.First(t => t.Name == Properties.Settings.Default.TabName);
|
|
|
|
SetTabControl(tab);
|
|
application.ViewActivating += Application_ViewActivating;
|
|
application.ControlledApplication.ApplicationInitialized += ControlledApplication_ApplicationInitialized;
|
|
}
|
|
|
|
private Autodesk.Windows.RibbonPanel addInManagerPanel;
|
|
private static RibbonControl RibbonControl => ComponentManager.Ribbon;
|
|
|
|
private void InsertQuickAccessAndHidePanel()
|
|
{
|
|
var tab = RibbonControl.FindTab(Properties.Settings.Default.TabName);
|
|
|
|
if (tab != null && addInManagerPanel != null)
|
|
{
|
|
var checklistButton = addInManagerPanel.Source.Items.FirstOrDefault();
|
|
ComponentManager.QuickAccessToolBar.AddStandardItem(checklistButton);
|
|
//移除面板
|
|
tab.Panels.Remove(addInManagerPanel);
|
|
}
|
|
}
|
|
|
|
private void SetTabControl(RibbonTab customRibbonTab)
|
|
{
|
|
addInManagerPanel = new Autodesk.Windows.RibbonPanel { FloatingOrientation = System.Windows.Controls.Orientation.Horizontal };
|
|
|
|
//面板资源
|
|
RibbonPanelSource panelSource = new() { Id = "ID_AddIns_Panel", Title = "插件管理" };
|
|
//面板源设置
|
|
addInManagerPanel.Source = panelSource;
|
|
RibbonChecklistButton checklist =
|
|
new()
|
|
{
|
|
Id = "Id_AddIns_CL",
|
|
Text = "插件管理",
|
|
Name = "插件管理",
|
|
Description = "控制插件在Revit界面上的显示",
|
|
Image = Properties.Resources.addin_16px.ToBitmapSource(),
|
|
LargeImage = Properties.Resources.addin_32px.ToBitmapSource(),
|
|
ShowText = true,
|
|
ShowImage = true,
|
|
ToolTip = "控制插件在Revit界面上的显示",
|
|
IsToolTipEnabled = true,
|
|
IsVisible = true,
|
|
IsEnabled = true,
|
|
Size = RibbonItemSize.Standard,
|
|
AllowInToolBar = true,
|
|
AllowInStatusBar = true,
|
|
IsCheckable = true
|
|
};
|
|
|
|
var ribbon = ComponentManager.Ribbon;
|
|
foreach (var tab in ribbon.Tabs)
|
|
{
|
|
if (tab.GetType() == typeof(RibbonTab) && tab.Title != Properties.Settings.Default.TabName)
|
|
{
|
|
RibbonToggleButton ribbonToggleButton =
|
|
new()
|
|
{
|
|
//Image = ConvertFromBitmap(Properties.Resources.Select_View_16px),
|
|
//LargeImage = ConvertFromBitmap(Properties.Resources.Select_View_32px),
|
|
//ShowImage = true,
|
|
Size = RibbonItemSize.Standard,
|
|
ShowText = true,
|
|
Id = $"Id_{tab.Title}_Tg",
|
|
Name = tab.Title,
|
|
Text = tab.Title,
|
|
IsEnabled = true,
|
|
IsVisible = true,
|
|
IsCheckable = true,
|
|
IsThreeState = false,
|
|
IsChecked = true
|
|
//CheckStateBinding = new System.Windows.Data.Binding()
|
|
//{
|
|
// Source = tab,
|
|
// Path = new PropertyPath(tab.IsVisible),
|
|
//},
|
|
//CommandHandler = new RelayCommand<object>((obj) =>
|
|
//{
|
|
// if (obj is Autodesk.Windows.RibbonButton rb)
|
|
// {
|
|
// string tabName = rb.CommandParameter.ToString();
|
|
// var ribbonTab = ribbon.FindAwTab(tabName);
|
|
// ribbonTab.IsVisible = true;
|
|
// }
|
|
//}),
|
|
//CommandParameter = tab.Name
|
|
//Orientation = System.Windows.Controls.Orientation.Horizontal
|
|
};
|
|
ribbonToggleButton.CheckStateChanged += RibbonToggleButton_CheckStateChanged;
|
|
checklist.Items.Add(ribbonToggleButton);
|
|
}
|
|
}
|
|
|
|
////布局
|
|
//RibbonRowPanel ribbonRowPanel = new RibbonRowPanel();
|
|
////按钮添加到流布局
|
|
//ribbonRowPanel.Items.Add(checklist);
|
|
//添加到绑定源
|
|
panelSource.Items.Add(checklist);
|
|
|
|
customRibbonTab.Panels.Add(addInManagerPanel);
|
|
//source.AddStandardItem(checklist);
|
|
}
|
|
//如果是族文档,在激活视图时,隐藏面板
|
|
private static void SetTabEnabled(string tabName, bool isVisible)
|
|
{
|
|
//Autodesk.Windows.RibbonTab revitRibbonTab = UIFramework.RevitRibbonControl.RibbonControl.FindAwTab(Properties.Settings.Default.TabName);
|
|
//revitRibbonTab.IsVisible = false;
|
|
var ribbon = ComponentManager.Ribbon;
|
|
var ribbonTab = ribbon.FindTab(tabName);
|
|
ribbonTab.IsVisible = isVisible;
|
|
//foreach (Autodesk.Windows.RibbonTab tab in ribbon.Tabs)
|
|
//{
|
|
// if (tab.Title == Properties.Settings.Default.TabName)
|
|
// {
|
|
// tab.IsVisible = isVisible;
|
|
// }
|
|
//}
|
|
}
|
|
//如果是族文档,在激活视图时,隐藏面板
|
|
private void Application_ViewActivating(object sender, Autodesk.Revit.UI.Events.ViewActivatingEventArgs e)
|
|
{
|
|
SetTabEnabled(Properties.Settings.Default.TabName, !e.NewActiveView.Document.IsFamilyDocument);
|
|
}
|
|
|
|
private void ControlledApplication_ApplicationInitialized(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e)
|
|
{
|
|
InsertQuickAccessAndHidePanel();
|
|
}
|
|
|
|
private void RibbonToggleButton_CheckStateChanged(object sender, EventArgs e)
|
|
{
|
|
if (sender is RibbonToggleButton toggleButton)
|
|
{
|
|
var tabName = toggleButton.Name;
|
|
var tab = TabManagerApp.RibbonControl.FindTab(tabName);
|
|
tab.IsVisible = toggleButton.IsChecked;
|
|
}
|
|
}
|
|
}
|