Skip to content

Commit ecdb353

Browse files
juzu-oCopilotdroidmonkey
authored andcommitted
Add URL auto-type and copy options to auto-type selection popup and menus (keepassxreboot#12341)
* Added "Type {URL}" option to the auto-type selection popup right-click context menu * Added "Copy {URL}" option to the auto-type selection popup right-click context menu * Added keyboard shortcuts: CTRL+4 for "Type {URL}" and CTRL+SHIFT+4 for "Copy {URL}" * Updated "Use Virtual Keyboard" shortcut from CTRL+4 to CTRL+5 to avoid inconsistency with order of shortcuts * Added URL auto-type options "{URL}" and "{URL}{ENTER}" to main window entry view right-click menu * Added URL auto-type options "{URL}" and "{URL}{ENTER}" to toolbar auto-type button dropdown menu * Added translation strings for "Type {URL}" and "Copy {URL}" to support internationalization --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: juzu-o <[email protected]> Co-authored-by: Jonathan White <[email protected]>
1 parent 14d040f commit ecdb353

File tree

7 files changed

+105
-17
lines changed

7 files changed

+105
-17
lines changed

share/translations/keepassxc_en.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -800,15 +800,6 @@
800800
<source>Double click a row to perform Auto-Type or find an entry using the search:</source>
801801
<translation type="unfinished"></translation>
802802
</message>
803-
<message>
804-
<source>&lt;p&gt;You can use advanced search queries to find any entry in your open databases. The following shortcuts are useful:&lt;br/&gt;
805-
Ctrl+F - Toggle database search&lt;br/&gt;
806-
Ctrl+1 - Type username&lt;br/&gt;
807-
Ctrl+2 - Type password&lt;br/&gt;
808-
Ctrl+3 - Type TOTP&lt;br/&gt;
809-
Ctrl+4 - Use Virtual Keyboard (Windows Only)&lt;/p&gt;</source>
810-
<translation type="unfinished"></translation>
811-
</message>
812803
<message>
813804
<source>Search all open databases</source>
814805
<translation type="unfinished"></translation>
@@ -853,6 +844,24 @@ Ctrl+4 - Use Virtual Keyboard (Windows Only)&lt;/p&gt;</source>
853844
<source>Use Virtual Keyboard</source>
854845
<translation type="unfinished"></translation>
855846
</message>
847+
<message>
848+
<source>&lt;p&gt;You can use advanced search queries to find any entry in your open databases. The following shortcuts are useful:&lt;br/&gt;
849+
Ctrl+F - Toggle database search&lt;br/&gt;
850+
Ctrl+1 - Type username&lt;br/&gt;
851+
Ctrl+2 - Type password&lt;br/&gt;
852+
Ctrl+3 - Type TOTP&lt;br/&gt;
853+
Ctrl+4 - Type URL&lt;br/&gt;
854+
Ctrl+5 - Use Virtual Keyboard (Windows Only)&lt;/p&gt;</source>
855+
<translation type="unfinished"></translation>
856+
</message>
857+
<message>
858+
<source>Type {URL}</source>
859+
<translation type="unfinished"></translation>
860+
</message>
861+
<message>
862+
<source>Copy URL</source>
863+
<translation type="unfinished"></translation>
864+
</message>
856865
</context>
857866
<context>
858867
<name>BrowserAccessControlDialog</name>

src/autotype/AutoTypeSelectDialog.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum MENU_FIELD
3737
USERNAME = 1,
3838
PASSWORD,
3939
TOTP,
40+
URL,
4041
};
4142

4243
AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
@@ -265,6 +266,7 @@ void AutoTypeSelectDialog::updateActionMenu(const AutoTypeMatch& match)
265266
bool hasUsername = !match.first->username().isEmpty();
266267
bool hasPassword = !match.first->password().isEmpty();
267268
bool hasTotp = match.first->hasValidTotp();
269+
bool hasUrl = !match.first->url().isEmpty();
268270

