mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-10-04 21:06:32 +08:00
Refactor to use wxFileName instead of boost::filesystem
This commit is contained in:
parent
6e80e73a3a
commit
af791ccd97
@ -5,17 +5,13 @@
|
|||||||
|
|
||||||
#include "Dialogs/PresetEditor.hpp"
|
#include "Dialogs/PresetEditor.hpp"
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
|
|
||||||
using namespace std::literals::string_literals;
|
using namespace std::literals::string_literals;
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
Preset::Preset(std::string load_dir, std::string filename, preset_t p) : group(p), file(filename), dir(load_dir) {
|
Preset::Preset(std::string load_dir, std::string filename, preset_t p) : group(p), _file(wxFileName(load_dir, filename)) {
|
||||||
// find last .ini at the end of the filename.
|
this->name = this->_file.GetName();
|
||||||
std::regex ini (".ini[ ]*$");
|
|
||||||
this->name = std::regex_replace(filename, ini, "$1");
|
|
||||||
|
|
||||||
this->_dirty_config = std::make_shared<Slic3r::Config>();
|
this->_dirty_config = std::make_shared<Slic3r::Config>();
|
||||||
this->_config = std::make_shared<Slic3r::Config>();
|
this->_config = std::make_shared<Slic3r::Config>();
|
||||||
@ -56,11 +52,10 @@ namespace Slic3r { namespace GUI {
|
|||||||
|
|
||||||
if (this->default_preset) {
|
if (this->default_preset) {
|
||||||
this->_config = Slic3r::Config::new_from_defaults(keys);
|
this->_config = Slic3r::Config::new_from_defaults(keys);
|
||||||
} else if (this->file.size() > 0) {
|
} else if (this->_file.HasName() > 0) {
|
||||||
filesystem::path full_path { this->dir + "/"s + this->file };
|
|
||||||
config_ptr config = Slic3r::Config::new_from_defaults(keys);
|
config_ptr config = Slic3r::Config::new_from_defaults(keys);
|
||||||
if (filesystem::exists(full_path)) {
|
if (this->file_exists()) {
|
||||||
auto external_config { Slic3r::Config::new_from_ini(full_path.string()) };
|
auto external_config { Slic3r::Config::new_from_ini(this->_file.GetFullPath().ToStdString()) };
|
||||||
// Apply preset values on top of defaults
|
// Apply preset values on top of defaults
|
||||||
config = Slic3r::Config::new_from_defaults(keys);
|
config = Slic3r::Config::new_from_defaults(keys);
|
||||||
config->apply_with_defaults(external_config, keys);
|
config->apply_with_defaults(external_config, keys);
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
#include <wx/filefn.h>
|
#include <wx/filefn.h>
|
||||||
|
#include <wx/filename.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
@ -37,7 +38,7 @@ class Preset {
|
|||||||
public:
|
public:
|
||||||
friend class PresetEditor;
|
friend class PresetEditor;
|
||||||
preset_t group;
|
preset_t group;
|
||||||
std::string name {""};
|
wxString name {""};
|
||||||
bool external {false};
|
bool external {false};
|
||||||
|
|
||||||
/// Preset
|
/// Preset
|
||||||
@ -46,12 +47,13 @@ public:
|
|||||||
/// Search the compatible_printers config option list for this preset name.
|
/// Search the compatible_printers config option list for this preset name.
|
||||||
/// Assume that Printer configs are compatible with other Printer configs
|
/// Assume that Printer configs are compatible with other Printer configs
|
||||||
bool compatible(std::string printer_name) { return true; }
|
bool compatible(std::string printer_name) { return true; }
|
||||||
|
bool compatible(const wxString& printer_name) { if (group == preset_t::Printer) return true; return true; }
|
||||||
bool compatible(const Preset& other) {return (this->group == preset_t::Printer || (compatible(other.name) && other.group == preset_t::Printer));}
|
bool compatible(const Preset& other) {return (this->group == preset_t::Printer || (compatible(other.name) && other.group == preset_t::Printer));}
|
||||||
|
|
||||||
/// Format the name appropriately.
|
/// Format the name appropriately.
|
||||||
wxString dropdown_name() { return (this->dirty() ? wxString(this->name) << " " << _("(modified)") : wxString(this->name)); }
|
wxString dropdown_name() { return (this->dirty() ? this->name << " " << _("(modified)") : this->name); }
|
||||||
|
|
||||||
bool file_exists() const { return wxFileExists(this->name); }
|
bool file_exists() const { return this->_file.IsFileReadable(); }
|
||||||
|
|
||||||
bool prompt_unsaved_changes(wxWindow* parent);
|
bool prompt_unsaved_changes(wxWindow* parent);
|
||||||
|
|
||||||
@ -101,10 +103,7 @@ private:
|
|||||||
config_ptr _dirty_config { nullptr };
|
config_ptr _dirty_config { nullptr };
|
||||||
|
|
||||||
/// Underlying filename for this preset config
|
/// Underlying filename for this preset config
|
||||||
std::string file {""};
|
wxFileName _file {};
|
||||||
|
|
||||||
/// dirname for the file.
|
|
||||||
std::string dir {""};
|
|
||||||
|
|
||||||
/// All the options owned by the corresponding editor
|
/// All the options owned by the corresponding editor
|
||||||
t_config_option_keys _group_keys() const;
|
t_config_option_keys _group_keys() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user