]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxAcceleratorEntry::ToRawString().
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 16 Apr 2012 12:12:19 +0000 (12:12 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 16 Apr 2012 12:12:19 +0000 (12:12 +0000)
This function can be used to obtain language/locale-independent representation
of an accelerator. This is particularly useful for storing it in configuration
files.

Closes #14228.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71203 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/accel.h
interface/wx/accel.h
src/common/accelcmn.cpp

index 4060433d9f725b1eed6ed57d9989f988f0b6a6a1..ddfc91898c855d2ef1c47eaea54842d0d142fe83 100644 (file)
@@ -503,6 +503,7 @@ All (GUI):
 - Enable/disable "Window" menu items in AUI MDI correctly (wsu).
 - Added wxTimePickerCtrl::Get/SetTime().
 - Fix WXK_MENU handling in wxStyledTextCtrl under wxGTK (cantabile).
+- Added wxAcceleratorEntry::ToRawString() (Armel Asselin).
 
 
 GTK:
index ca2d8dfb0e0bbb822678e36469653effde53ca53..562b257d9291b01ddd336b8c285477b34f7eb330 100644 (file)
@@ -118,7 +118,12 @@ public:
     // returns a wxString for the this accelerator.
     // this function formats it using the <flags>-<keycode> format
     // where <flags> maybe a hyphen-separated list of "shift|alt|ctrl"
-    wxString ToString() const;
+    wxString ToString() const { return AsPossiblyLocalizedString(true); }
+
+    // same as above but without translating, useful if the string is meant to
+    // be stored in a file or otherwise stored, instead of being shown to the
+    // user
+    wxString ToRawString() const { return AsPossiblyLocalizedString(false); }
 
     // returns true if the given string correctly initialized this object
     // (i.e. if IsOk() returns true after this call)
@@ -126,6 +131,8 @@ public:
 
 
 private:
+    wxString AsPossiblyLocalizedString(bool localized) const;
+
     // common part of Create() and FromString()
     static bool ParseAccel(const wxString& str, int *flags, int *keycode);
 
index 580d30033d1ec7962ed0e5272c955e92a9f3c504..bdc72a32ea4d82e9018d2f528211392b742ed322 100644 (file)
@@ -114,6 +114,20 @@ public:
     */
     wxString ToString() const;
 
+    /**
+        Returns a textual representation of this accelerator which is
+        appropriate for saving in configuration files.
+
+        Unlike the string returned by ToString(), this one is never translated
+        so, while it's not suitable for showing to the user, it can be used to
+        uniquely identify the accelerator independently of the user language.
+
+        The returned string can still be parsed by FromString().
+
+        @since 2.9.4
+    */
+    wxString ToRawString() const;
+
     /**
         Parses the given string and sets the accelerator accordingly.
 
index 1ed6c5947d99c540eab849196cdc9cfaf435c470..2b3165ec373150f250f4e6d7fd5c357b76f08d8a 100644 (file)
@@ -302,30 +302,43 @@ bool wxAcceleratorEntry::FromString(const wxString& str)
     return ParseAccel(str, &m_flags, &m_keyCode);
 }
 
-wxString wxAcceleratorEntry::ToString() const
+namespace
+{
+
+wxString PossiblyLocalize(const wxString& str, bool localize)
+{
+    return localize ? wxGetTranslation(str) : str;
+}
+
+}
+
+wxString wxAcceleratorEntry::AsPossiblyLocalizedString(bool localized) const
 {
     wxString text;
 
     int flags = GetFlags();
     if ( flags & wxACCEL_ALT )
-        text += _("Alt+");
+        text += PossiblyLocalize(wxTRANSLATE("Alt+"), localized);
     if ( flags & wxACCEL_CTRL )
-        text += _("Ctrl+");
+        text += PossiblyLocalize(wxTRANSLATE("Ctrl+"), localized);
     if ( flags & wxACCEL_SHIFT )
-        text += _("Shift+");
+        text += PossiblyLocalize(wxTRANSLATE("Shift+"), localized);
 #if defined(__WXMAC__) || defined(__WXCOCOA__)
     if ( flags & wxACCEL_RAW_CTRL )
-        text += _("RawCtrl+");
+        text += PossiblyLocalize(wxTRANSLATE("RawCtrl+"), localized);
 #endif
     
     const int code = GetKeyCode();
 
     if ( code >= WXK_F1 && code <= WXK_F12 )
-        text << _("F") << code - WXK_F1 + 1;
+        text << PossiblyLocalize(wxTRANSLATE("F"), localized)
+             << code - WXK_F1 + 1;
     else if ( code >= WXK_NUMPAD0 && code <= WXK_NUMPAD9 )
-        text << _("KP_") << code - WXK_NUMPAD0;
+        text << PossiblyLocalize(wxTRANSLATE("KP_"), localized)
+             << code - WXK_NUMPAD0;
     else if ( code >= WXK_SPECIAL1 && code <= WXK_SPECIAL20 )
-        text << _("SPECIAL") << code - WXK_SPECIAL1 + 1;
+        text << PossiblyLocalize(wxTRANSLATE("SPECIAL"), localized)
+             << code - WXK_SPECIAL1 + 1;
     else // check the named keys
     {
         size_t n;
@@ -334,7 +347,7 @@ wxString wxAcceleratorEntry::ToString() const
             const wxKeyName& kn = wxKeyNames[n];
             if ( code == kn.code )
             {
-                text << wxGetTranslation(kn.name);
+                text << PossiblyLocalize(kn.name, localized);
                 break;
             }
         }