Skip to content

Commit ddd9d4f

Browse files
WIP: Changed Slew point rename to inline edit
1 parent 002241e commit ddd9d4f

File tree

5 files changed

+125
-126
lines changed

5 files changed

+125
-126
lines changed

OATControl/OATControl.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@
138138
<Compile Include="MiniController.xaml.cs">
139139
<DependentUpon>MiniController.xaml</DependentUpon>
140140
</Compile>
141-
<Compile Include="RenameSlewPointDialog.xaml.cs">
142-
<DependentUpon>RenameSlewPointDialog.xaml</DependentUpon>
143-
</Compile>
144141
<Compile Include="SettingsDialog.xaml.cs">
145142
<DependentUpon>SettingsDialog.xaml</DependentUpon>
146143
</Compile>
@@ -221,10 +218,6 @@
221218
<SubType>Designer</SubType>
222219
<Generator>MSBuild:Compile</Generator>
223220
</Page>
224-
<Page Include="RenameSlewPointDialog.xaml">
225-
<SubType>Designer</SubType>
226-
<Generator>MSBuild:Compile</Generator>
227-
</Page>
228221
<Page Include="Resources\RedControls.xaml">
229222
<Generator>MSBuild:Compile</Generator>
230223
<SubType>Designer</SubType>

OATControl/RenameSlewPointDialog.xaml

Lines changed: 0 additions & 45 deletions
This file was deleted.

OATControl/RenameSlewPointDialog.xaml.cs

Lines changed: 0 additions & 61 deletions
This file was deleted.

OATControl/SlewPointsWindow.xaml

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@
99
Background="#600"
1010
Title="Slew Positions" MinHeight="250" MinWidth="405" WindowStyle="None" SizeToContent="Width">
1111
<Window.Resources>
12+
<converters:BoolToVisibilityConverter x:Key="BoolToShow" />
13+
<converters:BoolToVisibilityConverter x:Key="BoolToHide" IsReversed="true" />
14+
<Style x:Key="CustomListBoxItemStyle" TargetType="ListBoxItem">
15+
<Setter Property="Background" Value="Transparent"/>
16+
<Setter Property="Foreground" Value="White"/>
17+
<Setter Property="BorderThickness" Value="0"/>
18+
<Setter Property="Padding" Value="0"/>
19+
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
20+
<Setter Property="VerticalContentAlignment" Value="Center"/>
21+
<Setter Property="SnapsToDevicePixels" Value="True"/>
22+
<Style.Triggers>
23+
<Trigger Property="IsSelected" Value="True">
24+
<Setter Property="Background" Value="#400" />
25+
</Trigger>
26+
<Trigger Property="IsMouseOver" Value="True">
27+
<Setter Property="Background" Value="#600"/>
28+
</Trigger>
29+
</Style.Triggers>
30+
</Style>
1231
<Style TargetType="ToolTip">
1332
<Setter Property="Background" Value="#600" />
1433
<Setter Property="Foreground" Value="#F00" />
@@ -54,6 +73,16 @@
5473
<Setter Property="Background" Value="{StaticResource AccentColorBrush2}" />
5574
<Setter Property="Foreground" Value="#F00" />
5675
</Style>
76+
<Style x:Key="TextBorder" TargetType="TextBox" BasedOn="{StaticResource MetroTextBox}">
77+
<Setter Property="VerticalAlignment" Value="Center" />
78+
<Setter Property="Padding" Value="0" />
79+
<Setter Property="BorderBrush" Value="{StaticResource AccentColorBrush}" />
80+
<Setter Property="Background" Value="{StaticResource AccentColorBrush3}" />
81+
<Setter Property="HorizontalContentAlignment" Value="Left" />
82+
<Setter Property="FontSize" Value="12" />
83+
<Setter Property="MinWidth" Value="120" />
84+
<Setter Property="Foreground" Value="#B00" />
85+
</Style>
5786
<Style x:Key="CustomButtonStyle" TargetType="Button">
5887
<Setter Property="Margin" Value="5" />
5988
<Setter Property="Padding" Value="10,5" />
@@ -389,23 +418,46 @@
389418
</Grid>
390419

