Skip to content

Commit 99044eb

Browse files
lilyremigiabrliron
authored andcommitted
Enhance patch controls with first/last item detection
Added `IsFirst`, `IsLast`, and their inverted properties to better manage patch selection states. Updated UI buttons to conditionally display based on these properties, improving usability for moving patches up or down.
1 parent 77186b8 commit 99044eb

File tree

2 files changed

+156
-8
lines changed

2 files changed

+156
-8
lines changed

thcrap_configure_v3/Page2_advanced.xaml

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
UseLayoutRounding="True">
1010

1111
<UserControl.Resources>
12-
<!-- Define the reusable HoverVisibleButtonStyle -->
12+
<BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
1313
<Style x:Key="HoverVisibleButtonStyle" TargetType="Button">
1414
<Setter Property="Visibility" Value="Hidden" />
1515
<Setter Property="VerticalAlignment" Value="Stretch" />
@@ -22,7 +22,8 @@
2222
<Setter Property="Template">
2323
<Setter.Value>
2424
<ControlTemplate TargetType="Button">
25-
<Border Background="{TemplateBinding Background}" BorderThickness="0" SnapsToDevicePixels="True">
25+
<Border Background="{TemplateBinding Background}" BorderThickness="0"
26+
SnapsToDevicePixels="True">
2627
<ContentPresenter
2728
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
2829
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
@@ -358,21 +359,113 @@
358359
Style="{StaticResource HoverVisibleButtonStyle}"
359360
Content="🡸">
360361
</Button>
361-
<Button Click="SelectedPatch_MoveUp"
362+
<Button x:Name="UpButton"
363+
Click="SelectedPatch_MoveUp"
362364
Grid.Column="1"
363365
Grid.Row="0"
364366
Tag="{Binding}"
365-
Margin="0"
366-
Style="{StaticResource HoverVisibleButtonStyle}"
367367
Content="🡹">
368+
<Button.Style>
369+
<Style TargetType="Button">
370+
<Setter Property="Visibility" Value="Hidden" />
371+
<Setter Property="VerticalAlignment" Value="Stretch" />
372+
<Setter Property="HorizontalAlignment" Value="Stretch" />
373+
<Setter Property="Padding" Value="0,0" />
374+
<Setter Property="Margin" Value="0" />
375+
<Setter Property="Background" Value="White" />
376+
<Setter Property="BorderThickness" Value="0" />
377+
<Setter Property="BorderBrush" Value="Transparent" />
378+
<Setter Property="Template">
379+
<Setter.Value>
380+
<ControlTemplate TargetType="Button">
381+
<Border Background="{TemplateBinding Background}"
382+
BorderThickness="0" SnapsToDevicePixels="True">
383+
<ContentPresenter
384+
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
385+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
386+
</Border>
387+
</ControlTemplate>
388+
</Setter.Value>
389+
</Setter>
390+
391+
<Style.Triggers>
392+
<!-- Regular Hover style -->
393+
<DataTrigger
394+
Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
395+
Value="True">
396+
<Setter Property="Foreground" Value="DodgerBlue" />
397+
<Setter Property="Background" Value="White" />
398+
</DataTrigger>
399+
400+
<!-- Visibility condition -->
401+
<MultiDataTrigger>
402+
<MultiDataTrigger.Conditions>
403+
<!-- Hover Over Parent Grid -->
404+
<Condition
405+
Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=Grid}}"
406+
Value="True" />
407+
<!-- IsNotFirst condition -->
408+
<Condition Binding="{Binding IsNotFirst}" Value="True" />
409+
</MultiDataTrigger.Conditions>
410+
<Setter Property="Visibility" Value="Visible" />
411+
</MultiDataTrigger>
412+
</Style.Triggers>
413+
</Style>
414+
</Button.Style>
368415
</Button>
369-
<Button Click="SelectedPatch_MoveDown"
416+
<Button x:Name="DownButton"
417+
Click="SelectedPatch_MoveDown"
370418
Grid.Column="1"
371419
Grid.Row="1"
372420
Tag="{Binding}"
373-
Margin="0"
374-
Style="{StaticResource HoverVisibleButtonStyle}"
375421
Content="🡻">
422+
<Button.Style>
423+
<Style TargetType="Button">
424+
<Setter Property="Visibility" Value="Hidden" />
425+
<Setter Property="VerticalAlignment" Value="Stretch" />
426+
<Setter Property="HorizontalAlignment" Value="Stretch" />
427+
<Setter Property="Padding" Value="0,0" />
428+
<Setter Property="Margin" Value="0" />
429+
<Setter Property="Background" Value="White" />
430+
<Setter Property="BorderThickness" Value="0" />
431+
<Setter Property="BorderBrush" Value="Transparent" />
432+
<Setter Property="Template">
433+
<Setter.Value>
434+
<ControlTemplate TargetType="Button">
435+
<Border Background="{TemplateBinding Background}"
436+
BorderThickness="0" SnapsToDevicePixels="True">
437+
<ContentPresenter
438+
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
439+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
440+
</Border>
441+
</ControlTemplate>
442+
</Setter.Value>
443+
</Setter>
444+
445+
<Style.Triggers>
446+
<!-- Regular Hover style -->
447+
<DataTrigger
448+
Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
449+
Value="True">
450+
<Setter Property="Foreground" Value="DodgerBlue" />
451+
<Setter Property="Background" Value="White" />
452+
</DataTrigger>
453+
454+
<!-- Visibility condition -->
455+
<MultiDataTrigger>
456+
<MultiDataTrigger.Conditions>
457+
<!-- Hover Over Parent Grid -->
458+
<Condition
459+
Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=Grid}}"
460+
Value="True" />
461+
<!-- IsNotLast condition -->
462+
<Condition Binding="{Binding IsNotLast}" Value="True" />
463+
</MultiDataTrigger.Conditions>
464+
<Setter Property="Visibility" Value="Visible" />
465+
</MultiDataTrigger>
466+
</Style.Triggers>
467+
</Style>
468+
</Button.Style>
376469
</Button>
377470
</Grid>
378471
</DataTemplate>

