Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New version selector #2064

Open
wants to merge 4 commits into
base: Revit2018
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions src/Legacy/DynamoRevitVersionSelector/CommandsBinders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System;
using System.Collections.Generic;
using Autodesk.Revit.UI;
using System.Linq;
using DynamoRevitVersionSelector.Properties;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Diagnostics;
using Autodesk.Revit.UI.Events;

namespace Dynamo.Applications
{
/// <summary>
/// Bind/Unbind Ribbons Icon actions
/// </summary>
internal class CommandsBinders
{
#region Statics
/// <summary>
/// Dynamo Command ID
/// </summary>
public static readonly string DYNAMOID = "ID_VISUAL_PROGRAMMING_DYNAMO";

/// <summary>
/// Dynamo Player Command ID
/// </summary>
public static readonly string PLAYERID = "ID_PLAYLIST_DYNAMO";
#endregion

public event EventHandler<ExecutedEventArgs> OnDynamoClick;
public event EventHandler<ExecutedEventArgs> OnDynamoPlayerClick;

private UIControlledApplication uiControlledApplication;
private RevitCommandId DynamoCmdId;
private AddInCommandBinding DynamoCommand = null;
private RevitCommandId DynamoPlayerCmdId;
private AddInCommandBinding DynamoPlayerCommand = null;

private bool BindDynamoPlayer;

/// <summary>
/// Is Binding has been done
/// </summary>
public bool IsBinded { get; private set; }

/// <summary>
/// Constructor, Class to Bind/Unbind Ribbons Icon actions
/// </summary>
/// <param name="application"></param>
/// <param name="bindDynamoPlayer"></param>
public CommandsBinders(UIControlledApplication application, bool bindDynamoPlayer)
{
uiControlledApplication = application;
BindDynamoPlayer = bindDynamoPlayer;
DynamoCmdId = RevitCommandId.LookupCommandId(DYNAMOID);
DynamoPlayerCmdId = RevitCommandId.LookupCommandId(PLAYERID);
if (uiControlledApplication == null || DynamoCmdId == null || DynamoPlayerCmdId == null)
throw new ArgumentNullException();
IsBinded = false;
}

/// <summary>
/// Bind Ribbons Icon actions
/// </summary>
public void Bind()
{
if (IsBinded) return;
if (null == DynamoCommand)
{
DynamoCommand = uiControlledApplication.CreateAddInCommandBinding(DynamoCmdId);
DynamoCommand.CanExecute += canExecute;
DynamoCommand.BeforeExecuted += beforeExecuted;
DynamoCommand.Executed += executedDynamo;
}
if (null == DynamoPlayerCommand && BindDynamoPlayer)
{
DynamoPlayerCommand = uiControlledApplication.CreateAddInCommandBinding(DynamoPlayerCmdId);
DynamoPlayerCommand.CanExecute += canExecute;
DynamoPlayerCommand.BeforeExecuted += beforeExecuted;
DynamoPlayerCommand.Executed += executedPlayer;
}
IsBinded = true;
}

/// <summary>
/// UnBind Ribbons Icon actions
/// </summary>
public void UnBind()
{
if (!IsBinded) return;
if (null != DynamoCommand)
{
uiControlledApplication.RemoveAddInCommandBinding(DynamoCmdId);
DynamoCommand.BeforeExecuted -= beforeExecuted;
DynamoCommand.CanExecute -= canExecute;
DynamoCommand.Executed -= executedDynamo;
DynamoCommand = null;
}
if (null != DynamoPlayerCommand)
{
uiControlledApplication.RemoveAddInCommandBinding(DynamoPlayerCmdId);
DynamoPlayerCommand.BeforeExecuted -= beforeExecuted;
DynamoPlayerCommand.CanExecute -= canExecute;
DynamoPlayerCommand.Executed -= executedPlayer;
DynamoPlayerCommand = null;
}
IsBinded = false;
}

private void beforeExecuted(object sender, BeforeExecutedEventArgs e)
{
e.UsingCommandData = true;
}

private void canExecute(object sender, CanExecuteEventArgs e)
{
e.CanExecute = e.ActiveDocument != null;
}

private void executedDynamo(object sender, ExecutedEventArgs e)
{
OnDynamoClick(sender, e);
}

private void executedPlayer(object sender, ExecutedEventArgs e)
{
OnDynamoPlayerClick(sender, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="RevitAPI">
<HintPath>$(REVITAPI)\RevitAPI.dll</HintPath>
<Reference Include="AdWindows">
<HintPath>$(REVITAPI)\AdWindows.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RevitAPIUI">
<HintPath>$(REVITAPI)\RevitAPIUI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RevitAPI">
<HintPath>$(REVITAPI)\RevitAPI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
Expand All @@ -54,6 +58,9 @@
<Compile Include="$(SolutionDir)AssemblySharedInfoGenerator\AssemblySharedInfo.cs">
<Link>Properties\AssemblySharedInfo.cs</Link>
</Compile>
<Compile Include="CommandsBinders.cs" />
<Compile Include="Product.cs" />
<Compile Include="ProductsManager.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand All @@ -64,21 +71,13 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.en-US.resx</DependentUpon>
</Compile>
<Compile Include="Tools\ImageConversion.cs" />
<Compile Include="Tools\Presistence.cs" />
<Compile Include="Tools\UI.cs" />
<Compile Include="VersionDialog.cs" />
<Compile Include="VersionSelectorApp.cs" />
<Compile Include="DynamoVersionSelector.xaml.cs">
<DependentUpon>DynamoVersionSelector.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="DynamoVersionSelector.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Resource Include="logo_about.png" />
<None Include="Resources\dynamo_32x32.png" />
<Compile Include="VersionSelectorButton.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
Expand All @@ -90,6 +89,9 @@
<LastGenOutput>Resources.en-US.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Resources\dynamo_setting_32x32.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
15 changes: 0 additions & 15 deletions src/Legacy/DynamoRevitVersionSelector/DynamoVersionSelector.xaml

This file was deleted.

This file was deleted.

Loading