Conversation
Cuperino
commented
Mar 29, 2025
- feat: Add New, Open, and Save shortcuts to Script Panel
- fix: Check whether script needs to be saved before opening a new one
narnaud
left a comment
There was a problem hiding this comment.
It would be better to add shrtucts to the ScriptPanel::ScriptPanel.
This way the shortcuts will be visible on hover (better for discoverability).
The only problem will be to handle the same shortcuts multiple time, I can't remmeber if Qt do that nicely by derfault. Another option will be to use Ctrl+Alt+Foo for example.
|
I like the idea of handling them from ScriptPanel::ScriptPanel. Need to look how that would be done without creating conflicting bindings. In QML one can have one event handling function call another, effectively forwarding events conditionally. I wouldn't go for Ctrl+Alt+Foo because that would go against muscle memory. Standard binding outcomes should adapt according on the context. |
b67c689 to
7c2bd13
Compare
| auto document = Core::Project::instance()->currentDocument(); | ||
| if (document) | ||
| document->save(); | ||
| } |
There was a problem hiding this comment.
I would prefer to not change the mainwindow.cpp - after all, those actions are specific to the script panel.
We could do that with a QShortcut in ScriptPanel:
auto shortcut = new QShortcut(QKeySequence::Open, this);
shortcut->setContext(Qt::WidgetWithChildrenShortcut);
connect(shortcut, &QShortcut::activatedAmbiguously, this, &ScriptPanel::openScript);
Or, maybe better, create actions on the tool buttons and assign non-ambiguous shortcuts (Shift+Ctrl+...).
| } | ||
| return; | ||
| } | ||
| case Qt::Key_N: |
There was a problem hiding this comment.
This can be done in one line in the constrtuctor with:
newScriptAction->setShortcut(QKeySequence::New);
If you are afraid of ambiguous shortcuts, see for the others