Skip to content

Commit

Permalink
[Settings][AdvPaste]Check clibboard history gpo (#32977)
Browse files Browse the repository at this point in the history
* [Settings][AdvPaste]Check clibboard history gpo

* Fix XAML style

* GPO Infobar below
  • Loading branch information
jaimecbernardo committed May 23, 2024
1 parent 8fce41d commit 59f9785
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,18 @@
</controls:SettingsGroup>

<controls:SettingsGroup x:Uid="AdvancedPaste_ClipboardHistorySettingsGroup" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
<tkcontrols:SettingsCard x:Uid="AdvancedPaste_Clipboard_History_Enabled_SettingsCard" HeaderIcon="{ui:FontIcon Glyph=&#xF0E3;}">
<tkcontrols:SettingsCard
x:Uid="AdvancedPaste_Clipboard_History_Enabled_SettingsCard"
HeaderIcon="{ui:FontIcon Glyph=&#xF0E3;}"
IsEnabled="{x:Bind ViewModel.ClipboardHistoryDisabledByGPO, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}">
<ToggleSwitch IsOn="{x:Bind ViewModel.ClipboardHistoryEnabled, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<InfoBar
x:Uid="GPO_SettingIsManaged"
IsClosable="False"
IsOpen="{x:Bind ViewModel.ClipboardHistoryDisabledByGPO, Mode=OneWay}"
IsTabStop="{x:Bind ViewModel.ClipboardHistoryDisabledByGPO, Mode=OneWay}"
Severity="Informational" />
</controls:SettingsGroup>

<controls:SettingsGroup x:Uid="AdvancedPaste_Direct_Access_Hotkeys_GroupSettings" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
Expand Down
26 changes: 26 additions & 0 deletions src/settings-ui/Settings.UI/ViewModels/AdvancedPasteViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ private bool IsClipboardHistoryEnabled()
}
}

private bool IsClipboardHistoryDisabledByGPO()
{
string registryKey = @"HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\System\";
try
{
object allowClipboardHistory = Registry.GetValue(registryKey, "AllowClipboardHistory", null);
if (allowClipboardHistory != null)
{
return (int)allowClipboardHistory == 0;
}
else
{
return false;
}
}
catch (Exception)
{
return false;
}
}

private void SetClipboardHistoryEnabled(bool value)
{
string registryKey = @"HKEY_CURRENT_USER\Software\Microsoft\Clipboard\";
Expand All @@ -169,6 +190,11 @@ public bool ClipboardHistoryEnabled
}
}

public bool ClipboardHistoryDisabledByGPO
{
get => IsClipboardHistoryDisabledByGPO();
}

public HotkeySettings AdvancedPasteUIShortcut
{
get => _advancedPasteSettings.Properties.AdvancedPasteUIShortcut;
Expand Down

0 comments on commit 59f9785

Please sign in to comment.