Example #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)
Example #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)
Example #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)
Example #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)
Example #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()
Example #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 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)
Example #7
0
	def __writeItem(self, item=None, icon=None, name=None, comment=None, command=None, use_term=None, no_display=None, startup_notify=None, hidden=None):
		if item:
			file_path = item.get_desktop_file_path()
			file_id = item.get_desktop_file_id()
			keyfile = util.DesktopParser(file_path)
		elif item == None and name == None:
			raise Exception('New menu items need a name')
		else:
			file_id = util.getUniqueFileId(name, '.desktop')
			keyfile = util.DesktopParser()
		if icon:
			keyfile.set('Icon', icon)
			keyfile.set('Icon', icon, self.locale)
		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 command:
			keyfile.set('Exec', command)
		if use_term != None:
			keyfile.set('Terminal', use_term)
		if no_display != None:
			keyfile.set('NoDisplay', no_display)
		if startup_notify != None:
			keyfile.set('StartupNotify', startup_notify)
		if hidden != None:
			keyfile.set('Hidden', hidden)
		out_path = os.path.join(util.getUserItemPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		return file_id
Example #8
0
	def __writeItem(self, item=None, icon=None, name=None, comment=None, command=None, use_term=None, no_display=None, startup_notify=None, hidden=None):
		if item:
			file_path = item.get_desktop_file_path()
			file_id = item.get_desktop_file_id()
			keyfile = util.DesktopParser(file_path)
		elif item == None and name == None:
			raise Exception('New menu items need a name')
		else:
			file_id = util.getUniqueFileId(name, '.desktop')
			keyfile = util.DesktopParser()
		if icon:
			keyfile.set('Icon', icon)
			keyfile.set('Icon', icon, self.locale)
		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 command:
			keyfile.set('Exec', command)
		if use_term != None:
			keyfile.set('Terminal', use_term)
		if no_display != None:
			keyfile.set('NoDisplay', no_display)
		if startup_notify != None:
			keyfile.set('StartupNotify', startup_notify)
		if hidden != None:
			keyfile.set('Hidden', hidden)
		out_path = os.path.join(util.getUserItemPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		return file_id
Example #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()
Example #10
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()
Example #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 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)
Example #12
0
 def editItem(self,
              item,
              icon,
              name,
              comment,
              command,
              use_term,
              parent=None,
              final=True):
     #if nothing changed don't make a user copy
     app_info = item.get_app_info()
     if icon == app_info.get_icon() and name == app_info.get_display_name(
     ) and comment == item.get_comment() and command == item.get_exec(
     ) and use_term == item.get_launch_in_terminal():
         return
     #hack, item.get_parent() seems to fail a lot
     if not parent:
         parent = item.get_parent()
     self.writeItem(item,
                    Icon=icon,
                    Name=name,
                    Comment=comment,
                    Exec=command,
                    Terminal=use_term)
     if final:
         dom = self.dom
         menu_xml = self.getXmlMenu(self.getPath(parent),
                                    dom.documentElement, dom)
         self.addXmlTextElement(menu_xml, 'AppDir', util.getUserItemPath(),
                                dom)
     self.save()
Example #13
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()
Example #14
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()
Example #15
0
 def on_new_item_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.getUserItemPath(), util.getUniqueFileId('alacarte-made', '.desktop'))
     process = subprocess.Popen(['gnome-desktop-item-edit', file_path], env=os.environ)
     GObject.timeout_add(100, self.waitForNewItemProcess, process, parent.get_menu_id(), file_path)
Example #16
0
    def on_new_item_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.getUserItemPath(), util.getUniqueFileId('alacarte-made', '.desktop'))

        editor = LauncherEditor(self.main_window, file_path)
        editor.run()
Example #17
0
 def editItem(self, item, icon, name, comment, command, use_term, parent=None, final=True):
     #if nothing changed don't make a user copy
     app_info = item.get_app_info()
     if icon == app_info.get_icon() and name == app_info.get_display_name() and comment == item.get_comment() and command == item.get_exec() and use_term == item.get_launch_in_terminal():
         return
     #hack, item.get_parent() seems to fail a lot
     if not parent:
         parent = item.get_parent()
     self.writeItem(item, Icon=icon, Name=name, Comment=comment, Exec=command, Terminal=use_term)
     if final:
         dom = self.dom
         menu_xml = self.getXmlMenu(self.getPath(parent), dom.documentElement, dom)
         self.addXmlTextElement(menu_xml, 'AppDir', util.getUserItemPath(), dom)
     self.save()
Example #18
0
	def editItem(self, item, icon, name, comment, command, use_term, parent=None, final=True):
		#if nothing changed don't make a user copy
		if icon == item.get_icon() and name == item.get_display_name() and comment == item.get_comment() and command == item.get_exec() and use_term == item.get_launch_in_terminal():
			return
		#hack, item.get_parent() seems to fail a lot
		if not parent:
			parent = item.get_parent()
		if final:
			self.__addUndo([self.__getMenu(parent), item])
		self.__writeItem(item, icon, name, comment, command, use_term)
		if final:
			dom = self.__getMenu(parent).dom
			menu_xml = self.__getXmlMenu(self.__getPath(parent), dom, dom)
			self.__addXmlTextElement(menu_xml, 'AppDir', util.getUserItemPath(), dom)
		self.save()
