GalleryDialog: Changes the paths to the system and custom galleries

This commit is contained in:
YuSanka 2021-07-14 17:41:37 +02:00
parent 8f5715b0d7
commit 4257ffddde
18 changed files with 25 additions and 20 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

View File

@ -661,7 +661,7 @@ bool CLI::setup(int argc, char **argv)
set_resources_dir(path_resources.string());
set_var_dir((path_resources / "icons").string());
set_local_dir((path_resources / "localization").string());
set_gallery_dir((path_resources / "gallery").string());
set_sys_shapes_dir((path_resources / "shapes").string());
// Parse all command line options into a DynamicConfig.
// If any option is unsupported, print usage and abort immediately.

View File

@ -159,6 +159,7 @@ void PresetBundle::setup_directories()
data_dir,
data_dir / "vendor",
data_dir / "cache",
data_dir / "shapes",
#ifdef SLIC3R_PROFILE_USE_PRESETS_SUBDIR
// Store the print/filament/printer presets into a "presets" directory.
data_dir / "presets",

View File

@ -46,9 +46,9 @@ void set_local_dir(const std::string &path);
const std::string& localization_dir();
// Set a path with shapes gallery files.
void set_gallery_dir(const std::string &path);
// Return a full path to the gallery directory.
const std::string& gallery_dir();
void set_sys_shapes_dir(const std::string &path);
// Return a full path to the system shapes gallery directory.
const std::string& sys_shapes_dir();
// Set a path with preset files.
void set_data_dir(const std::string &path);

View File

@ -175,16 +175,16 @@ const std::string& localization_dir()
return g_local_dir;
}
static std::string g_gallery_dir;
static std::string g_sys_shapes_dir;
void set_gallery_dir(const std::string &dir)
void set_sys_shapes_dir(const std::string &dir)
{
g_gallery_dir = dir;
g_sys_shapes_dir = dir;
}
const std::string& gallery_dir()
const std::string& sys_shapes_dir()
{
return g_gallery_dir;
return g_sys_shapes_dir;
}
// Translate function callback, to call wxWidgets translate function to convert non-localized UTF8 string to a localized one.

View File

@ -160,7 +160,7 @@ static void add_lock(wxImage& image)
#ifdef __APPLE__
lock_sz /= mac_max_scaling_factor();
#endif
wxBitmap bmp = create_scaled_bitmap("lock", nullptr, 22);
wxBitmap bmp = create_scaled_bitmap("lock", nullptr, lock_sz);
wxImage lock_image = bmp.ConvertToImage();
if (!lock_image.IsOk() || lock_image.GetWidth() == 0 || lock_image.GetHeight() == 0)
@ -214,12 +214,14 @@ static void add_default_image(wxImageList* img_list, bool is_system)
static fs::path get_dir(bool sys_dir)
{
return fs::absolute(fs::path(gallery_dir()) / (sys_dir ? "system" : "custom")).make_preferred();
if (sys_dir)
return fs::absolute(fs::path(sys_shapes_dir())).make_preferred();
return fs::absolute(fs::path(data_dir()) / "shapes").make_preferred();
}
static bool custom_exists()
{
return fs::exists(fs::absolute(fs::path(gallery_dir()) / "custom").make_preferred());
return fs::exists(get_dir(false));
}
static std::string get_dir_path(bool sys_dir)
@ -382,20 +384,22 @@ void GalleryDialog::add_custom_shapes(wxEvent& event)
void GalleryDialog::del_custom_shapes(wxEvent& event)
{
auto dest_dir = get_dir(false);
auto custom_dir = get_dir(false);
for (const Item& item : m_selected_items) {
std::string filename = item.name + ".stl";
if (!fs::exists(dest_dir / filename))
continue;
auto remove_file = [custom_dir](const std::string& name) {
if (!fs::exists(custom_dir / name))
return;
try {
fs::remove(dest_dir / filename);
fs::remove(custom_dir / name);
}
catch (fs::filesystem_error const& e) {
std::cerr << e.what() << '\n';
return;
}
};
for (const Item& item : m_selected_items) {
remove_file(item.name + ".stl");
remove_file(item.name + ".png");
}
update();