mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-10-04 15:06:34 +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 <boost/filesystem.hpp>
|
||||
|
||||
using namespace std::literals::string_literals;
|
||||
using namespace boost;
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
Preset::Preset(std::string load_dir, std::string filename, preset_t p) : group(p), file(filename), dir(load_dir) {
|
||||
// find last .ini at the end of the filename.
|
||||
std::regex ini (".ini[ ]*$");
|
||||
this->name = std::regex_replace(filename, ini, "$1");
|
||||
Preset::Preset(std::string load_dir, std::string filename, preset_t p) : group(p), _file(wxFileName(load_dir, filename)) {
|
||||
this->name = this->_file.GetName();
|
||||
|
||||
this->_dirty_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) {
|
||||
this->_config = Slic3r::Config::new_from_defaults(keys);
|
||||
} else if (this->file.size() > 0) {
|
||||
filesystem::path full_path { this->dir + "/"s + this->file };
|
||||
} else if (this->_file.HasName() > 0) {
|
||||
config_ptr config = Slic3r::Config::new_from_defaults(keys);
|
||||
if (filesystem::exists(full_path)) {
|
||||
auto external_config { Slic3r::Config::new_from_ini(full_path.string()) };
|
||||
if (this->file_exists()) {
|
||||
auto external_config { Slic3r::Config::new_from_ini(this->_file.GetFullPath().ToStdString()) };
|
||||
// Apply preset values on top of defaults
|
||||
config = Slic3r::Config::new_from_defaults(keys);
|
||||
config->apply_with_defaults(external_config, keys);
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <wx/wx.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/filefn.h>
|
||||
#include <wx/filename.h>
|
||||
#endif
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
@ -37,7 +38,7 @@ class Preset {
|
||||
public:
|
||||
friend class PresetEditor;
|
||||
preset_t group;
|
||||
std::string name {""};
|
||||
wxString name {""};
|
||||
bool external {false};
|
||||
|
||||
/// Preset
|
||||
@ -46,12 +47,13 @@ public:
|
||||
/// Search the compatible_printers config option list for this preset name.
|
||||
/// Assume that Printer configs are compatible with other Printer configs
|
||||
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));}
|
||||
|
||||
/// 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);
|
||||
|
||||
@ -101,10 +103,7 @@ private:
|
||||
config_ptr _dirty_config { nullptr };
|
||||
|
||||
/// Underlying filename for this preset config
|
||||
std::string file {""};
|
||||
|
||||
/// dirname for the file.
|
||||
std::string dir {""};
|
||||
wxFileName _file {};
|
||||
|
||||
/// All the options owned by the corresponding editor
|
||||
t_config_option_keys _group_keys() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user