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()
def on_edit_properties_activate(self, menu): item_tree = self.tree.get_object(self.last_tree) items, iter = item_tree.get_selection().get_selected() if not iter: return item = items[iter][3] if not isinstance(item, CMenu.TreeEntry) and not isinstance( item, CMenu.TreeDirectory): return if isinstance(item, CMenu.TreeEntry): file_path = os.path.join(util.getUserItemPath(), item.get_desktop_file_id()) file_type = 'launcher' elif isinstance(item, CMenu.TreeDirectory): file_path = os.path.join( util.getUserDirectoryPath(), os.path.split(item.get_desktop_file_path())[1]) file_type = 'directory' if not os.path.isfile(file_path): shutil.copy(item.get_desktop_file_path(), file_path) if file_path not in self.edit_pool: self.edit_pool.append(file_path) process = subprocess.Popen([ 'cinnamon-desktop-editor', '-m' + file_type, '-o' + 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,)][3] menu_tree.expand_to_path((0,)) menu_tree.get_selection().select_path((0,)) else: parent = menus[iter][3] file_path = os.path.join(util.getUserDirectoryPath(), util.getUniqueFileId('alacarte-made', '.directory')) process = subprocess.Popen(['cinnamon-desktop-editor', '-mdirectory', '-o' + file_path], env=os.environ) GObject.timeout_add(100, self.waitForNewMenuProcess, process, parent.get_menu_id(), file_path)
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()
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()
def canRevert(self, item): if isinstance(item, CMenu.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, CMenu.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 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
def on_edit_properties_activate(self, menu): item_tree = self.tree.get_object(self.last_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)
def check_custom_path(self): self.item_path = os.path.join(util.getUserDirectoryPath(), os.path.split(self.item_path)[1])