Skip to content

Commit

Permalink
UI: Only allow right click to create a context menu if a game is sele…
Browse files Browse the repository at this point in the history
…cted.
  • Loading branch information
GreemDev committed Dec 31, 2024
1 parent bd29f65 commit 4135d74
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 24 deletions.
7 changes: 3 additions & 4 deletions src/Ryujinx/UI/Controls/ApplicationGridView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
x:DataType="viewModels:MainWindowViewModel">
<UserControl.Resources>
<helpers:BitmapArrayValueConverter x:Key="ByteImage" />
<controls:ApplicationContextMenu x:Key="ApplicationContextMenu" />
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
Expand All @@ -26,10 +25,10 @@
Padding="8"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ContextFlyout="{StaticResource ApplicationContextMenu}"
SelectedItem="{Binding GridSelectedApplication}"
ContextFlyout="{Binding GridAppContextMenu}"
DoubleTapped="GameList_DoubleTapped"
ItemsSource="{Binding AppsObservableList}"
SelectionChanged="GameList_SelectionChanged">
ItemsSource="{Binding AppsObservableList}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel
Expand Down
6 changes: 0 additions & 6 deletions src/Ryujinx/UI/Controls/ApplicationGridView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,5 @@ public void GameList_DoubleTapped(object sender, TappedEventArgs args)
if (sender is ListBox { SelectedItem: ApplicationData selected })
RaiseEvent(new ApplicationOpenedEventArgs(selected, ApplicationOpenedEvent));
}

public void GameList_SelectionChanged(object sender, SelectionChangedEventArgs args)
{
if (DataContext is MainWindowViewModel viewModel && sender is ListBox { SelectedItem: ApplicationData selected })
viewModel.GridSelectedApplication = selected;
}
}
}
8 changes: 3 additions & 5 deletions src/Ryujinx/UI/Controls/ApplicationListView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:converters="clr-namespace:Avalonia.Data.Converters;assembly=Avalonia.Base"
d:DesignHeight="450"
d:DesignWidth="800"
Focusable="True"
Expand All @@ -16,7 +15,6 @@
x:DataType="viewModels:MainWindowViewModel">
<UserControl.Resources>
<helpers:BitmapArrayValueConverter x:Key="ByteImage" />
<controls:ApplicationContextMenu x:Key="ApplicationContextMenu" />
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
Expand All @@ -28,10 +26,10 @@
Padding="8"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ContextFlyout="{StaticResource ApplicationContextMenu}"
SelectedItem="{Binding ListSelectedApplication}"
ContextFlyout="{Binding ListAppContextMenu}"
DoubleTapped="GameList_DoubleTapped"
ItemsSource="{Binding AppsObservableList}"
SelectionChanged="GameList_SelectionChanged">
ItemsSource="{Binding AppsObservableList}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel
Expand Down
6 changes: 0 additions & 6 deletions src/Ryujinx/UI/Controls/ApplicationListView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ public void GameList_DoubleTapped(object sender, TappedEventArgs args)
RaiseEvent(new ApplicationOpenedEventArgs(selected, ApplicationOpenedEvent));
}

public void GameList_SelectionChanged(object sender, SelectionChangedEventArgs args)
{
if (DataContext is MainWindowViewModel viewModel && sender is ListBox { SelectedItem: ApplicationData selected })
viewModel.ListSelectedApplication = selected;
}

private async void IdString_OnClick(object sender, RoutedEventArgs e)
{
if (DataContext is not MainWindowViewModel mwvm)
Expand Down
62 changes: 59 additions & 3 deletions src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,42 @@ public class MainWindowViewModel : BaseModel
private bool _isActive;
private bool _isSubMenuOpen;

public ApplicationData ListSelectedApplication;
public ApplicationData GridSelectedApplication;
private ApplicationData _listSelectedApplication;
private ApplicationData _gridSelectedApplication;
private ApplicationContextMenu _listAppContextMenu;
private ApplicationContextMenu _gridAppContextMenu;

public ApplicationData ListSelectedApplication
{
get => _listSelectedApplication;
set
{
_listSelectedApplication = value;

if (_listSelectedApplication != null && _listAppContextMenu == null)
ListAppContextMenu = new ApplicationContextMenu();
else if (_listSelectedApplication == null && _listAppContextMenu != null)
ListAppContextMenu = null;

OnPropertyChanged();
}
}

public ApplicationData GridSelectedApplication
{
get => _gridSelectedApplication;
set
{
_gridSelectedApplication = value;

if (_gridSelectedApplication != null && _gridAppContextMenu == null)
GridAppContextMenu = new ApplicationContextMenu();
else if (_gridSelectedApplication == null && _gridAppContextMenu != null)
GridAppContextMenu = null;

OnPropertyChanged();
}
}

// Key is Title ID
public SafeDictionary<string, LdnGameData.Array> LdnData = [];
Expand Down Expand Up @@ -218,7 +252,7 @@ public string SearchText

public bool CanUpdate
{
get => _canUpdate && EnableNonGameRunningControls && Updater.CanUpdate(false);
get => _canUpdate && EnableNonGameRunningControls && Updater.CanUpdate();
set
{
_canUpdate = value;
Expand Down Expand Up @@ -247,6 +281,28 @@ public ReadOnlyObservableCollection<ApplicationData> AppsObservableList
}
}

public ApplicationContextMenu ListAppContextMenu
{
get => _listAppContextMenu;
set
{
_listAppContextMenu = value;

OnPropertyChanged();
}
}

public ApplicationContextMenu GridAppContextMenu
{
get => _gridAppContextMenu;
set
{
_gridAppContextMenu = value;

OnPropertyChanged();
}
}

public bool IsPaused
{
get => _isPaused;
Expand Down

0 comments on commit 4135d74

Please sign in to comment.