Added ability to extend context menu of InputField via rpl.
This commit is contained in:
parent
24d69ee679
commit
ee44c5b89e
2 changed files with 20 additions and 3 deletions
|
|
@ -1413,6 +1413,16 @@ void InputField::onTouchTimer() {
|
|||
_touchRightButton = true;
|
||||
}
|
||||
|
||||
void InputField::setExtendedContextMenu(
|
||||
rpl::producer<ExtendedContextMenu> value) {
|
||||
std::move(
|
||||
value
|
||||
) | rpl::start_with_next([=](auto pair) {
|
||||
auto &[menu, e] = pair;
|
||||
contextMenuEventInner(&e, std::move(menu));
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void InputField::setInstantReplaces(const InstantReplaces &replaces) {
|
||||
_mutableInstantReplaces = replaces;
|
||||
}
|
||||
|
|
@ -3302,8 +3312,8 @@ bool InputField::revertFormatReplace() {
|
|||
return false;
|
||||
}
|
||||
|
||||
void InputField::contextMenuEventInner(QContextMenuEvent *e) {
|
||||
if (const auto menu = _inner->createStandardContextMenu()) {
|
||||
void InputField::contextMenuEventInner(QContextMenuEvent *e, QMenu *m) {
|
||||
if (const auto menu = m ? m : _inner->createStandardContextMenu()) {
|
||||
addMarkdownActions(menu, e);
|
||||
_contextMenu = base::make_unique_q<PopupMenu>(this, menu);
|
||||
_contextMenu->popup(e->globalPos());
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "ui/text/text_entity.h"
|
||||
#include "styles/style_widgets.h"
|
||||
|
||||
#include <QContextMenuEvent>
|
||||
#include <QtWidgets/QLineEdit>
|
||||
#include <QtWidgets/QTextEdit>
|
||||
#include <QtCore/QTimer>
|
||||
|
|
@ -238,11 +239,17 @@ public:
|
|||
QString link,
|
||||
EditLinkAction action)> callback);
|
||||
|
||||
struct ExtendedContextMenu {
|
||||
QMenu *menu = nullptr;
|
||||
QContextMenuEvent event;
|
||||
};
|
||||
|
||||
void setAdditionalMargin(int margin);
|
||||
|
||||
void setInstantReplaces(const InstantReplaces &replaces);
|
||||
void setInstantReplacesEnabled(rpl::producer<bool> enabled);
|
||||
void setMarkdownReplacesEnabled(rpl::producer<bool> enabled);
|
||||
void setExtendedContextMenu(rpl::producer<ExtendedContextMenu> value);
|
||||
void commitInstantReplacement(int from, int till, const QString &with);
|
||||
void commitMarkdownLinkEdit(
|
||||
EditLinkSelection selection,
|
||||
|
|
@ -376,7 +383,7 @@ private:
|
|||
void focusOutEventInner(QFocusEvent *e);
|
||||
void setFocused(bool focused);
|
||||
void keyPressEventInner(QKeyEvent *e);
|
||||
void contextMenuEventInner(QContextMenuEvent *e);
|
||||
void contextMenuEventInner(QContextMenuEvent *e, QMenu *m = nullptr);
|
||||
void dropEventInner(QDropEvent *e);
|
||||
void inputMethodEventInner(QInputMethodEvent *e);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue