mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-09-16 17:06:54 +08:00
UIManager: Added selection of the loaded archive (UI only)
+ Fixed state of selections till changes weren't saved
This commit is contained in:
parent
030a6c9f3b
commit
1cf8d0390d
@ -360,7 +360,7 @@ bool PresetArchiveDatabase::set_selected_repositories(const std::vector<std::str
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PresetArchiveDatabase::add_local_archive(const boost::filesystem::path path, std::string& msg)
|
||||
std::string PresetArchiveDatabase::add_local_archive(const boost::filesystem::path path, std::string& msg)
|
||||
{
|
||||
if (auto it = std::find_if(m_archive_repositories.begin(), m_archive_repositories.end(), [path](const std::unique_ptr<const ArchiveRepository>& ptr) {
|
||||
return ptr->get_manifest().source_path == path;
|
||||
@ -368,21 +368,21 @@ bool PresetArchiveDatabase::add_local_archive(const boost::filesystem::path path
|
||||
{
|
||||
msg = GUI::format(_L("Failed to add local archive %1%. Path already used."), path);
|
||||
BOOST_LOG_TRIVIAL(error) << msg;
|
||||
return false;
|
||||
return std::string();
|
||||
}
|
||||
std::string uuid = get_next_uuid();
|
||||
ArchiveRepository::RepositoryManifest header_data;
|
||||
if (!extract_local_archive_repository(uuid, path, m_unq_tmp_path, header_data)) {
|
||||
msg = GUI::format(_L("Failed to extract local archive %1%."), path);
|
||||
BOOST_LOG_TRIVIAL(error) << msg;
|
||||
return false;
|
||||
return std::string();
|
||||
}
|
||||
// Solve if it can be set true first.
|
||||
m_selected_repositories_uuid[uuid] = false;
|
||||
m_archive_repositories.emplace_back(std::make_unique<LocalArchiveRepository>(uuid, std::move(header_data)));
|
||||
|
||||
save_app_manifest_json();
|
||||
return true;
|
||||
return uuid;
|
||||
}
|
||||
void PresetArchiveDatabase::remove_local_archive(const std::string& uuid)
|
||||
{
|
||||
|
@ -119,7 +119,7 @@ public:
|
||||
void read_server_manifest(const std::string& json_body);
|
||||
const std::map<std::string, bool>& get_selected_repositories_uuid() const { assert(m_selected_repositories_uuid.size() == m_archive_repositories.size()); return m_selected_repositories_uuid; }
|
||||
bool set_selected_repositories(const std::vector<std::string>& used_uuids, std::string& msg);
|
||||
bool add_local_archive(const boost::filesystem::path path, std::string& msg);
|
||||
std::string add_local_archive(const boost::filesystem::path path, std::string& msg);
|
||||
void remove_local_archive(const std::string& uuid);
|
||||
private:
|
||||
void load_app_manifest_json();
|
||||
|
@ -52,52 +52,37 @@ UIManager::UIManager(wxWindow* parent, PresetArchiveDatabase* pad, int em) :
|
||||
|
||||
m_main_sizer->Add(m_offline_sizer, 0, wxALL, 2 * em);
|
||||
|
||||
fill_entries();
|
||||
fill_entries(true);
|
||||
fill_grids();
|
||||
}
|
||||
|
||||
void UIManager::fill_entries()
|
||||
void UIManager::fill_entries(bool init_selection/* = false*/)
|
||||
{
|
||||
m_online_entries.clear();
|
||||
m_offline_entries.clear();
|
||||
|
||||
m_online_selections.clear();
|
||||
m_offline_selections.clear();
|
||||
|
||||
const ArchiveRepositoryVector& archs = m_pad->get_archive_repositories();
|
||||
const std::map<std::string, bool>& selected_repos = m_pad->get_selected_repositories_uuid();
|
||||
|
||||
for (const auto& archive : archs) {
|
||||
const auto& data = archive->get_manifest();
|
||||
const std::string& uuid = archive->get_uuid();
|
||||
auto sel_it = selected_repos.find(uuid);
|
||||
assert(sel_it != selected_repos.end());
|
||||
if (init_selection && sel_it->second)
|
||||
m_selected_uuids.emplace(uuid);
|
||||
|
||||
const bool is_selected = m_selected_uuids.find(uuid) != m_selected_uuids.end();
|
||||
const auto& data = archive->get_manifest();
|
||||
|
||||
if (data.source_path.empty()) {
|
||||
// online repo
|
||||
auto selected_it = selected_repos.find(archive->get_uuid());
|
||||
assert(selected_it != selected_repos.end());
|
||||
bool is_selected = selected_it->second;
|
||||
m_online_entries.push_back({is_selected, archive->get_uuid(), data.name, data.description, data.visibility });
|
||||
if (is_selected)
|
||||
m_online_selections.emplace(archive->get_uuid());
|
||||
}
|
||||
m_online_entries.push_back({ is_selected, uuid, data.name, data.description, data.visibility });
|
||||
}
|
||||
else {
|
||||
// offline repo
|
||||
auto selected_it = selected_repos.find(archive->get_uuid());
|
||||
assert(selected_it != selected_repos.end());
|
||||
bool is_selected = selected_it->second;
|
||||
m_offline_entries.push_back({is_selected, archive->get_uuid(), data.name, data.description, data.source_path.filename().string(), fs::exists(data.source_path)});
|
||||
if (is_selected)
|
||||
m_offline_selections.emplace(archive->get_uuid());
|
||||
m_offline_entries.push_back({ is_selected, uuid, data.name, data.description, data.source_path.filename().string(), fs::exists(data.source_path) });
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 // ysFIXME_delete
|
||||
// Next code is just for testing
|
||||
|
||||
if (m_offline_entries.empty())
|
||||
m_offline_entries = {
|
||||
{true, "333", "Prusa AFS" , "Prusa FDM Prusa FDM Prusa FDM" , "/path/field/file1.zip", false},
|
||||
{false, "444", "Prusa Trilab" , "Prusa sla Prusa sla Prusa sla" , "/path/field/file2.zip", true},
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -129,9 +114,9 @@ void UIManager::fill_grids()
|
||||
CheckBox::SetValue(chb, entry.use);
|
||||
chb->Bind(wxEVT_CHECKBOX, [this, chb, &entry](wxCommandEvent e) {
|
||||
if (CheckBox::GetValue(chb))
|
||||
m_online_selections.emplace(entry.id);
|
||||
m_selected_uuids.emplace(entry.id);
|
||||
else
|
||||
m_online_selections.erase(entry.id);
|
||||
m_selected_uuids.erase(entry.id);
|
||||
});
|
||||
add(chb);
|
||||
|
||||
@ -169,9 +154,9 @@ void UIManager::fill_grids()
|
||||
CheckBox::SetValue(chb, entry.use);
|
||||
chb->Bind(wxEVT_CHECKBOX, [this, chb, &entry](wxCommandEvent e) {
|
||||
if (CheckBox::GetValue(chb))
|
||||
m_offline_selections.emplace(entry.id);
|
||||
m_selected_uuids.emplace(entry.id);
|
||||
else
|
||||
m_offline_selections.erase(entry.id);
|
||||
m_selected_uuids.erase(entry.id);
|
||||
});
|
||||
add(chb);
|
||||
|
||||
@ -229,6 +214,7 @@ void UIManager::update()
|
||||
void UIManager::remove_offline_repos(const std::string& id)
|
||||
{
|
||||
m_pad->remove_local_archive(id);
|
||||
m_selected_uuids.erase(id);
|
||||
|
||||
if (wxDialog* dlg = dynamic_cast<wxDialog*>(m_parent)) {
|
||||
// Invalidate min_size for correct next Layout()
|
||||
@ -257,26 +243,25 @@ void UIManager::load_offline_repos()
|
||||
try {
|
||||
fs::path input_path = fs::path(input_file);
|
||||
std::string msg;
|
||||
if (!m_pad->add_local_archive(input_path, msg))
|
||||
{
|
||||
std::string uuid = m_pad->add_local_archive(input_path, msg);
|
||||
if (uuid.empty()) {
|
||||
ErrorDialog(m_parent, msg, false).ShowModal();
|
||||
}
|
||||
else {
|
||||
m_selected_uuids.emplace(uuid);
|
||||
update();
|
||||
}
|
||||
}
|
||||
catch (fs::filesystem_error const& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
bool UIManager::set_selected_repositories()
|
||||
{
|
||||
std::vector<std::string> used_ids;
|
||||
for (const std::string& id : m_online_selections)
|
||||
used_ids.push_back(id);
|
||||
for (const std::string& id : m_offline_selections)
|
||||
used_ids.push_back(id);
|
||||
std::copy(m_selected_uuids.begin(), m_selected_uuids.end(), std::back_inserter(used_ids));
|
||||
|
||||
std::string msg;
|
||||
if (m_pad->set_selected_repositories(used_ids, msg))
|
||||
|
@ -50,10 +50,9 @@ class UIManager
|
||||
std::vector<OnlineEntry> m_online_entries;
|
||||
std::vector<OfflineEntry> m_offline_entries;
|
||||
|
||||
std::set<std::string> m_online_selections;
|
||||
std::set<std::string> m_offline_selections;
|
||||
std::set<std::string> m_selected_uuids;
|
||||
|
||||
void fill_entries();
|
||||
void fill_entries(bool init_selection = false);
|
||||
void fill_grids();
|
||||
|
||||
void update();
|
||||
|
Loading…
x
Reference in New Issue
Block a user