Added other items to TabbedPanel's context menu.

This commit is contained in:
23rd 2020-07-25 22:03:29 +03:00 committed by John Preston
parent 43056107fd
commit 5b95585725
6 changed files with 67 additions and 21 deletions

View File

@ -1468,6 +1468,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_context_copy_text" = "Copy Text";
"lng_context_open_gif" = "Open GIF";
"lng_context_save_gif" = "Save GIF";
"lng_context_delete_gif" = "Delete GIF";
"lng_context_attached_stickers" = "Attached Stickers";
"lng_context_to_msg" = "Go To Message";
"lng_context_reply_msg" = "Reply";

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "chat_helpers/gifs_list_widget.h"
#include "api/api_common.h"
#include "apiwrap.h" // ApiWrap::toggleSavedGif
#include "base/const_string.h"
#include "data/data_photo.h"
#include "data/data_document.h"
@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_cursor_state.h"
#include "history/view/history_view_schedule_box.h"
#include "app.h"
#include "storage/storage_account.h" // Account::writeSavedGifs
#include "styles/style_chat_helpers.h"
#include <QtWidgets/QApplication>
@ -46,6 +47,21 @@ constexpr auto kSearchBotUsername = "gif"_cs;
} // namespace
void DeleteSavedGif(not_null<DocumentData*> document) {
auto &data = document->owner();
document->session().api().toggleSavedGif(
document,
Data::FileOriginSavedGifs(),
false);
const auto index = data.stickers().savedGifs().indexOf(document);
if (index >= 0) {
data.stickers().savedGifsRef().remove(index);
document->session().local().writeSavedGifs();
}
data.stickers().notifySavedGifsUpdated();
}
class GifsListWidget::Footer : public TabbedSelector::InnerFooter {
public:
Footer(not_null<GifsListWidget*> parent);
@ -373,6 +389,24 @@ void GifsListWidget::fillContextMenu(
[&] { return type; },
silent,
schedule);
[&] {
const auto row = _selected / MatrixRowShift;
const auto column = _selected % MatrixRowShift;
if (row >= _rows.size() || column >= _rows[row].items.size()) {
return;
}
const auto item = _rows[row].items[column];
if (const auto document = item->getDocument()) {
auto &data = document->owner();
if (data.stickers().savedGifs().indexOf(document) < 0) {
return;
}
menu->addAction(tr::lng_context_delete_gif(tr::now), [=] {
ChatHelpers::DeleteSavedGif(document);
});
}
}();
}
void GifsListWidget::mouseReleaseEvent(QMouseEvent *e) {

View File

@ -38,6 +38,8 @@ enum class SendMenuType;
namespace ChatHelpers {
void DeleteSavedGif(not_null<DocumentData*> document);
class GifsListWidget
: public TabbedSelector::Inner
, public InlineBots::Layout::Context

View File

@ -2046,6 +2046,14 @@ QPoint StickersListWidget::buttonRippleTopLeft(int section) const {
return myrtlrect(removeButtonRect(section)).topLeft() + st::stickerPanRemoveSet.rippleAreaPosition;
}
void StickersListWidget::showStickerSetBox(not_null<DocumentData*> document) {
if (document->sticker()
&& document->sticker()->set.type() != mtpc_inputStickerSetEmpty) {
_displayingSet = true;
checkHideWithBox(StickerSetBox::Show(controller(), document));
}
}
void StickersListWidget::fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenuType type) {
@ -2079,6 +2087,22 @@ void StickersListWidget::fillContextMenu(
[&] { return type; },
silent,
schedule);
const auto toggleFavedSticker = [=] {
document->session().api().toggleFavedSticker(
document,
Data::FileOriginStickerSet(Data::Stickers::FavedSetId, 0),
!document->owner().stickers().isFaved(document));
};
menu->addAction(
(document->owner().stickers().isFaved(document)
? tr::lng_faved_stickers_remove
: tr::lng_faved_stickers_add)(tr::now),
toggleFavedSticker);
menu->addAction(tr::lng_context_pack_info(tr::now), [=] {
showStickerSetBox(document);
});
}
}
@ -2118,13 +2142,7 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) {
}
const auto document = set.stickers[sticker->index].document;
if (e->modifiers() & Qt::ControlModifier) {
if (document->sticker()
&& document->sticker()->set.type() != mtpc_inputStickerSetEmpty) {
_displayingSet = true;
checkHideWithBox(StickerSetBox::Show(
controller(),
document));
}
showStickerSetBox(document);
} else {
_chosen.fire_copy({ .document = document });
}

View File

@ -303,6 +303,8 @@ private:
void setColumnCount(int count);
void refreshFooterIcons();
void showStickerSetBox(not_null<DocumentData*> document);
void cancelSetsSearch();
void showSearchResults();
void searchResultsDone(const MTPmessages_FoundStickerSets &result);

View File

@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_photo_media.h"
#include "data/data_document_media.h"
#include "data/stickers/data_stickers.h"
#include "chat_helpers/gifs_list_widget.h" // ChatHelpers::DeleteSavedGif
#include "chat_helpers/stickers_lottie.h"
#include "inline_bots/inline_bot_result.h"
#include "lottie/lottie_single_player.h"
@ -22,10 +23,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "media/player/media_player_instance.h"
#include "history/history_location_manager.h"
#include "history/view/history_view_cursor_state.h"
#include "storage/storage_account.h"
#include "ui/image/image.h"
#include "main/main_session.h"
#include "apiwrap.h"
#include "lang/lang_keys.h"
#include "app.h"
#include "styles/style_overview.h"
@ -126,17 +125,7 @@ void Gif::setPosition(int32 position) {
}
void DeleteSavedGifClickHandler::onClickImpl() const {
_data->session().api().toggleSavedGif(
_data,
Data::FileOriginSavedGifs(),
false);
const auto index = _data->owner().stickers().savedGifs().indexOf(_data);
if (index >= 0) {
_data->owner().stickers().savedGifsRef().remove(index);
_data->session().local().writeSavedGifs();
}
_data->owner().stickers().notifySavedGifsUpdated();
ChatHelpers::DeleteSavedGif(_data);
}
int Gif::resizeGetHeight(int width) {