!752 static L origData, data; static S dir = "/"; static JTable table; static S ip; p-substance { if (ip == null) ip = gateway(); final JTextField tf = jTextField(ip); showForm("IP to browse:", tf, r { ip = trim(tf.getText()); load("dir"); browse(dir); }); } svoid browse(S path) { dir = path; save("dir"); S s = sendToAwareness(ip, "list directory *", dir); origData = (L) safeUnstructure(s); data = sortedByField("Name", map(func(Map map) { putKeysFirst(renameKeys(map, "dir", "Directory?", "m", "Last modified", "n", "Name", "l", "File Size (Bytes)"), "Name", "Directory?") }, origData)); S title = dir + " [" + ip + "]"; bool firstTime = table == null; table = showTableWithSearcher(table, data, title); if (firstTime) { onDoubleClickOrEnter(table, voidfunc(int row) { Map map = getTableLineAsMap(table, row); if (map == null) ret; Map map2 = findByField(origData, "n", map.get("Name")); print("map2=" + struct(map2)); S name = getString(map, "Name"); if (isTrue(_get(map2, "dir"))) browse(addSlash(dir) + name); else swingOpenPhoneFile(ip, addSlash(dir) + name); }); registerKey(getFrame(table), KeyEvent.VK_BACK_SPACE, "Back", r { browse(or2(substring(dir, 0, dir.lastIndexOf('/')), "/")); }); tablePopupMenu(table, voidfunc(JPopupMenu menu, int row) { Map map = getTableLineAsMap(table, row); if (map == null) ret; Map map2 = findByField(origData, "n", map.get("Name")); print("map2=" + struct(map2)); final S name = getString(map, "Name"); final S path = addSlash(dir) + name; if (!isTrue(_get(map2, "dir"))) addMenuItem(menu, "Download File", r { thread "Downloading" { print("Downloading from phone..."); byte[] data = readFileFromPhone(ip, path); File f = userHome("Downloads/" + name); saveBinaryFile(f, data); print("Saved: " + f.getAbsolutePath()); } }); }); } }