Skip to content

Commit

Permalink
#16 - allow to frezee item in the Utility Tree componenet
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed Oct 4, 2023
1 parent 1c332c2 commit d75eabd
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 35 deletions.
2 changes: 1 addition & 1 deletion sources/RevitDBExplorer/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
if (numberOfWindowsInMemory > 3)
{
#if DEBUG
throw new Exception("There is probably a memory leak.");
//throw new Exception("There is probably a memory leak.");
#endif
}

Expand Down
24 changes: 21 additions & 3 deletions sources/RevitDBExplorer/Domain/DataModel/SnoopableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ internal class SnoopableObject : BaseViewModel
public string TypeName { get; }
public IEnumerable<SnoopableObject> Items => items;
public int Index { get; init; } = -1;
public bool IsFrozen
{
get
{
return isFrozen;
}
set
{
isFrozen = value;
OnPropertyChanged();
}
}


public SnoopableObject(Document document, object @object) : this(document, @object, null)
Expand Down Expand Up @@ -113,11 +125,16 @@ private static IEnumerable<SnoopableMember> CreateMembers(SnoopableObject snoopa
private static readonly Type[] doNotFreeze = new Type[] { typeof(Document) , typeof(View), typeof(Element), typeof(Transform) };
public void Freeze(int candies = 0)
{
if (candies > 1) return;
if (candies > 2) return;

if (Object == null)
{
return;
}

if (candies != 0)
{
var objectType = Object.GetType();
var objectType = Object?.GetType();
foreach (var forbiden in doNotFreeze)
{
if (forbiden.IsAssignableFrom(objectType))
Expand All @@ -132,7 +149,8 @@ public void Freeze(int candies = 0)
frozenMembers = GetMembers(null).ToList();
frozenMembers.ForEach(x => x.Freeze(candies));
isFrozen = true;
NamePostfix = DateTime.Now.ToString("HH:mm:ss");
NamePostfix = "*"+DateTime.Now.ToString("HH:mm:ss");
OnPropertyChanged(nameof(NamePostfix));
}
catch (Exception ex)
{
Expand Down
33 changes: 33 additions & 0 deletions sources/RevitDBExplorer/Domain/Presentation/FreezeCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using RevitDBExplorer.Domain.DataModel;
using RevitDBExplorer.UIComponents.Trees.Base.Items;
using RevitDBExplorer.WPF;

namespace RevitDBExplorer.Domain.Presentation
{
internal class FreezeCommand : BaseCommand
{
public static readonly FreezeCommand Instance = new FreezeCommand();

public override bool CanExecute(object parameter)
{
if (parameter is SnoopableObjectTreeItem treeViewItem)
{
if (treeViewItem.Object is SnoopableObject snoopableObject)
{
return !snoopableObject.IsFrozen;
}
}
return false;
}
public override void Execute(object parameter)
{
if (parameter is SnoopableObjectTreeItem treeViewItem)
{
if (treeViewItem.Object is SnoopableObject snoopableObject)
{
snoopableObject.Freeze();
}
}
}
}
}
19 changes: 11 additions & 8 deletions sources/RevitDBExplorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,18 @@ private async void Tree_SelectedItemChanged(SelectedItemChangedEventArgs eventAr
{
List.ClearItems();

if (eventArgs.Sender == ExplorerTree)
if (eventArgs.NewOne != null)
{
if (UtilityTree.SelectedItem != null)
UtilityTree.SelectedItem.IsSelected = false;
}
if (eventArgs.Sender == UtilityTree)
{
if (ExplorerTree.SelectedItem != null)
ExplorerTree.SelectedItem.IsSelected = false;
if (eventArgs.Sender == ExplorerTree)
{
if (UtilityTree.SelectedItem != null)
UtilityTree.SelectedItem.IsSelected = false;
}
if (eventArgs.Sender == UtilityTree)
{
if (ExplorerTree.SelectedItem != null)
ExplorerTree.SelectedItem.IsSelected = false;
}
}

if (eventArgs.NewOne is SnoopableObjectTreeItem snoopableObjectTreeItem)
Expand Down
2 changes: 1 addition & 1 deletion sources/RevitDBExplorer/UIComponents/List/ListVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class ListVM : BaseViewModel
private ObservableCollection<DynamicGridViewColumn> columns = new();
private ListItem listSelectedItem = null;
private string filterPhrase = "";
private bool isMemberViewVisible;
private bool isMemberViewVisible = true;


public ObservableCollection<ListItem> ListItems
Expand Down
35 changes: 32 additions & 3 deletions sources/RevitDBExplorer/UIComponents/List/ListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,38 @@
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>

<UniformGrid Rows="1" Margin="0 0 4 0" Visibility="Collapsed">
<ToggleButton Content="Members" IsChecked="{Binding IsMemberViewVisible}" />
<ToggleButton Content="Properties" IsChecked="{Binding IsProperyViewVisible}"/>
<UniformGrid Rows="1" Margin="0 0 4 0" Visibility="Visible">
<UniformGrid.Resources>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="MinWidth" Value="21"/>
<Setter Property="MinHeight" Value="21"/>
<Setter Property="Background" Value="{DynamicResource Button.Static.Background}"/>
<Setter Property="BorderBrush" Value="{DynamicResource Button.Static.Border}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" x:Name="border" >
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter Property="Background" TargetName="border" Value="{DynamicResource Button.MouseOver.Background}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="border" Value="{DynamicResource Button.MouseOver.Background}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UniformGrid.Resources>

<ToggleButton Content="M" IsChecked="{Binding IsMemberViewVisible}" />
<ToggleButton Content="P" IsChecked="{Binding IsProperyViewVisible}"/>
</UniformGrid>

<controls:TextBoxWithPlaceholder Grid.Column="1" Margin="0 0 2 0" Text="{Binding FilterPhrase, Mode=TwoWay, Delay=200, UpdateSourceTrigger=PropertyChanged}" Placeholder="Filter list by name or value"/>
Expand Down
37 changes: 21 additions & 16 deletions sources/RevitDBExplorer/UIComponents/Trees/Base/BaseTreeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:RevitDBExplorer.UIComponents.Trees.Base.Items"
xmlns:converters="clr-namespace:RevitDBExplorer.WPF.Converters"
xmlns:wpf="clr-namespace:RevitDBExplorer.WPF"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
Expand All @@ -29,6 +30,7 @@
</Style.Resources>
</Style>

<wpf:BindingProxy x:Key="Proxy" Data="{Binding}" />
</ResourceDictionary>
</Grid.Resources>

Expand Down Expand Up @@ -97,34 +99,37 @@
<MenuItem Header="Draw in Revit (using model lines)" Command="{Binding Commands.DrawInRevit}" CommandParameter="{Binding}"/>
<MenuItem Header="Draw in Revit (AVF)" Command="{Binding Commands.DrawInRevitAVF}" CommandParameter="{Binding}"/>
<Separator />

<MenuItem Header="Generate C# code for a UPDATE command (RDS) " Command="{Binding Commands.GenerateUpdateQueryRDSCommand}" CommandParameter="{Binding}">
<MenuItem.Icon>
<Path Style="{StaticResource IconQuery}" Width="11" />
</MenuItem.Icon>
</MenuItem>

<MenuItem Header="Freeze" ToolTip="" Command="{Binding Commands.Freeze}" CommandParameter="{Binding}" Visibility="{Binding Data.AllowToFrezeeItem, Source={StaticResource Proxy}, Converter={StaticResource BoolToVisibilityConverter}}"/>
<Separator />
<MenuItem Header="Snoop in a new window" Command="{Binding Commands.SnoopInNewWindow}" CommandParameter="{Binding}" />
</ContextMenu>
</StackPanel.ContextMenu>

<Path Style="{Binding Object.NamePrefixIcon, Converter={StaticResource ToResourceWithKeyConverter}, ConverterParameter=Icon}" Margin="0 1 4 0" Fill="{Binding ElementName=cTextBlock, Path=Foreground}" />
<TextBlock x:Name="cTextBlock" IsHitTestVisible="False">
<Run Text="{Binding Prefix, Mode=OneWay}">
<Run.Style>
<Style TargetType="{x:Type Run}">
<Style.Triggers>
<MultiDataTrigger >
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=IsSelected}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource TreeView.Object.Prefix}"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Run.Style>
</Run>
<Run Text="{Binding Object.Name, Mode=OneWay}" />
<Run Text="{Binding Prefix, Mode=OneWay}">
<Run.Style>
<Style TargetType="{x:Type Run}">
<Style.Triggers>
<MultiDataTrigger >
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=IsSelected}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource TreeView.Object.Prefix}"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Run.Style>
</Run>
<Run Text="{Binding Object.Name, Mode=OneWay}" />
<Run Text="{Binding Object.NamePostfix, Mode=OneWay}"/>
</TextBlock>
<StackPanel Visibility="{Binding IsSelected, Converter={StaticResource BoolToVisibilityConverter}}" Margin="3 0 0 0">
<Button Style="{StaticResource TreeToolButton}" ToolTip="Select in Revit" Command="{Binding Commands.SelectInRevit}" CommandParameter="{Binding .}" Visibility="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsEnabled, Converter={StaticResource BoolToVisibilityConverter}}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ internal class BaseTreeViewModel : BaseViewModel
{
protected readonly TreeItemsCommands TreeItemsCommands;
private ObservableCollection<TreeItem> treeItems = new();
private TreeItem selectedItem;
private TreeItem selectedItem;
private bool allowToFrezeeItem;

public event Action<SelectedItemChangedEventArgs> SelectedItemChanged;
public event Action<string> ScriptForRDSHasChanged;
Expand Down Expand Up @@ -44,7 +45,19 @@ public TreeItem SelectedItem
OnPropertyChanged();
}
}

public bool AllowToFrezeeItem
{
get
{
return allowToFrezeeItem;
}
set
{
allowToFrezeeItem = value;
OnPropertyChanged();
}
}


public BaseTreeViewModel()
{
Expand All @@ -55,7 +68,7 @@ public BaseTreeViewModel()
public void RaiseSelectedItemChanged(TreeItem item)
{
var oldOne = SelectedItem;
SelectedItem = item;
SelectedItem = item;
SelectedItemChanged?.Invoke(new SelectedItemChangedEventArgs(this, oldOne, item));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal class TreeItemsCommands
public IsolateInRevitCommand IsolateInRevit { get; } = IsolateInRevitCommand.Instance;
public DrawInRevitCommand DrawInRevit { get; } = DrawInRevitCommand.Instance;
public DrawInRevitWithAVFCommand DrawInRevitAVF { get; } = DrawInRevitWithAVFCommand.Instance;
public FreezeCommand Freeze { get; } = FreezeCommand.Instance;
public RelayCommand GenerateUpdateQueryRDSCommand { get; }


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal class UtilityTreeViewModel : BaseTreeViewModel

public UtilityTreeViewModel()
{
AllowToFrezeeItem = true;
rootItem ??= new UtilityGroupTreeItem(TreeItemsCommands) { IsExpanded = true };
TreeItems.Add(rootItem);
RemoveCommand = new RelayCommand(RemoveItems);
Expand Down

0 comments on commit d75eabd

Please sign in to comment.