fix(app): shell follows RTL from startup; welcome keeps the keyboard; accessible dialogs and errors
- The rail grows with the longest label (128-200 px); the first-run dialog disables the shell behind it and focuses its chosen option; toasts stay above it; F6 reaches the newest toast. - Confirm and login dialogs are named by their heading, focus the safe button, announce sign-in errors. - Error toasts say what happened only for catalog sentences (ErrorText); other details stay in the log. - Window title, queued-jobs text (plural) and the pause button name come from resources. - Logs, paths and templates in the client styles stay left to right. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
12 files changed
+150
-53
No files matched your search
@@ -6,7 +6,10 @@
|
||||
<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
|
||||
<data name="Shell.AppName" xml:space="preserve"><value>Titano</value><comment>invariant</comment></data>
|
||||
<data name="Shell.JobBar.Idle" xml:space="preserve"><value>Ready</value></data>
|
||||
<data name="Shell.JobBar.Pause" xml:space="preserve"><value>Pause job</value></data>
|
||||
<data name="Shell.JobBar.Ready" xml:space="preserve"><value>Ready · {0} jobs queued</value></data>
|
||||
<data name="Shell.JobBar.Ready.one" xml:space="preserve"><value>Ready · {0} job queued</value><comment>{0} count</comment></data>
|
||||
<data name="Shell.JobBar.Ready.other" xml:space="preserve"><value>Ready · {0} jobs queued</value><comment>{0} count</comment></data>
|
||||
<data name="Shell.Nav.About" xml:space="preserve"><value>About</value></data>
|
||||
<data name="Shell.Nav.Archive" xml:space="preserve"><value>Archive</value></data>
|
||||
<data name="Shell.Nav.Import" xml:space="preserve"><value>Import</value></data>
|
||||
@@ -37,4 +40,5 @@
|
||||
<data name="Shell.Welcome.Server" xml:space="preserve"><value>Connect to a server</value></data>
|
||||
<data name="Shell.Welcome.Server.Found" xml:space="preserve"><value>{0} on this network · {1}</value></data>
|
||||
<data name="Shell.Welcome.Title" xml:space="preserve"><value>Welcome to Titano</value></data>
|
||||
<data name="Shell.WindowTitle" xml:space="preserve"><value>{0} — {1}</value><comment>{0} program name; {1} screen title</comment></data>
|
||||
</root>
|
||||
@@ -5,7 +5,10 @@
|
||||
<resheader name="reader"><value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
|
||||
<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
|
||||
<data name="Shell.JobBar.Idle" xml:space="preserve"><value>Pronto</value></data>
|
||||
<data name="Shell.JobBar.Pause" xml:space="preserve"><value>Pausa attività</value></data>
|
||||
<data name="Shell.JobBar.Ready" xml:space="preserve"><value>Pronto · {0} attività in coda</value></data>
|
||||
<data name="Shell.JobBar.Ready.one" xml:space="preserve"><value>Pronto · {0} attività in coda</value></data>
|
||||
<data name="Shell.JobBar.Ready.other" xml:space="preserve"><value>Pronto · {0} attività in coda</value></data>
|
||||
<data name="Shell.Nav.About" xml:space="preserve"><value>Informazioni</value></data>
|
||||
<data name="Shell.Nav.Archive" xml:space="preserve"><value>Archivio</value></data>
|
||||
<data name="Shell.Nav.Import" xml:space="preserve"><value>Importa</value></data>
|
||||
@@ -36,4 +39,5 @@
|
||||
<data name="Shell.Welcome.Server" xml:space="preserve"><value>Connettiti a un server</value></data>
|
||||
<data name="Shell.Welcome.Server.Found" xml:space="preserve"><value>{0} in questa rete · {1}</value></data>
|
||||
<data name="Shell.Welcome.Title" xml:space="preserve"><value>Benvenuto in Titano</value></data>
|
||||
<data name="Shell.WindowTitle" xml:space="preserve"><value>{0} — {1}</value></data>
|
||||
</root>
|
||||
@@ -1,10 +1,13 @@
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using Titano.Core.Localization;
|
||||
|
||||
namespace Titano.App.Infrastructure;
|
||||
|
||||
/// <summary>Switches the UI language at run time without restart (BRIEF §16), mirroring right-to-left languages.</summary>
|
||||
/// <summary>
|
||||
/// Switches the UI language at run time without restart (BRIEF §16). A <see cref="Ui.Controls.TitanoWindow"/> takes
|
||||
/// the language's direction when it is created and follows each switch, so right-to-left languages mirror windows
|
||||
/// opened before and after this call alike.
|
||||
/// </summary>
|
||||
public static class UiLanguage
|
||||
{
|
||||
/// <summary>Applies <paramref name="code"/> (or the OS language when null) and returns the culture in use.</summary>
|
||||
@@ -23,11 +26,6 @@ public static class UiLanguage
|
||||
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
||||
CultureInfo.CurrentUICulture = culture;
|
||||
Loc.SetCulture(culture);
|
||||
if (Application.Current is { } app)
|
||||
{
|
||||
foreach (Window window in app.Windows)
|
||||
window.FlowDirection = Loc.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
|
||||
}
|
||||
return culture;
|
||||
}
|
||||
}
|
||||
@@ -43,8 +43,9 @@
|
||||
<Setter Property="TextAlignment" Value="Right" />
|
||||
</Style>
|
||||
|
||||
<!-- Log tail: monospaced, muted. -->
|
||||
<!-- Log tail: monospaced, muted, left to right in every language (paths, times, codes). -->
|
||||
<Style x:Key="Text.Log" TargetType="TextBlock">
|
||||
<Setter Property="FlowDirection" Value="LeftToRight" />
|
||||
<Setter Property="FontFamily" Value="{StaticResource Font.Mono}" />
|
||||
<Setter Property="FontSize" Value="12" />
|
||||
<Setter Property="LineHeight" Value="18" />
|
||||
@@ -89,7 +90,7 @@
|
||||
|
||||
<!-- Section list entry of Settings: 34 px, active = Card fill + 3 px accent edge (Settings.html). -->
|
||||
<Style x:Key="ListBoxItem.Section" TargetType="ListBoxItem">
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
|
||||
<Setter Property="FocusVisualStyle" Value="{StaticResource Focus.Inset}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextMuted}" />
|
||||
<Setter Property="Height" Value="34" />
|
||||
<Setter Property="Margin" Value="0,0,0,2" />
|
||||
@@ -145,21 +146,6 @@
|
||||
<Setter Property="Margin" Value="0,0,6,0" />
|
||||
</Style>
|
||||
|
||||
<!-- "Auto · 8" pill (DESIGN §4 Auto/manual): accent outline, 24 px, 11 px text. -->
|
||||
<Style x:Key="Button.AutoPill" TargetType="Button" BasedOn="{StaticResource Button.Base}">
|
||||
<Setter Property="Height" Value="24" />
|
||||
<Setter Property="MinWidth" Value="0" />
|
||||
<Setter Property="Padding" Value="8,0" />
|
||||
<Setter Property="FontSize" Value="11" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource Brush.Accent}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Accent}" />
|
||||
<Setter Property="ui:ControlState.CornerRadius" Value="12" />
|
||||
<Setter Property="ui:ControlState.HoverBackground" Value="{DynamicResource Brush.AccentSubtle}" />
|
||||
<Setter Property="ui:ControlState.HoverBorderBrush" Value="{DynamicResource Brush.Accent}" />
|
||||
<Setter Property="ui:ControlState.PressedBackground" Value="{DynamicResource Brush.AccentSubtle}" />
|
||||
</Style>
|
||||
|
||||
<!-- Toolbar dropdown (Library filters): accent border while a filter is active (bind Tag to the active flag). -->
|
||||
<Style x:Key="ComboBox.Filter" TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="MinWidth" Value="88" />
|
||||
@@ -213,8 +199,8 @@
|
||||
<Setter Property="VerticalContentAlignment" Value="Top" />
|
||||
</Style>
|
||||
|
||||
<!-- Path and template fields in Settings (360 px, DESIGN mockup). -->
|
||||
<Style x:Key="TextBox.Setting" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
|
||||
<!-- Path, address and template fields in Settings (360 px, DESIGN mockup), left to right in every language. -->
|
||||
<Style x:Key="TextBox.Setting" TargetType="TextBox" BasedOn="{StaticResource TextBox.Path}">
|
||||
<Setter Property="Width" Value="360" />
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
</Style>
|
||||
|
||||
@@ -5,14 +5,17 @@
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui"
|
||||
Title="{l:Loc Shell.AppName}"
|
||||
IsDialog="True" ResizeMode="NoResize" SizeToContent="Height" Width="460"
|
||||
WindowStartupLocation="CenterOwner" ShowInTaskbar="False">
|
||||
<!-- DESIGN §4 dialog: two buttons, safe action left and default, the action on the right. -->
|
||||
WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
|
||||
AutomationProperties.Name="{Binding Heading}" AutomationProperties.HelpText="{Binding Message}">
|
||||
<!-- DESIGN §4 dialog: two buttons, safe action left and default, the action on the right. Screen readers hear the
|
||||
heading and the message as the dialog opens on the safe button. -->
|
||||
<StackPanel Margin="24,18,24,20">
|
||||
<TextBlock Text="{Binding Heading}" Style="{StaticResource Text.Title}" TextWrapping="Wrap" TextTrimming="None" />
|
||||
<TextBlock Text="{Binding Message}" Margin="0,8,0,0" Foreground="{DynamicResource Brush.TextMuted}" TextWrapping="Wrap" TextTrimming="None" LineHeight="18" />
|
||||
<Border Style="{StaticResource Border.Card}" Margin="0,16,0,0" Padding="12,10" ToolTip="{Binding DetailToolTip}"
|
||||
Visibility="{Binding Detail, Converter={x:Static ui:NullToCollapsedConverter.Instance}}">
|
||||
<TextBlock Text="{Binding Detail}" FontFamily="{StaticResource Font.Mono}" FontSize="{StaticResource Size.Secondary}" TextWrapping="Wrap" TextTrimming="None" LineHeight="18" />
|
||||
<TextBlock Text="{Binding Detail}" FontFamily="{StaticResource Font.Mono}" FontSize="{StaticResource Size.Secondary}" TextWrapping="Wrap" TextTrimming="None" LineHeight="18"
|
||||
FlowDirection="LeftToRight" />
|
||||
</Border>
|
||||
<StackPanel x:Name="Typing" Margin="0,16,0,0" Visibility="Collapsed">
|
||||
<TextBlock Text="{Binding TypedPrompt}" Foreground="{DynamicResource Brush.TextMuted}" TextWrapping="Wrap" />
|
||||
@@ -20,7 +23,7 @@
|
||||
AutomationProperties.Name="{Binding TypedPrompt}" TextChanged="OnTyped" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,24,0,0">
|
||||
<Button Content="{Binding SafeText}" ToolTip="{Binding SafeToolTip}" IsDefault="True" IsCancel="True" MinWidth="96" Click="OnSafe" />
|
||||
<Button x:Name="Safe" Content="{Binding SafeText}" ToolTip="{Binding SafeToolTip}" IsDefault="True" IsCancel="True" MinWidth="96" Click="OnSafe" />
|
||||
<Button x:Name="Action" Content="{Binding ActionText}" ToolTip="{Binding ActionToolTip}" MinWidth="96" Margin="8,0,0,0" Click="OnAction" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -12,7 +12,11 @@ public sealed partial class ConfirmDialog : TitanoWindow
|
||||
DataContext = request;
|
||||
InitializeComponent();
|
||||
Action.SetResourceReference(StyleProperty, request.IsDestructive ? "Button.Destructive" : "Button.Primary");
|
||||
if (request.TypedConfirmation is null) return;
|
||||
if (request.TypedConfirmation is null)
|
||||
{
|
||||
Loaded += (_, _) => Safe.Focus();
|
||||
return;
|
||||
}
|
||||
Typing.Visibility = Visibility.Visible;
|
||||
Loaded += (_, _) => Typed.Focus();
|
||||
EnableAction(false);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Reflection;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Render;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Data.Sync;
|
||||
using Titano.Protocol.Client;
|
||||
|
||||
namespace Titano.App.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// The sentence an error toast shows (BRIEF §0.2: one sentence saying what happened plus one action). Only failures
|
||||
/// that carry a catalog sentence say what happened; anything else (framework and OS messages, often technical
|
||||
/// English) reads "Something went wrong." and stays in the log.
|
||||
/// </summary>
|
||||
public static class ErrorText
|
||||
{
|
||||
public static string For(Exception ex) => Describe(Unwrap(ex)) ?? Loc.L("Errors.Unexpected");
|
||||
|
||||
private static string? Describe(Exception ex) => ex switch
|
||||
{
|
||||
LeaseUnavailableException or ArchiveOfflineException or NewerFormatException or ImportSourceUnavailableException
|
||||
or CopyVerificationException or StaleRenamePlanException or SyncConflictChangedException => ex.Message,
|
||||
// The server words its errors in the client's language (Accept-Language).
|
||||
TitanoApiException api when !string.IsNullOrWhiteSpace(api.Error.Message) => api.Error.Message,
|
||||
RenderException render => Loc.Get(render.ReasonKey, Loc.Culture) is null ? null : Loc.L(render.ReasonKey, [.. render.Args]),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
/// <summary>Awaited tasks and reflection wrap the real failure in one layer or more.</summary>
|
||||
private static Exception Unwrap(Exception ex)
|
||||
{
|
||||
while (ex is AggregateException { InnerExceptions.Count: 1 } or TargetInvocationException && ex.InnerException is { } inner) ex = inner;
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,11 @@
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui"
|
||||
Title="{l:Loc Shell.AppName}"
|
||||
IsDialog="True" ResizeMode="NoResize" SizeToContent="Height" Width="440"
|
||||
WindowStartupLocation="CenterOwner" ShowInTaskbar="False">
|
||||
WindowStartupLocation="CenterOwner" ShowInTaskbar="False" AutomationProperties.Name="{l:Loc Server.Login.Title}">
|
||||
<!-- BRIEF §12.7 login modal: the server is already identified and its certificate trusted. -->
|
||||
<StackPanel Margin="24,18,24,20">
|
||||
<TextBlock Text="{l:Loc Server.Login.Title}" Style="{StaticResource Text.Title}" />
|
||||
<TextBlock x:Name="ServerText" Margin="0,4,0,0" Style="{StaticResource Text.Secondary}" />
|
||||
<TextBlock x:Name="ServerText" Margin="0,4,0,0" Style="{StaticResource Text.Secondary}" FlowDirection="LeftToRight" HorizontalAlignment="Left" />
|
||||
<Grid Margin="0,18,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" MinWidth="92" />
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Automation.Peers;
|
||||
using Titano.Ui.Controls;
|
||||
|
||||
namespace Titano.App.Shell;
|
||||
@@ -6,7 +8,7 @@ namespace Titano.App.Shell;
|
||||
/// <summary>
|
||||
/// The login form (BRIEF §12.7). It calls back the connection with the credentials and stays open with the
|
||||
/// error sentence until the sign-in succeeds or the user cancels. The password never leaves the PasswordBox
|
||||
/// except for that call.
|
||||
/// except for that call. A failed sign-in is announced to screen readers and stays as the password box's help text.
|
||||
/// </summary>
|
||||
public sealed partial class LoginDialog : TitanoWindow
|
||||
{
|
||||
@@ -40,6 +42,7 @@ public sealed partial class LoginDialog : TitanoWindow
|
||||
{
|
||||
SignIn.IsEnabled = false;
|
||||
Error.Visibility = Visibility.Collapsed;
|
||||
AutomationProperties.SetHelpText(Password, string.Empty);
|
||||
try
|
||||
{
|
||||
var error = await _signIn(User.Text, Password.Password);
|
||||
@@ -50,8 +53,11 @@ public sealed partial class LoginDialog : TitanoWindow
|
||||
}
|
||||
Error.Text = error;
|
||||
Error.Visibility = Visibility.Visible;
|
||||
AutomationProperties.SetHelpText(Password, error);
|
||||
Password.Clear();
|
||||
Password.Focus();
|
||||
UIElementAutomationPeer.CreatePeerForElement(this)?.RaiseNotificationEvent(
|
||||
AutomationNotificationKind.ActionCompleted, AutomationNotificationProcessing.ImportantMostRecent, error, "Titano.SignIn");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -14,8 +14,23 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Navigation rail: full names, collapsible to icons (BRIEF §12.1). -->
|
||||
<Border x:Name="Rail" Background="{DynamicResource Brush.Chrome}" Width="128" ui:NavRail.IsCollapsed="{Binding IsRailCollapsed}">
|
||||
<!-- Navigation rail: full names, collapsible to icons (BRIEF §12.1). Expanded it is at least 128 px and grows with
|
||||
the longest label of the language (up to 200 px); collapsed it is 48 px of icons. While the first-run dialog is
|
||||
open the shell behind it takes no input. -->
|
||||
<Border x:Name="Rail" Background="{DynamicResource Brush.Chrome}" ui:NavRail.IsCollapsed="{Binding IsRailCollapsed}"
|
||||
IsEnabled="{Binding IsShellEnabled}">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="MinWidth" Value="128" />
|
||||
<Setter Property="MaxWidth" Value="200" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsRailCollapsed}" Value="True">
|
||||
<Setter Property="MinWidth" Value="0" />
|
||||
<Setter Property="Width" Value="48" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
<DockPanel Margin="8,8,8,8" LastChildFill="False">
|
||||
<Button DockPanel.Dock="Top" Style="{StaticResource Button.IconSubtle}" HorizontalAlignment="Left" Margin="0,0,0,6"
|
||||
ui:ButtonIcon.Glyph="{StaticResource Icon.Menu}" Command="{Binding ToggleRailCommand}"
|
||||
@@ -41,7 +56,7 @@
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<Grid Grid.Column="1">
|
||||
<Grid Grid.Column="1" IsEnabled="{Binding IsShellEnabled}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
@@ -50,7 +65,7 @@
|
||||
|
||||
<!-- Job bar (DESIGN §4): current job, progress, time left, pause; "Ready" when idle, hidden when idle in the editor. -->
|
||||
<ui:JobBar Text="{Binding JobText}" Progress="{Binding JobProgress}" IsActive="{Binding IsJobActive}" IsIndeterminate="{Binding IsJobIndeterminate}"
|
||||
StopCommand="{Binding StopJobCommand}" StopToolTip="{l:Loc Tooltips.Shell.PauseJob}" ActionGlyph="{StaticResource Icon.Pause}"
|
||||
StopCommand="{Binding StopJobCommand}" StopToolTip="{l:Loc Tooltips.Shell.PauseJob}" StopName="{l:Loc Shell.JobBar.Pause}" ActionGlyph="{StaticResource Icon.Pause}"
|
||||
Visibility="{Binding IsJobBarVisible, Converter={StaticResource BoolToVisibility}}" />
|
||||
|
||||
<ContentControl Grid.Row="1" Content="{Binding Current}" Focusable="False" />
|
||||
@@ -65,14 +80,17 @@
|
||||
<TextBlock Text="{Binding JobsText}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<ui:ToastHost x:Name="Toasts" Grid.Row="0" Grid.RowSpan="3" />
|
||||
</Grid>
|
||||
|
||||
<!-- First run (Welcome.html): the shell dimmed behind one dialog. -->
|
||||
<Grid Grid.ColumnSpan="2" Visibility="{Binding IsWelcomeOpen, Converter={StaticResource BoolToVisibility}}">
|
||||
<!-- First run (Welcome.html): the shell dimmed behind one dialog that keeps the keyboard. -->
|
||||
<Grid x:Name="WelcomeOverlay" Grid.ColumnSpan="2" Visibility="{Binding IsWelcomeOpen, Converter={StaticResource BoolToVisibility}}"
|
||||
KeyboardNavigation.TabNavigation="Cycle" KeyboardNavigation.ControlTabNavigation="Cycle" KeyboardNavigation.DirectionalNavigation="Contained">
|
||||
<Border Background="{DynamicResource Brush.Scrim}" />
|
||||
<s:WelcomeView DataContext="{Binding Welcome}" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,114,0,0" />
|
||||
<s:WelcomeView DataContext="{Binding Welcome}" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,114,0,0"
|
||||
AutomationProperties.Name="{l:Loc Shell.Welcome.Title}" />
|
||||
</Grid>
|
||||
|
||||
<!-- Above the first-run dialog too, so a card inserted meanwhile can still be acted on (Welcome.html). -->
|
||||
<ui:ToastHost x:Name="Toasts" Grid.ColumnSpan="2" />
|
||||
</Grid>
|
||||
</ui:TitanoWindow>
|
||||
@@ -1,5 +1,9 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.Ui.Controls;
|
||||
|
||||
@@ -14,21 +18,50 @@ public partial class MainWindow : TitanoWindow
|
||||
_shell = shell;
|
||||
DataContext = shell;
|
||||
InitializeComponent();
|
||||
Rail.Width = shell.IsRailCollapsed ? 48 : 128;
|
||||
UpdateConnection();
|
||||
shell.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName is nameof(ShellViewModel.IsRailCollapsed) or "")
|
||||
Rail.Width = shell.IsRailCollapsed ? 48 : 128;
|
||||
if (e.PropertyName is nameof(ShellViewModel.IsConnected) or "") UpdateConnection();
|
||||
if (e.PropertyName is nameof(ShellViewModel.IsWelcomeOpen) or "") FocusWelcome();
|
||||
};
|
||||
shell.PendingToasts.CollectionChanged += OnToastRequested;
|
||||
Loaded += (_, _) => FocusWelcome();
|
||||
RestorePlacement();
|
||||
Closing += (_, _) => SavePlacement();
|
||||
}
|
||||
|
||||
/// <summary>F6 moves the keyboard to the newest notification (as in Windows apps), Esc there dismisses it.</summary>
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
if (!e.Handled && e.Key == Key.F6 && Keyboard.Modifiers == ModifierKeys.None) e.Handled = Toasts.FocusNewest();
|
||||
}
|
||||
|
||||
private void UpdateConnection() =>
|
||||
Connection.SetResourceReference(System.Windows.Controls.TextBlock.ForegroundProperty, _shell.IsConnected ? "Brush.Accent" : "Brush.TextMuted");
|
||||
Connection.SetResourceReference(TextBlock.ForegroundProperty, _shell.IsConnected ? "Brush.Accent" : "Brush.TextMuted");
|
||||
|
||||
/// <summary>The first-run dialog takes the keyboard on its chosen option once it is on screen.</summary>
|
||||
private void FocusWelcome()
|
||||
{
|
||||
if (!_shell.IsWelcomeOpen) return;
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, () =>
|
||||
{
|
||||
if (!_shell.IsWelcomeOpen || !IsLoaded) return;
|
||||
if (FindChecked(WelcomeOverlay) is { } choice) choice.Focus();
|
||||
else WelcomeOverlay.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
|
||||
});
|
||||
}
|
||||
|
||||
private static RadioButton? FindChecked(DependencyObject root)
|
||||
{
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(root, i);
|
||||
if (child is RadioButton { IsChecked: true } radio) return radio;
|
||||
if (FindChecked(child) is { } nested) return nested;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void OnToastRequested(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
|
||||
@@ -85,12 +85,17 @@ public sealed class ShellViewModel : LocalizedViewModel
|
||||
get => _welcome;
|
||||
private set
|
||||
{
|
||||
if (Set(ref _welcome, value)) OnPropertyChanged(nameof(IsWelcomeOpen));
|
||||
if (!Set(ref _welcome, value)) return;
|
||||
OnPropertyChanged(nameof(IsWelcomeOpen));
|
||||
OnPropertyChanged(nameof(IsShellEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsWelcomeOpen => _welcome is not null;
|
||||
|
||||
/// <summary>The rail and the sections take input only while no first-run dialog covers them.</summary>
|
||||
public bool IsShellEnabled => _welcome is null;
|
||||
|
||||
public SectionViewModel Current
|
||||
{
|
||||
get => _current;
|
||||
@@ -105,7 +110,7 @@ public sealed class ShellViewModel : LocalizedViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public string WindowTitle => Current == Library ? "Titano" : "Titano — " + Current.Title;
|
||||
public string WindowTitle => Current == Library ? Loc.L("Shell.AppName") : Loc.L("Shell.WindowTitle", Loc.L("Shell.AppName"), Current.Title);
|
||||
|
||||
public bool IsRailCollapsed
|
||||
{
|
||||
@@ -160,7 +165,7 @@ public sealed class ShellViewModel : LocalizedViewModel
|
||||
// ---- Job bar ----
|
||||
public string JobText => _jobActive && _jobText is not null
|
||||
? _jobText
|
||||
: _queuedCount > 0 ? Loc.L("Shell.JobBar.Ready", _queuedCount) : Loc.L("Shell.JobBar.Idle");
|
||||
: _queuedCount > 0 ? Loc.Plural("Shell.JobBar.Ready", _queuedCount) : Loc.L("Shell.JobBar.Idle");
|
||||
|
||||
public double JobProgress { get => _jobProgress; private set => Set(ref _jobProgress, value); }
|
||||
public bool IsJobActive
|
||||
@@ -250,14 +255,13 @@ public sealed class ShellViewModel : LocalizedViewModel
|
||||
ActionCommand = action is null ? null : new RelayCommand(action),
|
||||
});
|
||||
|
||||
/// <summary>Errors are one sentence saying what happened plus one action (BRIEF §0.2 rule 6).</summary>
|
||||
/// <summary>Errors are one sentence saying what happened plus one action (BRIEF §0.2 rule 6); the details go to the log.</summary>
|
||||
public void ReportError(Exception ex)
|
||||
{
|
||||
Log.Error("ui", "Operation failed", ex);
|
||||
ShowToast(new Toast
|
||||
{
|
||||
Title = Loc.L("Errors.Unexpected"),
|
||||
Message = ex.Message,
|
||||
Title = ErrorText.For(ex),
|
||||
ActionText = Loc.L("Common.OpenLogs"),
|
||||
ActionToolTip = Loc.L("Tooltips.Common.OpenLogs"),
|
||||
ActionCommand = new RelayCommand(() => ShellActions.Reveal(Services.Environment.LogDirectory)),
|
||||
|
||||
Reference in new issue
Block a user