Add support for selectable assets directory in GUI

This commit is contained in:
Tyrrrz
2023-02-17 21:30:10 +02:00
parent 95115f3e99
commit d1647e8286
9 changed files with 159 additions and 87 deletions

View File

@@ -65,6 +65,8 @@ public class ExportSetupViewModel : DialogScreen
public bool ShouldReuseAssets { get; set; }
public string? AssetsDirPath { get; set; }
public bool IsAdvancedSectionDisplayed { get; set; }
public ExportSetupViewModel(DialogManager dialogManager, SettingsService settingsService)
@@ -79,15 +81,18 @@ public class ExportSetupViewModel : DialogScreen
ShouldFormatMarkdown = _settingsService.LastShouldFormatMarkdown;
ShouldDownloadAssets = _settingsService.LastShouldDownloadAssets;
ShouldReuseAssets = _settingsService.LastShouldReuseAssets;
AssetsDirPath = _settingsService.LastAssetsDirPath;
// Show the "advanced options" section by default if any
// of the advanced options are set to non-default values.
IsAdvancedSectionDisplayed =
After != default ||
Before != default ||
After is not null ||
Before is not null ||
!string.IsNullOrWhiteSpace(PartitionLimitValue) ||
!string.IsNullOrWhiteSpace(MessageFilterValue) ||
ShouldDownloadAssets != default;
ShouldDownloadAssets ||
ShouldReuseAssets ||
!string.IsNullOrWhiteSpace(AssetsDirPath);
}
public void ToggleAdvancedSection() => IsAdvancedSectionDisplayed = !IsAdvancedSectionDisplayed;
@@ -107,18 +112,25 @@ public class ExportSetupViewModel : DialogScreen
var extension = SelectedFormat.GetFileExtension();
var filter = $"{extension.ToUpperInvariant()} files|*.{extension}";
var outputPath = _dialogManager.PromptSaveFilePath(filter, defaultFileName);
if (!string.IsNullOrWhiteSpace(outputPath))
OutputPath = outputPath;
var path = _dialogManager.PromptSaveFilePath(filter, defaultFileName);
if (!string.IsNullOrWhiteSpace(path))
OutputPath = path;
}
else
{
var outputPath = _dialogManager.PromptDirectoryPath();
if (!string.IsNullOrWhiteSpace(outputPath))
OutputPath = outputPath;
var path = _dialogManager.PromptDirectoryPath();
if (!string.IsNullOrWhiteSpace(path))
OutputPath = path;
}
}
public void ShowAssetsDirPathPrompt()
{
var path = _dialogManager.PromptDirectoryPath();
if (!string.IsNullOrWhiteSpace(path))
AssetsDirPath = path;
}
public void Confirm()
{
// Prompt the output path if it's not set yet
@@ -138,6 +150,7 @@ public class ExportSetupViewModel : DialogScreen
_settingsService.LastShouldFormatMarkdown = ShouldFormatMarkdown;
_settingsService.LastShouldDownloadAssets = ShouldDownloadAssets;
_settingsService.LastShouldReuseAssets = ShouldReuseAssets;
_settingsService.LastAssetsDirPath = AssetsDirPath;
Close(true);
}
@@ -145,8 +158,10 @@ public class ExportSetupViewModel : DialogScreen
public static class ExportSetupViewModelExtensions
{
public static ExportSetupViewModel CreateExportSetupViewModel(this IViewModelFactory factory,
Guild guild, IReadOnlyList<Channel> channels)
public static ExportSetupViewModel CreateExportSetupViewModel(
this IViewModelFactory factory,
Guild guild,
IReadOnlyList<Channel> channels)
{
var viewModel = factory.CreateExportSetupViewModel();

View File

@@ -25,8 +25,10 @@ public static class MessageBoxViewModelExtensions
{
public static MessageBoxViewModel CreateMessageBoxViewModel(
this IViewModelFactory factory,
string title, string message,
string? okButtonText, string? cancelButtonText)
string title,
string message,
string? okButtonText,
string? cancelButtonText)
{
var viewModel = factory.CreateMessageBoxViewModel();
viewModel.Title = title;
@@ -42,6 +44,7 @@ public static class MessageBoxViewModelExtensions
public static MessageBoxViewModel CreateMessageBoxViewModel(
this IViewModelFactory factory,
string title, string message) =>
string title,
string message) =>
factory.CreateMessageBoxViewModel(title, message, "CLOSE", null);
}