Esempio n. 1
0
 def __addUndo(self, items):
     self.__undo.append([])
     for item in items:
         if isinstance(item, Menu):
             file_path = item.path
         elif isinstance(item, tuple):
             if item[0] == 'Item':
                 file_path = os.path.join(util.getUserItemPath(), item[1])
                 if not os.path.isfile(file_path):
                     file_path = util.getItemPath(item[1])
             elif item[0] == 'Menu':
                 file_path = os.path.join(util.getUserDirectoryPath(), item[1])
                 if not os.path.isfile(file_path):
                     file_path = util.getDirectoryPath(item[1])
             else:
                 continue
         elif isinstance(item, MateMenu.TreeDirectory):
             if item.get_desktop_file_path() is None:
                 continue
             file_path = os.path.join(util.getUserDirectoryPath(), os.path.split(item.get_desktop_file_path())[1])
             if not os.path.isfile(file_path):
                 file_path = item.get_desktop_file_path()
         elif isinstance(item, MateMenu.TreeEntry):
             file_path = os.path.join(util.getUserItemPath(), item.get_desktop_file_id())
             if not os.path.isfile(file_path):
                 file_path = item.get_desktop_file_path()
         else:
             continue
         with codecs.open(file_path, 'r', 'utf-8') as f:
             data = f.read()
         undo_path = util.getUniqueUndoFile(file_path)
         with codecs.open(undo_path, 'w', 'utf-8') as f:
             f.write(data)
         self.__undo[-1].append(undo_path)
     self.update_undo_redo_button_state()
Esempio n. 2
0
	def __addUndo(self, items):
		self.__undo.append([])
		for item in items:
			if isinstance(item, Menu):
				file_path = item.path
			elif isinstance(item, tuple):
				if item[0] == 'Item':
					file_path = os.path.join(util.getUserItemPath(), item[1])
					if not os.path.isfile(file_path):
						file_path = util.getItemPath(item[1])
				elif item[0] == 'Menu':
					file_path = os.path.join(util.getUserDirectoryPath(), item[1])
					if not os.path.isfile(file_path):
						file_path = util.getDirectoryPath(item[1])
				else:
					continue
			elif item.get_type() == matemenu.TYPE_DIRECTORY:
				if item.get_desktop_file_path() == None:
					continue
				file_path = os.path.join(util.getUserDirectoryPath(), os.path.split(item.get_desktop_file_path())[1])
				if not os.path.isfile(file_path):
					file_path = item.get_desktop_file_path()
			elif item.get_type() == matemenu.TYPE_ENTRY:
				file_path = os.path.join(util.getUserItemPath(), item.get_desktop_file_id())
				if not os.path.isfile(file_path):
					file_path = item.get_desktop_file_path()
			else:
				continue
			data = open(file_path).read()
			undo_path = util.getUniqueUndoFile(file_path)
			open(undo_path, 'w').write(data)
			self.__undo[-1].append(undo_path)
Esempio n. 3
0
 def __addUndo(self, items):
     self.__undo.append([])
     for item in items:
         if isinstance(item, Menu):
             file_path = item.path
         elif isinstance(item, tuple):
             if item[0] == 'Item':
                 file_path = os.path.join(util.getUserItemPath(), item[1])
                 if not os.path.isfile(file_path):
                     file_path = util.getItemPath(item[1])
             elif item[0] == 'Menu':
                 file_path = os.path.join(util.getUserDirectoryPath(), item[1])
                 if not os.path.isfile(file_path):
                     file_path = util.getDirectoryPath(item[1])
             else:
                 continue
         elif isinstance(item, MateMenu.TreeDirectory):
             if item.get_desktop_file_path() is None:
                 continue
             file_path = os.path.join(util.getUserDirectoryPath(), os.path.split(item.get_desktop_file_path())[1])
             if not os.path.isfile(file_path):
                 file_path = item.get_desktop_file_path()
         elif isinstance(item, MateMenu.TreeEntry):
             file_path = os.path.join(util.getUserItemPath(), item.get_desktop_file_id())
             if not os.path.isfile(file_path):
                 file_path = item.get_desktop_file_path()
         else:
             continue
         with codecs.open(file_path, 'r', 'utf-8') as f:
             data = f.read()
         undo_path = util.getUniqueUndoFile(file_path)
         with codecs.open(undo_path, 'w', 'utf-8') as f:
             f.write(data)
         self.__undo[-1].append(undo_path)
