Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate 3D model files #787

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jmwilson
Copy link
Contributor

The model map doesn't check for duplicate values, so you can add the same file several times, which seems like a bug.

Also, for packages that use multiple 3D models, it seems convenient to allow selecting multiple files in the chooser. Any chosen files that are already present get ignored.

Add Model allows multiple file selection
@@ -55,7 +97,8 @@ std::string ImpPackage::ask_3d_model_filename(const std::string &current_filenam
filter->add_pattern("*.STP");
chooser->add_filter(filter);
if (current_filename.size()) {
chooser->set_filename(Glib::build_filename(pool->get_base_path(), current_filename));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.gtk.org/gtk3/method.FileChooser.set_filename.html

says this should only be used in a save chooser, I found it caused problems with the directory defaulting to the last used directory instead of the model directory

Copy link
Member

@carrotIndustries carrotIndustries Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, for me it does work.

EDIT: only once...
EDIT2: nvm EDIT, different issue

@@ -83,16 +83,21 @@ ModelEditor::ModelEditor(ImpPackage &iimp, const UUID &iuu)

auto browse_button = Gtk::manage(new Gtk::Button("Browse…"));
browse_button->signal_clicked().connect([this, entry] {
Package::Model *model2 = nullptr;
if (imp.core_package.models.count(uu)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unable to a see a code path where imp.core_package.models[uu] goes away between the constructor and here, so I removed the check and directly use imp.core_package.models.at(uu). If the delete button is used then this button goes away too.

rel_names.push_back(rel_path);
}
if (std::none_of(rel_names.cbegin(), rel_names.cend(),
std::bind(std::string::empty, std::placeholders::_1))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails to build on all platforms and compiler versions in the CI. As far as i can tell what you're trying to do here is undefined behavior since you're trying to take the address of a standard library function: https://en.cppreference.com/w/cpp/language/extending_std

I suggest using a lambda function instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carrotIndustries looks like the CI is happy after switching to a lambda

@carrotIndustries
Copy link
Member

LGTM, i'd like to keep chooser->set_filename for now as this is somewhat separate from this improvement/bugfix.

@jmwilson
Copy link
Contributor Author

Hmm, I suspect it's a GTK issue with set_filename behaving broken on Windows but fine on Linux, since that's where I saw this behavior. If you want to strip it out, I'll do it but it seems like it gives better cross-platform behavior.

@carrotIndustries
Copy link
Member

To me at least the file picker defaulting to what's in the entry is part of a quality user experience.

If it doesn't work on windows, I think the best way around this is an #ifdef G_OS_WIN32 to get the best thing possible on all platforms.

@carrotIndustries
Copy link
Member

I think this a useful feature to have, but should be separated from the set_filename issue that can be discussed and fixed independently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants