mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Tag Mapper: Allow specifying a space as the split character when creating a split tags rule
This commit is contained in:
parent
b0318eed7a
commit
d9f30ffb89
@ -161,6 +161,7 @@ def find_tests():
|
|||||||
run(rule('split', '/', '/', 'has'), '/,d', 'd')
|
run(rule('split', '/', '/', 'has'), '/,d', 'd')
|
||||||
run(rule('split', '/', '/', 'has'), '/a/', 'a')
|
run(rule('split', '/', '/', 'has'), '/a/', 'a')
|
||||||
run(rule('split', 'a,b', '/'), 'a,b', 'a,b')
|
run(rule('split', 'a,b', '/'), 'a,b', 'a,b')
|
||||||
|
run(rule('split', 'a b', ' ', 'has'), 'a b', 'a,b')
|
||||||
return unittest.defaultTestLoader.loadTestsFromTestCase(TestTagMapper)
|
return unittest.defaultTestLoader.loadTestsFromTestCase(TestTagMapper)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -24,6 +24,12 @@ from calibre.utils.localization import localize_user_manual_link
|
|||||||
|
|
||||||
tag_maps = JSONConfig('tag-map-rules')
|
tag_maps = JSONConfig('tag-map-rules')
|
||||||
|
|
||||||
|
def intelligent_strip(action, val):
|
||||||
|
ans = val.strip()
|
||||||
|
if not ans and action == 'split':
|
||||||
|
ans = ' '
|
||||||
|
return ans
|
||||||
|
|
||||||
class QueryEdit(QLineEdit):
|
class QueryEdit(QLineEdit):
|
||||||
|
|
||||||
def contextMenuEvent(self, ev):
|
def contextMenuEvent(self, ev):
|
||||||
@ -151,11 +157,12 @@ class RuleEdit(QWidget):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def rule(self):
|
def rule(self):
|
||||||
|
ac = self.action.currentData()
|
||||||
return {
|
return {
|
||||||
'action': self.action.currentData(),
|
'action': ac,
|
||||||
'match_type': self.match_type.currentData(),
|
'match_type': self.match_type.currentData(),
|
||||||
'query': self.query.text().strip(),
|
'query': intelligent_strip(ac, self.query.text()),
|
||||||
'replace': self.replace.text().strip(),
|
'replace': intelligent_strip(ac, self.replace.text()),
|
||||||
}
|
}
|
||||||
|
|
||||||
@rule.setter
|
@rule.setter
|
||||||
@ -167,8 +174,9 @@ class RuleEdit(QWidget):
|
|||||||
idx = 0
|
idx = 0
|
||||||
c.setCurrentIndex(idx)
|
c.setCurrentIndex(idx)
|
||||||
sc('action'), sc('match_type')
|
sc('action'), sc('match_type')
|
||||||
self.query.setText(unicode(rule.get('query', '')).strip())
|
ac = self.action.currentData()
|
||||||
self.replace.setText(unicode(rule.get('replace', '')).strip())
|
self.query.setText(intelligent_strip(ac, unicode(rule.get('query', ''))))
|
||||||
|
self.replace.setText(intelligent_strip(ac, unicode(rule.get('replace', ''))))
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
rule = self.rule
|
rule = self.rule
|
||||||
|
Loading…
x
Reference in New Issue
Block a user