diff --git a/docs/changes.txt b/docs/changes.txt index 6a35852c93..3b30025e18 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/interface/wx/propgrid/property.h b/interface/wx/propgrid/property.h index 478bda5b05..8f56e84036 100644 --- a/interface/wx/propgrid/property.h +++ b/interface/wx/propgrid/property.h @@ -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: diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 3bd2c6f5df..b1c878c6f1 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -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,39 +1796,24 @@ 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; - } + if ( a == wxS('\r') ) + // Carriage Return. + dst_str << wxS("\\r"); + else if ( a == wxS('\n') ) + // Line Feed. + dst_str << wxS("\\n"); + else if ( a == wxS('\t') ) + // Tab. + dst_str << wxS("\\t"); + else if ( a == wxS('\\') ) + // Escape character (backslash). + dst_str << wxS("\\\\"); else - { - // This might need... - if ( a == wxS('\r') ) - { - // DOS style line end. - // Already taken care below - } - else if ( a == wxS('\n') ) - // UNIX style line end. - dst_str << wxS("\\n"); - else if ( a == wxS('\t') ) - // Tab. - dst_str << wxS('\t'); - else - { - //wxLogDebug(wxS("WARNING: Could not create escape sequence for character #%i"),(int)a); - dst_str << a; - } - } - - prev_a = a; + dst_str << a; } return dst_str; }