Skip to content

Commit

Permalink
Delete key does discard/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
tryashtar committed Aug 22, 2022
1 parent 13a8bee commit 5a84644
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ImageMap4/Controls/MapList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800"
Focusable="True">
Focusable="True"
MouseDown="List_MouseDown">
<UserControl.InputBindings>
<KeyBinding Modifiers="Ctrl"
Key="A"
Expand Down
6 changes: 6 additions & 0 deletions ImageMap4/Controls/MapList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public MapList()
private Selectable<Map>? LastClicked;
private void Map_MouseDown(object sender, MouseButtonEventArgs e)
{
this.Focus();
var map = (Selectable<Map>)((FrameworkElement)sender).DataContext;
if (e.RightButton == MouseButtonState.Pressed)
{
Expand Down Expand Up @@ -89,6 +90,11 @@ private void Map_MouseDown(object sender, MouseButtonEventArgs e)
}
LastClicked = map;
}

private void List_MouseDown(object sender, MouseButtonEventArgs e)
{
this.Focus();
}
}

public class Selectable<T> : ObservableObject
Expand Down
5 changes: 4 additions & 1 deletion ImageMap4/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<KeyBinding Modifiers="Ctrl+Shift"
Key="Z"
Command="{Binding RedoCommand}" />
<KeyBinding Key="Delete"
Command="{Binding DeleteCommand, RelativeSource={RelativeSource AncestorType=Window}}" />
</Window.InputBindings>
<Window.Resources>
<ResourceDictionary>
Expand Down Expand Up @@ -501,7 +503,8 @@
</Button>
</StackPanel>
</StackPanel>
<local:MapList Grid.Column="1"
<local:MapList x:Name="ExistingList"
Grid.Column="1"
Grid.Row="1"
DataContext="{Binding ExistingMapsView}"
MapMenu="{StaticResource ExistingMenu}">
Expand Down
8 changes: 8 additions & 0 deletions ImageMap4/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public partial class MainWindow : Window, IDropTarget
{
private MainViewModel ViewModel => (MainViewModel)this.DataContext;
public ICommand PasteCommand { get; }
public ICommand DeleteCommand { get; }
public ICommand OpenWorldFolderCommand { get; }
public ICommand OpenMapFileCommand { get; }
public ICommand ChangeIDCommand { get; }
Expand Down Expand Up @@ -101,6 +102,13 @@ public MainWindow()
ImageWindow.Activate();
}
});
DeleteCommand = new RelayCommand(() =>
{
if (ImportList.IsFocused)
ViewModel.DiscardCommand.Execute(ViewModel.ImportingMaps);
else if (ExistingList.IsFocused)
ViewModel.DeleteCommand.Execute(ViewModel.ExistingMaps);
});
InitializeComponent();
}

Expand Down

0 comments on commit 5a84644

Please sign in to comment.