thcrap_configure_v3/Page2_advanced.xaml.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.ObjectModel;
44
using System.ComponentModel;
55
using System.Diagnostics;
6+
using System.Globalization;
67
using System.Linq;
78
using System.IO;
89
using System.Text;
@@ -75,6 +76,47 @@ public class RepoPatch : INotifyPropertyChanged
7576
public thcrap_configure_v3.RepoPatch SourcePatch { get; set; }
7677
private bool isSelected = false;
7778
private bool isVisibleWithSearch = true;
79+
private bool _isFirst;
80+
private bool _isLast;
81+
82+
83+
public bool IsFirst
84+
{
85+
get => _isFirst;
86+
set
87+
{
88+
if (_isFirst != value)
89+
{
90+
_isFirst = value;
91+
OnPropertyChanged(nameof(IsFirst));
92+
OnPropertyChanged(nameof(IsNotFirst)); // Notify when IsFirst changes
93+
}
94+
}
95+
}
96+
97+
public bool IsLast
98+
{
99+
get => _isLast;
100+
set
101+
{
102+
if (_isLast != value)
103+
{
104+
_isLast = value;
105+
OnPropertyChanged(nameof(IsLast));
106+
OnPropertyChanged(nameof(IsNotLast)); // Notify when IsLast changes
107+
}
108+
}
109+
}
110+
111+
// New properties for inverted logic
112+
public bool IsNotFirst => !IsFirst;
113+
public bool IsNotLast => !IsLast;
114+
115+
protected virtual void OnPropertyChanged(string propertyName)
116+
{
117+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
118+
}
119+
78120

79121
public RepoPatch(thcrap_configure_v3.RepoPatch patch)
80122
{
@@ -187,6 +229,16 @@ private void SelectPatch(RepoPatch patch)
187229
AddToConfigName(patch.SourcePatch.Id);
188230
patch.Select(true);
189231
selectedPatches.Add(patch);
232+
UpdateFirstAndLastFlags();
233+
}
234+
235+
private void UpdateFirstAndLastFlags()
236+
{
237+
for (var i = 0; i < selectedPatches.Count; i++)
238+
{
239+
selectedPatches[i].IsFirst = (i == 0);
240+
selectedPatches[i].IsLast = (i == selectedPatches.Count - 1);
241+
}
190242
}
191243

192244
private void AvailablePatchDoubleClick(object sender, MouseButtonEventArgs e)
@@ -238,6 +290,7 @@ private void UnselectPatch(RepoPatch patch)
238290
selectedPatches.Remove(patch);
239291
patch.Select(false);
240292
RemoveFromConfigName(patch.SourcePatch.Id);
293+
UpdateFirstAndLastFlags();
241294
}
242295

243296
private void SelectedPatch_DoubleClick(object sender, MouseButtonEventArgs e)
@@ -302,6 +355,7 @@ private void SelectedPatch_MoveUp(object sender, RoutedEventArgs e)
302355
return;
303356

304357
selectedPatches.Move(idx, idx - 1);
358+
UpdateFirstAndLastFlags();
305359
}
306360

307361
private void SelectedPatch_MoveDown(object sender, RoutedEventArgs e)
@@ -323,6 +377,7 @@ private void SelectedPatch_MoveDown(object sender, RoutedEventArgs e)
323377
return;
324378

325379
selectedPatches.Move(idx, idx + 1);
380+
UpdateFirstAndLastFlags();
326381
}
327382

328383
public void ConfigNameChanged(object sender, TextChangedEventArgs e)

0 commit comments

Comments
 (0)