summaryrefslogtreecommitdiff
path: root/thunar/thunar-launcher.c
blob: 1b1c9470b5c5a3ae96cdba1bf44b3a03bd9b347e (plain)
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
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
/* vi:set et ai sw=2 sts=2 ts=2: */
/*-
 * Copyright (c) 2005-2006 Benedikt Meurer <benny@xfce.org>
 * Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org>
 * Copyright (c) 2020 Alexander Schwinn <alexxcons@xfce.org>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program 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 General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif

#include <thunar/thunar-application.h>
#include <thunar/thunar-browser.h>
#include <thunar/thunar-chooser-dialog.h>
#include <thunar/thunar-clipboard-manager.h>
#include <thunar/thunar-dialogs.h>
#include <thunar/thunar-gio-extensions.h>
#include <thunar/thunar-gobject-extensions.h>
#include <thunar/thunar-gtk-extensions.h>
#include <thunar/thunar-icon-factory.h>
#include <thunar/thunar-io-scan-directory.h>
#include <thunar/thunar-launcher.h>
#include <thunar/thunar-preferences.h>
#include <thunar/thunar-private.h>
#include <thunar/thunar-properties-dialog.h>
#include <thunar/thunar-renamer-dialog.h>
#include <thunar/thunar-sendto-model.h>
#include <thunar/thunar-shortcuts-pane.h>
#include <thunar/thunar-simple-job.h>
#include <thunar/thunar-device-monitor.h>
#include <thunar/thunar-tree-view.h>
#include <thunar/thunar-util.h>
#include <thunar/thunar-window.h>

#include <libxfce4ui/libxfce4ui.h>



/**
 * SECTION:thunar-launcher
 * @Short_description: Manages creation and execution of menu-item
 * @Title: ThunarLauncher
 *
 * The #ThunarLauncher class manages the creation and execution of menu-item which are used by multiple menus.
 * The management is done in a central way to prevent code duplication on various places.
 * XfceGtkActionEntry is used in order to define a list of the managed items and ease the setup of single items.
 *
 * #ThunarLauncher implements the #ThunarNavigator interface in order to use the "open in new tab" and "change directory" service.
 * It as well tracks the current directory via #ThunarNavigator.
 *
 * #ThunarLauncher implements the #ThunarComponent interface in order to track the currently selected files.
 * Based on to the current selection (and some other criteria), some menu items will not be shown, or will be insensitive.
 *
 * Files which are opened via #ThunarLauncher are poked first in order to e.g do missing mount operations.
 *
 * As well menu-item related services, like activation of selected files and opening tabs/new windows,
 * are provided by #ThunarLauncher.
 *
 * It is required to keep an instance of #ThunarLauncher open, in order to listen to accellerators which target
 * menu-items managed by #ThunarLauncher.
 * Typically a single instance of #ThunarLauncher is provided by each #ThunarWindow.
 */



typedef struct _ThunarLauncherPokeData ThunarLauncherPokeData;



/* Signal identifiers */
enum
{
  DEVICE_OPERATION_STARTED,
  DEVICE_OPERATION_FINISHED,
  NEW_FILES_CREATED,
  LAST_SIGNAL,
};

/* Property identifiers */
enum
{
  PROP_0,
  PROP_CURRENT_DIRECTORY,
  PROP_SELECTED_FILES,
  PROP_WIDGET,
  PROP_SELECTED_DEVICE,
  PROP_SELECTED_LOCATION,
  N_PROPERTIES
};



static void                    thunar_launcher_component_init             (ThunarComponentIface           *iface);
static void                    thunar_launcher_navigator_init             (ThunarNavigatorIface           *iface);
static void                    thunar_launcher_dispose                    (GObject                        *object);
static void                    thunar_launcher_finalize                   (GObject                        *object);
static void                    thunar_launcher_get_property               (GObject                        *object,
                                                                           guint                           prop_id,
                                                                           GValue                         *value,
                                                                           GParamSpec                     *pspec);
static void                    thunar_launcher_set_property               (GObject                        *object,
                                                                           guint                           prop_id,
                                                                           const GValue                   *value,
                                                                           GParamSpec                     *pspec);
static ThunarFile             *thunar_launcher_get_current_directory      (ThunarNavigator                *navigator);
static void                    thunar_launcher_set_current_directory      (ThunarNavigator                *navigator,
                                                                           ThunarFile                     *current_directory);
static void                    thunar_launcher_set_selected_files         (ThunarComponent                *component,
                                                                           GList                          *selected_files);
static void                    thunar_launcher_execute_files              (ThunarLauncher                 *launcher,
                                                                           GList                          *files);
static void                    thunar_launcher_open_files                 (ThunarLauncher                 *launcher,
                                                                           GList                          *files,
                                                                           GAppInfo                       *application_to_use);
static void                    thunar_launcher_open_paths                 (GAppInfo                       *app_info,
                                                                           GList                          *file_list,
                                                                           ThunarLauncher                 *launcher);
static void                    thunar_launcher_open_windows               (ThunarLauncher                 *launcher,
                                                                           GList                          *directories);
static void                    thunar_launcher_poke                       (ThunarLauncher                 *launcher,
                                                                           GAppInfo                       *application_to_use,
                                                                           ThunarLauncherFolderOpenAction  folder_open_action);
static void                    thunar_launcher_poke_device_finish         (ThunarBrowser                  *browser,
                                                                           ThunarDevice                   *volume,
                                                                           ThunarFile                     *mount_point,
                                                                           GError                         *error,
                                                                           gpointer                        user_data,
                                                                           gboolean                        cancelled);
static void                    thunar_launcher_poke_location_finish       (ThunarBrowser                  *browser,
                                                                           GFile                          *location,
                                                                           ThunarFile                     *file,
                                                                           ThunarFile                     *target_file,
                                                                           GError                         *error,
                                                                           gpointer                        user_data);
static void                    thunar_launcher_poke_files_finish          (ThunarBrowser                  *browser,
                                                                           ThunarFile                     *file,
                                                                           ThunarFile                     *target_file,
                                                                           GError                         *error,
                                                                           gpointer                        user_data);
static ThunarLauncherPokeData *thunar_launcher_poke_data_new              (GList                          *files_to_poke,
                                                                           GAppInfo                       *application_to_use,
                                                                           ThunarLauncherFolderOpenAction  folder_open_action,
                                                                           GFile                          *location_to_poke,
                                                                           ThunarDevice                   *device_to_poke);
static void                    thunar_launcher_poke_data_free             (ThunarLauncherPokeData         *data);
static void                    thunar_launcher_widget_destroyed           (ThunarLauncher                 *launcher,
                                                                           GtkWidget                      *widget);
