| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- // This file is part of Desktop App Toolkit,
- // a set of libraries for developing nice desktop applications.
- //
- // For license and copyright information please follow this link:
- // https://github.com/desktop-app/legal/blob/master/LEGAL
- //
- #include "ui/text/text_extended_data.h"
- #include "ui/text/text.h"
- #include "ui/integration.h"
- namespace Ui::Text {
- SpoilerClickHandler::SpoilerClickHandler(
- not_null<String*> text,
- Fn<bool(const ClickContext&)> filter)
- : _text(text)
- , _filter(std::move(filter)) {
- }
- not_null<String*> SpoilerClickHandler::text() const {
- return _text;
- }
- void SpoilerClickHandler::setText(not_null<String*> text) {
- _text = text;
- }
- void SpoilerClickHandler::onClick(ClickContext context) const {
- if (_filter && !_filter(context)) {
- return;
- }
- _text->setSpoilerRevealed(true, anim::type::normal);
- }
- PreClickHandler::PreClickHandler(
- not_null<String*> text,
- uint16 offset,
- uint16 length)
- : _text(text)
- , _offset(offset)
- , _length(length) {
- }
- not_null<String*> PreClickHandler::text() const {
- return _text;
- }
- void PreClickHandler::setText(not_null<String*> text) {
- _text = text;
- }
- void PreClickHandler::onClick(ClickContext context) const {
- if (context.button != Qt::LeftButton) {
- return;
- }
- const auto till = uint16(_offset + _length);
- auto text = _text->toTextForMimeData({ _offset, till });
- if (text.empty()) {
- return;
- } else if (!text.rich.text.endsWith('\n')) {
- text.rich.text.append('\n');
- }
- if (!text.expanded.endsWith('\n')) {
- text.expanded.append('\n');
- }
- if (Integration::Instance().copyPreOnClick(context.other)) {
- TextUtilities::SetClipboardText(std::move(text));
- }
- }
- BlockquoteClickHandler::BlockquoteClickHandler(
- not_null<String*> text,
- int quoteIndex)
- : _text(text)
- , _quoteIndex(quoteIndex) {
- }
- not_null<String*> BlockquoteClickHandler::text() const {
- return _text;
- }
- void BlockquoteClickHandler::setText(not_null<String*> text) {
- _text = text;
- }
- void BlockquoteClickHandler::onClick(ClickContext context) const {
- if (context.button != Qt::LeftButton) {
- return;
- }
- _text->setBlockquoteExpanded(
- _quoteIndex,
- !_text->blockquoteExpanded(_quoteIndex));
- }
- } // namespace Ui::Text
|