Remove WinForms from MainViewModel

This commit is contained in:
Matt Nadareski
2023-10-08 23:46:24 -04:00
parent 50ae32e3db
commit ae80ecefc8
4 changed files with 42 additions and 47 deletions

View File

@@ -44,6 +44,7 @@
- Small updtes to MainViewModel
- Remove MainWindow from MainViewModel
- Use callback for logging, fix Options window
- Remove WinForms from MainViewModel
### 2.6.6 (2023-10-04)

View File

@@ -4,7 +4,6 @@ using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using BurnOutSharp;
using MPF.Core;
using MPF.Core.Data;
using MPF.Core.Utilities;
using MPF.Core.Modules;

View File

@@ -13,7 +13,6 @@ using MPF.Core.Utilities;
using MPF.Core.UI.ComboBoxItems;
using SabreTools.RedumpLib.Data;
using WPFCustomMessageBox;
using WinForms = System.Windows.Forms;
namespace MPF.UI.Core.ViewModels
{
@@ -871,15 +870,6 @@ namespace MPF.UI.Core.ViewModels
/// </summary>
public static void ExitApplication() => Application.Current.Shutdown();
/// <summary>
/// Set the output path from a dialog box
/// </summary>
public void SetOutputPath()
{
BrowseFile();
EnsureDiscInformation();
}
/// <summary>
/// Show the About text popup
/// </summary>
@@ -1141,40 +1131,6 @@ namespace MPF.UI.Core.ViewModels
#region Helpers
/// <summary>
/// Browse for an output file path
/// </summary>
private void BrowseFile()
{
// Get the current path, if possible
string currentPath = this.OutputPath;
if (string.IsNullOrWhiteSpace(currentPath))
currentPath = Path.Combine(this.Options.DefaultOutputPath, "track.bin");
if (string.IsNullOrWhiteSpace(currentPath))
currentPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "track.bin");
// Get the full path
currentPath = Path.GetFullPath(currentPath);
// Get the directory
string directory = Path.GetDirectoryName(currentPath);
// Get the filename
string filename = Path.GetFileName(currentPath);
WinForms.FileDialog fileDialog = new WinForms.SaveFileDialog
{
FileName = filename,
InitialDirectory = directory,
};
WinForms.DialogResult result = fileDialog.ShowDialog();
if (result == WinForms.DialogResult.OK)
{
this.OutputPath = fileDialog.FileName;
}
}
/// <summary>
/// Cache the current disc type to internal variable
/// </summary>

View File

@@ -1,10 +1,12 @@
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using MPF.Core;
using MPF.UI.Core.ViewModels;
using SabreTools.RedumpLib.Data;
using WPFCustomMessageBox;
using WinForms = System.Windows.Forms;
namespace MPF.UI.Core.Windows
{
@@ -76,6 +78,40 @@ namespace MPF.UI.Core.Windows
OutputPathTextBox.TextChanged += OutputPathTextBoxTextChanged;
}
/// <summary>
/// Browse for an output file path
/// </summary>
public void BrowseFile()
{
// Get the current path, if possible
string currentPath = MainViewModel.OutputPath;
if (string.IsNullOrWhiteSpace(currentPath))
currentPath = Path.Combine(MainViewModel.Options.DefaultOutputPath, "track.bin");
if (string.IsNullOrWhiteSpace(currentPath))
currentPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "track.bin");
// Get the full path
currentPath = Path.GetFullPath(currentPath);
// Get the directory
string directory = Path.GetDirectoryName(currentPath);
// Get the filename
string filename = Path.GetFileName(currentPath);
WinForms.FileDialog fileDialog = new WinForms.SaveFileDialog
{
FileName = filename,
InitialDirectory = directory,
};
WinForms.DialogResult result = fileDialog.ShowDialog();
if (result == WinForms.DialogResult.OK)
{
MainViewModel.OutputPath = fileDialog.FileName;
}
}
/// <summary>
/// Build a dummy SubmissionInfo and display it for testing
/// </summary>
@@ -240,8 +276,11 @@ namespace MPF.UI.Core.Windows
/// <summary>
/// Handler for OutputPathBrowseButton Click event
/// </summary>
public void OutputPathBrowseButtonClick(object sender, RoutedEventArgs e) =>
MainViewModel.SetOutputPath();
public void OutputPathBrowseButtonClick(object sender, RoutedEventArgs e)
{
BrowseFile();
MainViewModel.EnsureDiscInformation();
}
/// <summary>
/// Handler for OutputPathTextBox TextChanged event