static gboolean                thunar_launcher_action_open                (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_open_in_new_tabs    (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_open_in_new_windows (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_open_location       (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_open_with_other     (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_set_default_app     (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_sendto_desktop      (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_properties          (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_sendto_device       (ThunarLauncher                 *launcher,
                                                                           GObject                        *object);
static gboolean                thunar_launcher_action_add_shortcuts       (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_make_link           (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_duplicate           (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_rename              (ThunarLauncher                 *launcher);
static void                    thunar_launcher_action_move_to_trash       (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_delete              (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_trash_delete        (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_remove_from_recent  (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_cut                 (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_copy                (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_paste               (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_paste_into_folder   (ThunarLauncher                 *launcher);
static void                    thunar_launcher_sendto_device              (ThunarLauncher                 *launcher,
                                                                           ThunarDevice                   *device);
static void                    thunar_launcher_sendto_mount_finish        (ThunarDevice                   *device,
                                                                           const GError                   *error,
                                                                           gpointer                        user_data);
static GtkWidget              *thunar_launcher_build_sendto_submenu       (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_menu_item_activated        (ThunarLauncher                 *launcher,
                                                                           GtkWidget                      *menu_item);
static gboolean                thunar_launcher_action_create_folder       (ThunarLauncher                 *launcher);
static gboolean                thunar_launcher_action_create_document     (ThunarLauncher                 *launcher,
                                                                           GtkWidget                      *menu_item);
static GtkWidget              *thunar_launcher_create_document_submenu_new(ThunarLauncher                 *launcher);
static void                    thunar_launcher_new_files_created          (ThunarLauncher                 *launcher,
                                                                           GList                          *new_thunar_files);



struct _ThunarLauncherClass
{
  GObjectClass __parent__;
};

struct _ThunarLauncher
{
  GObject __parent__;

  ThunarFile             *current_directory;

  GList                  *files_to_process;    /* List of thunar-files to work with */
  ThunarDevice           *device_to_process;   /* Device to work with */
  GFile                  *location_to_process; /* Location to work with (might be not reachable) */

  gint                    n_files_to_process;
  gint                    n_directories_to_process;
  gint                    n_regulars_to_process;
  gboolean                files_to_process_trashable;
  gboolean                files_are_selected;
  gboolean                files_are_all_executable;
  gboolean                single_directory_to_process;

  ThunarFile             *single_folder;
  ThunarFile             *parent_folder;

  /* closure invoked whenever launcher creates new files (create, paste, rename, etc) */
  GClosure               *new_files_created_closure;

  ThunarPreferences      *preferences;

  /* Parent widget which holds the instance of the launcher */
  GtkWidget              *widget;

  /* TRUE if the active view is displaying search results or actively searching for files */
  gboolean                is_searching;
};

static GQuark thunar_launcher_appinfo_quark;
static GQuark thunar_launcher_device_quark;
static GQuark thunar_launcher_file_quark;

static guint launcher_signals[LAST_SIGNAL];

struct _ThunarLauncherPokeData
{
  GList                          *files_to_poke; /* List of thunar-files */
  GList                          *files_poked;   /* List of thunar-files */
  GFile                          *location_to_poke;
  ThunarDevice                   *device_to_poke;
  GAppInfo                       *application_to_use;
  ThunarLauncherFolderOpenAction  folder_open_action;
};

static GParamSpec *launcher_props[N_PROPERTIES] = { NULL, };

static XfceGtkActionEntry thunar_launcher_action_entries[] =
{
    { THUNAR_LAUNCHER_ACTION_OPEN,             "<Actions>/ThunarLauncher/open",                    "<Primary>O",        XFCE_GTK_IMAGE_MENU_ITEM, N_ ("Open"),                            NULL,                                                                                            "document-open",        G_CALLBACK (thunar_launcher_action_open),                },
    { THUNAR_LAUNCHER_ACTION_EXECUTE,          "<Actions>/ThunarLauncher/execute",                 "",                  XFCE_GTK_IMAGE_MENU_ITEM, N_ ("E_xecute"),                        NULL,                                                                                            "system-run",           G_CALLBACK (thunar_launcher_action_open),                },
    { THUNAR_LAUNCHER_ACTION_OPEN_IN_TAB,      "<Actions>/ThunarLauncher/open-in-new-tab",         "<Primary><shift>P", XFCE_GTK_MENU_ITEM,       N_ ("Open in new _Tab"),                NULL,                                                                                            NULL,                   G_CALLBACK (thunar_launcher_action_open_in_new_tabs),    },
    { THUNAR_LAUNCHER_ACTION_OPEN_IN_WINDOW,   "<Actions>/ThunarLauncher/open-in-new-window",      "<Primary><shift>O", XFCE_GTK_MENU_ITEM,       N_ ("Open in new _Window"),             NULL,                                                                                            NULL,                   G_CALLBACK (thunar_launcher_action_open_in_new_windows), },
    { THUNAR_LAUNCHER_ACTION_OPEN_LOCATION,    "<Actions>/ThunarLauncher/open-location",           "",                  XFCE_GTK_MENU_ITEM,       N_ ("Open Item Location"),              NULL,                                                                                            NULL,                   G_CALLBACK (thunar_launcher_action_open_location),       },
    { THUNAR_LAUNCHER_ACTION_OPEN_WITH_OTHER,  "<Actions>/ThunarLauncher/open-with-other",         "",                  XFCE_GTK_MENU_ITEM,       N_ ("Open With Other _Application..."), N_ ("Choose another application with which to open the selected file"),                          NULL,                   G_CALLBACK (thunar_launcher_action_open_with_other),     },
    { THUNAR_LAUNCHER_ACTION_SET_DEFAULT_APP,  "<Actions>/ThunarStandardView/set-default-app",     "",                  XFCE_GTK_MENU_ITEM,       N_ ("Set _Default Application..."),     N_ ("Choose an application which should be used by default to open the selected file"),          NULL,                   G_CALLBACK (thunar_launcher_action_set_default_app),     },

    /* For backward compatibility the old accel paths are re-used. Currently not possible to automatically migrate to new accel paths. */
    /* Waiting for https://gitlab.gnome.org/GNOME/gtk/issues/2375 to be able to fix that */
    {THUNAR_LAUNCHER_ACTION_SENDTO_MENU,        "<Actions>/ThunarWindow/sendto-menu",             "",                  XFCE_GTK_MENU_ITEM,       N_ ("_Send To"),            NULL,                                             NULL,                                                                                         NULL,                                                    },
    {THUNAR_LAUNCHER_ACTION_SENDTO_SHORTCUTS,   "<Actions>/ThunarShortcutsPane/sendto-shortcuts", "<Primary>D",        XFCE_GTK_IMAGE_MENU_ITEM, N_ ("_Add Bookmark"),       N_ ("Create bookmarks for all selected folders in the sidepane. If nothing is selected, the current directory is bookmarked."), "bookmark-new", G_CALLBACK (thunar_launcher_action_add_shortcuts), },
    {THUNAR_LAUNCHER_ACTION_SENDTO_DESKTOP,     "<Actions>/ThunarLauncher/sendto-desktop",        "",                  XFCE_GTK_MENU_ITEM,       N_ ("Send to _Desktop"),    NULL,                                                                                            "user-desktop",                                G_CALLBACK (thunar_launcher_action_sendto_desktop),      },
    {THUNAR_LAUNCHER_ACTION_PROPERTIES,         "<Actions>/ThunarStandardView/properties",        "<Alt>Return",       XFCE_GTK_IMAGE_MENU_ITEM, N_ ("_Properties..."),      N_ ("View the properties of the selected file"),                                                 "document-properties",                         G_CALLBACK (thunar_launcher_action_properties),          },
    {THUNAR_LAUNCHER_ACTION_MAKE_LINK,          "<Actions>/ThunarStandardView/make-link",         "",                  XFCE_GTK_MENU_ITEM,       N_ ("Ma_ke Link"),          NULL,                                             NULL,                                                                                         G_CALLBACK (thunar_launcher_action_make_link),           },
    {THUNAR_LAUNCHER_ACTION_DUPLICATE,          "<Actions>/ThunarStandardView/duplicate",         "",                  XFCE_GTK_MENU_ITEM,       N_ ("Du_plicate"),          NULL,                                             NULL,                                                                                         G_CALLBACK (thunar_launcher_action_duplicate),           },
    {THUNAR_LAUNCHER_ACTION_RENAME,             "<Actions>/ThunarStandardView/rename",            "F2",                XFCE_GTK_MENU_ITEM,       N_ ("_Rename..."),          NULL,                                             NULL,                                                                                         G_CALLBACK (thunar_launcher_action_rename),              },
    {THUNAR_LAUNCHER_ACTION_EMPTY_TRASH,        "<Actions>/ThunarWindow/empty-trash",             "",                  XFCE_GTK_IMAGE_MENU_ITEM, N_ ("_Empty Trash"),        N_ ("Delete all files and folders in the Trash"), NULL,                                                                                         G_CALLBACK (thunar_launcher_action_empty_trash),         },
    {THUNAR_LAUNCHER_ACTION_REMOVE_FROM_RECENT, "<Actions>/ThunarWindow/remove-from-recent",      "",                  XFCE_GTK_MENU_ITEM,       N_ ("_Remove from recent"), N_ ("Remove the selected files from Recent"),     NULL,                                                                                         G_CALLBACK (thunar_launcher_action_remove_from_recent),       },
    {THUNAR_LAUNCHER_ACTION_CREATE_FOLDER,      "<Actions>/ThunarStandardView/create-folder",     "<Primary><shift>N", XFCE_GTK_IMAGE_MENU_ITEM, N_ ("Create _Folder..."),   N_ ("Create an empty folder within the current folder"),                                         "folder-new",                                  G_CALLBACK (thunar_launcher_action_create_folder),       },
    {THUNAR_LAUNCHER_ACTION_CREATE_DOCUMENT,    "<Actions>/ThunarStandardView/create-document",   "",                  XFCE_GTK_IMAGE_MENU_ITEM, N_ ("Create _Document"),    N_ ("Create a new document from a template"),                                                    "document-new",                                G_CALLBACK (NULL),                                       },

    {THUNAR_LAUNCHER_ACTION_RESTORE,            "<Actions>/ThunarLauncher/restore",               "",                  XFCE_GTK_MENU_ITEM,       N_ ("_Restore"),            NULL,                                             NULL,                                                                                         G_CALLBACK (thunar_launcher_action_restore),             },
    { THUNAR_LAUNCHER_ACTION_RESTORE_SHOW,      "<Actions>/ThunarLauncher/restore-show",          "",                  XFCE_GTK_MENU_ITEM,       N_ ("_Restore and Show"),   N_ ("_Restore and show the file(s)"),             NULL,                                                                                         G_CALLBACK (thunar_launcher_action_restore_and_show),    },
    {THUNAR_LAUNCHER_ACTION_MOVE_TO_TRASH,      "<Actions>/ThunarLauncher/move-to-trash",         "",                  XFCE_GTK_IMAGE_MENU_ITEM, N_ ("Mo_ve to Trash"),      NULL,                                                                                            "user-trash",                                  G_CALLBACK (thunar_launcher_action_trash_delete),        },
    {THUNAR_LAUNCHER_ACTION_DELETE,             "<Actions>/ThunarLauncher/delete",                "",                  XFCE_GTK_IMAGE_MENU_ITEM, N_ ("_Delete"),             NULL,                                                                                            "edit-delete",                                 G_CALLBACK (thunar_launcher_action_delete),              },
    {THUNAR_LAUNCHER_ACTION_DELETE,             "<Actions>/ThunarLauncher/delete-2",              "<Shift>Delete",     XFCE_GTK_IMAGE_MENU_ITEM, NULL,                       NULL,                                             NULL,                                                                                         G_CALLBACK (thunar_launcher_action_delete),              },
    {THUNAR_LAUNCHER_ACTION_DELETE,             "<Actions>/ThunarLauncher/delete-3",              "<Shift>KP_Delete",  XFCE_GTK_IMAGE_MENU_ITEM, NULL,                       NULL,                                             NULL,                                                                                         G_CALLBACK (thunar_launcher_action_delete),              },
    {THUNAR_LAUNCHER_ACTION_TRASH_DELETE,       "<Actions>/ThunarLauncher/trash-delete",          "Delete",            XFCE_GTK_IMAGE_MENU_ITEM, NULL,                       NULL,                                             NULL,                                                                                         G_CALLBACK (thunar_launcher_action_trash_delete),        },
    {THUNAR_LAUNCHER_ACTION_TRASH_DELETE,       "<Actions>/ThunarLauncher/trash-delete-2",        "KP_Delete",         XFCE_GTK_IMAGE_MENU_ITEM, NULL,                       NULL,                                             NULL,                                                                                         G_CALLBACK (thunar_launcher_action_trash_delete),        },
    { THUNAR_LAUNCHER_ACTION_PASTE,            "<Actions>/ThunarLauncher/paste",                   "<Primary>V",        XFCE_GTK_IMAGE_MENU_ITEM, N_ ("_Paste"),                          N_ ("Move or copy files previously selected by a Cut or Copy command"),                          "edit-paste",           G_CALLBACK (thunar_launcher_action_paste),               },
    { THUNAR_LAUNCHER_ACTION_PASTE_INTO_FOLDER,NULL,                                               "",                  XFCE_GTK_IMAGE_MENU_ITEM, N_ ("_Paste Into Folder"),              N_ ("Move or copy files previously selected by a Cut or Copy command into the selected folder"), "edit-paste",           G_CALLBACK (thunar_launcher_action_paste_into_folder),   },
    { THUNAR_LAUNCHER_ACTION_COPY,             "<Actions>/ThunarLauncher/copy",                    "<Primary>C",        XFCE_GTK_IMAGE_MENU_ITEM, N_ ("_Copy"),                           N_ ("Prepare the selected files to be copied with a Paste command"),                             "edit-copy",            G_CALLBACK (thunar_launcher_action_copy),                },
    { THUNAR_LAUNCHER_ACTION_CUT,              "<Actions>/ThunarLauncher/cut",                     "<Primary>X",        XFCE_GTK_IMAGE_MENU_ITEM, N_ ("Cu_t"),                            N_ ("Prepare the selected files to be moved with a Paste command"),                              "edit-cut",             G_CALLBACK (thunar_launcher_action_cut),                 },

    { THUNAR_LAUNCHER_ACTION_MOUNT,            NULL,                                               "",                  XFCE_GTK_MENU_ITEM,       N_ ("_Mount"),                          N_ ("Mount the selected device"),                                                                NULL,                   G_CALLBACK (thunar_launcher_action_open),                },
    { THUNAR_LAUNCHER_ACTION_UNMOUNT,          NULL,                                               "",                  XFCE_GTK_MENU_ITEM,       N_ ("_Unmount"),                        N_ ("Unmount the selected device"),                                                              NULL,                   G_CALLBACK (thunar_launcher_action_unmount),             },
    { THUNAR_LAUNCHER_ACTION_EJECT,            NULL,                                               "",                  XFCE_GTK_MENU_ITEM,       N_ ("_Eject"),                          N_ ("Eject the selected device"),                                                                NULL,                   G_CALLBACK (thunar_launcher_action_eject),               },
};

#define get_action_entry(id) xfce_gtk_get_action_entry_by_id(thunar_launcher_action_entries,G_N_ELEMENTS(thunar_launcher_action_entries),id)


G_DEFINE_TYPE_WITH_CODE (ThunarLauncher, thunar_launcher, G_TYPE_OBJECT,
    G_IMPLEMENT_INTERFACE (THUNAR_TYPE_BROWSER, NULL)
    G_IMPLEMENT_INTERFACE (THUNAR_TYPE_NAVIGATOR, thunar_launcher_navigator_init)
    G_IMPLEMENT_INTERFACE (THUNAR_TYPE_COMPONENT, thunar_launcher_component_init))



static void
thunar_launcher_class_init (ThunarLauncherClass *klass)
{
  GObjectClass *gobject_class;
  gpointer      g_iface;

  /* determine all used quarks */
  thunar_launcher_appinfo_quark = g_quark_from_static_string ("thunar-launcher-appinfo");
  thunar_launcher_device_quark = g_quark_from_static_string ("thunar-launcher-device");
  thunar_launcher_file_quark = g_quark_from_static_string ("thunar-launcher-file");

  xfce_gtk_translate_action_entries (thunar_launcher_action_entries, G_N_ELEMENTS (thunar_launcher_action_entries));

  gobject_class = G_OBJECT_CLASS (klass);
  gobject_class->dispose = thunar_launcher_dispose;
  gobject_class->finalize = thunar_launcher_finalize;
  gobject_class->get_property = thunar_launcher_get_property;
  gobject_class->set_property = thunar_launcher_set_property;

  /**
   * ThunarLauncher::device-operation-started:
   * @launcher : a #ThunarLauncher
   * @device   : the #ThunarDevice on which the operation was finished
   *
   * This signal is emitted by the @launcher right after the device operation (mount/unmount/eject) is started
   **/
  launcher_signals[DEVICE_OPERATION_STARTED] =
    g_signal_new (I_("device-operation-started"),
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_NO_HOOKS, 0,
                  NULL, NULL,
                  g_cclosure_marshal_generic,
                  G_TYPE_NONE, 1, THUNAR_TYPE_DEVICE);

  /**
   * ThunarLauncher::device-operation-finished:
   * @launcher : a #ThunarLauncher
   * @device   : the #ThunarDevice on which the operation was finished
   *
   * This signal is emitted by the @launcher right after the device operation (mount/unmount/eject) is finished
   **/
  launcher_signals[DEVICE_OPERATION_FINISHED] =
    g_signal_new (I_("device-operation-finished"),
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_NO_HOOKS, 0,
                  NULL, NULL,
                  g_cclosure_marshal_generic,
                  G_TYPE_NONE, 1, THUNAR_TYPE_DEVICE);

  /**
   * ThunarLauncher::new-files-created:
   * @launcher : a #ThunarLauncher
   * @files   : a GList of #ThunarFiles which were created
   *
   * This signal is emitted by the @launcher whenever new files were created (e.g. via "rename", "create" or "paste")
   **/
  launcher_signals[NEW_FILES_CREATED] =
    g_signal_new (I_("new-files-created"),
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_NO_HOOKS, 0,
                  NULL, NULL,
                  g_cclosure_marshal_generic,
                  G_TYPE_NONE, 1, G_TYPE_POINTER);

  /**
   * ThunarLauncher:widget:
   *
   * The #GtkWidget with which this launcher is associated.
   **/
  launcher_props[PROP_WIDGET] =
      g_param_spec_object ("widget",
                           "widget",
                           "widget",
                           GTK_TYPE_WIDGET,
                           EXO_PARAM_WRITABLE);

  /**
   * ThunarLauncher:select-device:
   *
   * The #ThunarDevice which currently is selected (or NULL if no #ThunarDevice is selected)
   **/
  launcher_props[PROP_SELECTED_DEVICE] =
     g_param_spec_pointer ("selected-device",
                           "selected-device",
                           "selected-device",
                           G_PARAM_WRITABLE);

  /**
   * ThunarLauncher:select-device:
   *
   * The #GFile which currently is selected (or NULL if no #GFile is selected)
   **/
  launcher_props[PROP_SELECTED_LOCATION] =
     g_param_spec_pointer ("selected-location",
                           "selected-location",
                           "selected-location",
                           G_PARAM_WRITABLE);

  /* Override ThunarNavigator's properties */
  g_iface = g_type_default_interface_peek (THUNAR_TYPE_NAVIGATOR);
  launcher_props[PROP_CURRENT_DIRECTORY] =
      g_param_spec_override ("current-directory",
                             g_object_interface_find_property (g_iface, "current-directory"));

  /* Override ThunarComponent's properties */
  g_iface = g_type_default_interface_peek (THUNAR_TYPE_COMPONENT);
  launcher_props[PROP_SELECTED_FILES] =
      g_param_spec_override ("selected-files",
                             g_object_interface_find_property (g_iface, "selected-files"));

  /* install properties */
  g_object_class_install_properties (gobject_class, N_PROPERTIES, launcher_props);
}



static void
thunar_launcher_component_init (ThunarComponentIface *iface)
{
  iface->get_selected_files = (gpointer) exo_noop_null;
  iface->set_selected_files = thunar_launcher_set_selected_files;
}



static void
thunar_launcher_navigator_init (ThunarNavigatorIface *iface)
{
  iface->get_current_directory = thunar_launcher_get_current_directory;
  iface->set_current_directory = thunar_launcher_set_current_directory;
}



static void
thunar_launcher_init (ThunarLauncher *launcher)
{
  launcher->files_to_process = NULL;
  launcher->device_to_process = NULL;
  launcher->location_to_process = NULL;
  launcher->parent_folder = NULL;

  /* grab a reference on the preferences */
  launcher->preferences = thunar_preferences_get ();

  /* initialize the new_files_created_closure */
  launcher->new_files_created_closure = g_cclosure_new_swap (G_CALLBACK (thunar_launcher_new_files_created), launcher, NULL);
  g_closure_ref (launcher->new_files_created_closure);
  g_closure_sink (launcher->new_files_created_closure);

  launcher->is_searching = FALSE;
}



static void
thunar_launcher_dispose (GObject *object)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (object);

  /* reset our properties */
  thunar_navigator_set_current_directory (THUNAR_NAVIGATOR (launcher), NULL);
  thunar_launcher_set_widget (THUNAR_LAUNCHER (launcher), NULL);

  /* unref all members */
  if (launcher->files_to_process != NULL)
    thunar_g_list_free_full (launcher->files_to_process);
  launcher->files_to_process = NULL;

  if (launcher->device_to_process != NULL)
    g_object_unref (launcher->device_to_process);
  launcher->device_to_process = NULL;

  if (launcher->location_to_process != NULL)
    g_object_unref (launcher->location_to_process);
  launcher->location_to_process = NULL;

  if (launcher->parent_folder != NULL)
      g_object_unref (launcher->parent_folder);
  launcher->parent_folder = NULL;

  (*G_OBJECT_CLASS (thunar_launcher_parent_class)->dispose) (object);
}



static void
thunar_launcher_finalize (GObject *object)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (object);

  g_closure_invalidate (launcher->new_files_created_closure);
  g_closure_unref (launcher->new_files_created_closure);

  /* release the preferences reference */
  g_object_unref (launcher->preferences);

  (*G_OBJECT_CLASS (thunar_launcher_parent_class)->finalize) (object);
}



static void
thunar_launcher_get_property (GObject    *object,
                              guint       prop_id,
                              GValue     *value,
                              GParamSpec *pspec)
{
  switch (prop_id)
    {
    case PROP_CURRENT_DIRECTORY:
      g_value_set_object (value, thunar_navigator_get_current_directory (THUNAR_NAVIGATOR (object)));
      break;

    case PROP_SELECTED_FILES:
      g_value_set_boxed (value, thunar_component_get_selected_files (THUNAR_COMPONENT (object)));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}



static void
thunar_launcher_set_property (GObject      *object,
                              guint         prop_id,
                              const GValue *value,
                              GParamSpec   *pspec)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (object);

  switch (prop_id)
    {
    case PROP_CURRENT_DIRECTORY:
      thunar_navigator_set_current_directory (THUNAR_NAVIGATOR (object), g_value_get_object (value));
      break;

    case PROP_SELECTED_FILES:
      thunar_launcher_set_selection (launcher, g_value_get_boxed (value), NULL, NULL);
      break;

    case PROP_WIDGET:
      thunar_launcher_set_widget (launcher, g_value_get_object (value));
      break;

    case PROP_SELECTED_DEVICE:
      thunar_launcher_set_selection (launcher, NULL, g_value_get_pointer (value), NULL);
      break;

    case PROP_SELECTED_LOCATION:
      thunar_launcher_set_selection (launcher, NULL, NULL, g_value_get_pointer (value));
     break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}



static ThunarFile*
thunar_launcher_get_current_directory (ThunarNavigator *navigator)
{
  return THUNAR_LAUNCHER (navigator)->current_directory;
}



static void
thunar_launcher_set_current_directory (ThunarNavigator *navigator,
                                       ThunarFile      *current_directory)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (navigator);

  /* disconnect from the previous directory */
  if (G_LIKELY (launcher->current_directory != NULL))
    g_object_unref (G_OBJECT (launcher->current_directory));

  /* activate the new directory */
  launcher->current_directory = current_directory;

  /* connect to the new directory */
  if (G_LIKELY (current_directory != NULL))
    {
      g_object_ref (G_OBJECT (current_directory));

      /* update files_to_process if not initialized yet */
      if (launcher->files_to_process == NULL)
        thunar_launcher_set_selected_files (THUNAR_COMPONENT (navigator), NULL);
    }

  /* notify listeners */
  g_object_notify_by_pspec (G_OBJECT (launcher), launcher_props[PROP_CURRENT_DIRECTORY]);
}



static void
thunar_launcher_set_selected_files (ThunarComponent *component,
                                    GList           *selected_files)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (component);
  GList          *lp;

  /* That happens at startup for some reason */
  if (launcher->current_directory == NULL)
    return;

  /* disconnect from the previous files to process */
  if (launcher->files_to_process != NULL)
    thunar_g_list_free_full (launcher->files_to_process);
  launcher->files_to_process = NULL;

  /* notify listeners */
  g_object_notify_by_pspec (G_OBJECT (launcher), launcher_props[PROP_SELECTED_FILES]);

  /* unref previous parent, if any */
  if (launcher->parent_folder != NULL)
    g_object_unref (launcher->parent_folder);
  launcher->parent_folder = NULL;

  launcher->files_are_selected = TRUE;
  if (selected_files == NULL || g_list_length (selected_files) == 0)
    launcher->files_are_selected = FALSE;

  launcher->files_to_process_trashable = TRUE;
  launcher->n_files_to_process         = 0;
  launcher->n_directories_to_process   = 0;
  launcher->n_regulars_to_process      = 0;
  launcher->files_are_all_executable   = TRUE;
  launcher->single_directory_to_process = FALSE;
  launcher->single_folder = NULL;

  /* if nothing is selected, the current directory is the folder to use for all menus */
  if (launcher->files_are_selected)
    launcher->files_to_process = thunar_g_list_copy_deep (selected_files);
  else
    launcher->files_to_process = g_list_append (launcher->files_to_process, g_object_ref (launcher->current_directory));

  /* determine the number of files/directories/executables */
  for (lp = launcher->files_to_process; lp != NULL; lp = lp->next, ++launcher->n_files_to_process)
    {
      if (thunar_file_is_directory (lp->data)
          || thunar_file_is_shortcut (lp->data)
          || thunar_file_is_mountable (lp->data))
        {
          ++launcher->n_directories_to_process;
          launcher->files_are_all_executable = FALSE;
        }
      else
        {
          if (launcher->files_are_all_executable && !thunar_file_is_executable (lp->data))
            launcher->files_are_all_executable = FALSE;
          ++launcher->n_regulars_to_process;
        }

      if (!thunar_file_can_be_trashed (lp->data))
        launcher->files_to_process_trashable = FALSE;
    }

  launcher->single_directory_to_process = (launcher->n_directories_to_process == 1 && launcher->n_files_to_process == 1);
  if (launcher->single_directory_to_process)
    {
      /* grab the folder of the first selected item */
      launcher->single_folder = THUNAR_FILE (launcher->files_to_process->data);
    }

  if (launcher->files_to_process != NULL)
    {
      /* just grab the folder of the first selected item */
      launcher->parent_folder = thunar_file_get_parent (THUNAR_FILE (launcher->files_to_process->data), NULL);
    }
}



 /**
 * thunar_launcher_set_widget:
 * @launcher : a #ThunarLauncher.
 * @widget   : a #GtkWidget or %NULL.
 *
 * Associates @launcher with @widget.
 **/
void
thunar_launcher_set_widget (ThunarLauncher *launcher,
                            GtkWidget      *widget)
{
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));
  _thunar_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));

  /* disconnect from the previous widget */
  if (G_UNLIKELY (launcher->widget != NULL))
    {
      g_signal_handlers_disconnect_by_func (G_OBJECT (launcher->widget), thunar_launcher_widget_destroyed, launcher);
      g_object_unref (G_OBJECT (launcher->widget));
    }

  launcher->widget = widget;

  /* connect to the new widget */
  if (G_LIKELY (widget != NULL))
    {
      g_object_ref (G_OBJECT (widget));
      g_signal_connect_swapped (G_OBJECT (widget), "destroy", G_CALLBACK (thunar_launcher_widget_destroyed), launcher);
    }

  /* notify listeners */
  g_object_notify_by_pspec (G_OBJECT (launcher), launcher_props[PROP_WIDGET]);
}



static gboolean
thunar_launcher_menu_item_activated (ThunarLauncher *launcher,
                                     GtkWidget      *menu_item)
{
  GAppInfo *app_info;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (G_UNLIKELY (launcher->files_to_process == NULL))
    return TRUE;

  /* if we have a mime handler associated with the menu_item, we pass it to the launcher (g_object_get_qdata will return NULL otherwise)*/
  app_info = g_object_get_qdata (G_OBJECT (menu_item), thunar_launcher_appinfo_quark);
  thunar_launcher_activate_selected_files (launcher, THUNAR_LAUNCHER_CHANGE_DIRECTORY, app_info);

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



/**
 * thunar_launcher_activate_selected_files:
 * @launcher : a #ThunarLauncher instance
 * @action   : the #ThunarLauncherFolderOpenAction to use, if there are folders among the selected files
 * @app_info : a #GAppInfo instance
 *
 * Will try to open all selected files with the provided #GAppInfo
 **/
void
thunar_launcher_activate_selected_files (ThunarLauncher                 *launcher,
                                         ThunarLauncherFolderOpenAction  action,
                                         GAppInfo                       *app_info)
{
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  thunar_launcher_poke (launcher, app_info, action);
}



static void
thunar_launcher_execute_files (ThunarLauncher *launcher,
                               GList          *files)
{
  GError *error = NULL;
  GFile  *working_directory;
  GList  *lp;

  /* execute all selected files */
  for (lp = files; lp != NULL; lp = lp->next)
    {
      ThunarFile  *file   = lp->data;
      GFile       *gfile  = thunar_file_get_file (file);

      working_directory = thunar_file_get_file (launcher->current_directory);
      gtk_recent_manager_add_item (gtk_recent_manager_get_default(), g_file_get_uri (gfile));

      if (!thunar_file_execute (lp->data, working_directory, launcher->widget, NULL, NULL, &error))
        {
          /* display an error message to the user */
          thunar_dialogs_show_error (launcher->widget, error, _("Failed to execute file \"%s\""), thunar_file_get_display_name (lp->data));
          g_error_free (error);
          break;
        }
    }
}



static guint
thunar_launcher_g_app_info_hash (gconstpointer app_info)
{
  return 0;
}



static void
thunar_launcher_open_files (ThunarLauncher *launcher,
                            GList          *files,
                            GAppInfo       *application_to_use)
{
  GHashTable *applications;
  GAppInfo   *app_info;
  GList      *file_list = NULL;
  GList      *lp;

  /* allocate a hash table to associate applications to URIs. since GIO allocates
   * new GAppInfo objects every time, g_direct_hash does not work. we therefore use
   * a fake hash function to always hit the collision list of the hash table and
   * avoid storing multiple equal GAppInfos by means of g_app_info_equal(). */
  applications = g_hash_table_new_full (thunar_launcher_g_app_info_hash,
                                        (GEqualFunc) g_app_info_equal,
                                        (GDestroyNotify) g_object_unref,
                                        (GDestroyNotify) thunar_g_list_free_full);

  for (lp = files; lp != NULL; lp = lp->next)
    {
      /* Because we created the hash_table with g_hash_table_new_full
       * g_object_unref on each hash_table key and value will be called by g_hash_table_destroy */
      if (application_to_use)
        {
          app_info = g_app_info_dup (application_to_use);

          /* Foreign data needs to be set explicitly to the new app_info */
          if (g_object_get_data (G_OBJECT (application_to_use), "skip-app-info-update") != NULL)
            g_object_set_data (G_OBJECT (app_info), "skip-app-info-update", GUINT_TO_POINTER (1));
        }
      else
        {
          /* determine the default application for the MIME type */
          app_info = thunar_file_get_default_handler (lp->data);
        }

      /* check if we have an application here */
      if (G_LIKELY (app_info != NULL))
        {
          /* check if we have that application already */
          /* Not possibly to check via g_hash_table_lookup directly, since that will only compare pointers */
          GList *keys = g_hash_table_get_keys (applications);
          for (GList *lp_keys = keys;  lp_keys != NULL; lp_keys = lp_keys->next)
            {
              if (thunar_g_app_info_equal (lp_keys->data, app_info))
                {
                  /* Reuse the existing appinfo instead of adding the new one to the list*/
                  g_object_unref (app_info);
                  app_info = g_object_ref (lp_keys->data);

                  file_list = g_hash_table_lookup (applications, app_info);

                  /* take a copy of the list as the old one will be dropped by the insert */
                  file_list = thunar_g_list_copy_deep (file_list);
                }
            }

          g_list_free (keys);

          /* append our new URI to the list */
          file_list = thunar_g_list_append_deep (file_list, thunar_file_get_file (lp->data));

          /* (re)insert the URI list for the application */
          g_hash_table_insert (applications, app_info, file_list);
        }
      else
        {
          /* display a chooser dialog for the file and stop */
          thunar_show_chooser_dialog (launcher->widget, lp->data, TRUE, TRUE);
          break;
        }
    }

  /* run all collected applications */
  g_hash_table_foreach (applications, (GHFunc) thunar_launcher_open_paths, launcher);

  /* drop the applications hash table */
  g_hash_table_destroy (applications);
}



static void
thunar_launcher_open_paths (GAppInfo       *app_info,
                            GList          *path_list,
                            ThunarLauncher *launcher)
{
  GdkAppLaunchContext *context;
  GdkScreen           *screen;
  GError              *error = NULL;
  GFile               *working_directory = NULL;
  gchar               *message;
  gchar               *name;
  guint                n;

  /* determine the screen on which to launch the application */
  screen = gtk_widget_get_screen (launcher->widget);

  /* create launch context */
  context = gdk_display_get_app_launch_context (gdk_screen_get_display (screen));
  gdk_app_launch_context_set_screen (context, screen);
  gdk_app_launch_context_set_timestamp (context, gtk_get_current_event_time ());
  gdk_app_launch_context_set_icon (context, g_app_info_get_icon (app_info));

  /* determine the working directory */
  if (launcher->current_directory != NULL)
    working_directory = thunar_file_get_file (launcher->current_directory);

  /* try to execute the application with the given URIs */
  if (!thunar_g_app_info_launch (app_info, working_directory, path_list, G_APP_LAUNCH_CONTEXT (context), &error))
    {
      /* figure out the appropriate error message */
      n = g_list_length (path_list);
      if (G_LIKELY (n == 1))
        {
          /* we can give a precise error message here */
          name = g_filename_display_name (g_file_get_basename (path_list->data));
          message = g_strdup_printf (_("Failed to open file \"%s\""), name);
          g_free (name);
        }
      else
        {
          /* we can just tell that n files failed to open */
          message = g_strdup_printf (ngettext ("Failed to open %d file", "Failed to open %d files", n), n);
        }

      /* display an error dialog to the user */
      thunar_dialogs_show_error (launcher->widget, error, "%s", message);
      g_error_free (error);
      g_free (message);
    }

  /* destroy the launch context */
  g_object_unref (context);
}



static void
thunar_launcher_open_windows (ThunarLauncher *launcher,
                              GList          *directories)
{
  ThunarApplication *application;
  GtkWidget         *dialog;
  GtkWidget         *window;
  GdkScreen         *screen;
  gchar             *label;
  GList             *lp;
  gint               response = GTK_RESPONSE_YES;
  gint               n;

  /* ask the user if we would open more than one new window */
  n = g_list_length (directories);
  if (G_UNLIKELY (n > 1))
    {
      /* open a message dialog */
      window = gtk_widget_get_toplevel (launcher->widget);
      dialog = gtk_message_dialog_new ((GtkWindow *) window,
                                       GTK_DIALOG_DESTROY_WITH_PARENT
                                       | GTK_DIALOG_MODAL,
                                       GTK_MESSAGE_QUESTION,
                                       GTK_BUTTONS_NONE,
                                       _("Are you sure you want to open all folders?"));
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                                ngettext ("This will open %d separate file manager window.",
                                                          "This will open %d separate file manager windows.",
                                                          n), n);
      label = g_strdup_printf (ngettext ("Open %d New Window", "Open %d New Windows", n), n);
      gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_CANCEL);
      gtk_dialog_add_button (GTK_DIALOG (dialog), label, GTK_RESPONSE_YES);
      gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
      response = gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);
      g_free (label);
    }

  /* open n new windows if the user approved it */
  if (G_LIKELY (response == GTK_RESPONSE_YES))
    {
      /* query the application object */
      application = thunar_application_get ();

      /* determine the screen on which to open the new windows */
      screen = gtk_widget_get_screen (launcher->widget);

      /* open all requested windows */
      for (lp = directories; lp != NULL; lp = lp->next)
        thunar_application_open_window (application, lp->data, screen, NULL, TRUE);

      /* release the application object */
      g_object_unref (G_OBJECT (application));
    }
}



static void
thunar_launcher_poke (ThunarLauncher                 *launcher,
                      GAppInfo                       *application_to_use,
                      ThunarLauncherFolderOpenAction  folder_open_action)
{
  ThunarLauncherPokeData *poke_data;

  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

   if (launcher->files_to_process == NULL)
     {
       g_warning("No files to process. thunar_launcher_poke aborted.");
       return;
     }

   poke_data = thunar_launcher_poke_data_new (launcher->files_to_process,
                                              application_to_use,
                                              folder_open_action,
                                              launcher->location_to_process,
                                              launcher->device_to_process);

   if (launcher->device_to_process != NULL)
     {
       g_signal_emit (launcher, launcher_signals[DEVICE_OPERATION_STARTED], 0, launcher->device_to_process);
       thunar_browser_poke_device (THUNAR_BROWSER (launcher), launcher->device_to_process,
                                   launcher->widget, thunar_launcher_poke_device_finish,
                                  poke_data);
     }
   else if (launcher->location_to_process != NULL)
     {
       thunar_browser_poke_location (THUNAR_BROWSER (launcher), poke_data->location_to_poke,
                                     launcher->widget, thunar_launcher_poke_location_finish,
                                     poke_data);
     }
   else
     {
      // We will only poke one file at a time, in order to dont use all available CPU's
      // TODO: Check if that could cause slowness
      thunar_browser_poke_file (THUNAR_BROWSER (launcher), poke_data->files_to_poke->data,
                                launcher->widget, thunar_launcher_poke_files_finish,
                                poke_data);
     }
}



static void thunar_launcher_poke_device_finish (ThunarBrowser *browser,
                                                ThunarDevice  *volume,
                                                ThunarFile    *mount_point,
                                                GError        *error,
                                                gpointer       user_data,
                                                gboolean       cancelled)
{
  ThunarLauncherPokeData *poke_data = user_data;
  gchar                  *device_name;

  if (error != NULL)
    {
      device_name = thunar_device_get_name (volume);
      thunar_dialogs_show_error (GTK_WIDGET (THUNAR_LAUNCHER (browser)->widget), error, _("Failed to mount \"%s\""), device_name);
      g_free (device_name);
    }

  if (cancelled == TRUE || error != NULL || mount_point == NULL)
    {
      g_signal_emit (browser, launcher_signals[DEVICE_OPERATION_FINISHED], 0, volume);
      thunar_launcher_poke_data_free (poke_data);
      return;
    }

  if (poke_data->folder_open_action == THUNAR_LAUNCHER_OPEN_AS_NEW_TAB)
    {
      thunar_navigator_open_new_tab (THUNAR_NAVIGATOR (browser), mount_point);
    }
  else if (poke_data->folder_open_action == THUNAR_LAUNCHER_OPEN_AS_NEW_WINDOW)
    {
      GList *directories = NULL;
      directories = g_list_append (directories, mount_point);
      thunar_launcher_open_windows (THUNAR_LAUNCHER (browser), directories);
      g_list_free (directories);
    }
  else if (poke_data->folder_open_action == THUNAR_LAUNCHER_CHANGE_DIRECTORY)
    {
      thunar_navigator_change_directory (THUNAR_NAVIGATOR (browser), mount_point);
    }

  g_signal_emit (browser, launcher_signals[DEVICE_OPERATION_FINISHED], 0, volume);
  thunar_launcher_poke_data_free (poke_data);
}



static void
thunar_launcher_poke_location_finish (ThunarBrowser *browser,
                                      GFile         *location,
                                      ThunarFile    *file,
                                      ThunarFile    *target_file,
                                      GError        *error,
                                      gpointer       user_data)
{
  ThunarLauncherPokeData *poke_data = user_data;
  _thunar_return_if_fail (THUNAR_IS_BROWSER (browser));

  if (error != NULL)
    {
      gchar* path = g_file_get_path (location);
      thunar_dialogs_show_error (GTK_WIDGET (THUNAR_LAUNCHER (browser)->widget), error,
                                 _("Failed to open \"%s\""), path);
      g_free (path);
      thunar_launcher_poke_data_free (poke_data);
      return;
    }

  thunar_launcher_poke_files_finish (browser, file, target_file, error, user_data);
}



static void
thunar_launcher_poke_files_finish (ThunarBrowser *browser,
                                   ThunarFile    *file,
                                   ThunarFile    *target_file,
                                   GError        *error,
                                   gpointer       user_data)
{
  ThunarLauncherPokeData *poke_data = user_data;
  gboolean                executable = TRUE;
  gboolean                open_new_window_as_tab = TRUE;
  GList                  *directories = NULL;
  GList                  *files = NULL;
  GList                  *lp;

  _thunar_return_if_fail (THUNAR_IS_BROWSER (browser));
  _thunar_return_if_fail (THUNAR_IS_FILE (file));
  _thunar_return_if_fail (poke_data != NULL);
  _thunar_return_if_fail (poke_data->files_to_poke != NULL);

  /* check if poking succeeded */
  if (error == NULL)
    {
      /* add opened file to `recent:///` */
      GFile *gfile = thunar_file_get_file (target_file);
      gtk_recent_manager_add_item (gtk_recent_manager_get_default(), g_file_get_uri (gfile));

      /* add the resolved file to the list of file to be opened/executed later */
      poke_data->files_poked = g_list_prepend (poke_data->files_poked,g_object_ref (target_file));
    }

  /* release and remove the just poked file from the list */
  g_object_unref (poke_data->files_to_poke->data);
  poke_data->files_to_poke = g_list_delete_link (poke_data->files_to_poke, poke_data->files_to_poke);

  if (poke_data->files_to_poke == NULL)
    {
      /* separate files and directories in the selected files list */
      for (lp = poke_data->files_poked; lp != NULL; lp = lp->next)
        {
          if (thunar_file_is_directory (lp->data))
            {
              /* add to our directory list */
              directories = g_list_prepend (directories, lp->data);
            }
          else
            {
              /* add to our file list */
              files = g_list_prepend (files, lp->data);

              /* check if the file is executable */
              executable = (executable && thunar_file_is_executable (lp->data));
            }
        }

      /* check if we have any directories to process */
      if (G_LIKELY (directories != NULL))
        {
          if (poke_data->application_to_use != NULL)
            {
              thunar_launcher_open_files (THUNAR_LAUNCHER (browser), directories, poke_data->application_to_use);
            }
          else if (poke_data->folder_open_action == THUNAR_LAUNCHER_OPEN_AS_NEW_TAB)
            {
              for (lp = directories; lp != NULL; lp = lp->next)
                thunar_navigator_open_new_tab (THUNAR_NAVIGATOR (browser), lp->data);
            }
          else if (poke_data->folder_open_action == THUNAR_LAUNCHER_OPEN_AS_NEW_WINDOW)
            {
              thunar_launcher_open_windows (THUNAR_LAUNCHER (browser), directories);
            }
          else if (poke_data->folder_open_action == THUNAR_LAUNCHER_CHANGE_DIRECTORY)
            {
              /* If multiple directories are passed, we assume that we should open them all */
              if (directories->next == NULL)
                thunar_navigator_change_directory (THUNAR_NAVIGATOR (browser), directories->data);
              else
                {
                  g_object_get (G_OBJECT (THUNAR_LAUNCHER (browser)->preferences), "misc-open-new-window-as-tab", &open_new_window_as_tab, NULL);
                  if (open_new_window_as_tab)
                    {
                      for (lp = directories; lp != NULL; lp = lp->next)
                        thunar_navigator_open_new_tab (THUNAR_NAVIGATOR (browser), lp->data);
                    }
                  else
                    thunar_launcher_open_windows (THUNAR_LAUNCHER (browser), directories);
                }
            }
          else if (poke_data->folder_open_action == THUNAR_LAUNCHER_NO_ACTION)
            {
              // nothing to do
            }
          else
              g_warning("'folder_open_action' was not defined");
          g_list_free (directories);
        }

      /* check if we have any files to process */
      if (G_LIKELY (files != NULL))
        {
          /* if all files are executable, we just run them here */
          if (G_UNLIKELY (executable) && poke_data->application_to_use == NULL)
            {
              /* try to execute all given files */
              thunar_launcher_execute_files (THUNAR_LAUNCHER (browser), files);
            }
          else
            {
              /* try to open all files */
              thunar_launcher_open_files (THUNAR_LAUNCHER (browser), files, poke_data->application_to_use);
            }

          /* cleanup */
          g_list_free (files);
        }

      /* free the poke data */
      thunar_launcher_poke_data_free (poke_data);
    }
  else
    {
      /* we need to continue this until all files have been resolved */
      // We will only poke one file at a time, in order to dont use all available CPU's
      // TODO: Check if that could cause slowness
      thunar_browser_poke_file (browser, poke_data->files_to_poke->data,
                                (THUNAR_LAUNCHER (browser))->widget, thunar_launcher_poke_files_finish, poke_data);
    }
}



static ThunarLauncherPokeData *
thunar_launcher_poke_data_new (GList                          *files_to_poke,
                               GAppInfo                       *application_to_use,
                               ThunarLauncherFolderOpenAction  folder_open_action,
                               GFile                          *location_to_poke,
                               ThunarDevice                   *device_to_poke)
{
  ThunarLauncherPokeData *data;

  data = g_slice_new0 (ThunarLauncherPokeData);
  data->files_to_poke = thunar_g_list_copy_deep (files_to_poke);
  data->files_poked = NULL;
  data->application_to_use = application_to_use;

  if (location_to_poke != NULL)
    data->location_to_poke = g_object_ref (location_to_poke);

  if (device_to_poke != NULL)
    data->device_to_poke = g_object_ref (device_to_poke);

  /* keep a reference on the appdata */
  if (application_to_use != NULL)
    g_object_ref (application_to_use);
  data->folder_open_action = folder_open_action;

  return data;
}



static void
thunar_launcher_poke_data_free (ThunarLauncherPokeData *data)
{
  _thunar_return_if_fail (data != NULL);

  thunar_g_list_free_full (data->files_to_poke);
  thunar_g_list_free_full (data->files_poked);

  if (data->location_to_poke != NULL)
    g_object_unref (data->location_to_poke);

  if (data->device_to_poke != NULL)
    g_object_unref (data->device_to_poke);

  if (data->application_to_use != NULL)
    g_object_unref (data->application_to_use);
  g_slice_free (ThunarLauncherPokeData, data);
}



static void
thunar_launcher_widget_destroyed (ThunarLauncher *launcher,
                                  GtkWidget      *widget)
{
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));
  _thunar_return_if_fail (launcher->widget == widget);
  _thunar_return_if_fail (GTK_IS_WIDGET (widget));

  /* just reset the widget property for the launcher */
  thunar_launcher_set_widget (launcher, NULL);
}



/**
 * thunar_launcher_open_selected_folders:
 * @launcher : a #ThunarLauncher instance
 * @open_in_tabs : TRUE to open each folder in a new tab, FALSE to open each folder in a new window
 *
 * Will open each selected folder in a new tab/window
 **/
void thunar_launcher_open_selected_folders (ThunarLauncher *launcher,
                                            gboolean        open_in_tabs)
{
  GList *lp;

  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  for (lp = launcher->files_to_process; lp != NULL; lp = lp->next)
    _thunar_return_if_fail (thunar_file_is_directory (THUNAR_FILE (lp->data)));

  if (open_in_tabs)
    thunar_launcher_poke (launcher, NULL, THUNAR_LAUNCHER_OPEN_AS_NEW_TAB);
  else
    thunar_launcher_poke (launcher, NULL, THUNAR_LAUNCHER_OPEN_AS_NEW_WINDOW);
}



static gboolean
thunar_launcher_action_open (ThunarLauncher *launcher)
{
  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (G_UNLIKELY (launcher->files_to_process == NULL))
    return TRUE;

  thunar_launcher_activate_selected_files (launcher, THUNAR_LAUNCHER_CHANGE_DIRECTORY, NULL);

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



/**
 * thunar_launcher_action_open_in_new_tabs:
 * @launcher : a #ThunarLauncher instance
 *
 * Will open each selected folder in a new tab
 **/
static gboolean
thunar_launcher_action_open_in_new_tabs (ThunarLauncher *launcher)
{
  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (G_UNLIKELY (launcher->files_to_process == NULL))
    return TRUE;

  thunar_launcher_open_selected_folders (launcher, TRUE);

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static gboolean
thunar_launcher_action_open_in_new_windows (ThunarLauncher *launcher)
{
  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (G_UNLIKELY (launcher->files_to_process == NULL))
    return TRUE;

  thunar_launcher_open_selected_folders (launcher, FALSE);

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



void
thunar_launcher_set_searching (ThunarLauncher *launcher,
                               gboolean        b)
{
  launcher->is_searching = b;
}



static gboolean
thunar_launcher_action_open_location (ThunarLauncher *launcher)
{
  GList *lp;
  GList *gfiles = NULL;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (G_UNLIKELY (launcher->files_to_process == NULL))
    return TRUE;

  for (lp = launcher->files_to_process; lp != NULL; lp = lp->next)
    gfiles = g_list_prepend (gfiles, thunar_file_get_file (THUNAR_FILE (lp->data)));

  thunar_window_open_files_in_location (THUNAR_WINDOW (launcher->widget), gfiles);

  g_list_free (gfiles);

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static gboolean
thunar_launcher_action_open_with_other (ThunarLauncher *launcher)
{
  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (launcher->n_files_to_process == 1)
    thunar_show_chooser_dialog (launcher->widget, launcher->files_to_process->data, TRUE, FALSE);

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



/**
 * thunar_launcher_action_set_default_app:
 * @launcher : a #ThunarLauncher instance
 *
 * Choose an application which should be used by default to open the selected file
 **/
static gboolean
thunar_launcher_action_set_default_app (ThunarLauncher *launcher)
{
  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (launcher->n_files_to_process == 1)
    thunar_show_chooser_dialog (launcher->widget, launcher->files_to_process->data, TRUE, TRUE);

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



/**
 * thunar_launcher_append_accelerators:
 * @launcher    : a #ThunarLauncher.
 * @accel_group : a #GtkAccelGroup to be used used for new menu items
 *
 * Connects all accelerators and corresponding default keys of this widget to the global accelerator list
 **/
void thunar_launcher_append_accelerators (ThunarLauncher *launcher,
                                          GtkAccelGroup  *accel_group)
{
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  xfce_gtk_accel_map_add_entries (thunar_launcher_action_entries, G_N_ELEMENTS (thunar_launcher_action_entries));
  xfce_gtk_accel_group_connect_action_entries (accel_group,
                                               thunar_launcher_action_entries,
                                               G_N_ELEMENTS (thunar_launcher_action_entries),
                                               launcher);
}



static gboolean
thunar_launcher_show_trash (ThunarLauncher *launcher)
{
  if (launcher->parent_folder == NULL)
    return FALSE;

  /* If the folder is read only, always show trash insensitive */
  /* If we are outside waste basket, the selection is trashable and we support trash, show trash */
  return !thunar_file_is_writable (launcher->parent_folder) || ( !thunar_file_is_trashed (launcher->parent_folder) && launcher->files_to_process_trashable && thunar_g_vfs_is_uri_scheme_supported ("trash"));
}



/**
 * thunar_launcher_append_menu_item:
 * @launcher       : Instance of a  #ThunarLauncher
 * @menu           : #GtkMenuShell to which the item should be added
 * @action         : #ThunarLauncherAction to select which item should be added
 * @force          : force to generate the item. If it cannot be used, it will be shown as insensitive
 *
 * Adds the selected, widget specific #GtkMenuItem to the passed #GtkMenuShell
 *
 * Return value: (transfer none): The added #GtkMenuItem
 **/
GtkWidget*
thunar_launcher_append_menu_item (ThunarLauncher       *launcher,
                                  GtkMenuShell         *menu,
                                  ThunarLauncherAction  action,
                                  gboolean              force)
{
  GtkWidget                *item = NULL;
  GtkWidget                *submenu;
  GtkWidget                *focused_widget;
  gchar                    *label_text;
  gchar                    *tooltip_text;
  const XfceGtkActionEntry *action_entry = get_action_entry (action);
  gboolean                  show_delete_item;
  gboolean                  show_item;
  ThunarClipboardManager   *clipboard;
  ThunarFile               *parent;
  gint                      n;
  const gchar              *eject_label;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), NULL);
  _thunar_return_val_if_fail (action_entry != NULL, NULL);

  /* This may occur when the thunar-window is build */
  if (G_UNLIKELY (launcher->files_to_process == NULL) && launcher->device_to_process == NULL)
    return NULL;

  switch (action)
    {
      case THUNAR_LAUNCHER_ACTION_OPEN: /* aka "activate" */
        return xfce_gtk_image_menu_item_new_from_icon_name (_("_Open"), ngettext ("Open the selected file", "Open the selected files", launcher->n_files_to_process),
                                           action_entry->accel_path, action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu);

      case THUNAR_LAUNCHER_ACTION_EXECUTE:
        return xfce_gtk_image_menu_item_new_from_icon_name (_("_Execute"), ngettext ("Execute the selected file", "Execute the selected files", launcher->n_files_to_process),
                                           action_entry->accel_path, action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu);

      case THUNAR_LAUNCHER_ACTION_OPEN_IN_TAB:
        n = launcher->n_files_to_process > 0 ? launcher->n_files_to_process : 1;
        label_text = g_strdup_printf (ngettext ("Open in New _Tab", "Open in %d New _Tabs", n), n);
        tooltip_text = g_strdup_printf (ngettext ("Open the selected directory in new tab",
                                                  "Open the selected directories in %d new tabs", n), n);
        item = xfce_gtk_menu_item_new (label_text, tooltip_text, action_entry->accel_path, action_entry->callback, G_OBJECT (launcher), menu);
        g_free (tooltip_text);
        g_free (label_text);
        return item;

      case THUNAR_LAUNCHER_ACTION_OPEN_IN_WINDOW:
        n = launcher->n_files_to_process > 0 ? launcher->n_files_to_process : 1;
        label_text = g_strdup_printf (ngettext ("Open in New _Window", "Open in %d New _Windows", n), n);
        tooltip_text = g_strdup_printf (ngettext ("Open the selected directory in new window",
                                                  "Open the selected directories in %d new windows",n), n);
        item = xfce_gtk_menu_item_new (label_text, tooltip_text, action_entry->accel_path, action_entry->callback, G_OBJECT (launcher), menu);
        g_free (tooltip_text);
        g_free (label_text);
        return item;

      case THUNAR_LAUNCHER_ACTION_OPEN_WITH_OTHER:
        return xfce_gtk_menu_item_new (action_entry->menu_item_label_text, action_entry->menu_item_tooltip_text,
                                       action_entry->accel_path, action_entry->callback, G_OBJECT (launcher), menu);

      case THUNAR_LAUNCHER_ACTION_SET_DEFAULT_APP:
        if (launcher->n_files_to_process != 1)
          return NULL;
        return xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu));

      case THUNAR_LAUNCHER_ACTION_SENDTO_MENU:
        if (launcher->files_are_selected == FALSE)
          return NULL;
        item = xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu));
        submenu = thunar_launcher_build_sendto_submenu (launcher);
        gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
        return item;

      case THUNAR_LAUNCHER_ACTION_SENDTO_SHORTCUTS:
        {
          if (launcher->n_directories_to_process > 0)
            return xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu));
          return NULL;
        }

      case THUNAR_LAUNCHER_ACTION_MAKE_LINK:
        show_item = thunar_file_is_writable (launcher->current_directory) &&
                    launcher->files_are_selected &&
                    thunar_file_is_trash (launcher->current_directory) == FALSE;
        if (!show_item && !force)
          return NULL;

        label_text = ngettext ("Ma_ke Link", "Ma_ke Links", launcher->n_files_to_process);
        tooltip_text = ngettext ("Create a symbolic link for the selected file",
                                 "Create a symbolic link for each selected file", launcher->n_files_to_process);
        item = xfce_gtk_menu_item_new (label_text, tooltip_text, action_entry->accel_path, action_entry->callback,
                                       G_OBJECT (launcher), menu);
        gtk_widget_set_sensitive (item, show_item && launcher->parent_folder != NULL && thunar_file_is_writable (launcher->parent_folder));
        return item;

      case THUNAR_LAUNCHER_ACTION_DUPLICATE:
        show_item = thunar_file_is_writable (launcher->current_directory) &&
                    launcher->files_are_selected &&
                    thunar_file_is_trash (launcher->current_directory) == FALSE;
        if (!show_item && !force)
          return NULL;
        item = xfce_gtk_menu_item_new (action_entry->menu_item_label_text, action_entry->menu_item_tooltip_text,
                                       action_entry->accel_path, action_entry->callback, G_OBJECT (launcher), menu);
        gtk_widget_set_sensitive (item, show_item && launcher->parent_folder != NULL && thunar_file_is_writable (launcher->parent_folder));
        return item;

      case THUNAR_LAUNCHER_ACTION_RENAME:
        show_item = thunar_file_is_writable (launcher->current_directory) &&
                    launcher->files_are_selected &&
                    thunar_file_is_trash (launcher->current_directory) == FALSE;
        if (!show_item && !force)
          return NULL;
        tooltip_text = ngettext ("Rename the selected file",
                                 "Rename the selected files", launcher->n_files_to_process);
        item = xfce_gtk_menu_item_new (action_entry->menu_item_label_text, tooltip_text, action_entry->accel_path,
                                       action_entry->callback, G_OBJECT (launcher), menu);
        gtk_widget_set_sensitive (item, show_item && launcher->parent_folder != NULL && thunar_file_is_writable (launcher->parent_folder));
        return item;

      case THUNAR_LAUNCHER_ACTION_RESTORE:
        if (launcher->files_are_selected && thunar_file_is_trash (launcher->current_directory))
          {
            tooltip_text = ngettext ("Restore the selected file to its original location",
                                     "Restore the selected files to its original location", launcher->n_files_to_process);
            item = xfce_gtk_menu_item_new (action_entry->menu_item_label_text, tooltip_text, action_entry->accel_path,
                                           action_entry->callback, G_OBJECT (launcher), menu);
            gtk_widget_set_sensitive (item, thunar_file_is_writable (launcher->current_directory));
            return item;
          }
        return NULL;

      case THUNAR_LAUNCHER_ACTION_RESTORE_SHOW:
        if (launcher->files_are_selected && thunar_file_is_trash (launcher->current_directory))
          {
            tooltip_text = ngettext ("Restore the selected file to its original location and open the location in a new window/tab",
                                     "Restore the selected files to their original locations and open the locations in a new window/tab", launcher->n_files_to_process);
            item = xfce_gtk_menu_item_new (action_entry->menu_item_label_text, tooltip_text, action_entry->accel_path,
                                           action_entry->callback, G_OBJECT (launcher), menu);
            gtk_widget_set_sensitive (item, thunar_file_is_writable (launcher->current_directory));
            return item;
          }
      return NULL;

      case THUNAR_LAUNCHER_ACTION_MOVE_TO_TRASH:
        if (!thunar_launcher_show_trash (launcher))
          return NULL;

        show_item = launcher->files_are_selected;
        if (!show_item && !force)
          return NULL;

        tooltip_text = ngettext ("Move the selected file to the Trash",
                                 "Move the selected files to the Trash", launcher->n_files_to_process);
        item = xfce_gtk_image_menu_item_new_from_icon_name (action_entry->menu_item_label_text, tooltip_text, action_entry->accel_path,
                                                            action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu);
        gtk_widget_set_sensitive (item, show_item && launcher->parent_folder != NULL && thunar_file_is_writable (launcher->parent_folder));
        return item;


      case THUNAR_LAUNCHER_ACTION_DELETE:
        g_object_get (G_OBJECT (launcher->preferences), "misc-show-delete-action", &show_delete_item, NULL);
        if (thunar_launcher_show_trash (launcher) && !show_delete_item)
          return NULL;

        show_item = launcher->files_are_selected;
        if (!show_item && !force)
          return NULL;

        tooltip_text = ngettext ("Permanently delete the selected file",
                                 "Permanently delete the selected files", launcher->n_files_to_process);
        item = xfce_gtk_image_menu_item_new_from_icon_name (action_entry->menu_item_label_text, tooltip_text, action_entry->accel_path,
                                                            action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu);
        gtk_widget_set_sensitive (item, show_item && launcher->parent_folder != NULL && thunar_file_is_writable (launcher->parent_folder));
        return item;

      case THUNAR_LAUNCHER_ACTION_EMPTY_TRASH:
        if (launcher->single_directory_to_process == TRUE)
          {
            if (thunar_file_is_trash (launcher->single_folder))
              {
                item = xfce_gtk_image_menu_item_new_from_icon_name (action_entry->menu_item_label_text, action_entry->menu_item_tooltip_text, action_entry->accel_path,
                                                                    action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu);
                gtk_widget_set_sensitive (item, thunar_file_get_item_count (launcher->single_folder) > 0);
                return item;
              }
          }
        return NULL;

      case THUNAR_LAUNCHER_ACTION_REMOVE_FROM_RECENT:
        if (launcher->files_are_selected && thunar_file_is_recent (launcher->current_directory))
          {
            item = xfce_gtk_image_menu_item_new_from_icon_name (action_entry->menu_item_label_text, action_entry->menu_item_tooltip_text, action_entry->accel_path,
                                                                action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu);
            return item;
          }
        return NULL;

      case THUNAR_LAUNCHER_ACTION_CREATE_FOLDER:
        if (THUNAR_IS_TREE_VIEW (launcher->widget) && launcher->files_are_selected && launcher->single_directory_to_process)
          parent = launcher->single_folder;
        else
          parent = launcher->current_directory;
        if (thunar_file_is_trash (parent))
          return NULL;
        item = xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu));
        gtk_widget_set_sensitive (item, thunar_file_is_writable (parent));
        return item;

      case THUNAR_LAUNCHER_ACTION_CREATE_DOCUMENT:
        if (THUNAR_IS_TREE_VIEW (launcher->widget) && launcher->files_are_selected && launcher->single_directory_to_process)
          parent = launcher->single_folder;
        else
          parent = launcher->current_directory;
        if (thunar_file_is_trash (parent))
          return NULL;
        item = xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu));
        submenu = thunar_launcher_create_document_submenu_new (launcher);
        gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
        gtk_widget_set_sensitive (item, thunar_file_is_writable (parent));
        return item;

      case THUNAR_LAUNCHER_ACTION_CUT:
        focused_widget = thunar_gtk_get_focused_widget();
        if (focused_widget && GTK_IS_EDITABLE (focused_widget))
          {
            item = xfce_gtk_image_menu_item_new_from_icon_name (
                          action_entry->menu_item_label_text,
                          N_ ("Cut the selection"),
                          action_entry->accel_path, G_CALLBACK (gtk_editable_cut_clipboard),
                          G_OBJECT (focused_widget), action_entry->menu_item_icon_name, menu);
            gtk_widget_set_sensitive (item, thunar_gtk_editable_can_cut (GTK_EDITABLE (focused_widget)));
          }
        else
          {
            show_item = launcher->files_are_selected;
            if (!show_item && !force)
              return NULL;
            tooltip_text = ngettext ("Prepare the selected file to be moved with a Paste command",
                                     "Prepare the selected files to be moved with a Paste command", launcher->n_files_to_process);
            item = xfce_gtk_image_menu_item_new_from_icon_name (action_entry->menu_item_label_text, tooltip_text, action_entry->accel_path,
                                                                action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu);
            gtk_widget_set_sensitive (item, show_item && launcher->parent_folder != NULL && thunar_file_is_writable (launcher->parent_folder));
          }
        return item;

      case THUNAR_LAUNCHER_ACTION_COPY:
        focused_widget = thunar_gtk_get_focused_widget();
        if (focused_widget && GTK_IS_EDITABLE (focused_widget))
          {
            item = xfce_gtk_image_menu_item_new_from_icon_name (
                          action_entry->menu_item_label_text,
                          N_ ("Copy the selection"),
                          action_entry->accel_path,G_CALLBACK (gtk_editable_copy_clipboard),
                          G_OBJECT (focused_widget), action_entry->menu_item_icon_name, menu);
            gtk_widget_set_sensitive (item, thunar_gtk_editable_can_copy (GTK_EDITABLE (focused_widget)));
          }
        else
          {
            show_item = launcher->files_are_selected;
            if (!show_item && !force)
              return NULL;
            tooltip_text = ngettext ("Prepare the selected file to be copied with a Paste command",
                                    "Prepare the selected files to be copied with a Paste command", launcher->n_files_to_process);
            item = xfce_gtk_image_menu_item_new_from_icon_name (action_entry->menu_item_label_text, tooltip_text, action_entry->accel_path,
                                                                action_entry->callback, G_OBJECT (launcher), action_entry->menu_item_icon_name, menu);
            gtk_widget_set_sensitive (item, show_item);
          }
        return item;

      case THUNAR_LAUNCHER_ACTION_PASTE_INTO_FOLDER:
        if (!launcher->single_directory_to_process)
          return NULL;
        clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (launcher->widget));
        item = xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu));
        gtk_widget_set_sensitive (item, thunar_clipboard_manager_get_can_paste (clipboard) && thunar_file_is_writable (launcher->single_folder));
        g_object_unref (clipboard);
        return item;

      case THUNAR_LAUNCHER_ACTION_PASTE:
        focused_widget = thunar_gtk_get_focused_widget();
        if (focused_widget && GTK_IS_EDITABLE (focused_widget))
          {
            item = xfce_gtk_image_menu_item_new_from_icon_name (
                          action_entry->menu_item_label_text,
                          N_ ("Paste the clipboard"),
                          action_entry->accel_path,G_CALLBACK (gtk_editable_paste_clipboard),
                          G_OBJECT (focused_widget), action_entry->menu_item_icon_name, menu);
            gtk_widget_set_sensitive (item, thunar_gtk_editable_can_paste (GTK_EDITABLE (focused_widget)));
          }
        else
          {
            if (launcher->single_directory_to_process && launcher->files_are_selected)
                return thunar_launcher_append_menu_item (launcher, menu, THUNAR_LAUNCHER_ACTION_PASTE_INTO_FOLDER, force);
            clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (launcher->widget));
            item = xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu));
            gtk_widget_set_sensitive (item, thunar_clipboard_manager_get_can_paste (clipboard) && thunar_file_is_writable (launcher->current_directory));
            g_object_unref (clipboard);
          }
        return item;

      case THUNAR_LAUNCHER_ACTION_MOUNT:
        if (launcher->device_to_process == NULL || thunar_device_is_mounted (launcher->device_to_process) == TRUE)
          return NULL;
        return xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu));

      case THUNAR_LAUNCHER_ACTION_UNMOUNT:
        if (launcher->device_to_process == NULL || thunar_device_is_mounted (launcher->device_to_process) == FALSE)
          return NULL;
        return xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu));

      case THUNAR_LAUNCHER_ACTION_EJECT:
        if (launcher->device_to_process == NULL || thunar_device_get_kind (launcher->device_to_process) != THUNAR_DEVICE_KIND_VOLUME)
          return NULL;
        item = xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu));
        gtk_widget_set_sensitive (item, thunar_device_can_eject (launcher->device_to_process));
        eject_label = thunar_device_get_eject_label (launcher->device_to_process);
        gtk_menu_item_set_label (GTK_MENU_ITEM (item), eject_label);
        return item;

      default:
        return xfce_gtk_menu_item_new_from_action_entry (action_entry, G_OBJECT (launcher), GTK_MENU_SHELL (menu));
    }
  return NULL;
}




