More misc functions (used to live as static functions in Slic3r::GUI perl file).

Passing -DVAR_ABS and -DVAR_ABS_PATH=/path/to/slic3r/var on compile redirects where Slic3r expects to find its var directory.
This commit is contained in:
Joseph Lenox 2018-04-28 18:15:16 -05:00 committed by Joseph Lenox
parent c1649c4dcf
commit 11716e0f11
2 changed files with 59 additions and 4 deletions

View File

@ -1,5 +1,8 @@
#include "misc_ui.hpp"
#include <wx/stdpaths.h>
#include <wx/msgdlg.h>
#include <exception>
namespace Slic3r { namespace GUI {
@ -14,11 +17,18 @@ void check_version(bool manual) {
#endif
const wxString var(const wxString& in) {
// TODO replace center string with path to VAR in actual distribution later
if (VAR_ABS) {
return VAR_ABS_PATH + "/" + in;
} else {
return bin() + VAR_REL + "/" + in;
}
}
const wxString bin() {
wxFileName f(wxStandardPaths::Get().GetExecutablePath());
wxString appPath(f.GetPath());
// replace center string with path to VAR in actual distribution later
return appPath + "/../var/" + in;
return appPath;
}
/// Returns the path to Slic3r's default user data directory.
@ -28,7 +38,6 @@ const wxString home(const wxString& in) {
return wxGetHomeDir() + "/." + in + "/";
}
wxString decode_path(const wxString& in) {
// TODO Stub
return in;
@ -38,6 +47,21 @@ wxString encode_path(const wxString& in) {
// TODO Stub
return in;
}
void show_error(wxWindow* parent, const wxString& message) {
wxMessageDialog(parent, message, _("Error"), wxOK | wxICON_ERROR).ShowModal();
}
void show_info(wxWindow* parent, const wxString& message, const wxString& title = _("Notice")) {
wxMessageDialog(parent, message, title, wxOK | wxICON_INFORMATION).ShowModal();
}
void fatal_error(wxWindow* parent, const wxString& message) {
show_error(parent, message);
throw std::runtime_error(message.ToStdString());
}
/*
sub append_submenu {
my ($self, $menu, $string, $description, $submenu, $id, $icon) = @_;

View File

@ -29,16 +29,47 @@ constexpr bool isDev = true;
constexpr bool isDev = false;
#endif
/// Mostly useful for Linux distro maintainers, this will change where Slic3r assumes
/// its ./var directory lives (where its art assets are).
/// Define VAR_ABS and VAR_ABS_PATH
#ifndef VAR_ABS
#define VAR_ABS false
#else
#define VAR_ABS true
#endif
#ifndef VAR_ABS_PATH
#define VAR_ABS_PATH "/usr/share/Slic3r/var"
#endif
#ifndef VAR_REL // Redefine on compile
#define VAR_REL L"/../var"
#endif
/// Performs a check via the Internet for a new version of Slic3r.
/// If this version of Slic3r was compiled with -DSLIC3R_DEV, check the development
/// space instead of release.
void check_version(bool manual = false);
/// Provides a path to Slic3r's var dir.
const wxString var(const wxString& in);
/// Provide a path to where Slic3r exec'd from.
const wxString bin();
/// Always returns path to home directory.
const wxString home(const wxString& in = "Slic3r");
/// Shows an error messagebox
void show_error(wxWindow* parent, const wxString& message);
/// Shows an info messagebox.
void show_info(wxWindow* parent, const wxString& message, const wxString& title);
/// Show an error messagebox and then throw an exception.
void fatal_error(wxWindow* parent, const wxString& message);
template <typename T>
void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T lambda, int id = wxID_ANY, const wxString& icon = "", const wxString& accel = "") {
wxMenuItem* tmp = menu->Append(wxID_ANY, name, help);