Skip to content

Commit

Permalink
DYN-4686 several changes in the group style context menu. (#12728)
Browse files Browse the repository at this point in the history
- Removed the IsChecked property so is not serialized into the dyn file.
- Removed the CurrentGroupStyleSelected property due that is was used for the checkmark functionality.
- All the functionality for checking and unchecking groupstyle menuitems was removed.
- Removed the checkmark label that was appearing next to the group style.
- The color contextmenu was moved to be a submenuitem.
  • Loading branch information
RobertGlobant20 authored Mar 23, 2022
1 parent b348f27 commit ac5968d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 108 deletions.
22 changes: 1 addition & 21 deletions src/DynamoCore/Configuration/GroupStyleItem.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dynamo.Configuration
namespace Dynamo.Configuration
{
public class GroupStyleItem: StyleItem
{
private bool isChecked = false;

/// <summary>
/// This property will say it we should display the checkmark in the MenuItem (appearing in the GroupStyles context menu)
/// </summary>
public bool IsChecked
{
get { return isChecked; }
set
{
isChecked = value;
RaisePropertyChanged(nameof(IsChecked));
}
}
}
}
19 changes: 0 additions & 19 deletions src/DynamoCoreWpf/ViewModels/Core/AnnotationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ public Double FontSize
}
}

[JsonIgnore]
internal GroupStyleItem CurrentGroupStyleSelected { get; set; }