Esempio n. 4
0
 def quit(self):
     for file_name in os.listdir(util.getUserItemPath()):
         if file_name[-6:-2] in ('redo', 'undo'):
             file_path = os.path.join(util.getUserItemPath(), file_name)
             os.unlink(file_path)
     for file_name in os.listdir(util.getUserDirectoryPath()):
         if file_name[-6:-2] in ('redo', 'undo'):
             file_path = os.path.join(util.getUserDirectoryPath(), file_name)
             os.unlink(file_path)
     for file_name in os.listdir(util.getUserMenuPath()):
         if file_name[-6:-2] in ('redo', 'undo'):
             file_path = os.path.join(util.getUserMenuPath(), file_name)
             os.unlink(file_path)
Esempio n. 5
0
 def quit(self):
     for file_name in os.listdir(util.getUserItemPath()):
         if file_name[-6:-2] in ('redo', 'undo'):
             file_path = os.path.join(util.getUserItemPath(), file_name)
             os.unlink(file_path)
     for file_name in os.listdir(util.getUserDirectoryPath()):
         if file_name[-6:-2] in ('redo', 'undo'):
             file_path = os.path.join(util.getUserDirectoryPath(), file_name)
             os.unlink(file_path)
     for file_name in os.listdir(util.getUserMenuPath()):
         if file_name[-6:-2] in ('redo', 'undo'):
             file_path = os.path.join(util.getUserMenuPath(), file_name)
             os.unlink(file_path)
Esempio n. 6
0
	def setVisible(self, item, visible):
		dom = self.__getMenu(item).dom
		if item.get_type() == matemenu.TYPE_ENTRY:
			self.__addUndo([self.__getMenu(item), item])
			menu_xml = self.__getXmlMenu(self.__getPath(item.get_parent()), dom, dom)
			if visible:
				self.__addXmlFilename(menu_xml, dom, item.get_desktop_file_id(), 'Include')
				self.__writeItem(item, no_display=False)
			else:
				self.__addXmlFilename(menu_xml, dom, item.get_desktop_file_id(), 'Exclude')
			self.__addXmlTextElement(menu_xml, 'AppDir', util.getUserItemPath(), dom)
		elif item.get_type() == matemenu.TYPE_DIRECTORY:
			self.__addUndo([self.__getMenu(item), item])
			#don't mess with it if it's empty
			if len(item.get_contents()) == 0:
				return
			menu_xml = self.__getXmlMenu(self.__getPath(item), dom, dom)
			for node in self.__getXmlNodesByName(['Deleted', 'NotDeleted'], menu_xml):
				node.parentNode.removeChild(node)
			if visible:
				self.__writeMenu(item, no_display=False)
			else:
				self.__writeMenu(item, no_display=True)
			self.__addXmlTextElement(menu_xml, 'DirectoryDir', util.getUserDirectoryPath(), dom)
		self.save()
Esempio n. 7
0
	def on_edit_properties_activate(self, menu):
		item_tree = self.tree.get_object('item_tree')
		items, iter = item_tree.get_selection().get_selected()
		if not iter:
			return
		item = items[iter][3]
		if item.get_type() not in (matemenu.TYPE_ENTRY, matemenu.TYPE_DIRECTORY):
			return

		if item.get_type() == matemenu.TYPE_ENTRY:
			file_path = os.path.join(util.getUserItemPath(), item.get_desktop_file_id())
			file_type = 'Item'
		elif item.get_type() == matemenu.TYPE_DIRECTORY:
			file_path = os.path.join(util.getUserDirectoryPath(), os.path.split(item.get_desktop_file_path())[1])
			file_type = 'Menu'

		if not os.path.isfile(file_path):
			shutil.copy(item.get_desktop_file_path(), file_path)
			self.editor._MenuEditor__addUndo([(file_type, os.path.split(file_path)[1]),])
		else:
			self.editor._MenuEditor__addUndo([item,])
		if file_path not in self.edit_pool:
			self.edit_pool.append(file_path)
			process = subprocess.Popen(['mate-desktop-item-edit', file_path], env=os.environ)
			GLib.timeout_add(100, self.waitForEditProcess, process, file_path)
 def __writeMenu(self,
                 menu=None,
                 icon=None,
                 name=None,
                 comment=None,
                 no_display=None):
     if menu:
         file_id = os.path.split(menu.get_desktop_file_path())[1]
         file_path = menu.get_desktop_file_path()
         keyfile = util.DesktopParser(file_path)
     elif menu == None and name == None:
         raise Exception('New menus need a name')
     else:
         file_id = util.getUniqueFileId(name, '.directory')
         keyfile = util.DesktopParser(file_type='Directory')
     if icon:
         keyfile.set('Icon', icon)
     if name:
         keyfile.set('Name', name)
         keyfile.set('Name', name, self.locale)
     if comment:
         keyfile.set('Comment', comment)
         keyfile.set('Comment', comment, self.locale)
     if no_display != None:
         keyfile.set('NoDisplay', no_display)
     out_path = os.path.join(util.getUserDirectoryPath(), file_id)
     keyfile.write(open(out_path, 'w'))
     return file_id
 def setVisible(self, item, visible):
     dom = self.__getMenu(item).dom
     if item.get_type() == matemenu.TYPE_ENTRY:
         self.__addUndo([self.__getMenu(item), item])
         menu_xml = self.__getXmlMenu(self.__getPath(item.get_parent()),
                                      dom, dom)
         if visible:
             self.__addXmlFilename(menu_xml, dom,
                                   item.get_desktop_file_id(), 'Include')
             self.__writeItem(item, no_display=False)
         else:
             self.__addXmlFilename(menu_xml, dom,
                                   item.get_desktop_file_id(), 'Exclude')
         self.__addXmlTextElement(menu_xml, 'AppDir',
                                  util.getUserItemPath(), dom)
     elif item.get_type() == matemenu.TYPE_DIRECTORY:
         self.__addUndo([self.__getMenu(item), item])
         #don't mess with it if it's empty
         if len(item.get_contents()) == 0:
             return
         menu_xml = self.__getXmlMenu(self.__getPath(item), dom, dom)
         for node in self.__getXmlNodesByName(['Deleted', 'NotDeleted'],
                                              menu_xml):
             node.parentNode.removeChild(node)
         if visible:
             self.__writeMenu(item, no_display=False)
         else:
             self.__writeMenu(item, no_display=True)
         self.__addXmlTextElement(menu_xml, 'DirectoryDir',
                                  util.getUserDirectoryPath(), dom)
     self.save()
Esempio n. 10
0
    def on_edit_properties_activate(self, menu):
        item_tree = self.tree.get_object('item_tree')
        items, iter = item_tree.get_selection().get_selected()
        if not iter:
            return
        item = items[iter][3]
        if not isinstance(item, MateMenu.TreeEntry) and not isinstance(item, MateMenu.TreeDirectory):
            return

        if isinstance(item, MateMenu.TreeEntry):
            file_path = os.path.join(util.getUserItemPath(), item.get_desktop_file_id())
            file_type = 'Item'
        elif isinstance(item, MateMenu.TreeDirectory):
            file_path = os.path.join(util.getUserDirectoryPath(), os.path.split(item.get_desktop_file_path())[1])
            file_type = 'Menu'

        if not os.path.isfile(file_path):
            shutil.copy(item.get_desktop_file_path(), file_path)
            self.editor._MenuEditor__addUndo([(file_type, os.path.split(file_path)[1]),])
        else:
            self.editor._MenuEditor__addUndo([item,])
        if file_path not in self.edit_pool:
            self.edit_pool.append(file_path)
            process = subprocess.Popen(['mate-desktop-item-edit', file_path], env=os.environ)
            GLib.timeout_add(100, self.waitForEditProcess, process, file_path)
Esempio n. 11
0
    def on_edit_properties_activate(self, menu):
        item_tree = self.tree.get_object("item_tree")
        items, iter = item_tree.get_selection().get_selected()
        if not iter:
            return
        item = items[iter][3]
        if item.get_type() not in (matemenu.TYPE_ENTRY, matemenu.TYPE_DIRECTORY):
            return

        if item.get_type() == matemenu.TYPE_ENTRY:
            file_path = os.path.join(util.getUserItemPath(), item.get_desktop_file_id())
            file_type = "Item"
        elif item.get_type() == matemenu.TYPE_DIRECTORY:
            if item.get_desktop_file_path() == None:
                file_path = util.getUniqueFileId("mozo-made", ".directory")
                parser = util.DesktopParser(file_path, "Directory")
                parser.set("Name", item.get_name())
                parser.set("Comment", item.get_comment())
                parser.set("Icon", item.get_icon())
                parser.write(open(file_path))
            else:
                file_path = os.path.join(util.getUserDirectoryPath(), os.path.split(item.get_desktop_file_path())[1])
            file_type = "Menu"

        if not os.path.isfile(file_path):
            data = open(item.get_desktop_file_path()).read()
            open(file_path, "w").write(data)
            self.editor._MenuEditor__addUndo([(file_type, os.path.split(file_path)[1])])
        else:
            self.editor._MenuEditor__addUndo([item])
        if file_path not in self.edit_pool:
            self.edit_pool.append(file_path)
            process = subprocess.Popen(["mate-desktop-item-edit", file_path], env=os.environ)
            gobject.timeout_add(100, self.waitForEditProcess, process, file_path)
Esempio n. 12
0
 def on_new_menu_button_clicked(self, button):
     menu_tree = self.tree.get_object('menu_tree')
     menus, iter = menu_tree.get_selection().get_selected()
     if not iter:
         parent = menus[(0,)][2]
         menu_tree.expand_to_path((0,))
         menu_tree.get_selection().select_path((0,))
     else:
         parent = menus[iter][2]
     file_path = os.path.join(util.getUserDirectoryPath(), util.getUniqueFileId('mozo-made', '.directory'))
     process = subprocess.Popen(['mate-desktop-item-edit', file_path], env=os.environ)
     GLib.timeout_add(100, self.waitForNewMenuProcess, process, parent.get_menu_id(), file_path)
Esempio n. 13
0
 def on_new_menu_button_clicked(self, button):
     menu_tree = self.tree.get_object("menu_tree")
     menus, iter = menu_tree.get_selection().get_selected()
     if not iter:
         parent = menus[(0,)][2]
         menu_tree.expand_to_path((0,))
         menu_tree.get_selection().select_path((0,))
     else:
         parent = menus[iter][2]
     file_path = os.path.join(util.getUserDirectoryPath(), util.getUniqueFileId("mozo-made", ".directory"))
     process = subprocess.Popen(["mate-desktop-item-edit", file_path], env=os.environ)
     gobject.timeout_add(100, self.waitForNewMenuProcess, process, parent.menu_id, file_path)
Esempio n. 14
0
 def editMenu(self, menu, icon, name, comment, final=True):
     #if nothing changed don't make a user copy
     if icon == menu.get_icon() and name == menu.get_name() and comment == menu.get_comment():
         return
     #we don't use this, we just need to make sure the <Menu> exists
     #otherwise changes won't show up
     dom = self.__getMenu(menu).dom
     menu_xml = self.__getXmlMenu(self.__getPath(menu), dom.documentElement, dom)
     self.__writeMenu(menu, Icon=icon, Name=name, Comment=comment)
     if final:
         self.__addXmlTextElement(menu_xml, 'DirectoryDir', util.getUserDirectoryPath(), dom)
         self.__addUndo([self.__getMenu(menu), menu])
     self.save()
Esempio n. 15
0
 def editMenu(self, menu, icon, name, comment, final=True):
     #if nothing changed don't make a user copy
     if icon == menu.get_icon() and name == menu.get_name() and comment == menu.get_comment():
         return
     #we don't use this, we just need to make sure the <Menu> exists
     #otherwise changes won't show up
     dom = self.__getMenu(menu).dom
     menu_xml = self.__getXmlMenu(self.__getPath(menu), dom.documentElement, dom)
     self.__writeMenu(menu, Icon=icon, Name=name, Comment=comment)
     if final:
         self.__addXmlTextElement(menu_xml, 'DirectoryDir', util.getUserDirectoryPath(), dom)
         self.__addUndo([self.__getMenu(menu), menu])
     self.save()
