Skip to content

Commit

Permalink
Copy key/value/names ContextMenu for resource tables
Browse files Browse the repository at this point in the history
  • Loading branch information
miloush committed Jun 24, 2023
1 parent ccab6f4 commit f267c43
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
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" />
<MenuItem Header="Copy _value" Command="ApplicationCommands.Copy" CommandParameter="Value" />
<MenuItem Header="Copy _type" Command="ApplicationCommands.Copy" CommandParameter="Type" />
</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" />
<MenuItem Header="Copy _value" Command="ApplicationCommands.Copy" CommandParameter="Value" />
</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

0 comments on commit f267c43

Please # to comment.