Skip to content

Commit 0d20a11

Browse files
committed
Refinements to PhotoCull selection mode.
Prevent selection of the second list item as the only item in the selection, since that results in comparing the item to itself. If a third item is selected, deselect the first item.
1 parent 506e5cd commit 0d20a11

File tree

4 files changed

+44
-54
lines changed

4 files changed

+44
-54
lines changed

PhotoCull/PhotoCullWindow.xaml

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:ptwpf="clr-namespace:PhotoTagger.Wpf;assembly=PhotoTagger.Wpf"
7-
xmlns:local="clr-namespace:PhotoCull"
87
x:Name="window" mc:Ignorable="d"
98
Title="Photo Cull"
109
AllowDrop="True" Drop="onFilesDrop">
@@ -42,7 +41,8 @@
4241
x:Name="photoList"
4342
SelectionMode="Multiple"
4443
ThumbnailHeight="{Binding ThumbnailHeight, ElementName=window}"
45-
Photos="{Binding Photos, ElementName=window}"/>
44+
Photos="{Binding Photos, ElementName=window}"
45+
OnSelectionChanged="onSelectionChanged"/>
4646
<StackPanel Grid.Row="1">
4747
<Button Content="Add images..."
4848
Click="addImagesEvent" />
@@ -86,26 +86,13 @@
8686
</Grid.RowDefinitions>
8787
<TextBlock Grid.Row="0">
8888
<TextBlock.Text>
89-
<PriorityBinding>
90-
<PriorityBinding.Bindings>
91-
<Binding ElementName="window"
92-
Path="SelectedPhotos[0].ShortTitle"/>
93-
<Binding ElementName="window"
94-
Path="Photos[0].ShortTitle"/>
95-
</PriorityBinding.Bindings>
96-
</PriorityBinding>
89+
<Binding ElementName="firstZoom"
90+
Path="Photo.ShortTitle"/>
9791
</TextBlock.Text>
9892
<TextBlock.TextDecorations>
99-
<PriorityBinding>
100-
<PriorityBinding.Bindings>
101-
<Binding Path="SelectedPhotos[0].MarkedForDeletion"
102-
Converter="{StaticResource RejectedToStrikethroughValueConverter}"
103-
ElementName="window" />
104-
<Binding Path="Photos[0].MarkedForDeletion"
105-
Converter="{StaticResource RejectedToStrikethroughValueConverter}"
106-
ElementName="window" />
107-
</PriorityBinding.Bindings>
108-
</PriorityBinding>
93+
<Binding Path="Photo.MarkedForDeletion"
94+
Converter="{StaticResource RejectedToStrikethroughValueConverter}"
95+
ElementName="firstZoom" />
10996
</TextBlock.TextDecorations>
11097
</TextBlock>
11198
<ptwpf:ImageZoomer Grid.Row="1"
@@ -166,26 +153,13 @@
166153
</Grid.RowDefinitions>
167154
<TextBlock Grid.Row="0">
168155
<TextBlock.Text>
169-
<PriorityBinding>
170-
<PriorityBinding.Bindings>
171-
<Binding ElementName="window"
172-
Path="SelectedPhotos[1].ShortTitle"/>
173-
<Binding ElementName="window"
174-
Path="Photos[1].ShortTitle"/>
175-
</PriorityBinding.Bindings>
176-
</PriorityBinding>
156+
<Binding ElementName="secondZoom"
157+
Path="Photo.ShortTitle"/>
177158
</TextBlock.Text>
178159
<TextBlock.TextDecorations>
179-
<PriorityBinding>
180-
<PriorityBinding.Bindings>
181-
<Binding Path="SelectedPhotos[1].MarkedForDeletion"
182-
Converter="{StaticResource RejectedToStrikethroughValueConverter}"
183-
ElementName="window" />
184-
<Binding Path="Photos[1].MarkedForDeletion"
185-
Converter="{StaticResource RejectedToStrikethroughValueConverter}"
186-
ElementName="window" />
187-
</PriorityBinding.Bindings>
188-
</PriorityBinding>
160+
<Binding Path="Photo.MarkedForDeletion"
161+
Converter="{StaticResource RejectedToStrikethroughValueConverter}"
162+
ElementName="secondZoom" />
189163
</TextBlock.TextDecorations>
190164
</TextBlock>
191165
<ptwpf:ImageZoomer Grid.Row="1"

