fix: reordering crashes

This commit is contained in:
AlexeyZavar 2025-05-20 22:56:30 +03:00
parent 5a015888d4
commit 3a9899529a

View file

@ -2038,9 +2038,7 @@ void SendFilesBox::moveFile(int from, int to) {
if (from == to) return;
std::swap(_list.files[from], _list.files[to]);
refreshAllAfterChanges(std::min(from, to));
refreshAllAfterChanges(std::min(from, to), [=] { std::swap(_list.files[from], _list.files[to]); });
}
void SendFilesBox::setupDragForBlock(not_null<Ui::RpWidget*> w, int index) {
@ -2049,8 +2047,8 @@ void SendFilesBox::setupDragForBlock(not_null<Ui::RpWidget*> w, int index) {
const auto pressed = w->lifetime().make_state<rpl::variable<bool>>(false);
const auto pressPos = w->lifetime().make_state<rpl::variable<QPoint>>();
base::install_event_filter(
w,
w->events(
) | rpl::start_with_next(
[=](not_null<QEvent *> e)
{
switch (e->type()) {
@ -2065,11 +2063,11 @@ void SendFilesBox::setupDragForBlock(not_null<Ui::RpWidget*> w, int index) {
case QEvent::MouseMove: {
if (pressed->current()) {
const auto ev = static_cast<QMouseEvent *>(e.get());
if ((ev->pos() - pressPos->current()).manhattanLength()
>= QApplication::startDragDistance()) {
if ((ev->pos() - pressPos->current()).manhattanLength() >=
QApplication::startDragDistance()) {
pressed->force_assign(false);
const auto drag = std::make_unique<QDrag>(w);
const auto drag = new QDrag(w);
auto mime = std::make_unique<QMimeData>();
mime->setData(kDragMime, QByteArray::number(index));
drag->setMimeData(mime.release());
@ -2080,15 +2078,13 @@ void SendFilesBox::setupDragForBlock(not_null<Ui::RpWidget*> w, int index) {
}
break;
}
case QEvent::MouseButtonRelease: pressed->force_assign(false);
break;
case QEvent::MouseButtonRelease: pressed->force_assign(false); break;
case QEvent::DragEnter:
case QEvent::DragMove: {
const auto ev = static_cast<QDragMoveEvent *>(e.get());
if (ev->mimeData()->hasFormat(kDragMime)) {
const auto from = ev->mimeData()
->data(kDragMime).toInt();
const auto from = ev->mimeData()->data(kDragMime).toInt();
if (isFileBlock(from) && isFileBlock(index)) {
ev->acceptProposedAction();
}
@ -2098,18 +2094,9 @@ void SendFilesBox::setupDragForBlock(not_null<Ui::RpWidget*> w, int index) {
case QEvent::Drop: {
const auto ev = static_cast<QDropEvent *>(e.get());
if (ev->mimeData()->hasFormat(kDragMime)) {
const auto from = ev->mimeData()
->data(kDragMime).toInt();
const auto from = ev->mimeData()->data(kDragMime).toInt();
if (isFileBlock(from) && isFileBlock(index)) {
const auto dest = index;
QMetaObject::invokeMethod(
this,
[this, from, dest]
{
moveFile(from, dest);
},
Qt::QueuedConnection);
crl::on_main(this, [=] { moveFile(from, index); });
ev->acceptProposedAction();
}
}
@ -2118,5 +2105,6 @@ void SendFilesBox::setupDragForBlock(not_null<Ui::RpWidget*> w, int index) {
default: break;
}
return base::EventFilterResult::Continue;
});
},
w->lifetime());
}