Commit 8fe370d7 authored by Philipp Hörist's avatar Philipp Hörist

Merge branch 'regex-filter-improved-rule-swap-mech' into 'master'

[regex_filter] Improve the rule swap mechanism

See merge request !34
parents 00b40e62 2c985341
[info]
name: Regex Filter
short_name: regex_filter
version: 0.2.6
version: 0.2.7
description: Filter incoming messages using regex.
authors: Yann Leboulanger <asterix@lagaule.org>
homepage: https://dev.gajim.org/gajim/gajim-plugins/wikis/RegexFilterPlugin
......
......@@ -88,11 +88,20 @@ class RegexFilterPlugin(GajimPlugin):
return False
@log_calls('RegexFilterPlugin')
def swap_rules(self, oldNum, newNum):
if newNum >= 0 and newNum < len(self.get_rules().items()):
temp = self.config[str(newNum)]
self.config[str(newNum)] = self.config[str(oldNum)]
self.config[str(oldNum)] = temp
def swap_rules(self, old_num, down):
new_num = old_num
rules_num = self.rules.keys()
rules_num.sort()
if down:
rules_num = reversed(rules_num)
for num in rules_num:
if num == old_num:
break
new_num = num
if new_num != old_num:
temp = self.config[str(new_num)]
self.config[str(new_num)] = self.config[str(old_num)]
self.config[str(old_num)] = temp
self.create_rules()
return True
return False
......
......@@ -115,14 +115,13 @@ class RegexFilterPluginConfigDialog(GajimPluginConfigDialog):
for rule in rules:
it = model.get_iter(rule)
ruleNum = model.get(it, 0)
self.plugin.swap_rules("%d" % ruleNum, int("%d" % ruleNum) - 1)
ruleNum, _ = model.get(it, 0, 1)
self.plugin.swap_rules(ruleNum, False)
def move_down_button_clicked_cb(self, button, *args):
model, rules = self.rules_view.get_selection().get_selected_rows()
for rule in rules:
it = model.get_iter(rule)
ruleNum = model.get(it, 0)
self.plugin.swap_rules("%d" % ruleNum, int("%d" % ruleNum) + 1)
ruleNum, _ = model.get(it, 0, 1)
self.plugin.swap_rules(ruleNum, True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment