Exemple #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 item.get_type() == gmenu.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() == gmenu.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)
Exemple #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() == gmenu.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() == gmenu.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)
Exemple #3
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)
Exemple #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)
Exemple #5
0
	def setVisible(self, item, visible):
		dom = self.__getMenu(item).dom
		if item.get_type() == gmenu.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() == gmenu.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()
Exemple #6
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, GMenu.TreeEntry) and not isinstance(item, GMenu.TreeDirectory):
            return

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

        copied = False
        if not os.path.isfile(file_path):
            shutil.copy(item.get_desktop_file_path(), file_path)
            copied = True

        editor = Editor(self.main_window, file_path)
        editor.connect('response', self.on_editor_response, file_path if copied else None)
        editor.run()
 def setVisible(self, item, visible):
     dom = self.dom
     if isinstance(item, GMenu.TreeEntry):
         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, GMenu.TreeDirectory):
         item_iter = item.iter()
         first_child_type = item_iter.next()
         #don't mess with it if it's empty
         if first_child_type == GMenu.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()
Exemple #8
0
	def setVisible(self, item, visible):
		dom = self.__getMenu(item).dom
		if item.get_type() == gmenu.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() == gmenu.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()
Exemple #9
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, GMenu.TreeEntry) and not isinstance(
                item, GMenu.TreeDirectory):
            return

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

        copied = False
        if not os.path.isfile(file_path):
            shutil.copy(item.get_desktop_file_path(), file_path)
            copied = True

        editor = Editor(self.main_window, file_path)
        editor.connect('response', self.on_editor_response,
                       file_path if copied else None)
        editor.run()
    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, GMenu.TreeEntry) and not isinstance(
                item, GMenu.TreeDirectory):
            return

        if isinstance(item, GMenu.TreeEntry):
            file_path = os.path.join(util.getUserItemPath(),
                                     item.get_desktop_file_id())
            file_type = 'Item'
        elif isinstance(item, GMenu.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):
            data = open(item.get_desktop_file_path()).read()
            open(file_path, 'w').write(data)

        if file_path not in self.edit_pool:
            self.edit_pool.append(file_path)
            process = subprocess.Popen(['gnome-desktop-item-edit', file_path],
                                       env=os.environ)
            GObject.timeout_add(100, self.waitForEditProcess, process,
                                file_path)
Exemple #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 (gmenu.TYPE_ENTRY, gmenu.TYPE_DIRECTORY):
			return

		if item.get_type() == gmenu.TYPE_ENTRY:
			file_path = os.path.join(util.getUserItemPath(), item.get_desktop_file_id())
			file_type = 'Item'
		elif item.get_type() == gmenu.TYPE_DIRECTORY:
			if item.get_desktop_file_path() == None:
				file_path = util.getUniqueFileId('alacarte-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(['gnome-desktop-item-edit', file_path], env=os.environ)
			gobject.timeout_add(100, self.waitForEditProcess, process, file_path)
 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('alacarte-made', '.directory'))
     process = subprocess.Popen(['gnome-desktop-item-edit', file_path], env=os.environ)
     GObject.timeout_add(100, self.waitForNewMenuProcess, process, parent.get_menu_id(), file_path)
Exemple #13
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.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.save()
Exemple #14
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('alacarte-made', '.directory'))

        editor = DirectoryEditor(self.main_window, file_path)
        editor.run()
Exemple #15
0
 def restoreMenu(self, menu):
     if not self.canRevert(menu):
         return
     #wtf happened here? oh well, just bail
     if not menu.get_desktop_file_path():
         return
     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()
Exemple #16
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, dom)
		file_id = self.__writeMenu(menu, icon, name, comment)
		if final:
			self.__addXmlTextElement(menu_xml, 'DirectoryDir', util.getUserDirectoryPath(), dom)
			self.__addUndo([self.__getMenu(menu), menu])
		self.save()
Exemple #17
0
 def restoreMenu(self, menu):
     if not self.canRevert(menu):
         return
     #wtf happened here? oh well, just bail
     if not menu.get_desktop_file_path():
         return
     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()
Exemple #18
0
	def canRevert(self, item):
		if item.get_type() == gmenu.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() == gmenu.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
 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('alacarte-made', '.directory'))
     process = subprocess.Popen(['gnome-desktop-item-edit', file_path],
                                env=os.environ)
     GObject.timeout_add(100, self.waitForNewMenuProcess, process,
                         parent.get_menu_id(), file_path)
Exemple #20
0
	def canRevert(self, item):
		if item.get_type() == gmenu.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() == gmenu.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
Exemple #21
0
 def canRevert(self, item):
     if isinstance(item, GMenu.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, GMenu.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 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_name = util.getUniqueFileId("alacarte-made", ".directory")
        file_path = os.path.join(util.getUserDirectoryPath(), file_name)

        editor = DirectoryEditor(self.main_window, file_path)
        editor.file_name = file_name
        editor.parent = parent.get_menu_id()
        editor.connect("response", self.on_directory_created)
        editor.run()
Exemple #23
0
 def canRevert(self, item):
     if isinstance(item, GMenu.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, GMenu.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
Exemple #24
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_name = util.getUniqueFileId('alacarte-made', '.directory')
        file_path = os.path.join(util.getUserDirectoryPath(), file_name)

        editor = DirectoryEditor(self.main_window, file_path)
        editor.file_name = file_name
        editor.parent = parent.get_menu_id()
        editor.connect('response', self.on_directory_created)
        editor.run()
Exemple #25
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 (gmenu.TYPE_ENTRY, gmenu.TYPE_DIRECTORY):
            return

        if item.get_type() == gmenu.TYPE_ENTRY:
            file_path = os.path.join(util.getUserItemPath(),
                                     item.get_desktop_file_id())
            file_type = 'Item'
        elif item.get_type() == gmenu.TYPE_DIRECTORY:
            if item.get_desktop_file_path() == None:
                file_path = util.getUniqueFileId('alacarte-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(['gnome-desktop-item-edit', file_path],
                                       env=os.environ)
            gobject.timeout_add(100, self.waitForEditProcess, process,
                                file_path)
Exemple #26
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()

        f = open(os.path.join(util.getUserDirectoryPath(), file_id), 'w')
        f.write(contents)
        f.close()
        return file_id
Exemple #27
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()

        f = open(os.path.join(util.getUserDirectoryPath(), file_id), 'w')
        f.write(contents)
        f.close()
        return file_id
Exemple #28
0
 def setVisible(self, item, visible):
     dom = self.dom
     if isinstance(item, GMenu.TreeEntry):
         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, GMenu.TreeDirectory):
         item_iter = item.iter()
         first_child_type = item_iter.next()
         #don't mess with it if it's empty
         if first_child_type == GMenu.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()
Exemple #29
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
Exemple #30
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
    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, GMenu.TreeEntry) and not isinstance(item, GMenu.TreeDirectory):
            return

        if isinstance(item, GMenu.TreeEntry):
            file_path = os.path.join(util.getUserItemPath(), item.get_desktop_file_id())
            file_type = 'Item'
        elif isinstance(item, GMenu.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):
            data = open(item.get_desktop_file_path()).read()
            open(file_path, 'w').write(data)

        if file_path not in self.edit_pool:
            self.edit_pool.append(file_path)
            process = subprocess.Popen(['gnome-desktop-item-edit', file_path], env=os.environ)
            GObject.timeout_add(100, self.waitForEditProcess, process, file_path)