Skip to content

Commit

Permalink
Clear RevitBusy
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Aug 14, 2024
1 parent da958fd commit 2fd8f02
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 74 deletions.
11 changes: 7 additions & 4 deletions Revit.Busy.Example/Revit.Busy.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,10 @@

<ItemGroup>
<PackageReference Include="ricaun.Revit.UI" Version="*" />
<PackageReference Include="ricaun.Revit.UI.Tasks" Version="*" />
<PackageReference Include="ricaun.Revit.Mvvm" Version="*" />
</ItemGroup>

<ItemGroup>
<Folder Include="Revit\Commands" />
</ItemGroup>

<ItemGroup>
<None Include="Revit\App.cs" />
<None Include="Revit\Commands\Command.cs" />
Expand All @@ -129,4 +126,10 @@
<ProjectReference Include="..\Revit.Busy\Revit.Busy.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Revit\Views\BusyView.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>

</Project>
38 changes: 20 additions & 18 deletions Revit.Busy.Example/Revit/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,57 @@
using Autodesk.Revit.UI;
using Revit.Busy;
using ricaun.Revit.UI;
using ricaun.Revit.UI.Tasks;
using System;
namespace Revit.Busy.Example.Revit
{
[AppLoader]
public class App : IExternalApplication
{
private static RevitTaskService revitTaskService;
public static IRevitTask RevitTask => revitTaskService;

private static RibbonPanel ribbonPanel;
private static RibbonItem ribbonItem;
private static RevitBusyService RevitBusyService;
public Result OnStartup(UIControlledApplication application)
{
revitTaskService = new RevitTaskService(application);
revitTaskService.Initialize();

ribbonPanel = application.CreatePanel("Example");
ribbonItem = ribbonPanel.CreatePushButton<Commands.Command>("RevitBusy")
var ribbonItem = ribbonPanel.CreatePushButton<Commands.Command>("RevitBusy")
.SetLargeImage("/UIFrameworkRes;component/ribbon/images/revit.ico");

var viewButton = ribbonPanel.CreatePushButton<Commands.CommandView>("View")
.SetLargeImage("/UIFrameworkRes;component/ribbon/images/revit.ico");

//RevitBusyControl.Initialize(application);
//RevitBusyControl.Control.PropertyChanged += RevitBusyControlPropertyChanged;
RevitBusyService = new RevitBusyService(application);
RevitBusyService.PropertyChanged += RevitBusyControlPropertyChanged;
RevitBusyService.PropertyChanged += (s, e) =>
{
UpdateLargeImageBusy(ribbonItem, RevitBusyService.IsRevitBusy);
UpdateLargeImageBusy(viewButton, RevitBusyService.IsRevitBusy);
};

UpdateLargeImageBusy(ribbonItem, RevitBusyControl.Control);
RevitBusyControl.Initialize(application);

return Result.Succeeded;
}

private void RevitBusyControlPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
Console.WriteLine($"RevitBusyControl PropertyChanged {e.PropertyName} {RevitBusyControl.Control.IsRevitBusy}");

var control = sender as RevitBusyService;
UpdateLargeImageBusy(ribbonItem, control);
}

public Result OnShutdown(UIControlledApplication application)
{
ribbonPanel?.Remove();
if (RevitBusyControl.Control is not null)
RevitBusyControl.Control.PropertyChanged -= RevitBusyControlPropertyChanged;

RevitBusyService?.Dispose();
revitTaskService?.Dispose();

return Result.Succeeded;
}

private static void UpdateLargeImageBusy(RibbonItem ribbonItem, RevitBusyService control)
private static void UpdateLargeImageBusy(RibbonItem ribbonItem, bool revitBusy)
{
const string LargeImageIsBusy = "/UIFrameworkRes;component/ribbon/images/close.ico";
const string LargeImageNoBusy = "/UIFrameworkRes;component/ribbon/images/add.ico";
if (control.IsRevitBusy)
if (revitBusy)
ribbonItem.SetLargeImage(LargeImageIsBusy);
else
ribbonItem.SetLargeImage(LargeImageNoBusy);
Expand Down
13 changes: 13 additions & 0 deletions Revit.Busy.Example/Revit/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,17 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme

public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; }
}

[Transaction(TransactionMode.Manual)]
public class CommandView : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIApplication uiapp = commandData.Application;

new Views.BusyView().Show();

