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
- Enable/disable "Window" menu items in AUI MDI correctly (wsu).
- Added wxTimePickerCtrl::Get/SetTime().
- Fix WXK_MENU handling in wxStyledTextCtrl under wxGTK (cantabile).
- 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).
// 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"
// 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)
// returns true if the given string correctly initialized this object
// (i.e. if IsOk() returns true after this call)
+ wxString AsPossiblyLocalizedString(bool localized) const;
+
// common part of Create() and FromString()
static bool ParseAccel(const wxString& str, int *flags, int *keycode);
// common part of Create() and FromString()
static bool ParseAccel(const wxString& str, int *flags, int *keycode);
*/
wxString ToString() const;
*/
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.
/**
Parses the given string and sets the accelerator accordingly.
return ParseAccel(str, &m_flags, &m_keyCode);
}
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 )
{
wxString text;
int flags = GetFlags();
if ( flags & wxACCEL_ALT )
+ text += PossiblyLocalize(wxTRANSLATE("Alt+"), localized);
if ( flags & wxACCEL_CTRL )
if ( flags & wxACCEL_CTRL )
+ text += PossiblyLocalize(wxTRANSLATE("Ctrl+"), localized);
if ( flags & wxACCEL_SHIFT )
if ( flags & wxACCEL_SHIFT )
+ text += PossiblyLocalize(wxTRANSLATE("Shift+"), localized);
#if defined(__WXMAC__) || defined(__WXCOCOA__)
if ( flags & wxACCEL_RAW_CTRL )
#if defined(__WXMAC__) || defined(__WXCOCOA__)
if ( flags & wxACCEL_RAW_CTRL )
+ text += PossiblyLocalize(wxTRANSLATE("RawCtrl+"), localized);
#endif
const int code = GetKeyCode();
if ( code >= WXK_F1 && code <= WXK_F12 )
#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 )
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 )
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;
else // check the named keys
{
size_t n;
const wxKeyName& kn = wxKeyNames[n];
if ( code == kn.code )
{
const wxKeyName& kn = wxKeyNames[n];
if ( code == kn.code )
{
- text << wxGetTranslation(kn.name);
+ text << PossiblyLocalize(kn.name, localized);