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

DYN-6440 Custom Selection Overlapped #14960

Merged
merged 6 commits into from
Feb 26, 2024
Merged
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
8 changes: 8 additions & 0 deletions src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,14 @@
Foreground="#F5F5F5"
IsReadOnly="{TemplateBinding IsReadOnly}"
Visibility="Hidden" />
<TextBlock x:Name="PART_ReadOnlyTextBlock"
Margin="10,0,20,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Focusable="True"
TextWrapping="Wrap"
TextTrimming="CharacterEllipsis"
Visibility="{Binding IsVisibleDropDownTextBlock, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" />
<Popup Name="Popup"
AllowsTransparency="True"
Focusable="False"
Expand Down
17 changes: 17 additions & 0 deletions src/Libraries/CoreNodeModels/Input/CustomSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ namespace CoreNodeModels.Input
public class CustomSelection : DSDropDownBase
{
private List<DynamoDropDownItem> serializedItems;
private bool isVisibleDropDownTextBlock = false;

/// <summary>
/// This property will Collapse or make Visible the TextBlock for the ComboBox template "RefreshComboBox" (by default will be Collapsed)
/// </summary>
public bool IsVisibleDropDownTextBlock
{
get
{
return isVisibleDropDownTextBlock;
}
set
{
isVisibleDropDownTextBlock = value;
RaisePropertyChanged(nameof(IsVisibleDropDownTextBlock));
}
}

/// <summary>
/// Copy of <see cref="DSDropDownBase.Items"/> to be serialized./>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
using System.Windows.Controls;
using System.Windows;
using Dynamo.Wpf;
using CoreNodeModels;
using System.Windows.Data;
using System.Data.Common;
using System;

namespace CoreNodeModelsWpf.Nodes
{
Expand All @@ -12,27 +16,77 @@ namespace CoreNodeModelsWpf.Nodes
/// </summary>
public class CustomSelectionNodeViewCustomization : DropDownNodeViewCustomization, INodeViewCustomization<CustomSelection>
{
private CustomSelectionControl formControl;
/// <summary>
/// Customize the visual appearance of the custom dropdown node.
/// </summary>
/// <param name="model"></param>
/// <param name="nodeView"></param>
public void CustomizeView(CustomSelection model, NodeView nodeView)
{
var formControl = new CustomSelectionControl(new CustomSelectionViewModel(model));
const double leftMargin = 40;
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
formControl = new CustomSelectionControl(new CustomSelectionViewModel(model));

nodeView.inputGrid.Children.Add(formControl);

// Add the dropdown.
base.CustomizeView(model, nodeView);

var dropdown = (ComboBox)nodeView.inputGrid.Children[1];
dropdown.MaxWidth = formControl.Width - leftMargin;

formControl.BaseComboBox = dropdown;
formControl.BaseComboBox.SelectionChanged += BaseComboBox_SelectionChanged;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsubscribe somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For unsubscribing the method I added the Dispose() method but not sure if this class is being disposed correctly or not.
It's supposed that if you derive from IDispose and implement the Dispose() method the right way to dispose the object should be by using the "using(instance)" or by calling object.Dispose() directly.
commit: c08ab0e

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks would you test when workspace is closed, if the dispose function is called? Just curious about the conclusion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QilongTang you were right, when closing the workspace the Dispose method is being reached.
image


// Add margin to the dropdown to show the expander.
dropdown.Margin = new Thickness(40, 0, 0, 0);
dropdown.Margin = new Thickness(leftMargin, 0, 0, 0);
dropdown.VerticalAlignment = VerticalAlignment.Top;
dropdown.ApplyTemplate();

var dropDownTextBlock = dropdown.Template.FindName("PART_ReadOnlyTextBlock", dropdown) as TextBlock;
if (dropDownTextBlock != null)
{
//IsVisibleDropDownTextBlock will be false by default so the TextBlock (located in the ComboBox template) will be Collapsed then just when is a Custom Selection node we set the value to true and the TextBlock will be visible
//We used a TextBlock because the normal TextBox doesn't have the TextTrimming property and the requirement was asking for setting TextTrimming="CharacterEllipsis"
model.IsVisibleDropDownTextBlock = true;
}
QilongTang marked this conversation as resolved.
Show resolved Hide resolved

var dropDownContent = dropdown.Template.FindName("ContentSite", dropdown) as ContentPresenter;
if (dropDownContent != null)
{
dropDownContent.Visibility = Visibility.Collapsed;
}

// Bind the TextBlock to the selected item hash.
var bindingVal = new Binding(nameof(DSDropDownBase.SelectedString))
{
Mode = BindingMode.TwoWay,
Source = model
};
dropDownTextBlock.SetBinding(TextBlock.TextProperty, bindingVal);
}

private void BaseComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var comboSender = sender as ComboBox;
if (comboSender != null)
{
comboSender.ToolTip = comboSender.SelectedItem?.ToString();
}
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected void Dispose(bool disposing)
{
if (disposing)
{
formControl.BaseComboBox.SelectionChanged -= BaseComboBox_SelectionChanged;
}
}
}
}
}
Loading