Added simple box to edit caption of single file while it's uploading.

This commit is contained in:
23rd 2025-05-22 16:22:09 +03:00
parent 5b9e24f3f4
commit 5ac373d4aa
4 changed files with 70 additions and 10 deletions

View file

@ -4197,6 +4197,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_context_pin_msg" = "Pin";
"lng_context_unpin_msg" = "Unpin";
"lng_context_cancel_upload" = "Cancel Upload";
"lng_context_upload_edit_caption" = "Edit Caption";
"lng_context_upload_edit_caption_error" = "Sorry, the file is already uploaded.";
"lng_context_copy_selected" = "Copy Selected Text";
"lng_context_copy_selected_items" = "Copy Selected as Text";
"lng_context_forward_selected" = "Forward Selected";

View file

@ -24,7 +24,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h"
#include "data/stickers/data_custom_emoji.h"
#include "data/stickers/data_stickers.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/view/controls/history_view_characters_limit.h"
#include "history/view/history_view_message.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
#include "media/clip/media_clip_reader.h"
@ -32,10 +35,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/controls/emoji_button.h"
#include "ui/controls/emoji_button_factory.h"
#include "ui/layers/generic_box.h"
#include "ui/widgets/fields/input_field.h"
#include "ui/rect.h"
#include "ui/text/text_entity.h"
#include "ui/ui_utility.h"
#include "ui/vertical_list.h"
#include "ui/widgets/fields/input_field.h"
#include "window/window_controller.h"
#include "window/window_session_controller.h"
#include "styles/style_boxes.h"
@ -224,10 +228,9 @@ namespace {
return input;
}
} // namespace
void CaptionBox(
not_null<Ui::GenericBox*> box,
rpl::producer<QString> confirmText,
not_null<PeerData*> peer,
const SendMenu::Details &details,
Fn<void(Api::SendOptions, TextWithTags)> done) {
@ -310,7 +313,7 @@ void CaptionBox(
done(std::move(options), input->getTextWithTags());
};
const auto confirm = box->addButton(
tr::lng_send_button(),
std::move(confirmText),
[=] { send({}); });
SendMenu::SetupMenuAndShortcuts(
confirm,
@ -331,6 +334,8 @@ void CaptionBox(
) | rpl::start_with_next([=] { send({}); }, input->lifetime());
}
} // namespace
void SendGifWithCaptionBox(
not_null<Ui::GenericBox*> box,
not_null<DocumentData*> document,
@ -343,7 +348,37 @@ void SendGifWithCaptionBox(
document,
st::boxWidth);
Ui::AddSkip(box->verticalLayout());
CaptionBox(box, peer, details, std::move(done));
CaptionBox(box, tr::lng_send_button(), peer, details, std::move(done));
}
void EditCaptionBox(
not_null<Ui::GenericBox*> box,
not_null<HistoryView::Element*> view) {
const auto window = Core::App().findWindow(box);
Assert(window != nullptr);
const auto controller = window->sessionController();
Assert(controller != nullptr);
box->setTitle(tr::lng_context_upload_edit_caption());
const auto item = view->data();
const auto peer = item->history()->peer;
auto done = [=](Api::SendOptions, TextWithTags textWithTags) {
if (item->isUploading()) {
item->setText({
base::take(textWithTags.text),
TextUtilities::ConvertTextTagsToEntities(
base::take(textWithTags.tags)),
});
peer->owner().requestViewResize(view);
box->closeBox();
} else {
controller->showToast(
tr::lng_context_upload_edit_caption_error(tr::now));
}
};
CaptionBox(box, tr::lng_settings_save(), peer, {}, std::move(done));
}
} // namespace Ui

View file

@ -18,15 +18,17 @@ namespace SendMenu {
struct Details;
} // namespace SendMenu
namespace HistoryView {
class Element;
} // namespace HistoryView
namespace Ui {
class GenericBox;
void CaptionBox(
void EditCaptionBox(
not_null<Ui::GenericBox*> box,
not_null<PeerData*> peer,
const SendMenu::Details &details,
Fn<void(Api::SendOptions, TextWithTags)> done);
not_null<HistoryView::Element*> view);
void SendGifWithCaptionBox(
not_null<Ui::GenericBox*> box,

View file

@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item_helpers.h"
#include "history/view/controls/history_view_forward_panel.h"
#include "history/view/controls/history_view_draft_options.h"
#include "boxes/moderate_messages_box.h"
#include "history/view/media/history_view_sticker.h"
#include "history/view/media/history_view_web_page.h"
#include "history/view/reactions/history_view_reactions.h"
@ -54,7 +53,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/statistics/info_statistics_widget.h"
#include "boxes/about_sponsored_box.h"
#include "boxes/delete_messages_box.h"
#include "boxes/moderate_messages_box.h"
#include "boxes/report_messages_box.h"
#include "boxes/send_gif_with_caption_box.h"
#include "boxes/star_gift_box.h" // ShowStarGiftBox
#include "boxes/sticker_set_box.h"
#include "boxes/translate_box.h"
@ -2718,6 +2719,16 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
if (item->canDelete()) {
const auto callback = [=] { deleteItem(itemId); };
if (item->isUploading()) {
_menu->addAction(
tr::lng_context_upload_edit_caption(tr::now),
[=] {
if (const auto view = viewByItem(item)) {
controller->uiShow()->show(Box(
Ui::EditCaptionBox,
view));
}
},
&st::menuIconEdit);
_menu->addAction(tr::lng_context_cancel_upload(tr::now), callback, &st::menuIconCancel);
} else {
_menu->addAction(Ui::DeleteMessageContextAction(
@ -2962,6 +2973,16 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
deleteAsGroup(itemId);
};
if (item->isUploading()) {
_menu->addAction(
tr::lng_context_upload_edit_caption(tr::now),
[=] {
if (const auto view = viewByItem(item)) {
controller->uiShow()->show(Box(
Ui::EditCaptionBox,
view));
}
},
&st::menuIconEdit);
_menu->addAction(tr::lng_context_cancel_upload(tr::now), callback, &st::menuIconCancel);
} else {
_menu->addAction(Ui::DeleteMessageContextAction(