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

View file

@ -142,8 +142,8 @@ void AlbumPreview::prepareThumbs(gsl::span<Ui::PreparedFile> items) {
layout[i], layout[i],
this, this,
[=] { update(); }, [=] { update(); },
[=] { changeThumbByIndex(thumbIndex(thumbUnderCursor())); }, [=] { changeThumbByIndex(orderIndex(thumbUnderCursor())); },
[=] { deleteThumbByIndex(thumbIndex(thumbUnderCursor())); })); [=] { deleteThumbByIndex(orderIndex(thumbUnderCursor())); }));
if (_thumbs.back()->isCompressedSticker()) { if (_thumbs.back()->isCompressedSticker()) {
_hasMixedFileHeights = true; _hasMixedFileHeights = true;
} }
@ -218,8 +218,7 @@ not_null<AlbumThumbnail*> AlbumPreview::findClosestThumb(
return result; return result;
} }
int AlbumPreview::orderIndex( int AlbumPreview::orderIndex(not_null<AlbumThumbnail*> thumb) const {
not_null<AlbumThumbnail*> thumb) const {
const auto i = ranges::find_if(_order, [&](int index) { const auto i = ranges::find_if(_order, [&](int index) {
return (_thumbs[index].get() == thumb); 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() { AlbumThumbnail *AlbumPreview::thumbUnderCursor() {
return findThumb(mapFromGlobal(QCursor::pos())); return findThumb(mapFromGlobal(QCursor::pos()));
} }
@ -439,7 +427,7 @@ void AlbumPreview::modifyThumbByIndex(int index) {
void AlbumPreview::thumbButtonsCallback( void AlbumPreview::thumbButtonsCallback(
not_null<AlbumThumbnail*> thumb, not_null<AlbumThumbnail*> thumb,
AttachButtonType type) { AttachButtonType type) {
const auto index = thumbIndex(thumb); const auto index = orderIndex(thumb);
switch (type) { switch (type) {
case AttachButtonType::None: return; case AttachButtonType::None: return;

View file

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