mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[Registry Preview] Adds "open Registry Editor at this Key" to the Command Bar (#25554)
* Adds JumpToKey Adds a new command button that allows the Registry Editor to open to whatever key is selected in the TreeView Also adds some separators in the commandbar for logical grouping of opperations. Also had to pick up the ERRORIMAGE constant from another CR so I don't forget to use it! * Correcting typos in comments
This commit is contained in:
1
.github/actions/spell-check/expect.txt
vendored
1
.github/actions/spell-check/expect.txt
vendored
@@ -598,6 +598,7 @@ ERASEBKGND
|
||||
EREOF
|
||||
EResize
|
||||
ERole
|
||||
ERRORIMAGE
|
||||
ERRORLEVEL
|
||||
ERRORTITLE
|
||||
ESettings
|
||||
|
||||
@@ -219,6 +219,26 @@ namespace RegistryPreview
|
||||
OpenRegistryEditor(string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the Registry Editor and tries to set "last used"; UAC is handled by the request to open
|
||||
/// </summary>
|
||||
private void RegistryJumpToKeyButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Get the selected Key, if there is one
|
||||
TreeViewNode currentNode = treeView.SelectedNode;
|
||||
if (currentNode != null)
|
||||
{
|
||||
// since there is a valid node, get the FullPath of the key that was selected
|
||||
string key = ((RegistryKey)currentNode.Content).FullPath;
|
||||
|
||||
// it's impossible to directly open a key via command-line option, so we must override the last remember key
|
||||
Microsoft.Win32.Registry.SetValue(@"HKEY_Current_User\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit", "LastKey", key);
|
||||
}
|
||||
|
||||
// pass in an empty string as we have no file to open
|
||||
OpenRegistryEditor(string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges the currently saved file into the Registry Editor; UAC is handled by the request to open
|
||||
/// </summary>
|
||||
@@ -308,6 +328,9 @@ namespace RegistryPreview
|
||||
treeViewNode = treeView.SelectedNode;
|
||||
}
|
||||
|
||||
// Update the toolbar button for the tree
|
||||
registryJumpToKeyButton.IsEnabled = CheckTreeForValidKey();
|
||||
|
||||
// Grab the object that has Registry data in it from the currently selected treeView node
|
||||
RegistryKey registryKey = (RegistryKey)treeViewNode.Content;
|
||||
|
||||
|
||||
@@ -153,6 +153,9 @@ namespace RegistryPreview
|
||||
}
|
||||
}
|
||||
|
||||
// Update the toolbar button for the trees
|
||||
registryJumpToKeyButton.IsEnabled = CheckTreeForValidKey();
|
||||
|
||||
// enable the UI
|
||||
ChangeCursor(gridPreview, false);
|
||||
}
|
||||
@@ -484,6 +487,9 @@ namespace RegistryPreview
|
||||
refreshButton.IsEnabled = enableRefresh;
|
||||
editButton.IsEnabled = enableEdit;
|
||||
writeButton.IsEnabled = enableWrite;
|
||||
|
||||
// Now check the tree and see if anything is in there
|
||||
registryJumpToKeyButton.IsEnabled = CheckTreeForValidKey();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -899,5 +905,25 @@ namespace RegistryPreview
|
||||
|
||||
registryValue.ToolTipText = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns the Open Key button in the command bar on/off, depending on if a key is selected
|
||||
/// </summary>
|
||||
private bool CheckTreeForValidKey()
|
||||
{
|
||||
if (treeView == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// See if a key is available
|
||||
TreeViewNode treeViewNode = treeView.SelectedNode;
|
||||
if (treeViewNode != null && ((RegistryKey)treeViewNode.Content).Image != ERRORIMAGE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="using:RegistryPreview"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="using:CommunityToolkit.WinUI.UI"
|
||||
xmlns:winuiex="using:WinUIEx"
|
||||
Closed="Window_Closed"
|
||||
mc:Ignorable="d">
|
||||
@@ -73,6 +71,7 @@
|
||||
<KeyboardAccelerator Key="O" Modifiers="Control" />
|
||||
</AppBarButton.KeyboardAccelerators>
|
||||
</AppBarButton>
|
||||
<AppBarSeparator />
|
||||
<AppBarButton
|
||||
x:Name="saveButton"
|
||||
x:Uid="SaveButton"
|
||||
@@ -127,6 +126,7 @@
|
||||
<KeyboardAccelerator Key="F5" />
|
||||
</AppBarButton.KeyboardAccelerators>
|
||||
</AppBarButton>
|
||||
<AppBarSeparator />
|
||||
<AppBarButton
|
||||
x:Name="writeButton"
|
||||
x:Uid="WriteButton"
|
||||
@@ -140,6 +140,7 @@
|
||||
<KeyboardAccelerator Key="W" Modifiers="Control" />
|
||||
</AppBarButton.KeyboardAccelerators>
|
||||
</AppBarButton>
|
||||
<AppBarSeparator />
|
||||
<AppBarButton
|
||||
x:Name="registryButton"
|
||||
x:Uid="RegistryButton"
|
||||
@@ -153,6 +154,20 @@
|
||||
<KeyboardAccelerator Key="R" Modifiers="Control" />
|
||||
</AppBarButton.KeyboardAccelerators>
|
||||
</AppBarButton>
|
||||
<AppBarButton
|
||||
x:Name="registryJumpToKeyButton"
|
||||
x:Uid="RegistryJumpToKeyButton"
|
||||
HorizontalAlignment="Left"
|
||||
Click="RegistryJumpToKeyButton_Click"
|
||||
IsTabStop="False"
|
||||
IsEnabled="True">
|
||||
<AppBarButton.Icon>
|
||||
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph=""/>
|
||||
</AppBarButton.Icon>
|
||||
<AppBarButton.KeyboardAccelerators>
|
||||
<KeyboardAccelerator Key="R" Modifiers="Control,Shift" />
|
||||
</AppBarButton.KeyboardAccelerators>
|
||||
</AppBarButton>
|
||||
</CommandBar>
|
||||
</Grid>
|
||||
<TextBox
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace RegistryPreview
|
||||
private const string APPNAME = "Registry Preview";
|
||||
private const string KEYIMAGE = "ms-appx:///Assets/folder32.png";
|
||||
private const string DELETEDKEYIMAGE = "ms-appx:///Assets/deleted-folder32.png";
|
||||
private const string ERRORIMAGE = "ms-appx:///Assets/error32.png";
|
||||
|
||||
// private members
|
||||
private Microsoft.UI.Windowing.AppWindow appWindow;
|
||||
|
||||
@@ -168,6 +168,9 @@
|
||||
<data name="RegistryButton.Label" xml:space="preserve">
|
||||
<value>Open Registry Editor...</value>
|
||||
</data>
|
||||
<data name="RegistryJumpToKeyButton.Label" xml:space="preserve">
|
||||
<value>Open Key...</value>
|
||||
</data>
|
||||
<data name="SaveAsButton.Label" xml:space="preserve">
|
||||
<value>Save file as...</value>
|
||||
</data>
|
||||
|
||||
Reference in New Issue
Block a user