-
Notifications
You must be signed in to change notification settings - Fork 19
/
StatusGridContextMenu.xaml.cs
78 lines (69 loc) · 3.02 KB
/
StatusGridContextMenu.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.IO;
using System.Windows;
using System.Collections;
using System.Linq;
using System.Windows.Controls;
using GG.Libraries;
using GG.Models;
using System.Collections.Generic;
namespace GG.UserControls
{
/// <summary>
/// Interaction logic for StatusGridContextMenu.xaml
/// </summary>
public partial class StatusGridContextMenu : ContextMenu
{
public StatusGridContextMenu()
{
InitializeComponent();
}
/// <summary>
/// Preprocessing prior to menu opening.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnOpened(object sender, System.Windows.RoutedEventArgs e)
{
HandleStageUnstageMenuItems();
HandleDeleteMenuItem();
}
/// <summary>
/// Shows and hides Stage and Unstage menu items accordingly to what has been selected.
/// </summary>
private void HandleStageUnstageMenuItems()
{
MenuItem stage = UIHelper.FindChild<MenuItem>(this, "Stage");
MenuItem unstage = UIHelper.FindChild<MenuItem>(this, "Unstage");
Separator stageSeparator = UIHelper.FindChild<Separator>(this, "StageSeparator");
// Retrieve some info regarding what is selected on the grid.
DataGrid statusGrid = PlacementTarget as DataGrid;
bool hasStagedItems = statusGrid.SelectedItems.OfType<StatusItem>().Any(i => ((StatusItem) i).IsStaged);
bool hasUnstagedItems = statusGrid.SelectedItems.OfType<StatusItem>().Any(i => ((StatusItem) i).IsStaged == false);
// Hide/show stage and unstage menu items accordingly.
if (hasStagedItems && hasUnstagedItems)
{
stage.Visibility = Visibility.Collapsed;
unstage.Visibility = Visibility.Collapsed;
stageSeparator.Visibility = Visibility.Collapsed;
}
else
{
stage.Visibility = !hasStagedItems ? Visibility.Visible : Visibility.Collapsed;
unstage.Visibility = hasStagedItems ? Visibility.Visible : Visibility.Collapsed;
stageSeparator.Visibility = Visibility.Visible;
}
}
/// <summary>
/// Handles the disabling/enabling of the Delete menu item.
/// </summary>
private void HandleDeleteMenuItem()
{
MenuItem delete = UIHelper.FindChild<MenuItem>(this, "Delete");
DataGrid statusGrid = PlacementTarget as DataGrid;
string repositoryFullPath = ((RepositoryViewModel) statusGrid.DataContext).RepositoryFullPath;
bool hasPhysicallyExistingFiles = statusGrid.SelectedItems.OfType<StatusItem>().Any(i => File.Exists(repositoryFullPath + "/" + ((StatusItem) i).Filename));
delete.Visibility = hasPhysicallyExistingFiles ? Visibility.Visible : Visibility.Collapsed;
}
}
}