def __init__(self):
self.shortcut_entry = re.compile(r'^\s*"([^"]+)"\s*\"([^"]+)\"')
self.bindings = {}
- self.bind = re.compile(r'^\s*\\bind\s+"([^"]+)"')
+ self.unbindings = {}
+ self.bind = re.compile(r'^\s*\\(un)?bind\s+"([^"]+)"')
if lyx_userdir_ver is None:
self.dir = lyx_userdir
else:
else:
die(1, "cad shortcut spec(" + c + ")")
+ def __UnuseShortcut(self, c):
+ m = self.shortcut_entry.match(c)
+ if m:
+ sh = m.group(1)
+ fkt = m.group(2)
+ self.unbindings[sh] = fkt
+ else:
+ die(1, "cad shortcut spec(" + c + ")")
+
def __PrepareShortcuts(self):
if not self.dir is None:
tmp = tempfile.NamedTemporaryFile(suffix='.bind', delete=False)
m = self.bind.match(line)
if m:
bindfound = True
- val = m.group(1)
+ val = m.group(2)
if val in self.bindings:
if self.bindings[val] != "":
tmp.write("\\bind \"" + val + "\" \"" + self.bindings[val] + "\"\n")
self.bindings[val] = ""
+ elif val in self.unbindings:
+ if self.unbindings[val] != "":
+ tmp.write("\\unbind \"" + val + "\" \"" + self.unbindings[val] + "\"\n")
+ self.unbindings[val] = ""
else:
tmp.write(line + '\n')
elif not bindfound:
)
for val in self.bindings:
if not self.bindings[val] is None:
- if self.bindings[val] != "":
+ if self.bindings[val] != "":
tmp.write("\\bind \"" + val + "\" \"" + self.bindings[val] + "\"\n")
self.bindings[val] = ""
+ for val in self.unbindings:
+ if not self.unbindings[val] is None:
+ if self.unbindings[val] != "":
+ tmp.write("\\unbind \"" + val + "\" \"" + self.unbindings[val] + "\"\n")
+ self.unbindings[val] = ""
tmp.close()
shutil.move(tmp.name, self.dir + '/bind/user.bind')
else:
def dispatch(self, c):
if c[0:12] == 'UseShortcut ':
self.__UseShortcut(c[12:])
+ elif c[0:14] == 'UnuseShortcut ':
+ self.__UnuseShortcut(c[14:])
elif c == 'PrepareShortcuts':
print('Preparing usefull sortcuts for tests')
self.__PrepareShortcuts()