PhotoCull/PhotoCullWindow.xaml.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ObservableCollection<Photo> Photos {
3838
DefaultValue = new ObservableCollection<Photo>()
3939
});
4040

41-
public ReadOnlyObservableCollection<Photo> SelectedPhotos {
41+
public ObservableCollection<Photo> SelectedPhotos {
4242
get {
4343
return this.photoList.Selected;
4444
}
@@ -296,11 +296,23 @@ private static bool debugging() {
296296
}
297297

298298
private void onFilesDrop(object sender, DragEventArgs e) {
299-
var files = e.Data.GetData(DataFormats.FileDrop) as string[];
300-
if (files == null || files.Length == 0) {
299+
if (!(e.Data.GetData(DataFormats.FileDrop) is string[] files) ||
300+
files.Length == 0) {
301301
return;
302302
}
303303
addImages(files);
304304
}
305+
306+
private void onSelectionChanged(object sender, SelectionChangedEventArgs e) {
307+
while (this.SelectedPhotos.Count > 2) {
308+
this.SelectedPhotos.RemoveAt(0);
309+
}
310+
if (this.SelectedPhotos.Count == 1 &&
311+
this.SelectedPhotos[0] == this.Photos[1]) {
312+
// Don't allow selecting the second photo in the list.
313+
// Otherwise we're just comparing that photo to itself.
314+
this.SelectedPhotos.RemoveAt(0);
315+
}
316+
}
305317
}
306318
}

PhotoTagger.Wpf/PhotoList.xaml.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using PhotoTagger.Imaging;
22
using System.Collections.ObjectModel;
3+
using System.Collections.Specialized;
34
using System.Windows;
45
using System.Windows.Controls;
56

@@ -10,9 +11,9 @@ namespace PhotoTagger.Wpf {
1011
public partial class PhotoList : UserControl {
1112
public PhotoList() {
1213
InitializeComponent();
14+
Selected.CollectionChanged += onSelectedForcedChange;
1315
}
1416

15-
1617
public SelectionMode SelectionMode {
1718
get {
1819
return (SelectionMode)GetValue(SelectionModeProperty);
@@ -41,27 +42,31 @@ public ObservableCollection<Photo> Photos {
4142
DependencyProperty.Register(nameof(Photos),
4243
typeof(ObservableCollection<Photo>), typeof(PhotoList));
4344

44-
45-
private readonly ObservableCollection<Photo> selected = new ObservableCollection<Photo>();
46-
47-
public ReadOnlyObservableCollection<Photo> Selected {
48-
get {
49-
return new ReadOnlyObservableCollection<Photo>(selected);
50-
}
51-
}
45+
public ObservableCollection<Photo> Selected {
46+
get;
47+
} = new ObservableCollection<Photo>();
5248

5349
public event SelectionChangedEventHandler OnSelectionChanged;
5450

5551
private void onSelectionChanged(object sender, SelectionChangedEventArgs e) {
5652
foreach (var item in e.RemovedItems) {
57-
this.selected.Remove(item as Photo);
53+
this.Selected.Remove(item as Photo);
5854
}
5955
foreach (var item in e.AddedItems) {
60-
this.selected.Add(item as Photo);
56+
this.Selected.Add(item as Photo);
6157
}
6258
OnSelectionChanged?.Invoke(sender, e);
6359
}
6460

61+
private void onSelectedForcedChange(object sender, NotifyCollectionChangedEventArgs e) {
62+
if (e.Action == NotifyCollectionChangedAction.Remove &&
63+
this.SelectionMode == SelectionMode.Multiple) {
64+
foreach (var item in e.OldItems) {
65+
this.ListBox.SelectedItems.Remove(item);
66+
}
67+
}
68+
// TODO: support other modification types.
69+
}
6570

6671
public object SelectedValue {
6772
get {
@@ -76,7 +81,6 @@ public object SelectedValue {
7681
DependencyProperty.Register(nameof(SelectedValue), typeof(object),
7782
typeof(PhotoList));
7883

79-
8084
public double ThumbnailHeight {
8185
get {
8286
return (double)GetValue(ThumbnailHeightProperty);

PhotoTagger/TaggerWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public ObservableCollection<Photo> Photos {
112112
DefaultValue = new ObservableCollection<Photo>()
113113
});
114114

115-
public ReadOnlyObservableCollection<Photo> SelectedPhotos {
115+
public ObservableCollection<Photo> SelectedPhotos {
116116
get {
117117
return this.photoList.Selected;
118118
}

0 commit comments

Comments
 (0)