Duplicate and copy & paste slices#5049
Conversation
7c4829d to
28a22c0
Compare
|
It works great! Just a couple of subjetive design comments (i.e. optional):
|
28a22c0 to
f787656
Compare
ckaiser
left a comment
There was a problem hiding this comment.
Duplicating with the right click menu works, but trying to use Ctrl+C or the copy menu does not for me, from what I can see, Site::selectedSlices() ends up being 0 when called in get_selected_slices - not sure if it's calling the wrong Site or before it gets populated or what exactly is going on there.
Left some comments over some localization/style stuff as well.
| doc->notifyBeforeSlicesDuplication(); | ||
| for (auto* s : selectedSlices) { | ||
| Slice* slice = new Slice(*s); | ||
| slice->setName(slice->name() + " Copy"); |
There was a problem hiding this comment.
This should probably be localized with "{} Copy"
| editor->clearSlicesSelection(); | ||
| for (auto& s : slices) { | ||
| Slice* slice = new Slice(s); | ||
| slice->setName(slice->name() + " Copy"); |
| if (!m_editor->selectSliceBox(bounds) && (bounds.w > 1 || bounds.h > 1)) { | ||
| Slice* slice = new Slice; | ||
| slice->setName(getUniqueSliceName()); | ||
| slice->setName(get_unique_slice_name(m_sprite)); |
There was a problem hiding this comment.
In the end now this ends up being only used here, seems like it could still be just a private member instead of a part of the utils, which might make the addition of the extra file and translation unit harder to justify since it could also just be a static function like Slice::getSelectedFromSite but that's just a style thing.
There was a problem hiding this comment.
About get_unique_slice_name, I think I used it in other places at some point, but maybe after some changes it ended up being used in just that place...so yeah, I will move that function back to the private scope.
About replacing get_selected_slices with a static Slice::getSelectedFromSite function, sure, I'll do it.
There was a problem hiding this comment.
Okay, I've just recalled why I moved the getUniqueSliceName to an utility function. It didn't make sense to me that the ToolLoopImpl class provided that function. So, my reasoning was that moving it to another translation unit would remove some noise from the ToolLoopImpl and reduce its size (speaking of lines of code) a bit.
So now I would prefer to keep the get_unique_slice_name function as an utility function in a separate translation unit. But I'm open to change my mind if you feel strongly about this.
There was a problem hiding this comment.
I might consider moving it as another static member of Slice, something like: Slice::makeUniqueName()maybe?
There was a problem hiding this comment.
I cannot convert the get_selected_slices function into Slice::getSelectedFromSite because the Site class belongs to the app module (src/app/site.h) and the Slice class belongs to the doc module (src/doc/slice.h), and the doc module doesn't depend on the app module. Hence the Slice class can't see the Site class.
I have also found that the doc module doesn't depend on the fmt lib, which the get_unique_slice_name uses (I know I could easily avoid using the fmt library but I prefer to leave these functions in the app module).
So I think I will leave both functions as is.
I just tried in macOS and it works both ways, will try in Windows to see if there is an issue there. Take into account that when using the Ctrl+C and Ctrl+V or copy menu and then paste menu, the copied slices are pasted in the same position as the original ones, not displaced as it happens when using the EDIT: See my comment...I thought it worked on macOS because I didn't realize that my mouse pointer was not over the sprite editor... |
10b4141 to
c4e305d
Compare
|
Force pushed a rebased version with the latest from beta. So, there are no changes yet. |
|
I can confirm that in Windows Ctrl+C doesn't copy the slices. However, the copy menu and paste menu do work as expected. Also, I've tried to copy the slices with the menu and paste them with Ctrl+V and it worked as well. EDIT: I was wrong. Actually it works the same in macOS and Windows. The thing is that the Ctrl key (Cmd key in macOS) is bound to the |
|
I'm going to test this PR. About the i18n of |
In this particular case I'm using the message for when a slice is copied. And the parameter is the name of the slice. Obviously we are not going to determine the name's gender to show the correct variant. So I guess you mean in the case the However, if we use Let me know what do you think we should do about this. I have a fix in mind for using the gender based templates, but I think it doesn't worth the additional complexity. |
Doing this kind of work ourselves is pretty intense, it's why projects like Fluent exist. I don't think we have enough text to justify it, could just be a matter of not using variables for this kind of thing and instead just having different strings for each ( |
|
As @ckaiser, for our case, we can have the string for each case. If in a future we consider that it’s getting out of hand, we could adopt some library like Fluent (didn’t know about that project, I remember some pluralization features from the old gettext library but never used it). |
Probably I was confused by the other PR, but as you said, it might work if it is the copy of a "name". Probably I got confused by the default name of things (later, slice, etc). Not sure if it can work in a generic form. |
|
@ckaiser exactly, that is the easiest way when we don't have to parameterize the text. Unfortunately, I have to.
No worries. I'm not sure either, but I think it is the only way to say that we copied something with a name. In the other PR (#5167) I was using it for when the user duplicates a sprite (the parameter is the name of the file) and when the user duplicates a layer (the parameter is the name of the layer). Is it okay to keep this as is then? Or should I revert the 000f163 change? |
We can keep it, but you should amend that commit, as the string is in the |
000f163 to
4a70697
Compare
|
I've just amended the last commit and rebased my branch. |
aseprite-bot
left a comment
There was a problem hiding this comment.
clang-tidy made some suggestions
|
|
||
| void DuplicateSliceCommand::onLoadParams(const Params& params) | ||
| { | ||
| std::string id = params.get("id"); |
There was a problem hiding this comment.
warning: variable 'id' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]
| std::string id = params.get("id"); | |
| std::string const id = params.get("id"); |
| selectedSlices.push_back(reader.sprite()->slices().getById(m_sliceId)); | ||
| } | ||
|
|
||
| ContextWriter writer(context); |
There was a problem hiding this comment.
warning: variable 'writer' of type 'ContextWriter' can be declared 'const' [misc-const-correctness]
| ContextWriter writer(context); | |
| ContextWriter const writer(context); |
| sliceName = selectedSlices[0]->name(); | ||
|
|
||
| StatusBar::instance()->invalidate(); | ||
| if (!sliceName.empty()) { |
There was a problem hiding this comment.
warning: if with identical then and else branches [bugprone-branch-clone]
if (!sliceName.empty()) {
^Additional context
src/app/commands/cmd_duplicate_slice.cpp:109: else branch starts here
else {
^|
|
||
| void Doc::notifyBeforeSlicesDuplication() | ||
| { | ||
| DocEvent ev(this); |
There was a problem hiding this comment.
warning: variable 'ev' of type 'DocEvent' can be declared 'const' [misc-const-correctness]
| DocEvent ev(this); | |
| DocEvent const ev(this); |
| @@ -510,6 +512,8 @@ bool DocView::onCanCopy(Context* ctx) | |||
| return true; | |||
There was a problem hiding this comment.
warning: repeated branch body in conditional chain [bugprone-branch-clone]
return true;
^Additional context
src/app/ui/doc_view.cpp:511: end of the original
return true;
^src/app/ui/doc_view.cpp:513: clone 1 starts here
return true;
^src/app/ui/doc_view.cpp:515: clone 2 starts here
return true;
^| m_state->onBeforeLayerEditableChange(this, ev.layer(), newState); | ||
| } | ||
|
|
||
| void Editor::onBeforeSlicesDuplication(DocEvent& ev) |
There was a problem hiding this comment.
warning: parameter 'ev' is unused [misc-unused-parameters]
| void Editor::onBeforeSlicesDuplication(DocEvent& ev) | |
| void Editor::onBeforeSlicesDuplication(DocEvent& /*ev*/) |
| m_data->picks = picks; | ||
| } | ||
|
|
||
| void Clipboard::copySlices(const std::vector<Slice*> slices) |
There was a problem hiding this comment.
warning: method 'copySlices' can be made static [readability-convert-member-functions-to-static]
| void Clipboard::copySlices(const std::vector<Slice*> slices) | |
| static void Clipboard::copySlices(const std::vector<Slice*> slices) |
| if (slices.empty()) | ||
| return; | ||
|
|
||
| ContextWriter writer(ctx); |
There was a problem hiding this comment.
warning: variable 'writer' of type 'ContextWriter' can be declared 'const' [misc-const-correctness]
| ContextWriter writer(ctx); | |
| ContextWriter const writer(ctx); |
| const doc::Palette* pal, | ||
| const doc::Tileset* tileset); | ||
| void copyPalette(const doc::Palette* palette, const doc::PalettePicks& picks); | ||
| void copySlices(const std::vector<doc::Slice*> slices); |
There was a problem hiding this comment.
warning: parameter 'slices' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]
| void copySlices(const std::vector<doc::Slice*> slices); | |
| void copySlices(std::vector<doc::Slice*> slices); |
|
@dacap Should I rebase this against main branch now? |
Please rebase with main 👍 |
4a70697 to
935283e
Compare
|
Hi there! One or more of the commit messages in this PR do not match our code submission policy, please check the |
Fix #4466
Fix #4972