Skip to content

Commit

Permalink
Remove camera from wall with context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-david committed Aug 23, 2020
1 parent e9c5f31 commit 74b536b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
41 changes: 41 additions & 0 deletions src/Camera.App/Core/CameraWallControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace Restless.App.Camera.Core
Expand All @@ -16,16 +17,21 @@ public class CameraWallControl : Grid
#region Private
private int rows;
private int columns;
private long contextCameraId;
#endregion

/************************************************************************/

#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="CameraWallControl"/> class.
/// </summary>
public CameraWallControl()
{
Background = Brushes.Transparent;
rows = columns = 1;
Loaded += CameraWallControlLoaded;
InitializeContextMenu();
}
#endregion

Expand Down Expand Up @@ -131,6 +137,21 @@ protected override void OnDrop(DragEventArgs e)
AddCameraToWall(camera, e.GetPosition(this));
}
}

/// <summary>
/// Called when the context menu is opening.
/// </summary>
/// <param name="e">The event args</param>
protected override void OnContextMenuOpening(ContextMenuEventArgs e)
{
base.OnContextMenuOpening(e);
/* can't use e.CursorLeft / e.CursorTop; they are relative the grid cell, not the whole grid */
Point point = Mouse.GetPosition(this);
Tuple<int,int> cell = GetGridCellByPoint(point);
CameraHostBorder host = GetCameraHost(cell.Item1, cell.Item2);
contextCameraId = host?.CameraControl?.Camera.Id ?? -1;
e.Handled = contextCameraId == -1;
}
#endregion

/************************************************************************/
Expand Down Expand Up @@ -366,6 +387,26 @@ private void ExecutePushCommand(PushCommand command)
break;
}
}

private void InitializeContextMenu()
{
ContextMenu = new ContextMenu();

MenuItem item = new MenuItem()
{
Header = "Remove from wall",
Icon = Application.Current.TryFindResource("PathGrayX")
};

item.Click += MenuItemRemoveFromWallClick;

ContextMenu.Items.Add(item);
}

private void MenuItemRemoveFromWallClick(object sender, RoutedEventArgs e)
{
RemoveCameraFromWall(contextCameraId);
}
#endregion
}
}
4 changes: 2 additions & 2 deletions src/Camera.App/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@
<core:CameraListControl.ContextMenu>
<ContextMenu>
<MenuItem Header="Manage camera" Command="{Binding Commands[ManageCamera]}"/>
<MenuItem Header="Remove from wall" Command="{Binding Commands[RemoveCamera]}"/>
<MenuItem Header="Remove from wall" Icon="{StaticResource PathGrayX}" Command="{Binding Commands[RemoveCamera]}"/>
<Separator/>
<MenuItem Icon="{StaticResource PathRedX}" Header="Delete camera" Command="{Binding Commands[DeleteCamera]}"/>
<MenuItem Header="Delete camera" Icon="{StaticResource PathRedX}" Command="{Binding Commands[DeleteCamera]}"/>
</ContextMenu>
</core:CameraListControl.ContextMenu>
</core:CameraListControl>
Expand Down

0 comments on commit 74b536b

Please sign in to comment.