def __init__(self):
global _datasource
self.name = 'Drag & Drop'
self.width = min(ui.get_window_size()[0] * 0.8, 700)
self.height = ui.get_window_size()[1] * 0.8
path = editor.get_path()
if path:
expanded_folder = os.path.dirname(path)
files = tab.get_paths()
else:
expanded_folder = None
files = None
root_node = FileNode(os.path.expanduser('~/Documents'), ignore=ignore)
_datasource = FolderPickerDataSource(root_node, expanded_folder, files)
tv = ui.TableView(frame=self.bounds, flex='WH')
tv.delegate = _datasource
tv.data_source = _datasource
tv.allows_multiple_selection = False
tv.allows_selection = True
tv.allows_multiple_selection_during_editing = False
tv.allows_selection_during_editing = False
tv.separator_color = 'clear'
self.add_subview(tv)
methods = [tableView_itemsForBeginningDragSession_atIndexPath_]
protocols = ['UITableViewDragDelegate']
DragDelegate = create_objc_class('DragDelegate', methods=methods, protocols=protocols)
self._drag_delegate = DragDelegate.alloc().init()
methods = [
tableView_canHandleDropSession_,
tableView_dropSessionDidUpdate_withDestinationIndexPath_,
tableView_performDropWithCoordinator_
]
protocols = ['UITableViewDropDelegate']
DropDelegate = create_objc_class('DropDelegate', methods=methods, protocols=protocols)
self._drop_delegate = DropDelegate.alloc().init()
tv_objc = ObjCInstance(tv)
tv_objc.setDragDelegate_(self._drag_delegate)
tv_objc.setDropDelegate_(self._drop_delegate)
def handle_escape():
self.close()
self._handlers = [
register_key_event_handler(UIEventKeyCode.escape, handle_escape),
register_key_event_handler(UIEventKeyCode.dot, handle_escape,
modifier=UIKeyModifier.command)
]
评论列表
文章目录