Esempio n. 16
0
 def revertMenu(self, menu):
     if not self.canRevert(menu):
         return
     #wtf happened here? oh well, just bail
     if not menu.get_desktop_file_path():
         return
     self.__addUndo([menu,])
     file_id = os.path.split(menu.get_desktop_file_path())[1]
     path = os.path.join(util.getUserDirectoryPath(), file_id)
     try:
         os.remove(path)
     except OSError:
         pass
     self.save()
Esempio n. 17
0
 def revertMenu(self, menu):
     if not self.canRevert(menu):
         return
     #wtf happened here? oh well, just bail
     if not menu.get_desktop_file_path():
         return
     self.__addUndo([menu,])
     file_id = os.path.split(menu.get_desktop_file_path())[1]
     path = os.path.join(util.getUserDirectoryPath(), file_id)
     try:
         os.remove(path)
     except OSError:
         pass
     self.save()
 def __addUndo(self, items):
     self.__undo.append([])
     for item in items:
         if isinstance(item, Menu):
             file_path = item.path
         elif isinstance(item, tuple):
             if item[0] == 'Item':
                 file_path = os.path.join(util.getUserItemPath(), item[1])
                 if not os.path.isfile(file_path):
                     file_path = util.getItemPath(item[1])
             elif item[0] == 'Menu':
                 file_path = os.path.join(util.getUserDirectoryPath(),
                                          item[1])
                 if not os.path.isfile(file_path):
                     file_path = util.getDirectoryPath(item[1])
             else:
                 continue
         elif item.get_type() == matemenu.TYPE_DIRECTORY:
             if item.get_desktop_file_path() == None:
                 continue
             file_path = os.path.join(
                 util.getUserDirectoryPath(),
                 os.path.split(item.get_desktop_file_path())[1])
             if not os.path.isfile(file_path):
                 file_path = item.get_desktop_file_path()
         elif item.get_type() == matemenu.TYPE_ENTRY:
             file_path = os.path.join(util.getUserItemPath(),
                                      item.get_desktop_file_id())
             if not os.path.isfile(file_path):
                 file_path = item.get_desktop_file_path()
         else:
             continue
         data = open(file_path).read()
         undo_path = util.getUniqueUndoFile(file_path)
         open(undo_path, 'w').write(data)
         self.__undo[-1].append(undo_path)
Esempio n. 19
0
 def canRevert(self, item):
     if isinstance(item, MateMenu.TreeEntry):
         if util.getItemPath(item.get_desktop_file_id()) is not None:
             path = util.getUserItemPath()
             if os.path.isfile(os.path.join(path, item.get_desktop_file_id())):
                 return True
     elif isinstance(item, MateMenu.TreeDirectory):
         if item.get_desktop_file_path():
             file_id = os.path.split(item.get_desktop_file_path())[1]
         else:
             file_id = item.get_menu_id() + '.directory'
         if util.getDirectoryPath(file_id) is not None:
             path = util.getUserDirectoryPath()
             if os.path.isfile(os.path.join(path, file_id)):
                 return True
     return False
Esempio n. 20
0
	def canRevert(self, item):
		if item.get_type() == matemenu.TYPE_ENTRY:
			if util.getItemPath(item.get_desktop_file_id()):
				path = util.getUserItemPath()
				if os.path.isfile(os.path.join(path, item.get_desktop_file_id())):
					return True
		elif item.get_type() == matemenu.TYPE_DIRECTORY:
			if item.get_desktop_file_path():
				file_id = os.path.split(item.get_desktop_file_path())[1]
			else:
				file_id = item.get_menu_id() + '.directory'
			if util.getDirectoryPath(file_id):
				path = util.getUserDirectoryPath()
				if os.path.isfile(os.path.join(path, file_id)):
					return True
		return False
