mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Added delete prevent in SendFilesBox when it has single item.
This commit is contained in:
parent
039cad21a5
commit
fad7996e63
1 changed files with 11 additions and 1 deletions
|
@ -533,6 +533,9 @@ void SendFilesBox::pushBlock(int from, int till) {
|
||||||
block.takeWidget(),
|
block.takeWidget(),
|
||||||
QMargins(0, _inner->count() ? st::sendMediaRowSkip : 0, 0, 0));
|
QMargins(0, _inner->count() ? st::sendMediaRowSkip : 0, 0, 0));
|
||||||
|
|
||||||
|
const auto preventDelete =
|
||||||
|
widget->lifetime().make_state<rpl::event_stream<int>>();
|
||||||
|
|
||||||
block.itemDeleteRequest(
|
block.itemDeleteRequest(
|
||||||
) | rpl::filter([=] {
|
) | rpl::filter([=] {
|
||||||
return !_removingIndex;
|
return !_removingIndex;
|
||||||
|
@ -543,12 +546,19 @@ void SendFilesBox::pushBlock(int from, int till) {
|
||||||
if (index < 0 || index >= _list.files.size()) {
|
if (index < 0 || index >= _list.files.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Prevent item delete if it is the only one.
|
||||||
|
if (_list.files.size() == 1) {
|
||||||
|
preventDelete->fire_copy(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
_list.files.erase(_list.files.begin() + index);
|
_list.files.erase(_list.files.begin() + index);
|
||||||
refreshAllAfterChanges(from);
|
refreshAllAfterChanges(from);
|
||||||
});
|
});
|
||||||
}, widget->lifetime());
|
}, widget->lifetime());
|
||||||
|
|
||||||
block.itemReplaceRequest(
|
rpl::merge(
|
||||||
|
block.itemReplaceRequest(),
|
||||||
|
preventDelete->events()
|
||||||
) | rpl::start_with_next([=](int index) {
|
) | rpl::start_with_next([=](int index) {
|
||||||
const auto replace = [=](Ui::PreparedList list) {
|
const auto replace = [=](Ui::PreparedList list) {
|
||||||
if (list.files.empty()) {
|
if (list.files.empty()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue