Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable entry actions when editing an entry and cleanup entry context menu #3641

Merged
merged 2 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 43 additions & 26 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ bool DatabaseWidget::isSearchActive() const
return m_entryView->inSearchMode();
}

bool DatabaseWidget::isEntryEditActive() const
{
return currentWidget() == m_editEntryWidget;
}

bool DatabaseWidget::isEditWidgetModified() const
{
if (currentWidget() == m_editEntryWidget) {
Expand Down Expand Up @@ -397,7 +402,7 @@ void DatabaseWidget::replaceDatabase(QSharedPointer<Database> db)

void DatabaseWidget::cloneEntry()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) {
return;
Expand All @@ -409,7 +414,7 @@ void DatabaseWidget::cloneEntry()

void DatabaseWidget::showTotp()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) {
return;
Expand All @@ -421,7 +426,7 @@ void DatabaseWidget::showTotp()

void DatabaseWidget::copyTotp()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) {
return;
Expand All @@ -431,7 +436,7 @@ void DatabaseWidget::copyTotp()

void DatabaseWidget::setupTotp()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) {
return;
Expand Down Expand Up @@ -568,47 +573,47 @@ void DatabaseWidget::setFocus()

void DatabaseWidget::copyTitle()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
if (currentEntry) {
setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->title()));
}
}

void DatabaseWidget::copyUsername()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
if (currentEntry) {
setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->username()));
}
}

void DatabaseWidget::copyPassword()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
if (currentEntry) {
setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->password()));
}
}

void DatabaseWidget::copyURL()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
if (currentEntry) {
setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->url()));
}
}

void DatabaseWidget::copyNotes()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
if (currentEntry) {
setClipboardTextAndMinimize(currentEntry->resolveMultiplePlaceholders(currentEntry->notes()));
}
}

void DatabaseWidget::copyAttribute(QAction* action)
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
if (currentEntry) {
setClipboardTextAndMinimize(
currentEntry->resolveMultiplePlaceholders(currentEntry->attributes()->value(action->data().toString())));
Expand All @@ -617,7 +622,7 @@ void DatabaseWidget::copyAttribute(QAction* action)

void DatabaseWidget::showTotpKeyQrCode()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
if (currentEntry) {
auto totpDisplayDialog = new TotpExportSettingsDialog(this, currentEntry);
totpDisplayDialog->open();
Expand All @@ -638,15 +643,15 @@ void DatabaseWidget::setClipboardTextAndMinimize(const QString& text)

void DatabaseWidget::performAutoType()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
if (currentEntry) {
autoType()->performAutoType(currentEntry, window());
}
}

void DatabaseWidget::openUrl()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
if (currentEntry) {
openUrlForEntry(currentEntry);
}
Expand Down Expand Up @@ -749,6 +754,15 @@ void DatabaseWidget::openUrlForEntry(Entry* entry)
}
}

Entry* DatabaseWidget::currentSelectedEntry()
{
if (currentWidget() == m_editEntryWidget) {
return m_editEntryWidget->currentEntry();
}

return m_entryView->currentEntry();
}

void DatabaseWidget::createGroup()
{
Q_ASSERT(m_groupView->currentGroup());
Expand Down Expand Up @@ -845,7 +859,8 @@ void DatabaseWidget::switchToMainView(bool previousDialogAccepted)

void DatabaseWidget::switchToHistoryView(Entry* entry)
{
m_historyEditEntryWidget->loadEntry(entry, false, true, m_editEntryWidget->entryTitle(), m_db);
auto entryTitle = m_editEntryWidget->currentEntry() ? m_editEntryWidget->currentEntry()->title() : "";
m_historyEditEntryWidget->loadEntry(entry, false, true, entryTitle, m_db);
setCurrentWidget(m_historyEditEntryWidget);
}

Expand All @@ -869,10 +884,13 @@ void DatabaseWidget::switchToEntryEdit(Entry* entry, bool create)
group = currentGroup();
} else {
group = entry->group();
// Ensure we have only this entry selected
m_entryView->setCurrentEntry(entry);
}

Q_ASSERT(group);