static gboolean
thunar_launcher_action_sendto_desktop (ThunarLauncher *launcher)
{
  ThunarApplication *application;
  GFile             *desktop_file;
  GList             *files;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  /* determine the source paths */
  files = thunar_file_list_to_thunar_g_file_list (launcher->files_to_process);
  if (G_UNLIKELY (files == NULL))
    return TRUE;

  /* determine the file to the ~/Desktop folder */
  desktop_file = thunar_g_file_new_for_desktop ();

  /* launch the link job */
  application = thunar_application_get ();
  thunar_application_link_into (application, launcher->widget, files, desktop_file, NULL);
  g_object_unref (G_OBJECT (application));

  /* cleanup */
  g_object_unref (desktop_file);
  thunar_g_list_free_full (files);

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static void
thunar_launcher_sendto_device (ThunarLauncher *launcher,
                               ThunarDevice   *device)
{
  ThunarApplication *application;
  GFile             *mount_point;
  GList             *files;

  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));
  _thunar_return_if_fail (THUNAR_IS_DEVICE (device));

  if (!thunar_device_is_mounted (device))
    return;

  /* determine the source paths */
  files = thunar_file_list_to_thunar_g_file_list (launcher->files_to_process);
  if (G_UNLIKELY (files == NULL))
    return;

  mount_point = thunar_device_get_root (device);
  if (mount_point != NULL)
    {
      /* copy the files onto the specified device */
      application = thunar_application_get ();
      thunar_application_copy_into (application, launcher->widget, files, mount_point, NULL);
      g_object_unref (application);
      g_object_unref (mount_point);
    }

  /* cleanup */
  thunar_g_list_free_full (files);
}



