diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 86aa309d1..8b9051f01 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -92,6 +92,7 @@ DatabaseWidget::DatabaseWidget(Database* db, QWidget* parent) addWidget(m_databaseSettingsWidget); connect(m_groupView, SIGNAL(groupChanged(Group*)), m_entryView, SLOT(setGroup(Group*))); + connect(m_groupView, SIGNAL(groupChanged(Group*)), this, SLOT(clearLastGroup(Group*))); connect(m_entryView, SIGNAL(entryActivated(Entry*)), SLOT(switchToEntryEdit(Entry*))); connect(m_editEntryWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool))); connect(m_editGroupWidget, SIGNAL(editFinished(bool)), SLOT(switchToView(bool))); @@ -256,8 +257,14 @@ void DatabaseWidget::switchToEntryEdit(Entry* entry) void DatabaseWidget::switchToEntryEdit(Entry* entry, bool create) { - m_editEntryWidget->loadEntry(entry, create, m_groupView->currentGroup()->name(), - m_db); + Group* group = m_groupView->currentGroup(); + if (!group) { + Q_ASSERT(m_entryView->inSearch()); + group = m_lastGroup; + } + Q_ASSERT(group); + + m_editEntryWidget->loadEntry(entry, create, group->name(), m_db); setCurrentIndex(1); } @@ -332,6 +339,11 @@ void DatabaseWidget::search() Group* searchGroup = m_db->rootGroup(); QList searchResult = searchGroup->search(m_searchEdit->text(), Qt::CaseInsensitive); + Group* group = m_groupView->currentGroup(); + if (group) { + m_lastGroup = m_groupView->currentGroup(); + } + m_groupView->setCurrentIndex(QModelIndex()); m_entryView->search(searchResult); } @@ -355,3 +367,10 @@ void DatabaseWidget::truncateHistories() entry->truncateHistory(); } } + +void DatabaseWidget::clearLastGroup(Group* group) +{ + if (group) { + m_lastGroup = 0; + } +} diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index e81b689c5..669014258 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -77,6 +77,7 @@ private Q_SLOTS: void updateMasterKey(bool accepted); void updateSettings(bool accepted); void emitCurrentModeChanged(); + void clearLastGroup(Group* group); private: void truncateHistories(); @@ -93,6 +94,7 @@ private: Entry* m_newEntry; Group* m_newParent; QLineEdit* m_searchEdit; + Group* m_lastGroup; }; #endif // KEEPASSX_DATABASEWIDGET_H