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
|
/* $Id$ */
/*-
* Copyright (c) 2005-2007 Benedikt Meurer <benny@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 <libxfce4ui/libxfce4ui.h>
#include <thunar/thunar-abstract-dialog.h>
#include <thunar/thunar-application.h>
#include <thunar/thunar-dialogs.h>
#include <thunar/thunar-gtk-extensions.h>
#include <thunar/thunar-icon-factory.h>
#include <thunar/thunar-icon-renderer.h>
#include <thunar/thunar-launcher.h>
#include <thunar/thunar-private.h>
#include <thunar/thunar-properties-dialog.h>
#include <thunar/thunar-renamer-dialog.h>
#include <thunar/thunar-renamer-dialog-ui.h>
#include <thunar/thunar-renamer-model.h>
#include <thunar/thunar-renamer-progress.h>
/* Property identifiers */
enum
{
PROP_0,
PROP_CURRENT_DIRECTORY,
PROP_SELECTED_FILES,
PROP_STANDALONE,
};
/* Identifiers for DnD target types */
enum
{
TARGET_GTK_TREE_MODEL_ROW,
TARGET_TEXT_URI_LIST,
};
static void thunar_renamer_dialog_dispose (GObject *object);
static void thunar_renamer_dialog_finalize (GObject *object);
static void thunar_renamer_dialog_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void thunar_renamer_dialog_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void thunar_renamer_dialog_realize (GtkWidget *widget);
static void thunar_renamer_dialog_unrealize (GtkWidget *widget);
static void thunar_renamer_dialog_response (GtkDialog *dialog,
gint response);
static void thunar_renamer_dialog_context_menu (ThunarRenamerDialog *renamer_dialog,
guint button,
guint32 timestamp);
static void thunar_renamer_dialog_help (ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_save (ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_action_add_files (GtkAction *action,
ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_action_remove_files (GtkAction *action,
ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_action_clear (GtkAction *action,
ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_action_about (GtkAction *action,
ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_action_properties (GtkAction *action,
ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_name_column_clicked (GtkTreeViewColumn *column,
ThunarRenamerDialog *renamer_dialog);
static gboolean thunar_renamer_dialog_button_press_event (GtkWidget *tree_view,
GdkEventButton *event,
ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_drag_data_received (GtkWidget *tree_view,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint timestamp,
ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_drag_leave (GtkWidget *tree_view,
GdkDragContext *context,
guint timestamp,
ThunarRenamerDialog *renamer_dialog);
static gboolean thunar_renamer_dialog_drag_motion (GtkWidget *tree_view,
GdkDragContext *context,
gint x,
gint y,
guint timestamp,
ThunarRenamerDialog *renamer_dialog);
static gboolean thunar_renamer_dialog_drag_drop (GtkWidget *tree_view,
GdkDragContext *context,
gint x,
gint y,
guint timestamp,
ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_notify_page (GtkNotebook *notebook,
GParamSpec *pspec,
ThunarRenamerDialog *renamer_dialog);
static gboolean thunar_renamer_dialog_popup_menu (GtkWidget *tree_view,
ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_row_activated (GtkTreeView *tree_view,
GtkTreePath *path,
GtkTreeViewColumn *column,
ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_selection_changed (GtkTreeSelection *selection,
ThunarRenamerDialog *renamer_dialog);
static ThunarFile *thunar_renamer_dialog_get_current_directory (ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_set_current_directory (ThunarRenamerDialog *renamer_dialog,
ThunarFile *current_directory);
static GList *thunar_renamer_dialog_get_selected_files (ThunarRenamerDialog *renamer_dialog);
static gboolean thunar_renamer_dialog_get_standalone (ThunarRenamerDialog *renamer_dialog);
static void thunar_renamer_dialog_set_standalone (ThunarRenamerDialog *renamer_dialog,
gboolean fixed);
struct _ThunarRenamerDialogClass
{
ThunarAbstractDialogClass __parent__;
};
struct _ThunarRenamerDialog
{
ThunarAbstractDialog __parent__;
/* need to grab a reference on the icon factory for the standalone version */
ThunarIconFactory *icon_factory;
ThunarRenamerModel *model;
ThunarLauncher *launcher;
GtkActionGroup *action_group;
GtkUIManager *ui_manager;
GtkWidget *cancel_button;
GtkWidget *close_button;
GtkWidget *tree_view;
GtkWidget *progress;
GtkTreeViewColumn *name_column;
/* the current directory used for the "Add Files" dialog */
ThunarFile *current_directory;
/* the list of currently selected files */
GList *selected_files;
/* whether the dialog should act like a standalone application */
gboolean standalone;
/* TRUE while drop highlighting */
gboolean drag_highlighted;
};
static const GtkActionEntry action_entries[] =
{
{ "file-menu", NULL, N_ ("_File"), NULL, },
{ "sendto-menu", NULL, N_ ("_Send To"), NULL, },
{ "file-context-menu", NULL, N_ ("File Context Menu"), NULL, },
{ "add-files", GTK_STOCK_ADD, N_ ("_Add Files..."), NULL, N_ ("Include additional files in the list of files to be renamed"), G_CALLBACK (thunar_renamer_dialog_action_add_files), },
{ "remove-files", GTK_STOCK_REMOVE, NULL, NULL, NULL, G_CALLBACK (thunar_renamer_dialog_action_remove_files), },
{ "clear", GTK_STOCK_CLEAR, N_ ("Clear"), NULL, N_ ("Clear the file list below"), G_CALLBACK (thunar_renamer_dialog_action_clear), },
{ "about", GTK_STOCK_ABOUT, N_ ("_About"), NULL, N_ ("Display information about Thunar Bulk Rename"), G_CALLBACK (thunar_renamer_dialog_action_about), },
{ "properties", GTK_STOCK_PROPERTIES, N_ ("_Properties..."), "<alt>Return", N_ ("View the properties of the selected file"), G_CALLBACK (thunar_renamer_dialog_action_properties), },
};
/* Target types for dropping to the tree view */
static const GtkTargetEntry drop_targets[] =
{
{ "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, TARGET_GTK_TREE_MODEL_ROW },
{ "text/uri-list", 0, TARGET_TEXT_URI_LIST }
};
/* Target types for dragging files in the tree view */
static const GtkTargetEntry drag_targets[] = {
{ "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, TARGET_GTK_TREE_MODEL_ROW }
};
G_DEFINE_TYPE (ThunarRenamerDialog, thunar_renamer_dialog, THUNAR_TYPE_ABSTRACT_DIALOG)
static void
thunar_renamer_dialog_class_init (ThunarRenamerDialogClass *klass)
{
GtkDialogClass *gtkdialog_class;
GtkWidgetClass *gtkwidget_class;
GObjectClass *gobject_class;
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->dispose = thunar_renamer_dialog_dispose;
gobject_class->finalize = thunar_renamer_dialog_finalize;
gobject_class->get_property = thunar_renamer_dialog_get_property;
gobject_class->set_property = thunar_renamer_dialog_set_property;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->realize = thunar_renamer_dialog_realize;
gtkwidget_class->unrealize = thunar_renamer_dialog_unrealize;
gtkdialog_class = GTK_DIALOG_CLASS (klass);
gtkdialog_class->response = thunar_renamer_dialog_response;
/**
* ThunarRenamerDialog:current-directory:
*
* The current directory of the #ThunarRenamerDialog,
* which is the default directory for the "Add Files"
* dialog. May also be %NULL in which case the default
* current directory of the file manager process will
* be used.
**/
g_object_class_install_property (gobject_class,
PROP_CURRENT_DIRECTORY,
g_param_spec_object ("current-directory",
"current-directory",
"current-directory",
THUNAR_TYPE_FILE,
EXO_PARAM_READWRITE));
/**
* ThunarRenamerDialog:selected-files:
*
* The list of currently selected #ThunarFile<!---->s
* in this #ThunarRenamerDialog.
**/
g_object_class_install_property (gobject_class,
PROP_SELECTED_FILES,
g_param_spec_boxed ("selected-files",
"selected-files",
"selected-files",
THUNARX_TYPE_FILE_INFO_LIST,
EXO_PARAM_READABLE));
/**
* ThunarRenamerDialog:standalone:
*
* %TRUE if the #ThunarRenamerDialog should display a
* toolbar and add several actions which are only
* useful in a standalone fashion.
*
* If the #ThunarRenamerDialog is opened from within
* Thunar this property will always be %FALSE.
**/
g_object_class_install_property (gobject_class,
PROP_STANDALONE,
g_param_spec_boolean ("standalone",
"standalone",
"standalone",
FALSE,
EXO_PARAM_READWRITE));
}
static gint
trd_renamer_compare (gconstpointer a,
gconstpointer b)
{
return g_utf8_collate (thunarx_renamer_get_name (THUNARX_RENAMER (a)),
thunarx_renamer_get_name (THUNARX_RENAMER (b)));
}
static void
thunar_renamer_dialog_init (ThunarRenamerDialog *renamer_dialog)
{
ThunarxProviderFactory *provider_factory;
GtkTreeViewColumn *column;
GtkTreeSelection *selection;
GtkCellRenderer *renderer;
GtkAccelGroup *accel_group;
GtkSizeGroup *size_group;
const gchar *active_str;
GHashTable *settings;
GEnumClass *klass;
GtkWidget *notebook;
GtkWidget *toolbar;
GtkWidget *button;
GtkWidget *mcombo;
GtkWidget *rcombo;
GtkWidget *frame;
GtkWidget *image;
GtkWidget *label;
GtkWidget *hbox;
GtkWidget *mbox;
GtkWidget *rbox;
GtkWidget *vbox;
GtkWidget *swin;
XfceRc *rc;
gchar **entries;
GList *providers;
GList *renamers = NULL;
GList *lp;
gint active = 0;
guint n;
/* allocate a new bulk rename model */
renamer_dialog->model = thunar_renamer_model_new ();
/* determine the list of available renamers (using the renamer providers) */
provider_factory = thunarx_provider_factory_get_default ();
providers = thunarx_provider_factory_list_providers (provider_factory, THUNARX_TYPE_RENAMER_PROVIDER);
for (lp = providers; lp != NULL; lp = lp->next)
{
/* determine the renamers for this provider */
renamers = g_list_concat (renamers, thunarx_renamer_provider_get_renamers (lp->data));
/* release this provider */
g_object_unref (G_OBJECT (lp->data));
}
g_object_unref (G_OBJECT (provider_factory));
g_list_free (providers);
/* initialize the dialog */
gtk_window_set_default_size (GTK_WINDOW (renamer_dialog), 510, 490);
gtk_window_set_title (GTK_WINDOW (renamer_dialog), _("Rename Multiple Files"));
/* add the Cancel/Close buttons */
renamer_dialog->cancel_button = gtk_dialog_add_button (GTK_DIALOG (renamer_dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
renamer_dialog->close_button = gtk_dialog_add_button (GTK_DIALOG (renamer_dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_DELETE_EVENT);
gtk_widget_hide (renamer_dialog->close_button);
/* add the "Rename Files" button */
button = gtk_dialog_add_button (GTK_DIALOG (renamer_dialog), _("_Rename Files"), GTK_RESPONSE_ACCEPT);
exo_binding_new (G_OBJECT (renamer_dialog->model), "can-rename", G_OBJECT (button), "sensitive");
gtk_dialog_set_default_response (GTK_DIALOG (renamer_dialog), GTK_RESPONSE_ACCEPT);
gtk_widget_set_tooltip_text (button, _("Click here to actually rename the files listed above to their new names."));
/* setup the action group for this dialog */
renamer_dialog->action_group = gtk_action_group_new ("ThunarRenamerDialog");
gtk_action_group_set_translation_domain (renamer_dialog->action_group, GETTEXT_PACKAGE);
gtk_action_group_add_actions (renamer_dialog->action_group, action_entries, G_N_ELEMENTS (action_entries), GTK_WIDGET (renamer_dialog));
/* setup the UI manager for this dialog */
renamer_dialog->ui_manager = gtk_ui_manager_new ();
gtk_ui_manager_insert_action_group (renamer_dialog->ui_manager, renamer_dialog->action_group, 0);
gtk_ui_manager_add_ui_from_string (renamer_dialog->ui_manager, thunar_renamer_dialog_ui, thunar_renamer_dialog_ui_length, NULL);
/* connect the accelerators */
accel_group = gtk_ui_manager_get_accel_group (renamer_dialog->ui_manager);
gtk_window_add_accel_group (GTK_WINDOW (renamer_dialog), accel_group);
/* setup the launcher support for this dialog */
renamer_dialog->launcher = thunar_launcher_new ();
thunar_launcher_set_widget (renamer_dialog->launcher, GTK_WIDGET (renamer_dialog));
thunar_component_set_ui_manager (THUNAR_COMPONENT (renamer_dialog->launcher), renamer_dialog->ui_manager);
exo_binding_new (G_OBJECT (renamer_dialog), "selected-files", G_OBJECT (renamer_dialog->launcher), "selected-files");
/* add the toolbar to the dialog */
toolbar = gtk_ui_manager_get_widget (renamer_dialog->ui_manager, "/toolbar");
exo_binding_new (G_OBJECT (renamer_dialog), "standalone", G_OBJECT (toolbar), "visible");
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (renamer_dialog)->vbox), toolbar, FALSE, FALSE, 0);
/* create the main vbox */
mbox = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (mbox), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (renamer_dialog)->vbox), mbox, TRUE, TRUE, 0);
gtk_widget_show (mbox);
/* create the scrolled window for the tree view */
swin = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin), GTK_SHADOW_ETCHED_IN);
gtk_box_pack_start (GTK_BOX (mbox), swin, TRUE, TRUE, 0);
gtk_widget_show (swin);
/* create the tree view */
renamer_dialog->tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (renamer_dialog->model));
gtk_tree_view_set_search_column (GTK_TREE_VIEW (renamer_dialog->tree_view), THUNAR_RENAMER_MODEL_COLUMN_OLDNAME);
gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (renamer_dialog->tree_view), TRUE);
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (renamer_dialog->tree_view), TRUE);
gtk_tree_view_set_rubber_banding (GTK_TREE_VIEW (renamer_dialog->tree_view), TRUE);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (renamer_dialog->tree_view), TRUE);
g_signal_connect (G_OBJECT (renamer_dialog->tree_view), "button-press-event", G_CALLBACK (thunar_renamer_dialog_button_press_event), renamer_dialog);
g_signal_connect (G_OBJECT (renamer_dialog->tree_view), "popup-menu", G_CALLBACK (thunar_renamer_dialog_popup_menu), renamer_dialog);
g_signal_connect (G_OBJECT (renamer_dialog->tree_view), "row-activated", G_CALLBACK (thunar_renamer_dialog_row_activated), renamer_dialog);
gtk_container_add (GTK_CONTAINER (swin), renamer_dialog->tree_view);
gtk_widget_show (renamer_dialog->tree_view);
/* create the tree view column for the old file name */
renamer_dialog->name_column = column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_spacing (column, 2);
gtk_tree_view_column_set_min_width (column, 100);
gtk_tree_view_column_set_title (column, _("Name"));
gtk_tree_view_column_set_resizable (column, TRUE);
gtk_tree_view_column_set_fixed_width (column, 250);
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_clickable (column, TRUE);
g_signal_connect (G_OBJECT (column), "clicked", G_CALLBACK (thunar_renamer_dialog_name_column_clicked), renamer_dialog);
renderer = g_object_new (THUNAR_TYPE_ICON_RENDERER, "size", 16, NULL);
gtk_tree_view_column_pack_start (column, renderer, FALSE);
gtk_tree_view_column_set_attributes (column, renderer, "file", THUNAR_RENAMER_MODEL_COLUMN_FILE, NULL);
renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_set_attributes (column, renderer, "text", THUNAR_RENAMER_MODEL_COLUMN_OLDNAME, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (renamer_dialog->tree_view), column);
/* create the tree view column for the new file name */
column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_min_width (column, 75);
gtk_tree_view_column_set_resizable (column, TRUE);
gtk_tree_view_column_set_title (column, _("New Name"));
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
"ellipsize", PANGO_ELLIPSIZE_END,
"foreground", "Red",
NULL);
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_set_attributes (column, renderer,
"foreground-set", THUNAR_RENAMER_MODEL_COLUMN_CONFLICT,
"text", THUNAR_RENAMER_MODEL_COLUMN_NEWNAME,
"weight", THUNAR_RENAMER_MODEL_COLUMN_CONFLICT_WEIGHT,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (renamer_dialog->tree_view), column);
/* create the vbox for the renamer parameters */
vbox = gtk_vbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (mbox), vbox, FALSE, FALSE, 0);
gtk_widget_show (vbox);
/* create the hbox for the renamer selection */
rbox = gtk_hbox_new (FALSE, 3);
gtk_box_pack_start (GTK_BOX (vbox), rbox, FALSE, FALSE, 0);
gtk_widget_show (rbox);
/* create the rename progress bar */
renamer_dialog->progress = thunar_renamer_progress_new ();
gtk_box_pack_start (GTK_BOX (vbox), renamer_dialog->progress, FALSE, FALSE, 0);
exo_binding_new_with_negation (G_OBJECT (renamer_dialog->progress), "visible", G_OBJECT (rbox), "visible");
exo_binding_new_with_negation (G_OBJECT (renamer_dialog->progress), "visible", G_OBJECT (swin), "sensitive");
exo_binding_new_with_negation (G_OBJECT (renamer_dialog->progress), "visible", G_OBJECT (toolbar), "sensitive");
exo_binding_new (G_OBJECT (renamer_dialog->progress), "visible", G_OBJECT (renamer_dialog->model), "frozen");
/* synchronize the height of the progress bar and the rbox with the combos */
size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
gtk_size_group_add_widget (size_group, renamer_dialog->progress);
gtk_size_group_add_widget (size_group, rbox);
g_object_unref (G_OBJECT (size_group));
/* create the frame for the renamer widgets */
frame = g_object_new (GTK_TYPE_FRAME, "shadow-type", GTK_SHADOW_ETCHED_IN, NULL);
exo_binding_new_with_negation (G_OBJECT (renamer_dialog->progress), "visible", G_OBJECT (frame), "sensitive");
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
/* check if we have any renamers */
if (G_LIKELY (renamers != NULL))
{
/* sort the renamers by name */
renamers = g_list_sort (renamers, trd_renamer_compare);
/* open the config file, xfce_rc_config_open() should never return NULL */
rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "Thunar/renamerrc", TRUE);
xfce_rc_set_group (rc, "Configuration");
/* create the renamer combo box for the renamer selection */
rcombo = gtk_combo_box_text_new ();
for (lp = renamers; lp != NULL; lp = lp->next)
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (rcombo), thunarx_renamer_get_name (lp->data));
gtk_box_pack_start (GTK_BOX (rbox), rcombo, FALSE, FALSE, 0);
gtk_widget_show (rcombo);
/* add a "Help" button */
button = gtk_button_new ();
gtk_widget_set_tooltip_text (button, _("Click here to view the documentation for the selected rename operation."));
g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (thunar_renamer_dialog_help), renamer_dialog);
gtk_box_pack_start (GTK_BOX (rbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
image = gtk_image_new_from_stock (GTK_STOCK_HELP, GTK_ICON_SIZE_BUTTON);
gtk_container_add (GTK_CONTAINER (button), image);
gtk_widget_show (image);
/* create the name/suffix/both combo box */
mcombo = gtk_combo_box_text_new ();
klass = g_type_class_ref (THUNAR_TYPE_RENAMER_MODE);
active_str = xfce_rc_read_entry_untranslated (rc, "LastActiveMode", "");
for (active = 0, n = 0; n < klass->n_values; ++n)
{
if (exo_str_is_equal (active_str, klass->values[n].value_name))
active = n;
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (mcombo), _(klass->values[n].value_nick));
}
exo_mutual_binding_new (G_OBJECT (renamer_dialog->model), "mode", G_OBJECT (mcombo), "active");
gtk_box_pack_end (GTK_BOX (rbox), mcombo, FALSE, FALSE, 0);
gtk_combo_box_set_active (GTK_COMBO_BOX (mcombo), active);
g_type_class_unref (klass);
gtk_widget_show (mcombo);
/* allocate the notebook with the renamers */
notebook = gtk_notebook_new ();
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);
g_signal_connect (G_OBJECT (notebook), "notify::page", G_CALLBACK (thunar_renamer_dialog_notify_page), renamer_dialog);
gtk_container_add (GTK_CONTAINER (frame), notebook);
gtk_widget_show (notebook);
/* determine the last active renamer (as string) */
active_str = xfce_rc_read_entry_untranslated (rc, "LastActiveRenamer", "");
/* add the renamers to the notebook */
for (active = 0, lp = renamers; lp != NULL; lp = lp->next)
{
/* append the renamer to the notebook... */
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), lp->data, NULL);
/* check if this page should be active by default */
if (exo_str_is_equal (G_OBJECT_TYPE_NAME (lp->data), active_str))
active = g_list_position (renamers, lp);
/* try to load the settings for the renamer */
entries = xfce_rc_get_entries (rc, G_OBJECT_TYPE_NAME (lp->data));
if (G_LIKELY (entries != NULL))
{
/* add the settings to a hash table */
xfce_rc_set_group (rc, G_OBJECT_TYPE_NAME (lp->data));
settings = g_hash_table_new (g_str_hash, g_str_equal);
for (n = 0; entries[n] != NULL; ++n)
g_hash_table_insert (settings, entries[n], (gchar *) xfce_rc_read_entry_untranslated (rc, entries[n], NULL));
/* let the renamer load the settings */
thunarx_renamer_load (THUNARX_RENAMER (lp->data), settings);
/* cleanup */
g_hash_table_destroy (settings);
g_strfreev (entries);
}
/* ...and make sure its visible */
gtk_widget_show (lp->data);
}
/* default to the first renamer */
gtk_combo_box_set_active (GTK_COMBO_BOX (rcombo), active);
/* connect the combo box to the notebook */
exo_binding_new (G_OBJECT (rcombo), "active", G_OBJECT (notebook), "page");
/* close the config handle */
xfce_rc_close (rc);
/* setup drop support for the tree view */
gtk_drag_dest_set (renamer_dialog->tree_view, 0, drop_targets, G_N_ELEMENTS (drop_targets), GDK_ACTION_COPY | GDK_ACTION_MOVE);
gtk_drag_source_set (renamer_dialog->tree_view, GDK_BUTTON1_MASK, drag_targets, G_N_ELEMENTS (drag_targets), GDK_ACTION_MOVE);
g_signal_connect (G_OBJECT (renamer_dialog->tree_view), "drag-data-received", G_CALLBACK (thunar_renamer_dialog_drag_data_received), renamer_dialog);
g_signal_connect (G_OBJECT (renamer_dialog->tree_view), "drag-leave", G_CALLBACK (thunar_renamer_dialog_drag_leave), renamer_dialog);
g_signal_connect (G_OBJECT (renamer_dialog->tree_view), "drag-motion", G_CALLBACK (thunar_renamer_dialog_drag_motion), renamer_dialog);
g_signal_connect (G_OBJECT (renamer_dialog->tree_view), "drag-drop", G_CALLBACK (thunar_renamer_dialog_drag_drop), renamer_dialog);
/* setup the tree selection */
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (renamer_dialog->tree_view));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (thunar_renamer_dialog_selection_changed), renamer_dialog);
thunar_renamer_dialog_selection_changed (selection, renamer_dialog);
}
else
{
/* make the other widgets insensitive */
gtk_widget_set_sensitive (toolbar, FALSE);
gtk_widget_set_sensitive (swin, FALSE);
/* display an error to the user */
hbox = gtk_hbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
gtk_container_add (GTK_CONTAINER (frame), hbox);
gtk_widget_show (hbox);
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
/* TRANSLATORS: You can test this string by temporarily removing thunar-sbr.* from $libdir/thunarx-2/,
* and opening the multi rename dialog by selecting multiple files and pressing F2.
*/
label = gtk_label_new (_("No renamer modules were found on your system. Please check your\n"
"installation or contact your system administrator. If you install Thunar\n"
"from source, be sure to enable the \"Simple Builtin Renamers\" plugin."));
gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
gtk_widget_show (label);
}
/* release the renamers list */
g_list_free_full (renamers, g_object_unref);
}
static void
thunar_renamer_dialog_dispose (GObject *object)
{
ThunarRenamerDialog *renamer_dialog = THUNAR_RENAMER_DIALOG (object);
/* reset the "current-directory" property */
thunar_renamer_dialog_set_current_directory (renamer_dialog, NULL);
/* reset the widget for the launcher support */
thunar_launcher_set_widget (renamer_dialog->launcher, NULL);
(*G_OBJECT_CLASS (thunar_renamer_dialog_parent_class)->dispose) (object);
}
static void
thunar_renamer_dialog_finalize (GObject *object)
{
ThunarRenamerDialog *renamer_dialog = THUNAR_RENAMER_DIALOG (object);
/* release the launcher support */
g_object_unref (G_OBJECT (renamer_dialog->launcher));
/* release the action group and the ui manager */
g_object_unref (G_OBJECT (renamer_dialog->action_group));
g_object_unref (G_OBJECT (renamer_dialog->ui_manager));
/* release our bulk rename model */
g_object_unref (G_OBJECT (renamer_dialog->model));
/* release the list of selected files */
thunarx_file_info_list_free (renamer_dialog->selected_files);
(*G_OBJECT_CLASS (thunar_renamer_dialog_parent_class)->finalize) (object);
}
static void
thunar_renamer_dialog_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ThunarRenamerDialog *renamer_dialog = THUNAR_RENAMER_DIALOG (object);
switch (prop_id)
{
case PROP_CURRENT_DIRECTORY:
g_value_set_object (value, thunar_renamer_dialog_get_current_directory (renamer_dialog));
break;
case PROP_SELECTED_FILES:
g_value_set_boxed (value, thunar_renamer_dialog_get_selected_files (renamer_dialog));
break;
case PROP_STANDALONE:
g_value_set_boolean (value, thunar_renamer_dialog_get_standalone (renamer_dialog));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
thunar_renamer_dialog_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ThunarRenamerDialog *renamer_dialog = THUNAR_RENAMER_DIALOG (object);
switch (prop_id)
{
case PROP_CURRENT_DIRECTORY:
thunar_renamer_dialog_set_current_directory (renamer_dialog, g_value_get_object (value));
break;
case PROP_STANDALONE:
thunar_renamer_dialog_set_standalone (renamer_dialog, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
thunar_renamer_dialog_realize (GtkWidget *widget)
{
ThunarRenamerDialog *renamer_dialog = THUNAR_RENAMER_DIALOG (widget);
GtkIconTheme *icon_theme;
/* realize the widget */
(*GTK_WIDGET_CLASS (thunar_renamer_dialog_parent_class)->realize) (widget);
/* grab a reference on the icon factory for the screen */
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
renamer_dialog->icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme);
}
static void
thunar_renamer_dialog_unrealize (GtkWidget *widget)
{
ThunarRenamerDialog *renamer_dialog = THUNAR_RENAMER_DIALOG (widget);
/* release the reference on the icon factory */
g_object_unref (G_OBJECT (renamer_dialog->icon_factory));
renamer_dialog->icon_factory = NULL;
/* unrealize the dialog */
(*GTK_WIDGET_CLASS (thunar_renamer_dialog_parent_class)->unrealize) (widget);
}
static void
thunar_renamer_dialog_response (GtkDialog *dialog,
gint response)
{
ThunarRenamerDialog *renamer_dialog = THUNAR_RENAMER_DIALOG (dialog);
GtkTreeIter iter;
ThunarFile *file;
GList *pair_list = NULL;
gchar *name;
/* grab an additional reference on the dialog */
g_object_ref (G_OBJECT (dialog));
/* check if we should rename */
if (G_LIKELY (response == GTK_RESPONSE_ACCEPT))
{
/* hide the close button and show the cancel button */
gtk_widget_show (renamer_dialog->cancel_button);
gtk_widget_hide (renamer_dialog->close_button);
/* save the current settings */
thunar_renamer_dialog_save (renamer_dialog);
/* display the rename progress bar */
gtk_widget_show (renamer_dialog->progress);
/* determine the iterator for the first item */
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (renamer_dialog->model), &iter))
{
/* determine the tree row references for the rows that should be renamed */
do
{
/* determine the file and newname for the row */
gtk_tree_model_get (GTK_TREE_MODEL (renamer_dialog->model), &iter,
THUNAR_RENAMER_MODEL_COLUMN_NEWNAME, &name,
THUNAR_RENAMER_MODEL_COLUMN_FILE, &file,
-1);
/* check if this row should be renamed */
if (G_LIKELY (name != NULL && *name != '\0'))
pair_list = g_list_append (pair_list, thunar_renamer_pair_new (file, name));
/* cleanup */
g_object_unref (file);
g_free (name);
}
while (gtk_tree_model_iter_next (GTK_TREE_MODEL (renamer_dialog->model), &iter));
}
/* perform the rename (returns when done) */
thunar_renamer_progress_run (THUNAR_RENAMER_PROGRESS (renamer_dialog->progress), pair_list);
/* hide the rename progress bar */
gtk_widget_hide (renamer_dialog->progress);
/* release the pairs */
thunar_renamer_pair_list_free (pair_list);
/* check if we're in standalone mode */
if (thunar_renamer_dialog_get_standalone (renamer_dialog))
{
/* hide the cancel button again and display the close button */
gtk_widget_hide (renamer_dialog->cancel_button);
gtk_widget_show (renamer_dialog->close_button);
}
else
{
/* hide and destroy the dialog window */
gtk_widget_hide (GTK_WIDGET (dialog));
gtk_widget_destroy (GTK_WIDGET (dialog));
}
}
else if (thunar_renamer_progress_running (THUNAR_RENAMER_PROGRESS (renamer_dialog->progress)))
{
/* cancel the rename operation */
thunar_renamer_progress_cancel (THUNAR_RENAMER_PROGRESS (renamer_dialog->progress));
}
else
{
/* hide and destroy the dialog window */
gtk_widget_hide (GTK_WIDGET (dialog));
gtk_widget_destroy (GTK_WIDGET (dialog));
}
/* release the additional reference on the dialog */
g_object_unref (G_OBJECT (dialog));
}
static void
thunar_renamer_dialog_context_menu (ThunarRenamerDialog *renamer_dialog,
guint button,
guint32 timestamp)
{
GtkActionGroup *renamer_actions = NULL;
ThunarxRenamer *renamer;
GtkWidget *menu;
GList *actions = NULL;
GList *lp;
gint renamer_merge_id = 0;
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
/* grab an additional reference on the dialog */
g_object_ref (G_OBJECT (renamer_dialog));
/* determine the active renamer */
renamer = thunar_renamer_model_get_renamer (renamer_dialog->model);
if (G_LIKELY (renamer != NULL))
{
/* determine the actions provided by the active renamer */
actions = thunarx_renamer_get_actions (renamer, GTK_WINDOW (renamer_dialog), renamer_dialog->selected_files);
}
/* check if we have any renamer actions */
if (G_UNLIKELY (actions != NULL))
{
/* allocate a new action group and the merge id for the custom actions */
renamer_actions = gtk_action_group_new ("thunar-renamer-dialog-renamer-actions");
renamer_merge_id = gtk_ui_manager_new_merge_id (renamer_dialog->ui_manager);
gtk_ui_manager_insert_action_group (renamer_dialog->ui_manager, renamer_actions, -1);
/* add the actions to the UI manager */
for (lp = actions; lp != NULL; lp = lp->next)
{
/* add the action to the action group */
gtk_action_group_add_action (renamer_actions, GTK_ACTION (lp->data));
/* add the action to the UI manager */
gtk_ui_manager_add_ui (renamer_dialog->ui_manager, renamer_merge_id,
"/file-context-menu/placeholder-renamer-actions",
gtk_action_get_name (GTK_ACTION (lp->data)),
gtk_action_get_name (GTK_ACTION (lp->data)),
GTK_UI_MANAGER_MENUITEM, FALSE);
/* release the reference on the action */
g_object_unref (G_OBJECT (lp->data));
}
/* be sure to update the UI manager to avoid flickering */
gtk_ui_manager_ensure_update (renamer_dialog->ui_manager);
/* cleanup */
g_list_free (actions);
}
/* run the menu on the dialog's screen */
menu = gtk_ui_manager_get_widget (renamer_dialog->ui_manager, "/file-context-menu");
thunar_gtk_menu_run (GTK_MENU (menu), GTK_WIDGET (renamer_dialog), NULL, NULL, button, timestamp);
/* remove the previously merge items from the UI manager */
if (G_UNLIKELY (renamer_merge_id != 0))
{
gtk_ui_manager_remove_ui (renamer_dialog->ui_manager, renamer_merge_id);
gtk_ui_manager_ensure_update (renamer_dialog->ui_manager);
}
/* disconnect the previously created action group */
if (G_UNLIKELY (renamer_actions != NULL))
{
gtk_ui_manager_remove_action_group (renamer_dialog->ui_manager, renamer_actions);
g_object_unref (G_OBJECT (renamer_actions));
}
/* release the additional reference on the dialog */
g_object_unref (G_OBJECT (renamer_dialog));
}
static void
thunar_renamer_dialog_help (ThunarRenamerDialog *renamer_dialog)
{
ThunarxRenamer *renamer;
const gchar *help_url = NULL;
GdkScreen *screen;
GError *error = NULL;
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
/* check if the active renamer provides a help URL */
renamer = thunar_renamer_model_get_renamer (renamer_dialog->model);
if (G_LIKELY (renamer != NULL))
help_url = thunarx_renamer_get_help_url (renamer);
/* check if we have a specific URL */
if (G_LIKELY (help_url == NULL))
{
/* open the general documentation if no specific URL */
xfce_dialog_show_help (GTK_WINDOW (renamer_dialog), "thunar",
"bulk-renamer/start", NULL);
}
else
{
/* determine the dialog's screen */
screen = gtk_widget_get_screen (GTK_WIDGET (renamer_dialog));
/* try to launch the specific URL */
if (!gtk_show_uri (screen, help_url, gtk_get_current_event_time (), &error))
{
/* tell the user that we failed */
thunar_dialogs_show_error (GTK_WIDGET (renamer_dialog), error, _("Failed to open the documentation browser"));
/* release the error */
g_error_free (error);
}
}
}
static void
trd_save_foreach (gpointer key,
gpointer value,
gpointer user_data)
{
xfce_rc_write_entry (user_data, key, value);
}
static void
thunar_renamer_dialog_save (ThunarRenamerDialog *renamer_dialog)
{
ThunarxRenamer *renamer;
GHashTable *settings;
GEnumClass *klass;
GEnumValue *value;
XfceRc *rc;
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
/* try to open the config handle for writing */
rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "Thunar/renamerrc", FALSE);
if (G_UNLIKELY (rc == NULL))
return;
/* determine the currently active renamer */
renamer = thunar_renamer_model_get_renamer (renamer_dialog->model);
if (G_LIKELY (renamer != NULL))
{
/* save general settings first */
xfce_rc_set_group (rc, "Configuration");
/* remember current mode as last active */
klass = g_type_class_ref (THUNAR_TYPE_RENAMER_MODE);
value = g_enum_get_value (klass, thunar_renamer_model_get_mode (renamer_dialog->model));
if (G_LIKELY (value != NULL))
xfce_rc_write_entry (rc, "LastActiveMode", value->value_name);
g_type_class_unref (klass);
/* remember renamer as last active */
xfce_rc_write_entry (rc, "LastActiveRenamer", G_OBJECT_TYPE_NAME (renamer));
/* save the renamer's settings */
settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
xfce_rc_delete_group (rc, G_OBJECT_TYPE_NAME (renamer), TRUE);
xfce_rc_set_group (rc, G_OBJECT_TYPE_NAME (renamer));
thunarx_renamer_save (renamer, settings);
g_hash_table_foreach (settings, trd_save_foreach, rc);
g_hash_table_destroy (settings);
}
/* close the config handle */
xfce_rc_close (rc);
}
static gboolean
trd_audio_filter_func (const GtkFileFilterInfo *info,
gpointer data)
{
/* check if the MIME type is an audio MIME type */
return (strncmp (info->mime_type, "audio/", 6) == 0);
}
static gboolean
trd_video_filter_func (const GtkFileFilterInfo *info,
gpointer data)
{
/* check if the MIME type is a video MIME type */
return (strncmp (info->mime_type, "video/", 6) == 0);
}
static void
thunar_renamer_dialog_action_add_files (GtkAction *action,
ThunarRenamerDialog *renamer_dialog)
{
GtkFileFilter *filter;
ThunarFile *file;
GtkWidget *chooser;
GSList *uris;
GSList *lp;
gchar *uri;
_thunar_return_if_fail (GTK_IS_ACTION (action));
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
/* allocate the file chooser */
chooser = gtk_file_chooser_dialog_new (_("Select files to rename"),
GTK_WINDOW (renamer_dialog),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), TRUE);
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
/* add file chooser filers */
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("All Files"));
gtk_file_filter_add_pattern (filter, "*");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("Audio Files"));
gtk_file_filter_add_custom (filter, GTK_FILE_FILTER_MIME_TYPE, trd_audio_filter_func, NULL, NULL);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("Image Files"));
gtk_file_filter_add_pixbuf_formats (filter);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("Video Files"));
gtk_file_filter_add_custom (filter, GTK_FILE_FILTER_MIME_TYPE, trd_video_filter_func, NULL, NULL);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
/* check if "current-directory" is set */
if (G_LIKELY (renamer_dialog->current_directory != NULL))
{
/* use the "current-directory" as default for the chooser */
uri = thunarx_file_info_get_uri (THUNARX_FILE_INFO (renamer_dialog->current_directory));
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser), uri);
g_free (uri);
}
/* run the chooser dialog */
if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
{
/* determine the URIs of the selected files */
uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
for (lp = uris; lp != NULL; lp = lp->next)
{
/* determine the file for the URI */
file = thunar_file_get_for_uri (lp->data, NULL);
if (G_LIKELY (file != NULL))
{
/* append the file to the renamer model */
thunar_renamer_model_append (renamer_dialog->model, file);
/* unset sort order */
gtk_tree_view_column_set_sort_indicator (renamer_dialog->name_column, FALSE);
/* release the file */
g_object_unref (G_OBJECT (file));
}
/* release the URI */
g_free (lp->data);
}
g_slist_free (uris);
/* determine the current folder of the chooser */
uri = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (chooser));
if (G_LIKELY (uri != NULL))
{
/* determine the file for that URI */
file = thunar_file_get_for_uri (uri, NULL);
if (G_LIKELY (file != NULL))
{
/* remember the current folder of the chooser as default */
thunar_renamer_dialog_set_current_directory (renamer_dialog, file);
/* release the file */
g_object_unref (G_OBJECT (file));
}
/* release the URI */
g_free (uri);
}
}
/* cleanup */
gtk_widget_destroy (chooser);
}
static void
thunar_renamer_dialog_action_remove_files (GtkAction *action,
ThunarRenamerDialog *renamer_dialog)
{
GtkTreeRowReference *row;
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreePath *path;
GList *rows;
GList *lp;
_thunar_return_if_fail (GTK_IS_ACTION (action));
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
/* determine the selected rows in the view */
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (renamer_dialog->tree_view));
rows = gtk_tree_selection_get_selected_rows (selection, &model);
for (lp = rows; lp != NULL; lp = lp->next)
{
/* turn the path into a tree row reference */
row = gtk_tree_row_reference_new (model, lp->data);
gtk_tree_path_free (lp->data);
lp->data = row;
}
/* actually remove the rows */
for (lp = rows; lp != NULL; lp = lp->next)
{
/* determine the path for the row */
path = gtk_tree_row_reference_get_path (lp->data);
if (G_LIKELY (path != NULL))
{
/* remove the row from the model */
thunar_renamer_model_remove (THUNAR_RENAMER_MODEL (model), path);
gtk_tree_path_free (path);
}
/* release the row reference */
gtk_tree_row_reference_free (lp->data);
}
/* cleanup */
g_list_free (rows);
}
static void
thunar_renamer_dialog_action_clear (GtkAction *action,
ThunarRenamerDialog *renamer_dialog)
{
_thunar_return_if_fail (GTK_IS_ACTION (action));
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
/* just clear the list of files in the model */
thunar_renamer_model_clear (renamer_dialog->model);
}
static void
thunar_renamer_dialog_action_about (GtkAction *action,
ThunarRenamerDialog *renamer_dialog)
{
_thunar_return_if_fail (GTK_IS_ACTION (action));
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
/* just popup the about dialog */
thunar_dialogs_show_about (GTK_WINDOW (renamer_dialog), _("Bulk Rename"),
_("Thunar Bulk Rename is a powerful and extensible\n"
"tool to rename multiple files at once."));
}
static void
thunar_renamer_dialog_action_properties (GtkAction *action,
ThunarRenamerDialog *renamer_dialog)
{
GtkWidget *dialog;
_thunar_return_if_fail (GTK_IS_ACTION (action));
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
/* popup the properties dialog */
dialog = thunar_properties_dialog_new (GTK_WINDOW (renamer_dialog));
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
thunar_properties_dialog_set_files (THUNAR_PROPERTIES_DIALOG (dialog), renamer_dialog->selected_files);
gtk_widget_show (dialog);
}
static void
thunar_renamer_dialog_name_column_clicked (GtkTreeViewColumn *column,
ThunarRenamerDialog *renamer_dialog)
{
GtkSortType sort_order = GTK_SORT_ASCENDING;
_thunar_return_if_fail (renamer_dialog->name_column == column);
if (!gtk_tree_view_column_get_sort_indicator (column))
{
/* show sort order */
gtk_tree_view_column_set_sort_indicator (column, TRUE);
}
else
{
/* invert new sort order */
if (gtk_tree_view_column_get_sort_order (column) == GTK_SORT_ASCENDING)
sort_order = GTK_SORT_DESCENDING;
else
sort_order = GTK_SORT_ASCENDING;
}
/* set new sort direction */
gtk_tree_view_column_set_sort_order (column, sort_order);
/* sort the model */
thunar_renamer_model_sort (renamer_dialog->model, sort_order);
}
static gboolean
thunar_renamer_dialog_button_press_event (GtkWidget *tree_view,
GdkEventButton *event,
ThunarRenamerDialog *renamer_dialog)
{
GtkTreeSelection *selection;
GtkTreePath *path;
_thunar_return_val_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog), FALSE);
_thunar_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), FALSE);
/* determine the tree selection */
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
/* we unselect all selected items if the user clicks on an empty
* area of the treeview and no modifier key is active.
*/
if ((event->state & gtk_accelerator_get_default_mod_mask ()) == 0
&& !gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree_view), event->x, event->y, NULL, NULL, NULL, NULL))
{
/* just unselect all rows */
gtk_tree_selection_unselect_all (selection);
}
/* check if we should popup the context menu */
if (event->window == gtk_tree_view_get_bin_window (GTK_TREE_VIEW (tree_view)) && event->type == GDK_BUTTON_PRESS && event->button == 3)
{
/* determine the path at the event coordinates */
if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree_view), event->x, event->y, &path, NULL, NULL, NULL))
{
/* select the path on which the user clicked if not already selected */
if (!gtk_tree_selection_path_is_selected (selection, path))
{
/* we don't unselect all other items if Control is active */
if ((event->state & GDK_CONTROL_MASK) == 0)
gtk_tree_selection_unselect_all (selection);
gtk_tree_selection_select_path (selection, path);
}
/* release the tree path */
gtk_tree_path_free (path);
}
/* popup the context menu */
thunar_renamer_dialog_context_menu (renamer_dialog, event->button, event->time);
/* we handled the event */
return TRUE;
}
return FALSE;
}
static void
thunar_renamer_dialog_drag_data_received (GtkWidget *tree_view,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint timestamp,
ThunarRenamerDialog *renamer_dialog)
{
ThunarFile *file;
GList *file_list;
GList *lp;
GtkTreeModel *model;
GtkTreePath *path;
GtkTreeViewDropPosition drop_pos;
gint position = -1;
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
_thunar_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
/* we only accept text/uri-list drops with format 8 and atleast one byte of data */
if (info == TARGET_TEXT_URI_LIST && selection_data->format == 8 && selection_data->length > 0)
{
/* determine the renamer model */
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
/* get the drop position, if no path is foud we append the files */
if (gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (tree_view), x, y, &path, &drop_pos))
{
/* get the position of the path */
position = gtk_tree_path_get_indices (path)[0];
gtk_tree_path_free (path);
/* advance the offset if we drop after the item */
if (drop_pos == GTK_TREE_VIEW_DROP_AFTER || drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
position++;
/* append if we've reached the end of the model */
if (position >= gtk_tree_model_iter_n_children (model, NULL))
position = -1;
}
/* determine the file list from the selection_data */
file_list = thunar_g_file_list_new_from_string ((const gchar *) selection_data->data);
/* add all paths to the model */
for (lp = file_list; lp != NULL; lp = lp->next)
{
/* determine the file for the path */
file = thunar_file_get (lp->data, NULL);
if (G_LIKELY (file != NULL))
{
/* insert the file in the model */
thunar_renamer_model_insert (renamer_dialog->model, file, position);
/* unset sort order */
gtk_tree_view_column_set_sort_indicator (renamer_dialog->name_column, FALSE);
/* advance the offset if we do not append, so the drop order is consistent */
if (position != -1)
position++;
/* release the file */
g_object_unref (file);
}
/* release the GFile */
g_object_unref (lp->data);
}
/* finish the drag */
gtk_drag_finish (context, (file_list != NULL), FALSE, timestamp);
/* release the list */
g_list_free (file_list);
}
/* stop the emission of the "drag-data-received" signal */
g_signal_stop_emission_by_name (G_OBJECT (tree_view), "drag-data-received");
}
static void
thunar_renamer_dialog_drag_leave (GtkWidget *tree_view,
GdkDragContext *context,
guint timestamp,
ThunarRenamerDialog *renamer_dialog)
{
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
_thunar_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
/* disable the highlighting */
if (renamer_dialog->drag_highlighted)
{
/* we use the tree view parent (the scrolled window),
* as the drag_highlight doesn't work for tree views.
*/
gtk_drag_unhighlight (tree_view->parent);
renamer_dialog->drag_highlighted = FALSE;
}
}
static gboolean
thunar_renamer_dialog_drag_motion (GtkWidget *tree_view,
GdkDragContext *context,
gint x,
gint y,
guint timestamp,
ThunarRenamerDialog *renamer_dialog)
{
GdkAtom target;
GtkTreeViewDropPosition position;
GtkTreePath *path;
GdkDragAction action;
GtkTreeModel *model;
gint n_rows;
_thunar_return_val_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog), FALSE);
_thunar_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), FALSE);
/* determine the drop target */
target = gtk_drag_dest_find_target (tree_view, context, NULL);
if (target == gdk_atom_intern_static_string ("text/uri-list"))
{
/* set the drag action for uris */
action = GDK_ACTION_COPY;
}
else if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
{
/* set the drag action for tree rows */
action = GDK_ACTION_MOVE;
}
else
{
if (renamer_dialog->drag_highlighted)
{
/* we use the tree view parent (the scrolled window),
* as the drag_highlight doesn't work for tree views.
*/
gtk_drag_unhighlight (tree_view->parent);
renamer_dialog->drag_highlighted = FALSE;
}
/* we cannot handle the drop */
return FALSE;
}
/* compute the drop position */
if (gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (tree_view), x, y, &path, &position))
{
/* we can only drop before or after an item */
if (position == GTK_TREE_VIEW_DROP_BEFORE || position == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
position = GTK_TREE_VIEW_DROP_BEFORE;
else
position = GTK_TREE_VIEW_DROP_AFTER;
}
else
{
/* append the item if there are rows in the model */
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
n_rows = gtk_tree_model_iter_n_children (model, NULL);
if (G_LIKELY (n_rows > 0))
{
/* get the last tree path in the model */
path = gtk_tree_path_new_from_indices (n_rows - 1, -1);
position = GTK_TREE_VIEW_DROP_AFTER;
}
}
if (G_LIKELY (path != NULL))
{
/* highlight the appropriate row */
gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (tree_view), path, position);
gtk_tree_path_free (path);
}
else if (!renamer_dialog->drag_highlighted)
{
/* highlight the parent */
gtk_drag_highlight (tree_view->parent);
renamer_dialog->drag_highlighted = TRUE;
}
/* we can handle the drop */
gdk_drag_status (context, action, timestamp);
return TRUE;
}
static gboolean
thunar_renamer_dialog_drag_drop (GtkWidget *tree_view,
GdkDragContext *context,
gint x,
gint y,
guint timestamp,
ThunarRenamerDialog *renamer_dialog)
{
GdkAtom target;
GtkTreeSelection *selection;
GtkTreePath *dst_path;
GtkTreeModel *model;
GtkTreeViewDropPosition drop_pos;
gint position = -1;
GList *rows;
_thunar_return_val_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog), FALSE);
_thunar_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), FALSE);
/* determine the drop target */
target = gtk_drag_dest_find_target (tree_view, context, NULL);
if (G_LIKELY (target == gdk_atom_intern_static_string ("text/uri-list")))
{
/* request the data, we call gtk_drag_finish() later */
gtk_drag_get_data (tree_view, context, target, timestamp);
}
else if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
{
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
rows = gtk_tree_selection_get_selected_rows (selection, &model);
if (G_LIKELY (rows != NULL))
{
/* get the drop position, if no path is found we append the file */
if (gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (tree_view), x, y, &dst_path, &drop_pos))
{
/* get the position of the path */
position = gtk_tree_path_get_indices (dst_path)[0];
gtk_tree_path_free (dst_path);
/* advance the offset if we drop after the item */
if (drop_pos == GTK_TREE_VIEW_DROP_AFTER || drop_pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
position++;
}
/* perform the move */
if (G_LIKELY (rows != NULL))
{
thunar_renamer_model_reorder (renamer_dialog->model, rows, position);
g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free);
}
/* unset sort column */
gtk_tree_view_column_set_sort_indicator (renamer_dialog->name_column, FALSE);
}
/* finish the dnd operation */
gtk_drag_finish (context, TRUE, FALSE, timestamp);
}
else
{
/* we cannot handle the drop */
return FALSE;
}
return TRUE;
}
static void
thunar_renamer_dialog_notify_page (GtkNotebook *notebook,
GParamSpec *pspec,
ThunarRenamerDialog *renamer_dialog)
{
GtkWidget *renamer;
gint page;
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
_thunar_return_if_fail (GTK_IS_NOTEBOOK (notebook));
/* determine the currently active renamer page */
page = gtk_notebook_get_current_page (notebook);
if (G_LIKELY (page >= 0))
{
/* determine the renamer for that page... */
renamer = gtk_notebook_get_nth_page (notebook, page);
/* ...and set that renamer for the model */
thunar_renamer_model_set_renamer (renamer_dialog->model, THUNARX_RENAMER (renamer));
}
}
static gboolean
thunar_renamer_dialog_popup_menu (GtkWidget *tree_view,
ThunarRenamerDialog *renamer_dialog)
{
_thunar_return_val_if_fail (GTK_IS_TREE_VIEW (tree_view), FALSE);
_thunar_return_val_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog), FALSE);
/* popup the context menu */
thunar_renamer_dialog_context_menu (renamer_dialog, 0, gtk_get_current_event_time ());
/* we handled the event */
return TRUE;
}
static void
thunar_renamer_dialog_row_activated (GtkTreeView *tree_view,
GtkTreePath *path,
GtkTreeViewColumn *column,
ThunarRenamerDialog *renamer_dialog)
{
GtkAction *action;
_thunar_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
/* just activate the "open" action */
action = thunar_gtk_ui_manager_get_action_by_name (renamer_dialog->ui_manager, "open");
if (G_LIKELY (action != NULL))
gtk_action_activate (action);
}
static void
thunar_renamer_dialog_selection_changed (GtkTreeSelection *selection,
ThunarRenamerDialog *renamer_dialog)
{
GtkTreeModel *model;
GtkTreeIter iter;
ThunarFile *file;
GtkAction *action;
GList *rows;
GList *lp;
gint n_selected_files = 0;
_thunar_return_if_fail (GTK_IS_TREE_SELECTION (selection));
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
/* release the list of previously selected files */
thunarx_file_info_list_free (renamer_dialog->selected_files);
renamer_dialog->selected_files = NULL;
/* determine the new list of selected files */
rows = gtk_tree_selection_get_selected_rows (selection, &model);
for (lp = g_list_last (rows); lp != NULL; lp = lp->prev, ++n_selected_files)
{
/* determine the iter for this path */
if (gtk_tree_model_get_iter (model, &iter, lp->data))
{
/* determine the file for this row and prepend it to our list */
gtk_tree_model_get (model, &iter, THUNAR_RENAMER_MODEL_COLUMN_FILE, &file, -1);
if (G_LIKELY (file != NULL))
renamer_dialog->selected_files = g_list_prepend (renamer_dialog->selected_files, file);
}
/* release this path */
gtk_tree_path_free (lp->data);
}
g_list_free (rows);
/* the "Remove Files" action is only sensitive if we have one or more files in the selection */
action = gtk_action_group_get_action (renamer_dialog->action_group, "remove-files");
g_object_set (G_OBJECT (action),
"label", ngettext ("Remove File", "Remove Files", n_selected_files),
"sensitive", (n_selected_files > 0),
"tooltip", ngettext ("Remove the selected file from the list of files to be renamed",
"Remove the selected files from the list of files to be renamed",
n_selected_files),
NULL);
/* the "Properties" action is only sensitive if we have exactly one selected file */
action = gtk_action_group_get_action (renamer_dialog->action_group, "properties");
gtk_action_set_sensitive (action, n_selected_files > 0);
/* notify listeners */
g_object_notify (G_OBJECT (renamer_dialog), "selected-files");
}
/**
* thunar_renamer_dialog_get_current_directory:
* @renamer_dialog : a #ThunarRenamerDialog.
*
* Returns the current directory of the @renamer_dialog, which
* is used as default directory for the "Add Files" dialog.
* May also be %NULL in which case the current directory of the
* file manager process will be used.
*
* Return value: the current directory for @renamer_dialog.
**/
static ThunarFile*
thunar_renamer_dialog_get_current_directory (ThunarRenamerDialog *renamer_dialog)
{
_thunar_return_val_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog), NULL);
return renamer_dialog->current_directory;
}
/**
* thunar_renamer_dialog_set_current_directory:
* @renamer_dialog : a #ThunarRenamerDialog.
* @current_directory : a #ThunarFile or %NULL.
*
* The @renamer_dialog will use @current_directory as default
* directory for the "Add Files" dialog. If @current_directory
* is %NULL, the current directory of the file manager process
* will be used.
**/
static void
thunar_renamer_dialog_set_current_directory (ThunarRenamerDialog *renamer_dialog,
ThunarFile *current_directory)
{
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
_thunar_return_if_fail (current_directory == NULL || THUNAR_IS_FILE (current_directory));
/* check if we already use that directory */
if (G_UNLIKELY (renamer_dialog->current_directory == current_directory))
return;
/* disconnect from the previous directory */
if (renamer_dialog->current_directory != NULL)
g_object_unref (G_OBJECT (renamer_dialog->current_directory));
/* activate the new directory */
renamer_dialog->current_directory = current_directory;
/* connect to the new directory */
if (current_directory != NULL)
g_object_ref (G_OBJECT (current_directory));
/* notify listeners */
g_object_notify (G_OBJECT (renamer_dialog), "current-directory");
}
/**
* thunar_renamer_dialog_get_selected_files:
* @renamer_dialog : a #ThunarRenamerDialog.
*
* Returns the #GList of the currently selected #ThunarFile<!---->s
* in @renamer_dialog.
*
* Return value: the list of currently selected files.
**/
static GList*
thunar_renamer_dialog_get_selected_files (ThunarRenamerDialog *renamer_dialog)
{
_thunar_return_val_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog), NULL);
return renamer_dialog->selected_files;
}
/**
* thunar_renamer_dialog_get_standalone:
* @renamer_dialog : a #ThunarRenamerDialog.
*
* Returns %TRUE if the @renamer_dialog is standalone, i.e.
* if it was not opened from within the file manager with
* a preset file list.
*
* Return value: %TRUE if @renamer_dialog is standalone.
**/
static gboolean
thunar_renamer_dialog_get_standalone (ThunarRenamerDialog *renamer_dialog)
{
_thunar_return_val_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog), FALSE);
return renamer_dialog->standalone;
}
/**
* thunar_renamer_dialog_set_standalone:
* @renamer_dialog : a #ThunarRenamerDialog.
* @standalone : the new standalone state for @renamer_dialog.
*
* If @standalone is %TRUE the @renamer_dialog will display a
* toolbar and several other actions that do not make sense
* when opened from within the file manager.
**/
static void
thunar_renamer_dialog_set_standalone (ThunarRenamerDialog *renamer_dialog,
gboolean standalone)
{
_thunar_return_if_fail (THUNAR_IS_RENAMER_DIALOG (renamer_dialog));
/* normalize the value */
standalone = !!standalone;
/* check if we have a new setting */
if (G_LIKELY (renamer_dialog->standalone != standalone))
{
/* apply the new setting */
renamer_dialog->standalone = standalone;
/* change title to reflect the standalone status */
gtk_window_set_title (GTK_WINDOW (renamer_dialog), standalone ? _("Bulk Rename - Rename Multiple Files") : _("Rename Multiple Files"));
/* display the appropriate Cancel/Close button */
if (G_UNLIKELY (standalone))
{
/* standalone has Close button by default */
gtk_widget_hide (renamer_dialog->cancel_button);
gtk_widget_show (renamer_dialog->close_button);
}
else
{
/* else, Cancel button is default */
gtk_widget_show (renamer_dialog->cancel_button);
gtk_widget_hide (renamer_dialog->close_button);
}
/* notify listeners */
g_object_notify (G_OBJECT (renamer_dialog), "standalone");
}
}
/**
* thunar_show_renamer_dialog:
* @parent : the #GtkWidget or the #GdkScreen on which to open the
* dialog. May also be %NULL in which case the default
* #GdkScreen will be used.
* @current_directory : the current directory for the #ThunarRenamerDialog,
* which is used as default folder for the "Add Files"
* dialog. May also be %NULL in which case the current
* directory of the file manager process will be used.
* @files : the list of #ThunarFile<!---->s to rename.
* @standalone : whether the dialog should appear like a standalone
* application instead of an integrated renamer dialog.
* @startup_id : startup id to set on the window or %NULL.
*
* Convenience function to display a #ThunarRenamerDialog with
* the given parameters.
**/
void
thunar_show_renamer_dialog (gpointer parent,
ThunarFile *current_directory,
GList *files,
gboolean standalone,
const gchar *startup_id)
{
ThunarApplication *application;
GdkScreen *screen;
GtkWidget *dialog;
GtkWidget *window = NULL;
GList *lp;
_thunar_return_if_fail (parent == NULL || GDK_IS_SCREEN (parent) || GTK_IS_WIDGET (parent));
/* determine the screen for the dialog */
if (G_UNLIKELY (parent == NULL))
{
/* just use the default screen, no toplevel window */
screen = gdk_screen_get_default ();
}
else if (GTK_IS_WIDGET (parent))
{
/* use the screen for the widget and the toplevel window */
screen = gtk_widget_get_screen (parent);
window = gtk_widget_get_toplevel (parent);
}
else
{
/* parent is a screen, no toplevel window */
screen = GDK_SCREEN (parent);
}
/* display the bulk rename dialog */
dialog = g_object_new (THUNAR_TYPE_RENAMER_DIALOG,
"current-directory", current_directory,
"screen", screen,
"standalone", standalone,
NULL);
/* set the dialogs startup id if available */
if (startup_id != NULL && *startup_id != '\0')
gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id);
/* check if we have a toplevel window */
if (G_LIKELY (window != NULL && gtk_widget_get_toplevel (window)))
{
/* dialog is transient for toplevel window, but not modal */
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
}
/* append all specified files to the dialog's model */
for (lp = files; lp != NULL; lp = lp->next)
thunar_renamer_model_append (THUNAR_RENAMER_DIALOG (dialog)->model, lp->data);
/* let the application handle the dialog */
application = thunar_application_get ();
thunar_application_take_window (application, GTK_WINDOW (dialog));
g_object_unref (G_OBJECT (application));
/* display the dialog */
gtk_widget_show (dialog);
}
|