static void
thunar_launcher_sendto_mount_finish (ThunarDevice *device,
                                     const GError *error,
                                     gpointer      user_data)
{
  ThunarLauncher *launcher = user_data;
  gchar          *device_name;

  _thunar_return_if_fail (THUNAR_IS_DEVICE (device));
  _thunar_return_if_fail (user_data != NULL);
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (user_data));

  if (error != NULL)
    {
      /* tell the user that we were unable to mount the device, which is
       * required to send files to it */
      device_name = thunar_device_get_name (device);
      thunar_dialogs_show_error (launcher->widget, error, _("Failed to mount \"%s\""), device_name);
      g_free (device_name);
    }
  else
    {
      thunar_launcher_sendto_device (launcher, device);
    }
}



static gboolean
thunar_launcher_action_sendto_device (ThunarLauncher *launcher,
                                      GObject        *object)
{
  GMountOperation *mount_operation;
  ThunarDevice    *device;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  /* determine the device to which to send */
  device = g_object_get_qdata (G_OBJECT (object), thunar_launcher_device_quark);
  if (G_UNLIKELY (device == NULL))
    return TRUE;

  /* make sure to mount the device first, if it's not already mounted */
  if (!thunar_device_is_mounted (device))
    {
      /* allocate a GTK+ mount operation */
      mount_operation = thunar_gtk_mount_operation_new (launcher->widget);

      /* try to mount the device and later start sending the files */
      thunar_device_mount (device,
                           mount_operation,
                           NULL,
                           thunar_launcher_sendto_mount_finish,
                           launcher);

      g_object_unref (mount_operation);
    }
  else
    {
      thunar_launcher_sendto_device (launcher, device);
    }

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}


static gboolean
thunar_launcher_action_add_shortcuts (ThunarLauncher *launcher)
{
  GList           *lp;
  GtkWidget       *window;
  const GtkWidget *sidepane;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  /* determine the toplevel window we belong to */
  window = gtk_widget_get_toplevel (launcher->widget);
  if (THUNAR_IS_WINDOW (window) == FALSE)
    return FALSE;
  if (thunar_window_has_shortcut_sidepane (THUNAR_WINDOW (window)) == FALSE)
    return TRUE;

  sidepane = thunar_window_get_sidepane (THUNAR_WINDOW (window));
  if (sidepane != NULL  && THUNAR_IS_SHORTCUTS_PANE (sidepane))
    {
      for (lp = launcher->files_to_process; lp != NULL; lp = lp->next)
        thunar_shortcuts_pane_add_shortcut (THUNAR_SHORTCUTS_PANE (sidepane), lp->data);
    }

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static GtkWidget*
thunar_launcher_build_sendto_submenu (ThunarLauncher *launcher)
{
  GList                    *lp;
  gboolean                  linkable = TRUE;
  gchar                    *label_text;
  gchar                    *tooltip_text;
  GtkWidget                *image;
  GtkWidget                *item;
  GtkWidget                *submenu;
  GtkWidget                *window;
  GList                    *devices;
  GList                    *appinfo_list;
  GIcon                    *icon;
  ThunarDeviceMonitor      *device_monitor;
  ThunarSendtoModel        *sendto_model;
  const XfceGtkActionEntry *action_entry;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), NULL);

  submenu = gtk_menu_new();

  /* show "sent to shortcut" if only directories are selected */
  if (launcher->n_directories_to_process > 0 && launcher->n_directories_to_process == launcher->n_files_to_process)
    {
      /* determine the toplevel window we belong to */
      window = gtk_widget_get_toplevel (launcher->widget);
      if (THUNAR_IS_WINDOW (window) && thunar_window_has_shortcut_sidepane (THUNAR_WINDOW (window)))
        {
          action_entry = get_action_entry (THUNAR_LAUNCHER_ACTION_SENDTO_SHORTCUTS);
          if (action_entry != NULL)
            {
              label_text   = ngettext ("Side Pane (Add Bookmark)", "Side Pane (Add Bookmarks)", launcher->n_files_to_process);
              tooltip_text = ngettext ("Add the selected folder to the shortcuts side pane",
                                       "Add the selected folders to the shortcuts side pane", launcher->n_files_to_process);
              item = xfce_gtk_image_menu_item_new_from_icon_name (label_text, tooltip_text, action_entry->accel_path, action_entry->callback,
                                                                  G_OBJECT (launcher), action_entry->menu_item_icon_name, GTK_MENU_SHELL (submenu));
            }
        }
    }

  /* Check whether at least one files is located in the trash (to en-/disable the "sendto-desktop" action). */
  for (lp = launcher->files_to_process; lp != NULL; lp = lp->next)
    {
      if (G_UNLIKELY (thunar_file_is_trashed (lp->data)))
        linkable = FALSE;
    }
  if (linkable)
    {
      action_entry = get_action_entry (THUNAR_LAUNCHER_ACTION_SENDTO_DESKTOP);
      if (action_entry != NULL)
        {
          label_text   = ngettext ("Desktop (Create Link)", "Desktop (Create Links)", launcher->n_files_to_process);
          tooltip_text = ngettext ("Create a link to the selected file on the desktop",
                                   "Create links to the selected files on the desktop", launcher->n_files_to_process);
          item = xfce_gtk_image_menu_item_new_from_icon_name (label_text, tooltip_text, action_entry->accel_path, action_entry->callback,
                                                              G_OBJECT (launcher), action_entry->menu_item_icon_name, GTK_MENU_SHELL (submenu));
        }
    }

  item = gtk_separator_menu_item_new ();
  gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
  gtk_widget_show (item);

  /* determine the currently active devices */
  device_monitor = thunar_device_monitor_get ();
  devices = thunar_device_monitor_get_devices (device_monitor);
  g_object_unref (device_monitor);

  /* add removable (and writable) drives and media */
  for (lp = devices; lp != NULL; lp = lp->next)
    {
      /* generate a unique name and tooltip for the device */
      label_text = thunar_device_get_name (lp->data);
      tooltip_text = g_strdup_printf (ngettext ("Send the selected file to \"%s\"",
                                                "Send the selected files to \"%s\"", launcher->n_files_to_process), label_text);
      icon = thunar_device_get_icon (lp->data);
      image = NULL;
      if (G_LIKELY (icon != NULL))
        {
          image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
          g_object_unref (icon);
        }
      item = xfce_gtk_image_menu_item_new (label_text, tooltip_text, NULL, G_CALLBACK (thunar_launcher_action_sendto_device),
                                           G_OBJECT (launcher), image, GTK_MENU_SHELL (submenu));
      g_object_set_qdata_full (G_OBJECT (item), thunar_launcher_device_quark, lp->data, g_object_unref);
      g_object_set_data (G_OBJECT (lp->data), "skip-app-info-update", GUINT_TO_POINTER (1));

      /* cleanup */
      g_free (tooltip_text);
      g_free (label_text);
    }

  /* free the devices list */
  g_list_free (devices);

  item = gtk_separator_menu_item_new ();
  gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
  gtk_widget_show (item);

  /* determine the sendto appInfos for the selected files */
  sendto_model = thunar_sendto_model_get_default ();
  appinfo_list = thunar_sendto_model_get_matching (sendto_model, launcher->files_to_process);
  g_object_unref (sendto_model);

  if (G_LIKELY (appinfo_list != NULL))
    {
      /* add all handlers to the user interface */
      for (lp = appinfo_list; lp != NULL; lp = lp->next)
        {
          /* generate a unique name and tooltip for the handler */
          label_text = g_strdup (g_app_info_get_name (lp->data));
          tooltip_text = g_strdup_printf (ngettext ("Send the selected file to \"%s\"",
                                                    "Send the selected files to \"%s\"", launcher->n_files_to_process), label_text);

          icon = g_app_info_get_icon (lp->data);
          image = NULL;
          if (G_LIKELY (icon != NULL))
              image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);

          item = xfce_gtk_image_menu_item_new (label_text, tooltip_text, NULL, G_CALLBACK (thunar_launcher_menu_item_activated),
                                               G_OBJECT (launcher), image, GTK_MENU_SHELL (submenu));
          g_object_set_qdata_full (G_OBJECT (item), thunar_launcher_appinfo_quark, g_object_ref (lp->data), g_object_unref);
          g_object_set_data (G_OBJECT (lp->data), "skip-app-info-update", GUINT_TO_POINTER (1));

          /* cleanup */
          g_free (label_text);
          g_free (tooltip_text);
        }

      /* release the appinfo list */
      g_list_free_full (appinfo_list, g_object_unref);
    }

  return submenu;
}



static gboolean
thunar_launcher_action_properties (ThunarLauncher *launcher)
{
  GtkWidget *toplevel;
  GtkWidget *dialog;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  /* popup the files dialog */
  toplevel = gtk_widget_get_toplevel (launcher->widget);
  if (G_LIKELY (toplevel != NULL))
    {
      dialog = thunar_properties_dialog_new (GTK_WINDOW (toplevel));

      /* check if no files are currently selected */
      if (launcher->files_to_process == NULL)
        {
          /* if we don't have any files selected, we just popup the properties dialog for the current folder. */
          thunar_properties_dialog_set_file (THUNAR_PROPERTIES_DIALOG (dialog), launcher->current_directory);
        }
      else
        {
          /* popup the properties dialog for all file(s) */
          thunar_properties_dialog_set_files (THUNAR_PROPERTIES_DIALOG (dialog), launcher->files_to_process);
        }
      gtk_widget_show (dialog);
    }

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static gboolean
thunar_launcher_action_make_link (ThunarLauncher *launcher)
{
  ThunarApplication *application;
  GList             *g_files = NULL;
  GList             *lp;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (G_UNLIKELY (launcher->current_directory == NULL))
    return TRUE;
  if (launcher->files_are_selected == FALSE || thunar_file_is_trash (launcher->current_directory))
    return TRUE;

  for (lp = launcher->files_to_process; lp != NULL; lp = lp->next)
    {
      g_files = g_list_append (g_files, thunar_file_get_file (lp->data));
    }
  /* link the selected files into the current directory, which effectively
   * creates new unique links for the files.
   */
  application = thunar_application_get ();
  thunar_application_link_into (application, launcher->widget, g_files,
                                thunar_file_get_file (launcher->current_directory), launcher->new_files_created_closure);
  g_object_unref (G_OBJECT (application));
  g_list_free (g_files);

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static gboolean
thunar_launcher_action_duplicate (ThunarLauncher *launcher)
{
  ThunarApplication *application;
  GList             *files_to_process;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (G_UNLIKELY (launcher->current_directory == NULL))
    return TRUE;
  if (launcher->files_are_selected == FALSE || thunar_file_is_trash (launcher->current_directory))
    return TRUE;

  /* determine the selected files for the view */
  files_to_process = thunar_file_list_to_thunar_g_file_list (launcher->files_to_process);
  if (G_LIKELY (files_to_process != NULL))
    {
      /* copy the selected files into the current directory, which effectively
       * creates duplicates of the files.
       */
      application = thunar_application_get ();
      thunar_application_copy_into (application, launcher->widget, files_to_process,
                                    thunar_file_get_file (launcher->current_directory), launcher->new_files_created_closure);
      g_object_unref (G_OBJECT (application));

      /* clean up */
      thunar_g_list_free_full (files_to_process);
    }

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



/**
 * thunar_launcher_append_custom_actions:
 * @launcher : a #ThunarLauncher instance
 * @menu : #GtkMenuShell on which the custom actions should be appended
 *
 * Will append all custom actions which match the file-type to the provided #GtkMenuShell
 *
 * Return value: TRUE if any custom action was added
 **/
gboolean
thunar_launcher_append_custom_actions (ThunarLauncher *launcher,
                                       GtkMenuShell   *menu)
{
  gboolean                uca_added = FALSE;
  GtkWidget              *window;
  GtkWidget              *gtk_menu_item;
  ThunarxProviderFactory *provider_factory;
  GList                  *providers;
  GList                  *thunarx_menu_items = NULL;
  GList                  *lp_provider;
  GList                  *lp_item;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);
  _thunar_return_val_if_fail (GTK_IS_MENU (menu), FALSE);

  /* determine the toplevel window we belong to */
  window = gtk_widget_get_toplevel (launcher->widget);

  /* load the menu providers from the provider factory */
  provider_factory = thunarx_provider_factory_get_default ();
  providers = thunarx_provider_factory_list_providers (provider_factory, THUNARX_TYPE_MENU_PROVIDER);
  g_object_unref (provider_factory);

  if (G_UNLIKELY (providers == NULL))
    return FALSE;

  /* This may occur when the thunar-window is build */
  if (G_UNLIKELY (launcher->files_to_process == NULL))
    return FALSE;

  /* load the menu items offered by the menu providers */
  for (lp_provider = providers; lp_provider != NULL; lp_provider = lp_provider->next)
    {
      if (launcher->files_are_selected == FALSE)
        thunarx_menu_items = thunarx_menu_provider_get_folder_menu_items (lp_provider->data, window, THUNARX_FILE_INFO (launcher->current_directory));
      else
        thunarx_menu_items = thunarx_menu_provider_get_file_menu_items (lp_provider->data, window, launcher->files_to_process);

      for (lp_item = thunarx_menu_items; lp_item != NULL; lp_item = lp_item->next)
        {
          gtk_menu_item = thunar_gtk_menu_thunarx_menu_item_new (lp_item->data, menu);

          /* Each thunarx_menu_item will be destroyed together with its related gtk_menu_item*/
          g_signal_connect_swapped (G_OBJECT (gtk_menu_item), "destroy", G_CALLBACK (g_object_unref), lp_item->data);
          uca_added = TRUE;
        }
      g_list_free (thunarx_menu_items);
    }
  g_list_free_full (providers, g_object_unref);
  return uca_added;
}



gboolean
thunar_launcher_check_uca_key_activation (ThunarLauncher *launcher,
                                          GdkEventKey    *key_event)
{
  GtkWidget              *window;
  ThunarxProviderFactory *provider_factory;
  GList                  *providers;
  GList                  *thunarx_menu_items = NULL;
  GList                  *lp_provider;
  GList                  *lp_item;
  GtkAccelKey             uca_key;
  gchar                  *name, *accel_path;
  gboolean                uca_activated = FALSE;

  /* determine the toplevel window we belong to */
  window = gtk_widget_get_toplevel (launcher->widget);

  /* load the menu providers from the provider factory */
  provider_factory = thunarx_provider_factory_get_default ();
  providers = thunarx_provider_factory_list_providers (provider_factory, THUNARX_TYPE_MENU_PROVIDER);
  g_object_unref (provider_factory);

  if (G_UNLIKELY (providers == NULL))
    return uca_activated;

  /* load the menu items offered by the menu providers */
  for (lp_provider = providers; lp_provider != NULL; lp_provider = lp_provider->next)
    {
      if (launcher->files_are_selected == FALSE)
        thunarx_menu_items = thunarx_menu_provider_get_folder_menu_items (lp_provider->data, window, THUNARX_FILE_INFO (launcher->current_directory));
      else
        thunarx_menu_items = thunarx_menu_provider_get_file_menu_items (lp_provider->data, window, launcher->files_to_process);
      for (lp_item = thunarx_menu_items; lp_item != NULL; lp_item = lp_item->next)
        {
          g_object_get (G_OBJECT (lp_item->data), "name", &name, NULL);
          accel_path = g_strconcat ("<Actions>/ThunarActions/", name, NULL);
          if (gtk_accel_map_lookup_entry (accel_path, &uca_key) == TRUE)
            {
              if (g_ascii_tolower (key_event->keyval) == g_ascii_tolower (uca_key.accel_key))
                {
                  if ((key_event->state & gtk_accelerator_get_default_mod_mask ()) == uca_key.accel_mods)
                    {
                      thunarx_menu_item_activate (lp_item->data);
                      uca_activated = TRUE;
                    }
                }
            }
          g_free (name);
          g_free (accel_path);
          g_object_unref (lp_item->data);
        }
      g_list_free (thunarx_menu_items);
    }
  g_list_free_full (providers, g_object_unref);
  return uca_activated;
}



static void
thunar_launcher_rename_error (ExoJob    *job,
                              GError    *error,
                              GtkWidget *widget)
{
  GArray     *param_values;
  ThunarFile *file;

  _thunar_return_if_fail (EXO_IS_JOB (job));
  _thunar_return_if_fail (error != NULL);

  param_values = thunar_simple_job_get_param_values (THUNAR_SIMPLE_JOB (job));
  file = g_value_get_object (&g_array_index (param_values, GValue, 0));

  thunar_dialogs_show_error (GTK_WIDGET (widget), error,
                             _("Failed to rename \"%s\""),
                             thunar_file_get_display_name (file));
  g_object_unref (file);
}



static void
thunar_launcher_rename_finished (ExoJob    *job,
                                 GtkWidget *widget)
{
  _thunar_return_if_fail (EXO_IS_JOB (job));

  /* destroy the job */
  g_signal_handlers_disconnect_matched (job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, widget);
  g_object_unref (job);
}



static gboolean
thunar_launcher_action_rename (ThunarLauncher *launcher)
{
  ThunarJob *job;
  GtkWidget *window;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (launcher->files_to_process == NULL || g_list_length (launcher->files_to_process) == 0)
    return TRUE;
  if (launcher->files_are_selected == FALSE || thunar_file_is_trash (launcher->current_directory))
    return TRUE;

  /* get the window */
  window = gtk_widget_get_toplevel (launcher->widget);

  /* start renaming if we have exactly one selected file */
  if (g_list_length (launcher->files_to_process) == 1)
    {
      /* run the rename dialog */
      job = thunar_dialogs_show_rename_file (GTK_WINDOW (window), THUNAR_FILE (launcher->files_to_process->data));
      if (G_LIKELY (job != NULL))
        {
          g_signal_connect (job, "error", G_CALLBACK (thunar_launcher_rename_error), launcher->widget);
          g_signal_connect (job, "finished", G_CALLBACK (thunar_launcher_rename_finished), launcher->widget);
        }
    }
  else
    {
      /* display the bulk rename dialog */
      thunar_show_renamer_dialog (GTK_WIDGET (window), launcher->current_directory, launcher->files_to_process, FALSE, NULL);
    }

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



gboolean
thunar_launcher_action_restore (ThunarLauncher *launcher)
{
  ThunarApplication *application;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (launcher->files_are_selected == FALSE || !thunar_file_is_trash (launcher->current_directory))
    return TRUE;

  /* restore the selected files */
  application = thunar_application_get ();
  thunar_application_restore_files (application, launcher->widget, launcher->files_to_process, NULL);
  g_object_unref (G_OBJECT (application));

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



gboolean
thunar_launcher_action_restore_and_show (ThunarLauncher *launcher)
{
  ThunarApplication *application;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (launcher->files_are_selected == FALSE || !thunar_file_is_trash (launcher->current_directory))
    return TRUE;

  /* restore the selected files */
  application = thunar_application_get ();
  thunar_application_restore_files (application, launcher->widget, launcher->files_to_process, launcher->new_files_created_closure);
  g_object_unref (G_OBJECT (application));

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static void
thunar_launcher_action_move_to_trash (ThunarLauncher *launcher)
{
  ThunarApplication *application;

  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  if (launcher->parent_folder == NULL || launcher->files_are_selected == FALSE)
    return;

  application = thunar_application_get ();
  thunar_application_unlink_files (application, launcher->widget, launcher->files_to_process, FALSE);
  g_object_unref (G_OBJECT (application));
}



static gboolean
thunar_launcher_action_delete (ThunarLauncher *launcher)
{
  ThunarApplication *application;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (launcher->parent_folder == NULL || launcher->files_are_selected == FALSE)
    return TRUE;

  application = thunar_application_get ();
  thunar_application_unlink_files (application, launcher->widget, launcher->files_to_process, TRUE);
  g_object_unref (G_OBJECT (application));

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static gboolean
thunar_launcher_action_trash_delete (ThunarLauncher *launcher)
{
  GdkModifierType event_state;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  /* when shift modifier is pressed, we delete (as well via context menu) */
  if (gtk_get_current_event_state (&event_state) && (event_state & GDK_SHIFT_MASK) != 0)
    thunar_launcher_action_delete (launcher);
  else if (thunar_g_vfs_is_uri_scheme_supported ("trash"))
    thunar_launcher_action_move_to_trash (launcher);
  else
    thunar_launcher_action_delete (launcher);

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static gboolean
thunar_launcher_action_remove_from_recent (ThunarLauncher *launcher)
{
  GtkRecentManager  *recent_manager = gtk_recent_manager_get_default();
  GList             *lp;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (launcher->parent_folder == NULL || launcher->files_are_selected == FALSE)
    return TRUE;

  for (lp = launcher->files_to_process; lp != NULL; lp = lp->next)
    {
      ThunarFile  *file  = lp->data;
      GFile       *gfile = thunar_file_get_file (file);
      gchar       *uri   = g_file_get_uri (gfile);
      gtk_recent_manager_remove_item (recent_manager, uri, NULL);
      g_free(uri);
    }

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



gboolean
thunar_launcher_action_empty_trash (ThunarLauncher *launcher)
{
  ThunarApplication *application;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  application = thunar_application_get ();
  thunar_application_empty_trash (application, launcher->widget, NULL);
  g_object_unref (G_OBJECT (application));

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static gboolean
thunar_launcher_action_create_folder (ThunarLauncher *launcher)
{
  ThunarApplication *application;
  GList              path_list;
  gchar             *name;
  gchar             *generated_name;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (thunar_file_is_trash (launcher->current_directory))
    return TRUE;

  /* ask the user to enter a name for the new folder */
  generated_name = thunar_util_next_new_file_name (launcher->current_directory, _("New Folder"), THUNAR_NEXT_FILE_NAME_MODE_NEW);
  name = thunar_dialogs_show_create (launcher->widget,
                                     "inode/directory",
                                     generated_name,
                                     _("Create New Folder"));
  g_free (generated_name);

  if (G_LIKELY (name != NULL))
    {
      /* fake the path list */
      if (THUNAR_IS_TREE_VIEW (launcher->widget) && launcher->files_are_selected && launcher->single_directory_to_process)
        path_list.data = g_file_resolve_relative_path (thunar_file_get_file (launcher->single_folder), name);
      else
        path_list.data = g_file_resolve_relative_path (thunar_file_get_file (launcher->current_directory), name);
      path_list.next = path_list.prev = NULL;

      /* launch the operation */
      application = thunar_application_get ();
      thunar_application_mkdir (application, launcher->widget, &path_list, launcher->new_files_created_closure);
      g_object_unref (G_OBJECT (application));

      /* release the path */
      g_object_unref (path_list.data);

      /* release the file name */
      g_free (name);
    }

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static gboolean
thunar_launcher_action_create_document (ThunarLauncher *launcher,
                                        GtkWidget      *menu_item)
{
  ThunarApplication *application;
  GList              target_path_list;
  gchar             *name;
  gchar             *generated_name;
  gchar             *title;
  ThunarFile        *template_file;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (thunar_file_is_trash (launcher->current_directory))
    return TRUE;

  template_file = g_object_get_qdata (G_OBJECT (menu_item), thunar_launcher_file_quark);

  if (template_file != NULL)
    {
      /* generate a title for the create dialog */
      title = g_strdup_printf (_("Create Document from template \"%s\""),
                               thunar_file_get_display_name (template_file));

      /* ask the user to enter a name for the new document */
      generated_name = thunar_util_next_new_file_name (launcher->current_directory, g_file_get_basename (thunar_file_get_file (template_file)), THUNAR_NEXT_FILE_NAME_MODE_NEW);
      name = thunar_dialogs_show_create (launcher->widget,
                                         thunar_file_get_content_type (THUNAR_FILE (template_file)),
                                         generated_name,
                                         title);
      /* cleanup */
      g_free (title);
    }
  else
    {
      /* ask the user to enter a name for the new empty file */
      generated_name = thunar_util_next_new_file_name (launcher->current_directory, _("New Empty File"), THUNAR_NEXT_FILE_NAME_MODE_NEW);
      name = thunar_dialogs_show_create (launcher->widget,
                                         "text/plain",
                                         generated_name,
                                         _("New Empty File..."));
    }
  g_free (generated_name);

  if (G_LIKELY (name != NULL))
    {
      if (G_LIKELY (launcher->parent_folder != NULL))
        {
          /* fake the target path list */
          if (THUNAR_IS_TREE_VIEW (launcher->widget) && launcher->files_are_selected && launcher->single_directory_to_process)
            target_path_list.data = g_file_get_child (thunar_file_get_file (launcher->single_folder), name);
          else
            target_path_list.data = g_file_get_child (thunar_file_get_file (launcher->current_directory), name);
          target_path_list.next = NULL;
          target_path_list.prev = NULL;

          /* launch the operation */
          application = thunar_application_get ();
          thunar_application_creat (application, launcher->widget, &target_path_list,
                                    template_file != NULL ? thunar_file_get_file (template_file) : NULL,
                                    launcher->new_files_created_closure);
          g_object_unref (G_OBJECT (application));

          /* release the target path */
          g_object_unref (target_path_list.data);
        }

      /* release the file name */
      g_free (name);
    }

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



/* helper method in order to find the parent menu for a menu item */
static GtkWidget *
thunar_launcher_create_document_submenu_templates_find_parent_menu (ThunarFile *file,
                                                                    GList      *dirs,
                                                                    GList      *items)
{
  GtkWidget *parent_menu = NULL;
  GFile     *parent;
  GList     *lp;
  GList     *ip;

  /* determine the parent of the file */
  parent = g_file_get_parent (thunar_file_get_file (file));

  /* check if the file has a parent at all */
  if (parent == NULL)
    return NULL;

  /* iterate over all dirs and menu items */
  for (lp = g_list_first (dirs), ip = g_list_first (items);
       parent_menu == NULL && lp != NULL && ip != NULL;
       lp = lp->next, ip = ip->next)
    {
      /* check if the current dir/item is the parent of our file */
      if (g_file_equal (parent, thunar_file_get_file (lp->data)))
        {
          /* we want to insert an item for the file in this menu */
          parent_menu = gtk_menu_item_get_submenu (ip->data);
        }
    }

  /* destroy the parent GFile */
  g_object_unref (parent);

  return parent_menu;
}



/* recursive helper method in order to create menu items for all available templates */
static gboolean
thunar_launcher_create_document_submenu_templates (ThunarLauncher *launcher,
                                                   GtkWidget      *create_file_submenu,
                                                   GList          *files)
{
  ThunarIconFactory *icon_factory;
  ThunarFile        *file;
  GdkPixbuf         *icon;
  GtkWidget         *parent_menu;
  GtkWidget         *submenu;
  GtkWidget         *image;
  GtkWidget         *item;
  GList             *lp;
  GList             *dirs = NULL;
  GList             *items = NULL;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  /* do nothing if there is no menu */
  if (create_file_submenu == NULL)
    return FALSE;

  /* get the icon factory */
  icon_factory = thunar_icon_factory_get_default ();

  /* sort items so that directories come before files and ancestors come
   * before descendants */
  files = g_list_sort (files, (GCompareFunc) (void (*)(void)) thunar_file_compare_by_type);

  for (lp = g_list_first (files); lp != NULL; lp = lp->next)
    {
      file = lp->data;

      /* determine the parent menu for this file/directory */
      parent_menu = thunar_launcher_create_document_submenu_templates_find_parent_menu (file, dirs, items);
      if (parent_menu == NULL)
        parent_menu = create_file_submenu;

      /* determine the icon for this file/directory */
      icon = thunar_icon_factory_load_file_icon (icon_factory, file, THUNAR_FILE_ICON_STATE_DEFAULT, 16);

      /* allocate an image based on the icon */
      image = gtk_image_new_from_pixbuf (icon);

      item = xfce_gtk_image_menu_item_new (thunar_file_get_display_name (file), NULL, NULL, NULL, NULL, image, GTK_MENU_SHELL (parent_menu));
      if (thunar_file_is_directory (file))
        {
          /* allocate a new submenu for the directory */
          submenu = gtk_menu_new ();

          /* allocate a new menu item for the directory */
          gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);

          /* prepend the directory, its item and the parent menu it should
           * later be added to to the respective lists */
          dirs = g_list_prepend (dirs, file);
          items = g_list_prepend (items, item);
        }
      else
        {
          g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_launcher_action_create_document), launcher);
          g_object_set_qdata_full (G_OBJECT (item), thunar_launcher_file_quark, g_object_ref (file), g_object_unref);
        }
      /* release the icon reference */
      g_object_unref (icon);
    }

  /* destroy lists */
  g_list_free (dirs);
  g_list_free (items);

  /* release the icon factory */
  g_object_unref (icon_factory);

  /* let the job destroy the file list */
  return FALSE;
}



/**
 * thunar_launcher_create_document_submenu_new:
 * @launcher : a #ThunarLauncher instance
 *
 * Will create a complete 'create_document* #GtkMenu and return it
 *
 * Return value: (transfer full): the created #GtkMenu
 **/
static GtkWidget*
thunar_launcher_create_document_submenu_new (ThunarLauncher *launcher)
{
  GList           *files = NULL;
  GFile           *home_dir;
  GFile           *templates_dir = NULL;
  const gchar     *path;
  gchar           *template_path;
  gchar           *label_text;
  GtkWidget       *submenu;
  GtkWidget       *item;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), NULL);

  home_dir = thunar_g_file_new_for_home ();
  path = g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES);

  if (G_LIKELY (path != NULL))
    templates_dir = g_file_new_for_path (path);

  /* If G_USER_DIRECTORY_TEMPLATES not found, set "~/Templates" directory as default */
  if (G_UNLIKELY (path == NULL) || G_UNLIKELY (g_file_equal (templates_dir, home_dir)))
    {
      if (templates_dir != NULL)
        g_object_unref (templates_dir);
      templates_dir = g_file_resolve_relative_path (home_dir, "Templates");
    }

  if (G_LIKELY (templates_dir != NULL))
    {
      /* load the ThunarFiles */
      files = thunar_io_scan_directory (NULL, templates_dir, G_FILE_QUERY_INFO_NONE, TRUE, FALSE, TRUE, NULL);
    }

  submenu = gtk_menu_new();
  if (files == NULL)
    {
      template_path = g_file_get_path (templates_dir);
      label_text = g_strdup_printf (_("No templates installed in \"%s\""), template_path);
      item = xfce_gtk_image_menu_item_new (label_text, NULL, NULL, NULL, NULL, NULL, GTK_MENU_SHELL (submenu));
      gtk_widget_set_sensitive (item, FALSE);
      g_free (template_path);
      g_free (label_text);
    }
  else
    {
      thunar_launcher_create_document_submenu_templates (launcher, submenu, files);
      thunar_g_list_free_full (files);
    }

  xfce_gtk_menu_append_seperator (GTK_MENU_SHELL (submenu));
  xfce_gtk_image_menu_item_new_from_icon_name (_("_Empty File"), NULL, NULL, G_CALLBACK (thunar_launcher_action_create_document),
                                               G_OBJECT (launcher), "text-x-generic", GTK_MENU_SHELL (submenu));


  g_object_unref (templates_dir);
  g_object_unref (home_dir);

  return submenu;
}



static gboolean
thunar_launcher_action_cut (ThunarLauncher *launcher)
{
  ThunarClipboardManager *clipboard;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (launcher->files_are_selected == FALSE || launcher->parent_folder == NULL)
    return TRUE;

  clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (launcher->widget));
  thunar_clipboard_manager_cut_files (clipboard, launcher->files_to_process);
  g_object_unref (G_OBJECT (clipboard));

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static gboolean
thunar_launcher_action_copy (ThunarLauncher *launcher)
{
  ThunarClipboardManager *clipboard;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (launcher->files_are_selected == FALSE)
    return TRUE;

  clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (launcher->widget));
  thunar_clipboard_manager_copy_files (clipboard, launcher->files_to_process);
  g_object_unref (G_OBJECT (clipboard));

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static gboolean
thunar_launcher_action_paste (ThunarLauncher *launcher)
{
  ThunarClipboardManager *clipboard;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (launcher->widget));
  thunar_clipboard_manager_paste_files (clipboard, thunar_file_get_file (launcher->current_directory), launcher->widget, launcher->new_files_created_closure);
  g_object_unref (G_OBJECT (clipboard));

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static gboolean
thunar_launcher_action_paste_into_folder (ThunarLauncher *launcher)
{
  ThunarClipboardManager *clipboard;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (!launcher->single_directory_to_process)
    return TRUE;

  clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (launcher->widget));
  thunar_clipboard_manager_paste_files (clipboard, thunar_file_get_file (launcher->single_folder), launcher->widget, launcher->new_files_created_closure);
  g_object_unref (G_OBJECT (clipboard));

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}


/**
 * thunar_launcher_action_mount:
 * @launcher : a #ThunarLauncher instance
*
 * Will mount the selected device, if any. The related folder will not be opened.
 **/
void
thunar_launcher_action_mount (ThunarLauncher *launcher)
{
  thunar_launcher_poke (launcher, NULL,THUNAR_LAUNCHER_NO_ACTION);
}



static void
thunar_launcher_action_eject_finish (ThunarDevice  *device,
                                      const GError *error,
                                      gpointer      user_data)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (user_data);
  gchar          *device_name;

  _thunar_return_if_fail (THUNAR_IS_DEVICE (device));
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  /* check if there was an error */
  if (error != NULL)
    {
      /* display an error dialog to inform the user */
      device_name = thunar_device_get_name (device);
      thunar_dialogs_show_error (GTK_WIDGET (launcher->widget), error, _("Failed to eject \"%s\""), device_name);
      g_free (device_name);
    }

  g_object_unref (launcher);
  g_signal_emit (launcher, launcher_signals[DEVICE_OPERATION_FINISHED], 0, device);
}



/**
 * thunar_launcher_action_eject:
 * @launcher : a #ThunarLauncher instance
*
 * Will eject the selected device, if any
 **/
gboolean
thunar_launcher_action_eject (ThunarLauncher *launcher)
{
  GMountOperation *mount_operation;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (G_LIKELY (launcher->device_to_process != NULL))
    {
      /* prepare a mount operation */
      mount_operation = thunar_gtk_mount_operation_new (GTK_WIDGET (launcher->widget));

      g_signal_emit (launcher, launcher_signals[DEVICE_OPERATION_STARTED], 0, launcher->device_to_process);

      /* eject */
      thunar_device_eject (launcher->device_to_process,
                           mount_operation,
                           NULL,
                           thunar_launcher_action_eject_finish,
                           g_object_ref (launcher));

      g_object_unref (mount_operation);
    }

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static void
thunar_launcher_action_unmount_finish (ThunarDevice *device,
                                       const GError *error,
                                       gpointer      user_data)
{
  ThunarLauncher *launcher = THUNAR_LAUNCHER (user_data);
  gchar          *device_name;

  _thunar_return_if_fail (THUNAR_IS_DEVICE (device));
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  /* check if there was an error */
  if (error != NULL)
    {
      /* display an error dialog to inform the user */
      device_name = thunar_device_get_name (device);
      thunar_dialogs_show_error (GTK_WIDGET (launcher->widget), error, _("Failed to unmount \"%s\""), device_name);
      g_free (device_name);
    }

  g_object_unref (launcher);
  g_signal_emit (launcher, launcher_signals[DEVICE_OPERATION_FINISHED], 0, device);
}



/**
 * thunar_launcher_action_eject:
 * @launcher : a #ThunarLauncher instance
*
 * Will unmount the selected device, if any
 **/
gboolean
thunar_launcher_action_unmount (ThunarLauncher *launcher)
{
  GMountOperation *mount_operation;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  if (G_LIKELY (launcher->device_to_process != NULL))
    {
      /* prepare a mount operation */
      mount_operation = thunar_gtk_mount_operation_new (GTK_WIDGET (launcher->widget));

      g_signal_emit (launcher, launcher_signals[DEVICE_OPERATION_STARTED], 0, launcher->device_to_process);

      /* eject */
      thunar_device_unmount (launcher->device_to_process,
                             mount_operation,
                             NULL,
                             thunar_launcher_action_unmount_finish,
                             g_object_ref (launcher));

      /* release the device */
      g_object_unref (mount_operation);
    }

  /* required in case of shortcut activation, in order to signal that the accel key got handled */
  return TRUE;
}



static GtkWidget*
thunar_launcher_build_application_submenu (ThunarLauncher *launcher,
                                           GList          *applications)
{
  GList     *lp;
  GtkWidget *submenu;
  GtkWidget *image;
  GtkWidget *item;
  gchar     *label_text;
  gchar     *tooltip_text;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), NULL);

  submenu =  gtk_menu_new();
  /* add open with subitem per application */
  for (lp = applications; lp != NULL; lp = lp->next)
    {
      label_text = g_strdup_printf (_("Open With \"%s\""), g_app_info_get_name (lp->data));
      tooltip_text = g_strdup_printf (ngettext ("Use \"%s\" to open the selected file",
                                           "Use \"%s\" to open the selected files",
                                           launcher->n_files_to_process), g_app_info_get_name (lp->data));
      image = gtk_image_new_from_gicon (g_app_info_get_icon (lp->data), GTK_ICON_SIZE_MENU);
      item = xfce_gtk_image_menu_item_new (label_text, tooltip_text, NULL, G_CALLBACK (thunar_launcher_menu_item_activated), G_OBJECT (launcher), image, GTK_MENU_SHELL (submenu));
      g_object_set_qdata_full (G_OBJECT (item), thunar_launcher_appinfo_quark, g_object_ref (lp->data), g_object_unref);
      g_free (tooltip_text);
      g_free (label_text);
    }

  if (launcher->n_files_to_process == 1)
    {
      xfce_gtk_menu_append_seperator (GTK_MENU_SHELL (submenu));
      thunar_launcher_append_menu_item (launcher, GTK_MENU_SHELL (submenu), THUNAR_LAUNCHER_ACTION_OPEN_WITH_OTHER, FALSE);
      xfce_gtk_menu_append_seperator (GTK_MENU_SHELL (submenu));
      thunar_launcher_append_menu_item (launcher, GTK_MENU_SHELL (submenu), THUNAR_LAUNCHER_ACTION_SET_DEFAULT_APP, FALSE);
    }

  return submenu;
}



/**
 * thunar_launcher_append_open_section:
 * @launcher                 : a #ThunarLauncher instance
 * @menu                     : #GtkMenuShell on which the open section should be appended
 * @support_tabs             : Set to TRUE if 'open in new tab' should be shown
 * @support_change_directory : Set to TRUE if 'open' should be shown
 * @force                    : Append the open section, even if the selected folder is the current folder
 *
 * Will append the section "open/open in new window/open in new tab/open with" to the provided #GtkMenuShell
 *
 * Return value: TRUE if the section was added
 **/
gboolean
thunar_launcher_append_open_section (ThunarLauncher *launcher,
                                     GtkMenuShell   *menu,
                                     gboolean        support_tabs,
                                     gboolean        support_change_directory,
                                     gboolean        force)
{
  GList     *applications;
  gchar     *label_text;
  gchar     *tooltip_text;
  GtkWidget *image;
  GtkWidget *menu_item;
  GtkWidget *submenu;

  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), FALSE);

  /* Usually it is not required to open the current directory */
  if (launcher->files_are_selected == FALSE && !force)
    return FALSE;

  /* determine the set of applications that work for all selected files */
  applications = thunar_file_list_get_applications (launcher->files_to_process);

  /* Execute OR Open OR OpenWith */
  if (G_UNLIKELY (launcher->files_are_all_executable))
    thunar_launcher_append_menu_item (launcher, GTK_MENU_SHELL (menu), THUNAR_LAUNCHER_ACTION_EXECUTE, FALSE);
  else if (G_LIKELY (launcher->n_directories_to_process >= 1))
    {
      if (support_change_directory)
        thunar_launcher_append_menu_item (launcher, GTK_MENU_SHELL (menu), THUNAR_LAUNCHER_ACTION_OPEN, FALSE);
    }
  else if (G_LIKELY (applications != NULL))
    {
      label_text = g_strdup_printf (_("_Open With \"%s\""), g_app_info_get_name (applications->data));
      tooltip_text = g_strdup_printf (ngettext ("Use \"%s\" to open the selected file",
                                                "Use \"%s\" to open the selected files",
                                                launcher->n_files_to_process), g_app_info_get_name (applications->data));

      image = gtk_image_new_from_gicon (g_app_info_get_icon (applications->data), GTK_ICON_SIZE_MENU);
      menu_item = xfce_gtk_image_menu_item_new (label_text, tooltip_text, NULL, G_CALLBACK (thunar_launcher_menu_item_activated),
                                                G_OBJECT (launcher), image, menu);

      /* remember the default application for the "Open" action as quark */
      g_object_set_qdata_full (G_OBJECT (menu_item), thunar_launcher_appinfo_quark, applications->data, g_object_unref);
      g_free (tooltip_text);
      g_free (label_text);

      /* drop the default application from the list */
      applications = g_list_delete_link (applications, applications);
    }
  else
    {
      /* we can only show a generic "Open" action */
      label_text = g_strdup_printf (_("_Open With Default Applications"));
      tooltip_text = g_strdup_printf (ngettext ("Open the selected file with the default application",
                                                "Open the selected files with the default applications", launcher->n_files_to_process));
      xfce_gtk_menu_item_new (label_text, tooltip_text, NULL, G_CALLBACK (thunar_launcher_menu_item_activated), G_OBJECT (launcher), menu);
      g_free (tooltip_text);
      g_free (label_text);
    }

  if (launcher->n_files_to_process == launcher->n_directories_to_process && launcher->n_directories_to_process >= 1)
    {
      if (support_tabs)
        thunar_launcher_append_menu_item (launcher, GTK_MENU_SHELL (menu), THUNAR_LAUNCHER_ACTION_OPEN_IN_TAB, FALSE);
      thunar_launcher_append_menu_item (launcher, GTK_MENU_SHELL (menu), THUNAR_LAUNCHER_ACTION_OPEN_IN_WINDOW, FALSE);
    }

  /* active while searching and while in 'recent:///' */
  if (launcher->n_files_to_process > 0 && (launcher->is_searching || thunar_file_is_recent (launcher->current_directory)))
    thunar_launcher_append_menu_item (launcher, GTK_MENU_SHELL (menu), THUNAR_LAUNCHER_ACTION_OPEN_LOCATION, FALSE);

  if (G_LIKELY (applications != NULL))
    {
      menu_item = xfce_gtk_menu_item_new (_("Open With"),
                                          _("Choose another application with which to open the selected file"),
                                          NULL, NULL, NULL, menu);
      submenu = thunar_launcher_build_application_submenu (launcher, applications);
      gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), submenu);
    }
  else
    {
      if (launcher->n_files_to_process == 1)
      {
        thunar_launcher_append_menu_item (launcher, GTK_MENU_SHELL (menu), THUNAR_LAUNCHER_ACTION_OPEN_WITH_OTHER, FALSE);
        xfce_gtk_menu_append_seperator (GTK_MENU_SHELL (menu));
        thunar_launcher_append_menu_item (launcher, GTK_MENU_SHELL (menu), THUNAR_LAUNCHER_ACTION_SET_DEFAULT_APP, FALSE);
      }
    }

  g_list_free_full (applications, g_object_unref);
  return TRUE;
}



