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;
|
_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) {
|
void InputField::setInstantReplaces(const InstantReplaces &replaces) {
|
||||||
_mutableInstantReplaces = replaces;
|
_mutableInstantReplaces = replaces;
|
||||||
}
|
}
|
||||||
|
|
@ -3302,8 +3312,8 @@ bool InputField::revertFormatReplace() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputField::contextMenuEventInner(QContextMenuEvent *e) {
|
void InputField::contextMenuEventInner(QContextMenuEvent *e, QMenu *m) {
|
||||||
if (const auto menu = _inner->createStandardContextMenu()) {
|
if (const auto menu = m ? m : _inner->createStandardContextMenu()) {
|
||||||
addMarkdownActions(menu, e);
|
addMarkdownActions(menu, e);
|
||||||
_contextMenu = base::make_unique_q<PopupMenu>(this, menu);
|
_contextMenu = base::make_unique_q<PopupMenu>(this, menu);
|
||||||
_contextMenu->popup(e->globalPos());
|
_contextMenu->popup(e->globalPos());
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include "ui/text/text_entity.h"
|
#include "ui/text/text_entity.h"
|
||||||
#include "styles/style_widgets.h"
|
#include "styles/style_widgets.h"
|
||||||
|
|
||||||
|
#include <QContextMenuEvent>
|
||||||
#include <QtWidgets/QLineEdit>
|
#include <QtWidgets/QLineEdit>
|
||||||
#include <QtWidgets/QTextEdit>
|
#include <QtWidgets/QTextEdit>
|
||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
|
|
@ -238,11 +239,17 @@ public:
|
||||||
QString link,
|
QString link,
|
||||||
EditLinkAction action)> callback);
|
EditLinkAction action)> callback);
|
||||||
|
|
||||||
|
struct ExtendedContextMenu {
|
||||||
|
QMenu *menu = nullptr;
|
||||||
|
QContextMenuEvent event;
|
||||||
|
};
|
||||||
|
|
||||||
void setAdditionalMargin(int margin);
|
void setAdditionalMargin(int margin);
|
||||||
|
|
||||||
void setInstantReplaces(const InstantReplaces &replaces);
|
void setInstantReplaces(const InstantReplaces &replaces);
|
||||||
void setInstantReplacesEnabled(rpl::producer<bool> enabled);
|
void setInstantReplacesEnabled(rpl::producer<bool> enabled);
|
||||||
void setMarkdownReplacesEnabled(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 commitInstantReplacement(int from, int till, const QString &with);
|
||||||
void commitMarkdownLinkEdit(
|
void commitMarkdownLinkEdit(
|
||||||
EditLinkSelection selection,
|
EditLinkSelection selection,
|
||||||
|
|
@ -376,7 +383,7 @@ private:
|
||||||
void focusOutEventInner(QFocusEvent *e);
|
void focusOutEventInner(QFocusEvent *e);
|
||||||
void setFocused(bool focused);
|
void setFocused(bool focused);
|
||||||
void keyPressEventInner(QKeyEvent *e);
|
void keyPressEventInner(QKeyEvent *e);
|
||||||
void contextMenuEventInner(QContextMenuEvent *e);
|
void contextMenuEventInner(QContextMenuEvent *e, QMenu *m = nullptr);
|
||||||
void dropEventInner(QDropEvent *e);
|
void dropEventInner(QDropEvent *e);
|
||||||
void inputMethodEventInner(QInputMethodEvent *e);
|
void inputMethodEventInner(QInputMethodEvent *e);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue