mirror of https://github.com/procxx/kepka.git
Don't switch chats on ctrl+shift+send (support).
This commit is contained in:
parent
83919492d3
commit
be6e329e94
|
@ -4298,6 +4298,7 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
|
|||
options.replyTo = message.replyTo;
|
||||
options.generateLocal = true;
|
||||
options.webPageId = message.webPageId;
|
||||
options.handleSupportSwitch = message.handleSupportSwitch;
|
||||
sendAction(options);
|
||||
|
||||
if (!peer->canWrite()) {
|
||||
|
|
|
@ -262,6 +262,7 @@ public:
|
|||
WebPageId webPageId = 0;
|
||||
bool clearDraft = false;
|
||||
bool generateLocal = true;
|
||||
bool handleSupportSwitch = false;
|
||||
};
|
||||
rpl::producer<SendOptions> sendActions() const {
|
||||
return _sendActions.events();
|
||||
|
@ -318,6 +319,7 @@ public:
|
|||
MsgId replyTo = 0;
|
||||
WebPageId webPageId = 0;
|
||||
bool clearDraft = true;
|
||||
bool handleSupportSwitch = false;
|
||||
};
|
||||
void sendMessage(MessageToSend &&message);
|
||||
void sendInlineResult(
|
||||
|
|
|
@ -462,7 +462,10 @@ HistoryWidget::HistoryWidget(
|
|||
connect(_botStart, SIGNAL(clicked()), this, SLOT(onBotStart()));
|
||||
connect(_joinChannel, SIGNAL(clicked()), this, SLOT(onJoinChannel()));
|
||||
connect(_muteUnmute, SIGNAL(clicked()), this, SLOT(onMuteUnmute()));
|
||||
connect(_field, &Ui::InputField::submitted, [=] { send(); });
|
||||
connect(
|
||||
_field,
|
||||
&Ui::InputField::submitted,
|
||||
[=](Qt::KeyboardModifiers modifiers) { send(modifiers); });
|
||||
connect(_field, SIGNAL(cancelled()), this, SLOT(onCancel()));
|
||||
connect(_field, SIGNAL(tabbed()), this, SLOT(onFieldTabbed()));
|
||||
connect(_field, SIGNAL(resized()), this, SLOT(onFieldResize()));
|
||||
|
@ -761,7 +764,9 @@ HistoryWidget::HistoryWidget(
|
|||
if (cancelReply(lastKeyboardUsed) && !options.clearDraft) {
|
||||
onCloudDraftSave();
|
||||
}
|
||||
handleSupportSwitch(options.history);
|
||||
if (options.handleSupportSwitch) {
|
||||
handleSupportSwitch(options.history);
|
||||
}
|
||||
}, lifetime());
|
||||
|
||||
orderWidgets();
|
||||
|
@ -796,16 +801,19 @@ void HistoryWidget::supportShareContact(Support::Contact contact) {
|
|||
}
|
||||
contact.comment = _field->getLastText();
|
||||
|
||||
const auto submit = [=] {
|
||||
if (!_history) {
|
||||
const auto submit = [=](Qt::KeyboardModifiers modifiers) {
|
||||
const auto history = _history;
|
||||
if (!history) {
|
||||
return;
|
||||
}
|
||||
send();
|
||||
send(Support::SkipSwitchModifiers());
|
||||
auto options = ApiWrap::SendOptions(history);
|
||||
options.handleSupportSwitch = Support::HandleSwitch(modifiers);
|
||||
Auth().api().shareContact(
|
||||
contact.phone,
|
||||
contact.firstName,
|
||||
contact.lastName,
|
||||
ApiWrap::SendOptions(_history));
|
||||
options);
|
||||
};
|
||||
const auto box = Ui::show(Box<Support::ConfirmContactBox>(
|
||||
_history,
|
||||
|
@ -3097,7 +3105,7 @@ void HistoryWidget::hideSelectorControlsAnimated() {
|
|||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::send() {
|
||||
void HistoryWidget::send(Qt::KeyboardModifiers modifiers) {
|
||||
if (!_history) return;
|
||||
|
||||
if (_editMsgId) {
|
||||
|
@ -3105,16 +3113,17 @@ void HistoryWidget::send() {
|
|||
return;
|
||||
}
|
||||
|
||||
WebPageId webPageId = _previewCancelled
|
||||
const auto webPageId = _previewCancelled
|
||||
? CancelledWebPageId
|
||||
: ((_previewData && _previewData->pendingTill >= 0)
|
||||
? _previewData->id
|
||||
: 0);
|
||||
: WebPageId(0));
|
||||
|
||||
auto message = ApiWrap::MessageToSend(_history);
|
||||
message.textWithTags = _field->getTextWithAppliedMarkdown();
|
||||
message.replyTo = replyToId();
|
||||
message.webPageId = webPageId;
|
||||
message.handleSupportSwitch = Support::HandleSwitch(modifiers);
|
||||
Auth().api().sendMessage(std::move(message));
|
||||
|
||||
clearFieldText();
|
||||
|
@ -5456,7 +5465,15 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) {
|
|||
replyToPreviousMessage();
|
||||
}
|
||||
} else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
|
||||
onListEnterPressed();
|
||||
if (!_botStart->isHidden()) {
|
||||
onBotStart();
|
||||
}
|
||||
if (!_canSendMessages) {
|
||||
const auto submitting = Ui::InputField::ShouldSubmit(
|
||||
Auth().settings().sendSubmitWay(),
|
||||
e->modifiers());
|
||||
send(e->modifiers());
|
||||
}
|
||||
} else if (e->key() == Qt::Key_O && e->modifiers() == Qt::ControlModifier) {
|
||||
chooseAttach();
|
||||
} else {
|
||||
|
@ -6438,12 +6455,6 @@ void HistoryWidget::onListEscapePressed() {
|
|||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::onListEnterPressed() {
|
||||
if (!_botStart->isHidden()) {
|
||||
onBotStart();
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::clearSelected() {
|
||||
if (_list) {
|
||||
_list->clearSelected();
|
||||
|
|
|
@ -294,7 +294,6 @@ public:
|
|||
void stopRecording(bool send);
|
||||
|
||||
void onListEscapePressed();
|
||||
void onListEnterPressed();
|
||||
|
||||
void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo);
|
||||
void hideSingleUseKeyboard(PeerData *peer, MsgId replyTo);
|
||||
|
@ -439,7 +438,7 @@ private:
|
|||
using TabbedSelector = ChatHelpers::TabbedSelector;
|
||||
using DragState = Storage::MimeDataState;
|
||||
|
||||
void send();
|
||||
void send(Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers());
|
||||
void handlePendingHistoryUpdate();
|
||||
void fullPeerUpdated(PeerData *peer);
|
||||
void toggleTabbedSelectorMode();
|
||||
|
@ -450,7 +449,6 @@ private:
|
|||
void showNextUnreadMention();
|
||||
void handlePeerUpdate();
|
||||
void setMembersShowAreaActive(bool active);
|
||||
void forwardItems(MessageIdsList &&items);
|
||||
void handleHistoryChange(not_null<const History*> history);
|
||||
void refreshAboutProxyPromotion();
|
||||
void unreadCountUpdated();
|
||||
|
|
|
@ -9,8 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
#include "support/support_templates.h"
|
||||
#include "support/support_common.h"
|
||||
#include "history/view/history_view_message.h"
|
||||
#include "history/view/history_view_service_message.h"
|
||||
#include "history/history_message.h"
|
||||
|
@ -66,7 +68,7 @@ private:
|
|||
int _selected = -1;
|
||||
int _pressed = -1;
|
||||
bool _selectByKeys = false;
|
||||
rpl::event_stream<> _activated;
|
||||
rpl::event_stream<Qt::KeyboardModifiers> _activated;
|
||||
|
||||
};
|
||||
|
||||
|
@ -252,7 +254,7 @@ void Inner::mousePressEvent(QMouseEvent *e) {
|
|||
void Inner::mouseReleaseEvent(QMouseEvent *e) {
|
||||
const auto pressed = base::take(_pressed);
|
||||
if (pressed == _selected && pressed >= 0) {
|
||||
_activated.fire({});
|
||||
_activated.fire(e->modifiers());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,9 +375,9 @@ void Autocomplete::setupContent() {
|
|||
|
||||
const auto inner = scroll->setOwnedWidget(object_ptr<Inner>(scroll));
|
||||
|
||||
const auto submit = [=] {
|
||||
const auto submit = [=](Qt::KeyboardModifiers modifiers) {
|
||||
if (const auto question = inner->selected()) {
|
||||
submitValue(question->value);
|
||||
submitValue(question->value, modifiers);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -437,7 +439,9 @@ void Autocomplete::setupContent() {
|
|||
}, lifetime());
|
||||
}
|
||||
|
||||
void Autocomplete::submitValue(const QString &value) {
|
||||
void Autocomplete::submitValue(
|
||||
const QString &value,
|
||||
Qt::KeyboardModifiers modifiers) {
|
||||
const auto prefix = qstr("contact:");
|
||||
if (value.startsWith(prefix)) {
|
||||
const auto line = value.indexOf('\n');
|
||||
|
@ -457,7 +461,8 @@ void Autocomplete::submitValue(const QString &value) {
|
|||
text,
|
||||
phone,
|
||||
firstName,
|
||||
lastName });
|
||||
lastName,
|
||||
HandleSwitch(modifiers) });
|
||||
}
|
||||
} else {
|
||||
_insertRequests.fire_copy(value);
|
||||
|
@ -468,7 +473,7 @@ ConfirmContactBox::ConfirmContactBox(
|
|||
QWidget*,
|
||||
not_null<History*> history,
|
||||
const Contact &data,
|
||||
Fn<void()> submit)
|
||||
Fn<void(Qt::KeyboardModifiers)> submit)
|
||||
: _comment(GenerateCommentItem(this, history, data))
|
||||
, _contact(GenerateContactItem(this, history, data))
|
||||
, _submit(submit) {
|
||||
|
@ -499,16 +504,34 @@ void ConfirmContactBox::prepare() {
|
|||
setDimensions(width, height);
|
||||
_contact->initDimensions();
|
||||
|
||||
addButton(langFactory(lng_send_button), [=] {
|
||||
_submit = [=, original = std::move(_submit)](Qt::KeyboardModifiers m) {
|
||||
const auto weak = make_weak(this);
|
||||
_submit();
|
||||
original(m);
|
||||
if (weak) {
|
||||
closeBox();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const auto button = addButton(langFactory(lng_send_button), [] {});
|
||||
button->clicks(
|
||||
) | rpl::start_with_next([=](Qt::MouseButton which) {
|
||||
_submit((which == Qt::RightButton)
|
||||
? SkipSwitchModifiers()
|
||||
: button->clickModifiers());
|
||||
}, button->lifetime());
|
||||
button->setAcceptBoth(true);
|
||||
|
||||
addButton(langFactory(lng_cancel), [=] { closeBox(); });
|
||||
}
|
||||
|
||||
void ConfirmContactBox::keyPressEvent(QKeyEvent *e) {
|
||||
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
||||
_submit(e->modifiers());
|
||||
} else {
|
||||
BoxContent::keyPressEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfirmContactBox::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ struct Contact {
|
|||
QString phone;
|
||||
QString firstName;
|
||||
QString lastName;
|
||||
bool handleSwitch = false;
|
||||
};
|
||||
|
||||
class Autocomplete : public Ui::RpWidget {
|
||||
|
@ -44,7 +45,7 @@ protected:
|
|||
|
||||
private:
|
||||
void setupContent();
|
||||
void submitValue(const QString &value);
|
||||
void submitValue(const QString &value, Qt::KeyboardModifiers modifiers);
|
||||
|
||||
not_null<AuthSession*> _session;
|
||||
Fn<void()> _activate;
|
||||
|
@ -64,7 +65,7 @@ public:
|
|||
QWidget*,
|
||||
not_null<History*> history,
|
||||
const Contact &data,
|
||||
Fn<void()> submit);
|
||||
Fn<void(Qt::KeyboardModifiers)> submit);
|
||||
|
||||
using Element = HistoryView::Element;
|
||||
HistoryView::Context elementContext() override;
|
||||
|
@ -82,11 +83,12 @@ public:
|
|||
protected:
|
||||
void prepare() override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
|
||||
private:
|
||||
AdminLog::OwnedItem _comment;
|
||||
AdminLog::OwnedItem _contact;
|
||||
Fn<void()> _submit;
|
||||
Fn<void(Qt::KeyboardModifiers)> _submit;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -20,6 +20,16 @@ bool ValidateAccount(const MTPUser &self) {
|
|||
});
|
||||
}
|
||||
|
||||
bool HandleSwitch(Qt::KeyboardModifiers modifiers) {
|
||||
return !(modifiers & Qt::ShiftModifier)
|
||||
|| (!(modifiers & Qt::ControlModifier)
|
||||
&& !(modifiers & Qt::MetaModifier));
|
||||
}
|
||||
|
||||
Qt::KeyboardModifiers SkipSwitchModifiers() {
|
||||
return Qt::ControlModifier | Qt::ShiftModifier;
|
||||
}
|
||||
|
||||
void PerformSwitch(SwitchSettings value) {
|
||||
switch (value) {
|
||||
case SwitchSettings::Next:
|
||||
|
|
|
@ -17,6 +17,8 @@ enum class SwitchSettings {
|
|||
Previous,
|
||||
};
|
||||
|
||||
Qt::KeyboardModifiers SkipSwitchModifiers();
|
||||
bool HandleSwitch(Qt::KeyboardModifiers modifiers);
|
||||
void PerformSwitch(SwitchSettings value);
|
||||
|
||||
} // namespace Support
|
||||
|
|
|
@ -2473,19 +2473,28 @@ not_null<const QTextEdit*> InputField::rawTextEdit() const {
|
|||
return _inner.get();
|
||||
}
|
||||
|
||||
bool InputField::ShouldSubmit(
|
||||
SubmitSettings settings,
|
||||
Qt::KeyboardModifiers modifiers) {
|
||||
const auto shift = modifiers.testFlag(Qt::ShiftModifier);
|
||||
const auto ctrl = modifiers.testFlag(Qt::ControlModifier)
|
||||
|| modifiers.testFlag(Qt::MetaModifier);
|
||||
return (ctrl && shift)
|
||||
|| (ctrl
|
||||
&& settings != SubmitSettings::None
|
||||
&& settings != SubmitSettings::Enter)
|
||||
|| (!ctrl
|
||||
&& !shift
|
||||
&& settings != SubmitSettings::None
|
||||
&& settings != SubmitSettings::CtrlEnter);
|
||||
}
|
||||
|
||||
void InputField::keyPressEventInner(QKeyEvent *e) {
|
||||
bool shift = e->modifiers().testFlag(Qt::ShiftModifier), alt = e->modifiers().testFlag(Qt::AltModifier);
|
||||
bool macmeta = (cPlatform() == dbipMac || cPlatform() == dbipMacOld) && e->modifiers().testFlag(Qt::ControlModifier) && !e->modifiers().testFlag(Qt::MetaModifier) && !e->modifiers().testFlag(Qt::AltModifier);
|
||||
bool ctrl = e->modifiers().testFlag(Qt::ControlModifier) || e->modifiers().testFlag(Qt::MetaModifier);
|
||||
bool enterSubmit = (_mode == Mode::SingleLine)
|
||||
|| (ctrl && shift)
|
||||
|| (ctrl
|
||||
&& _submitSettings != SubmitSettings::None
|
||||
&& _submitSettings != SubmitSettings::Enter)
|
||||
|| (!ctrl
|
||||
&& !shift
|
||||
&& _submitSettings != SubmitSettings::None
|
||||
&& _submitSettings != SubmitSettings::CtrlEnter);
|
||||
|| ShouldSubmit(_submitSettings, e->modifiers());
|
||||
bool enter = (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return);
|
||||
if (e->key() == Qt::Key_Left
|
||||
|| e->key() == Qt::Key_Right
|
||||
|
|
|
@ -267,6 +267,9 @@ public:
|
|||
|
||||
using SubmitSettings = InputSubmitSettings;
|
||||
void setSubmitSettings(SubmitSettings settings);
|
||||
static bool ShouldSubmit(
|
||||
SubmitSettings settings,
|
||||
Qt::KeyboardModifiers modifiers);
|
||||
void customUpDown(bool isCustom);
|
||||
void customTab(bool isCustom);
|
||||
int borderAnimationStart() const;
|
||||
|
|
Loading…
Reference in New Issue