/**
 * thunar_launcher_get_widget:
 * @launcher : a #ThunarLauncher instance
 *
 * Will return the parent widget of this #ThunarLauncher
 *
 * Return value: (transfer none): the parent widget of this #ThunarLauncher
 **/
GtkWidget*
thunar_launcher_get_widget (ThunarLauncher *launcher)
{
  _thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), NULL);
  return launcher->widget;
}



/**
 * thunar_launcher_set_selection:
 * @launcher : a #ThunarLauncher instance
 * @selected_thunar_files: #GList of selected #ThunarFile instances, or NULL
 * @selected_device: selected #ThunarDevice or NULL
 * @selected_location: selected #GFile (possibly only holds an URI), or NULL
 *
 * Will set the related items as "selection" and clear any previous selection.
 * Note that always only one of the 3 "selected" arguments should be set.
 **/
void
thunar_launcher_set_selection (ThunarLauncher *launcher,
                               GList          *selected_thunar_files,
                               ThunarDevice   *selected_device,
                               GFile          *selected_location)
{
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  /* unref the current device/location */
  if (launcher->device_to_process != NULL)
    {
      g_object_unref (launcher->device_to_process);
      launcher->device_to_process = NULL;
    }
  if (launcher->location_to_process != NULL)
    {
      g_object_unref (launcher->location_to_process);
      launcher->location_to_process = NULL;
    }

  /* ref the new device/location */
  if (selected_device != NULL)
    launcher->device_to_process = g_object_ref (selected_device);
  if (selected_location != NULL)
    launcher->location_to_process = g_object_ref (selected_location);

  /* for selected files things are a bit more conmplicated */
  thunar_launcher_set_selected_files (THUNAR_COMPONENT (launcher), selected_thunar_files);
}



static void
thunar_launcher_new_files_created (ThunarLauncher *launcher,
                                   GList          *new_thunar_files)
{
  _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));

  g_signal_emit (launcher, launcher_signals[NEW_FILES_CREATED], 0, new_thunar_files);
}



XfceGtkActionEntry*
thunar_launcher_get_action_entries (void)
{
  return thunar_launcher_action_entries;
}