def move_item_to_parent(self): if core_api.block_databases(): selection = self.get_selections(none=False, many=False) if selection: item = selection[0] id_ = self.get_item_id(item) oldpid = core_api.get_item_parent(self.filename, id_) if core_api.move_item_to_parent(self.filename, id_, description='Move item to parent'): newpid = core_api.get_item_parent(self.filename, id_) # oldpid cannot be 0 here because # core_api.move_item_to_parent succeded, which means that # it wasn't the root item oldparent = self.get_tree_item(oldpid) newparent = self.get_tree_item_safe(newpid) self.dvmodel.ItemDeleted(oldparent, item) self.dvmodel.ItemAdded(newparent, item) self._reset_children(id_, item) self._refresh_item_arrow(newparent, oldpid, oldparent) self.select_item(id_) self.dbhistory.refresh() core_api.release_databases()
def delete_items(self, ids, description="Delete items"): group = core_api.get_next_history_group(self.filename) roots = core_api.find_independent_items(self.filename, ids) for root in roots: rootpid = core_api.get_item_parent(self.filename, root) core_api.delete_subtree(self.filename, root, group=group, description=description) if rootpid > 0: rootpid2 = core_api.get_item_parent(self.filename, rootpid) rootparent2 = self.get_tree_item_safe(rootpid2) self._refresh_item_arrow(rootparent2, rootpid, self.get_tree_item(rootpid))
def _move_item(self, id_, item): pid = core_api.get_item_parent(self.filename, id_) parent = self.get_tree_item_safe(pid) self.dvmodel.ItemDeleted(parent, item) self.dvmodel.ItemAdded(parent, item) self._reset_children(id_, item)
def create_sibling(self): if core_api.block_databases(): # Do not use none=False in order to allow the creation of the # first item selection = self.get_selections(many=False) # If multiple items are selected, selection will be False if selection is not False: text = 'New item' if len(selection) > 0: previd = self.get_item_id(selection[0]) parid = core_api.get_item_parent(self.filename, previd) id_ = core_api.create_sibling(filename=self.filename, parent=parid, previous=previd, text=text, description='Insert item') else: id_ = core_api.create_child(filename=self.filename, parent=0, text=text, description='Insert item') self.select_item(id_) self.dbhistory.refresh() core_api.release_databases()
def GetParent(self, item): if not item: return dv.NullDataViewItem else: id_ = self.ItemToObject(item).get_id() pid = core_api.get_item_parent(self.filename, id_) if pid > 0: return self.ObjectToItem(self.data[pid]) else: return dv.NullDataViewItem