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

7525: DYN-7252: note edit textbox fix #15583

Merged
merged 2 commits into from
Nov 4, 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
146 changes: 107 additions & 39 deletions src/DynamoCoreWpf/UI/Prompts/EditWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<Window x:Class="Dynamo.UI.Prompts.EditWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:Dynamo.UI"
xmlns:p="clr-namespace:Dynamo.Wpf.Properties"
Title="{x:Static p:Resources.EditWindowTitle}"
MaxHeight="{x:Static SystemParameters.PrimaryScreenHeight}"
xmlns:ui="clr-namespace:Dynamo.UI"
Title="{x:Static p:Resources.EditWindowTitle}"
Width="400"
Height="200"
MinWidth="300"
MinHeight="170"
MaxWidth="{x:Static SystemParameters.PrimaryScreenWidth}"
MinHeight="170" MinWidth="300"
Height="250" Width="400"
Style="{DynamicResource DynamoWindowStyle}"
MaxHeight="{x:Static SystemParameters.PrimaryScreenHeight}"
AllowsTransparency="True"
Style="{DynamicResource DynamoWindowStyle}"
WindowStyle="None">

<Window.Background>
Expand All @@ -23,36 +25,117 @@
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoColorsAndBrushesDictionaryUri}" />
<ui:SharedResourceDictionary Source="{x:Static ui:SharedDictionaryManager.DynamoModernDictionaryUri}" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="InputStyle" TargetType="TextBox">
<Setter Property="Margin" Value="0,0,0,12" />
<Setter Property="MinWidth" Value="62px" />
<Setter Property="Cursor" Value="IBeam" />
<Setter Property="Background" Value="{StaticResource DarkThemeInputBoxBackgroundBrush}" />
<Setter Property="Foreground" Value="{StaticResource PrimaryCharcoal200Brush}" />
<Setter Property="FontFamily" Value="{StaticResource ArtifaktElementRegular}" />
<Setter Property="FontSize" Value="12" />
<Setter Property="CaretBrush" Value="{StaticResource Blue300Brush}" />
<Setter Property="BorderBrush" Value="{StaticResource DarkMidGreyBrush}" />
<Setter Property="BorderThickness" Value="0,0,0,1" />
<Setter Property="Padding" Value="8,10" />

<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<!-- Main content -->
<ScrollViewer x:Name="PART_ContentHost" />

<!-- Underline and Shadow -->
<StackPanel Height="4px" VerticalAlignment="Bottom">
<Rectangle x:Name="Underline"
Height="1px"
Fill="#9B9B9B"
Opacity="0" />
<Rectangle x:Name="UnderlineShadow"
Height="3px"
Fill="#6E6E6E"
Opacity="0" />
</StackPanel>
</Grid>
</Border>

<!-- ControlTemplate Triggers -->
<ControlTemplate.Triggers>
<!-- MouseOver Trigger: Fade in underline and change border -->
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard SpeedRatio="10">
<DoubleAnimation Storyboard.TargetName="Underline"
Storyboard.TargetProperty="Opacity"
To="0.75"
Duration="0:0:1" />
<DoubleAnimation Storyboard.TargetName="UnderlineShadow"
Storyboard.TargetProperty="Opacity"
To="0.75"
Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard SpeedRatio="2">
<DoubleAnimation Storyboard.TargetName="Underline"
Storyboard.TargetProperty="Opacity"
To="0"
Duration="0:0:1" />
<DoubleAnimation Storyboard.TargetName="UnderlineShadow"
Storyboard.TargetProperty="Opacity"
To="0"
Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
<!-- IsFocused Trigger -->
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="Underline" Property="Fill" Value="{StaticResource Blue300Brush}" />
<Setter TargetName="UnderlineShadow" Property="Fill" Value="#497386" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Window.Resources>
<Window.CommandBindings>
<CommandBinding Command="Close" Executed="OnCloseExecuted" />
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding Command="Close" Key="Esc"/>
<KeyBinding Key="Esc" Command="Close" />
</Window.InputBindings>


<Grid Background="Transparent" MouseDown="UIElement_OnMouseDown">
<Border Name="MainBorder" Style="{StaticResource NoStyleWindowBorderStyle}" Background="#535353">
<Border Name="MainBorder"
Background="#535353"
Style="{StaticResource NoStyleWindowBorderStyle}">

<Grid Margin="0">

<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>

<!-- Title Bar + Close Button -->
<DockPanel Grid.Row="0"
Margin="15 15 14 30"
Margin="15,15,14,30"
HorizontalAlignment="Stretch">

<Button Name="CloseButton"
Margin="25,0,0,0"
Click="CloseButton_OnClick"
DockPanel.Dock="Right"
Margin="25 0 0 0"
Style="{StaticResource CloseButtonDarkStyle}" />

<Button Name="MaximizeButton"
Expand All @@ -63,11 +146,11 @@
<Button Name="NormalizeButton"
Click="MaximizeButton_OnClick"
DockPanel.Dock="Right"
Visibility="Collapsed"
Style="{StaticResource RestoreButtonDarkStyle}" />
Style="{StaticResource RestoreButtonDarkStyle}"
Visibility="Collapsed" />

<Button Name="MinimizeButton"
Margin="0 0 25 0"
Margin="0,0,25,0"
Click="MinimizeButton_OnClick"
DockPanel.Dock="Right"
Style="{StaticResource MinimizeButtonDarkStyle}" />
Expand All @@ -78,35 +161,20 @@
FontFamily="{StaticResource ArtifaktElementRegular}"
FontSize="20px"
Foreground="{StaticResource DarkThemeBodyMediumBrush}"
Text="{x:Static p:Resources.EditNodeWindowTitle}"
Text="{x:Static p:Resources.EditNodeWindowTitle}"
TextWrapping="Wrap" />
</DockPanel>

<Rectangle Style="{StaticResource DividerRectangleStyle}" Grid.Row="0" />

<TextBox
PreviewKeyDown="OnEditWindowPreviewKeyDown"
x:FieldModifier="private"
Grid.Row="1"
Margin="15 1 15 10"
HorizontalAlignment="Stretch"
Name="editText"
IsHitTestVisible="True"
Style="{StaticResource HintingInputStyle}"/>


<StackPanel Grid.Row="2" Orientation="Horizontal" FlowDirection="RightToLeft">
<Button
Content="{x:Static p:Resources.EditWindowAcceptButton}"
Margin="11 0 0 12"
MinWidth="90"
BorderBrush="#0696D7"
Foreground="White"
Background="#0696D7"
Style="{StaticResource CtaButtonStyle}"
Click="OkClick" />
</StackPanel>
<Rectangle Grid.Row="0" Style="{StaticResource DividerRectangleStyle}" />

<TextBox Name="editText"
Grid.Row="1"
Margin="15,1,15,15"
HorizontalAlignment="Stretch"
x:FieldModifier="private"
IsHitTestVisible="True"
PreviewKeyDown="OnEditWindowPreviewKeyDown"
Style="{DynamicResource InputStyle}" />
</Grid>
</Border>
</Grid>
Expand Down
19 changes: 15 additions & 4 deletions src/DynamoCoreWpf/UI/Prompts/EditWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand Down Expand Up @@ -33,9 +33,17 @@ public EditWindow(DynamoViewModel dynamoViewModel,
InitializeComponent();
this.dynamoViewModel = dynamoViewModel;

this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
this.editText.Focus();

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;
if (false != updateSourceOnTextChange)
Expand Down Expand Up @@ -97,6 +105,9 @@ 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
Loading