Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez <slluis.devel@gmail.com>2013-08-19 19:16:19 +0400
committerLluis Sanchez <slluis.devel@gmail.com>2013-08-19 19:16:19 +0400
commitac711c69e325cf2ebc91349c218e86754077ed7f (patch)
treefc962dc26f4c73e35747c2276d8465e1b61bfe0b /Xwt.Mac
parent95d4e3d4b40aebde03d9c6774f768c3a41b9e32b (diff)
parent2abbe4f9de10b8e0d01645e08fa4a93bf30470c3 (diff)
Merge pull request #234 from dlech/mnemonics
Implement mnemonics
Diffstat (limited to 'Xwt.Mac')
-rw-r--r--Xwt.Mac/Xwt.Mac/ButtonBackend.cs4
-rw-r--r--Xwt.Mac/Xwt.Mac/MenuItemBackend.cs17
-rw-r--r--Xwt.Mac/Xwt.Mac/Util.cs38
3 files changed, 50 insertions, 9 deletions
diff --git a/Xwt.Mac/Xwt.Mac/ButtonBackend.cs b/Xwt.Mac/Xwt.Mac/ButtonBackend.cs
index 5e266aba..de0983c9 100644
--- a/Xwt.Mac/Xwt.Mac/ButtonBackend.cs
+++ b/Xwt.Mac/Xwt.Mac/ButtonBackend.cs
@@ -56,8 +56,10 @@ namespace Xwt.Mac
((MacButton)Widget).DisableEvent (ev);
}
- public void SetContent (string label, ImageDescription image, ContentPosition imagePosition)
+ public void SetContent (string label, bool useMnemonic, ImageDescription image, ContentPosition imagePosition)
{
+ if (useMnemonic)
+ label = label.RemoveMnemonic ();
Widget.Title = label ?? "";
if (string.IsNullOrEmpty (label))
imagePosition = ContentPosition.Center;
diff --git a/Xwt.Mac/Xwt.Mac/MenuItemBackend.cs b/Xwt.Mac/Xwt.Mac/MenuItemBackend.cs
index 8e1b6d43..fb5a0bf5 100644
--- a/Xwt.Mac/Xwt.Mac/MenuItemBackend.cs
+++ b/Xwt.Mac/Xwt.Mac/MenuItemBackend.cs
@@ -38,6 +38,8 @@ namespace Xwt.Mac
IMenuItemEventSink eventSink;
List<MenuItemEvent> enabledEvents;
ApplicationContext context;
+ string label;
+ bool useMnemonic;
public MenuItemBackend (): this (new NSMenuItem ())
{
@@ -67,10 +69,21 @@ namespace Xwt.Mac
public string Label {
get {
- return item.Title;
+ return label;
}
set {
- item.Title = value;
+ item.Title = UseMnemonic ? value.RemoveMnemonic () : value;
+ label = value;
+ }
+ }
+
+ public bool UseMnemonic {
+ get {
+ return useMnemonic;
+ }
+ set {
+ useMnemonic = value;
+ Label = label ?? string.Empty;
}
}
diff --git a/Xwt.Mac/Xwt.Mac/Util.cs b/Xwt.Mac/Xwt.Mac/Util.cs
index 28675797..58c3e5b1 100644
--- a/Xwt.Mac/Xwt.Mac/Util.cs
+++ b/Xwt.Mac/Xwt.Mac/Util.cs
@@ -25,16 +25,18 @@
// THE SOFTWARE.
using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.Text;
using MonoMac.AppKit;
-using Xwt.Drawing;
using MonoMac.CoreGraphics;
-using SizeF = System.Drawing.SizeF;
-using RectangleF = System.Drawing.RectangleF;
-using MonoMac.ObjCRuntime;
using MonoMac.Foundation;
-using System.Collections.Generic;
+using MonoMac.ObjCRuntime;
using Xwt.Backends;
-using System.Runtime.InteropServices;
+using Xwt.Drawing;
+
+using RectangleF = System.Drawing.RectangleF;
+using SizeF = System.Drawing.SizeF;
namespace Xwt.Mac
{
@@ -336,6 +338,30 @@ namespace Xwt.Mac
return ns;
}
+ /// <summary>
+ /// Removes the mnemonics (underscore character) from a string.
+ /// </summary>
+ /// <returns>The string with the mnemonics unescaped.</returns>
+ /// <param name="text">The string.</param>
+ /// <remarks>
+ /// Single underscores are removed. Double underscores are replaced with single underscores (unescaped).
+ /// </remarks>
+ public static string RemoveMnemonic(this string str)
+ {
+ if (str == null)
+ return null;
+ var newText = new StringBuilder ();
+ for (int i = 0; i < str.Length; i++) {
+ if (str [i] != '_')
+ newText.Append (str [i]);
+ else if (i < str.Length && str [i + 1] == '_') {
+ newText.Append ('_');
+ i++;
+ }
+ }
+ return newText.ToString ();
+ }
+
public static CheckBoxState ToXwtState (this NSCellStateValue state)
{
switch (state) {