Add "Photo or video" and "Document" attach menu items.

This commit is contained in:
John Preston 2022-04-05 10:49:55 +04:00
parent 0e75204762
commit 0374d8caa8
12 changed files with 28 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 993 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -1489,6 +1489,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_attach_file" = "File"; "lng_attach_file" = "File";
"lng_attach_photo" = "Photo"; "lng_attach_photo" = "Photo";
"lng_attach_camera" = "Camera"; "lng_attach_camera" = "Camera";
"lng_attach_document" = "Document";
"lng_attach_photo_or_video" = "Photo or video";
"lng_media_open_with" = "Open With"; "lng_media_open_with" = "Open With";
"lng_media_download" = "Download"; "lng_media_download" = "Download";

View file

@ -498,10 +498,14 @@ HistoryWidget::HistoryWidget(
_attachBotsMenu->setAutoHiding(true); _attachBotsMenu->setAutoHiding(true);
} }
}; };
const auto attach = [=](bool compress) {
chooseAttach(compress);
};
_attachBotsMenu = InlineBots::MakeAttachBotsMenu( _attachBotsMenu = InlineBots::MakeAttachBotsMenu(
this, this,
controller, controller,
forceShown); forceShown,
attach);
_attachBotsMenu->setOrigin( _attachBotsMenu->setOrigin(
Ui::PanelAnimation::Origin::BottomLeft); Ui::PanelAnimation::Origin::BottomLeft);
if (_history && _history->peer->isUser()) { if (_history && _history->peer->isUser()) {
@ -4039,7 +4043,8 @@ void HistoryWidget::cornerButtonsAnimationFinish() {
updateCornerButtonsPositions(); updateCornerButtonsPositions();
} }
void HistoryWidget::chooseAttach() { void HistoryWidget::chooseAttach(
std::optional<bool> overrideSendImagesAsPhotos) {
if (_editMsgId) { if (_editMsgId) {
controller()->show(Ui::MakeInformBox(tr::lng_edit_caption_attach())); controller()->show(Ui::MakeInformBox(tr::lng_edit_caption_attach()));
return; return;
@ -4058,7 +4063,9 @@ void HistoryWidget::chooseAttach() {
return; return;
} }
const auto filter = FileDialog::AllOrImagesFilter(); const auto filter = (overrideSendImagesAsPhotos == true)
? FileDialog::ImagesOrAllFilter()
: FileDialog::AllOrImagesFilter();
FileDialog::GetOpenPaths(this, tr::lng_choose_files(tr::now), filter, crl::guard(this, [=]( FileDialog::GetOpenPaths(this, tr::lng_choose_files(tr::now), filter, crl::guard(this, [=](
FileDialog::OpenResult &&result) { FileDialog::OpenResult &&result) {
@ -4073,7 +4080,8 @@ void HistoryWidget::chooseAttach() {
if (!read.image.isNull() && !read.animated) { if (!read.image.isNull() && !read.animated) {
confirmSendingFiles( confirmSendingFiles(
std::move(read.image), std::move(read.image),
std::move(result.remoteContent)); std::move(result.remoteContent),
overrideSendImagesAsPhotos);
} else { } else {
uploadFile(result.remoteContent, SendMediaType::File); uploadFile(result.remoteContent, SendMediaType::File);
} }
@ -4081,6 +4089,7 @@ void HistoryWidget::chooseAttach() {
auto list = Storage::PrepareMediaList( auto list = Storage::PrepareMediaList(
result.paths, result.paths,
st::sendMediaPreviewSize); st::sendMediaPreviewSize);
list.overrideSendImagesAsPhotos = overrideSendImagesAsPhotos;
confirmSendingFiles(std::move(list)); confirmSendingFiles(std::move(list));
} }
}), nullptr); }), nullptr);

View file

@ -423,7 +423,7 @@ private:
void animationCallback(); void animationCallback();
void updateOverStates(QPoint pos); void updateOverStates(QPoint pos);
void chooseAttach(); void chooseAttach(std::optional<bool> overrideSendImagesAsPhotos = {});
void cornerButtonsAnimationFinish(); void cornerButtonsAnimationFinish();
void sendButtonClicked(); void sendButtonClicked();
void newItemAdded(not_null<HistoryItem*> item); void newItemAdded(not_null<HistoryItem*> item);

View file

@ -674,7 +674,8 @@ void AttachWebView::toggleInMenu(
std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu( std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
Fn<void(bool)> forceShown) { Fn<void(bool)> forceShown,
Fn<void(bool)> attach) {
auto result = std::make_unique<Ui::DropdownMenu>( auto result = std::make_unique<Ui::DropdownMenu>(
parent, parent,
st::dropdownMenuWithIcons); st::dropdownMenuWithIcons);
@ -682,12 +683,12 @@ std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
const auto raw = result.get(); const auto raw = result.get();
const auto refresh = [=] { const auto refresh = [=] {
raw->clearActions(); raw->clearActions();
raw->addAction(u"Photo or video"_q, [=] { raw->addAction(tr::lng_attach_photo_or_video(tr::now), [=] {
attach(true);
}); }, &st::menuIconPhoto);
raw->addAction(u"Document"_q, [=] { raw->addAction(tr::lng_attach_document(tr::now), [=] {
attach(false);
}); }, &st::menuIconFile);
for (const auto &bot : bots->attachBots()) { for (const auto &bot : bots->attachBots()) {
const auto callback = [=] { const auto callback = [=] {
const auto active = controller->activeChatCurrent(); const auto active = controller->activeChatCurrent();

View file

@ -132,6 +132,7 @@ private:
[[nodiscard]] std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu( [[nodiscard]] std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
Fn<void(bool)> forceShown); Fn<void(bool)> forceShown,
Fn<void(bool)> attach);
} // namespace InlineBots } // namespace InlineBots

View file

@ -108,6 +108,8 @@ menuIconCustomize: icon {{ "menu/customize", menuIconColor }};
menuIconSoundOn: icon {{ "menu/sound_enable", menuIconColor }}; menuIconSoundOn: icon {{ "menu/sound_enable", menuIconColor }};
menuIconSoundOff: icon {{ "menu/sound_disable", menuIconColor }}; menuIconSoundOff: icon {{ "menu/sound_disable", menuIconColor }};
menuIconSoundSelect: icon {{ "menu/sound_select", menuIconColor }}; menuIconSoundSelect: icon {{ "menu/sound_select", menuIconColor }};
menuIconFile: icon {{ "menu/file", menuIconColor }};
menuIconPhoto: icon {{ "menu/image", menuIconColor }};
menuIconTTLAny: icon {{ "menu/auto_delete_plain", menuIconColor }}; menuIconTTLAny: icon {{ "menu/auto_delete_plain", menuIconColor }};
menuIconTTLAnyTextPosition: point(11px, 22px); menuIconTTLAnyTextPosition: point(11px, 22px);