// Setup the entry edit widget and display
m_editEntryWidget->loadEntry(entry, create, false, group->name(), m_db);
setCurrentWidget(m_editEntryWidget);
}
Expand Down Expand Up @@ -1099,8 +1117,7 @@ void DatabaseWidget::switchToImportOpVault(const QString& fileName)

void DatabaseWidget::switchToEntryEdit()
{
Entry* entry = m_entryView->currentEntry();

auto entry = m_entryView->currentEntry();
if (!entry) {
return;
}
Expand All @@ -1110,8 +1127,7 @@ void DatabaseWidget::switchToEntryEdit()

void DatabaseWidget::switchToGroupEdit()
{
Group* group = m_groupView->currentGroup();

auto group = m_groupView->currentGroup();
if (!group) {
return;
}
Expand Down Expand Up @@ -1362,8 +1378,9 @@ bool DatabaseWidget::lock()
m_groupBeforeLock = m_db->rootGroup()->uuid();
}

if (m_entryView->currentEntry()) {
m_entryBeforeLock = m_entryView->currentEntry()->uuid();
auto currentEntry = currentSelectedEntry();
if (currentEntry) {
m_entryBeforeLock = currentEntry->uuid();
}

endSearch();
Expand Down Expand Up @@ -1482,7 +1499,7 @@ bool DatabaseWidget::currentEntryHasFocus()

bool DatabaseWidget::currentEntryHasTitle()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) {
return false;
Expand All @@ -1492,7 +1509,7 @@ bool DatabaseWidget::currentEntryHasTitle()

bool DatabaseWidget::currentEntryHasUsername()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) {
return false;
Expand All @@ -1502,7 +1519,7 @@ bool DatabaseWidget::currentEntryHasUsername()

bool DatabaseWidget::currentEntryHasPassword()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) {
return false;
Expand All @@ -1512,7 +1529,7 @@ bool DatabaseWidget::currentEntryHasPassword()

bool DatabaseWidget::currentEntryHasUrl()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) {
return false;
Expand All @@ -1522,7 +1539,7 @@ bool DatabaseWidget::currentEntryHasUrl()

bool DatabaseWidget::currentEntryHasTotp()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) {
return false;
Expand All @@ -1532,7 +1549,7 @@ bool DatabaseWidget::currentEntryHasTotp()

bool DatabaseWidget::currentEntryHasNotes()
{
Entry* currentEntry = m_entryView->currentEntry();
auto currentEntry = currentSelectedEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/DatabaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class DatabaseWidget : public QStackedWidget
DatabaseWidget::Mode currentMode() const;
bool isLocked() const;
bool isSearchActive() const;
bool isEntryEditActive() const;

QString getCurrentSearch();
void refreshSearch();
Expand Down Expand Up @@ -234,6 +235,7 @@ private slots:
void processAutoOpen();
bool confirmDeleteEntries(QList<Entry*> entries, bool permanent);
void performIconDownloads(const QList<Entry*>& entries, bool force = false);
Entry* currentSelectedEntry();

QSharedPointer<Database> m_db;

Expand Down
55 changes: 45 additions & 10 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ MainWindow::MainWindow()

m_countDefaultAttributes = m_ui->menuEntryCopyAttribute->actions().size();

m_entryContextMenu = new QMenu(this);
m_entryContextMenu->addAction(m_ui->actionEntryCopyUsername);
m_entryContextMenu->addAction(m_ui->actionEntryCopyPassword);
m_entryContextMenu->addAction(m_ui->menuEntryCopyAttribute->menuAction());
m_entryContextMenu->addAction(m_ui->menuEntryTotp->menuAction());
m_entryContextMenu->addSeparator();
m_entryContextMenu->addAction(m_ui->actionEntryAutoType);
m_entryContextMenu->addSeparator();
m_entryContextMenu->addAction(m_ui->actionEntryEdit);
m_entryContextMenu->addAction(m_ui->actionEntryClone);
m_entryContextMenu->addAction(m_ui->actionEntryDelete);
m_entryContextMenu->addSeparator();
m_entryContextMenu->addAction(m_ui->actionEntryOpenUrl);
m_entryContextMenu->addAction(m_ui->actionEntryDownloadIcon);

restoreGeometry(config()->get("GUI/MainWindowGeometry").toByteArray());
restoreState(config()->get("GUI/MainWindowState").toByteArray());
#ifdef WITH_XC_BROWSER
Expand Down Expand Up @@ -639,13 +654,33 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
case DatabaseWidget::Mode::EditMode:
case DatabaseWidget::Mode::ImportMode:
case DatabaseWidget::Mode::LockedMode: {
const QList<QAction*> entryActions = m_ui->menuEntries->actions();
for (QAction* action : entryActions) {
action->setEnabled(false);
// Enable select actions when editing an entry
bool editEntryActive = dbWidget->isEntryEditActive();
const auto editEntryActionsMask = QList<QAction*>({m_ui->actionEntryCopyUsername,
m_ui->actionEntryCopyPassword,
m_ui->actionEntryCopyURL,
m_ui->actionEntryOpenUrl,
m_ui->actionEntryAutoType,
m_ui->actionEntryDownloadIcon,
m_ui->actionEntryCopyNotes,
m_ui->actionEntryCopyTitle,
m_ui->menuEntryCopyAttribute->menuAction(),
m_ui->menuEntryTotp->menuAction(),
m_ui->actionEntrySetupTotp});

auto entryActions = m_ui->menuEntries->actions();
entryActions << m_ui->menuEntryCopyAttribute->actions();
entryActions << m_ui->menuEntryTotp->actions();
for (auto action : entryActions) {
bool enabled = editEntryActive && editEntryActionsMask.contains(action);
if (action->menu()) {
action->menu()->setEnabled(enabled);
}
action->setEnabled(enabled);
}

const QList<QAction*> groupActions = m_ui->menuGroups->actions();
for (QAction* action : groupActions) {
const auto groupActions = m_ui->menuGroups->actions();
for (auto action : groupActions) {
action->setEnabled(false);
}

Expand All @@ -666,13 +701,13 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
}
m_ui->actionDatabaseClose->setEnabled(true);
} else {
const QList<QAction*> entryActions = m_ui->menuEntries->actions();
for (QAction* action : entryActions) {
const auto entryActions = m_ui->menuEntries->actions();
for (auto action : entryActions) {
action->setEnabled(false);
}

const QList<QAction*> groupActions = m_ui->menuGroups->actions();
for (QAction* action : groupActions) {
const auto groupActions = m_ui->menuGroups->actions();
for (auto action : groupActions) {
action->setEnabled(false);
}

Expand Down Expand Up @@ -1090,7 +1125,7 @@ void MainWindow::releaseContextFocusLock()

void MainWindow::showEntryContextMenu(const QPoint& globalPos)
{
m_ui->menuEntries->popup(globalPos);
m_entryContextMenu->popup(globalPos);
}

void MainWindow::showGroupContextMenu(const QPoint& globalPos)
Expand Down
1 change: 1 addition & 0 deletions src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ private slots:
SignalMultiplexer m_actionMultiplexer;
QAction* m_clearHistoryAction;
QAction* m_searchWidgetAction;
QMenu* m_entryContextMenu;
QActionGroup* m_lastDatabasesActions;
QActionGroup* m_copyAdditionalAttributeActions;
InactivityTimer* m_inactivityTimer;
Expand Down
6 changes: 3 additions & 3 deletions src/gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>20</height>
<height>21</height>
</rect>
</property>
<property name="focusPolicy">
Expand Down Expand Up @@ -298,11 +298,11 @@
<addaction name="actionEntryCopyUsername"/>
<addaction name="actionEntryCopyPassword"/>
<addaction name="menuEntryCopyAttribute"/>
<addaction name="separator"/>
<addaction name="menuEntryTotp"/>
<addaction name="actionEntryOpenUrl"/>
<addaction name="separator"/>
<addaction name="actionEntryAutoType"/>
<addaction name="separator"/>
<addaction name="actionEntryOpenUrl"/>
<addaction name="actionEntryDownloadIcon"/>
</widget>
<widget class="QMenu" name="menuGroups">
Expand Down
Loading