X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=libs%2Fgtkutil%2Ffilechooser.cpp;h=abfc225dcc4b05136bf91fff90ec924d52ccffe4;hb=c928e000281714672f6b891894537bab4aa98f3d;hp=f375e53a91e2cef067eb20ed828b51f640d6f1fc;hpb=42a317b7459e9f8152eb0cae61fbafa87ef67a72;p=xonotic%2Fnetradiant.git diff --git a/libs/gtkutil/filechooser.cpp b/libs/gtkutil/filechooser.cpp index f375e53a..abfc225d 100644 --- a/libs/gtkutil/filechooser.cpp +++ b/libs/gtkutil/filechooser.cpp @@ -164,25 +164,23 @@ const char* file_dialog_show( ui::Window parent, bool open, const char* title, c gtk_window_set_position( dialog, GTK_WIN_POS_CENTER_ON_PARENT ); // we expect an actual path below, if the path is 0 we might crash - if ( path != 0 && !string_empty( path ) ) { + if ( path != nullptr && !string_empty( path ) ) { ASSERT_MESSAGE( path_is_absolute( path ), "file_dialog_show: path not absolute: " << makeQuoted( path ) ); - Array new_path( strlen( path ) + 1 ); + std::string new_path( path ); - // copy path, replacing dir separators as appropriate - Array::iterator w = new_path.begin(); - for ( const char* r = path; *r != '\0'; ++r ) - { - *w++ = ( *r == '/' ) ? G_DIR_SEPARATOR : *r; + // replacing dir separators as appropriate + for ( char &c : new_path ) { + if ( c == '/' ) { + c = G_DIR_SEPARATOR; + } } // remove separator from end of path if required - if ( *( w - 1 ) == G_DIR_SEPARATOR ) { - --w; + if ( new_path.back() == G_DIR_SEPARATOR ) { + new_path.pop_back(); } - // terminate string - *w = '\0'; - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), new_path.data() ); + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), new_path.c_str() ); } // we should add all important paths as shortcut folder...