Fix pressing Enter in the search box causes the same search to be executed twice in the plugins and keyboard shortcuts preferences panels

This commit is contained in:
Kovid Goyal 2011-08-13 20:56:08 -06:00
parent c3d46f1460
commit dcc5ae6137
2 changed files with 15 additions and 5 deletions

View File

@ -20,7 +20,7 @@ from calibre.constants import DEBUG
from calibre import prints
from calibre.utils.icu import sort_key, lower
from calibre.gui2 import NONE, error_dialog, info_dialog
from calibre.utils.search_query_parser import SearchQueryParser
from calibre.utils.search_query_parser import SearchQueryParser, ParseException
from calibre.gui2.search_box import SearchBox2
ROOT = QModelIndex()
@ -590,11 +590,19 @@ class ShortcutConfig(QWidget): # {{{
return self.view.state() == self.view.EditingState
def find(self, query):
idx = self._model.find(query)
if not query:
return
try:
idx = self._model.find(query)
except ParseException:
self.search.search_done(False)
return
self.search.search_done(True)
if not idx.isValid():
return info_dialog(self, _('No matches'),
_('Could not find any matching shortcuts'), show=True,
show_copy_button=False)
info_dialog(self, _('No matches'),
_('Could not find any shortcuts matching %s')%query,
show=True, show_copy_button=False)
return
self.highlight_index(idx)
def highlight_index(self, idx):

View File

@ -163,6 +163,8 @@ class SearchBox2(QComboBox): # {{{
# Comes from the combobox itself
def keyPressEvent(self, event):
k = event.key()
if k in (Qt.Key_Enter, Qt.Key_Return):
return self.do_search()
if k not in (Qt.Key_Up, Qt.Key_Down):
QComboBox.keyPressEvent(self, event)
else: