Use block-scoped namespaces

This commit is contained in:
Isaac Marovitz 2023-01-03 18:04:12 -05:00
parent fb884c7a30
commit eef1e1cc6a
No known key found for this signature in database
GPG key ID: 97250B2B09A132E1
9 changed files with 186 additions and 177 deletions

View file

@ -1,11 +1,12 @@
using Avalonia.Controls; using Avalonia.Controls;
namespace Ryujinx.Ava.UI.Views.Settings; namespace Ryujinx.Ava.UI.Views.Settings
public partial class SettingsAudioView : UserControl
{ {
public SettingsAudioView() public partial class SettingsAudioView : UserControl
{ {
InitializeComponent(); public SettingsAudioView()
{
InitializeComponent();
}
} }
} }

View file

@ -1,11 +1,12 @@
using Avalonia.Controls; using Avalonia.Controls;
namespace Ryujinx.Ava.UI.Views.Settings; namespace Ryujinx.Ava.UI.Views.Settings
public partial class SettingsCPUView : UserControl
{ {
public SettingsCPUView() public partial class SettingsCPUView : UserControl
{ {
InitializeComponent(); public SettingsCPUView()
{
InitializeComponent();
}
} }
} }

View file

@ -1,11 +1,12 @@
using Avalonia.Controls; using Avalonia.Controls;
namespace Ryujinx.Ava.UI.Views.Settings; namespace Ryujinx.Ava.UI.Views.Settings
public partial class SettingsGraphicsView : UserControl
{ {
public SettingsGraphicsView() public partial class SettingsGraphicsView : UserControl
{ {
InitializeComponent(); public SettingsGraphicsView()
{
InitializeComponent();
}
} }
} }

View file

@ -7,74 +7,75 @@ using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Input; using Ryujinx.Input;
using Ryujinx.Input.Assigner; using Ryujinx.Input.Assigner;
namespace Ryujinx.Ava.UI.Views.Settings; namespace Ryujinx.Ava.UI.Views.Settings
public partial class SettingsHotkeysView : UserControl
{ {
private ButtonKeyAssigner _currentAssigner; public partial class SettingsHotkeysView : UserControl
private IGamepadDriver AvaloniaKeyboardDriver;
public SettingsHotkeysView()
{ {
InitializeComponent(); private ButtonKeyAssigner _currentAssigner;
AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(this); private IGamepadDriver AvaloniaKeyboardDriver;
}
private void MouseClick(object sender, PointerPressedEventArgs e) public SettingsHotkeysView()
{
bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed;
_currentAssigner?.Cancel(shouldUnbind);
PointerPressed -= MouseClick;
}
private void Button_Checked(object sender, RoutedEventArgs e)
{
if (sender is ToggleButton button)
{ {
if (_currentAssigner != null && button == _currentAssigner.ToggledButton) InitializeComponent();
AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(this);
}
private void MouseClick(object sender, PointerPressedEventArgs e)
{
bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed;
_currentAssigner?.Cancel(shouldUnbind);
PointerPressed -= MouseClick;
}
private void Button_Checked(object sender, RoutedEventArgs e)
{
if (sender is ToggleButton button)
{ {
return; if (_currentAssigner != null && button == _currentAssigner.ToggledButton)
}
if (_currentAssigner == null && button.IsChecked != null && (bool)button.IsChecked)
{
_currentAssigner = new ButtonKeyAssigner(button);
FocusManager.Instance?.Focus(this, NavigationMethod.Pointer);
PointerPressed += MouseClick;
var keyboard = (IKeyboard)AvaloniaKeyboardDriver.GetGamepad(AvaloniaKeyboardDriver.GamepadsIds[0]);
IButtonAssigner assigner = new KeyboardKeyAssigner(keyboard);
_currentAssigner.GetInputAndAssign(assigner);
}
else
{
if (_currentAssigner != null)
{ {
ToggleButton oldButton = _currentAssigner.ToggledButton; return;
}
_currentAssigner.Cancel(); if (_currentAssigner == null && button.IsChecked != null && (bool)button.IsChecked)
_currentAssigner = null; {
_currentAssigner = new ButtonKeyAssigner(button);
button.IsChecked = false; FocusManager.Instance?.Focus(this, NavigationMethod.Pointer);
PointerPressed += MouseClick;
var keyboard = (IKeyboard)AvaloniaKeyboardDriver.GetGamepad(AvaloniaKeyboardDriver.GamepadsIds[0]);
IButtonAssigner assigner = new KeyboardKeyAssigner(keyboard);
_currentAssigner.GetInputAndAssign(assigner);
}
else
{
if (_currentAssigner != null)
{
ToggleButton oldButton = _currentAssigner.ToggledButton;
_currentAssigner.Cancel();
_currentAssigner = null;
button.IsChecked = false;
}
} }
} }
} }
}
private void Button_Unchecked(object sender, RoutedEventArgs e) private void Button_Unchecked(object sender, RoutedEventArgs e)
{ {
_currentAssigner?.Cancel(); _currentAssigner?.Cancel();
_currentAssigner = null; _currentAssigner = null;
} }
public void Dispose() public void Dispose()
{ {
_currentAssigner?.Cancel(); _currentAssigner?.Cancel();
_currentAssigner = null; _currentAssigner = null;
}
} }
} }

View file

@ -1,16 +1,17 @@
using Avalonia.Controls; using Avalonia.Controls;
namespace Ryujinx.Ava.UI.Views.Settings; namespace Ryujinx.Ava.UI.Views.Settings
public partial class SettingsInputView : UserControl
{ {
public SettingsInputView() public partial class SettingsInputView : UserControl
{ {
InitializeComponent(); public SettingsInputView()
} {
InitializeComponent();
}
public void Dispose() public void Dispose()
{ {
ControllerSettings.Dispose(); ControllerSettings.Dispose();
}
} }
} }

View file

@ -1,11 +1,12 @@
using Avalonia.Controls; using Avalonia.Controls;
namespace Ryujinx.Ava.UI.Views.Settings; namespace Ryujinx.Ava.UI.Views.Settings
public partial class SettingsLoggingView : UserControl
{ {
public SettingsLoggingView() public partial class SettingsLoggingView : UserControl
{ {
InitializeComponent(); public SettingsLoggingView()
{
InitializeComponent();
}
} }
} }

View file

@ -1,11 +1,12 @@
using Avalonia.Controls; using Avalonia.Controls;
namespace Ryujinx.Ava.UI.Views.Settings; namespace Ryujinx.Ava.UI.Views.Settings
public partial class SettingsNetworkView : UserControl
{ {
public SettingsNetworkView() public partial class SettingsNetworkView : UserControl
{ {
InitializeComponent(); public SettingsNetworkView()
{
InitializeComponent();
}
} }
} }

View file

@ -6,45 +6,46 @@ using System;
using System.Linq; using System.Linq;
using TimeZone = Ryujinx.Ava.UI.Models.TimeZone; using TimeZone = Ryujinx.Ava.UI.Models.TimeZone;
namespace Ryujinx.Ava.UI.Views.Settings; namespace Ryujinx.Ava.UI.Views.Settings
public partial class SettingsSystemView : UserControl
{ {
public SettingsViewModel ViewModel; public partial class SettingsSystemView : UserControl
public SettingsSystemView()
{ {
InitializeComponent(); public SettingsViewModel ViewModel;
FuncMultiValueConverter<string, string> converter = new(parts => string.Format("{0} {1} {2}", parts.ToArray()).Trim()); public SettingsSystemView()
MultiBinding tzMultiBinding = new() { Converter = converter };
tzMultiBinding.Bindings.Add(new Binding("UtcDifference"));
tzMultiBinding.Bindings.Add(new Binding("Location"));
tzMultiBinding.Bindings.Add(new Binding("Abbreviation"));
TimeZoneBox.ValueMemberBinding = tzMultiBinding;
}
private void TimeZoneBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems != null && e.AddedItems.Count > 0)
{ {
if (e.AddedItems[0] is TimeZone timeZone) InitializeComponent();
{
e.Handled = true;
ViewModel.ValidateAndSetTimeZone(timeZone.Location); FuncMultiValueConverter<string, string> converter = new(parts => string.Format("{0} {1} {2}", parts.ToArray()).Trim());
MultiBinding tzMultiBinding = new() { Converter = converter };
tzMultiBinding.Bindings.Add(new Binding("UtcDifference"));
tzMultiBinding.Bindings.Add(new Binding("Location"));
tzMultiBinding.Bindings.Add(new Binding("Abbreviation"));
TimeZoneBox.ValueMemberBinding = tzMultiBinding;
}
private void TimeZoneBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems != null && e.AddedItems.Count > 0)
{
if (e.AddedItems[0] is TimeZone timeZone)
{
e.Handled = true;
ViewModel.ValidateAndSetTimeZone(timeZone.Location);
}
} }
} }
}
private void TimeZoneBox_OnTextChanged(object sender, EventArgs e) private void TimeZoneBox_OnTextChanged(object sender, EventArgs e)
{
if (sender is AutoCompleteBox box && box.SelectedItem is TimeZone timeZone)
{ {
if (sender is AutoCompleteBox box && box.SelectedItem is TimeZone timeZone)
{ {
ViewModel.ValidateAndSetTimeZone(timeZone.Location); {
ViewModel.ValidateAndSetTimeZone(timeZone.Location);
}
} }
} }
} }

View file

@ -7,75 +7,76 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
namespace Ryujinx.Ava.UI.Views.Settings; namespace Ryujinx.Ava.UI.Views.Settings
public partial class SettingsUIView : UserControl
{ {
public SettingsViewModel ViewModel; public partial class SettingsUIView : UserControl
public SettingsUIView()
{ {
InitializeComponent(); public SettingsViewModel ViewModel;
}
private async void AddButton_OnClick(object sender, RoutedEventArgs e) public SettingsUIView()
{
string path = PathBox.Text;
if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !ViewModel.GameDirectories.Contains(path))
{ {
ViewModel.GameDirectories.Add(path); InitializeComponent();
ViewModel.DirectoryChanged = true;
} }
else
private async void AddButton_OnClick(object sender, RoutedEventArgs e)
{ {
string path = PathBox.Text;
if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path) && !ViewModel.GameDirectories.Contains(path))
{
ViewModel.GameDirectories.Add(path);
ViewModel.DirectoryChanged = true;
}
else
{
if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
path = await new OpenFolderDialog().ShowAsync(desktop.MainWindow);
if (!string.IsNullOrWhiteSpace(path))
{
ViewModel.GameDirectories.Add(path);
ViewModel.DirectoryChanged = true;
}
}
}
}
private void RemoveButton_OnClick(object sender, RoutedEventArgs e)
{
int oldIndex = GameList.SelectedIndex;
foreach (string path in new List<string>(GameList.SelectedItems.Cast<string>()))
{
ViewModel.GameDirectories.Remove(path);
ViewModel.DirectoryChanged = true;
}
if (GameList.ItemCount > 0)
{
GameList.SelectedIndex = oldIndex < GameList.ItemCount ? oldIndex : 0;
}
}
public async void BrowseTheme(object sender, RoutedEventArgs e)
{
var dialog = new OpenFileDialog()
{
Title = LocaleManager.Instance[LocaleKeys.SettingsSelectThemeFileDialogTitle],
AllowMultiple = false
};
dialog.Filters.Add(new FileDialogFilter() { Extensions = { "xaml" }, Name = LocaleManager.Instance[LocaleKeys.SettingsXamlThemeFile] });
if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{ {
path = await new OpenFolderDialog().ShowAsync(desktop.MainWindow); var file = await dialog.ShowAsync(desktop.MainWindow);
if (!string.IsNullOrWhiteSpace(path)) if (file != null && file.Length > 0)
{ {
ViewModel.GameDirectories.Add(path); ViewModel.CustomThemePath = file[0];
ViewModel.DirectoryChanged = true;
} }
} }
} }
} }
private void RemoveButton_OnClick(object sender, RoutedEventArgs e)
{
int oldIndex = GameList.SelectedIndex;
foreach (string path in new List<string>(GameList.SelectedItems.Cast<string>()))
{
ViewModel.GameDirectories.Remove(path);
ViewModel.DirectoryChanged = true;
}
if (GameList.ItemCount > 0)
{
GameList.SelectedIndex = oldIndex < GameList.ItemCount ? oldIndex : 0;
}
}
public async void BrowseTheme(object sender, RoutedEventArgs e)
{
var dialog = new OpenFileDialog()
{
Title = LocaleManager.Instance[LocaleKeys.SettingsSelectThemeFileDialogTitle],
AllowMultiple = false
};
dialog.Filters.Add(new FileDialogFilter() { Extensions = { "xaml" }, Name = LocaleManager.Instance[LocaleKeys.SettingsXamlThemeFile] });
if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var file = await dialog.ShowAsync(desktop.MainWindow);
if (file != null && file.Length > 0)
{
ViewModel.CustomThemePath = file[0];
}
}
}
} }