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

Cherrypicks 3.4 #15618

Merged
merged 2 commits into from
Nov 7, 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
31 changes: 20 additions & 11 deletions src/DynamoCoreWpf/UI/Prompts/EditWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ public EditWindow(DynamoViewModel dynamoViewModel,

Owner = dynamoViewModel.Owner;
this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
this.Loaded += (sender, e) => this.editText.Focus();

// Center the window again once rendering is complete
this.ContentRendered += (sender, e) =>
{
this.Left = Owner.Left + (Owner.Width - this.ActualWidth) / 2;
this.Top = Owner.Top + (Owner.Height - this.ActualHeight) / 2;
};

// do not accept value if user closes
this.Closing += (sender, args) => this.DialogResult = false;
Expand All @@ -57,8 +49,28 @@ public EditWindow(DynamoViewModel dynamoViewModel,
}
this.editText.PreviewKeyDown += EditText_PreviewKeyDown;
this.Closed += EditWindow_Closed;
this.ContentRendered += OnContentRendered;
}

// Centralize the window correctly after it is rendered
private void OnContentRendered(object sender, EventArgs e)
{
// Unsubscribe immediately, we only call this once on initialization
this.ContentRendered -= OnContentRendered;

CenterWindowRelativeToOwner();
editText.Focus();
}

// Centralize the window relative to another Window
private void CenterWindowRelativeToOwner()
{
if (Owner != null)
{
this.Left = Owner.Left + (Owner.Width - this.ActualWidth) / 2;
this.Top = Owner.Top + (Owner.Height - this.ActualHeight) / 2;
}
}

private void CloseButton_OnClick(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -105,9 +117,6 @@ private void ToggleButtons(bool toggle)

private void EditText_PreviewKeyDown(object sender, KeyEventArgs e)
{
var textBox = sender as TextBox;
var caretIndex = textBox.CaretIndex;

EditTextBoxPreviewKeyDown?.Invoke(sender, e);
}

Expand Down
83 changes: 46 additions & 37 deletions src/DynamoCoreWpf/UI/Prompts/PortPropertiesEditPrompt.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
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:UI.Prompts"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:p="clr-namespace:Dynamo.Wpf.Properties;assembly=DynamoCoreWpf"
xmlns:ui="clr-namespace:Dynamo.UI"
mc:Ignorable="d"
Width="450"
Height="368"
WindowStartupLocation="CenterOwner"
WindowStyle="None">
WindowStyle="None"
mc:Ignorable="d">
<Window.Background>
<SolidColorBrush Opacity="0" />
</Window.Background>
Expand All @@ -31,26 +32,26 @@
<ControlTemplate TargetType="TextBox">
<Grid>
<TextBox x:Name="InputTextBox"
Padding="8,10"
Background="#353535"
BorderThickness="0"
CaretBrush="{StaticResource Blue300Brush}"
Focusable="True"
FontFamily="{StaticResource ArtifaktElementRegular}"
FontSize="12px"
Foreground="{StaticResource PrimaryCharcoal200Brush}"
MaxLength="{TemplateBinding MaxLength}"
Tag="{TemplateBinding Tag}"
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
Padding="8,10"
Background="#353535"
BorderThickness="0"
CaretBrush="{StaticResource Blue300Brush}"
Focusable="True"
FontFamily="{StaticResource ArtifaktElementRegular}"
FontSize="12px"
Foreground="{StaticResource PrimaryCharcoal200Brush}"
MaxLength="{TemplateBinding MaxLength}"
Tag="{TemplateBinding Tag}"
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
<TextBlock x:Name="WatermarkLabel"
Padding="10"
FontFamily="{StaticResource ArtifaktElementRegular}"
FontSize="12px"
Foreground="{StaticResource PrimaryCharcoal200Brush}"
IsHitTestVisible="False"
Opacity="0.5"
Text="{TemplateBinding Tag}">
Padding="10"
FontFamily="{StaticResource ArtifaktElementRegular}"
FontSize="12px"
Foreground="{StaticResource PrimaryCharcoal200Brush}"
IsHitTestVisible="False"
Opacity="0.5"
Text="{TemplateBinding Tag}">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Visibility" Value="Collapsed" />
Expand All @@ -64,11 +65,11 @@
</TextBlock>
<StackPanel Height="4px" VerticalAlignment="Bottom">
<Rectangle Name="Underline"
Height="1px"
Fill="Transparent" />
Height="1px"
Fill="Transparent" />
<Rectangle Name="UnderlineShadow"
Height="3px"
Fill="Transparent" />
Height="3px"
Fill="Transparent" />
</StackPanel>
</Grid>
<ControlTemplate.Triggers>
Expand All @@ -90,23 +91,27 @@
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="FrameworkElement" x:Key="VisibleAnimation">
<Setter Property="Opacity" Value="0"></Setter>
<Style x:Key="VisibleAnimation" TargetType="FrameworkElement">
<Setter Property="Opacity" Value="0" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsStatusWarning}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
From="0" To="1" Duration="0:0:0.3"/>
From="0"
To="1"
Duration="0:0:0.3" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
From="1" To="0" Duration="0:0:0.3"/>
From="1"
To="0"
Duration="0:0:0.3" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
Expand All @@ -116,6 +121,7 @@
</ResourceDictionary>
</Window.Resources>


