You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.5 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. // Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.Collections;
  20. using System.Collections.Generic;
  21. using System.ComponentModel;
  22. using System.Text;
  23. using System.Windows;
  24. using System.Windows.Controls;
  25. using System.Windows.Data;
  26. using System.Windows.Input;
  27. namespace ICSharpCode.ILSpy.Controls
  28. {
  29. /// <summary>
  30. /// Interaction logic for ResourceStringTable.xaml
  31. /// </summary>
  32. public partial class ResourceStringTable : UserControl
  33. {
  34. ICollectionView filteredView;
  35. string filter;
  36. public ResourceStringTable(IEnumerable strings, FrameworkElement container)
  37. {
  38. InitializeComponent();
  39. // set size to fit decompiler window
  40. container.SizeChanged += OnParentSizeChanged;
  41. if (!double.IsNaN(container.ActualWidth))
  42. Width = Math.Max(container.ActualWidth - 45, 0);
  43. MaxHeight = container.ActualHeight;
  44. filteredView = CollectionViewSource.GetDefaultView(strings);
  45. filteredView.Filter = OnResourceFilter;
  46. resourceListView.ItemsSource = filteredView;
  47. }
  48. private bool OnResourceFilter(object obj)
  49. {
  50. if (string.IsNullOrEmpty(filter))
  51. return true;
  52. if (obj is KeyValuePair<string, string> item)
  53. return item.Key?.Contains(filter, StringComparison.OrdinalIgnoreCase) == true ||
  54. item.Value?.Contains(filter, StringComparison.OrdinalIgnoreCase) == true;
  55. return false; // make it obvious search is not working
  56. }
  57. private void OnParentSizeChanged(object sender, SizeChangedEventArgs e)
  58. {
  59. if (e.WidthChanged && !double.IsNaN(e.NewSize.Width))
  60. Width = Math.Max(e.NewSize.Width - 45, 0);
  61. if (e.HeightChanged)
  62. MaxHeight = e.NewSize.Height;
  63. }
  64. private void OnFilterTextChanged(object sender, TextChangedEventArgs e)
  65. {
  66. filter = resourceFilterBox.Text;
  67. filteredView?.Refresh();
  68. }
  69. void ExecuteCopy(object sender, ExecutedRoutedEventArgs args)
  70. {
  71. StringBuilder sb = new StringBuilder();
  72. foreach (var item in resourceListView.SelectedItems)
  73. {
  74. if (item is KeyValuePair<string, string> pair)
  75. {
  76. switch (args.Parameter)
  77. {
  78. case "Key":
  79. sb.AppendLine(pair.Key);
  80. continue;
  81. case "Value":
  82. sb.AppendLine(pair.Value);
  83. continue;
  84. default:
  85. sb.AppendLine($"{pair.Key}\t{pair.Value}");
  86. continue;
  87. }
  88. }
  89. sb.AppendLine(item.ToString());
  90. }
  91. Clipboard.SetText(sb.ToString());
  92. }
  93. void CanExecuteCopy(object sender, CanExecuteRoutedEventArgs args)
  94. {
  95. args.CanExecute = true;
  96. }
  97. }
  98. }