Prevent crashes when no item is selected and a keyboard shortcut is used

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@148 b624d157-de02-0410-bad0-e51aec6abb33
master
highjinx 17 years ago
parent 961268a67d
commit 5a210a8e30
  1. 21
      src/lib/EntryView.cpp
  2. 4
      src/mainwindow.cpp

@ -131,7 +131,7 @@ void KeepassEntryView::OnHeaderSectionClicked(int index){
}
void KeepassEntryView::OnSaveAttachment(){
Q_ASSERT(selectedItems().size()==1);
if (selectedItems().size() == 0) return;
CEditEntryDlg::saveAttachment(((EntryViewItem*)selectedItems().first())->EntryHandle,this);
}
@ -228,7 +228,16 @@ void KeepassEntryView::editEntry(EntryViewItem* item){
void KeepassEntryView::OnNewEntry(){
IEntryHandle* NewEntry=db->newEntry(CurrentGroup);
IEntryHandle* NewEntry = NULL;
if (!CurrentGroup){// We must be viewing search results. Add the new entry to the first group.
if (db->groups().size() > 0)
NewEntry=db->newEntry(db->sortedGroups()[0]);
else{
QMessageBox::critical(NULL,tr("Error"),tr("At least one group must exist before adding an entry."),tr("OK"));
}
}
else
NewEntry=db->newEntry(CurrentGroup);
CEditEntryDlg dlg(db,NewEntry,this,true);
if(!dlg.exec()){
db->deleteLastEntry();
@ -257,16 +266,17 @@ void KeepassEntryView::OnEntryActivated(QTreeWidgetItem* item,int Column){
}
void KeepassEntryView::OnEditEntry(){
Q_ASSERT(selectedItems().size()==1);
if (selectedItems().size() == 0) return;
editEntry((EntryViewItem*)selectedItems().first());
}
void KeepassEntryView::OnEditOpenUrl(){
Q_ASSERT(selectedItems().size()==1);
if (selectedItems().size() == 0) return;
openBrowser(((EntryViewItem*)selectedItems().first())->text(logicalColIndex(2)));
}
void KeepassEntryView::OnUsernameToClipboard(){
if (selectedItems().size() == 0) return;
Clipboard->setText(((EntryViewItem*)selectedItems().first())->EntryHandle->username(), QClipboard::Clipboard);
if(Clipboard->supportsSelection()){
Clipboard->setText(((EntryViewItem*)selectedItems().first())->EntryHandle->username(),QClipboard::Selection);
@ -276,6 +286,7 @@ void KeepassEntryView::OnUsernameToClipboard(){
}
void KeepassEntryView::OnPasswordToClipboard(){
if (selectedItems().size() == 0) return;
SecString password;
password=((EntryViewItem*)selectedItems().first())->EntryHandle->password();
password.unlock();
@ -581,7 +592,7 @@ void KeepassEntryView::removeDragItems(){
}
void KeepassEntryView::OnAutoType(){
Q_ASSERT(selectedItems().size()==1);
if (selectedItems().size() == 0) return;
QString error;
AutoType::perform(((EntryViewItem*)selectedItems().first())->EntryHandle,error);
}

@ -652,7 +652,7 @@ switch(EntrySelection){
EditPasswordToClipboardAction->setEnabled(true);
EditUsernameToClipboardAction->setEnabled(true);
EditOpenUrlAction->setEnabled(true);
EditSaveAttachmentAction->setEnabled(true);
EditSaveAttachmentAction->setEnabled(((EntryViewItem*)(EntryView->selectedItems()[0]))->EntryHandle->binarySize() > 0);
EditEditEntryAction->setEnabled(true);
EditCloneEntryAction->setEnabled(true);
EditCloneEntryAction->setText(tr("Clone Entry"));
@ -692,7 +692,7 @@ switch(EntrySelection){
EditUsernameToClipboardAction->setEnabled(true);
EditPasswordToClipboardAction->setEnabled(true);
EditOpenUrlAction->setEnabled(true);
EditSaveAttachmentAction->setEnabled(true);
EditSaveAttachmentAction->setEnabled(((EntryViewItem*)(EntryView->selectedItems()[0]))->EntryHandle->binarySize() > 0);
EditEditEntryAction->setEnabled(true);
EditCloneEntryAction->setEnabled(false);
EditCloneEntryAction->setText(tr("Clone Entry"));