Skip to content
Open
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
33 changes: 32 additions & 1 deletion src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public sealed partial class FilePreview : UserControl, IDisposable
typeof(FilePreview),
new PropertyMetadata(false, async (d, e) => await ((FilePreview)d).OnScalingFactorPropertyChanged()));

public static readonly DependencyProperty ShowFilePreviewTooltipProperty =
DependencyProperty.Register(
nameof(ShowFilePreviewTooltip),
typeof(bool),
typeof(FilePreview),
new PropertyMetadata(true, (d, e) => ((FilePreview)d).OnShowFilePreviewTooltipChanged()));

[ObservableProperty]
private int numberOfFiles;

Expand All @@ -64,7 +71,7 @@ public sealed partial class FilePreview : UserControl, IDisposable
private IPreviewer? previewer;

[ObservableProperty]
private string infoTooltip = ResourceLoaderInstance.ResourceLoader.GetString("PreviewTooltip_Blank");
private string? infoTooltip = ResourceLoaderInstance.ResourceLoader.GetString("PreviewTooltip_Blank");

[ObservableProperty]
private string noMoreFilesText = ResourceLoaderInstance.ResourceLoader.GetString("NoMoreFiles");
Expand Down Expand Up @@ -139,6 +146,24 @@ public double ScalingFactor
}
}

public bool ShowFilePreviewTooltip
{
get => (bool)GetValue(ShowFilePreviewTooltipProperty);
set => SetValue(ShowFilePreviewTooltipProperty, value);
}

private void OnShowFilePreviewTooltipChanged()
{
if (!ShowFilePreviewTooltip)
{
InfoTooltip = null;
}
else if (Item != null)
{
_ = UpdateTooltipAsync(_cancellationTokenSource.Token);
}
}

public bool MatchPreviewState(PreviewState? value, PreviewState stateToMatch)
{
return value == stateToMatch;
Expand Down Expand Up @@ -366,6 +391,12 @@ private void KeyboardAccelerator_Space_Invoked(KeyboardAccelerator sender, Keybo

private async Task UpdateTooltipAsync(CancellationToken cancellationToken)
{
if (!ShowFilePreviewTooltip)
{
InfoTooltip = null;
return;
}

if (Item == null)
{
return;
Expand Down
1 change: 1 addition & 0 deletions src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
NumberOfFiles="{x:Bind ViewModel.DisplayItemCount, Mode=OneWay}" />

<fp:FilePreview
x:Name="FilePreviewer"
Grid.Row="1"
Item="{x:Bind ViewModel.CurrentItem, Mode=OneWay}"
NumberOfFiles="{x:Bind ViewModel.DisplayItemCount, Mode=OneWay}"
Expand Down
2 changes: 2 additions & 0 deletions src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ private void Initialize(SelectedItem selectedItem)
var bootTime = new System.Diagnostics.Stopwatch();
bootTime.Start();

FilePreviewer.ShowFilePreviewTooltip = Application.Current.GetService<IUserSettings>().ShowFilePreviewTooltip;

ViewModel.Initialize(selectedItem);

// If no files were found (e.g., user is typing in rename/search box, or in virtual folders),
Expand Down
2 changes: 2 additions & 0 deletions src/modules/peek/Peek.UI/Services/IUserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public interface IUserSettings
public bool CloseAfterLosingFocus { get; }

public bool ConfirmFileDelete { get; set; }

public bool ShowFilePreviewTooltip { get; }
}
}
8 changes: 7 additions & 1 deletion src/modules/peek/Peek.UI/Services/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private PeekSettings Settings
_settings = value;
CloseAfterLosingFocus = _settings.Properties.CloseAfterLosingFocus.Value;
ConfirmFileDelete = _settings.Properties.ConfirmFileDelete.Value;
ShowFilePreviewTooltip = _settings.Properties.ShowFilePreviewTooltip.Value;
}
}
}
Expand All @@ -63,7 +64,7 @@ public bool ConfirmFileDelete
{
_confirmFileDelete = value;

// We write directly to the settings file. The Settings UI will pick detect
// We write directly to the settings file. The Settings UI will detect
// this change via its file watcher and update accordingly. This is the only
// setting that is modified by Peek itself.
lock (_settingsLock)
Expand All @@ -75,6 +76,11 @@ public bool ConfirmFileDelete
}
}

/// <summary>
/// Gets a value indicating whether the file metadata tooltip is shown when hovering over the Peek preview.
/// </summary>
public bool ShowFilePreviewTooltip { get; private set; }

public UserSettings()
{
_settingsUtils = SettingsUtils.Default;
Expand Down
3 changes: 3 additions & 0 deletions src/settings-ui/Settings.UI.Library/PeekProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public PeekProperties()
CloseAfterLosingFocus = new BoolProperty(false);
ConfirmFileDelete = new BoolProperty(true);
EnableSpaceToActivate = new BoolProperty(true); // Toggle is ON by default for new users. No impact on existing users.
ShowFilePreviewTooltip = new BoolProperty(true);
}

public HotkeySettings ActivationShortcut { get; set; }
Expand All @@ -32,6 +33,8 @@ public PeekProperties()

public BoolProperty EnableSpaceToActivate { get; set; }

public BoolProperty ShowFilePreviewTooltip { get; set; }

public override string ToString() => JsonSerializer.Serialize(this, SettingsSerializationContext.Default.PeekProperties);
}
}
6 changes: 6 additions & 0 deletions src/settings-ui/Settings.UI/SettingsXAML/Views/PeekPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
HeaderIcon="{ui:FontIcon Glyph=&#xE7BA;}">
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.ConfirmFileDelete, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard
Name="PeekShowFilePreviewTooltip"
x:Uid="Peek_ShowFilePreviewTooltip"
HeaderIcon="{ui:FontIcon Glyph=&#xE171;}">
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.ShowFilePreviewTooltip, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
</controls:SettingsGroup>

<controls:SettingsGroup x:Uid="Peek_Preview_GroupSettings" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
Expand Down
6 changes: 6 additions & 0 deletions src/settings-ui/Settings.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3131,6 +3131,12 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
<data name="Peek_ConfirmFileDelete.Description" xml:space="preserve">
<value>You'll be asked to confirm before files are moved to the Recycle Bin</value>
</data>
<data name="Peek_ShowFilePreviewTooltip.Header" xml:space="preserve">
<value>Show file preview tooltip</value>
</data>
<data name="Peek_ShowFilePreviewTooltip.Description" xml:space="preserve">
<value>Show file information as a tooltip when hovering over the preview</value>
</data>
<data name="Peek_ActivationMethod.Header" xml:space="preserve">
<value>Activation method</value>
</data>
Expand Down
14 changes: 14 additions & 0 deletions src/settings-ui/Settings.UI/ViewModels/PeekViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,20 @@ public bool EnableSpaceToActivate
}
}

public bool ShowFilePreviewTooltip
{
get => _peekSettings.Properties.ShowFilePreviewTooltip.Value;
set
{
if (_peekSettings.Properties.ShowFilePreviewTooltip.Value != value)
{
_peekSettings.Properties.ShowFilePreviewTooltip.Value = value;
OnPropertyChanged(nameof(ShowFilePreviewTooltip));
NotifySettingsChanged();
}
}
}

public bool SourceCodeWrapText
{
get => _peekPreviewSettings.SourceCodeWrapText.Value;
Expand Down