def test_outlineView_willDisplayCell_forTableColumn_item_(): ewc = WindowController(None) m = Mocker() view = m.mock(ak.NSOutlineView) cell = m.mock(ImageAndTextCell) col, item, editor, icon = m.mock(), m.mock(), m.mock(), m.mock() col.identifier() >> "name" representedObject(item) >> editor editor.icon() >> icon cell.setImage_(icon) cell.editor = editor with m: ewc.outlineView_willDisplayCell_forTableColumn_item_(view, cell, col, item)
def validate_drop(self, outline_view, info, item, index): if self.is_project_drag(info): if item is not None: obj = representedObject(item) path = self.wc.docsController.indexPathForObject_(obj) if path is not None: index = path.indexAtPosition_(0) outline_view.setDropItem_dropChildIndex_(None, index) else: return ak.NSDragOperationNone elif index < 0: nprojs = len(self.projects) outline_view.setDropItem_dropChildIndex_(None, nprojs) else: # text document drag if item is not None: obj = representedObject(item) if isinstance(obj, Project): if index < 0: #outline_view.setDropItem_dropChildIndex_(item, 0) # the following might be more correct, but is too confusing outline_view.setDropItem_dropChildIndex_(item, len(obj.documents())) else: return ak.NSDragOperationNone # document view cannot have children else: if index < 0: # drop on listview background last_proj_index = len(self.projects) - 1 if last_proj_index > -1: # we have at least one project path = fn.NSIndexPath.indexPathWithIndex_(last_proj_index) node = self.wc.docsController.nodeAtArrangedIndexPath_(path) proj = representedObject(node) outline_view.setDropItem_dropChildIndex_(node, len(proj.documents())) else: outline_view.setDropItem_dropChildIndex_(None, -1) elif index == 0: return ak.NSDragOperationNone # prevent drop above top project # src = info.draggingSource() # if src is not None: # # internal drag # if src is not outline_view: # delegate = getattr(src, "delegate", lambda:None)() # if isinstance(delegate, EditorWindowController) and \ # delegate is not self.wc: # # drag from some other window controller # # allow copy (may need to override outline_view.ignoreModifierKeysWhileDragging) return ak.NSDragOperationGeneric
def reloadData(self): # based on Jonathan Dann's ESOutlineView super(OutlineView, self).reloadData() for row in reversed(range(self.numberOfRows())): item = self.itemAtRow_(row) obj = representedObject(item) if getattr(obj, "expanded", False): self.expandItem_(item)
def menuForEvent_(self, event): point = self.convertPoint_fromView_(event.locationInWindow(), None) row = self.rowAtPoint_(point) item = self.itemAtRow_(row) if item is not None: obj = representedObject(item) # HACK reach around to set object on menu target self._default_menu.target.current_object = obj return super().menuForEvent_(event) return None
def test(c): m = Mocker() ed = m.mock(Window) ewc = WindowController(ed) n = m.mock() # ak.NSOutlineViewItemDid___Notification node = m.mock(ak.NSTreeControllerTreeNode); n.userInfo() >> {"NSObject": node} it = representedObject(node) >> m.mock(Project) it.expanded = c.exp with m: getattr(ewc, c.method)(n)
def validate_drop(self, outline_view, info, item, index): if self.is_project_drag(info): if item is not None: obj = representedObject(item) path = self.wc.docsController.indexPathForObject_(obj) if path is not None: index = path.indexAtPosition_(0) outline_view.setDropItem_dropChildIndex_(None, index) else: return ak.NSDragOperationNone elif index < 0: outline_view.setDropItem_dropChildIndex_(None, len(self.projects)) return ak.NSDragOperationMove else: # text document drag if item is not None: obj = representedObject(item) if isinstance(obj, Project): if index < 0: #outline_view.setDropItem_dropChildIndex_(item, 0) # the following might be more correct, but is too confusing outline_view.setDropItem_dropChildIndex_(item, len(obj.editors)) else: return ak.NSDragOperationNone # document view cannot have children else: if index < 0: # drop on listview background last_proj_index = len(self.projects) - 1 if last_proj_index > -1: # we have at least one project path = fn.NSIndexPath.indexPathWithIndex_(last_proj_index) node = self.wc.docsController.nodeAtArrangedIndexPath_(path) proj = representedObject(node) outline_view.setDropItem_dropChildIndex_(node, len(proj.editors)) else: outline_view.setDropItem_dropChildIndex_(None, -1) elif index == 0: return ak.NSDragOperationNone # prevent drop above top project op = info.draggingSourceOperationMask() if op not in [ak.NSDragOperationCopy, ak.NSDragOperationGeneric]: op = ak.NSDragOperationMove return op
def accept_drop(self, outline_view, info, item, index): """Accept drop operation :param outline_view: The OutlineView on which the drop occurred. :param info: NSDraggingInfo object. :param item: The parent item in the outline view. :param index: The index in the outline view or parent item at which the drop occurred. :returns: True if the drop was accepted, otherwise False. """ pb = info.draggingPasteboard() t = pb.availableTypeFromArray_(self.supported_drag_types) action = None if t == const.DOC_ID_LIST_PBOARD_TYPE: items = self.iter_dropped_id_list(pb) action = const.MOVE elif t == ak.NSFilenamesPboardType: items = self.iter_dropped_paths(pb) else: assert t is None, t return False parent = None if item is None else representedObject(item) return self.accept_dropped_items(items, parent, index, action)
def iterVisibleObjects(self): """Iterate (row, visible object) pairs""" for row in range(self.numberOfRows()): item = self.itemAtRow_(row) yield row, representedObject(item)
def realItemForOpaqueItem_(self, item): return representedObject(item)
def outlineView_willDisplayCell_forTableColumn_item_(self, view, cell, col, item): if col.identifier() == "name": cell.setImage_(representedObject(item).icon())
def outlineViewItemDidExpand_(self, notification): representedObject(notification.userInfo()["NSObject"]).expanded = True
def outlineViewItemDidCollapse_(self, notification): representedObject(notification.userInfo()["NSObject"]).expanded = False
def should_edit_item(self, col, item): if col.isEditable(): obj = representedObject(item) return isinstance(obj, Project) and obj.can_rename() return False
def outlineView_acceptDrop_item_childIndex_(self, view, info, item, index): pboard = info.draggingPasteboard() parent = None if item is None else representedObject(item) # move unless modifier specifies copy or generic insert (copy unless present) action = self.DROP_ACTIONS.get(info.draggingSourceOperationMask(), const.MOVE) return self.window_.accept_drop(view, pboard, parent, index, action)