Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 7 additions & 83 deletions src/WinUI3/MainWindow.Dialogs.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.Diagnostics;
using Microsoft.UI;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using Windows.System;
using WinRT.Interop;

namespace ModFolderCopier.WinUI;

Expand Down Expand Up @@ -263,32 +261,6 @@ private async void OnNotificationRequested(object? sender, StatusNotification no
}
}

private async Task OpenExternalUrlAsync(string? url, string failureTitle)
{
if (string.IsNullOrWhiteSpace(url))
{
await ShowMessageAsync(
T("Dialogs.ThisEntryDoesNotHaveA"),
failureTitle);
return;
}

try
{
Process.Start(new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
catch (Exception ex)
{
await ShowMessageAsync(
T("Common.FailedToOpenLink") + ex.Message,
failureTitle);
}
}

private UIElement CreateInfoCard(string title, string body)
{
return new Border
Expand Down Expand Up @@ -318,64 +290,16 @@ private UIElement CreateInfoCard(string title, string body)
};
}

private Task<string?> PickFolderAsync(string? preferredPath = null) =>
Task.FromResult(NativeFileDialog.PickFolder(WindowNative.GetWindowHandle(this)));
// Stage J finish, step 2: these live in DialogService; the window keeps one-line forwards for its own callers.
private Task OpenExternalUrlAsync(string? url, string failureTitle) => _services.Dialogs.OpenExternalUrlAsync(url, failureTitle);

private Task<string?> PickFileAsync(string[] extensions) =>
Task.FromResult(NativeFileDialog.PickFile(WindowNative.GetWindowHandle(this), extensions));
private Task<string?> PickFolderAsync(string? preferredPath = null) => _services.Dialogs.PickFolderAsync(preferredPath);

private void OpenDirectory(string? directory, string title)
{
try
{
if (string.IsNullOrWhiteSpace(directory) || !Directory.Exists(directory))
{
_ = ShowMessageAsync(
title + T("Dialogs.DoesNotExistPleaseChooseIt"),
T("Common.InvalidPath"));
return;
}
private Task<string?> PickFileAsync(string[] extensions) => _services.Dialogs.PickFileAsync(extensions);

Process.Start(new ProcessStartInfo
{
FileName = directory,
UseShellExecute = true
});
}
catch (Exception ex)
{
_ = ShowMessageAsync(
T("Dialogs.FailedToOpenFolder") + ex.Message,
T("Dialogs.OperationFailed"));
}
}
private void OpenDirectory(string? directory, string title) => _services.Dialogs.OpenDirectory(directory, title);

private void OpenFileLocation(string? filePath, string title)
{
try
{
if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
{
_ = ShowMessageAsync(
title + T("Dialogs.DoesNotExistPleaseChooseIt"),
T("Common.InvalidPath"));
return;
}

Process.Start(new ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = "/select,\"" + filePath + "\"",
UseShellExecute = true
});
}
catch (Exception ex)
{
_ = ShowMessageAsync(
T("Dialogs.FailedToOpenFileLocation") + ex.Message,
T("Dialogs.OperationFailed"));
}
}
private void OpenFileLocation(string? filePath, string title) => _services.Dialogs.OpenFileLocation(filePath, title);

// The common dialogs, shown by DialogService (stage J8).
private Task ShowMessageAsync(string content, string title) => _services.Dialogs.MessageAsync(title, content);
Expand Down
5 changes: 0 additions & 5 deletions src/WinUI3/MainWindow.OnlineHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ private static HttpClient CreateHttpClient()
bool IOnlineHost.IsOnlinePageShown => _currentPrimarySection == PrimarySection.Online;
FrameworkElement IOnlineHost.Root => RootGrid;
Windows.Foundation.Rect IOnlineHost.Bounds => Bounds;
Brush IOnlineHost.GetAppThemeBrush(string resourceKey) => GetAppThemeBrush(resourceKey);
string IOnlineHost.Density => _interfaceDensity.ToString();
bool IOnlineHost.ReduceMotion => _reduceMotion;
bool IOnlineHost.ShouldReduceAnimations => ShouldReduceAnimations;
void IOnlineHost.AnimateImageReveal(UIElement image) => _workspaceView.AnimateImageReveal(image);
Task<string?> IOnlineHost.PickFolderAsync(string? preferredPath) => PickFolderAsync(preferredPath);
Task IOnlineHost.OpenExternalUrlAsync(string? url, string failureTitle) => OpenExternalUrlAsync(url, failureTitle);
Task IOnlineHost.ShowImageViewerAsync(ImageSource? source, string title, IReadOnlyList<string>? imageUrls, int selectedIndex)
=> ShowImageViewerAsync(source, title, imageUrls, selectedIndex);

