Add a configurable keyboard shortcut to commit text.

This new shortcut defaults to `ctrl+enter`, and it commits the text
you're currently typing. It does *not* change the behavior of enter
(pressing enter still inserts a newline), nor does it actually exit
flameshot. This isn't exactly what was requested, but I'm going to
somewhat cavalierly say that this fixes
https://github.com/flameshot-org/flameshot/issues/812.

*Note: I added a new user-visible string here, but I didn't update any
ts files. Is that ok?
This commit is contained in:
Jeremy Fleischman
2020-10-28 00:36:14 -07:00
committed by borgmanJeremy
parent 86fee7010c
commit c5e9def59f
3 changed files with 33 additions and 11 deletions

View File

@@ -235,6 +235,26 @@ QPixmap CaptureWidget::pixmap()
return m_context.selectedScreenshotArea();
}
// Finish whatever the current tool is doing, if there is a current active
// tool.
bool CaptureWidget::commitCurrentTool()
{
if (m_activeButton) {
if (m_activeTool) {
if (m_activeTool->isValid() && m_toolWidget) {
pushToolToStack();
} else {
m_activeTool->deleteLater();
}
if (m_toolWidget) {
m_toolWidget->deleteLater();
return true;
}
}
}
return false;
}
void CaptureWidget::deleteToolwidgetOrClose()
{
if (m_panel->isVisible()) {
@@ -335,16 +355,8 @@ void CaptureWidget::mousePressEvent(QMouseEvent* e)
m_mouseIsClicked = true;
// Click using a tool
if (m_activeButton) {
if (m_activeTool) {
if (m_activeTool->isValid() && m_toolWidget) {
pushToolToStack();
} else {
m_activeTool->deleteLater();
}
if (m_toolWidget) {
m_toolWidget->deleteLater();
return;
}
if (commitCurrentTool()) {
return;
}
m_activeTool = m_activeButton->tool()->copy(this);
@@ -997,6 +1009,11 @@ void CaptureWidget::initShortcuts()
this,
SLOT(downMove()));
new QShortcut(
QKeySequence(ConfigHandler().shortcut("TYPE_COMMIT_CURRENT_TOOL")),
this,
SLOT(commitCurrentTool()));
new QShortcut(Qt::Key_Escape, this, SLOT(deleteToolwidgetOrClose()));
}
@@ -1145,4 +1162,4 @@ QRect CaptureWidget::extendedRect(QRect* r) const
r->top() * devicePixelRatio,
r->width() * devicePixelRatio,
r->height() * devicePixelRatio);
}
}