Esempio n. 21
0
 def canRevert(self, item):
     if isinstance(item, MateMenu.TreeEntry):
         if util.getItemPath(item.get_desktop_file_id()) is not None:
             path = util.getUserItemPath()
             if os.path.isfile(os.path.join(path, item.get_desktop_file_id())):
                 return True
     elif isinstance(item, MateMenu.TreeDirectory):
         if item.get_desktop_file_path():
             file_id = os.path.split(item.get_desktop_file_path())[1]
         else:
             file_id = item.get_menu_id() + '.directory'
         if util.getDirectoryPath(file_id) is not None:
             path = util.getUserDirectoryPath()
             if os.path.isfile(os.path.join(path, file_id)):
                 return True
     return False
 def canRevert(self, item):
     if item.get_type() == matemenu.TYPE_ENTRY:
         if util.getItemPath(item.get_desktop_file_id()):
             path = util.getUserItemPath()
             if os.path.isfile(
                     os.path.join(path, item.get_desktop_file_id())):
                 return True
     elif item.get_type() == matemenu.TYPE_DIRECTORY:
         if item.get_desktop_file_path():
             file_id = os.path.split(item.get_desktop_file_path())[1]
         else:
             file_id = item.get_menu_id() + '.directory'
         if util.getDirectoryPath(file_id):
             path = util.getUserDirectoryPath()
             if os.path.isfile(os.path.join(path, file_id)):
                 return True
     return False
Esempio n. 23
0
    def on_edit_properties_activate(self, menu):
        item_tree = self.tree.get_object('item_tree')
        items, iter = item_tree.get_selection().get_selected()
        if not iter:
            return
        item = items[iter][3]
        if item.get_type() not in (matemenu.TYPE_ENTRY,
                                   matemenu.TYPE_DIRECTORY):
            return

        if item.get_type() == matemenu.TYPE_ENTRY:
            file_path = os.path.join(util.getUserItemPath(),
                                     item.get_desktop_file_id())
            file_type = 'Item'
        elif item.get_type() == matemenu.TYPE_DIRECTORY:
            if item.get_desktop_file_path() == None:
                file_path = util.getUniqueFileId('mozo-made', '.directory')
                parser = util.DesktopParser(file_path, 'Directory')
                parser.set('Name', item.get_name())
                parser.set('Comment', item.get_comment())
                parser.set('Icon', item.get_icon())
                parser.write(open(file_path))
            else:
                file_path = os.path.join(
                    util.getUserDirectoryPath(),
                    os.path.split(item.get_desktop_file_path())[1])
            file_type = 'Menu'

        if not os.path.isfile(file_path):
            data = open(item.get_desktop_file_path()).read()
            open(file_path, 'w').write(data)
            self.editor._MenuEditor__addUndo([
                (file_type, os.path.split(file_path)[1]),
            ])
        else:
            self.editor._MenuEditor__addUndo([
                item,
            ])
        if file_path not in self.edit_pool:
            self.edit_pool.append(file_path)
            process = subprocess.Popen(['mate-desktop-item-edit', file_path],
                                       env=os.environ)
            gobject.timeout_add(100, self.waitForEditProcess, process,
                                file_path)
Esempio n. 24
0
    def __writeMenu(self, menu, **kwargs):
        if menu is not None:
            file_id = os.path.split(menu.get_desktop_file_path())[1]
            file_path = menu.get_desktop_file_path()
            keyfile = GLib.KeyFile()
            keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)
        elif menu is None and 'Name' not in kwargs:
            raise Exception('New menus need a name')
        else:
            file_id = util.getUniqueFileId(kwargs['Name'], '.directory')
            keyfile = GLib.KeyFile()

        util.fillKeyFile(keyfile, kwargs)

        contents, length = keyfile.to_data()

        with open(os.path.join(util.getUserDirectoryPath(), file_id), 'w') as f:
            f.write(contents)
        return file_id
Esempio n. 25
0
    def __writeMenu(self, menu, **kwargs):
        if menu is not None:
            file_id = os.path.split(menu.get_desktop_file_path())[1]
            file_path = menu.get_desktop_file_path()
            keyfile = GLib.KeyFile()
            keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)
        elif menu is None and 'Name' not in kwargs:
            raise Exception('New menus need a name')
        else:
            file_id = util.getUniqueFileId(kwargs['Name'], '.directory')
            keyfile = GLib.KeyFile()

        util.fillKeyFile(keyfile, kwargs)

        contents = keyfile.to_data()[0]

        with open(os.path.join(util.getUserDirectoryPath(), file_id), 'w') as f:
            f.write(contents)
        return file_id
