mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
GUI add regex: Store history in gprefs instead of in filename_pattern.
This commit is contained in:
parent
94fb463ab2
commit
156dc57e99
@ -142,13 +142,7 @@ def metadata_from_filename(name, pat=None):
|
||||
name = name.rpartition('.')[0]
|
||||
mi = MetaInformation(None, None)
|
||||
if pat is None:
|
||||
pat_re = prefs.get('filename_pattern')
|
||||
if isinstance(pat_re, list):
|
||||
if pat_re:
|
||||
pat_re = pat_re[0]
|
||||
else:
|
||||
pat_re = ''
|
||||
pat = re.compile(pat_re)
|
||||
pat = re.compile(prefs.get('filename_pattern'))
|
||||
name = name.replace('_', ' ')
|
||||
match = pat.search(name)
|
||||
if match is not None:
|
||||
|
@ -71,17 +71,27 @@ class FilenamePattern(QWidget, Ui_Form):
|
||||
self.re.lineEdit().textChanged.connect(lambda x: self.changed_signal.emit())
|
||||
|
||||
def initialize(self, defaults=False):
|
||||
# Get all itmes in the combobox. If we are resting
|
||||
# to defaults we don't want to lose what the user
|
||||
# has added.
|
||||
val_hist = [unicode(self.re.lineEdit().text())] + [unicode(self.re.itemText(i)) for i in xrange(self.re.count())]
|
||||
self.re.clear()
|
||||
|
||||
if defaults:
|
||||
val = prefs.defaults['filename_pattern']
|
||||
else:
|
||||
val = prefs['filename_pattern']
|
||||
if isinstance(val, list):
|
||||
if len(val) > 0:
|
||||
for v in val:
|
||||
self.re.lineEdit().setText(val)
|
||||
|
||||
val_hist += gprefs.get('filename_pattern_history', ['(?P<title>.+)', '(?P<author>[^_-]+) -?\s*(?P<series>[^_0-9-]*)(?P<series_index>[0-9]*)\s*-\s*(?P<title>[^_].+) ?'])
|
||||
if val in val_hist:
|
||||
del val_hist[val_hist.index(val)]
|
||||
val_hist.insert(0, val)
|
||||
for v in val_hist:
|
||||
# Ensure we don't have duplicate items.
|
||||
if v and self.re.findText(v) == -1:
|
||||
self.re.addItem(v)
|
||||
self.re.setCurrentIndex(0)
|
||||
else:
|
||||
self.re.lineEdit().setText(val if val else '')
|
||||
|
||||
def do_test(self):
|
||||
try:
|
||||
@ -118,12 +128,17 @@ class FilenamePattern(QWidget, Ui_Form):
|
||||
return re.compile(pat)
|
||||
|
||||
def commit(self):
|
||||
pat = []
|
||||
patterns = [unicode(self.re.lineEdit().text())] + [unicode(self.re.itemText(i)) for i in xrange(self.re.count())]
|
||||
for p in patterns[:14]:
|
||||
if p not in pat:
|
||||
pat.append(p)
|
||||
pat = self.pattern().pattern
|
||||
prefs['filename_pattern'] = pat
|
||||
|
||||
history = []
|
||||
history_pats = [unicode(self.re.lineEdit().text())] + [unicode(self.re.itemText(i)) for i in xrange(self.re.count())]
|
||||
for p in history_pats[:14]:
|
||||
# Ensure we don't have duplicate items.
|
||||
if p and p not in history:
|
||||
history.append(p)
|
||||
gprefs['filename_pattern_history'] = history
|
||||
|
||||
return pat
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user