269271
for (auto action : m_actionMenu->actions()) {
270272
auto prop = action->property(MENU_FIELD_PROP_NAME);
@@ -279,6 +281,9 @@ void AutoTypeSelectDialog::updateActionMenu(const AutoTypeMatch& match)
279281
case MENU_FIELD::TOTP:
280282
action->setEnabled(hasTotp);
281283
break;
284+
case MENU_FIELD::URL:
285+
action->setEnabled(hasUrl);
286+
break;
282287
}
283288
}
284289
}
@@ -290,15 +295,19 @@ void AutoTypeSelectDialog::buildActionMenu()
290295
auto typeUsernameAction = new QAction(icons()->icon("auto-type"), tr("Type {USERNAME}"), this);
291296
auto typePasswordAction = new QAction(icons()->icon("auto-type"), tr("Type {PASSWORD}"), this);
292297
auto typeTotpAction = new QAction(icons()->icon("auto-type"), tr("Type {TOTP}"), this);
298+
auto typeUrlAction = new QAction(icons()->icon("auto-type"), tr("Type {URL}"), this);
293299
auto copyUsernameAction = new QAction(icons()->icon("username-copy"), tr("Copy Username"), this);
294300
auto copyPasswordAction = new QAction(icons()->icon("password-copy"), tr("Copy Password"), this);
295301
auto copyTotpAction = new QAction(icons()->icon("totp"), tr("Copy TOTP"), this);
302+
auto copyUrlAction = new QAction(icons()->icon("url-copy"), tr("Copy URL"), this);
296303
m_actionMenu->addAction(typeUsernameAction);
297304
m_actionMenu->addAction(typePasswordAction);
298305
m_actionMenu->addAction(typeTotpAction);
306+
m_actionMenu->addAction(typeUrlAction);
299307
m_actionMenu->addAction(copyUsernameAction);
300308
m_actionMenu->addAction(copyPasswordAction);
301309
m_actionMenu->addAction(copyTotpAction);
310+
m_actionMenu->addAction(copyUrlAction);
302311

303312
typeUsernameAction->setShortcut(Qt::CTRL + Qt::Key_1);
304313
typeUsernameAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::USERNAME);
@@ -324,10 +333,18 @@ void AutoTypeSelectDialog::buildActionMenu()
324333
submitAutoTypeMatch(match);
325334
});
326335

336+
typeUrlAction->setShortcut(Qt::CTRL + Qt::Key_4);
337+
typeUrlAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::URL);
338+
connect(typeUrlAction, &QAction::triggered, this, [&] {
339+
auto match = m_ui->view->currentMatch();
340+
match.second = "{URL}";
341+
submitAutoTypeMatch(match);
342+
});
343+
327344
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
328345
auto typeVirtualAction = new QAction(icons()->icon("auto-type"), tr("Use Virtual Keyboard"), nullptr);
329346
m_actionMenu->insertAction(copyUsernameAction, typeVirtualAction);
330-
typeVirtualAction->setShortcut(Qt::CTRL + Qt::Key_4);
347+
typeVirtualAction->setShortcut(Qt::CTRL + Qt::Key_5);
331348
connect(typeVirtualAction, &QAction::triggered, this, [&] {
332349
m_virtualMode = true;
333350
activateCurrentMatch();
@@ -364,17 +381,29 @@ void AutoTypeSelectDialog::buildActionMenu()
364381
}
365382
});
366383

384+
copyUrlAction->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_4);
385+
copyUrlAction->setProperty(MENU_FIELD_PROP_NAME, MENU_FIELD::URL);
386+
connect(copyUrlAction, &QAction::triggered, this, [&] {
387+
auto entry = m_ui->view->currentMatch().first;
388+
if (entry) {
389+
clipboard()->setText(entry->resolvePlaceholder(entry->url()));
390+
reject();
391+
}
392+
});
393+
367394
// Qt 5.10 introduced a new "feature" to hide shortcuts in context menus
368395
// Unfortunately, Qt::AA_DontShowShortcutsInContextMenus is broken, have to manually enable them
369396
typeUsernameAction->setShortcutVisibleInContextMenu(true);
370397
typePasswordAction->setShortcutVisibleInContextMenu(true);
371398
typeTotpAction->setShortcutVisibleInContextMenu(true);
399+
typeUrlAction->setShortcutVisibleInContextMenu(true);
372400
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
373401
typeVirtualAction->setShortcutVisibleInContextMenu(true);
374402
#endif
375403
copyUsernameAction->setShortcutVisibleInContextMenu(true);
376404
copyPasswordAction->setShortcutVisibleInContextMenu(true);
377405
copyTotpAction->setShortcutVisibleInContextMenu(true);
406+
copyUrlAction->setShortcutVisibleInContextMenu(true);
378407
}
379408

380409
void AutoTypeSelectDialog::showEvent(QShowEvent* event)

src/autotype/AutoTypeSelectDialog.ui

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@
5050
<property name="focusPolicy">
5151
<enum>Qt::NoFocus</enum>
5252
</property>
53-
<property name="toolTip">
54-
<string>&lt;p&gt;You can use advanced search queries to find any entry in your open databases. The following shortcuts are useful:&lt;br/&gt;
55-
Ctrl+F - Toggle database search&lt;br/&gt;
56-
Ctrl+1 - Type username&lt;br/&gt;
57-
Ctrl+2 - Type password&lt;br/&gt;
58-
Ctrl+3 - Type TOTP&lt;br/&gt;
59-
Ctrl+4 - Use Virtual Keyboard (Windows Only)&lt;/p&gt;</string>
53+
<property name="toolTip">
54+
<string>&lt;p&gt;You can use advanced search queries to find any entry in your open databases. The following shortcuts are useful:&lt;br/&gt;
55+
Ctrl+F - Toggle database search&lt;br/&gt;
56+
Ctrl+1 - Type username&lt;br/&gt;
57+
Ctrl+2 - Type password&lt;br/&gt;
58+
Ctrl+3 - Type TOTP&lt;br/&gt;
59+
Ctrl+4 - Type URL&lt;br/&gt;
60+
Ctrl+5 - Use Virtual Keyboard (Windows Only)&lt;/p&gt;</string>
6061
</property>
6162
<property name="styleSheet">
6263
<string notr="true">QToolButton {

src/gui/DatabaseWidget.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,16 @@ void DatabaseWidget::performAutoTypeTOTP()
924924
performAutoType(QStringLiteral("{TOTP}"));
925925
}
926926

927+
void DatabaseWidget::performAutoTypeURL()
928+
{
929+
performAutoType(QStringLiteral("{URL}"));
930+
}
931+
932+
void DatabaseWidget::performAutoTypeURLEnter()
933+
{
934+
performAutoType(QStringLiteral("{URL}{ENTER}"));
935+
}
936+
927937
void DatabaseWidget::openUrl()
928938
{
929939
auto currentEntry = currentSelectedEntry();

src/gui/DatabaseWidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ public slots:
214214
void performAutoTypePassword();
215215
void performAutoTypePasswordEnter();
216216
void performAutoTypeTOTP();
217+
void performAutoTypeURL();
218+
void performAutoTypeURLEnter();
217219
void setClipboardTextAndMinimize(const QString& text);
218220
void openUrl();
219221
void downloadSelectedFavicons();

src/gui/MainWindow.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ MainWindow::MainWindow()
172172
autotypeMenu->addAction(m_ui->actionEntryAutoTypePassword);
173173
autotypeMenu->addAction(m_ui->actionEntryAutoTypePasswordEnter);
174174
autotypeMenu->addAction(m_ui->actionEntryAutoTypeTOTP);
175+
autotypeMenu->addAction(m_ui->actionEntryAutoTypeURL);
176+
autotypeMenu->addAction(m_ui->actionEntryAutoTypeURLEnter);
175177
m_ui->actionEntryAutoType->setMenu(autotypeMenu);
176178
auto autoTypeButton = qobject_cast<QToolButton*>(m_ui->toolBar->widgetForAction(m_ui->actionEntryAutoType));
177179
if (autoTypeButton) {
@@ -387,6 +389,8 @@ MainWindow::MainWindow()
387389
m_ui->actionEntryAutoTypePassword->setIcon(icons()->icon("auto-type"));
388390
m_ui->actionEntryAutoTypePasswordEnter->setIcon(icons()->icon("auto-type"));
389391
m_ui->actionEntryAutoTypeTOTP->setIcon(icons()->icon("auto-type"));
392+
m_ui->actionEntryAutoTypeURL->setIcon(icons()->icon("auto-type"));
393+
m_ui->actionEntryAutoTypeURLEnter->setIcon(icons()->icon("auto-type"));
390394
m_ui->actionEntryMoveUp->setIcon(icons()->icon("move-up"));
391395
m_ui->actionEntryMoveDown->setIcon(icons()->icon("move-down"));
392396
m_ui->actionEntryCopyUsername->setIcon(icons()->icon("username-copy"));
@@ -526,6 +530,9 @@ MainWindow::MainWindow()
526530
m_actionMultiplexer.connect(
527531
m_ui->actionEntryAutoTypePasswordEnter, SIGNAL(triggered()), SLOT(performAutoTypePasswordEnter()));
528532
m_actionMultiplexer.connect(m_ui->actionEntryAutoTypeTOTP, SIGNAL(triggered()), SLOT(performAutoTypeTOTP()));
533+
m_actionMultiplexer.connect(m_ui->actionEntryAutoTypeURL, SIGNAL(triggered()), SLOT(performAutoTypeURL()));
534+
m_actionMultiplexer.connect(
535+
m_ui->actionEntryAutoTypeURLEnter, SIGNAL(triggered()), SLOT(performAutoTypeURLEnter()));
529536
m_actionMultiplexer.connect(m_ui->actionEntryOpenUrl, SIGNAL(triggered()), SLOT(openUrl()));
530537
m_actionMultiplexer.connect(m_ui->actionEntryDownloadIcon, SIGNAL(triggered()), SLOT(downloadSelectedFavicons()));
531538
#ifdef WITH_XC_SSHAGENT
@@ -976,6 +983,8 @@ void MainWindow::updateMenuActionState()
976983
m_ui->actionEntryAutoTypePassword->setEnabled(singleEntrySelected && dbWidget->currentEntryHasPassword());
977984
m_ui->actionEntryAutoTypePasswordEnter->setEnabled(singleEntrySelected && dbWidget->currentEntryHasPassword());
978985
m_ui->actionEntryAutoTypeTOTP->setEnabled(singleEntrySelected && dbWidget->currentEntryHasTotp());
986+
m_ui->actionEntryAutoTypeURL->setEnabled(singleEntrySelected && dbWidget->currentEntryHasUrl());
987+
m_ui->actionEntryAutoTypeURLEnter->setEnabled(singleEntrySelected && dbWidget->currentEntryHasUrl());
979988
m_ui->actionEntryAutoTypeTOTP->setVisible(singleEntrySelected && dbWidget->currentEntryHasTotp());
980989
m_ui->actionEntryOpenUrl->setEnabled(singleEntryOrEditing && dbWidget->currentEntryHasUrl());
981990
m_ui->actionEntryTotp->setEnabled(singleEntrySelected && dbWidget->currentEntryHasTotp());

src/gui/MainWindow.ui

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,34 @@
859859
<string>Perform Auto-Type: {TOTP}</string>
860860
</property>
861861
</action>
862+
<action name="actionEntryAutoTypeURL">
863+
<property name="enabled">
864+
<bool>false</bool>
865+
</property>
866+
<property name="text">
867+
<string notr="true">{URL}</string>
868+
</property>
869+
<property name="iconText">
870+
<string notr="true">{URL}</string>
871+
</property>
872+
<property name="toolTip">
873+
<string notr="true">{URL}</string>
874+
</property>
875+
</action>
876+
<action name="actionEntryAutoTypeURLEnter">
877+
<property name="enabled">
878+
<bool>false</bool>
879+
</property>
880+
<property name="text">
881+
<string notr="true">{URL}{ENTER}</string>
882+
</property>
883+
<property name="iconText">
884+
<string notr="true">{URL}{ENTER}</string>
885+
</property>
886+
<property name="toolTip">
887+
<string notr="true">{URL}{ENTER}</string>
888+
</property>
889+
</action>
862890
<action name="actionEntryDownloadIcon">
863891
<property name="text">
864892
<string>Download &amp;Favicon</string>

0 commit comments

Comments
 (0)