<Grid Name="mainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="58px" />
Expand All @@ -128,6 +134,8 @@
Grid.Row="0"
Grid.RowSpan="3"
Background="{StaticResource DarkMidGreyBrush}"
BorderBrush="{StaticResource WorkspaceBackgroundHomeBrush}"
BorderThickness="1"
CornerRadius="4"
MouseDown="FunctionNamePrompt_MouseDown">
<DockPanel HorizontalAlignment="Stretch">
Expand Down Expand Up @@ -157,6 +165,7 @@

<!-- Middle Section: Details -->
<Border Grid.Row="1"
Margin="1,0"
Background="{StaticResource DarkMidGreyBrush}"
BorderBrush="#7E7E7E"
BorderThickness="0,1,0,0">
Expand Down Expand Up @@ -185,8 +194,8 @@
Style="{StaticResource HintingInputStyle}"
TextChanged="NameBox_OnTextChanged" />
<StackPanel x:Name="ErrorUnderline"
VerticalAlignment="Bottom"
Grid.Row="0"
VerticalAlignment="Bottom"
Style="{StaticResource VisibleAnimation}">
<Rectangle Name="Underline"
Height="1px"
Expand All @@ -199,9 +208,9 @@
</StackPanel>
<StackPanel x:Name="ErrorMessage"
Grid.Row="1"
Orientation="Horizontal"
Margin="0,6,0,0"
VerticalAlignment="Top"
Margin="0 6 0 0"
Orientation="Horizontal"
Style="{StaticResource VisibleAnimation}">
<Image x:Name="ErrorIcon"
Width="16"
Expand All @@ -221,10 +230,10 @@
Text="{Binding ErrorString, UpdateSourceTrigger=PropertyChanged}"
TextTrimming="CharacterEllipsis">
<TextBlock.ToolTip>
<ToolTip Content="{Binding ErrorString, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource GenericToolTipLight}"/>
<ToolTip Content="{Binding ErrorString, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource GenericToolTipLight}" />
</TextBlock.ToolTip>
</TextBlock>
</StackPanel>
</StackPanel>
</Grid>

<!-- Description -->
Expand Down Expand Up @@ -268,9 +277,9 @@
DockPanel.Dock="Right"
Foreground="White"
IsDefault="True"
IsEnabled="{Binding IsStatusWarning, Converter={StaticResource InverseBooleanConverter}}"
Style="{DynamicResource ResourceKey=CtaButtonStyle}"
TabIndex="2"
IsEnabled="{Binding IsStatusWarning, Converter={StaticResource InverseBooleanConverter}}"/>
TabIndex="2" />
</DockPanel>
</Grid>
</Window>
46 changes: 42 additions & 4 deletions src/DynamoCoreWpf/UI/Prompts/PortPropertiesEditPrompt.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Dynamo.Controls;
using Dynamo.Utilities;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Dynamo.Controls;
using Dynamo.Graph.Nodes;
using Dynamo.Utilities;

namespace UI.Prompts
{
Expand Down Expand Up @@ -105,14 +106,51 @@ public PortPropertiesEditPrompt()
InitializeComponent();

this.DataContext = this;
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;

Owner = WpfUtilities.FindUpVisualTree<DynamoView>(this);
Owner = GetDynamoView();
WindowStartupLocation = WindowStartupLocation.CenterOwner;

this.ContentRendered += OnContentRendered;
}

#region Centralize

// Centralize the window correctly after it is rendered
private void OnContentRendered(object sender, EventArgs e)
{
// Unsubscribe immediately, we only call this once on initialization
this.ContentRendered -= OnContentRendered;

CenterWindowRelativeToOwner();
nameBox.Focus();
}

// Centralize the window relative to another Window
private void CenterWindowRelativeToOwner()
{
if (Owner != null)
{
this.Left = Owner.Left + (Owner.Width - this.ActualWidth) / 2;
this.Top = Owner.Top + (Owner.Height - this.ActualHeight) / 2;
}
}

// A helper method to find DynamoView Window
// Contrary to the expectation, DynamoView does not own this prompt window
// Upon inspection, both windows are direct children of the Dynamo process with no visual tree relationship
private DynamoView GetDynamoView()
{
foreach (Window window in Application.Current.Windows)
{
if (window is DynamoView dynamoView)
{
return dynamoView;
}
}
return null;
}
#endregion

#region Methods
void OK_Click(object sender, RoutedEventArgs e)
{
Expand Down
Loading