2015-12-04 20:25:45 +00:00
|
|
|
#include "GUI.hpp"
|
2018-10-05 21:29:15 +00:00
|
|
|
#include "GUI_App.hpp"
|
2018-11-26 13:41:58 +00:00
|
|
|
#include "I18N.hpp"
|
2015-12-04 20:25:45 +00:00
|
|
|
|
2019-01-02 14:11:05 +00:00
|
|
|
#include <string>
|
2017-11-02 15:21:34 +00:00
|
|
|
|
2018-05-21 20:10:38 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2020-05-23 22:50:11 +00:00
|
|
|
#include <boost/any.hpp>
|
2018-02-02 11:38:35 +00:00
|
|
|
|
2015-12-04 20:25:45 +00:00
|
|
|
#if __APPLE__
|
|
|
|
#import <IOKit/pwr_mgt/IOPMLib.h>
|
|
|
|
#elif _WIN32
|
2018-12-06 13:47:53 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#define NOMINMAX
|
2015-12-04 20:25:45 +00:00
|
|
|
#include <Windows.h>
|
2017-11-02 15:21:34 +00:00
|
|
|
#include "boost/nowide/convert.hpp"
|
2015-12-04 20:25:45 +00:00
|
|
|
#endif
|
|
|
|
|
2018-04-09 15:03:37 +00:00
|
|
|
#include "AboutDialog.hpp"
|
2020-03-04 10:32:22 +00:00
|
|
|
#include "MsgDialog.hpp"
|
2017-12-05 14:54:01 +00:00
|
|
|
|
2018-11-26 13:41:58 +00:00
|
|
|
#include "libslic3r/Print.hpp"
|
2018-03-23 10:41:20 +00:00
|
|
|
|
2020-03-04 10:32:22 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
class AppConfig;
|
|
|
|
|
|
|
|
namespace GUI {
|
2015-12-04 20:25:45 +00:00
|
|
|
|
2015-12-05 10:48:24 +00:00
|
|
|
#if __APPLE__
|
2015-12-04 20:25:45 +00:00
|
|
|
IOPMAssertionID assertionID;
|
2015-12-05 10:48:24 +00:00
|
|
|
#endif
|
2015-12-04 20:25:45 +00:00
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
void disable_screensaver()
|
2015-12-04 20:25:45 +00:00
|
|
|
{
|
|
|
|
#if __APPLE__
|
|
|
|
CFStringRef reasonForActivity = CFSTR("Slic3r");
|
|
|
|
IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
|
|
|
|
kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
|
|
|
|
// ignore result: success == kIOReturnSuccess
|
|
|
|
#elif _WIN32
|
2015-12-06 10:17:50 +00:00
|
|
|
SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_CONTINUOUS);
|
2015-12-04 20:25:45 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
void enable_screensaver()
|
2015-12-04 20:25:45 +00:00
|
|
|
{
|
|
|
|
#if __APPLE__
|
|
|
|
IOReturn success = IOPMAssertionRelease(assertionID);
|
|
|
|
#elif _WIN32
|
2015-12-06 10:17:50 +00:00
|
|
|
SetThreadExecutionState(ES_CONTINUOUS);
|
2015-12-04 20:25:45 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
bool debugged()
|
2016-04-13 18:45:44 +00:00
|
|
|
{
|
2016-04-13 18:51:03 +00:00
|
|
|
#ifdef _WIN32
|
2018-10-31 15:22:36 +00:00
|
|
|
return IsDebuggerPresent() == TRUE;
|
2016-04-13 18:51:03 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif /* _WIN32 */
|
2016-04-13 18:45:44 +00:00
|
|
|
}
|
|
|
|
|
2017-10-25 10:53:31 +00:00
|
|
|
void break_to_debugger()
|
2016-04-13 18:45:44 +00:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (IsDebuggerPresent())
|
|
|
|
DebugBreak();
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
}
|
|
|
|
|
2019-02-03 10:10:25 +00:00
|
|
|
const std::string& shortkey_ctrl_prefix()
|
|
|
|
{
|
|
|
|
static const std::string str =
|
|
|
|
#ifdef __APPLE__
|
|
|
|
"⌘"
|
|
|
|
#else
|
|
|
|
"Ctrl+"
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& shortkey_alt_prefix()
|
|
|
|
{
|
|
|
|
static const std::string str =
|
|
|
|
#ifdef __APPLE__
|
|
|
|
"⌥"
|
|
|
|
#else
|
|
|
|
"Alt+"
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2018-02-15 16:30:33 +00:00
|
|
|
// opt_index = 0, by the reason of zero-index in ConfigOptionVector by default (in case only one element)
|
2018-04-13 10:35:04 +00:00
|
|
|
void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/)
|
2018-01-07 17:41:40 +00:00
|
|
|
{
|
|
|
|
try{
|
2019-07-28 20:00:39 +00:00
|
|
|
|
|
|
|
if (config.def()->get(opt_key)->type == coBools && config.def()->get(opt_key)->nullable) {
|
|
|
|
ConfigOptionBoolsNullable* vec_new = new ConfigOptionBoolsNullable{ boost::any_cast<unsigned char>(value) };
|
|
|
|
config.option<ConfigOptionBoolsNullable>(opt_key)->set_at(vec_new, opt_index, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-31 11:56:08 +00:00
|
|
|
switch (config.def()->get(opt_key)->type) {
|
2018-01-09 12:52:01 +00:00
|
|
|
case coFloatOrPercent:{
|
2018-02-20 11:30:13 +00:00
|
|
|
std::string str = boost::any_cast<std::string>(value);
|
|
|
|
bool percent = false;
|
2018-10-31 11:56:08 +00:00
|
|
|
if (str.back() == '%') {
|
2018-02-20 11:30:13 +00:00
|
|
|
str.pop_back();
|
|
|
|
percent = true;
|
|
|
|
}
|
|
|
|
double val = stod(str);
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent));
|
2018-01-09 12:52:01 +00:00
|
|
|
break;}
|
2018-01-07 17:41:40 +00:00
|
|
|
case coPercent:
|
2018-01-11 09:33:17 +00:00
|
|
|
config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast<double>(value)));
|
2018-01-09 12:52:01 +00:00
|
|
|
break;
|
|
|
|
case coFloat:{
|
2018-01-07 17:41:40 +00:00
|
|
|
double& val = config.opt_float(opt_key);
|
2018-01-09 08:41:07 +00:00
|
|
|
val = boost::any_cast<double>(value);
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-02-26 08:57:08 +00:00
|
|
|
case coPercents:{
|
|
|
|
ConfigOptionPercents* vec_new = new ConfigOptionPercents{ boost::any_cast<double>(value) };
|
|
|
|
config.option<ConfigOptionPercents>(opt_key)->set_at(vec_new, opt_index, opt_index);
|
2018-01-09 12:52:01 +00:00
|
|
|
break;
|
2018-02-26 08:57:08 +00:00
|
|
|
}
|
|
|
|
case coFloats:{
|
|
|
|
ConfigOptionFloats* vec_new = new ConfigOptionFloats{ boost::any_cast<double>(value) };
|
|
|
|
config.option<ConfigOptionFloats>(opt_key)->set_at(vec_new, opt_index, opt_index);
|
|
|
|
break;
|
2018-01-09 12:52:01 +00:00
|
|
|
}
|
2018-01-07 17:41:40 +00:00
|
|
|
case coString:
|
2018-01-09 12:52:01 +00:00
|
|
|
config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast<std::string>(value)));
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
2018-01-12 11:41:13 +00:00
|
|
|
case coStrings:{
|
2019-01-07 13:52:13 +00:00
|
|
|
if (opt_key == "compatible_prints" || opt_key == "compatible_printers") {
|
2018-04-13 10:35:04 +00:00
|
|
|
config.option<ConfigOptionStrings>(opt_key)->values =
|
|
|
|
boost::any_cast<std::vector<std::string>>(value);
|
|
|
|
}
|
2018-10-31 11:56:08 +00:00
|
|
|
else if (config.def()->get(opt_key)->gui_flags.compare("serialized") == 0) {
|
2018-04-13 10:35:04 +00:00
|
|
|
std::string str = boost::any_cast<std::string>(value);
|
2019-01-08 09:15:15 +00:00
|
|
|
std::vector<std::string> values {};
|
|
|
|
if (!str.empty()) {
|
|
|
|
if (str.back() == ';') str.pop_back();
|
|
|
|
// Split a string to multiple strings by a semi - colon.This is the old way of storing multi - string values.
|
|
|
|
// Currently used for the post_process config value only.
|
|
|
|
boost::split(values, str, boost::is_any_of(";"));
|
|
|
|
if (values.size() == 1 && values[0] == "")
|
|
|
|
values.resize(0);
|
|
|
|
}
|
2018-03-23 16:27:43 +00:00
|
|
|
config.option<ConfigOptionStrings>(opt_key)->values = values;
|
2018-01-12 11:41:13 +00:00
|
|
|
}
|
|
|
|
else{
|
2018-01-25 12:46:04 +00:00
|
|
|
ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast<std::string>(value) };
|
2018-03-02 12:41:37 +00:00
|
|
|
config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new, opt_index, 0);
|
2018-01-12 11:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
|
|
|
case coBool:
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast<bool>(value)));
|
|
|
|
break;
|
2018-01-09 12:52:01 +00:00
|
|
|
case coBools:{
|
2018-11-08 19:18:40 +00:00
|
|
|
ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast<unsigned char>(value) != 0 };
|
2018-03-02 12:41:37 +00:00
|
|
|
config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, opt_index, 0);
|
2018-01-09 12:52:01 +00:00
|
|
|
break;}
|
2018-01-07 17:41:40 +00:00
|
|
|
case coInt:
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value)));
|
|
|
|
break;
|
2018-01-12 11:41:13 +00:00
|
|
|
case coInts:{
|
|
|
|
ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast<int>(value) };
|
2018-03-02 12:41:37 +00:00
|
|
|
config.option<ConfigOptionInts>(opt_key)->set_at(vec_new, opt_index, 0);
|
2018-01-12 11:41:13 +00:00
|
|
|
}
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
2018-01-11 09:33:17 +00:00
|
|
|
case coEnum:{
|
2019-02-22 14:25:35 +00:00
|
|
|
if (opt_key == "top_fill_pattern" ||
|
|
|
|
opt_key == "bottom_fill_pattern" ||
|
|
|
|
opt_key == "fill_pattern")
|
2018-01-11 09:33:17 +00:00
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<InfillPattern>(boost::any_cast<InfillPattern>(value)));
|
2020-04-14 09:53:28 +00:00
|
|
|
else if (opt_key.compare("ironing_type") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<IroningType>(boost::any_cast<IroningType>(value)));
|
2018-01-11 09:33:17 +00:00
|
|
|
else if (opt_key.compare("gcode_flavor") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<GCodeFlavor>(boost::any_cast<GCodeFlavor>(value)));
|
|
|
|
else if (opt_key.compare("support_material_pattern") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<SupportMaterialPattern>(boost::any_cast<SupportMaterialPattern>(value)));
|
|
|
|
else if (opt_key.compare("seam_position") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<SeamPosition>(boost::any_cast<SeamPosition>(value)));
|
2018-07-08 12:32:48 +00:00
|
|
|
else if (opt_key.compare("host_type") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<PrintHostType>(boost::any_cast<PrintHostType>(value)));
|
2018-12-14 16:19:17 +00:00
|
|
|
else if (opt_key.compare("display_orientation") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<SLADisplayOrientation>(boost::any_cast<SLADisplayOrientation>(value)));
|
2019-01-09 11:21:43 +00:00
|
|
|
else if(opt_key.compare("support_pillar_connection_mode") == 0)
|
|
|
|
config.set_key_value(opt_key, new ConfigOptionEnum<SLAPillarConnectionMode>(boost::any_cast<SLAPillarConnectionMode>(value)));
|
2018-01-11 09:33:17 +00:00
|
|
|
}
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
2018-01-30 11:10:12 +00:00
|
|
|
case coPoints:{
|
2018-10-31 11:56:08 +00:00
|
|
|
if (opt_key.compare("bed_shape") == 0) {
|
2018-08-21 19:05:24 +00:00
|
|
|
config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Vec2d>>(value);
|
2018-03-23 16:27:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-08-21 19:05:24 +00:00
|
|
|
ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast<Vec2d>(value) };
|
2018-03-08 10:58:06 +00:00
|
|
|
config.option<ConfigOptionPoints>(opt_key)->set_at(vec_new, opt_index, 0);
|
2018-01-30 11:10:12 +00:00
|
|
|
}
|
2018-01-07 17:41:40 +00:00
|
|
|
break;
|
|
|
|
case coNone:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-31 15:22:36 +00:00
|
|
|
catch (const std::exception & /* e */)
|
2018-01-07 17:41:40 +00:00
|
|
|
{
|
2019-09-03 08:27:16 +00:00
|
|
|
// int i = 0;//no reason, just experiment
|
2018-01-07 17:41:40 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-06 08:52:19 +00:00
|
|
|
|
2018-10-31 11:56:08 +00:00
|
|
|
void show_error(wxWindow* parent, const wxString& message)
|
|
|
|
{
|
2018-04-30 12:31:57 +00:00
|
|
|
ErrorDialog msg(parent, message);
|
|
|
|
msg.ShowModal();
|
2017-12-22 10:50:28 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 12:38:06 +00:00
|
|
|
void show_error(wxWindow* parent, const char* message)
|
|
|
|
{
|
2020-02-29 11:03:07 +00:00
|
|
|
assert(message);
|
2020-02-21 12:38:06 +00:00
|
|
|
show_error(parent, wxString::FromUTF8(message));
|
|
|
|
}
|
|
|
|
|
2018-10-31 11:56:08 +00:00
|
|
|
void show_error_id(int id, const std::string& message)
|
|
|
|
{
|
2018-04-30 12:31:57 +00:00
|
|
|
auto *parent = id != 0 ? wxWindow::FindWindowById(id) : nullptr;
|
2020-02-21 12:38:06 +00:00
|
|
|
show_error(parent, message);
|
2017-12-22 10:50:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 11:56:08 +00:00
|
|
|
void show_info(wxWindow* parent, const wxString& message, const wxString& title)
|
|
|
|
{
|
2020-02-29 11:03:07 +00:00
|
|
|
wxMessageDialog msg_wingow(parent, message, wxString(SLIC3R_APP_NAME " - ") + (title.empty() ? _(L("Notice")) : title), wxOK | wxICON_INFORMATION);
|
2018-04-30 12:31:57 +00:00
|
|
|
msg_wingow.ShowModal();
|
2017-12-04 09:48:40 +00:00
|
|
|
}
|
|
|
|
|
2020-02-29 11:03:07 +00:00
|
|
|
void show_info(wxWindow* parent, const char* message, const char* title)
|
|
|
|
{
|
|
|
|
assert(message);
|
|
|
|
show_info(parent, wxString::FromUTF8(message), title ? wxString::FromUTF8(title) : wxString());
|
|
|
|
}
|
|
|
|
|
2018-10-31 11:56:08 +00:00
|
|
|
void warning_catcher(wxWindow* parent, const wxString& message)
|
|
|
|
{
|
2018-04-30 12:31:57 +00:00
|
|
|
wxMessageDialog msg(parent, message, _(L("Warning")), wxOK | wxICON_WARNING);
|
|
|
|
msg.ShowModal();
|
2018-02-22 10:12:29 +00:00
|
|
|
}
|
|
|
|
|
2018-02-02 11:38:35 +00:00
|
|
|
void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value)
|
|
|
|
{
|
2018-02-06 11:43:25 +00:00
|
|
|
if (comboCtrl == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxCheckListBoxComboPopup* popup = new wxCheckListBoxComboPopup;
|
2018-02-02 11:38:35 +00:00
|
|
|
if (popup != nullptr)
|
|
|
|
{
|
2018-02-20 14:22:30 +00:00
|
|
|
// FIXME If the following line is removed, the combo box popup list will not react to mouse clicks.
|
|
|
|
// On the other side, with this line the combo box popup cannot be closed by clicking on the combo button on Windows 10.
|
|
|
|
comboCtrl->UseAltPopupWindow();
|
|
|
|
|
|
|
|
comboCtrl->EnablePopupAnimation(false);
|
2018-02-02 11:38:35 +00:00
|
|
|
comboCtrl->SetPopupControl(popup);
|
2018-02-28 14:39:20 +00:00
|
|
|
popup->SetStringValue(from_u8(text));
|
2018-02-20 10:40:15 +00:00
|
|
|
popup->Bind(wxEVT_CHECKLISTBOX, [popup](wxCommandEvent& evt) { popup->OnCheckListBox(evt); });
|
|
|
|
popup->Bind(wxEVT_LISTBOX, [popup](wxCommandEvent& evt) { popup->OnListBoxSelection(evt); });
|
2018-02-20 13:25:40 +00:00
|
|
|
popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); });
|
|
|
|
popup->Bind(wxEVT_KEY_UP, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); });
|
2018-02-02 11:38:35 +00:00
|
|
|
|
|
|
|
std::vector<std::string> items_str;
|
|
|
|
boost::split(items_str, items, boost::is_any_of("|"), boost::token_compress_off);
|
|
|
|
|
|
|
|
for (const std::string& item : items_str)
|
|
|
|
{
|
2018-02-26 15:23:44 +00:00
|
|
|
popup->Append(from_u8(item));
|
2018-02-02 11:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < popup->GetCount(); ++i)
|
|
|
|
{
|
|
|
|
popup->Check(i, initial_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int combochecklist_get_flags(wxComboCtrl* comboCtrl)
|
|
|
|
{
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
wxCheckListBoxComboPopup* popup = wxDynamicCast(comboCtrl->GetPopupControl(), wxCheckListBoxComboPopup);
|
|
|
|
if (popup != nullptr)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < popup->GetCount(); ++i)
|
|
|
|
{
|
|
|
|
if (popup->IsChecked(i))
|
2018-02-13 16:46:23 +00:00
|
|
|
flags |= 1 << i;
|
2018-02-02 11:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2018-02-22 10:12:29 +00:00
|
|
|
AppConfig* get_app_config()
|
|
|
|
{
|
2018-10-02 11:23:38 +00:00
|
|
|
return wxGetApp().app_config;
|
2018-02-22 10:12:29 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 08:44:53 +00:00
|
|
|
wxString from_u8(const std::string &str)
|
2018-02-22 10:34:41 +00:00
|
|
|
{
|
|
|
|
return wxString::FromUTF8(str.c_str());
|
|
|
|
}
|
|
|
|
|
2018-09-19 08:34:21 +00:00
|
|
|
std::string into_u8(const wxString &str)
|
|
|
|
{
|
|
|
|
auto buffer_utf8 = str.utf8_str();
|
|
|
|
return std::string(buffer_utf8.data());
|
|
|
|
}
|
|
|
|
|
2019-01-02 14:11:05 +00:00
|
|
|
wxString from_path(const boost::filesystem::path &path)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
return wxString(path.string<std::wstring>());
|
|
|
|
#else
|
2019-01-07 18:17:10 +00:00
|
|
|
return from_u8(path.string<std::string>());
|
2019-01-02 14:11:05 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::filesystem::path into_path(const wxString &str)
|
|
|
|
{
|
|
|
|
return boost::filesystem::path(str.wx_str());
|
|
|
|
}
|
|
|
|
|
2018-04-09 15:03:37 +00:00
|
|
|
void about()
|
|
|
|
{
|
|
|
|
AboutDialog dlg;
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|
2018-05-21 19:04:03 +00:00
|
|
|
void desktop_open_datadir_folder()
|
2018-06-04 07:07:29 +00:00
|
|
|
{
|
2018-05-21 20:10:38 +00:00
|
|
|
// Execute command to open a file explorer, platform dependent.
|
2018-06-04 07:07:29 +00:00
|
|
|
// FIXME: The const_casts aren't needed in wxWidgets 3.1, remove them when we upgrade.
|
|
|
|
|
|
|
|
const auto path = data_dir();
|
2018-05-21 19:04:03 +00:00
|
|
|
#ifdef _WIN32
|
2019-01-07 18:17:10 +00:00
|
|
|
const wxString widepath = from_u8(path);
|
2018-06-04 07:07:29 +00:00
|
|
|
const wchar_t *argv[] = { L"explorer", widepath.GetData(), nullptr };
|
|
|
|
::wxExecute(const_cast<wchar_t**>(argv), wxEXEC_ASYNC, nullptr);
|
2018-05-21 19:04:03 +00:00
|
|
|
#elif __APPLE__
|
2018-06-04 07:07:29 +00:00
|
|
|
const char *argv[] = { "open", path.data(), nullptr };
|
|
|
|
::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr);
|
2018-05-21 19:04:03 +00:00
|
|
|
#else
|
2018-06-04 07:07:29 +00:00
|
|
|
const char *argv[] = { "xdg-open", path.data(), nullptr };
|
|
|
|
|
|
|
|
// Check if we're running in an AppImage container, if so, we need to remove AppImage's env vars,
|
|
|
|
// because they may mess up the environment expected by the file manager.
|
|
|
|
// Mostly this is about LD_LIBRARY_PATH, but we remove a few more too for good measure.
|
|
|
|
if (wxGetEnv("APPIMAGE", nullptr)) {
|
|
|
|
// We're running from AppImage
|
|
|
|
wxEnvVariableHashMap env_vars;
|
|
|
|
wxGetEnvMap(&env_vars);
|
|
|
|
|
|
|
|
env_vars.erase("APPIMAGE");
|
|
|
|
env_vars.erase("APPDIR");
|
|
|
|
env_vars.erase("LD_LIBRARY_PATH");
|
|
|
|
env_vars.erase("LD_PRELOAD");
|
|
|
|
env_vars.erase("UNION_PRELOAD");
|
|
|
|
|
|
|
|
wxExecuteEnv exec_env;
|
|
|
|
exec_env.env = std::move(env_vars);
|
|
|
|
|
|
|
|
wxString owd;
|
|
|
|
if (wxGetEnv("OWD", &owd)) {
|
|
|
|
// This is the original work directory from which the AppImage image was run,
|
|
|
|
// set it as CWD for the child process:
|
|
|
|
exec_env.cwd = std::move(owd);
|
|
|
|
}
|
|
|
|
|
|
|
|
::wxExecute(const_cast<char**>(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<char**>(argv), wxEXEC_ASYNC, nullptr, nullptr);
|
|
|
|
}
|
2018-05-21 20:10:38 +00:00
|
|
|
#endif
|
2018-03-12 15:52:21 +00:00
|
|
|
}
|
|
|
|
|
2015-12-04 20:25:45 +00:00
|
|
|
} }
|