Fix album part edit/delete/replace after reorder.

This commit is contained in:
John Preston 2023-08-16 13:23:06 +02:00
parent f502229cc8
commit b5d3391956
3 changed files with 10 additions and 17 deletions

View File

@ -760,6 +760,8 @@ void SendFilesBox::pushBlock(int from, int till) {
) | rpl::filter([=] {
return !_removingIndex;
}) | rpl::start_with_next([=](int index) {
applyBlockChanges();
_removingIndex = index;
crl::on_main(this, [=] {
const auto index = base::take(_removingIndex).value_or(-1);
@ -780,6 +782,8 @@ void SendFilesBox::pushBlock(int from, int till) {
const auto show = uiShow();
block.itemReplaceRequest(
) | rpl::start_with_next([=](int index) {
applyBlockChanges();
const auto replace = [=](Ui::PreparedList list) {
if (list.files.empty()) {
return;
@ -855,6 +859,8 @@ void SendFilesBox::pushBlock(int from, int till) {
const auto openedOnce = widget->lifetime().make_state<bool>(false);
block.itemModifyRequest(
) | rpl::start_with_next([=, show = _show](int index) {
applyBlockChanges();
if (!(*openedOnce)) {
show->session().settings().incrementPhotoEditorHintShown();
show->session().saveSettings();

View File

@ -142,8 +142,8 @@ void AlbumPreview::prepareThumbs(gsl::span<Ui::PreparedFile> items) {
layout[i],
this,
[=] { update(); },
[=] { changeThumbByIndex(thumbIndex(thumbUnderCursor())); },
[=] { deleteThumbByIndex(thumbIndex(thumbUnderCursor())); }));
[=] { changeThumbByIndex(orderIndex(thumbUnderCursor())); },
[=] { deleteThumbByIndex(orderIndex(thumbUnderCursor())); }));
if (_thumbs.back()->isCompressedSticker()) {
_hasMixedFileHeights = true;
}
@ -218,8 +218,7 @@ not_null<AlbumThumbnail*> AlbumPreview::findClosestThumb(
return result;
}
int AlbumPreview::orderIndex(
not_null<AlbumThumbnail*> thumb) const {
int AlbumPreview::orderIndex(not_null<AlbumThumbnail*> thumb) const {
const auto i = ranges::find_if(_order, [&](int index) {
return (_thumbs[index].get() == thumb);
});
@ -400,17 +399,6 @@ void AlbumPreview::paintFiles(Painter &p, QRect clip) const {
}
}
int AlbumPreview::thumbIndex(AlbumThumbnail *thumb) {
if (!thumb) {
return -1;
}
const auto thumbIt = ranges::find_if(_thumbs, [&](auto &t) {
return t.get() == thumb;
});
Expects(thumbIt != _thumbs.end());
return std::distance(_thumbs.begin(), thumbIt);
}
AlbumThumbnail *AlbumPreview::thumbUnderCursor() {
return findThumb(mapFromGlobal(QCursor::pos()));
}
@ -439,7 +427,7 @@ void AlbumPreview::modifyThumbByIndex(int index) {
void AlbumPreview::thumbButtonsCallback(
not_null<AlbumThumbnail*> thumb,
AttachButtonType type) {
const auto index = thumbIndex(thumb);
const auto index = orderIndex(thumb);
switch (type) {
case AttachButtonType::None: return;

View File

@ -64,7 +64,6 @@ private:
void updateSize();
void updateFileRows();
int thumbIndex(AlbumThumbnail *thumb);
AlbumThumbnail *thumbUnderCursor();
void deleteThumbByIndex(int index);
void changeThumbByIndex(int index);