return Result.Succeeded;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Window x:Class="Revit.Busy.Revit.Views.BusyView"
<Window x:Class="Revit.Busy.Example.Revit.Views.BusyView"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Revit.Busy.Revit.Views"
xmlns:busy="clr-namespace:Revit.Busy"
xmlns:local="clr-namespace:Revit.Busy.Example.Revit.Views"
xmlns:busy="clr-namespace:Revit.Busy.Example.Revit.Views"
mc:Ignorable="d"
Background="WhiteSmoke"
>
Expand All @@ -16,7 +16,7 @@
</Window.Resources>

<Grid Margin="15">
<Grid IsEnabled="{Binding IsRevitBusy, Source={x:Static busy:RevitBusyControl.Control}, Converter={StaticResource InverseBooleanConverter}}">
<Grid IsEnabled="{Binding IsRevitBusy, Source={x:Static busy:Controls.Control}, Converter={StaticResource InverseBooleanConverter}}">
<Button HorizontalAlignment="Center"
VerticalAlignment="Center"
Height="120"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Windows;
using System.Windows.Data;

namespace Revit.Busy.Revit.Views
namespace Revit.Busy.Example.Revit.Views
{
[PropertyChanged.AddINotifyPropertyChangedInterface]
public partial class BusyView : Window
Expand All @@ -25,6 +25,7 @@ await App.RevitTask.Run((uiapp) =>
});
});

this.Title = "Wall - BusyView";
InitializeComponent();
InitializeWindow();
}
Expand All @@ -41,6 +42,11 @@ private void InitializeWindow()
#endregion
}

public class Controls
{
public static RevitBusyService Control => RevitBusyControl.Control;
}

[ValueConversion(typeof(bool), typeof(bool))]
public class InverseBooleanConverter : IValueConverter
{
Expand Down
15 changes: 0 additions & 15 deletions Revit.Busy/Revit.Busy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,12 @@

<ItemGroup Condition="$(Configuration.Contains('Debug'))">
<PackageReference Include="ricaun.Revit.UI" Version="*" />
<PackageReference Include="ricaun.Revit.Mvvm" Version="*" />
<PackageReference Include="ricaun.Revit.UI.Tasks" Version="*" />
</ItemGroup>

<ItemGroup>
<None Include="Revit\App.cs" />
<None Include="Revit\Commands\Command.cs" />
</ItemGroup>

<!-- Fody -->
<ItemGroup Condition="$(Configuration.Contains('Debug'))">
<PackageReference Include="PropertyChanged.Fody" Version="3.*" IncludeAssets="build; compile" PrivateAssets="all" />
</ItemGroup>
<PropertyGroup>
<WeaverConfiguration>
<Weavers>
<PropertyChanged />
</Weavers>
</WeaverConfiguration>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Revit_All_Main_Versions_API_x64" Version="$(RevitVersion).*-*" IncludeAssets="build; compile" PrivateAssets="All" />
</ItemGroup>
Expand Down
27 changes: 17 additions & 10 deletions Revit.Busy/Revit/App.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using ricaun.Revit.UI;
using ricaun.Revit.UI.Tasks;
using System;

namespace Revit.Busy.Revit
{
[AppLoader]
//[AppLoader]
public class App : IExternalApplication
{
private static RevitTaskService revitTaskService;
public static IRevitTask RevitTask => revitTaskService;

[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand, IExternalCommandAvailability
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIApplication uiapp = commandData.Application;

return Result.Succeeded;
}

public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories) { return true; }
}


private static RibbonPanel ribbonPanel;
private static RibbonItem ribbonItem;
public Result OnStartup(UIControlledApplication application)
{
revitTaskService = new RevitTaskService(application);
revitTaskService.Initialize();

ribbonPanel = application.CreatePanel("Revit.Busy");
ribbonItem = ribbonPanel.CreatePushButton<Commands.Command>("View")
ribbonItem = ribbonPanel.CreatePushButton<Command>("Busy")
.SetLargeImage("/UIFrameworkRes;component/ribbon/images/revit.ico");

RevitBusyControl.Initialize(application);
Expand All @@ -41,8 +50,6 @@ private void RevitBusyControlPropertyChanged(object sender, System.ComponentMode

public Result OnShutdown(UIControlledApplication application)
{
revitTaskService?.Dispose();

ribbonPanel?.Remove();
RevitBusyControl.Control.PropertyChanged -= RevitBusyControlPropertyChanged;
RevitBusyControl.Dispose();
Expand Down
22 changes: 0 additions & 22 deletions Revit.Busy/Revit/Commands/Command.cs

This file was deleted.

0 comments on commit 2fd8f02

Please sign in to comment.