From a0d1231340617ab28a941f723793ad7be242ca0c Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 10 Mar 2015 18:35:00 +0100 Subject: always normalize directory separators to "/" in the "*" Q-Register * on Windows, this register contained backward slashes. This means that macros working with that register had to cope with both forward and backward slashes. * The file names are still displayed in the native style by the UI * This approach also has disadvantages: What if the user wants to insert the current file name somewhere where "\" is expected? However, this seems to be an unlikely case and the use can still replace the "/" with "\" again. * Avoid some virtual method calls in QRegisterBufferInfo --- src/qregisters.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/qregisters.cpp') diff --git a/src/qregisters.cpp b/src/qregisters.cpp index 20f6e99..acb12cf 100644 --- a/src/qregisters.cpp +++ b/src/qregisters.cpp @@ -318,7 +318,22 @@ QRegisterBufferInfo::get_integer(void) gchar * QRegisterBufferInfo::get_string(void) { - return g_strdup(ring.current->filename ? : ""); + gchar *str = g_strdup(ring.current->filename ? : ""); + + /* + * On platforms with a default non-forward-slash directory + * separator (i.e. Windows), Buffer::filename will have + * the wrong separator. + * To make the life of macros that evaluate "*" easier, + * the directory separators are normalized to "/" here. + * This does not change the size of the string, so + * get_string_size() still works. + */ +#if G_DIR_SEPARATOR != '/' + g_strdelimit(str, G_DIR_SEPARATOR_S, '/'); +#endif + + return str; } gsize @@ -330,7 +345,8 @@ QRegisterBufferInfo::get_string_size(void) gint QRegisterBufferInfo::get_character(gint position) { - if (position < 0 || position >= (gint)get_string_size()) + if (position < 0 || + position >= (gint)QRegisterBufferInfo::get_string_size()) return -1; return ring.current->filename[position]; @@ -339,11 +355,14 @@ QRegisterBufferInfo::get_character(gint position) void QRegisterBufferInfo::edit(void) { + gchar *str; + QRegister::edit(); QRegisters::view.ssm(SCI_BEGINUNDOACTION); - QRegisters::view.ssm(SCI_SETTEXT, 0, - (sptr_t)(ring.current->filename ? : "")); + str = QRegisterBufferInfo::get_string(); + QRegisters::view.ssm(SCI_SETTEXT, 0, (sptr_t)str); + g_free(str); QRegisters::view.ssm(SCI_ENDUNDOACTION); QRegisters::view.undo_ssm(SCI_UNDO); -- cgit v1.2.3