[JsonIgnore]
public IEnumerable<ModelBase> Nodes
{
Expand Down Expand Up @@ -978,14 +975,6 @@ internal void UpdateGroupStyle(GroupStyleItem itemEntryParameter)
{
if (itemEntryParameter == null) return;

var groupStyleItems = GroupStyleList.OfType<GroupStyleItem>();
groupStyleItems.Where(c => !c.Name.Equals(itemEntryParameter.Name)).ToList().ForEach(cc =>
{
cc.IsChecked = false;
});

itemEntryParameter.IsChecked = true;
CurrentGroupStyleSelected = itemEntryParameter;
Background = (Color)ColorConverter.ConvertFromString("#"+itemEntryParameter.HexColorString);

WorkspaceViewModel.HasUnsavedChanges = true;
Expand Down Expand Up @@ -1020,17 +1009,9 @@ private void LoadGroupStylesFromPreferences(IEnumerable<Configuration.StyleItem>
internal void ReloadGroupStyles()
{
if (preferencesStyleItemsList == null) return;
var currentSelectedGroupStyle = groupStyleList.OfType<GroupStyleItem>().Where(style => style.IsChecked == true).FirstOrDefault();
groupStyleList.Clear();

LoadGroupStylesFromPreferences(preferencesStyleItemsList);
if (currentSelectedGroupStyle == null) return;

var currentCustomGroupStyles = groupStyleList.OfType<GroupStyleItem>();
var selectedGroupStyle = currentCustomGroupStyles.Where(style => style.Name.Equals(currentSelectedGroupStyle.Name)).FirstOrDefault();

if (selectedGroupStyle == null) return;
selectedGroupStyle.IsChecked = true;
}

/// <summary>
Expand Down
61 changes: 26 additions & 35 deletions src/DynamoCoreWpf/Views/Core/AnnotationView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,26 +319,15 @@
<Style x:Key="GroupStyleItemStyle" TargetType="{x:Type MenuItem}">
<Setter Property="MenuItem.IsChecked"
Value="{Binding IsChecked}"/>
<EventSetter Event="Click"
<EventSetter Event="Click"
Handler="GroupStyleCheckmark_Click"/>
<EventSetter Event="Checked"
Handler="GroupStyleCheckmark_Checked"/>
<Setter Property="MenuItem.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<StackPanel x:Name="groupStyleStackPanel"
Orientation="Horizontal"
MinWidth="150"
Background="{StaticResource PreferencesWindowVisualSettingsAddStyleBackground}">
<Label x:Name="GroupStyleCheckmark"
HorizontalAlignment="Left"
VerticalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Content=""
FontSize="14px"
Foreground="White"
Visibility="{Binding Path=IsChecked,Converter={StaticResource BooleanToVisibilityConverter}}" />
<Label x:Name="buttonColorPicker"
Margin="5,0,5,0"
FontFamily="{StaticResource ArtifaktElementRegular}"
Expand Down Expand Up @@ -368,6 +357,31 @@
</Style>
</MenuItem.Resources>
</MenuItem>
<MenuItem Name="ColorMenuItem" Header="Color">
<ListBox ItemContainerStyle="{StaticResource ColorSelectorListBoxItem}"
SelectionChanged="OnNodeColorSelectionChanged"
Height="Auto"
Style="{StaticResource ColorSelectorListBox}">
<ListBox.Items>
<Rectangle Fill="#d4b6db" />
<Rectangle Fill="#ffb8d8" />
<Rectangle Fill="#ffc999" />
<Rectangle Fill="#e8f7ad" />
<Rectangle Fill="#b9f9e1" />
<Rectangle Fill="#a4e1ff" />
<Rectangle Fill="#b5b5b5" />
<Rectangle Fill="#FFFFFF" />
<Rectangle Fill="#bb87c6" />
<Rectangle Fill="#ff7bac" />
<Rectangle Fill="#ffaa45" />
<Rectangle Fill="#c1d676" />
<Rectangle Fill="#71c6a8" />
<Rectangle Fill="#48b9ff" />
<Rectangle Fill="#848484" />
<Rectangle Fill="#d8d8d8" />
</ListBox.Items>
</ListBox>
</MenuItem>
<MenuItem Name="ChangeSize" Header="{x:Static p:Resources.GroupContextMenuFont}">
<MenuItem Name="FontSize0"
Command="{Binding ChangeFontSize}"
Expand Down Expand Up @@ -416,29 +430,6 @@
IsChecked="{Binding Path=FontSize, Converter={StaticResource MenuItemCheckConverter}, ConverterParameter=96}" />

</MenuItem>
<ListBox ItemContainerStyle="{StaticResource ColorSelectorListBoxItem}"
SelectionChanged="OnNodeColorSelectionChanged"
Height="Auto"
Style="{StaticResource ColorSelectorListBox}">
<ListBox.Items>
<Rectangle Fill="#d4b6db" />
<Rectangle Fill="#ffb8d8" />
<Rectangle Fill="#ffc999" />
<Rectangle Fill="#e8f7ad" />
<Rectangle Fill="#b9f9e1" />
<Rectangle Fill="#a4e1ff" />
<Rectangle Fill="#b5b5b5" />
<Rectangle Fill="#FFFFFF" />
<Rectangle Fill="#bb87c6" />
<Rectangle Fill="#ff7bac" />
<Rectangle Fill="#ffaa45" />
<Rectangle Fill="#c1d676" />
<Rectangle Fill="#71c6a8" />
<Rectangle Fill="#48b9ff" />
<Rectangle Fill="#848484" />
<Rectangle Fill="#d8d8d8" />
</ListBox.Items>
</ListBox>
</ContextMenu>
</Grid.ContextMenu>

Expand Down
34 changes: 1 addition & 33 deletions src/DynamoCoreWpf/Views/Core/AnnotationView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,39 +453,7 @@ private void GroupStyleCheckmark_Click(object sender, RoutedEventArgs e)
var groupStyleItemSelected = menuItemSelected.DataContext as GroupStyleItem;
if (groupStyleItemSelected == null) return;

//Means that no GroupStyle (Default, Custom) has been selected then the clicked one will be selected
if (ViewModel.CurrentGroupStyleSelected == null)
{
ViewModel.UpdateGroupStyle(groupStyleItemSelected);
return;
}

//Means that the user clicked over a MenuItem that is already selected, when we need uncheck it if is not a Default Style
if (groupStyleItemSelected != ViewModel.CurrentGroupStyleSelected && groupStyleItemSelected.IsChecked == false)
{
ViewModel.UpdateGroupStyle(groupStyleItemSelected);
return;
}

//Means that the GroupStyle selected is not a Default Style and is already checked
if (ViewModel.CurrentGroupStyleSelected.IsChecked == true && !groupStyleItemSelected.IsDefault)
{
var groupStyleItems = ViewModel.GroupStyleList.OfType<GroupStyleItem>();
var firstDefaultGroupStyle = groupStyleItems.Where(item => item.IsDefault == true).FirstOrDefault();
ViewModel.UpdateGroupStyle(firstDefaultGroupStyle);
return;
}
}

private void GroupStyleCheckmark_Checked(object sender, RoutedEventArgs e)
{
var menuItemSelected = sender as MenuItem;
if (menuItemSelected == null) return;

var groupStyleItemSelected = menuItemSelected.DataContext as GroupStyleItem;
if (groupStyleItemSelected == null) return;

ViewModel.CurrentGroupStyleSelected = groupStyleItemSelected;
ViewModel.UpdateGroupStyle(groupStyleItemSelected);
}

/// <summary>
Expand Down

0 comments on commit ac5968d

Please sign in to comment.