391420
<ListBox x:Name="slewPointsList" Grid.Row="2"
392-
ItemsSource="{Binding SlewPoints}"
393-
Background="#300"
394-
BorderBrush="#900"
395-
Foreground="White"
396-
Margin="0,0,0,0"
397-
HorizontalContentAlignment="Stretch">
421+
ItemsSource="{Binding SlewPoints}"
422+
Background="#300"
423+
BorderBrush="#900"
424+
Foreground="White"
425+
Margin="0,0,0,0"
426+
HorizontalContentAlignment="Stretch"
427+
ItemContainerStyle="{StaticResource CustomListBoxItemStyle}"
428+
>
398429
<ListBox.ItemTemplate>
399430
<DataTemplate>
400-
<Border BorderThickness="0,1,0,0" BorderBrush="#200">
431+
<Border BorderThickness="0,1,0,0" BorderBrush="#200" Background="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=Background}">
401432
<Grid>
402433
<Grid.ColumnDefinitions>
403434
<ColumnDefinition Width="*"/>
404435
<ColumnDefinition Width="60"/>
405436
<ColumnDefinition Width="60"/>
406437
<ColumnDefinition Width="125"/>
407438
</Grid.ColumnDefinitions>
408-
<TextBlock Text="{Binding Name}" Foreground="#B00" VerticalAlignment="Center" Padding="2,0" MinWidth="120"/>
439+
<Grid>
440+
<Grid.Resources>
441+
<Style TargetType="TextBox">
442+
<Setter Property="MinWidth" Value="120"/>
443+
</Style>
444+
</Grid.Resources>
445+
<TextBlock x:Name="NameTextBlock"
446+
Text="{Binding Name}"
447+
Foreground="#B00"
448+
VerticalAlignment="Center"
449+
Padding="2,0"
450+
MinWidth="120"
451+
Visibility="{Binding IsEditing, Converter={StaticResource BoolToHide}}"/>
452+
<TextBox x:Name="NameTextBox"
453+
Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
454+
Style="{StaticResource TextBorder}"
455+
Background="#400"
456+
Visibility="{Binding IsEditing, Converter={StaticResource BoolToShow}}"
457+
KeyDown="NameTextBox_KeyDown"
458+
LostFocus="NameTextBox_LostFocus"
459+
IsVisibleChanged="NameTextBox_IsVisibleChanged"/>
460+
</Grid>
409461
<TextBlock Text="{Binding RaStepperPosition}" Foreground="#B00" VerticalAlignment="Center" Grid.Column="1" TextAlignment="Center"/>
410462
<TextBlock Text="{Binding DecStepperPosition}" Foreground="#B00" VerticalAlignment="Center" Grid.Column="2" TextAlignment="Center"/>
411463
<StackPanel Grid.Column="3" Orientation="Horizontal" VerticalAlignment="Center">

OATControl/SlewPointsWindow.xaml.cs

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ namespace OATControl
2323
public class SlewPoint : INotifyPropertyChanged
2424
{
2525
private string _name;
26+
private string _savedName;
2627
private int _raStepperPosition;
2728
private int _decStepperPosition;
29+
private bool _isEditing;
30+
31+
public string SavedName
32+
{
33+
get { return _savedName; }
34+
}
2835

2936
public string Name
3037
{
@@ -39,6 +46,24 @@ public string Name
3946
}
4047
}
4148

49+
public bool IsEditing
50+
{
51+
get => _isEditing;
52+
set
53+
{
54+
if (_isEditing != value)
55+
{
56+
_isEditing = value;
57+
if (_isEditing)
58+
{
59+
_savedName = _name;
60+
}
61+
OnPropertyChanged(nameof(IsEditing));
62+
}
63+
}
64+
}
65+
66+
4267
public int RaStepperPosition
4368
{
4469
get { return _raStepperPosition; }
@@ -168,11 +193,9 @@ private void RemoveSlewPoint(SlewPoint point)
168193

169194
private void RenameSlewPoint(SlewPoint point)
170195
{
171-
RenameSlewPointDialog dialog = new RenameSlewPointDialog(point.Name) { Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner };
172-
if (dialog.ShowDialog() == true)
173-
{
174-
point.Name = dialog.PointName;
175-
}
196+
197+
point.IsEditing = true;
198+
176199
}
177200

178201
private async void GoToSlewPoint(SlewPoint point)
@@ -182,6 +205,33 @@ private async void GoToSlewPoint(SlewPoint point)
182205
await _mount.MoveMountBy(point.RaStepperPosition - (int)_mount.RAStepper, point.DecStepperPosition - (int)_mount.DECStepper);
183206
}
184207
}
208+
209+
private void NameTextBox_KeyDown(object sender, KeyEventArgs e)
210+
{
211+
var tb = sender as TextBox;
212+
SlewPoint point = (tb?.DataContext as SlewPoint);
213+
if (point != null)
214+
{
215+
if (e.Key == Key.Enter)
216+
{
217+
point.IsEditing = false;
218+
}
219+
else if (e.Key == Key.Escape)
220+
{
221+
point.Name = point.SavedName;
222+
point.IsEditing = false;
223+
}
224+
}
225+
}
226+
227+
private void NameTextBox_LostFocus(object sender, RoutedEventArgs e)
228+
{
229+
var tb = sender as TextBox;
230+
if (tb?.DataContext is SlewPoint point)
231+
{
232+
point.IsEditing = false;
233+
}
234+
}
185235

186236
private void UpdateSlewPoint(SlewPoint point)
187237
{
@@ -206,5 +256,15 @@ protected void OnPropertyChanged(string propertyName)
206256
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
207257
}
208258

259+
private void NameTextBox_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
260+
{
261+
var tb = sender as TextBox;
262+
if (tb != null && tb.IsVisible)
263+
{
264+
tb.Focus();
265+
tb.SelectAll();
266+
}
267+
}
268+
209269
}
210270
}

0 commit comments

Comments
 (0)