1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927
|
/********************************************************************************
* *
* F i l e L i s t O b j e c t *
* *
*********************************************************************************
* Copyright (C) 1998,2022 by Jeroen van der Zijp. All Rights Reserved. *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/> *
********************************************************************************/
#include "xincs.h"
#include "fxver.h"
#include "fxdefs.h"
#include "fxmath.h"
#include "fxkeys.h"
#include "fxascii.h"
#include "fxunicode.h"
#include "FXArray.h"
#include "FXHash.h"
#include "FXMutex.h"
#include "FXStream.h"
#include "FXObjectList.h"
#include "FXString.h"
#include "FXSize.h"
#include "FXPoint.h"
#include "FXRectangle.h"
#include "FXSystem.h"
#include "FXPath.h"
#include "FXIO.h"
#include "FXStat.h"
#include "FXFile.h"
#include "FXDir.h"
#include "FXURL.h"
#include "FXStringDictionary.h"
#include "FXSettings.h"
#include "FXRegistry.h"
#include "FXFont.h"
#include "FXEvent.h"
#include "FXWindow.h"
#include "FXApp.h"
#include "FXIcon.h"
#include "FXGIFIcon.h"
#include "FXScrollBar.h"
#include "FXIconSource.h"
#include "FXShell.h"
#include "FXPopup.h"
#include "FXMenuPane.h"
#include "FXMenuCaption.h"
#include "FXMenuCommand.h"
#include "FXMenuCascade.h"
#include "FXMenuRadio.h"
#include "FXMenuCheck.h"
#include "FXMenuSeparator.h"
#include "FXDictionary.h"
#include "FXDictionaryOf.h"
#include "FXIconCache.h"
#include "FXFileAssociations.h"
#include "FXHeader.h"
#include "FXIconList.h"
#include "FXFileList.h"
#include "FXFileProgressDialog.h"
#include "FXMessageBox.h"
#include "icons.h"
/*
Notes:
- Share icons with other widgets; upgrade icons to some nicer ones.
- Should some of these icons move to FXFileAssociations?
- Clipboard of filenames.
- Clipboard, DND, etc. support.
- When being dragged over, if hovering over a directory item for some
time we need to open it.
- We should generate SEL_INSERTED, SEL_DELETED, SEL_CHANGED
messages as the FXFileList updates itself from the file system.
- The solution currently used to determine whether or not to blend the
icon isn't so great; this class shouldn't have to know about FXPNGIcon.
- If you land in a large directory with images, things are a tad slow;
need to speed this up some how.
*/
#define OPENDIRDELAY 700000000 // Delay before opening directory
#define REFRESHINTERVAL 1000000000 // Interval between refreshes
#define REFRESHCOUNT 30 // Refresh every REFRESHCOUNT-th time
using namespace FX;
/*******************************************************************************/
namespace FX {
// Object implementation
FXIMPLEMENT(FXFileItem,FXIconItem,nullptr,0)
// Map
FXDEFMAP(FXFileList) FXFileListMap[]={
FXMAPFUNC(SEL_DND_ENTER,0,FXFileList::onDNDEnter),
FXMAPFUNC(SEL_DND_LEAVE,0,FXFileList::onDNDLeave),
FXMAPFUNC(SEL_DND_DROP,0,FXFileList::onDNDDrop),
FXMAPFUNC(SEL_DND_MOTION,0,FXFileList::onDNDMotion),
FXMAPFUNC(SEL_DND_REQUEST,0,FXFileList::onDNDRequest),
FXMAPFUNC(SEL_BEGINDRAG,0,FXFileList::onBeginDrag),
FXMAPFUNC(SEL_DRAGGED,0,FXFileList::onDragged),
FXMAPFUNC(SEL_ENDDRAG,0,FXFileList::onEndDrag),
FXMAPFUNC(SEL_CLIPBOARD_LOST,0,FXFileList::onClipboardLost),
FXMAPFUNC(SEL_CLIPBOARD_REQUEST,0,FXFileList::onClipboardRequest),
FXMAPFUNC(SEL_CHORE,FXFileList::ID_PREVIEWCHORE,FXFileList::onPreviewChore),
FXMAPFUNC(SEL_TIMEOUT,FXFileList::ID_OPENTIMER,FXFileList::onOpenTimer),
FXMAPFUNC(SEL_TIMEOUT,FXFileList::ID_REFRESHTIMER,FXFileList::onRefreshTimer),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_DIRECTORY_UP,FXFileList::onUpdDirectoryUp),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_SORT_BY_NAME,FXFileList::onUpdSortByName),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_SORT_BY_TYPE,FXFileList::onUpdSortByType),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_SORT_BY_SIZE,FXFileList::onUpdSortBySize),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_SORT_BY_TIME,FXFileList::onUpdSortByTime),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_SORT_BY_USER,FXFileList::onUpdSortByUser),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_SORT_BY_GROUP,FXFileList::onUpdSortByGroup),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_SORT_REVERSE,FXFileList::onUpdSortReverse),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_SORT_CASE,FXFileList::onUpdSortCase),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_SET_PATTERN,FXFileList::onUpdSetPattern),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_SET_DIRECTORY,FXFileList::onUpdSetDirectory),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_SHOW_HIDDEN,FXFileList::onUpdShowHidden),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_HIDE_HIDDEN,FXFileList::onUpdHideHidden),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_TOGGLE_HIDDEN,FXFileList::onUpdToggleHidden),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_TOGGLE_IMAGES,FXFileList::onUpdToggleImages),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_HEADER,FXFileList::onUpdHeader),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_CUT_SEL,FXFileList::onUpdHaveSel),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_COPY_SEL,FXFileList::onUpdHaveSel),
FXMAPFUNC(SEL_UPDATE,FXFileList::ID_DELETE_SEL,FXFileList::onUpdHaveSel),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_HEADER,FXFileList::onCmdHeader),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_DIRECTORY_UP,FXFileList::onCmdDirectoryUp),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SORT_BY_NAME,FXFileList::onCmdSortByName),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SORT_BY_TYPE,FXFileList::onCmdSortByType),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SORT_BY_SIZE,FXFileList::onCmdSortBySize),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SORT_BY_TIME,FXFileList::onCmdSortByTime),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SORT_BY_USER,FXFileList::onCmdSortByUser),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SORT_BY_GROUP,FXFileList::onCmdSortByGroup),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SORT_REVERSE,FXFileList::onCmdSortReverse),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SORT_CASE,FXFileList::onCmdSortCase),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SET_PATTERN,FXFileList::onCmdSetPattern),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SET_DIRECTORY,FXFileList::onCmdSetDirectory),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SETVALUE,FXFileList::onCmdSetValue),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SETSTRINGVALUE,FXFileList::onCmdSetStringValue),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_GETSTRINGVALUE,FXFileList::onCmdGetStringValue),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_SHOW_HIDDEN,FXFileList::onCmdShowHidden),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_HIDE_HIDDEN,FXFileList::onCmdHideHidden),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_TOGGLE_HIDDEN,FXFileList::onCmdToggleHidden),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_TOGGLE_IMAGES,FXFileList::onCmdToggleImages),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_REFRESH,FXFileList::onCmdRefresh),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_CUT_SEL,FXFileList::onCmdCutSel),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_COPY_SEL,FXFileList::onCmdCopySel),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_DELETE_SEL,FXFileList::onCmdDeleteSel),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_PASTE_SEL,FXFileList::onCmdPasteSel),
FXMAPFUNC(SEL_CHORE,FXFileList::ID_DROPASK,FXFileList::onCmdDropAsk),
FXMAPFUNC(SEL_CHORE,FXFileList::ID_DROPCOPY,FXFileList::onCmdDropCopy),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_DROPCOPY,FXFileList::onCmdDropCopy),
FXMAPFUNC(SEL_CHORE,FXFileList::ID_DROPMOVE,FXFileList::onCmdDropMove),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_DROPMOVE,FXFileList::onCmdDropMove),
FXMAPFUNC(SEL_CHORE,FXFileList::ID_DROPLINK,FXFileList::onCmdDropLink),
FXMAPFUNC(SEL_COMMAND,FXFileList::ID_DROPLINK,FXFileList::onCmdDropLink),
};
// Object implementation
FXIMPLEMENT(FXFileList,FXIconList,FXFileListMap,ARRAYNUMBER(FXFileListMap))
// For serialization
FXFileList::FXFileList(){
dropEnable();
associations=nullptr;
iconloader=nullptr;
list=nullptr;
big_folder=nullptr;
mini_folder=nullptr;
big_doc=nullptr;
mini_doc=nullptr;
big_app=nullptr;
mini_app=nullptr;
#ifdef WIN32
matchmode=FXPath::PathName|FXPath::NoEscape|FXPath::CaseFold;
setSortFunc(ascendingCase);
#else
matchmode=FXPath::PathName|FXPath::NoEscape;
setSortFunc(ascending);
#endif
dropaction=DRAG_COPY;
matchmode=0;
imagesize=32;
timestamp=0;
counter=0;
clipcut=false;
draggable=true;
}
// File List
FXFileList::FXFileList(FXComposite *p,FXObject* tgt,FXSelector sel,FXuint opts,FXint x,FXint y,FXint w,FXint h):FXIconList(p,tgt,sel,opts,x,y,w,h),directory(PATHSEPSTRING),pattern("*"){
dropEnable();
appendHeader(tr("Name\tName"),nullptr,200);
appendHeader(tr("Type\tFile type"),nullptr,100);
appendHeader(tr("Size\tFile size"),nullptr,60);
appendHeader(tr("Modified Date\tDate when last modified"),nullptr,150);
appendHeader(tr("User\tUser name"),nullptr,50);
appendHeader(tr("Group\tGroup name"),nullptr,50);
appendHeader(tr("Attributes\tFile attributes"),nullptr,100);
#ifndef WIN32
appendHeader(tr("Link\tSymbolic link to"),nullptr,200);
#endif
associations=nullptr;
if(!(options&FILELIST_NO_OWN_ASSOC)) associations=new FXFileAssociations(getApp());
iconloader=&FXIconSource::defaultIconSource;
list=nullptr;
big_folder=new FXGIFIcon(getApp(),bigfolder);
mini_folder=new FXGIFIcon(getApp(),minifolder);
big_doc=new FXGIFIcon(getApp(),bigdoc);
mini_doc=new FXGIFIcon(getApp(),minidoc);
big_app=new FXGIFIcon(getApp(),bigapp);
mini_app=new FXGIFIcon(getApp(),miniapp);
timeformat=tr(FXSystem::defaultTimeFormat);
dropaction=DRAG_COPY;
#ifdef WIN32
matchmode=FXPath::PathName|FXPath::NoEscape|FXPath::CaseFold;
setSortFunc(ascendingCase);
#else
matchmode=FXPath::PathName|FXPath::NoEscape;
setSortFunc(ascending);
#endif
imagesize=32;
timestamp=0;
counter=0;
clipcut=false;
draggable=true;
}
// Starts the timer
void FXFileList::create(){
FXIconList::create();
getApp()->addTimeout(this,ID_REFRESHTIMER,REFRESHINTERVAL);
big_folder->create();
mini_folder->create();
big_doc->create();
mini_doc->create();
big_app->create();
mini_app->create();
}
// Detach disconnects the icons
void FXFileList::detach(){
FXIconList::detach();
getApp()->removeTimeout(this,ID_REFRESHTIMER);
getApp()->removeTimeout(this,ID_OPENTIMER);
big_folder->detach();
mini_folder->detach();
big_doc->detach();
mini_doc->detach();
big_app->detach();
mini_app->detach();
deleteType=0;
urilistType=0;
actionType=0;
}
// Destroy zaps the icons
void FXFileList::destroy(){
FXIconList::destroy();
getApp()->removeTimeout(this,ID_REFRESHTIMER);
getApp()->removeTimeout(this,ID_OPENTIMER);
big_folder->destroy();
mini_folder->destroy();
big_doc->destroy();
mini_doc->destroy();
big_app->destroy();
mini_app->destroy();
}
// Create custom item
FXIconItem *FXFileList::createItem(const FXString& text,FXIcon *big,FXIcon* mini,void* ptr){
return new FXFileItem(text,big,mini,ptr);
}
/*******************************************************************************/
// Compare string and string with natural interpretation of decimal numbers
FXint FXFileList::compareSectionNatural(const FXchar* s1,const FXchar* s2,FXint s,FXbool ci){
const FXchar *ns1,*ne1,*ns2,*ne2;
FXint diff=0,c1=0,c2=0,d;
for(d=s; d && *s1; d-=(*s1++=='\t')){}
for(d=s; d && *s2; d-=(*s2++=='\t')){}
while((c1=(FXuchar)*s1)>=' ' && (c2=(FXuchar)*s2)>=' '){
// Both are numbers: special treatment
if(c1<='9' && c2<='9' && '0'<=c1 && '0'<=c2){
// Parse over leading zeroes
for(ns1=s1; *ns1=='0'; ++ns1){ }
for(ns2=s2; *ns2=='0'; ++ns2){ }
// Use number of leading zeroes as tie-breaker
if(diff==0){ diff=(ns1-s1)-(ns2-s2); }
// Parse over numbers
for(ne1=ns1; '0'<=*ne1 && *ne1<='9'; ++ne1){ }
for(ne2=ns2; '0'<=*ne2 && *ne2<='9'; ++ne2){ }
// Check length difference of the numbers
if((d=(ne1-ns1)-(ne2-ns2))!=0){ return d; }
// Compare the numbers
while(ns1<ne1){
if((d=*ns1++ - *ns2++)!=0){ return d; }
}
// Continue with the rest
s1=ne1;
s2=ne2;
continue;
}
// Get lower case
if(ci){
c1=Ascii::toLower(c1);
c2=Ascii::toLower(c2);
}
// Characters differ
if(c1!=c2){ return c1-c2; }
// Advance
s1++;
s2++;
}
if(c1<' ') c1=0;
if(c2<' ') c2=0;
// Characters differ
if(c1!=c2){ return c1-c2; }
// Use tie-breaker
return diff;
}
// Compare file names
FXint FXFileList::ascending(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=compareSectionNatural(a->label.text(),b->label.text(),0,false);
}
return diff;
}
// Reversed compare file name
FXint FXFileList::descending(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=compareSectionNatural(b->label.text(),a->label.text(),0,false);
}
return diff;
}
// Compare file names, case insensitive
FXint FXFileList::ascendingCase(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=compareSectionNatural(a->label.text(),b->label.text(),0,true);
}
return diff;
}
// Reversed compare file name, case insensitive
FXint FXFileList::descendingCase(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=compareSectionNatural(b->label.text(),a->label.text(),0,true);
}
return diff;
}
// Compare file types
FXint FXFileList::ascendingType(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=compareSection(a->label.text(),b->label.text(),1);
if(diff==0){
diff=compareSection(a->label.text(),b->label.text(),0);
}
}
return diff;
}
// Reversed compare file type
FXint FXFileList::descendingType(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=compareSection(b->label.text(),a->label.text(),1);
if(diff==0){
diff=compareSection(b->label.text(),a->label.text(),0);
}
}
return diff;
}
// Compare file size
FXint FXFileList::ascendingSize(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=FXSGNZ(static_cast<const FXFileItem*>(a)->size - static_cast<const FXFileItem*>(b)->size);
if(diff==0){
diff=compareSection(a->label.text(),b->label.text(),0);
}
}
return diff;
}
// Reversed compare file size
FXint FXFileList::descendingSize(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=FXSGNZ(static_cast<const FXFileItem*>(b)->size - static_cast<const FXFileItem*>(a)->size);
if(diff==0){
diff=compareSection(b->label.text(),a->label.text(),0);
}
}
return diff;
}
// Compare file time
FXint FXFileList::ascendingTime(const FXIconItem* a,const FXIconItem* b){
FXint diff=(FXint)((const FXFileItem*)b)->isDirectory() - (FXint)((const FXFileItem*)a)->isDirectory();
if(diff==0){
diff=FXSGNZ(static_cast<const FXFileItem*>(a)->date - static_cast<const FXFileItem*>(b)->date);
if(diff==0){
diff=compareSection(a->label.text(),b->label.text(),0);
}
}
return diff;
}
// Reversed compare file time
FXint FXFileList::descendingTime(const FXIconItem* a,const FXIconItem* b){
FXint diff=(FXint)((const FXFileItem*)b)->isDirectory() - (FXint)((const FXFileItem*)a)->isDirectory();
if(diff==0){
diff=FXSGNZ(static_cast<const FXFileItem*>(b)->date - static_cast<const FXFileItem*>(a)->date);
if(diff==0){
diff=compareSection(b->label.text(),a->label.text(),0);
}
}
return diff;
}
// Compare file user
FXint FXFileList::ascendingUser(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=compareSection(a->label.text(),b->label.text(),4);
if(diff==0){
diff=compareSection(a->label.text(),b->label.text(),0);
}
}
return diff;
}
// Reversed compare file user
FXint FXFileList::descendingUser(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=compareSection(b->label.text(),a->label.text(),4);
if(diff==0){
diff=compareSection(b->label.text(),a->label.text(),0);
}
}
return diff;
}
// Compare file group
FXint FXFileList::ascendingGroup(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=compareSection(a->label.text(),b->label.text(),5);
if(diff==0){
diff=compareSection(a->label.text(),b->label.text(),0);
}
}
return diff;
}
// Reversed compare file group
FXint FXFileList::descendingGroup(const FXIconItem* a,const FXIconItem* b){
FXint diff=static_cast<const FXFileItem*>(b)->isDirectory() - static_cast<const FXFileItem*>(a)->isDirectory();
if(diff==0){
diff=compareSection(b->label.text(),a->label.text(),5);
if(diff==0){
diff=compareSection(b->label.text(),a->label.text(),0);
}
}
return diff;
}
/*******************************************************************************/
// Select files matching wildcard pattern
FXbool FXFileList::selectMatching(const FXString& ptrn,FXuint mode,FXbool notify){
FXbool changes=false;
for(FXint i=0; i<getNumItems(); i++){
if(!isItemNavigational(i) && FXPath::match(getItemFilename(i),ptrn,mode)){
changes|=selectItem(i,notify);
}
}
return changes;
}
// Return uri-list of selected files
FXString FXFileList::getSelectedFiles() const {
FXString result;
for(FXint i=0; i<getNumItems(); i++){
if(!isItemNavigational(i) && isItemSelected(i)){
result.append(FXURL::fileToURL(getItemPathname(i)));
result.append("\r\n");
}
}
return result;
}
// Update if we have selection
long FXFileList::onUpdHaveSel(FXObject* sender,FXSelector,void*){
for(FXint i=0; i<getNumItems(); i++){
if(!isItemNavigational(i) && isItemSelected(i)){
sender->handle(this,FXSEL(SEL_COMMAND,ID_ENABLE),nullptr);
return 1;
}
}
sender->handle(this,FXSEL(SEL_COMMAND,ID_DISABLE),nullptr);
return 1;
}
/*******************************************************************************/
// Delete selection
long FXFileList::onCmdDeleteSel(FXObject*,FXSelector,void*){
FXString delfiles=getSelectedFiles();
delete_files(delfiles); // FIXME confirmation would be nice
return 1;
}
// Paste clipboard
long FXFileList::onCmdPasteSel(FXObject*,FXSelector,void*){
FXString files,action;
if(getDNDData(FROM_CLIPBOARD,urilistType,files)){
if(getDNDData(FROM_CLIPBOARD,actionType,action)){
FXTRACE((100,"%s::onCmdPasteSel(): Action: %s Files: %s\n",getClassName(),action.text(),files.text()));
if(action[0]=='1'){
move_files(directory,files);
}
else{
// FXint count=files.contains("\r\n");
// FXTRACE((1,"number of files=%d\n",count));
//FXFileProgressDialog fileprogress(this,"Copying Files","Copying 10 files (100MB)",big_folder,DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE,0,0,600,0);
//fileprogress.execute();
copy_files(directory,files);
}
return 1;
}
}
getApp()->beep();
return 1;
}
// Cut
long FXFileList::onCmdCutSel(FXObject*,FXSelector,void*){
FXDragType types[2]={urilistType,actionType};
if(acquireClipboard(types,ARRAYNUMBER(types))){
clipfiles=getSelectedFiles();
clipcut=true;
}
return 1;
}
// Copy
long FXFileList::onCmdCopySel(FXObject*,FXSelector,void*){
FXDragType types[2]={urilistType,actionType};
if(acquireClipboard(types,ARRAYNUMBER(types))){
clipfiles=getSelectedFiles();
clipcut=false;
}
return 1;
}
// We lost the selection somehow
long FXFileList::onClipboardLost(FXObject* sender,FXSelector sel,void* ptr){
FXIconList::onClipboardLost(sender,sel,ptr);
FXTRACE((100,"deleting clipfiles\n"));
clipfiles=FXString::null;
clipcut=false;
return 1;
}
// Somebody wants our selection
long FXFileList::onClipboardRequest(FXObject* sender,FXSelector sel,void* ptr){
// Try base class first
if(FXIconList::onClipboardRequest(sender,sel,ptr)) return 1;
// Return list of filenames as a uri-list
if(((FXEvent*)ptr)->target==urilistType){
FXTRACE((100,"Returning urilistType\n"));
setDNDData(FROM_CLIPBOARD,urilistType,clipfiles);
return 1;
}
// Return type of clipboard action
if(((FXEvent*)ptr)->target==actionType){
FXTRACE((100,"Returning actionType\n"));
setDNDData(FROM_CLIPBOARD,actionType,clipcut?"1":"0");
return 1;
}
return 0;
}
/*******************************************************************************/
// Delete files from the systems
void FXFileList::delete_files(const FXString& files){
FXString filename;
FXint beg,end;
for(beg=0; beg<files.length(); beg=end+2){
if((end=files.find_first_of("\r\n",beg))<0) end=files.length();
filename=FXURL::fileFromURL(files.mid(beg,end-beg));
if(!FXFile::removeFiles(filename,true)){
if(FXMessageBox::question(this,MBOX_OK_CANCEL,tr("Failed Deleting Files"),tr("Failed to delete file: %s; continue?"),filename.text())==MBOX_CLICKED_CANCEL) break;
}
}
}
// Copy files to directory
void FXFileList::copy_files(const FXString& dir,const FXString& files){
FXString filedst,filesrc;
FXuint answer=0;
FXint beg,end;
FXbool ok;
for(beg=0; beg<files.length(); beg=end+2){
if((end=files.find_first_of("\r\n",beg))<0) end=files.length();
filesrc=FXURL::fileFromURL(files.mid(beg,end-beg));
filedst=FXPath::absolute(dir,FXPath::name(filesrc));
ok=FXFile::copyFiles(filesrc,filedst,(answer==MBOX_CLICKED_YESALL));
if(!ok){
if(answer==MBOX_CLICKED_NOALL) continue;
if(answer!=MBOX_CLICKED_YESALL){
answer=FXMessageBox::question(this,MBOX_YES_YESALL_NO_NOALL_CANCEL,tr("Overwrite File"),tr("Overwrite existing file or directory: %s?"),filedst.text());
if(answer==MBOX_CLICKED_CANCEL) break;
if(answer==MBOX_CLICKED_NO) continue;
if(answer==MBOX_CLICKED_NOALL) continue;
ok=FXFile::copyFiles(filesrc,filedst,true);
}
if(!ok){
if(FXMessageBox::question(this,MBOX_OK_CANCEL,tr("Failed Copying File"),tr("Failed to overwrite file: %s; continue?"),filedst.text())==MBOX_CLICKED_OK) continue;
break;
}
}
}
}
// Move files to directory
void FXFileList::move_files(const FXString& dir,const FXString& files){
FXString filedst,filesrc;
FXuint answer=0;
FXint beg,end;
FXbool ok;
for(beg=0; beg<files.length(); beg=end+2){
if((end=files.find_first_of("\r\n",beg))<0) end=files.length();
filesrc=FXURL::fileFromURL(files.mid(beg,end-beg));
filedst=FXPath::absolute(dir,FXPath::name(filesrc));
ok=FXFile::moveFiles(filesrc,filedst,(answer==MBOX_CLICKED_YESALL));
if(!ok){
if(answer==MBOX_CLICKED_NOALL) continue;
if(answer!=MBOX_CLICKED_YESALL){
answer=FXMessageBox::question(this,MBOX_YES_YESALL_NO_NOALL_CANCEL,tr("Overwrite File"),tr("Overwrite existing file or directory: %s?"),filedst.text());
if(answer==MBOX_CLICKED_CANCEL) break;
if(answer==MBOX_CLICKED_NO) continue;
if(answer==MBOX_CLICKED_NOALL) continue;
ok=FXFile::moveFiles(filesrc,filedst,true);
}
if(!ok){
if(FXMessageBox::question(this,MBOX_OK_CANCEL,tr("Failed Moving File"),tr("Failed to overwrite file: %s; continue?"),filedst.text())==MBOX_CLICKED_OK) continue;
break;
}
}
}
}
#if 0
FXProgressDialog progress(this,tr("Copying Files"),FXString::null,PROGRESSDIALOG_NORMAL|PROGRESSDIALOG_CANCEL,0,0,520,0);
FXuint ans=MBOX_CLICKED_NO;
FXString filedst,filesrc;
FXint beg,end,ok;
progress.create();
progress.show(PLACEMENT_CURSOR);
progress.setTotal(dropfiles.contains("\r\n"));
progress.setProgress(0);
getApp()->flush();
getApp()->runModalWhileEvents(&progress,500000000);
getApp()->flush();
for(beg=0; beg<files.length(); beg=end+2){
if(progress.isCancelled()) break;
if((end=files.find_first_of("\r\n",beg))<0) end=files.length();
filesrc=FXURL::fileFromURL(files.mid(beg,end-beg));
filedst=FXPath::absolute(directory,FXPath::name(filesrc));
progress.setMessage(tr("Copying file:\n\n")+filesrc);
progress.increment(1);
getApp()->flush();
getApp()->runModalWhileEvents(&progress,500000000);
FXThread::sleep(100000000);
// FXFile::copyFiles(filesrc,filedst,false);
/*
ok=FXFile::copyFiles(filesrc,filedst,(ans==MBOX_CLICKED_YESALL));
if(!ok && (ans!=MBOX_CLICKED_NOALL)){
if(ans!=MBOX_CLICKED_YESALL && ans!=MBOX_CLICKED_NOALL){
ans=FXMessageBox::question(this,MBOX_YES_YESALL_NO_NOALL_CANCEL,tr("Overwrite File"),tr("Overwrite existing file or directory: %s?"),filedst.text());
if(ans==MBOX_CLICKED_CANCEL) break;
if((ans==MBOX_CLICKED_YESALL) || (ans==MBOX_CLICKED_YES)){
ok=FXFile::copyFiles(filesrc,filedst,true);
}
}
}
*/
}
#endif
/*******************************************************************************/
// Copy files to drop directory
long FXFileList::onCmdDropCopy(FXObject*,FXSelector,void*){
copy_files(dropdirectory,dropfiles);
dropdirectory=FXString::null;
dropfiles=FXString::null;
dropaction=DRAG_REJECT;
return 1;
}
// Move files to drop directory
long FXFileList::onCmdDropMove(FXObject*,FXSelector,void*){
move_files(dropdirectory,dropfiles);
dropdirectory=FXString::null;
dropfiles=FXString::null;
dropaction=DRAG_REJECT;
return 1;
}
// Link to files from dropdirectory
long FXFileList::onCmdDropLink(FXObject*,FXSelector,void*){
FXString filedst,filesrc; FXint beg,end;
for(beg=0; beg<dropfiles.length(); beg=end+2){
if((end=dropfiles.find_first_of("\r\n",beg))<0) end=dropfiles.length();
filesrc=FXURL::fileFromURL(dropfiles.mid(beg,end-beg));
filedst=FXPath::absolute(dropdirectory,FXPath::name(filesrc));
if(!FXFile::symlink(filesrc,filedst)){
if(FXMessageBox::question(this,MBOX_OK_CANCEL,tr("Failed Linking File"),tr("Failed to make symbolic link from: %s; continue?"),filedst.text())==MBOX_CLICKED_CANCEL) break;
}
}
dropdirectory=FXString::null;
dropfiles=FXString::null;
dropaction=DRAG_REJECT;
return 1;
}
// Deal with the drop that has just occurred
long FXFileList::onCmdDropAsk(FXObject*,FXSelector,void* ptr){
FXMenuPane dropmenu(this);
FXGIFIcon filemoveicon(getApp(),filemove);
FXGIFIcon filecopyicon(getApp(),filecopy);
FXGIFIcon filelinkicon(getApp(),filelink);
FXGIFIcon filecancelicon(getApp(),filecancel);
new FXMenuCommand(&dropmenu,tr("Move Here"),&filemoveicon,this,ID_DROPMOVE);
new FXMenuCommand(&dropmenu,tr("Copy Here"),&filecopyicon,this,ID_DROPCOPY);
new FXMenuCommand(&dropmenu,tr("Link Here"),&filelinkicon,this,ID_DROPLINK);
new FXMenuSeparator(&dropmenu);
new FXMenuCommand(&dropmenu,tr("Cancel"),&filecancelicon);
dropmenu.create();
dropmenu.popup(nullptr,((FXEvent*)ptr)->root_x,((FXEvent*)ptr)->root_y);
getApp()->runModalWhileShown(&dropmenu);
dropdirectory=FXString::null;
dropfiles=FXString::null;
dropaction=DRAG_REJECT;
return 1;
}
/*******************************************************************************/
// Change directory when hovering over a folder
// Remember current directory prior to change
long FXFileList::onOpenTimer(FXObject*,FXSelector,void*){
FXint xx,yy,index; FXuint buttons;
getCursorPosition(xx,yy,buttons);
index=getItemAt(xx,yy);
if(0<=index && isItemDirectory(index)){
if(startdirectory.empty()){ startdirectory=getDirectory(); }
dropdirectory=getItemPathname(index);
setDirectory(dropdirectory,true);
}
return 1;
}
// Handle drag-and-drop enter, remember current directory
long FXFileList::onDNDEnter(FXObject* sender,FXSelector sel,void* ptr){
FXIconList::onDNDEnter(sender,sel,ptr);
return 1;
}
// Handle drag-and-drop leave
// Restore current directory and scroll position prior drag
long FXFileList::onDNDLeave(FXObject* sender,FXSelector sel,void* ptr){
FXIconList::onDNDLeave(sender,sel,ptr);
getApp()->removeTimeout(this,ID_OPENTIMER);
stopAutoScroll();
if(!startdirectory.empty()){
setDirectory(startdirectory,true);
startdirectory=FXString::null;
}
dropdirectory=FXString::null;
dropfiles=FXString::null;
dropaction=DRAG_REJECT;
return 1;
}
// Handle drag-and-drop motion
long FXFileList::onDNDMotion(FXObject* sender,FXSelector sel,void* ptr){
FXEvent *event=(FXEvent*)ptr;
FXint index=-1;
// Cancel open up timer
getApp()->removeTimeout(this,ID_OPENTIMER);
// Start autoscrolling
if(startAutoScroll(event,false)) return 1;
// Give base class a shot
if(FXIconList::onDNDMotion(sender,sel,ptr)) return 1;
// Dropping list of filenames
if(offeredDNDType(FROM_DRAGNDROP,urilistType)){
// Drop in the background
dropdirectory=getDirectory();
// Drop action to be performed
dropaction=inquireDNDAction();
// We will open up a folder if we can hover over it for a while
index=getItemAt(event->win_x,event->win_y);
if(0<=index && isItemDirectory(index)){
// Start open up timer when hovering over item
getApp()->addTimeout(this,ID_OPENTIMER,OPENDIRDELAY);
// Directory where to drop, or directory to open up
dropdirectory=getItemPathname(index);
}
// See if dropdirectory is writable
if(FXStat::isAccessible(dropdirectory,FXIO::ReadOnly|FXIO::WriteOnly)){
acceptDrop(DRAG_ACCEPT);
}
return 1;
}
return 0;
}
// Handle drag-and-drop drop
long FXFileList::onDNDDrop(FXObject* sender,FXSelector sel,void* ptr){
// Cancel open up timer
getApp()->removeTimeout(this,ID_OPENTIMER);
// Stop scrolling
stopAutoScroll();
// Restore start directory and scroll position
if(!startdirectory.empty()){
setDirectory(startdirectory,true);
startdirectory=FXString::null;
}
// Perhaps target wants to deal with it
if(FXIconList::onDNDDrop(sender,sel,ptr)) return 1;
// Get list of files as uri-list
if(getDNDData(FROM_DRAGNDROP,urilistType,dropfiles)){
if(!dropfiles.empty()){
switch(dropaction){
case DRAG_COPY:
getApp()->addChore(this,ID_DROPCOPY,ptr);
break;
case DRAG_MOVE:
getApp()->addChore(this,ID_DROPMOVE,ptr);
break;
case DRAG_LINK:
getApp()->addChore(this,ID_DROPLINK,ptr);
break;
default:
getApp()->addChore(this,ID_DROPASK,ptr);
break;
}
return 1;
}
}
return 0;
}
// Somebody wants our dragged data
long FXFileList::onDNDRequest(FXObject* sender,FXSelector sel,void* ptr){
// Perhaps the target wants to supply its own data
if(FXIconList::onDNDRequest(sender,sel,ptr)) return 1;
// Return list of filenames as a uri-list
if(((FXEvent*)ptr)->target==urilistType){
setDNDData(FROM_DRAGNDROP,urilistType,dragfiles);
return 1;
}
// Delete selected files
if(((FXEvent*)ptr)->target==deleteType){
FXTRACE((100,"Delete files not yet implemented\n"));
return 1;
}
return 0;
}
// Start a drag operation
long FXFileList::onBeginDrag(FXObject* sender,FXSelector sel,void* ptr){
if(!FXIconList::onBeginDrag(sender,sel,ptr)){
beginDrag(&urilistType,1);
dragfiles=getSelectedFiles();
}
return 1;
}
// Dragged stuff around
long FXFileList::onDragged(FXObject* sender,FXSelector sel,void* ptr){
FXEvent* event=(FXEvent*)ptr;
if(!FXIconList::onDragged(sender,sel,ptr)){
FXDragAction action=DRAG_ASK;
if(event->state&CONTROLMASK) action=DRAG_COPY;
if(event->state&SHIFTMASK) action=DRAG_MOVE;
if(event->state&ALTMASK) action=DRAG_LINK;
handleDrag(event->root_x,event->root_y,action);
action=didAccept();
switch(action){
case DRAG_COPY:
setDragCursor(getApp()->getDefaultCursor(DEF_DNDCOPY_CURSOR));
break;
case DRAG_MOVE:
setDragCursor(getApp()->getDefaultCursor(DEF_DNDMOVE_CURSOR));
break;
case DRAG_LINK:
setDragCursor(getApp()->getDefaultCursor(DEF_DNDLINK_CURSOR));
break;
case DRAG_ASK:
setDragCursor(getApp()->getDefaultCursor(DEF_DNDASK_CURSOR));
break;
default:
setDragCursor(getApp()->getDefaultCursor(DEF_DNDSTOP_CURSOR));
break;
}
}
return 1;
}
// End drag operation
long FXFileList::onEndDrag(FXObject* sender,FXSelector sel,void* ptr){
if(!FXIconList::onEndDrag(sender,sel,ptr)){
endDrag((didAccept()!=DRAG_REJECT));
setDragCursor(getDefaultCursor());
dragfiles=FXString::null;
}
return 1;
}
/*******************************************************************************/
// Cycle through items that represent images
long FXFileList::onPreviewChore(FXObject*,FXSelector,void* ptr){
FXint index=(FXint)(FXival)ptr;
if(showImages() && iconloader && index<getNumItems()){
FXIcon *icon=iconloader->loadScaledIconFile(getApp(),getItemPathname(index),imagesize);
if(icon){
icon->create();
setItemBigIcon(index,icon,true);
setItemMiniIcon(index,icon,false);
}
if(++index<getNumItems()){
getApp()->addChore(this,ID_PREVIEWCHORE,(void*)(FXival)index);
}
}
return 1;
}
/*******************************************************************************/
// Set value from a message
long FXFileList::onCmdSetValue(FXObject*,FXSelector,void* ptr){
setCurrentFile((const FXchar*)ptr,true);
return 1;
}
// Set current directory from dir part of filename
long FXFileList::onCmdSetStringValue(FXObject*,FXSelector,void* ptr){
setCurrentFile(*((FXString*)ptr),true);
return 1;
}
// Get current file name (NULL if no current file)
long FXFileList::onCmdGetStringValue(FXObject*,FXSelector,void* ptr){
*((FXString*)ptr)=getCurrentFile();
return 1;
}
// Toggle hidden files display
long FXFileList::onCmdToggleHidden(FXObject*,FXSelector,void*){
showHiddenFiles(!showHiddenFiles(),true);
return 1;
}
// Update toggle hidden files widget
long FXFileList::onUpdToggleHidden(FXObject* sender,FXSelector,void*){
sender->handle(this,showHiddenFiles()?FXSEL(SEL_COMMAND,ID_CHECK):FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Show hidden files
long FXFileList::onCmdShowHidden(FXObject*,FXSelector,void*){
showHiddenFiles(true,true);
return 1;
}
// Update show hidden files widget
long FXFileList::onUpdShowHidden(FXObject* sender,FXSelector,void*){
sender->handle(this,showHiddenFiles()?FXSEL(SEL_COMMAND,ID_CHECK):FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Hide hidden files
long FXFileList::onCmdHideHidden(FXObject*,FXSelector,void*){
showHiddenFiles(false,true);
return 1;
}
// Update hide hidden files widget
long FXFileList::onUpdHideHidden(FXObject* sender,FXSelector,void*){
sender->handle(this,showHiddenFiles()?FXSEL(SEL_COMMAND,ID_UNCHECK):FXSEL(SEL_COMMAND,ID_CHECK),nullptr);
return 1;
}
// Toggle image preview
long FXFileList::onCmdToggleImages(FXObject*,FXSelector,void*){
showImages(!showImages(),true);
return 1;
}
// Update image preview
long FXFileList::onUpdToggleImages(FXObject* sender,FXSelector,void*){
sender->handle(this,showImages()?FXSEL(SEL_COMMAND,ID_CHECK):FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Move up one level
long FXFileList::onCmdDirectoryUp(FXObject*,FXSelector,void*){
setDirectory(FXPath::upLevel(directory),true);
return 1;
}
// Determine if we can still go up more
long FXFileList::onUpdDirectoryUp(FXObject* sender,FXSelector,void*){
sender->handle(this,FXPath::isTopDirectory(directory)?FXSEL(SEL_COMMAND,ID_DISABLE):FXSEL(SEL_COMMAND,ID_ENABLE),nullptr);
return 1;
}
// Change pattern
long FXFileList::onCmdSetPattern(FXObject*,FXSelector,void* ptr){
setPattern((const char*)ptr,true);
return 1;
}
// Update pattern
long FXFileList::onUpdSetPattern(FXObject* sender,FXSelector,void*){
sender->handle(this,FXSEL(SEL_COMMAND,FXWindow::ID_SETVALUE),(void*)pattern.text());
return 1;
}
// Change directory
long FXFileList::onCmdSetDirectory(FXObject*,FXSelector,void* ptr){
setDirectory((const char*)ptr,true);
return 1;
}
// Update directory
long FXFileList::onUpdSetDirectory(FXObject* sender,FXSelector,void*){
sender->handle(this,FXSEL(SEL_COMMAND,FXWindow::ID_SETVALUE),(void*)directory.text());
return 1;
}
// Sort by name
long FXFileList::onCmdSortByName(FXObject*,FXSelector,void*){
#ifdef WIN32
if(getSortFunc()==ascending) setSortFunc(descending);
else if(getSortFunc()==ascendingCase) setSortFunc(descendingCase);
else if(getSortFunc()==descending) setSortFunc(ascending);
else setSortFunc(ascendingCase);
#else
if(getSortFunc()==ascending) setSortFunc(descending);
else if(getSortFunc()==ascendingCase) setSortFunc(descendingCase);
else if(getSortFunc()==descending) setSortFunc(ascending);
else setSortFunc(ascending);
#endif
sortItems();
return 1;
}
// Update sender
long FXFileList::onUpdSortByName(FXObject* sender,FXSelector,void*){
sender->handle(this,(getSortFunc()==ascending || getSortFunc()==descending || getSortFunc()==ascendingCase || getSortFunc()==descendingCase) ? FXSEL(SEL_COMMAND,ID_CHECK) : FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Sort by type
long FXFileList::onCmdSortByType(FXObject*,FXSelector,void*){
setSortFunc((getSortFunc()==ascendingType) ? descendingType : ascendingType);
sortItems();
return 1;
}
// Update sender
long FXFileList::onUpdSortByType(FXObject* sender,FXSelector,void*){
sender->handle(this,(getSortFunc()==ascendingType || getSortFunc()==descendingType) ? FXSEL(SEL_COMMAND,ID_CHECK) : FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Sort by size
long FXFileList::onCmdSortBySize(FXObject*,FXSelector,void*){
setSortFunc((getSortFunc()==ascendingSize) ? descendingSize : ascendingSize);
sortItems();
return 1;
}
// Update sender
long FXFileList::onUpdSortBySize(FXObject* sender,FXSelector,void*){
sender->handle(this,(getSortFunc()==ascendingSize || getSortFunc()==descendingSize) ? FXSEL(SEL_COMMAND,ID_CHECK) : FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Sort by time
long FXFileList::onCmdSortByTime(FXObject*,FXSelector,void*){
setSortFunc((getSortFunc()==ascendingTime) ? descendingTime : ascendingTime);
sortItems();
return 1;
}
// Update sender
long FXFileList::onUpdSortByTime(FXObject* sender,FXSelector,void*){
sender->handle(this,(getSortFunc()==ascendingTime || getSortFunc()==descendingTime) ? FXSEL(SEL_COMMAND,ID_CHECK) : FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Sort by user
long FXFileList::onCmdSortByUser(FXObject*,FXSelector,void*){
setSortFunc((getSortFunc()==ascendingUser) ? descendingUser : ascendingUser);
sortItems();
return 1;
}
// Update sender
long FXFileList::onUpdSortByUser(FXObject* sender,FXSelector,void*){
sender->handle(this,(getSortFunc()==ascendingUser || getSortFunc()==descendingUser) ? FXSEL(SEL_COMMAND,ID_CHECK) : FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Sort by group
long FXFileList::onCmdSortByGroup(FXObject*,FXSelector,void*){
setSortFunc((getSortFunc()==ascendingGroup) ? descendingGroup : ascendingGroup);
sortItems();
return 1;
}
// Update sender
long FXFileList::onUpdSortByGroup(FXObject* sender,FXSelector,void*){
sender->handle(this,(getSortFunc()==ascendingGroup || getSortFunc()==descendingGroup) ? FXSEL(SEL_COMMAND,ID_CHECK) : FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
return 1;
}
// Reverse sort order
long FXFileList::onCmdSortReverse(FXObject*,FXSelector,void*){
if(getSortFunc()==ascending) setSortFunc(descending);
else if(getSortFunc()==descending) setSortFunc(ascending);
else if(getSortFunc()==ascendingCase) setSortFunc(descendingCase);
else if(getSortFunc()==descendingCase) setSortFunc(ascendingCase);
else if(getSortFunc()==ascendingType) setSortFunc(descendingType);
else if(getSortFunc()==descendingType) setSortFunc(ascendingType);
else if(getSortFunc()==ascendingSize) setSortFunc(descendingSize);
else if(getSortFunc()==descendingSize) setSortFunc(ascendingSize);
else if(getSortFunc()==ascendingTime) setSortFunc(descendingTime);
else if(getSortFunc()==descendingTime) setSortFunc(ascendingTime);
else if(getSortFunc()==ascendingUser) setSortFunc(descendingUser);
else if(getSortFunc()==descendingUser) setSortFunc(ascendingUser);
else if(getSortFunc()==ascendingGroup) setSortFunc(descendingGroup);
else if(getSortFunc()==descendingGroup) setSortFunc(ascendingGroup);
sortItems();
return 1;
}
// Update sender
long FXFileList::onUpdSortReverse(FXObject* sender,FXSelector,void*){
FXSelector selector=FXSEL(SEL_COMMAND,ID_UNCHECK);
if(getSortFunc()==descending) selector=FXSEL(SEL_COMMAND,ID_CHECK);
else if(getSortFunc()==descendingCase) selector=FXSEL(SEL_COMMAND,ID_CHECK);
else if(getSortFunc()==descendingType) selector=FXSEL(SEL_COMMAND,ID_CHECK);
else if(getSortFunc()==descendingSize) selector=FXSEL(SEL_COMMAND,ID_CHECK);
else if(getSortFunc()==descendingTime) selector=FXSEL(SEL_COMMAND,ID_CHECK);
else if(getSortFunc()==descendingUser) selector=FXSEL(SEL_COMMAND,ID_CHECK);
else if(getSortFunc()==descendingGroup) selector=FXSEL(SEL_COMMAND,ID_CHECK);
sender->handle(this,selector,nullptr);
return 1;
}
// Toggle case sensitivity
long FXFileList::onCmdSortCase(FXObject*,FXSelector,void*){
if(getSortFunc()==ascending) setSortFunc(ascendingCase);
else if(getSortFunc()==ascendingCase) setSortFunc(ascending);
else if(getSortFunc()==descending) setSortFunc(descendingCase);
else if(getSortFunc()==descendingCase) setSortFunc(descending);
sortItems();
return 1;
}
// Check if case sensitive
long FXFileList::onUpdSortCase(FXObject* sender,FXSelector,void*){
sender->handle(this,(getSortFunc()==ascendingCase || getSortFunc()==descendingCase) ? FXSEL(SEL_COMMAND,ID_CHECK) : FXSEL(SEL_COMMAND,ID_UNCHECK),nullptr);
sender->handle(this,(getSortFunc()==ascendingCase || getSortFunc()==ascending || getSortFunc()==descendingCase || getSortFunc()==descending) ? FXSEL(SEL_COMMAND,ID_ENABLE) : FXSEL(SEL_COMMAND,ID_DISABLE),nullptr);
return 1;
}
// Clicked header button
long FXFileList::onCmdHeader(FXObject*,FXSelector,void* ptr){
if(((FXuint)(FXuval)ptr)<6) handle(this,FXSEL(SEL_COMMAND,(ID_SORT_BY_NAME+(FXuint)(FXuval)ptr)),nullptr);
return 1;
}
// Clicked header button
long FXFileList::onUpdHeader(FXObject*,FXSelector,void*){
header->setArrowDir(0,(getSortFunc()==ascending || getSortFunc()==ascendingCase) ? FXHeaderItem::ARROW_DOWN : (getSortFunc()==descending || getSortFunc()==descendingCase) ? FXHeaderItem::ARROW_UP : FXHeaderItem::ARROW_NONE); // Name
header->setArrowDir(1,(getSortFunc()==ascendingType) ? FXHeaderItem::ARROW_DOWN : (getSortFunc()==descendingType) ? FXHeaderItem::ARROW_UP : FXHeaderItem::ARROW_NONE); // Type
header->setArrowDir(2,(getSortFunc()==ascendingSize) ? FXHeaderItem::ARROW_DOWN : (getSortFunc()==descendingSize) ? FXHeaderItem::ARROW_UP : FXHeaderItem::ARROW_NONE); // Size
header->setArrowDir(3,(getSortFunc()==ascendingTime) ? FXHeaderItem::ARROW_DOWN : (getSortFunc()==descendingTime) ? FXHeaderItem::ARROW_UP : FXHeaderItem::ARROW_NONE); // Date
header->setArrowDir(4,(getSortFunc()==ascendingUser) ? FXHeaderItem::ARROW_DOWN : (getSortFunc()==descendingUser) ? FXHeaderItem::ARROW_UP : FXHeaderItem::ARROW_NONE); // User
header->setArrowDir(5,(getSortFunc()==ascendingGroup) ? FXHeaderItem::ARROW_DOWN : (getSortFunc()==descendingGroup)? FXHeaderItem::ARROW_UP : FXHeaderItem::ARROW_NONE); // Group
return 1;
}
/*******************************************************************************/
// Periodically check to see if directory was changed, and update the list if it was.
long FXFileList::onRefreshTimer(FXObject*,FXSelector,void*){
if(flags&FLAG_UPDATE){
counter+=1;
if(!listItems((counter==REFRESHCOUNT),true)){
setDirectory(FXPath::validPath(directory),true);
}
}
getApp()->addTimeout(this,ID_REFRESHTIMER,REFRESHINTERVAL);
return 0;
}
// Force an immediate update of the list
long FXFileList::onCmdRefresh(FXObject*,FXSelector,void*){
listItems(true,true);
return 1;
}
// Compare till '\t' or '\0'
static FXbool fileequal(const FXchar* p1,const FXchar* p2){
FXint c1,c2;
do{
c1=*p1++;
c2=*p2++;
}
while((c1==c2) && ('\t'<c1));
return (c1<='\t') && (c2<='\t');
}
// List the items in the directory.
// Regenerate the list if an update is forced or the directory timestamp was changed.
// Add, remove, or update items as needed, generating the proper callbacks.
// In addition, re-sort the items using current sort-function.
// Return false if the directory can not be accessed, true otherwise.
FXbool FXFileList::listItems(FXbool force,FXbool notify){
FXStat info;
FXTRACE((100,"%s::listItems(%d,%d)\n",getClassName(),force,notify));
// See if directory still there
if(FXStat::statFile(directory,info)){
// Last modified time of current directory
FXTime time=info.modified();
// Regenerate list if update forced or modified time changed
if(force || time!=timestamp){
FXFileItem *oldlist=list; // Old insert-order list
FXFileItem *newlist=nullptr; // New insert-order list
FXFileItem **po=&oldlist; // Head of old list
FXFileItem **pn=&newlist; // Head of new list
FXFileItem *olditem;
FXFileItem *newitem;
FXFileItem *link;
FXString pathname;
FXString extension;
FXString label;
FXString name;
FXString grpid;
FXString usrid;
FXString attrs;
FXString modtm;
FXString lnknm;
FXuint mode;
FXbool istop;
FXDir dir;
// Get directory stream pointer
if(dir.open(directory)){
// Are we at the top directory?
istop=FXPath::isTopDirectory(directory);
// Loop over directory entries
while(dir.next(name)){
// Suppress '.' if not showing navigational items or not at top directory
if(name[0]=='.'){
if(name[1]=='\0'){
if(!istop || (options&FILELIST_NO_PARENT)) continue;
}
else if(name[1]=='.' && name[2]=='\0'){
if(istop || (options&FILELIST_NO_PARENT)) continue;
}
else{
if(!(options&FILELIST_SHOWHIDDEN)) continue;
}
}
// Build full pathname
pathname=directory;
if(!ISPATHSEP(pathname.tail())) pathname+=PATHSEPSTRING;
pathname+=name;
#ifdef WIN32
// Get file/link info
if(!FXStat::statFile(pathname,info)) continue;
mode=info.mode();
// Suppress hidden files or directories
if((mode&FXIO::Hidden) && !(options&FILELIST_SHOWHIDDEN)) continue;
#else
// Get file/link info
if(!FXStat::statLink(pathname,info)) continue;
mode=info.mode();
// If its a link, get file mode from target
if(info.isLink()){
mode=FXStat::mode(pathname) | FXIO::SymLink;
}
#endif
// Skip item if it is a directory and we want only files, if it is a file and we want only directories,
// or if it is a file and it fails to match the wildcard pattern.
if(mode&FXIO::Directory){
if(options&FILELIST_SHOWFILES) continue;
}
else{
if(options&FILELIST_SHOWDIRS) continue;
if(!FXPath::match(name,pattern,matchmode)) continue;
}
// Search for item in old list, unlink from old if found
for(FXFileItem** pp=po; (olditem=*pp)!=nullptr; pp=&olditem->link){
if(fileequal(olditem->label.text(),name.text())){
*pp=olditem->link; olditem->link=nullptr;
break;
}
}
// Use a new item if forced, if there was no old item, or if the item information was changed
if(force || !olditem || olditem->getDate()!=info.modified() || olditem->getSize()!=info.size() || olditem->getMode()!=mode){
// Make new item
newitem=(FXFileItem*)createItem(FXString::null,nullptr,nullptr,nullptr);
// Obtain user name
usrid=FXSystem::userName(info.user());
// Obtain group name
grpid=FXSystem::groupName(info.group());
// Permissions
attrs=FXSystem::modeString(mode);
// Mod time
modtm=FXSystem::localTime(info.modified(),timeformat.text());
// Link name, if any
lnknm=FXString::null;
if(info.isLink()) lnknm=FXFile::symlink(pathname);
// Update item information
newitem->setDraggable(draggable);
newitem->setSize(info.size());
newitem->setDate(info.modified());
newitem->setMode(mode);
newitem->setAssoc(nullptr);
// Determine icons and type
if(newitem->isDirectory()){
extension=tr("Folder");
newitem->setBigIcon(big_folder);
newitem->setMiniIcon(mini_folder);
if(associations) newitem->setAssoc(associations->findDirBinding(pathname));
}
else if(newitem->isExecutable()){
extension=tr("Application");
newitem->setBigIcon(big_app);
newitem->setMiniIcon(mini_app);
if(associations) newitem->setAssoc(associations->findExecBinding(pathname));
}
else{
extension=tr("Document");
newitem->setBigIcon(big_doc);
newitem->setMiniIcon(mini_doc);
if(associations) newitem->setAssoc(associations->findFileBinding(pathname));
}
// If association is found, use it
if(newitem->getAssoc()){
extension=newitem->getAssoc()->extension;
if(newitem->getAssoc()->bigicon) newitem->setBigIcon(newitem->getAssoc()->bigicon);
if(newitem->getAssoc()->miniicon) newitem->setMiniIcon(newitem->getAssoc()->miniicon);
}
// Update item information
label.format("%s\t%s\t%'lld\t%s\t%s\t%s\t%s\t%s",name.text(),extension.text(),newitem->size,modtm.text(),usrid.text(),grpid.text(),attrs.text(),lnknm.text());
// New label
newitem->setText(label);
// Create item
if(id()) newitem->create();
// Replace or add item
if(olditem){
setItem(items.find(olditem),newitem,notify);
}
else{
appendItem(newitem,notify);
}
*pn=newitem; pn=&newitem->link;
}
// Keep old item if nothing changed
else{
*pn=olditem; pn=&olditem->link;
}
}
// Show thumbnails
if(showImages()){
getApp()->addChore(this,ID_PREVIEWCHORE,(void*)(FXival)0);
}
// Close directory
dir.close();
}
// Wipe items remaining in list:- they have disappeared!!
for(olditem=oldlist; olditem; olditem=link){
link=olditem->link;
removeItem(items.find(olditem),notify);
}
// Remember new list
list=newlist;
// Update sort order
sortItems();
// Update timestamp
timestamp=time;
// Reset counter
counter=0;
}
return true;
}
return false;
}
/*******************************************************************************/
// Set current file; return true if success
FXbool FXFileList::setCurrentFile(const FXString& file,FXbool notify){
FXTRACE((100,"%s::setCurrentFile(%s)\n",getClassName(),file.text()));
if(setDirectory(FXPath::directory(file),notify)){
FXint index=findItem(FXPath::name(file));
if(0<=index){
makeItemVisible(index);
setAnchorItem(index);
setCurrentItem(index,notify);
selectItem(index,notify);
return true;
}
}
return false;
}
// Get pathname to current file, if any
FXString FXFileList::getCurrentFile() const {
if(0<=getCurrentItem()){
return getItemPathname(getCurrentItem());
}
return FXString::null;
}
// Set current directory; return true if success
FXbool FXFileList::setDirectory(const FXString& pathname,FXbool notify){
FXTRACE((100,"%s::setDirectory(%s)\n",getClassName(),pathname.text()));
FXString path(FXPath::absolute(directory,pathname));
if(FXStat::isDirectory(path)){
if(directory==path) return true;
clearItems(notify);
directory=path;
list=nullptr;
if(listItems(true,notify)){
if(getNumItems()){
makeItemVisible(0);
setAnchorItem(0);
setCurrentItem(0,notify);
}
return true;
}
}
return false;
}
/*******************************************************************************/
// Get file name from item
FXString FXFileList::getItemFilename(FXint index) const {
if(index<0 || getNumItems()<=index){ fxerror("%s::getItemFilename: index out of range.\n",getClassName()); }
return items[index]->label.section('\t',0);
}
// Get full pathname to item
FXString FXFileList::getItemPathname(FXint index) const {
if(index<0 || getNumItems()<=index){ fxerror("%s::getItemPathname: index out of range.\n",getClassName()); }
return FXPath::absolute(directory,items[index]->label.section('\t',0));
}
// Is file
FXbool FXFileList::isItemFile(FXint index) const {
if(index<0 || getNumItems()<=index){ fxerror("%s::isItemFile: index out of range.\n",getClassName()); }
return ((FXFileItem*)items[index])->isFile();
}
// Is directory
FXbool FXFileList::isItemDirectory(FXint index) const {
if(index<0 || getNumItems()<=index){ fxerror("%s::isItemDirectory: index out of range.\n",getClassName()); }
return ((FXFileItem*)items[index])->isDirectory();
}
// Is executable
FXbool FXFileList::isItemExecutable(FXint index) const {
if(index<0 || getNumItems()<=index){ fxerror("%s::isItemExecutable: index out of range.\n",getClassName()); }
return ((FXFileItem*)items[index])->isExecutable();
}
// Return true if this is a symbolic link item
FXbool FXFileList::isItemSymlink(FXint index) const {
if(index<0 || getNumItems()<=index){ fxerror("%s::isItemSymlink: index out of range.\n",getClassName()); }
return ((FXFileItem*)items[index])->isSymlink();
}
// Return true if item is navigational item like '.' or '..'
FXbool FXFileList::isItemNavigational(FXint index) const {
if(index<0 || getNumItems()<=index){ fxerror("%s::isItemNavigational: index out of range.\n",getClassName()); }
return ((FXFileItem*)items[index])->isNavigational();
}
// Get associations (if any) from the file
FXFileAssoc* FXFileList::getItemAssoc(FXint index) const {
if(index<0 || getNumItems()<=index){ fxerror("%s::getItemAssoc: index out of range.\n",getClassName()); }
return ((FXFileItem*)items[index])->getAssoc();
}
// Return the file size for this item
FXlong FXFileList::getItemSize(FXint index) const {
if(index<0 || getNumItems()<=index){ fxerror("%s::getItemSize: index out of range.\n",getClassName()); }
return ((FXFileItem*)items[index])->getSize();
}
// Return the date for this item, in nanoseconds
FXTime FXFileList::getItemDate(FXint index) const {
if(index<0 || getNumItems()<=index){ fxerror("%s::getItemDate: index out of range.\n",getClassName()); }
return ((FXFileItem*)items[index])->getDate();
}
// Return the mode bits for this item
FXuint FXFileList::getItemMode(FXint index) const {
if(index<0 || getNumItems()<=index){ fxerror("%s::getItemMode: index out of range.\n",getClassName()); }
return ((FXFileItem*)items[index])->getMode();
}
/*******************************************************************************/
// Set the pattern to filter
void FXFileList::setPattern(const FXString& ptrn,FXbool notify){
if(!ptrn.empty() && pattern!=ptrn){
pattern=ptrn;
listItems(true,notify);
}
}
// Change file match mode
void FXFileList::setMatchMode(FXuint mode,FXbool notify){
if(matchmode!=mode){
matchmode=mode;
listItems(true,notify);
}
}
// Change show hidden files mode
void FXFileList::showHiddenFiles(FXbool flag,FXbool notify){
FXuint opts=((-(FXint)flag^options)&FILELIST_SHOWHIDDEN)^options;
if(opts!=options){
options=opts;
listItems(true,notify);
}
}
// Return true if showing hidden files
FXbool FXFileList::showHiddenFiles() const {
return (options&FILELIST_SHOWHIDDEN)!=0;
}
// Change show directories only mode
void FXFileList::showOnlyDirectories(FXbool flag,FXbool notify){
FXuint opts=(((0-flag)^options)&FILELIST_SHOWDIRS)^options;
if(opts!=options){
options=opts;
listItems(true,notify);
}
}
// Return true if showing directories only
FXbool FXFileList::showOnlyDirectories() const {
return (options&FILELIST_SHOWDIRS)!=0;
}
// Show files only
void FXFileList::showOnlyFiles(FXbool flag,FXbool notify){
FXuint opts=(((0-flag)^options)&FILELIST_SHOWFILES)^options;
if(opts!=options){
options=opts;
listItems(true,notify);
}
}
// Return true if showing files only
FXbool FXFileList::showOnlyFiles() const {
return (options&FILELIST_SHOWFILES)!=0;
}
// Show parent directories
void FXFileList::showParents(FXbool flag,FXbool notify){
FXuint opts=(((flag-1)^options)&FILELIST_NO_PARENT)^options;
if(opts!=options){
options=opts;
listItems(true,notify);
}
}
// Return true if showing parent directories
FXbool FXFileList::showParents() const {
return (options&FILELIST_NO_PARENT)==0;
}
// Change show image display mode
void FXFileList::showImages(FXbool flag,FXbool notify){
FXuint opts=(((0-flag)^options)&FILELIST_SHOWIMAGES)^options;
if(opts!=options){
options=opts;
listItems(true,notify);
}
}
// Return true if displaying image
FXbool FXFileList::showImages() const {
return (options&FILELIST_SHOWIMAGES)!=0;
}
// Change images preview size
void FXFileList::setImageSize(FXint size,FXbool notify){
if(size!=imagesize){
imagesize=size;
listItems(true,notify);
}
}
// Change file associations; delete the old one unless it was shared
void FXFileList::setAssociations(FXFileAssociations* assocs,FXbool owned,FXbool notify){
FXuint opts=options;
options^=((owned-1)^options)&FILELIST_NO_OWN_ASSOC;
if(associations!=assocs){
if(!(opts&FILELIST_NO_OWN_ASSOC)) delete associations;
associations=assocs;
listItems(true,notify);
}
}
// Set draggable files
void FXFileList::setDraggableFiles(FXbool flg,FXbool notify){
if(draggable!=flg){
draggable=flg;
listItems(true,notify);
}
}
// Set file time format
void FXFileList::setTimeFormat(const FXString& fmt,FXbool notify){
if(timeformat!=fmt){
timeformat=fmt;
listItems(true,notify);
}
}
/*******************************************************************************/
// Save data
void FXFileList::save(FXStream& store) const {
FXIconList::save(store);
store << associations;
store << iconloader;
store << big_folder;
store << mini_folder;
store << big_doc;
store << mini_doc;
store << big_app;
store << mini_app;
store << directory;
store << pattern;
store << timeformat;
store << matchmode;
store << imagesize;
store << draggable;
}
// Load data
void FXFileList::load(FXStream& store){
FXIconList::load(store);
store >> associations;
store >> iconloader;
store >> big_folder;
store >> mini_folder;
store >> big_doc;
store >> mini_doc;
store >> big_app;
store >> mini_app;
store >> directory;
store >> pattern;
store >> timeformat;
store >> matchmode;
store >> imagesize;
store >> draggable;
}
// Cleanup
FXFileList::~FXFileList(){
getApp()->removeChore(this);
getApp()->removeTimeout(this,ID_OPENTIMER);
getApp()->removeTimeout(this,ID_REFRESHTIMER);
if(!(options&FILELIST_NO_OWN_ASSOC)) delete associations;
delete big_folder;
delete mini_folder;
delete big_doc;
delete mini_doc;
delete big_app;
delete mini_app;
associations=(FXFileAssociations*)-1L;
iconloader=(FXIconSource*)-1L;
list=(FXFileItem*)-1L;
big_folder=(FXIcon*)-1L;
mini_folder=(FXIcon*)-1L;
big_doc=(FXIcon*)-1L;
mini_doc=(FXIcon*)-1L;
big_app=(FXIcon*)-1L;
mini_app=(FXIcon*)-1L;
}
}
|