Example #19
0
	def copyItem(self, item, new_parent, before=None, after=None):
		dom = self.__getMenu(new_parent).dom
		file_path = item.get_desktop_file_path()
		keyfile = util.DesktopParser(file_path)
		#erase Categories in new file
		keyfile.set('Categories', ('',))
		keyfile.set('Hidden', False)
		file_id = util.getUniqueFileId(item.get_name(), '.desktop')
		out_path = os.path.join(util.getUserItemPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		self.__addItem(new_parent, file_id, dom)
		self.__positionItem(new_parent, ('Item', file_id), before, after)
		self.__addUndo([self.__getMenu(new_parent), ('Item', file_id)])
		self.save()
		return file_id
Example #20
0
	def editItem(self, item, icon, name, comment, command, use_term, parent=None, final=True):
		#if nothing changed don't make a user copy
		if icon == item.get_icon() and name == item.get_display_name() and comment == item.get_comment() and command == item.get_exec() and use_term == item.get_launch_in_terminal():
			return
		#hack, item.get_parent() seems to fail a lot
		if not parent:
			parent = item.get_parent()
		if final:
			self.__addUndo([self.__getMenu(parent), item])
		self.__writeItem(item, icon, name, comment, command, use_term)
		if final:
			dom = self.__getMenu(parent).dom
			menu_xml = self.__getXmlMenu(self.__getPath(parent), dom, dom)
			self.__addXmlTextElement(menu_xml, 'AppDir', util.getUserItemPath(), dom)
		self.save()
Example #21
0
	def copyItem(self, item, new_parent, before=None, after=None):
		dom = self.__getMenu(new_parent).dom
		file_path = item.get_desktop_file_path()
		keyfile = util.DesktopParser(file_path)
		#erase Categories in new file
		keyfile.set('Categories', ('',))
		keyfile.set('Hidden', False)
		file_id = util.getUniqueFileId(item.get_name(), '.desktop')
		out_path = os.path.join(util.getUserItemPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		self.__addItem(new_parent, file_id, dom)
		self.__positionItem(new_parent, ('Item', file_id), before, after)
		self.__addUndo([self.__getMenu(new_parent), ('Item', file_id)])
		self.save()
		return file_id
Example #22
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
Example #23
0
 def on_new_item_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.getUserItemPath(),
         util.getUniqueFileId('alacarte-made', '.desktop'))
     process = subprocess.Popen(['gnome-desktop-item-edit', file_path],
                                env=os.environ)
     GObject.timeout_add(100, self.waitForNewItemProcess, process,
                         parent.get_menu_id(), file_path)
Example #24
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
Example #25
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
Example #26
0
    def on_new_item_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', '.desktop')
        file_path = os.path.join(util.getUserItemPath(), file_name)

        editor = LauncherEditor(self.main_window, file_path)
        editor.file_name = file_name
        editor.parent = parent.get_menu_id()
        editor.connect('response', self.on_item_created)
        editor.run()
Example #27
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_item_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", ".desktop")
        file_path = os.path.join(util.getUserItemPath(), file_name)

        editor = LauncherEditor(self.main_window, file_path)
        editor.file_name = file_name
        editor.parent = parent.get_menu_id()
        editor.connect("response", self.on_item_created)
        editor.run()
Example #29
0
    def writeItem(self, item, **kwargs):
        if item is not None:
            file_path = item.get_desktop_file_path()
        else:
            file_path = None

        keyfile = self.makeKeyFile(file_path, kwargs)

        if item is not None:
            file_id = item.get_desktop_file_id()
        else:
            file_id = util.getUniqueFileId(keyfile.get_string(GLib.KEY_FILE_DESKTOP_GROUP, 'Name'), '.desktop')

        contents, length = keyfile.to_data()
        f = open(os.path.join(util.getUserItemPath(), file_id), 'w')
        f.write(contents)
        f.close()
        return file_id
Example #30
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)
Example #31
0
    def writeItem(self, item, **kwargs):
        if item is not None:
            file_path = item.get_desktop_file_path()
        else:
            file_path = None

        keyfile = self.makeKeyFile(file_path, kwargs)

        if item is not None:
            file_id = item.get_desktop_file_id()
        else:
            file_id = util.getUniqueFileId(
                keyfile.get_string(GLib.KEY_FILE_DESKTOP_GROUP, 'Name'),
                '.desktop')

        contents, length = keyfile.to_data()
        f = open(os.path.join(util.getUserItemPath(), file_id), 'w')
        f.write(contents)
        f.close()
        return file_id
Example #32
0
    def copyItem(self, item, new_parent, before=None, after=None):
        dom = self.dom
        file_path = item.get_desktop_file_path()
        keyfile = GLib.KeyFile()
        keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)

        util.fillKeyFile(keyfile, dict(Categories=[], Hidden=False))

        app_info = item.get_app_info()
        file_id = util.getUniqueFileId(app_info.get_name().replace(os.sep, '-'), '.desktop')
        out_path = os.path.join(util.getUserItemPath(), file_id)

        contents, length = keyfile.to_data()

        with open(out_path, 'w') as f:
            f.write(contents)

        self.addItem(new_parent, file_id, dom)
        self.positionItem(new_parent, ('Item', file_id), before, after)
        self.save()
        return file_id
Example #33
0
    def copyItem(self, item, new_parent, before=None, after=None):
        dom = self.dom
        file_path = item.get_desktop_file_path()
        keyfile = GLib.KeyFile()
        keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)

        util.fillKeyFile(keyfile, dict(Categories=[], Hidden=False))

        app_info = item.get_app_info()
        file_id = util.getUniqueFileId(
            app_info.get_name().replace(os.sep, '-'), '.desktop')
        out_path = os.path.join(util.getUserItemPath(), file_id)

        contents, length = keyfile.to_data()

        with open(out_path, 'w') as f:
            f.write(contents)

        self.addItem(new_parent, file_id, dom)
        self.positionItem(new_parent, ('Item', file_id), before, after)
        self.save()
        return file_id
Example #34
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()
Example #35
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'
        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)