Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 79bdcec

Browse files
committed
Remove unused code (WinForms->WPF menu conversion)
1 parent fa2c1a6 commit 79bdcec

4 files changed

Lines changed: 3 additions & 61 deletions

File tree

src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplaceDialog.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Drawing;
66
using System.Windows.Forms;
7-
87
using ICSharpCode.Core;
98
using ICSharpCode.Core.WinForms;
109
using ICSharpCode.SharpDevelop;
@@ -148,7 +147,7 @@ Keys GetKeyboardShortcut(string path, string id)
148147
if (node != null) {
149148
foreach (Codon codon in node.Codons) {
150149
if (codon.Id == id) {
151-
return MenuCommand.ParseShortcut(codon.Properties["shortcut"]);
150+
return (Keys)new KeysConverter().ConvertFromInvariantString(codon.Properties["shortcut"].Replace('|', '+'));
152151
}
153152
}
154153
}

src/Main/Base/Project/Src/Util/ExtensionMethods.cs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -423,33 +423,6 @@ public static Image CreateImage(this IImage image)
423423
return new Image { Source = image.ImageSource };
424424
}
425425

426-
/// <summary>
427-
/// Translates a WinForms menu to WPF.
428-
/// </summary>
429-
public static ICollection TranslateToWpf(this ToolStripItem[] items)
430-
{
431-
return items.OfType<ToolStripMenuItem>().Select(item => TranslateMenuItemToWpf(item)).ToList();
432-
}
433-
434-
static System.Windows.Controls.MenuItem TranslateMenuItemToWpf(ToolStripMenuItem item)
435-
{
436-
var r = new System.Windows.Controls.MenuItem();
437-
r.Header = MenuService.ConvertLabel(item.Text);
438-
r.InputGestureText = MenuService.ConvertKeys(item.ShortcutKeys);
439-
//r.InputGestureText = new KeyGesture(Key.F6).GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture);
440-
if (item.ImageIndex >= 0)
441-
r.Icon = ClassBrowserIconService.GetImageByIndex(item.ImageIndex).CreateImage();
442-
if (item.DropDownItems.Count > 0) {
443-
foreach (ToolStripMenuItem subItem in item.DropDownItems) {
444-
r.Items.Add(TranslateMenuItemToWpf(subItem));
445-
}
446-
} else {
447-
r.Click += delegate { item.PerformClick(); };
448-
}
449-
r.IsChecked = item.Checked;
450-
return r;
451-
}
452-
453426
/// <summary>
454427
/// Returns the index of the first element for which <paramref name="predicate"/> returns true.
455428
/// If none of the items in the list fits the <paramref name="predicate"/>, -1 is returned.
@@ -467,7 +440,7 @@ public static int FindIndex<T>(this IList<T> list, Func<T, bool> predicate)
467440
/// <summary>
468441
/// Adds item to the list if the item is not null.
469442
/// </summary>
470-
public static void AddIfNotNull<T>(this IList<T> list, T itemToAdd)
443+
public static void AddIfNotNull<T>(this IList<T> list, T itemToAdd) where T : class
471444
{
472445
if (itemToAdd != null)
473446
list.Add(itemToAdd);

src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,7 @@ public static string ConvertLabel(string label)
259259
/// </summary>
260260
public static KeyGesture ParseShortcut(string text)
261261
{
262-
return (KeyGesture)new KeyGestureConverter().ConvertFromInvariantString(text.Replace(',', '+').Replace('|', '+'));
263-
}
264-
265-
static WinForms.KeysConverter shortcutKeysConverter = new WinForms.KeysConverter();
266-
/// <summary>
267-
/// Converts Windows-Forms Keys enum to WPF string representation, suitable e.g. for MenuItem.InputGestureText.
268-
/// </summary>
269-
public static string ConvertKeys(System.Windows.Forms.Keys shortcutKeys)
270-
{
271-
if (shortcutKeys == WinForms.Keys.None || shortcutKeys == WinForms.Keys.NoName || shortcutKeys == WinForms.Keys.IMENonconvert)
272-
return string.Empty;
273-
return shortcutKeysConverter.ConvertToString(shortcutKeys);
262+
return (KeyGesture)new KeyGestureConverter().ConvertFromInvariantString(text.Replace('|', '+'));
274263
}
275264
}
276265
}

src/Main/ICSharpCode.Core.WinForms/Menu/MenuCommand.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,6 @@ public MenuCommand(Codon codon, object caller) : this(codon, caller, false)
7171

7272
}
7373

74-
public static Keys ParseShortcut(string shortcutString)
75-
{
76-
Keys shortCut = Keys.None;
77-
if (shortcutString.Length > 0) {
78-
try {
79-
foreach (string key in shortcutString.Split('|')) {
80-
shortCut |= (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), key);
81-
}
82-
} catch (Exception ex) {
83-
MessageService.ShowException(ex);
84-
return System.Windows.Forms.Keys.None;
85-
}
86-
}
87-
return shortCut;
88-
}
89-
9074
public MenuCommand(Codon codon, object caller, bool createCommand)
9175
{
9276
this.RightToLeft = RightToLeft.Inherit;
@@ -98,9 +82,6 @@ public MenuCommand(Codon codon, object caller, bool createCommand)
9882
}
9983

10084
UpdateText();
101-
if (codon.Properties.Contains("shortcut")) {
102-
ShortcutKeys = ParseShortcut(codon.Properties["shortcut"]);
103-
}
10485
}
10586

10687
public MenuCommand(string label, EventHandler handler) : this(label)

0 commit comments

Comments
 (0)