From 329831d98697b8c72c522766c3c2a05a6ce98d69 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Sat, 26 Sep 2026 13:29:16 +1200 Subject: [PATCH] Repeat the last drawing or placing command with Enter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enter on a folio runs the last drawing or placing command again, as it does in SolidWorks: the last tool from the add-item family (text, line, rectangle, terminal strip plan...) or the last element placed, however it was placed -- dragged, double-clicked, picked, or from the shortcut bar. Enter is handled in DiagramView::keyPressEvent, not bound as a shortcut, so it keeps working everywhere else: search fields, the collection tree, dialogs. On the folio it is left alone while a tool is running or an item has the focus (a text being edited), and with any modifier held. The same command is in Édition, named after what it will do -- "Répéter : Ajouter une ligne", "Répéter : insérer « Diode »" -- and registered with ShortcutManager (diagrameditor.repeat_last_command, no default key), so it can be bound or put on the shortcut bar. Discussion #1033. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG (cherry picked from commit 1e06ce97961ee18734ddaaa9b72b0303a169b9b2) --- sources/diagramview.cpp | 12 ++++++++ sources/qetdiagrameditor.cpp | 55 ++++++++++++++++++++++++++++++++++++ sources/qetdiagrameditor.h | 6 ++++ 3 files changed, 73 insertions(+) diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 39feac21c..e6be0675a 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -963,6 +963,18 @@ void DiagramView::keyPressEvent(QKeyEvent *e) focusNextChild(); } return; + case Qt::Key_Return: + case Qt::Key_Enter: + //Repeat the last drawing or placing command, as SolidWorks + //does. Not while a tool is running or a text has the focus: + //both use Enter themselves. + if (e->modifiers() == Qt::NoModifier + && !m_diagram->eventInterfaceIsRunning() + && !m_diagram->focusItem() + && diagramEditor()->repeatLastCommand()) { + return; + } + break; case Qt::Key_PageUp: current_project->changeTabUp(); return; diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 516d13c16..28124445e 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -857,6 +857,21 @@ void QETDiagramEditor::setUpActions() this, &QETDiagramEditor::showShortcutBar); addAction(m_show_shortcut_bar); + //Enter on the folio repeats it (DiagramView::keyPressEvent). That is + //handled by the view rather than bound here, so Enter keeps working + //in the search fields, the collection tree and every dialog. + m_repeat_last_command = new QAction(tr("Répéter la dernière commande"), this); + m_repeat_last_command->setStatusTip( + tr("Relance le dernier outil de dessin ou la dernière insertion d'élément (Entrée sur le folio)", + "status bar tip")); + m_repeat_last_command->setEnabled(false); + ShortcutManager::instance().registerAction( + m_repeat_last_command, "diagrameditor.repeat_last_command", + tr("Éditeur de schémas"), QKeySequence()); + connect(m_repeat_last_command, &QAction::triggered, + this, &QETDiagramEditor::repeatLastCommand); + addAction(m_repeat_last_command); + m_delete_selection->setStatusTip( tr("Enlève les éléments sélectionnés du folio", "status bar tip")); m_rotate_selection->setStatusTip( tr("Pivote les éléments et textes sélectionnés", "status bar tip")); m_rotate_group_selection->setStatusTip( tr("Pivote la sélection comme un groupe autour de son centre, au lieu de chaque élément sur place", "status bar tip")); @@ -1151,6 +1166,7 @@ void QETDiagramEditor::setUpMenu() menu_edition -> addAction(m_insert_last_element); menu_edition -> addAction(m_show_element_picker); menu_edition -> addAction(m_show_shortcut_bar); + menu_edition -> addAction(m_repeat_last_command); menu_edition -> addSeparator(); //The same actions the "Ajouter" toolbar holds. They were toolbar-only, //which left them unreachable for anyone working without a mouse: a @@ -1865,6 +1881,8 @@ void QETDiagramEditor::addItemGroupTriggered(QAction *action) return; } + setLastCommand(action); + DiagramEventInterface *diagram_event = nullptr; if (value == "line") @@ -2061,6 +2079,8 @@ void QETDiagramEditor::slot_updateActions() m_insert_last_element-> setEnabled(opened_diagram && editable_project && !m_last_inserted_element.isNull()); m_show_element_picker-> setEnabled(opened_diagram && editable_project); m_show_shortcut_bar-> setEnabled(opened_diagram && editable_project); + m_repeat_last_command-> setEnabled(opened_diagram && editable_project + && m_last_command && m_last_command->isEnabled()); m_row_column_actions_group. setEnabled(editable_project); m_background_color_button-> setEnabled(opened_diagram); m_draw_grid-> setEnabled(opened_diagram); @@ -3096,6 +3116,41 @@ void QETDiagramEditor::rememberPlacedElement(const ElementsLocation &location) { m_last_inserted_element = location; m_insert_last_element->setEnabled(true); + setLastCommand(m_insert_last_element); +} + +/** + @brief QETDiagramEditor::setLastCommand + Remember @a action as the command Enter repeats, and name it in the + Édition menu entry so it is clear what will happen. +*/ +void QETDiagramEditor::setLastCommand(QAction *action) +{ + m_last_command = action; + m_repeat_last_command->setText( + action == m_insert_last_element + ? tr("Répéter : insérer « %1 »").arg(m_last_inserted_element.name()) + : tr("Répéter : %1").arg(action->text().remove(QLatin1Char('&')))); + slot_updateActions(); +} + +/** + @brief QETDiagramEditor::repeatLastCommand + Run the last drawing or placing command again -- a line, a text field, + the last element -- as Enter does in SolidWorks. + @return true if a command was run +*/ +bool QETDiagramEditor::repeatLastCommand() +{ + if (!m_last_command || !m_repeat_last_command->isEnabled()) { + return false; + } + //A tool that is still on would be switched off by triggering it + if (m_last_command->isCheckable() && m_last_command->isChecked()) { + return false; + } + m_last_command->trigger(); + return true; } /** diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index 7a6abc53a..161be3709 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -133,6 +134,7 @@ class QETDiagramEditor : public QETMainWindow void rememberPlacedElement(const ElementsLocation &location); void showElementPicker(); void showShortcutBar(); + bool repeatLastCommand(); void generateTerminalBlock(); void setWindowedMode(); void setTabbedMode(); @@ -277,6 +279,10 @@ class QETDiagramEditor : public QETMainWindow ElementPickerPopup *elementPicker(); QAction *m_show_element_picker = nullptr; QAction *m_show_shortcut_bar = nullptr; + QAction *m_repeat_last_command = nullptr; + /// What Enter on the folio repeats + QPointer m_last_command; + void setLastCommand(QAction *action); ElementPickerPopup *m_element_picker = nullptr; ///< Built on first use ElementsCollectionWidget *m_element_collection_widget; /// Last element placed from the collection, for "insert last"