Skip to content

Commit

Permalink
fixed crash on double-click of empty games library
Browse files Browse the repository at this point in the history
  • Loading branch information
Asnivor committed Oct 11, 2016
1 parent a9fc600 commit c6fdc05
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
4 changes: 2 additions & 2 deletions MedLaunch/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@
Controls:TextBoxHelper.Watermark="Dynamic Search" />
<GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" />

<DataGrid Background="Transparent" MouseDoubleClick="LaunchRom_Click" Grid.Row="2" Name="dgGameList" IsReadOnly="True" SelectionChanged="dgGameList_SelectionChanged" SelectionMode="Single" ContextMenuOpening="dgGameList_ContextMenuOpening">
<DataGrid PreviewMouseRightButtonDown="DataGrid_PreviewMouseRightButtonDown" Background="Transparent" MouseDoubleClick="LaunchRom_Click" Grid.Row="2" Name="dgGameList" IsReadOnly="True" SelectionChanged="dgGameList_SelectionChanged" SelectionMode="Single" >
<DataGrid.ContextMenu>
<ContextMenu>
<ContextMenu x:Name="dgContext">
<MenuItem x:Name="LaunchRom" Header="Play Game" Click="LaunchRom_Click" />
<MenuItem Header="Favorites" Click="MenuItemFavorite_Click" />
<MenuItem Header="Copy Launch String to Clipboard" Click="CopyLaunchStringToClipboard_Click" />
Expand Down
63 changes: 62 additions & 1 deletion MedLaunch/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Globalization;
using System.Windows.Controls.Primitives;

namespace MedLaunch
{
Expand Down Expand Up @@ -1316,9 +1318,21 @@ private void dgGameList_ContextMenuOpening(object sender, ContextMenuEventArgs e
FrameworkElement fe = e.Source as FrameworkElement;
ContextMenu cm = fe.ContextMenu;

ContextMenu c = (ContextMenu)this.FindName("dgContext");

// get selected row data
DataGridGamesView drv = (DataGridGamesView)dgGameList.SelectedItem;
if (drv == null)
{
c = (ContextMenu)this.FindName("dgContext");
//c.Visibility = Visibility.Collapsed;
//c.IsOpen = false;
return;
}
// c.Visibility = Visibility.Visible;


//MessageBox.Show(drv.ID.ToString());
string romName = drv.Game;
int romId = drv.ID;

Expand Down Expand Up @@ -1347,6 +1361,9 @@ private void dgGameList_ContextMenuOpening(object sender, ContextMenuEventArgs e
mi.Header = "Delete From Games Library"; // + romName;
}
}




//fe.ContextMenu = CMenu.BuildGamesMenu(dgGameList);
}
Expand Down Expand Up @@ -1384,6 +1401,8 @@ private void CopyLaunchStringToClipboard_Click(object sender, RoutedEventArgs e)
private async void LaunchRom_Click(object sender, RoutedEventArgs e)
{
DataGridGamesView drv = (DataGridGamesView)dgGameList.SelectedItem;
if (drv == null)
return;
int romId = drv.ID;

// create new GameLauncher instance
Expand Down Expand Up @@ -1774,6 +1793,48 @@ private void btnSettingsCancelAllChanges_Click(object sender, RoutedEventArgs e)

}


public class OneReturnsTrueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (int)value == 1;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}

private void DataGrid_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
DependencyObject DepObject = (DependencyObject)e.OriginalSource;

while ((DepObject != null) && !(DepObject is DataGridColumnHeader))
{
DepObject = VisualTreeHelper.GetParent(DepObject);
}

if (DepObject == null)
{
return;
}
if (DepObject is DataGridRow)
{
dgGameList.ContextMenu.Visibility = Visibility.Visible;
return;
}

if (DepObject is DataGridColumnHeader)
{
dgGameList.ContextMenu.Visibility = Visibility.Collapsed;
}
else
{
dgGameList.ContextMenu.Visibility = Visibility.Visible;
}
}


}
}

0 comments on commit c6fdc05

Please sign in to comment.