Fix escaping/unescaping in wxLongStringProperty
wxPropertyGrid::ExpandEscapeSequences() function should convert all valid escape sequences (\r, \n, \t, \\) to the corresponding single characters (CR, LF, TAB, backslash, accordingly) and wxPropertyGrid::CreateEscapeSequences() function should do the reverse operation and convert these raw characters to the corresponding escape sequences. Closes #17896.
This commit is contained in:
@@ -145,6 +145,7 @@ All (GUI):
|
||||
- Add support for bitmaps to wxToggleButton XRC handler (tm).
|
||||
- Fix wxGCDC::SetDeviceClippingRegion().
|
||||
- Never restore size smaller than the best one in wxPersistentTLW.
|
||||
- Fix escaping/unescaping characters in wxLongStringProperty in wxPG (mikek).
|
||||
|
||||
wxGTK:
|
||||
|
||||
|
@@ -543,8 +543,14 @@ wxPG_PROP_CLASS_SPECIFIC_3 = 0x00400000
|
||||
@subsection wxLongStringProperty
|
||||
|
||||
Like wxStringProperty, but has a button that triggers a small text editor
|
||||
dialog. Note that in long string values, tabs are represented by "\t" and
|
||||
line break by "\n".
|
||||
dialog. Note that in long string values, some control characters are
|
||||
escaped: tab is represented by "\t", line break by "\n", carriage return
|
||||
by "\r" and backslash character by "\\". If another character is preceded
|
||||
by backslash, the backslash is skipped.
|
||||
Note also that depending on the system (port), some sequences of special
|
||||
characters, like e.g. "\r\n", can be interpreted and presented in
|
||||
a different way in the editor and therefore such sequences may not be
|
||||
the same before and after the edition.
|
||||
|
||||
To display custom dialog on button press, you can subclass
|
||||
wxLongStringProperty and implement OnButtonClick, like this:
|
||||
|
@@ -1744,9 +1744,8 @@ wxString& wxPropertyGrid::ExpandEscapeSequences( wxString& dst_str, const wxStri
|
||||
|
||||
bool prev_is_slash = false;
|
||||
|
||||
wxString::const_iterator i = src_str.begin();
|
||||
|
||||
for ( ; i != src_str.end(); ++i )
|
||||
wxString::const_iterator i;
|
||||
for ( i = src_str.begin(); i != src_str.end(); ++i )
|
||||
{
|
||||
wxUniChar a = *i;
|
||||
|
||||
@@ -1759,13 +1758,9 @@ wxString& wxPropertyGrid::ExpandEscapeSequences( wxString& dst_str, const wxStri
|
||||
else
|
||||
{
|
||||
if ( a == wxS('n') )
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
dst_str << wxS('\n');
|
||||
#else
|
||||
dst_str << wxS('\n');
|
||||
#endif
|
||||
}
|
||||
else if ( a == wxS('r') )
|
||||
dst_str << wxS('\r');
|
||||
else if ( a == wxS('t') )
|
||||
dst_str << wxS('\t');
|
||||
else
|
||||
@@ -1801,40 +1796,25 @@ wxString& wxPropertyGrid::CreateEscapeSequences( wxString& dst_str, const wxStri
|
||||
}
|
||||
|
||||
wxString::const_iterator i;
|
||||
wxUniChar prev_a = wxS('\0');
|
||||
|
||||
for ( i = src_str.begin(); i != src_str.end(); ++i )
|
||||
{
|
||||
wxUniChar a = *i;
|
||||
|
||||
if ( a >= wxS(' ') )
|
||||
{
|
||||
// This surely is not something that requires an escape sequence.
|
||||
dst_str << a;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This might need...
|
||||
if ( a == wxS('\r') )
|
||||
{
|
||||
// DOS style line end.
|
||||
// Already taken care below
|
||||
}
|
||||
// Carriage Return.
|
||||
dst_str << wxS("\\r");
|
||||
else if ( a == wxS('\n') )
|
||||
// UNIX style line end.
|
||||
// Line Feed.
|
||||
dst_str << wxS("\\n");
|
||||
else if ( a == wxS('\t') )
|
||||
// Tab.
|
||||
dst_str << wxS('\t');
|
||||
dst_str << wxS("\\t");
|
||||
else if ( a == wxS('\\') )
|
||||
// Escape character (backslash).
|
||||
dst_str << wxS("\\\\");
|
||||
else
|
||||
{
|
||||
//wxLogDebug(wxS("WARNING: Could not create escape sequence for character #%i"),(int)a);
|
||||
dst_str << a;
|
||||
}
|
||||
}
|
||||
|
||||
prev_a = a;
|
||||
}
|
||||
return dst_str;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user