def undo(self): if len(self.__undo) == 0: return files = self.__undo.pop() redo = [] for file_path in files: new_path = file_path.rsplit('.', 1)[0] redo_path = util.getUniqueRedoFile(new_path) f_file_path = codecs.open(new_path, 'r', 'utf-8') f_new_path = codecs.open(new_path, 'rw', 'utf-8') f_redo_path = codecs.open(redo_path, 'rw', 'utf-8') data = f_new_path.read() f_redo_path.write(data) data = f_file_path.read() f_new_path.write(data) f_file_path.close() f_new_path.close() f_redo_path.close() os.unlink(file_path) redo.append(redo_path) # reload DOM to make changes stick for name in ('applications', 'settings'): menu = getattr(self, name) try: menu.dom = xml.dom.minidom.parse(menu.path) except (IOError, xml.parsers.expat.ExpatError): menu.dom = xml.dom.minidom.parseString(util.getUserMenuXml(menu.tree)) util.removeWhitespaceNodes(menu.dom) self.__redo.append(redo)
def undo(self): if len(self.__undo) == 0: return files = self.__undo.pop() redo = [] for undo_path in files[::-1]: new_path = undo_path.rsplit('.', 1)[0] if not os.path.exists(undo_path): continue redo_path = util.getUniqueRedoFile(new_path) # create redo file try: with codecs.open(new_path, 'r', 'utf-8') as f_new: with codecs.open(redo_path, 'w', 'utf-8') as f_redo: f_redo.write(f_new.read()) redo.append(redo_path) except FileNotFoundError: pass # restore undo file try: with codecs.open(undo_path, 'r', 'utf-8') as f_undo: with codecs.open(new_path, 'w', 'utf-8') as f_new: f_new.write(f_undo.read()) os.unlink(undo_path) except FileNotFoundError: pass # reload DOM to make changes stick for name in ('applications', 'settings'): menu = getattr(self, name) try: menu.dom = xml.dom.minidom.parse(menu.path) except (IOError, xml.parsers.expat.ExpatError): menu.dom = xml.dom.minidom.parseString(util.getUserMenuXml(menu.tree)) util.removeWhitespaceNodes(menu.dom) if redo: self.__redo.append(redo) self.update_undo_redo_button_state()
def undo(self): if len(self.__undo) == 0: return files = self.__undo.pop() redo = [] for file_path in files: new_path = file_path.rsplit('.', 1)[0] redo_path = util.getUniqueRedoFile(new_path) data = open(new_path).read() open(redo_path, 'w').write(data) data = open(file_path).read() open(new_path, 'w').write(data) os.unlink(file_path) redo.append(redo_path) #reload DOM to make changes stick for name in ('applications', 'settings'): menu = getattr(self, name) if not os.path.isfile(menu.path): menu.dom = xml.dom.minidom.parseString(util.getUserMenuXml(menu.tree)) else: menu.dom = xml.dom.minidom.parse(menu.path) self.__remove_whilespace_nodes(menu.dom) self.__redo.append(redo)
def undo(self): if len(self.__undo) == 0: return files = self.__undo.pop() redo = [] for file_path in files: new_path = file_path.rsplit('.', 1)[0] redo_path = util.getUniqueRedoFile(new_path) data = open(new_path).read() open(redo_path, 'w').write(data) data = open(file_path).read() open(new_path, 'w').write(data) os.unlink(file_path) redo.append(redo_path) #reload DOM to make changes stick for name in ('applications', 'settings'): menu = getattr(self, name) if not os.path.isfile(menu.path): menu.dom = xml.dom.minidom.parseString( util.getUserMenuXml(menu.tree)) else: menu.dom = xml.dom.minidom.parse(menu.path) self.__remove_whilespace_nodes(menu.dom) self.__redo.append(redo)