Edit book: Allow disabling the completion popups for the search and replace fields. Right click on the search/replace field to enable/disable the completion popup

This commit is contained in:
Kovid Goyal 2014-03-12 09:59:42 +05:30
parent 0e3362fd4b
commit 13b47f4a29
3 changed files with 30 additions and 2 deletions

View File

@ -76,6 +76,7 @@ class Completer(QListView): # {{{
def __init__(self, completer_widget, max_visible_items=7):
QListView.__init__(self)
self.disable_popup = False
self.completer_widget = weakref.ref(completer_widget)
self.setWindowFlags(Qt.Popup)
self.max_visible_items = max_visible_items
@ -132,6 +133,8 @@ class Completer(QListView): # {{{
self.setCurrentIndex(index)
def popup(self, select_first=True):
if self.disable_popup:
return
p = self
m = p.model()
widget = self.completer_widget()
@ -293,6 +296,13 @@ class LineEdit(QLineEdit, LineEditECM):
self.mcompleter.model().set_items(items)
return property(fget=fget, fset=fset)
@dynamic_property
def disable_popup(self):
def fget(self):
return self.mcompleter.disable_popup
def fset(self, val):
self.mcompleter.disable_popup = bool(val)
return property(fget=fget, fset=fset)
# }}}
def complete(self, show_all=False, select_first=True):

View File

@ -40,6 +40,7 @@ d['remove_existing_links_when_linking_sheets'] = True
d['charmap_favorites'] = list(map(ord, '\xa0\u2002\u2003\u2009\xad' '‘’“”‹›«»‚„' '—–§¶†‡©®™' '→⇒•·°±−×÷¼½½¾' '…µ¢£€¿¡¨´¸ˆ˜' 'ÀÁÂÃÄÅÆÇÈÉÊË' 'ÌÍÎÏÐÑÒÓÔÕÖØ' 'ŒŠÙÚÛÜÝŸÞßàá' 'âãäåæçèéêëìí' 'îïðñòóôõöøœš' 'ùúûüýÿþªºαΩ∞')) # noqa
d['folders_for_types'] = {'style':'styles', 'image':'images', 'font':'fonts', 'audio':'audio', 'video':'video'}
d['pretty_print_on_open'] = False
d['disable_completion_popup_for_search'] = False
del d

View File

@ -25,6 +25,23 @@ class PushButton(QPushButton):
QPushButton.__init__(self, text, parent)
self.clicked.connect(lambda : parent.search_triggered.emit(action))
class HistoryLineEdit(HistoryLineEdit2):
def __init__(self, parent):
HistoryLineEdit2.__init__(self, parent)
self.disable_popup = tprefs['disable_completion_popup_for_search']
def contextMenuEvent(self, event):
menu = self.createStandardContextMenu()
menu.addSeparator()
menu.addAction((_('Show completion based on search history') if self.disable_popup else _(
'Hide completion based on search history')), self.toggle_popups)
menu.exec_(event.globalPos())
def toggle_popups(self):
self.disable_popup = not bool(self.disable_popup)
tprefs['disable_completion_popup_for_search'] = self.disable_popup
class SearchWidget(QWidget):
DEFAULT_STATE = {
@ -46,7 +63,7 @@ class SearchWidget(QWidget):
self.fl = fl = QLabel(_('&Find:'))
fl.setAlignment(Qt.AlignRight | Qt.AlignCenter)
self.find_text = ft = HistoryLineEdit2(self)
self.find_text = ft = HistoryLineEdit(self)
ft.initialize('tweak_book_find_edit')
ft.returnPressed.connect(lambda : self.search_triggered.emit('find'))
fl.setBuddy(ft)
@ -55,7 +72,7 @@ class SearchWidget(QWidget):
self.rl = rl = QLabel(_('&Replace:'))
rl.setAlignment(Qt.AlignRight | Qt.AlignCenter)
self.replace_text = rt = HistoryLineEdit2(self)
self.replace_text = rt = HistoryLineEdit(self)
rt.initialize('tweak_book_replace_edit')
rl.setBuddy(rt)
l.addWidget(rl, 1, 0)