Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Copy key/value/names ContextMenu for resource tables #3024

Merged
merged 2 commits into from
Jul 2, 2023
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
10 changes: 10 additions & 0 deletions ILSpy/Controls/ResourceObjectTable.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
Value="{Binding RelativeSource={RelativeSource Self},
Path=(ItemsControl.AlternationIndex),
Converter={StaticResource BackgroundConverter}}" />
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="_Copy" Command="ApplicationCommands.Copy" />
<MenuItem Header="Copy _name" Command="ApplicationCommands.Copy" CommandParameter="Key" InputGestureText=" " />
<MenuItem Header="Copy _value" Command="ApplicationCommands.Copy" CommandParameter="Value" InputGestureText=" " />
<MenuItem Header="Copy _type" Command="ApplicationCommands.Copy" CommandParameter="Type" InputGestureText=" " />
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
Expand Down
21 changes: 21 additions & 0 deletions ILSpy/Controls/ResourceObjectTable.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ void ExecuteCopy(object sender, ExecutedRoutedEventArgs args)
StringBuilder sb = new StringBuilder();
foreach (var item in resourceListView.SelectedItems)
{
if (item is TreeNodes.ResourcesFileTreeNode.SerializedObjectRepresentation so)
{
switch (args.Parameter)
{
case "Key":
sb.AppendLine(so.Key);
continue;

case "Value":
sb.AppendLine(so.Value);
continue;

case "Type":
sb.AppendLine(so.Type);
continue;

default:
sb.AppendLine($"{so.Key}\t{so.Value}\t{so.Type}");
continue;
}
}
sb.AppendLine(item.ToString());
}
Clipboard.SetText(sb.ToString());
Expand Down
9 changes: 9 additions & 0 deletions ILSpy/Controls/ResourceStringTable.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
Value="{Binding RelativeSource={RelativeSource Self},
Path=(ItemsControl.AlternationIndex),
Converter={StaticResource BackgroundConverter}}" />
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="_Copy" Command="ApplicationCommands.Copy" />
<MenuItem Header="Copy _name" Command="ApplicationCommands.Copy" CommandParameter="Key" InputGestureText=" " />
<MenuItem Header="Copy _value" Command="ApplicationCommands.Copy" CommandParameter="Value" InputGestureText=" " />
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
Expand Down
17 changes: 17 additions & 0 deletions ILSpy/Controls/ResourceStringTable.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ void ExecuteCopy(object sender, ExecutedRoutedEventArgs args)
StringBuilder sb = new StringBuilder();
foreach (var item in resourceListView.SelectedItems)
{
if (item is KeyValuePair<string, string> pair)
{
switch (args.Parameter)
{
case "Key":
sb.AppendLine(pair.Key);
continue;

case "Value":
sb.AppendLine(pair.Value);
continue;

default:
sb.AppendLine($"{pair.Key}\t{pair.Value}");
continue;
}
}
sb.AppendLine(item.ToString());
}
Clipboard.SetText(sb.ToString());
Expand Down