Esempio n. 26
0
	def __writeMenu(self, menu=None, icon=None, name=None, comment=None, no_display=None):
		if menu:
			file_id = os.path.split(menu.get_desktop_file_path())[1]
			file_path = menu.get_desktop_file_path()
			keyfile = util.DesktopParser(file_path)
		elif menu == None and name == None:
			raise Exception('New menus need a name')
		else:
			file_id = util.getUniqueFileId(name, '.directory')
			keyfile = util.DesktopParser(file_type='Directory')
		if icon:
			keyfile.set('Icon', icon)
		if name:
			keyfile.set('Name', name)
			keyfile.set('Name', name, self.locale)
		if comment:
			keyfile.set('Comment', comment)
			keyfile.set('Comment', comment, self.locale)
		if no_display != None:
			keyfile.set('NoDisplay', no_display)
		out_path = os.path.join(util.getUserDirectoryPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		return file_id
Esempio n. 27
0
 def setVisible(self, item, visible):
     dom = self.__getMenu(item).dom
     if isinstance(item, MateMenu.TreeEntry):
         self.__addUndo([self.__getMenu(item), item])
         menu_xml = self.__getXmlMenu(self.__getPath(item.get_parent()), dom.documentElement, dom)
         if visible:
             self.__addXmlFilename(menu_xml, dom, item.get_desktop_file_id(), 'Include')
             self.__writeItem(item, NoDisplay=False)
         else:
             self.__addXmlFilename(menu_xml, dom, item.get_desktop_file_id(), 'Exclude')
         self.__addXmlTextElement(menu_xml, 'AppDir', util.getUserItemPath(), dom)
     elif isinstance(item, MateMenu.TreeDirectory):
         self.__addUndo([self.__getMenu(item), item])
         item_iter = item.iter()
         first_child_type = item_iter.next()
         #don't mess with it if it's empty
         if first_child_type == MateMenu.TreeItemType.INVALID:
             return
         menu_xml = self.__getXmlMenu(self.__getPath(item), dom.documentElement, dom)
         for node in self.__getXmlNodesByName(['Deleted', 'NotDeleted'], menu_xml):
             node.parentNode.removeChild(node)
         self.__writeMenu(item, NoDisplay=not visible)
         self.__addXmlTextElement(menu_xml, 'DirectoryDir', util.getUserDirectoryPath(), dom)
     self.save()
Esempio n. 28
0
 def setVisible(self, item, visible):
     dom = self.__getMenu(item).dom
     if isinstance(item, MateMenu.TreeEntry):
         self.__addUndo([self.__getMenu(item), item])
         menu_xml = self.__getXmlMenu(self.__getPath(item.get_parent()), dom.documentElement, dom)
         if visible:
             self.__addXmlFilename(menu_xml, dom, item.get_desktop_file_id(), 'Include')
             self.__writeItem(item, NoDisplay=False)
         else:
             self.__addXmlFilename(menu_xml, dom, item.get_desktop_file_id(), 'Exclude')
         self.__addXmlTextElement(menu_xml, 'AppDir', util.getUserItemPath(), dom)
     elif isinstance(item, MateMenu.TreeDirectory):
         self.__addUndo([self.__getMenu(item), item])
         item_iter = item.iter()
         first_child_type = item_iter.next()
         #don't mess with it if it's empty
         if first_child_type == MateMenu.TreeItemType.INVALID:
             return
         menu_xml = self.__getXmlMenu(self.__getPath(item), dom.documentElement, dom)
         for node in self.__getXmlNodesByName(['Deleted', 'NotDeleted'], menu_xml):
             node.parentNode.removeChild(node)
         self.__writeMenu(item, NoDisplay=not visible)
         self.__addXmlTextElement(menu_xml, 'DirectoryDir', util.getUserDirectoryPath(), dom)
     self.save()