From 8dcc3cd20de72697dbba3ce8d3fca634c0dc48fe Mon Sep 17 00:00:00 2001 From: SoftFever Date: Tue, 24 Mar 2026 20:34:32 +0800 Subject: [PATCH] Remove const_cast workarounds for wxExecute (wxWidgets 3.1+) wxWidgets 3.1+ accepts const argv arrays (const wchar_t* const* and const char* const*) in wxExecute(), making the const_casts unnecessary. Remove all 14 const_cast/const_cast wrappers around wxExecute calls and their associated FIXME comments across GUI.cpp, NotificationManager.cpp, and Downloader.cpp. --- src/slic3r/GUI/Downloader.cpp | 10 ++++------ src/slic3r/GUI/GUI.cpp | 15 ++++++--------- src/slic3r/GUI/NotificationManager.cpp | 10 ++++------ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/slic3r/GUI/Downloader.cpp b/src/slic3r/GUI/Downloader.cpp index 63cd9dafc8..c61b2716fc 100644 --- a/src/slic3r/GUI/Downloader.cpp +++ b/src/slic3r/GUI/Downloader.cpp @@ -17,15 +17,13 @@ void open_folder(const std::string& path) // Code taken from NotificationManager.cpp // Execute command to open a file explorer, platform dependent. - // FIXME: The const_casts aren't needed in wxWidgets 3.1, remove them when we upgrade. - #ifdef _WIN32 const wxString widepath = from_u8(path); const wchar_t* argv[] = { L"explorer", widepath.GetData(), nullptr }; - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr); #elif __APPLE__ const char* argv[] = { "open", path.data(), nullptr }; - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr); #else const char* argv[] = { "xdg-open", path.data(), nullptr }; @@ -53,11 +51,11 @@ void open_folder(const std::string& path) exec_env.cwd = std::move(owd); } - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr, &exec_env); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr, &exec_env); } else { // Looks like we're NOT running from AppImage, we'll make no changes to the environment. - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr, nullptr); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr, nullptr); } #endif } diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index d133720c7e..6fbdbee6e9 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -530,16 +530,14 @@ void login() void desktop_open_datadir_folder() { // Execute command to open a file explorer, platform dependent. - // FIXME: The const_casts aren't needed in wxWidgets 3.1, remove them when we upgrade. - const auto path = data_dir(); #ifdef _WIN32 const wxString widepath = from_u8(path); const wchar_t *argv[] = { L"explorer", widepath.GetData(), nullptr }; - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr); #elif __APPLE__ const char *argv[] = { "open", path.data(), nullptr }; - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr); #else const char *argv[] = { "xdg-open", path.data(), nullptr }; @@ -567,10 +565,10 @@ void desktop_open_datadir_folder() exec_env.cwd = std::move(owd); } - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr, &exec_env); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr, &exec_env); } else { // Looks like we're NOT running from AppImage, we'll make no changes to the environment. - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr, nullptr); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr, nullptr); } #endif } @@ -578,7 +576,6 @@ void desktop_open_datadir_folder() void desktop_open_any_folder( const std::string& path ) { // Execute command to open a file explorer, platform dependent. - // FIXME: The const_casts aren't needed in wxWidgets 3.1, remove them when we upgrade. #ifdef _WIN32 const wxString widepath = from_u8(path); @@ -619,10 +616,10 @@ void desktop_open_any_folder( const std::string& path ) exec_env.cwd = std::move(owd); } - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr, &exec_env); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr, &exec_env); } else { // Looks like we're NOT running from AppImage, we'll make no changes to the environment. - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr, nullptr); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr, nullptr); } #endif } diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index abd5a12373..ec592685a1 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -69,15 +69,13 @@ namespace { // Code taken from desktop_open_datadir_folder() // Execute command to open a file explorer, platform dependent. - // FIXME: The const_casts aren't needed in wxWidgets 3.1, remove them when we upgrade. - #ifdef _WIN32 const wxString widepath = from_u8(path); const wchar_t* argv[] = { L"explorer", widepath.GetData(), nullptr }; - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr); #elif __APPLE__ const char* argv[] = { "open", path.data(), nullptr }; - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr); #else const char* argv[] = { "xdg-open", path.data(), nullptr }; @@ -105,11 +103,11 @@ namespace { exec_env.cwd = std::move(owd); } - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr, &exec_env); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr, &exec_env); } else { // Looks like we're NOT running from AppImage, we'll make no changes to the environment. - ::wxExecute(const_cast(argv), wxEXEC_ASYNC, nullptr, nullptr); + ::wxExecute(argv, wxEXEC_ASYNC, nullptr, nullptr); } #endif }