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

Prompt when importing conflicting asset names #7177

Open
Samq64 opened this issue Feb 17, 2024 · 13 comments · May be fixed by #7232
Open

Prompt when importing conflicting asset names #7177

Samq64 opened this issue Feb 17, 2024 · 13 comments · May be fixed by #7232
Labels
new addon Related to new addons to this extension. `scope: addons` should still be added. scope: addon Related to one or multiple addons type: enhancement New feature for the project

Comments

@Samq64
Copy link
Member

Samq64 commented Feb 17, 2024

Why this would be helpful

When importing a bunch of assets into a project the user might not want them to be renamed automatically.

How this addon works

The addon would prompt the user to cancel/skip, replace or rename the asset with a textbox that is auto filled with what it would have been renamed to without the addon. Importing multiple files would add a checkbox to apply to all.

Basically just a file manager conflict dialog.

Possible alternatives

No response

Additional context

Closed PR: #7168

@Samq64 Samq64 added type: enhancement New feature for the project new addon Related to new addons to this extension. `scope: addons` should still be added. scope: addon Related to one or multiple addons labels Feb 17, 2024
@Samq64 Samq64 linked a pull request Feb 17, 2024 that will close this issue
@Joeclinton1
Copy link
Contributor

Joeclinton1 commented Feb 22, 2024

I will begin implementing this addon today hopefully.

@Joeclinton1
Copy link
Contributor

Joeclinton1 commented Feb 22, 2024

"a textbox that is auto filled with what it would have been renamed to without the addon", this doesn't make sense when uploading multiple files.

I suggest no textbox and instead there's just an option to rename.

@Joeclinton1
Copy link
Contributor

Joeclinton1 commented Feb 22, 2024

Here's my research notes on how everything works:

  1. The relevant code for the renaming is:
    a. vm.addCostume() -> target.addCostume() ->sprite.addCostumeAt() and target.addSound()
    b. this occurs at the VM level. This makes it difficult to modify the behaviour per costume.
  2. The code that calls these occurs higher up in the GUI level at:
    a. handleNewCostume and handleSoundUpload
  3. These are called by fileUploader during:
    a. here for costumes and here for sounds

I really don't want the addon to do it's own check for duplicates, as that adds redundancy. If we can use the result of the VM's name duplication check directly it will be better. With this in mind, here's my idea:

pseudo code:

conflictQueue = []

// this called higher up and we don't want to pollute it
// for costume in costumes {
// file.onLoad(()=>createNewCostume(costume);
// }


function addCostumeAt(costume, choice=None) {
// Check for renames.
if (renameRequired && choice == None) {
    const conflict = (args, (choice) =>{addCostumeAt(costume, choice)})
    conflictQueue.push(conflict);
    if(conflictQueue.length==1){
       dequeueConflictModal();
    }    
    return true;
} else if ( renameRequired){
   switch (choice) {
    case 'skip':
        // Skip this costume
        return;
    case 'replace':
        // Delete conflicting and proceed
        break;
    default:
        pass;
   }
}
// Rest of logic for costume creation
}

function dequeueConflictModal(callback) {
[args, callback] = conflictQueue.shift()
// Create and display modal using 'args' which calls 'callback' with choice when user submits dialog
if(conflictQueue){
  dequeueConflictModal();
}
}

@mybearworld
Copy link
Contributor

This can also happen when importing sprites, and also when renaming any costumes.

A much simpler way that wouldn't require overriding all those functions would be to override StringUtil.unusedName, but I don't think that that's accessible from the outside.

@Joeclinton1
Copy link
Contributor

Joeclinton1 commented Feb 23, 2024

This can also happen when importing sprites, and also when renaming any costumes.

A much simpler way that wouldn't require overriding all those functions would be to override StringUtil.unusedName, but I don't think that that's accessible from the outside.

Even we could pollute it, it's not enough. The very act of replacing requires us to delete an existing costume, or alternatively to change it's costume object instead of adding a new one but either way polluting this isn't going to solve that.

I am not going to do this for importing sprites as it's too much work and not useful. Same goes for renaming.

@mybearworld
Copy link
Contributor

The very act of replacing requires us to delete an existing costume, or alternatively to change it's costume object instead of adding a new one but either way polluting this isn't going to solve that.

StringUtil.unusedName is called in every context where a costume is created or changed. We wouldn't need to replace any costume objects it this were possible.

@Joeclinton1
Copy link
Contributor

The very act of replacing requires us to delete an existing costume, or alternatively to change it's costume object instead of adding a new one but either way polluting this isn't going to solve that.

StringUtil.unusedName is called in every context where a costume is created or changed. We wouldn't need to replace any costume objects it this were possible.

I don't think you understand what is required here. We must replace the costume/sound object. That is just a dumb util function to get the first unused name in a list of names. It's clearly the wrong function to pollute.

@Joeclinton1
Copy link
Contributor

Code is written, will begin debugging and hopefully testing tomorrow.

@mybearworld
Copy link
Contributor

Am I misunderstanding what this is about? Isn't this exactly about overriding StringUtil.unusedName's behavior? When a name is already used, it shouldn't fall back on adding 2 to it, but instead ask the user for a different name. Right?

@mxmou
Copy link
Member

mxmou commented Feb 23, 2024

Am I misunderstanding what this is about? Isn't this exactly about overriding StringUtil.unusedName's behavior? When a name is already used, it shouldn't fall back on adding 2 to it, but instead ask the user for a different name. Right?

The OP wants to be able to skip, replace or rename the asset. Overriding unusedName would only allow renaming.

@mybearworld
Copy link
Contributor

Am I misunderstanding what this is about? Isn't this exactly about overriding StringUtil.unusedName's behavior? When a name is already used, it shouldn't fall back on adding 2 to it, but instead ask the user for a different name. Right?

The OP wants to be able to skip, replace or rename the asset. Overriding unusedName would only allow renaming.

Ah, I see, sorry.

@Joeclinton1
Copy link
Contributor

Joeclinton1 commented Feb 24, 2024

The addon implementation is getting closer to done, but it's definitely far from easy like I first thought it would be.

@Joeclinton1
Copy link
Contributor

Joeclinton1 commented Feb 24, 2024

I just realized I need to be polluting vm.addCostume() and vm.addSound() instead of the lower level things since they'll break if they think a costume/sound has been added but it actually hasn't. Also I need to handle which costume to select if no costume was added, and when to call emitProjectChanged or emitTargetsUpdate

@Joeclinton1 Joeclinton1 linked a pull request Feb 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new addon Related to new addons to this extension. `scope: addons` should still be added. scope: addon Related to one or multiple addons type: enhancement New feature for the project
Projects
None yet
4 participants