Пример #1
0
 def redo(self):
     if len(self.__redo) == 0:
         return
     files = self.__redo.pop()
     undo = []
     for file_path in files:
         new_path = file_path.rsplit('.', 1)[0]
         undo_path = util.getUniqueUndoFile(new_path)
         f_file_path = codecs.open(new_path, 'r', 'utf-8')
         f_new_path = codecs.open(new_path, 'rw', 'utf-8')
         f_undo_path = codecs.open(undo_path, 'rw', 'utf-8')
         data = f_new_path.read()
         f_undo_path.write(data)
         data = f_file_path.read()
         f_new_path.write(data)
         os.unlink(file_path)
         undo.append(undo_path)
         f_file_path.close()
         f_new_path.close()
         f_undo_path.close()
     #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.__undo.append(undo)
Пример #2
0
	def __loadMenus(self):
		self.applications = Menu()
		self.applications.tree = matemenu.lookup_tree('mate-applications.menu', matemenu.FLAGS_SHOW_EMPTY|matemenu.FLAGS_INCLUDE_EXCLUDED|matemenu.FLAGS_INCLUDE_NODISPLAY|matemenu.FLAGS_SHOW_ALL_SEPARATORS)
		self.applications.visible_tree = matemenu.lookup_tree('mate-applications.menu')
		self.applications.tree.sort_key = matemenu.SORT_DISPLAY_NAME
		self.applications.visible_tree.sort_key = matemenu.SORT_DISPLAY_NAME
		self.applications.path = os.path.join(util.getUserMenuPath(), self.applications.tree.get_menu_file())
		try:
			self.applications.dom = xml.dom.minidom.parse(self.applications.path)
		except (IOError, xml.parsers.expat.ExpatError):
			self.applications.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.applications.tree))
		util.removeWhitespaceNodes(self.applications.dom)

		self.settings = Menu()
		self.settings.tree = matemenu.lookup_tree('mate-settings.menu', matemenu.FLAGS_SHOW_EMPTY|matemenu.FLAGS_INCLUDE_EXCLUDED|matemenu.FLAGS_INCLUDE_NODISPLAY|matemenu.FLAGS_SHOW_ALL_SEPARATORS)
		self.settings.visible_tree = matemenu.lookup_tree('mate-settings.menu')
		self.settings.tree.sort_key = matemenu.SORT_DISPLAY_NAME
		self.settings.visible_tree.sort_key = matemenu.SORT_DISPLAY_NAME
		self.settings.path = os.path.join(util.getUserMenuPath(), self.settings.tree.get_menu_file())
		try:
			self.settings.dom = xml.dom.minidom.parse(self.settings.path)
		except (IOError, xml.parsers.expat.ExpatError):
			self.settings.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.settings.tree))
		util.removeWhitespaceNodes(self.settings.dom)

		self.save(True)
Пример #3
0
    def __loadMenus(self):
        self.applications.path = os.path.join(util.getUserMenuPath(), self.applications.tree.props.menu_basename)
        try:
            self.applications.dom = xml.dom.minidom.parse(self.applications.path)
        except (IOError, xml.parsers.expat.ExpatError):
            self.applications.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.applications.tree))
        util.removeWhitespaceNodes(self.applications.dom)

        self.settings.path = os.path.join(util.getUserMenuPath(), self.settings.tree.props.menu_basename)
        try:
            self.settings.dom = xml.dom.minidom.parse(self.settings.path)
        except (IOError, xml.parsers.expat.ExpatError):
            self.settings.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.settings.tree))
        util.removeWhitespaceNodes(self.settings.dom)
        self.save(True)
Пример #4
0
    def __loadMenus(self):
        self.applications.path = os.path.join(util.getUserMenuPath(), self.applications.tree.props.menu_basename)
        try:
            self.applications.dom = xml.dom.minidom.parse(self.applications.path)
        except (IOError, xml.parsers.expat.ExpatError):
            self.applications.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.applications.tree))
        util.removeWhitespaceNodes(self.applications.dom)

        self.settings.path = os.path.join(util.getUserMenuPath(), self.settings.tree.props.menu_basename)
        try:
            self.settings.dom = xml.dom.minidom.parse(self.settings.path)
        except (IOError, xml.parsers.expat.ExpatError):
            self.settings.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.settings.tree))
        util.removeWhitespaceNodes(self.settings.dom)
        self.save(True)
Пример #5
0
 def revert(self):
     for name in ('applications', 'settings'):
         menu = getattr(self, name)
         self.revertTree(menu.tree.get_root_directory())
         path = os.path.join(util.getUserMenuPath(), menu.tree.props.menu_basename)
         try:
             os.unlink(path)
         except OSError:
             pass
         #reload DOM for each menu
         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)
     #reset undo/redo, no way to recover from this
     self.__undo, self.__redo = [], []
     self.save()
Пример #6
0
 def revert(self):
     for name in ('applications', 'settings'):
         menu = getattr(self, name)
         self.revertTree(menu.tree.get_root_directory())
         path = os.path.join(util.getUserMenuPath(), menu.tree.props.menu_basename)
         try:
             os.unlink(path)
         except OSError:
             pass
         #reload DOM for each menu
         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)
     #reset undo/redo, no way to recover from this
     self.__undo, self.__redo = [], []
     self.update_undo_redo_button_state()
     self.save()
Пример #7
0
    def redo(self):
        if len(self.__redo) == 0:
            return
        files = self.__redo.pop()
        undo = []
        for redo_path in files[::-1]:
            new_path = redo_path.rsplit('.', 1)[0]
            if not os.path.exists(redo_path):
                continue
            undo_path = util.getUniqueUndoFile(new_path)

            # create undo file
            try:
                with codecs.open(new_path, 'r', 'utf-8') as f_new:
                    with codecs.open(undo_path, 'w', 'utf-8') as f_undo:
                        f_undo.write(f_new.read())
                undo.append(undo_path)
            except FileNotFoundError:
                pass

            # restore redo file
            try:
                with codecs.open(redo_path, 'r', 'utf-8') as f_redo:
                    with codecs.open(new_path, 'w', 'utf-8') as f_new:
                        f_new.write(f_redo.read())
                os.unlink(redo_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 undo:
            self.__undo.append(undo)
        self.update_undo_redo_button_state()