From 6e69069ba2b961d2581c1c63f711ab7fd099217a Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 30 Mar 2019 11:53:28 +0300 Subject: [PATCH] Added Ctrl+E and Ctrl+O shortcut to edit media. --- .../SourceFiles/boxes/edit_caption_box.cpp | 19 +++++++++++++++++-- Telegram/SourceFiles/boxes/edit_caption_box.h | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index a8152bf2d..501782779 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -407,7 +407,7 @@ void EditCaptionBox::createEditMediaButton() { } }; - addButton(langFactory(lng_edit_media), [=] { + const auto buttonCallback = [=] { const auto filters = _isNotAlbum ? QStringList(FileDialog::AllFilesFilter()) : QStringList(qsl("Image and Video Files (*.png *.jpg *.mp4)")); @@ -416,7 +416,13 @@ void EditCaptionBox::createEditMediaButton() { lang(lng_choose_file), filters.join(qsl(";;")), crl::guard(this, callback)); - }); + }; + + _editMediaClicks.events() | rpl::start_with_next([=] { + buttonCallback(); + }, lifetime()); + + addButton(langFactory(lng_edit_media), buttonCallback); } void EditCaptionBox::prepare() { @@ -719,3 +725,12 @@ void EditCaptionBox::setName(QString nameString, qint64 size) { _name.maxWidth(), st::normalFont->width(_status)); } + +void EditCaptionBox::keyPressEvent(QKeyEvent *e) { + if ((e->key() == Qt::Key_E || e->key() == Qt::Key_O) + && e->modifiers() == Qt::ControlModifier) { + _editMediaClicks.fire({}); + } else { + e->ignore(); + } +} diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.h b/Telegram/SourceFiles/boxes/edit_caption_box.h index 3e1bc176c..cbec2a63a 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.h +++ b/Telegram/SourceFiles/boxes/edit_caption_box.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" #include "storage/storage_media_prepare.h" #include "ui/wrap/slide_wrap.h" +#include namespace ChatHelpers { class TabbedPanel; @@ -46,6 +47,7 @@ protected: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; private: void updateBoxSize(); @@ -108,6 +110,7 @@ private: QString _newMediaPath; bool _isAllowedEditMedia = false; bool _isNotAlbum; + rpl::event_stream<> _editMediaClicks; QString _error;