mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-24 01:06:59 +00:00
Added ability to show document from Controller for sections.
This commit is contained in:
parent
eefa7263b5
commit
dc0aaec4a4
@ -316,6 +316,22 @@ DocumentClickHandler::DocumentClickHandler(
|
||||
, _document(document) {
|
||||
}
|
||||
|
||||
DocumentOpenClickHandler::DocumentOpenClickHandler(
|
||||
not_null<DocumentData*> document,
|
||||
Fn<void()> &&callback)
|
||||
: DocumentClickHandler(document)
|
||||
, _handler(std::move(callback)) {
|
||||
}
|
||||
|
||||
void DocumentOpenClickHandler::onClickImpl() const {
|
||||
if (_handler) {
|
||||
_handler();
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentOpenClickHandlerOld::onClickImpl() const {
|
||||
}
|
||||
|
||||
void DocumentOpenClickHandler::Open(
|
||||
Data::FileOrigin origin,
|
||||
not_null<DocumentData*> data,
|
||||
@ -323,10 +339,6 @@ void DocumentOpenClickHandler::Open(
|
||||
Data::ResolveDocument(data, context);
|
||||
}
|
||||
|
||||
void DocumentOpenClickHandler::onClickImpl() const {
|
||||
Open(context(), document(), getActionItem());
|
||||
}
|
||||
|
||||
void DocumentSaveClickHandler::Save(
|
||||
Data::FileOrigin origin,
|
||||
not_null<DocumentData*> data,
|
||||
|
@ -362,7 +362,9 @@ protected:
|
||||
|
||||
class DocumentOpenClickHandler : public DocumentClickHandler {
|
||||
public:
|
||||
using DocumentClickHandler::DocumentClickHandler;
|
||||
DocumentOpenClickHandler(
|
||||
not_null<DocumentData*> document,
|
||||
Fn<void()> &&callback);
|
||||
static void Open(
|
||||
Data::FileOrigin origin,
|
||||
not_null<DocumentData*> document,
|
||||
@ -371,6 +373,18 @@ public:
|
||||
protected:
|
||||
void onClickImpl() const override;
|
||||
|
||||
private:
|
||||
Fn<void()> _handler;
|
||||
|
||||
};
|
||||
|
||||
class DocumentOpenClickHandlerOld : public DocumentClickHandler {
|
||||
public:
|
||||
using DocumentClickHandler::DocumentClickHandler;
|
||||
|
||||
protected:
|
||||
void onClickImpl() const override;
|
||||
|
||||
};
|
||||
|
||||
class DocumentCancelClickHandler : public DocumentClickHandler {
|
||||
|
@ -608,6 +608,13 @@ void InnerWidget::elementOpenPhoto(
|
||||
_controller->openPhoto(photo, context);
|
||||
}
|
||||
|
||||
void InnerWidget::elementOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView) {
|
||||
_controller->openDocument(document, context, showInMediaView);
|
||||
}
|
||||
|
||||
void InnerWidget::elementShowTooltip(
|
||||
const TextWithEntities &text,
|
||||
Fn<void()> hiddenCallback) {
|
||||
|
@ -111,6 +111,10 @@ public:
|
||||
void elementOpenPhoto(
|
||||
not_null<PhotoData*> photo,
|
||||
FullMsgId context) override;
|
||||
void elementOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView = false) override;
|
||||
void elementShowTooltip(
|
||||
const TextWithEntities &text,
|
||||
Fn<void()> hiddenCallback) override;
|
||||
|
@ -2573,6 +2573,13 @@ void HistoryInner::elementOpenPhoto(
|
||||
_controller->openPhoto(photo, context);
|
||||
}
|
||||
|
||||
void HistoryInner::elementOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView) {
|
||||
_controller->openDocument(document, context, showInMediaView);
|
||||
}
|
||||
|
||||
void HistoryInner::elementShowTooltip(
|
||||
const TextWithEntities &text,
|
||||
Fn<void()> hiddenCallback) {
|
||||
@ -3458,6 +3465,17 @@ not_null<HistoryView::ElementDelegate*> HistoryInner::ElementDelegate() {
|
||||
Instance->elementOpenPhoto(photo, context);
|
||||
}
|
||||
}
|
||||
void elementOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView = false) override {
|
||||
if (Instance) {
|
||||
Instance->elementOpenDocument(
|
||||
document,
|
||||
context,
|
||||
showInMediaView);
|
||||
}
|
||||
}
|
||||
void elementShowTooltip(
|
||||
const TextWithEntities &text,
|
||||
Fn<void()> hiddenCallback) override {
|
||||
|
@ -91,6 +91,10 @@ public:
|
||||
void elementOpenPhoto(
|
||||
not_null<PhotoData*> photo,
|
||||
FullMsgId context);
|
||||
void elementOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView = false);
|
||||
void elementShowTooltip(
|
||||
const TextWithEntities &text,
|
||||
Fn<void()> hiddenCallback);
|
||||
|
@ -112,6 +112,12 @@ void SimpleElementDelegate::elementOpenPhoto(
|
||||
FullMsgId context) {
|
||||
}
|
||||
|
||||
void SimpleElementDelegate::elementOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView) {
|
||||
}
|
||||
|
||||
void SimpleElementDelegate::elementShowTooltip(
|
||||
const TextWithEntities &text,
|
||||
Fn<void()> hiddenCallback) {
|
||||
|
@ -63,6 +63,10 @@ public:
|
||||
virtual void elementOpenPhoto(
|
||||
not_null<PhotoData*> photo,
|
||||
FullMsgId context) = 0;
|
||||
virtual void elementOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView = false) = 0;
|
||||
virtual void elementShowTooltip(
|
||||
const TextWithEntities &text,
|
||||
Fn<void()> hiddenCallback) = 0;
|
||||
@ -103,6 +107,10 @@ public:
|
||||
void elementOpenPhoto(
|
||||
not_null<PhotoData*> photo,
|
||||
FullMsgId context) override;
|
||||
void elementOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView = false) override;
|
||||
void elementShowTooltip(
|
||||
const TextWithEntities &text,
|
||||
Fn<void()> hiddenCallback) override;
|
||||
|
@ -1306,6 +1306,13 @@ void ListWidget::elementOpenPhoto(
|
||||
_controller->openPhoto(photo, context);
|
||||
}
|
||||
|
||||
void ListWidget::elementOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView) {
|
||||
_controller->openDocument(document, context, showInMediaView);
|
||||
}
|
||||
|
||||
void ListWidget::elementShowTooltip(
|
||||
const TextWithEntities &text,
|
||||
Fn<void()> hiddenCallback) {
|
||||
|
@ -237,6 +237,10 @@ public:
|
||||
void elementOpenPhoto(
|
||||
not_null<PhotoData*> photo,
|
||||
FullMsgId context) override;
|
||||
void elementOpenDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId context,
|
||||
bool showInMediaView = false) override;
|
||||
void elementShowTooltip(
|
||||
const TextWithEntities &text,
|
||||
Fn<void()> hiddenCallback) override;
|
||||
|
@ -220,9 +220,7 @@ void Document::createComponents(bool caption) {
|
||||
_realParent->fullId());
|
||||
}
|
||||
if (const auto voice = Get<HistoryDocumentVoice>()) {
|
||||
voice->_seekl = std::make_shared<VoiceSeekClickHandler>(
|
||||
_data,
|
||||
_realParent->fullId());
|
||||
voice->_seekl = std::make_shared<VoiceSeekClickHandler>(_data, [] {});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/text/format_values.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history.h"
|
||||
#include "history/view/history_view_element.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_session.h"
|
||||
#include "styles/style_chat.h"
|
||||
@ -103,7 +104,11 @@ void File::setDocumentLinks(
|
||||
not_null<HistoryItem*> realParent) {
|
||||
const auto context = realParent->fullId();
|
||||
setLinks(
|
||||
std::make_shared<DocumentOpenClickHandler>(document, context),
|
||||
std::make_shared<DocumentOpenClickHandler>(
|
||||
document,
|
||||
crl::guard(this, [=] {
|
||||
_parent->delegate()->elementOpenDocument(document, context);
|
||||
})),
|
||||
std::make_shared<DocumentSaveClickHandler>(document, context),
|
||||
std::make_shared<DocumentCancelClickHandler>(document, context));
|
||||
}
|
||||
|
@ -286,7 +286,11 @@ void Sticker::refreshLink() {
|
||||
// .webp image and we allow to open it in media viewer.
|
||||
_link = std::make_shared<DocumentOpenClickHandler>(
|
||||
_data,
|
||||
_parent->data()->fullId());
|
||||
crl::guard(this, [=] {
|
||||
_parent->delegate()->elementOpenDocument(
|
||||
_data,
|
||||
_parent->data()->fullId());
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ void RadialProgressItem::setDocumentLinks(
|
||||
not_null<DocumentData*> document) {
|
||||
const auto context = parent()->fullId();
|
||||
setLinks(
|
||||
std::make_shared<DocumentOpenClickHandler>(document, context),
|
||||
std::make_shared<DocumentOpenClickHandlerOld>(document, context),
|
||||
std::make_shared<DocumentSaveClickHandler>(document, context),
|
||||
std::make_shared<DocumentCancelClickHandler>(document, context));
|
||||
}
|
||||
@ -593,7 +593,7 @@ Voice::Voice(
|
||||
const style::OverviewFileLayout &st)
|
||||
: RadialProgressItem(delegate, parent)
|
||||
, _data(voice)
|
||||
, _namel(std::make_shared<DocumentOpenClickHandler>(_data, parent->fullId()))
|
||||
, _namel(std::make_shared<DocumentOpenClickHandlerOld>(_data, parent->fullId()))
|
||||
, _st(st) {
|
||||
AddComponents(Info::Bit());
|
||||
|
||||
@ -900,7 +900,7 @@ Document::Document(
|
||||
: RadialProgressItem(delegate, parent)
|
||||
, _data(document)
|
||||
, _msgl(goToMessageClickHandler(parent))
|
||||
, _namel(std::make_shared<DocumentOpenClickHandler>(_data, parent->fullId()))
|
||||
, _namel(std::make_shared<DocumentOpenClickHandlerOld>(_data, parent->fullId()))
|
||||
, _st(st)
|
||||
, _date(langDateTime(base::unixtime::parse(_data->date)))
|
||||
, _datew(st::normalFont->width(_date))
|
||||
@ -1452,7 +1452,7 @@ Link::Link(
|
||||
if (_page) {
|
||||
mainUrl = _page->url;
|
||||
if (_page->document) {
|
||||
_photol = std::make_shared<DocumentOpenClickHandler>(
|
||||
_photol = std::make_shared<DocumentOpenClickHandlerOld>(
|
||||
_page->document,
|
||||
parent->fullId());
|
||||
} else if (_page->photo) {
|
||||
|
@ -1235,8 +1235,15 @@ void SessionController::openPhoto(
|
||||
|
||||
void SessionController::openDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId contextId) {
|
||||
FullMsgId contextId,
|
||||
bool showInMediaView) {
|
||||
// TEMP.
|
||||
if (showInMediaView) {
|
||||
_window->openInMediaView(Media::View::OpenRequest(
|
||||
document,
|
||||
session().data().message(contextId)));
|
||||
return;
|
||||
}
|
||||
Data::ResolveDocument(document, session().data().message(contextId));
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,10 @@ public:
|
||||
|
||||
void openPhoto(not_null<PhotoData*> photo, FullMsgId contextId);
|
||||
void openPhoto(not_null<PhotoData*> photo, not_null<PeerData*> peer);
|
||||
void openDocument(not_null<DocumentData*> document, FullMsgId contextId);
|
||||
void openDocument(
|
||||
not_null<DocumentData*> document,
|
||||
FullMsgId contextId,
|
||||
bool showInMediaView = false);
|
||||
|
||||
void showChooseReportMessages(
|
||||
not_null<PeerData*> peer,
|
||||
|
Loading…
Reference in New Issue
Block a user