Expand All @@ -42,7 +38,6 @@ Task IOnlineHost.ShowImageViewerAsync(ImageSource? source, string title, IReadOn
void IOnlineHost.SaveShellConfig(bool throwOnError) => SaveShellConfig(throwOnError);
bool IOnlineHost.SaveConfig() => SaveConfig();

WorkspaceRepository? IOnlineHost.GetSelectedRepository() => GetSelectedRepository();
Task IOnlineHost.RefreshListsAsync() => _workspaceView.RefreshListsAsync();
void IOnlineHost.SelectSecondLevelByPath(string? path) => _workspaceView.SelectSecondLevelByPath(path);
void IOnlineHost.SetBusyState(bool busy) => _workspaceView.SetBusyState(busy);
Expand Down
1 change: 0 additions & 1 deletion src/WinUI3/MainWindow.UpdatesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ private void InitializeUpdatesHost()
{
UpdatesView.ActionRequested += OnUpdatesActionRequested;
UpdatesView.PropertyChanged += OnUpdatesViewChanged;
_services.Appearance.ReduceAnimations = () => ShouldReduceAnimations;
_services.Downloads.IsRetryBlocked = () => _onlineView._onlineDownloadActions.IsPreparing;
// The navigation shows the running downloads; the Updates page lists the finished ones itself.
_services.Downloads.Changed += (_, _) =>
Expand Down
7 changes: 0 additions & 7 deletions src/WinUI3/MainWindow.WorkspaceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,13 @@ private void AttachWorkspacePageEvents()
Windows.Foundation.Rect IWorkspaceHost.Bounds => Bounds;
object IWorkspaceHost.OnlineNavButton => OnlineNavButton;
void IWorkspaceHost.AttachTrackedTextInput(TextBox box) => AttachTrackedTextInput(box);
Brush IWorkspaceHost.GetAppThemeBrush(string resourceKey) => GetAppThemeBrush(resourceKey);
void IWorkspaceHost.OnOnlineNavClicked(object sender, RoutedEventArgs e) => OnOnlineNavClicked(sender, e);

(List<FirstLevelFolderItem> Items, int SecondCount) IWorkspaceHost.LoadFolderItemsUsingIndex(string repositoryId, string sourceDir, string targetDir, CancellationToken cancellationToken, out int warningCount) => LoadFolderItemsUsingIndex(repositoryId, sourceDir, targetDir, cancellationToken, out warningCount);
void IWorkspaceHost.LogApplicationIssue(string operation, Exception exception) => LogApplicationIssue(operation, exception);
bool IWorkspaceHost.ShouldReduceAnimations => ShouldReduceAnimations;
void IWorkspaceHost.ReportUiActionFailure(string operation, Exception exception) => ReportUiActionFailure(operation, exception);
Task IWorkspaceHost.RunUiActionAsync(string operation, Func<Task> action) => RunUiActionAsync(operation, action);

void IWorkspaceHost.OpenDirectory(string? directory, string title) => OpenDirectory(directory, title);
void IWorkspaceHost.OpenFileLocation(string? filePath, string title) => OpenFileLocation(filePath, title);
Task<string?> IWorkspaceHost.PickFileAsync(string[] extensions) => PickFileAsync(extensions);
Task<string?> IWorkspaceHost.PickFolderAsync(string? preferredPath) => PickFolderAsync(preferredPath);
Task IWorkspaceHost.ShowImageViewerAsync(ImageSource? source, string title, IReadOnlyList<string>? imageUrls, int selectedIndex) => ShowImageViewerAsync(source, title, imageUrls, selectedIndex);

bool IWorkspaceHost.SaveConfig() => SaveConfig();
Expand All @@ -54,7 +48,6 @@ private void AttachWorkspacePageEvents()
void IWorkspaceHost.ApplyShortcutPlaceholders() => ApplyShortcutPlaceholders();
void IWorkspaceHost.RefreshLocalizedStates() => RefreshLocalizedStates();

WorkspaceRepository? IWorkspaceHost.GetSelectedRepository() => GetSelectedRepository();
void IWorkspaceHost.OnEditRepositoryDetailsClicked(object sender, RoutedEventArgs e) => OnEditRepositoryDetailsClicked(sender, e);
void IWorkspaceHost.SwitchRepository(string repositoryId, bool openManager) => SwitchRepository(repositoryId, openManager);

Expand Down
2 changes: 2 additions & 0 deletions src/WinUI3/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public MainWindow()
AttachWorkspacePageEvents();
_services.Images.Attach(_httpClient, LogApplicationIssue);
_services.Dialogs.Attach(() => RootGrid.XamlRoot, () => RootGrid.ActualTheme);
_services.Appearance.ReduceAnimations = () => ShouldReduceAnimations;
_services.Dialogs.AttachWindow(() => WinRT.Interop.WindowNative.GetWindowHandle(this));
_services.Status.NotificationRequested += OnNotificationRequested;
InitializeSettingsHost();
InitializeUpdatesHost();
Expand Down
5 changes: 0 additions & 5 deletions src/WinUI3/Pages/Online/IOnlineHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ internal interface IOnlineHost
bool IsOnlinePageShown { get; }
FrameworkElement Root { get; }
Windows.Foundation.Rect Bounds { get; }
Brush GetAppThemeBrush(string resourceKey);
// The density name, part of the page's layout cache key.
string Density { get; }
bool ReduceMotion { get; }
bool ShouldReduceAnimations { get; }
void AnimateImageReveal(UIElement image);
Task<string?> PickFolderAsync(string? preferredPath = null);
Task OpenExternalUrlAsync(string? url, string failureTitle);
Task ShowImageViewerAsync(ImageSource? source, string title, IReadOnlyList<string>? imageUrls = null, int selectedIndex = 0);

// Errors and the error log.
Expand All @@ -39,7 +35,6 @@ internal interface IOnlineHost
bool SaveConfig();

// The repository and the Mod workspace: the selected repository, refreshing and selecting after an install.
WorkspaceRepository? GetSelectedRepository();
Task RefreshListsAsync();
void SelectSecondLevelByPath(string? path);
void SetBusyState(bool busy);
Expand Down
2 changes: 1 addition & 1 deletion src/WinUI3/Pages/Online/OnlinePage.AuthorWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private void OnOnlineWorkFilterClicked(object sender, RoutedEventArgs e)
private async Task ShowOnlineLibraryAsync()
{
UiCrashDiagnostics.RecordAction("Author and saved workspace opened");
var repo = _host.GetSelectedRepository();
var repo = _services.Repositories.Selected;
if (repo is null) return;
string category = GetEffectiveOnlineCategoryId(repo);
string contextKey = GetOnlineDetailContextKey();
Expand Down
2 changes: 1 addition & 1 deletion src/WinUI3/Pages/Online/OnlinePage.BatchDownloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private async Task PrepareSavedBatchAsync(OnlineSavedMod[] saved, WorkspaceRepos
enabled, isChecked, files, options, folderIndex, note));
}
if (await BatchDownloadDialogs.ReviewAsync(_services, context.RepositoryName, context.RepositoryPath, reviewRows,
(key, file) => GetOnlineDuplicateKind(((PreparedSavedDownload)key).Mod, file, context), _host.GetAppThemeBrush("AppNavSelectedBorderBrush"),
(key, file) => GetOnlineDuplicateKind(((PreparedSavedDownload)key).Mod, file, context), GetAppThemeBrush("AppNavSelectedBorderBrush"),
_host.Root.ActualWidth, _host.Root.ActualHeight) is not { } review
|| _onlineWindowClosed || contextKey != GetOnlineDetailContextKey()) return;
var chosen = review.Rows.Select(plan => (Data: (PreparedSavedDownload)plan.Key, plan.File, Choice: plan.Folder)).ToArray();
Expand Down
4 changes: 2 additions & 2 deletions src/WinUI3/Pages/Online/OnlinePage.BrowseSessions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed partial class OnlinePage

private string? CurrentBrowseSessionKey()
{
var repository = _host.GetSelectedRepository();
var repository = _services.Repositories.Selected;
return repository is null ? null : WorkspaceIdentity.Online(repository.Id, repository.SourcePath,
GetEffectiveOnlineSource(repository), GetEffectiveOnlineCategoryId(repository));
}
Expand All @@ -30,7 +30,7 @@ private void EnsureOnlineBrowseSession()
CancelOnlineModListRequest();
_lastLoadedOnlineConfigKey = null;
_onlinePage.Mods.Clear();
EnsureOnlineCharacterOptionsForRepository(_host.GetSelectedRepository());
EnsureOnlineCharacterOptionsForRepository(_services.Repositories.Selected);
++_browseRestoreRevision;
var state = key is not null && _onlinePreferences.BrowseSessions.TryGetValue(key, out var saved) && saved is not null
? saved.Sanitize() : new OnlineBrowseSession { Layout = _onlinePage.CardLayoutMode.ToString() };
Expand Down
24 changes: 12 additions & 12 deletions src/WinUI3/Pages/Online/OnlinePage.Fields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ public sealed partial class OnlinePage
internal void ApplySecondaryNavButtonVisual(Button button, bool isSelected)
{
Brush backgroundBrush = isSelected
? _host.GetAppThemeBrush("AppSecondarySelectedBrush")
: _host.GetAppThemeBrush("AppSecondaryDefaultBrush");
? GetAppThemeBrush("AppSecondarySelectedBrush")
: GetAppThemeBrush("AppSecondaryDefaultBrush");
Brush borderBrush = isSelected
? _host.GetAppThemeBrush("AppNavSelectedBorderBrush")
: _host.GetAppThemeBrush("AppCardBorderBrush");
? GetAppThemeBrush("AppNavSelectedBorderBrush")
: GetAppThemeBrush("AppCardBorderBrush");
Brush foregroundBrush = isSelected
? _host.GetAppThemeBrush("AppSecondarySelectedForegroundBrush")
: _host.GetAppThemeBrush("AppSecondaryDefaultForegroundBrush");
Brush disabledForegroundBrush = _host.GetAppThemeBrush("AppDisabledForegroundBrush");
Brush disabledBackgroundBrush = _host.GetAppThemeBrush("AppSecondaryDefaultBrush");
Brush disabledBorderBrush = _host.GetAppThemeBrush("AppCardBorderBrush");
? GetAppThemeBrush("AppSecondarySelectedForegroundBrush")
: GetAppThemeBrush("AppSecondaryDefaultForegroundBrush");
Brush disabledForegroundBrush = GetAppThemeBrush("AppDisabledForegroundBrush");
Brush disabledBackgroundBrush = GetAppThemeBrush("AppSecondaryDefaultBrush");
Brush disabledBorderBrush = GetAppThemeBrush("AppCardBorderBrush");

button.Background = backgroundBrush;
button.BorderBrush = borderBrush;
Expand Down Expand Up @@ -122,10 +122,10 @@ internal FrameworkElement WrapCharacterButtonWithFavorite(Button characterButton
? VerticalAlignment.Top
: VerticalAlignment.Center,
CornerRadius = new CornerRadius(15),
Background = _host.GetAppThemeBrush(isFavorite ? "AppAccentSoftBrush" : "AppSecondaryDefaultBrush"),
BorderBrush = _host.GetAppThemeBrush(isFavorite ? "AppNavSelectedBorderBrush" : "AppCardBorderBrush"),
Background = GetAppThemeBrush(isFavorite ? "AppAccentSoftBrush" : "AppSecondaryDefaultBrush"),
BorderBrush = GetAppThemeBrush(isFavorite ? "AppNavSelectedBorderBrush" : "AppCardBorderBrush"),
BorderThickness = new Thickness(1),
Foreground = _host.GetAppThemeBrush(isFavorite ? "AppAccentBrush" : "AppSecondaryDefaultForegroundBrush"),
Foreground = GetAppThemeBrush(isFavorite ? "AppAccentBrush" : "AppSecondaryDefaultForegroundBrush"),
Content = new FontIcon
{
Glyph = isFavorite ? "\uE735" : "\uE734",
Expand Down
6 changes: 3 additions & 3 deletions src/WinUI3/Pages/Online/OnlinePage.OnlineBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ private HyperlinkButton CreateOnlineAuthorLink(OnlineModCard mod)

private OnlineCardStatus GetOnlineCardStatus(OnlineModCard mod, TrackedModOrigin? installed, string defaultStatus)
{
bool active = _onlineDownloadActions.IsActive(CaptureOnlineDownloadContext(_host.GetSelectedRepository()),
bool active = _onlineDownloadActions.IsActive(CaptureOnlineDownloadContext(_services.Repositories.Selected),
GetOnlineDownloadIdentity(mod));
DownloadTaskItem? task = _services.Downloads.Tasks.FirstOrDefault(item =>
item.Session is not null && item.SourceIdentity == GetOnlineDownloadIdentity(mod)
&& string.Equals(item.Session.Context.RepositoryId, _host.GetSelectedRepository()?.Id, StringComparison.OrdinalIgnoreCase)
&& string.Equals(item.Session.Context.RepositoryPath, _host.GetSelectedRepository()?.SourcePath, StringComparison.OrdinalIgnoreCase));
&& string.Equals(item.Session.Context.RepositoryId, _services.Repositories.Selected?.Id, StringComparison.OrdinalIgnoreCase)
&& string.Equals(item.Session.Context.RepositoryPath, _services.Repositories.Selected?.SourcePath, StringComparison.OrdinalIgnoreCase));
// A retry can be preparing while its previous terminal task is still in history.
if (active && task is not null && DownloadProgressPolicy.IsTerminal(task.State)) task = null;
string text = task?.State switch
Expand Down
16 changes: 8 additions & 8 deletions src/WinUI3/Pages/Online/OnlinePage.OnlineCards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ private EmptyState CreateOnlineEmptyState(string glyph, string title, string hin
// Placeholder cards shaped like the current view (rows or tiles), shown under the loading ring.
private void ShowOnlineLoadingPlaceholders()
{
Brush fill = _host.GetAppThemeBrush("AppInsetBackgroundBrush");
Brush shade = _host.GetAppThemeBrush("AppAccentSoftBrush");
Brush fill = GetAppThemeBrush("AppInsetBackgroundBrush");
Brush shade = GetAppThemeBrush("AppAccentSoftBrush");
if (_onlinePage.CardLayoutMode == OnlineCardLayoutMode.Grid)
{
double width = OnlineResultsHost.ActualWidth > 0 ? OnlineResultsHost.ActualWidth - 12 : OnlineLayoutPolicy.PreferredTileWidth;
Expand Down Expand Up @@ -286,7 +286,7 @@ private void AnimateOnlineCardsEntrance()
FrameworkElement resultsElement = GetOnlineResultsElement();
var visual = ElementCompositionPreview.GetElementVisual(resultsElement);
visual.StopAnimation("Opacity");
if (_host.ShouldReduceAnimations)
if (_services.Appearance.ReduceAnimations())
{
visual.Opacity = 1f;
return;
Expand Down Expand Up @@ -469,7 +469,7 @@ private void UpdateOnlineGridCardMetrics(double availableWidth)
private OnlineModTileViewModel CreateOnlineTileModel(OnlineModCard mod)
{
var model = new OnlineModTileViewModel(mod,
openPage: () => _host.RunUiActionAsync("_host.OpenExternalUrlAsync", () => _host.OpenExternalUrlAsync(mod.ProfileUrl, T("Common.OpenPageFailed"))),
openPage: () => _host.RunUiActionAsync("_host.OpenExternalUrlAsync", () => _services.Dialogs.OpenExternalUrlAsync(mod.ProfileUrl, T("Common.OpenPageFailed"))),
download: () => _host.RunUiActionAsync("DownloadAndExtractOnlineModAsync", () => DownloadAndExtractOnlineModAsync(mod)))
{
CharacterLabel = GetOnlineCharacterDisplayName(mod.CharacterName),
Expand Down Expand Up @@ -519,8 +519,8 @@ private async void OnOnlineResultItemClick(object sender, ItemClickEventArgs e)

private void AnimateOnlineModCardHover(Border card, bool isPointerOver)
{
card.Background = _host.GetAppThemeBrush(isPointerOver ? "AppSecondarySelectedBrush" : "AppInsetBackgroundBrush");
if (_host.ShouldReduceAnimations)
card.Background = GetAppThemeBrush(isPointerOver ? "AppSecondarySelectedBrush" : "AppInsetBackgroundBrush");
if (_services.Appearance.ReduceAnimations())
{
return;
}
Expand Down Expand Up @@ -564,8 +564,8 @@ private Border CreateOnlineInstalledIndicator(string installedPath)
var indicator = new Border
{
HorizontalAlignment = HorizontalAlignment.Left,
Background = _host.GetAppThemeBrush("AppAccentSoftBrush"),
BorderBrush = _host.GetAppThemeBrush("AppNavSelectedBorderBrush"),
Background = GetAppThemeBrush("AppAccentSoftBrush"),
BorderBrush = GetAppThemeBrush("AppNavSelectedBorderBrush"),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(4),
Padding = new Thickness(8, 4, 8, 4),
Expand Down
Loading
Loading