summaryrefslogtreecommitdiffstats
path: root/src/IndentHandler.cpp
blob: a11ea24bed0626a54961109c766cb9c5785b242d (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
/***************************************************************************
 *   Copyright (C) 2006-2012 by Thomas Schweitzer                          *
 *   thomas-schweitzer(at)arcor.de                                         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License version 2.0 as   *
 *   published by the Free Software Foundation.                            *
 *                                                                         *
 *   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 in the file LICENSE.GPL; if not, write to the *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "config.h"
#include "IndentHandler.h"

#include <cstdlib>

#include "MainWindow.h"
#include "SettingsPaths.h"
#include "UiGuiErrorMessage.h"
#include "UiGuiIniFileParser.h"
#include "UiGuiSettings.h"
#include "TemplateBatchScript.h"

#include <tqapplication.h>
#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqcursor.h>
#include <tqdir.h>
#include <tqfile.h>
#include <tqfiledialog.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqmessagebox.h>
#include <tqpopupmenu.h>
#include <tqspinbox.h>
#include <tqtoolbox.h>
#include <tqtoolbutton.h>
#include <tqtooltip.h>
//--- #include <tqprocess.h>
//--- #include <tqsettings.h>
//--- #include <tqstringlist.h>
//--- #include <tqbytearray.h>
//--- #include <tqtextstream.h>
//--- #include <tqtextcodec.h>
//--- #include <tqtscript.h>
//--- #include <tqdesktopservices.h>
//--- #include <tqaction.h>
//--- #include <tqcontextmenuevent.h>
//--- #include <tqtdebug.h>

// \defgroup grp_Indenter All concerning handling of the indenter.

/*
    \class IndentHandler
    \brief A widget for handling many indenters that are configured by an ini file.

    This is a widget that is used by the main window. It handles access to the
    indenter config file and calls the chosen indenter to reformat the source text.
    Calls the indenter each time a setting has been changed and informs
    the main window about the reformatted source code.
*/


/*
    \brief Constructor of the indent handler.

    By calling this constructor the indenter to be loaded, can be selected by setting
    its \a indenterID, which is the number of found indenter ini files in alphabetic
    order starting at index 0.
 */
IndentHandler::IndentHandler(int indenterID, MainWindow *mainWindow, TQWidget *parent) :
        TQWidget(parent), m_mainWindow(mainWindow), m_parent(parent),
        m_indenterSelectionCombobox(nullptr), m_indenterParameterHelpButton(nullptr),
        m_indenterParameterCategoriesToolBox(nullptr), m_errorMessageDialog(nullptr),
        m_toolBoxContainerLayout(nullptr), m_indenterSettings(nullptr)
{
	// Create the settings object, which loads all UiGui settings from a file.
	m_settings = UiGuiSettings::getInstance();

	if (indenterID < 0)
	{
		indenterID = 0;
	}

	// define this widgets resize behavior
	setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);

	if (m_mainWindow)
	{
		connect((TQObject*)m_mainWindow->actionLoadIndenterConfigFile, SIGNAL(activated()),
		        this, SLOT(openConfigFileDialog()));
		connect((TQObject*)m_mainWindow->actionSaveIndenterConfigFile, SIGNAL(activated()),
		        this, SLOT(saveasIndentCfgFileDialog()));
		connect((TQObject*)m_mainWindow->actionCreateShellScript, SIGNAL(activated()),
		        this, SLOT(createIndenterCallShellScript()));
		connect((TQObject*)m_mainWindow->actionResetIndenterParameters, SIGNAL(activated()),
		        this, SLOT(resetIndenterParameter()));
	}

	// create vertical layout box, into which the toolbox will be added
	m_toolBoxContainerLayout = new TQVBoxLayout(this);
	m_toolBoxContainerLayout->setMargin(2);
	m_toolBoxContainerLayout->setSpacing(5);

	// Create horizontal layout for indenter selector and help button.
	TQHBoxLayout *hboxLayout = new TQHBoxLayout();
	hboxLayout->setSpacing(5);
	m_toolBoxContainerLayout->addLayout(hboxLayout);

	// Create the indenter selection combo box.
	m_indenterSelectionCombobox = new TQComboBox(this);
	m_indenterSelectionCombobox->setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum);
	connect(m_indenterSelectionCombobox, SIGNAL(activated(int)), this, SLOT(setIndenter(int)));
	hboxLayout->addWidget(m_indenterSelectionCombobox);

	// Create the indenter parameter help button.
	m_indenterParameterHelpButton = new TQToolButton(this);
	m_indenterParameterHelpButton->setIconSet(TQPixmap(TQString(APP_ICONS_PATH)+ "help.png"));
	connect(m_indenterParameterHelpButton, SIGNAL(clicked()), this, SLOT(showIndenterManual()));
	hboxLayout->addWidget(m_indenterParameterHelpButton);

	// create a toolbox and set its resize behavior
	m_indenterParameterCategoriesToolBox = new TQToolBox(this);
	m_indenterParameterCategoriesToolBox->setSizePolicy(TQSizePolicy::MinimumExpanding,
	        TQSizePolicy::Expanding);
	m_toolBoxContainerLayout->addWidget(m_indenterParameterCategoriesToolBox);

	m_indenterExecutableCallString = "";
	m_indenterExecutableSuffix     = "";

	m_indenterDirectoryStr  = SettingsPaths::getIndenterPath();
	m_tempDirectoryStr      = SettingsPaths::getTempPath();
	m_settingsDirectoryStr  = SettingsPaths::getSettingsPath();

	if (m_mainWindow)
	{
		m_errorMessageDialog = new UiGuiErrorMessage(m_mainWindow);
	}
	else
	{
		m_errorMessageDialog = new UiGuiErrorMessage(this);
	}

	TQDir indenterDirectory = TQDir(m_indenterDirectoryStr);
	m_indenterIniFileList = indenterDirectory.entryList(TQString("uigui_*.ini"));
	if (m_indenterIniFileList.count() > 0)
	{
		// Take care if the selected indenterID is smaller or greater than the number of existing
		// indenters
		if (indenterID < 0)
		{
			indenterID = 0;
		}
		if (indenterID >= m_indenterIniFileList.count())
		{
			indenterID = m_indenterIniFileList.count() - 1;
		}

		// Reads and parses the indenter ini file specified by indenterID and creates toolbox entries
		readIndentIniFile(m_indenterDirectoryStr + "/" + m_indenterIniFileList[indenterID]);

		// Find out how the indenter can be executed.
		createIndenterCallString();

		// Load the users last settings made for this indenter.
		loadConfigFile(m_settingsDirectoryStr + "/" + m_indenterFileName + ".cfg");

		// Fill the indenter selection combo box with the list of available indenters.
		TQStringList availableIndenters = getAvailableIndenters();
		if (!availableIndenters.isEmpty())
		{
			m_indenterSelectionCombobox->insertStringList(availableIndenters);
			m_indenterSelectionCombobox->setCurrentItem(indenterID);
		}
	}
	else
	{
		m_errorMessageDialog->showMessage(tr("No indenter ini files"),
		        tr("No valid indenter ini file found in directory ") +
		        TQDir(m_indenterDirectoryStr).absPath());
	}
}

/*
    \brief Implicitly writes the current indenter parameters to the indenters config file.
 */
IndentHandler::~IndentHandler()
{
	// Generate the parameter string that will be saved to the indenters config file.
	TQString parameterString = getParameterString();
	if (!m_indenterFileName.isEmpty())
	{
		saveConfigFile(m_settingsDirectoryStr + "/" + m_indenterFileName + ".cfg", parameterString);
	}

	delete m_errorMessageDialog;
}

/*
    \brief Opens the context menu, used for some actions like saving the indenter config file,
		at the event position.
 */
void IndentHandler::contextMenuEvent(TQContextMenuEvent *event)
{
	if (m_mainWindow)
	{
		m_mainWindow->menuIndenter->exec(event->globalPos());
	}
}

/*
    \brief Creates the content for a shell script that can be used as a external tool call
    to indent an as parameter defined file.
 */
TQString IndentHandler::generateShellScript(const TQString &configFilename)
{
	TQString indenterCompleteCallString;
	TQString parameterInputFile;
	TQString parameterOuputFile;
	TQString parameterParameterFile;
	TQString replaceInputFileCommand;

	// Define the placeholder for parameter variables either in batch or bash programming.
	TQString shellParameterPlaceholder = "$1";

	parameterInputFile = " " + m_inputFileParameter + "\"" + shellParameterPlaceholder + "\"";

	if (m_outputFileParameter != "none" && m_outputFileParameter != "stdout")
	{
		if (m_outputFileName == m_inputFileName)
		{
			parameterOuputFile = " " + m_outputFileParameter + "\"" + shellParameterPlaceholder + "\"";
		}
		else
		{
			parameterOuputFile = " " + m_outputFileParameter + m_outputFileName + ".tmp";
		}
	}

	// If the config file name is empty it is assumed that all parameters are sent via command line
	// call
	if (m_globalConfigFilename.isEmpty())
	{
		parameterParameterFile = " " + getParameterString();
	}
	// else if needed add the parameter to the indenter call string where the config file can be
	// found.
	else if (m_useCfgFileParameter != "none")
	{
		parameterParameterFile = " " + m_useCfgFileParameter + "\"./" + configFilename + "\"";
	}

	// Assemble indenter call string for parameters according to the set order.
	if (m_parameterOrder == "ipo")
	{
		indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile;
	}
	else if (m_parameterOrder == "pio")
	{
		indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile;
	}
	else if (m_parameterOrder == "poi")
	{
		indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile;
	}
	else
	{
		indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile;
	}

	// Generate the indenter call string either for win32 or other systems.
	indenterCompleteCallString = "#!/bin/bash\n" + m_indenterExecutableCallString +
	        indenterCompleteCallString;

	// If the indenter writes to stdout pipe the output into a file
	if (m_outputFileParameter == "stdout")
	{
		indenterCompleteCallString = indenterCompleteCallString + " >" + m_outputFileName + ".tmp";
	}

	// If the output filename is not the same as the input filename copy the output over the input.
	if (m_outputFileName != m_inputFileName)
	{
		replaceInputFileCommand = "mv " + m_outputFileName + ".tmp \"" + shellParameterPlaceholder +
		        "\"\n";
	}

	TQString shellScript(TemplateBatchScript::getTemplateBatchScript());
	shellScript = shellScript.replace("__INDENTERCALLSTRING2__",
	        indenterCompleteCallString + "\n" + replaceInputFileCommand);
	indenterCompleteCallString = indenterCompleteCallString.replace("$1", "$file2indent");
	replaceInputFileCommand    = replaceInputFileCommand.replace("$1", "$file2indent");
	shellScript = shellScript.replace("__INDENTERCALLSTRING1__",
	        indenterCompleteCallString + "\n" + replaceInputFileCommand);

	return shellScript;
}

//--- /*
//---     \brief Format \a sourceCode by calling the indenter.
//--- 
//---     The \a inputFileExtension has to be given as parameter so the called indenter
//---     can identify the programming language if needed.
//---  */
//--- TQString IndentHandler::callIndenter(TQString sourceCode, TQString inputFileExtension)
//--- {
//--- 	if (m_indenterExecutableSuffix == ".js")
//--- 	{
//--- 		return callJavaScriptIndenter(sourceCode);
//--- 	}
//--- 	else
//--- 	{
//--- 		return callExecutableIndenter(sourceCode, inputFileExtension);
//--- 	}
//--- }
//--- 
//--- /*
//---     \brief Format \a sourceCode by calling the interpreted JavaScript code of the indenter.
//--- 
//---     The \a inputFileExtension has to be given as parameter so the called indenter
//---     can identify the programming language if needed.
//---  */
//--- TQString IndentHandler::callJavaScriptIndenter(TQString sourceCode)
//--- {
//--- 	TQScriptEngine engine;
//--- 
//--- 	engine.globalObject().setProperty("unformattedCode", sourceCode);
//--- 
//--- 	TQFile   jsDecoderFile(m_indenterExecutableCallString);
//--- 	TQString jsDecoderCode;
//--- 	if (jsDecoderFile.open(TQFile::ReadOnly))
//--- 	{
//--- 		jsDecoderCode = jsDecoderFile.readAll();
//--- 	}
//--- 	jsDecoderFile.close();
//--- 
//--- 	TQScriptValue value = engine.evaluate(jsDecoderCode);
//--- 	return value.toString();
//--- }
//--- 
//--- /*
//---     \brief Format \a sourceCode by calling the binary executable of the indenter.
//--- 
//---     The \a inputFileExtension has to be given as parameter so the called indenter
//---     can identify the programming language if needed.
//---  */
//--- TQString IndentHandler::callExecutableIndenter(TQString sourceCode, TQString inputFileExtension)
//--- {
//--- 	Q_ASSERT_X(!m_inputFileName.isEmpty(), "callIndenter", "m_inputFileName is empty");
//--- 	//    Q_ASSERT_X( !m_outputFileName.isEmpty(), "callIndenter", "m_outputFileName is empty" );
//--- 	Q_ASSERT_X(!m_indenterFileName.isEmpty(), "callIndenter", "m_indenterFileName is empty");
//--- 
//--- 	if (m_indenterFileName.isEmpty())
//--- 	{
//--- 		return "";
//--- 	}
//--- 
//--- 	TQString  formattedSourceCode;
//--- 	TQString  indenterCompleteCallString;
//--- 	TQString  parameterInputFile;
//--- 	TQString  parameterOuputFile;
//--- 	TQString  parameterParameterFile;
//--- 	TQProcess indentProcess;
//--- 	TQString  processReturnString;
//--- 
//--- 	// Generate the parameter string that will be saved to the indenters config file
//--- 	TQString parameterString = getParameterString();
//--- 
//--- 	if (!m_globalConfigFilename.isEmpty())
//--- 	{
//--- 		saveConfigFile(m_tempDirectoryStr + "/" + m_globalConfigFilename, parameterString);
//--- 	}
//--- 
//--- 	// Only add a dot to file extension if the string is not empty
//--- 	if (!inputFileExtension.isEmpty())
//--- 	{
//--- 		inputFileExtension = "." + inputFileExtension;
//--- 	}
//--- 
//--- 	// Delete any previously used input src file and create a new input src file.
//--- 	TQFile::remove(m_tempDirectoryStr + "/" + m_inputFileName + inputFileExtension);
//--- 	TQFile inputSrcFile(m_tempDirectoryStr + "/" + m_inputFileName + inputFileExtension);
//--- 	// Write the source code to the input file for the indenter
//--- 	if (inputSrcFile.open(TQFile::ReadWrite | TQFile::Text))
//--- 	{
//--- 		inputSrcFile.write(sourceCode.toUtf8());
//--- 		inputSrcFile.close();
//--- 		tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Wrote to be indented source code to file " <<
//--- 		        inputSrcFile.fileName();
//--- 	}
//--- 	else
//--- 	{
//--- 		qCritical() << __LINE__ << " " << __FUNCTION__ <<
//--- 		        ": Couldn't write to be indented source code to file " << inputSrcFile.fileName();
//--- 	}
//--- 
//--- 	// Set the input file for the to be called indenter.
//--- 	if (m_inputFileParameter.trimmed() == "<" || m_inputFileParameter == "stdin")
//--- 	{
//--- 		parameterInputFile = "";
//--- 		indentProcess.setStandardInputFile(inputSrcFile.fileName());
//--- 	}
//--- 	else
//--- 	{
//--- 		parameterInputFile = " " + m_inputFileParameter + m_inputFileName + inputFileExtension;
//--- 	}
//--- 
//--- 	// Set the output file for the to be called indenter.
//--- 	if (m_outputFileParameter != "none" && m_outputFileParameter != "stdout")
//--- 	{
//--- 		parameterOuputFile = " " + m_outputFileParameter + m_outputFileName + inputFileExtension;
//--- 	}
//--- 
//--- 	// If the config file name is empty it is assumed that all parameters are sent via command line
//--- 	// call
//--- 	if (m_globalConfigFilename.isEmpty())
//--- 	{
//--- 		parameterParameterFile = " " + parameterString;
//--- 	}
//--- 	// if needed add the parameter to the indenter call string where the config file can be found
//--- 	else if (m_useCfgFileParameter != "none")
//--- 	{
//--- 		parameterParameterFile = " " + m_useCfgFileParameter + "\"" + m_tempDirectoryStr + "/" +
//--- 		        m_globalConfigFilename + "\"";
//--- 	}
//--- 
//--- 	// Assemble indenter call string for parameters according to the set order.
//--- 	if (m_parameterOrder == "ipo")
//--- 	{
//--- 		indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile;
//--- 	}
//--- 	else if (m_parameterOrder == "pio")
//--- 	{
//--- 		indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile;
//--- 	}
//--- 	else if (m_parameterOrder == "poi")
//--- 	{
//--- 		indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile;
//--- 	}
//--- 	else
//--- 	{
//--- 		indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile;
//--- 	}
//--- 
//--- 	// If no indenter executable call string could be created before, show an error message.
//--- 	if (m_indenterExecutableCallString.isEmpty())
//--- 	{
//--- 		m_errorMessageDialog->showMessage(tr("No indenter executable"), tr(
//--- 							"There exists no indenter executable with the name \"%1\" in the directory \"%2\" nor in the global environment.").arg(
//--- 							m_indenterFileName).arg(m_indenterDirectoryStr));
//--- 		return sourceCode;
//--- 	}
//--- 
//--- 	// Generate the indenter call string either for win32 or other systems.
//--- 	indenterCompleteCallString = m_indenterExecutableCallString + indenterCompleteCallString;
//--- 
//--- 	// errors and standard outputs from the process call are merged together
//--- 	//indentProcess.setReadChannelMode(TQProcess::MergedChannels);
//--- 
//--- 	// Set the directory where the indenter will be executed for the process' environment as PWD.
//--- 	TQStringList env = indentProcess.environment();
//--- 	env << "PWD=" + TQFileInfo(m_tempDirectoryStr).absoluteFilePath();
//--- 	indentProcess.setEnvironment(env);
//--- 
//--- 	// Set the directory for the indenter execution
//--- 	indentProcess.setWorkingDirectory(TQFileInfo(m_tempDirectoryStr).absoluteFilePath());
//--- 
//--- 	tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Will call the indenter in the directory " <<
//--- 	        indentProcess.workingDirectory() << " using this commandline call: " <<
//--- 	        indenterCompleteCallString;
//--- 
//--- 	indentProcess.start(indenterCompleteCallString);
//--- 
//--- 	processReturnString = "";
//--- 	bool calledProcessSuccessfully = indentProcess.waitForFinished(10000);
//--- 	// test if there was an error during starting the process of the indenter
//--- 	if (!calledProcessSuccessfully)
//--- 	{
//--- 		processReturnString  = "<html><body>";
//--- 		processReturnString += tr("<b>Returned error message:</b> ") + indentProcess.errorString() +
//--- 		        "<br>";
//--- 
//--- 		switch (indentProcess.error())
//--- 		{
//--- 			case TQProcess::FailedToStart:
//--- 			{
//--- 				processReturnString += tr("<b>Reason could be:</b> ") +
//--- 				        "The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.<br>";
//--- 				break;
//--- 			}
//--- 
//--- 			case TQProcess::Crashed:
//--- 			{
//--- 				processReturnString += "The process crashed some time after starting successfully.<br>";
//--- 				break;
//--- 			}
//--- 
//--- 			case TQProcess::Timedout:
//--- 			{
//--- 				processReturnString +=
//--- 				        "The called indenter did not response for over 10 seconds, so aborted its execution.<br>";
//--- 				break;
//--- 			}
//--- 
//--- 			case TQProcess::WriteError:
//--- 			{
//--- 				processReturnString +=
//--- 				        "An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.<br>";
//--- 				break;
//--- 			}
//--- 
//--- 			case TQProcess::ReadError:
//--- 			{
//--- 				processReturnString +=
//--- 				        "An error occurred when attempting to read from the process. For example, the process may not be running.<br>";
//--- 				break;
//--- 			}
//--- 
//--- 			case TQProcess::UnknownError:
//--- 			{
//--- 				processReturnString +=
//--- 				        "An unknown error occurred. This is the default return value of error().<br>";
//--- 				break;
//--- 			}
//--- 
//--- 			default:
//--- 			{
//--- 				break;
//--- 			}
//--- 		}
//--- 		processReturnString += tr("<br><b>Callstring was:</b> ") + encodeToHTML(
//--- 			indenterCompleteCallString);
//--- 		processReturnString += tr("<br><br><b>Indenter output was:</b><pre>") + "<br>" + "(STDOUT):" +
//--- 		        encodeToHTML(indentProcess.readAllStandardOutput()) + "<br>" + "(STDERR):" +
//--- 		        encodeToHTML(indentProcess.readAllStandardError()) + "<br>" + "</pre></html></body>";
//--- 		tqWarning() << __LINE__ << " " << __FUNCTION__ << processReturnString;
//--- 		TQApplication::restoreOverrideCursor();
//--- 		m_errorMessageDialog->showMessage(tr("Error calling Indenter"), processReturnString);
//--- 	}
//--- 
//--- 	// If the indenter returned an error code != 0 show its output.
//--- 	if (indentProcess.exitCode() != 0)
//--- 	{
//--- 		TQString exitCode;
//--- 		exitCode.setNum(indentProcess.exitCode());
//--- 		processReturnString = tr("<b>Indenter returned with exit code:</b> ") + exitCode + "<br>" + tr(
//--- 			"<b>Indent console output was:</b> ") + "<br>" + "(STDOUT):" + encodeToHTML(
//--- 			indentProcess.readAllStandardOutput()) + "<br>" + "(STDERR):" + encodeToHTML(
//--- 			indentProcess.readAllStandardError()) + "<br>" + tr("<br><b>Callstring was:</b> ") +
//--- 		        encodeToHTML(indenterCompleteCallString) + "</html></body>";
//--- 		tqWarning() << __LINE__ << " " << __FUNCTION__ << processReturnString;
//--- 		TQApplication::restoreOverrideCursor();
//--- 		m_errorMessageDialog->showMessage(tr("Indenter returned error"), processReturnString);
//--- 	}
//--- 
//--- 	// Only get the formatted source code, if calling the indenter did succeed.
//--- 	if (calledProcessSuccessfully)
//--- 	{
//--- 		// If the indenter results are written to stdout, read them from there...
//--- 		if (indentProcess.exitCode() == 0 && m_outputFileParameter == "stdout")
//--- 		{
//--- 			formattedSourceCode = indentProcess.readAllStandardOutput();
//--- 			tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Read indenter output from StdOut.";
//--- 		}
//--- 		// ... else read the output file generated by the indenter call.
//--- 		else
//--- 		{
//--- 			TQFile outSrcFile(m_tempDirectoryStr + "/" + m_outputFileName + inputFileExtension);
//--- 			if (outSrcFile.open(TQFile::ReadOnly | TQFile::Text))
//--- 			{
//--- 				TQTextStream outSrcStrm(&outSrcFile);
//--- 				outSrcStrm.setCodec(TQTextCodec::codecForName("UTF-8"));
//--- 				formattedSourceCode = outSrcStrm.readAll();
//--- 				outSrcFile.close();
//--- 				tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Read indenter output from file " <<
//--- 				        outSrcFile.fileName();
//--- 			}
//--- 			else
//--- 			{
//--- 				qCritical() << __LINE__ << " " << __FUNCTION__ <<
//--- 				        ": Couldn't read indenter output from file " << outSrcFile.fileName();
//--- 			}
//--- 		}
//--- 	}
//--- 	else
//--- 	{
//--- 		return sourceCode;
//--- 	}
//--- 
//--- 	// Delete the temporary input and output files.
//--- 	TQFile::remove(m_tempDirectoryStr + "/" + m_outputFileName + inputFileExtension);
//--- 	TQFile::remove(m_tempDirectoryStr + "/" + m_inputFileName + inputFileExtension);
//--- 
//--- 	return formattedSourceCode;
//--- }

/*
    \brief Generates and returns a string with all parameters needed to call the indenter.
 */
TQString IndentHandler::getParameterString()
{
	TQString parameterString = "";

	// generate parameter string for all boolean values
	for (const ParamBoolean &pBoolean : m_paramBooleans)
	{
		if (pBoolean.checkBox->isChecked())
		{
			if (!pBoolean.trueString.isEmpty())
			{
				parameterString += pBoolean.trueString + m_cfgFileParameterEnding;
			}
		}
		else
		{
			if (!pBoolean.falseString.isEmpty())
			{
				parameterString += pBoolean.falseString + m_cfgFileParameterEnding;
			}
		}
	}

	// generate parameter string for all numeric values
	for (const ParamNumeric &pNumeric : m_paramNumerics)
	{
		if (pNumeric.valueEnabledChkBox->isChecked())
		{
			parameterString += pNumeric.paramCallName + TQString::number(pNumeric.spinBox->value()) +
			        m_cfgFileParameterEnding;
		}
	}

	// generate parameter string for all string values
	for (const ParamString &pString : m_paramStrings)
	{
		if (!pString.lineEdit->text().isEmpty() && pString.valueEnabledChkBox->isChecked())
		{
			// Create parameter definition for each value devided by a | sign.
			TQStringList pStringList = TQStringList::split("|", pString.lineEdit->text());
			for (const TQString &paramValue : pStringList)
			{
				parameterString += pString.paramCallName + paramValue + m_cfgFileParameterEnding;
			}
		}
	}

	// generate parameter string for all multiple choice values
	for (const ParamMultiple &pMultiple : m_paramMultiples)
	{
		if (pMultiple.valueEnabledChkBox->isChecked())
		{
			parameterString += pMultiple.choicesStrings[pMultiple.comboBox->currentItem()] +
			        m_cfgFileParameterEnding;
		}
	}

	return parameterString;
}

/*
    \brief Write settings for the indenter to a config file.
 */
void IndentHandler::saveConfigFile(const TQString &filePathName, const TQString &paramString)
{
	TQFile::remove(filePathName);
	TQFile cfgFile(filePathName);

	cfgFile.open(IO_ReadWrite | IO_Translate);
	TQCString paramCString = paramString.local8Bit();
	cfgFile.writeBlock(paramCString.data(), paramCString.length());
	cfgFile.close();
}

/*
    \brief Load the config file for the indenter and apply the settings made there.
 */
bool IndentHandler::loadConfigFile(const TQString &filePathName)
{
	TQFile   cfgFile(filePathName);
	TQString cfgFileData = TQString::null;

	if (!cfgFile.exists())
	{
		// If the config file to be loaded does not exist, leave all values as they are and return false
		return false;
	}
	else
	{
		// else if the config file exists, retrieve its whole content
		cfgFile.open(IO_ReadOnly | IO_Translate);
		cfgFileData = TQString(cfgFile.readAll());
		cfgFile.close();
	}

	// Search for name of each boolean parameter and set its value if found.
	for (const ParamBoolean &pBoolean : m_paramBooleans)
	{
		// boolean value that will be assigned to the checkbox
		bool paramValue = false;

		// first search for the longer parameter string
		// the true parameter string is longer than the false string
		if (pBoolean.trueString.length() > pBoolean.falseString.length())
		{
			// search for the true string
			int index = cfgFileData.find(pBoolean.trueString, 0, false);
			// if true string found set the parameter value to true
			if (index != -1)
			{
				paramValue = true;
			}
			// if true string not found, search for false string
			else
			{
				index = cfgFileData.find(pBoolean.falseString, 0, false);
				// if false string found set the parameter value to false
				if (index != -1)
				{
					paramValue = false;
				}
				// neither true nor false parameter found so use default value
				else
				{
					paramValue = m_indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool();
				}
			}
		}
		// the false parameter string is longer than the true string
		else
		{
			// search for the false string
			int index = cfgFileData.find(pBoolean.falseString, 0, false);
			// if false string found set the parameter value to false
			if (index != -1)
			{
				paramValue = false;
			}
			// if false string not found, search for true string
			else
			{
				index = cfgFileData.find(pBoolean.trueString, 0, false);
				// if true string found set the parameter value to true
				if (index != -1)
				{
					paramValue = true;
				}
				// neither true nor false parameter found so use default value
				else
				{
					paramValue = m_indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool();
				}
			}
		}
		pBoolean.checkBox->setChecked(paramValue);
	}

	// Search for name of each numeric parameter and set the value found behind it.
	for(const ParamNumeric &pNumeric : m_paramNumerics)
	{
		int index = cfgFileData.find(pNumeric.paramCallName, 0, false);
		// parameter was found in config file
		if (index != -1)
		{
			// set index after the parameter name, so in front of the number
			index += pNumeric.paramCallName.length();

			// Find the end of the parameter by searching for set config file parameter ending. Most of
			// time this is a carriage return.
			int crPos = cfgFileData.find(m_cfgFileParameterEnding, index + 1);

			// get the number and convert it to int
			TQString test = cfgFileData.mid(index, crPos - index);
			int paramValue = cfgFileData.mid(index, crPos - index).toInt(nullptr);

			// disable the signal-slot connection. Otherwise signal is emmitted each time when value is
			// set
			TQObject::disconnect(pNumeric.spinBox, SIGNAL(valueChanged(int)), this,
			        SLOT(handleChangedIndenterSettings()));
			pNumeric.spinBox->setValue(paramValue);
			pNumeric.valueEnabledChkBox->setChecked(true);
			TQObject::connect(pNumeric.spinBox, SIGNAL(valueChanged(int)), this,
			        SLOT(handleChangedIndenterSettings()));
		}
		// parameter was not found in config file
		else
		{
			int defaultValue = m_indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt();
			pNumeric.spinBox->setValue(defaultValue);
			pNumeric.valueEnabledChkBox->setChecked(false);
		}
	}

	// Search for name of each string parameter and set it.
	for (const ParamString &pString : m_paramStrings)
	{
		// The number of the found values for this parameter name.
		int numberOfValues = 0;
		int index = cfgFileData.find(pString.paramCallName, 0, false);
		// If parameter was found in config file
		if (index != -1)
		{
			TQString paramValueStr = TQString::null;
			while (index != -1)
			{
				numberOfValues++;

				// Set index after the parameter name, so it points to the front of the string value.
				index += pString.paramCallName.length();

				// Find the end of the parameter by searching for set config file parameter ending. Most of
				// time this is a carriage return.
				int crPos = cfgFileData.find(m_cfgFileParameterEnding, index + 1);

				// Get the string and remember it.
				if (numberOfValues < 2)
				{
					paramValueStr = TQString(cfgFileData.mid(index, crPos - index));
				}
				// If the same parameter has been set multiple times, concatenate the strings dvivided by a
				// |.
				else
				{
					paramValueStr = paramValueStr + "|" + TQString(cfgFileData.mid(index, crPos - index));
				}

				// Get next value for this setting, if one exists.
				index = cfgFileData.find(pString.paramCallName, crPos + 1, false);
			}
			// Set the text for the line edit.
			pString.lineEdit->setText(paramValueStr);
			pString.valueEnabledChkBox->setChecked(true);
		}
		// Parameter was not found in config file
		else
		{
			pString.lineEdit->setText(m_indenterSettings->value(pString.paramName +
			        "/ValueDefault").toString());
			pString.valueEnabledChkBox->setChecked(false);
		}
	}

	// search for name of each multiple choice parameter and set it
	for (const ParamMultiple &pMultiple : m_paramMultiples)
	{
		int i = 0;
		int index = -1;

		// search for all parameter names of the multiple choice list
		// if one is found, set it and leave the while loop
		while (i < pMultiple.choicesStrings.count() && index == -1)
		{
			index = cfgFileData.find(pMultiple.choicesStrings[i], 0, false);
			if (index != -1)
			{
				pMultiple.comboBox->setCurrentItem(i);
				pMultiple.valueEnabledChkBox->setChecked(true);
			}
			i++;
		}

		// parameter was not set in config file, so use default value
		if (index == -1)
		{
			int defaultValue = m_indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt();
			pMultiple.comboBox->setCurrentItem(defaultValue);
			pMultiple.valueEnabledChkBox->setChecked(false);
		}
	}

	return true;
}

/*
    \brief Sets all indenter parameters to their default values defined in the ini file.
 */
void IndentHandler::resetToDefaultValues()
{
	// Search for name of each boolean parameter and set its value if found.
	for (ParamBoolean &pBoolean : m_paramBooleans)
	{
		// Boolean value that will be assigned to the checkbox.
		bool defaultValue = m_indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool();
		pBoolean.checkBox->setChecked(defaultValue);
	}

	// Search for name of each numeric parameter and set the value found behind it.
	for (ParamNumeric &pNumeric : m_paramNumerics)
	{
		int defaultValue = m_indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt();
		pNumeric.spinBox->setValue(defaultValue);
		pNumeric.valueEnabledChkBox->setChecked(m_indenterSettings->value(
		        pNumeric.paramName + "/Enabled").toBool());
	}

	// Search for name of each string parameter and set it.
	for (ParamString &pString : m_paramStrings)
	{
		TQString defaultValue =
		        m_indenterSettings->value(pString.paramName + "/ValueDefault").toString();
		pString.lineEdit->setText(defaultValue);
		pString.valueEnabledChkBox->setChecked(m_indenterSettings->value(
		        pString.paramName + "/Enabled").toBool());
	}

	// Search for name of each multiple choice parameter and set it.
	for (ParamMultiple &pMultiple : m_paramMultiples)
	{
		int defaultValue = m_indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt();
		pMultiple.comboBox->setCurrentItem(defaultValue);
		pMultiple.valueEnabledChkBox->setChecked(m_indenterSettings->value(pMultiple.paramName +
		        "/Enabled").toBool());
	}
}

/*
    \brief Opens and parses the indenter ini file that is declared by \a iniFilePath.
 */
void IndentHandler::readIndentIniFile(const TQString &iniFilePath)
{
	if (iniFilePath.isEmpty())
	{
		m_errorMessageDialog->showMessage(tr("readIndentIniFile"),
		        tr("The iniFilePath for the indenter file is empty"));
		return;
	}

	// open the ini-file that contains all available indenter settings with their additional infos
	m_indenterSettings = new UiGuiIniFileParser(iniFilePath);

	//
	//  parse ini file indenter header
	//

	m_indenterName           = m_indenterSettings->value("header/indenterName").toString();
	m_indenterFileName       = m_indenterSettings->value("header/indenterFileName").toString();
	m_globalConfigFilename   = m_indenterSettings->value("header/configFilename").toString();
	m_useCfgFileParameter    = m_indenterSettings->value("header/useCfgFileParameter").toString();
	m_cfgFileParameterEnding = m_indenterSettings->value("header/cfgFileParameterEnding").toString();
	if (m_cfgFileParameterEnding == "cr")
	{
		m_cfgFileParameterEnding = "\n";
	}
	m_indenterShowHelpParameter = m_indenterSettings->value("header/showHelpParameter").toString();

	if (m_indenterFileName.isEmpty())
	{
		m_errorMessageDialog->showMessage(tr("Indenter ini file header error"),
							tr("The loaded indenter ini file \"%1\"has a faulty header. At least the indenter file name is not set.").
							arg(iniFilePath));
	}

	// Read the parameter order. Possible values are (p=parameter[file] i=inputfile o=outputfile)
	// pio, ipo, iop
	m_parameterOrder      = m_indenterSettings->value("header/parameterOrder", "pio").toString();
	m_inputFileParameter  = m_indenterSettings->value("header/inputFileParameter").toString();
	m_inputFileName       = m_indenterSettings->value("header/inputFileName").toString();
	m_outputFileParameter = m_indenterSettings->value("header/outputFileParameter").toString();
	m_outputFileName      = m_indenterSettings->value("header/outputFileName").toString();
	m_fileTypes = m_indenterSettings->value("header/fileTypes").toString();
	m_fileTypes.replace('|', " ");

	// read the categories names which are separated by "|"
	TQString categoriesStr = m_indenterSettings->value("header/categories").toString();
	TQStringList categories = TQStringList::split('|', categoriesStr);
	// Assure that the category list is never empty. At least contain a "general" section.
	if (categories.isEmpty())
	{
		categories.append("General");
	}

	IndenterParameterCategoryPage categoryPage;

	// For some unknown reasons, TQToolbox does not display the content of the first
	// widget once the indenter is changed. To work around this problem we insert a
	// dummy widget before the real categories and we will get rid of it at the end
	TQWidget *dummyWidget = new TQWidget();
	m_indenterParameterCategoriesToolBox->addItem(dummyWidget, "Dummy");

	// create a page for each category and store its references in a toolboxpage-array
	for (const TQString &category : categories)
	{
		categoryPage.widget = new TQWidget();
		categoryPage.widget->setName(category.local8Bit());
		categoryPage.widget->setSizePolicy(TQSizePolicy::MinimumExpanding,
		        TQSizePolicy::MinimumExpanding);
		categoryPage.vboxLayout = new TQVBoxLayout(categoryPage.widget);
		categoryPage.vboxLayout->setSpacing(6);
		categoryPage.vboxLayout->setMargin(9);
		categoryPage.vboxLayout->setName(category.local8Bit());
		m_indenterParameterCategoryPages.append(categoryPage);
		m_indenterParameterCategoriesToolBox->addItem(categoryPage.widget, category);
	}

	//
	//  parse ini file indenter parameters
	//

	// read all possible parameters written in brackets []
	m_indenterParameters = m_indenterSettings->childGroups();

	// read each parameter to create the corresponding input field
	for (const TQString &indenterParameter : m_indenterParameters)
	{
		// if it is not the indent header definition read the parameter and add it to
		// the corresponding category toolbox page
		if (indenterParameter != "header")
		{
			// read to which category the parameter belongs
			int category = m_indenterSettings->value(indenterParameter + "/Category").toInt();
			// Assure that the category number is never greater than the available categories.
			if (category > m_indenterParameterCategoryPages.size() - 1)
			{
				category = m_indenterParameterCategoryPages.size() - 1;
			}
			// read which type of input field the parameter needs
			TQString editType = m_indenterSettings->value(indenterParameter + "/EditorType").toString();

			// edit type is numeric so create a spinbox with label
			if (editType == "numeric")
			{
				// read the parameter name as it is used at the command line or in its config file
				TQString parameterCallName =
				        m_indenterSettings->value(indenterParameter + "/CallName").toString();

				// create checkbox which enables or disables the parameter
				TQCheckBox *chkBox = new TQCheckBox(m_indenterParameterCategoryPages.at(category).widget);
				chkBox->setChecked(m_indenterSettings->value(indenterParameter + "/Enabled").toBool());
				TQToolTip::add(chkBox,
					      "Enables/disables the parameter. If disabled the indenters default value will be used.");
				chkBox->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed);

				// create the spinbox
				TQSpinBox *spinBox = new TQSpinBox(m_indenterParameterCategoryPages.at(category).widget);
				TQString paramToolTip = m_indenterSettings->value(indenterParameter + "/Description").toString();
				TQToolTip::add(spinBox, paramToolTip);
				spinBox->setMaximumWidth(50);
				spinBox->setMinimumWidth(50);
				if (m_mainWindow != nullptr)
				{
					spinBox->installEventFilter(m_mainWindow);
				}
				if (m_indenterSettings->value(indenterParameter + "/MinVal").toString() != "")
				{
					spinBox->setMinValue(m_indenterSettings->value(indenterParameter + "/MinVal").toInt());
				}
				else
				{
					spinBox->setMinValue(0);
				}
				if (m_indenterSettings->value(indenterParameter + "/MaxVal").toString() != "")
				{
					spinBox->setMaxValue(m_indenterSettings->value(indenterParameter + "/MaxVal").toInt());
				}
				else
				{
					spinBox->setMaxValue(2000);
				}

				// create the label
				TQLabel *label = new TQLabel(m_indenterParameterCategoryPages.at(category).widget);
				label->setText(indenterParameter);
				label->setBuddy(spinBox);
				TQToolTip::add(label, paramToolTip);
				if (m_mainWindow != nullptr)
				{
					label->installEventFilter(m_mainWindow);
				}

				// put all into a layout and add it to the toolbox page
				TQHBoxLayout *hboxLayout = new TQHBoxLayout();
				hboxLayout->addWidget(chkBox);
				hboxLayout->addWidget(spinBox);
				hboxLayout->addWidget(label);
				m_indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout);

				// remember parameter name and reference to its spinbox
				ParamNumeric paramNumeric;
				paramNumeric.paramName     = indenterParameter;
				paramNumeric.paramCallName = parameterCallName;
				paramNumeric.spinBox       = spinBox;
				paramNumeric.label = label;
				paramNumeric.valueEnabledChkBox = chkBox;
				paramNumeric.spinBox->setValue(m_indenterSettings->value(paramNumeric.paramName +
				        "/ValueDefault").toInt());
				m_paramNumerics.append(paramNumeric);

				TQObject::connect(spinBox, SIGNAL(valueChanged(int)), this,
				        SLOT(handleChangedIndenterSettings()));
				TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings()));
			}
			// edit type is boolean so create a checkbox
			else if (editType == "boolean")
			{
				// create the checkbox, make its settings and add it to the toolbox page
				TQCheckBox *chkBox = new TQCheckBox(m_indenterParameterCategoryPages.at(category).widget);
				chkBox->setText(indenterParameter);
				TQString paramToolTip = m_indenterSettings->value(indenterParameter + "/Description").toString();
				TQToolTip::add(chkBox, paramToolTip);
				if (m_mainWindow != nullptr)
				{
					chkBox->installEventFilter(m_mainWindow);
				}
				m_indenterParameterCategoryPages.at(category).vboxLayout->addWidget(chkBox);

				// remember parameter name and reference to its checkbox
				ParamBoolean paramBoolean;
				paramBoolean.paramName = indenterParameter;
				paramBoolean.checkBox  = chkBox;
				TQStringList trueFalseStrings = TQStringList::split("|",
				        m_indenterSettings->value(indenterParameter + "/TrueFalse").toString());
				paramBoolean.trueString  = trueFalseStrings[0];
				paramBoolean.falseString = trueFalseStrings[1];
				paramBoolean.checkBox->setChecked(m_indenterSettings->value(paramBoolean.paramName +
				        "/ValueDefault").toBool());
				m_paramBooleans.append(paramBoolean);

				TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings()));
			}
			// edit type is numeric so create a line edit with label
			else if (editType == "string")
			{
				// read the parameter name as it is used at the command line or in its config file
				TQString parameterCallName =
				        m_indenterSettings->value(indenterParameter + "/CallName").toString();

				// create check box which enables or disables the parameter
				TQCheckBox *chkBox = new TQCheckBox(m_indenterParameterCategoryPages.at(category).widget);
				chkBox->setChecked(m_indenterSettings->value(indenterParameter + "/Enabled").toBool());
				TQToolTip::add(chkBox,
				        "Enables/disables the parameter. If disabled the indenters default value will be used.");
				chkBox->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed);

				// create the line edit
				TQLineEdit *lineEdit = new TQLineEdit(m_indenterParameterCategoryPages.at(category).widget);
				TQString paramToolTip = m_indenterSettings->value(indenterParameter + "/Description").toString();
				TQToolTip::add(lineEdit, paramToolTip);
				lineEdit->setMaximumWidth(50);
				lineEdit->setMinimumWidth(50);
				if (m_mainWindow != nullptr)
				{
					lineEdit->installEventFilter(m_mainWindow);
				}

				// create the label
				TQLabel *label = new TQLabel(m_indenterParameterCategoryPages.at(category).widget);
				label->setText(indenterParameter);
				label->setBuddy(lineEdit);
				label->setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::Preferred);
				TQToolTip::add(label, paramToolTip);
				if (m_mainWindow != nullptr)
				{
					label->installEventFilter(m_mainWindow);
				}

				// put all into a layout and add it to the toolbox page
				TQHBoxLayout *hboxLayout = new TQHBoxLayout();
				hboxLayout->addWidget(chkBox);
				hboxLayout->addWidget(lineEdit);
				hboxLayout->addWidget(label);
				m_indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout);

				// remember parameter name and reference to its line edit
				ParamString paramString;
				paramString.paramName     = indenterParameter;
				paramString.paramCallName = parameterCallName;
				paramString.lineEdit      = lineEdit;
				paramString.label = label;
				paramString.valueEnabledChkBox = chkBox;
				paramString.lineEdit->setText(m_indenterSettings->value(paramString.paramName +
				        "/ValueDefault").toString());
				m_paramStrings.append(paramString);

				TQObject::connect(lineEdit, SIGNAL(returnPressed()), this,
				        SLOT(handleChangedIndenterSettings()));
				TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings()));
			}
			// edit type is multiple so create a combobox with label
			else if (editType == "multiple")
			{
				// read the parameter name as it is used at the command line or in its config file
				TQString parameterCallName =
				        m_indenterSettings->value(indenterParameter + "/CallName").toString();

				// create checkbox which enables or disables the parameter
				TQCheckBox *chkBox = new TQCheckBox(m_indenterParameterCategoryPages.at(category).widget);
				chkBox->setChecked(m_indenterSettings->value(indenterParameter + "/Enabled").toBool());
				TQToolTip::add(chkBox,
					"Enables/disables the parameter. If disabled the indenters default value will be used.");
				chkBox->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed);

				// create the combo box
				TQComboBox *comboBox = new TQComboBox(m_indenterParameterCategoryPages.at(category).widget);
				TQStringList choicesStrings = TQStringList::split("|",
				        m_indenterSettings->value(indenterParameter + "/Choices").toString());
				TQStringList choicesStringsReadable = TQStringList::split("|",
				        m_indenterSettings->value(indenterParameter + "/ChoicesReadable").toString(), true);
				if (choicesStringsReadable.isEmpty())
				{
					comboBox->insertStringList(choicesStrings);
				}
				else
				{
					comboBox->insertStringList(choicesStringsReadable);
				}
				TQString paramToolTip = m_indenterSettings->value(indenterParameter + "/Description").toString();
				TQToolTip::add(comboBox, paramToolTip);
				if (m_mainWindow != nullptr)
				{
					comboBox->installEventFilter(m_mainWindow);
				}

				// put all into a layout and add it to the toolbox page
				TQHBoxLayout *hboxLayout = new TQHBoxLayout();
				hboxLayout->addWidget(chkBox);
				hboxLayout->addWidget(comboBox);
				m_indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout);

				// remember parameter name and reference to its lineedit
				ParamMultiple paramMultiple;
				paramMultiple.paramName      = indenterParameter;
				paramMultiple.paramCallName  = parameterCallName;
				paramMultiple.comboBox       = comboBox;
				paramMultiple.choicesStrings = choicesStrings;
				paramMultiple.choicesStringsReadable = choicesStringsReadable;
				paramMultiple.valueEnabledChkBox     = chkBox;
				paramMultiple.comboBox->setCurrentItem(m_indenterSettings->value(paramMultiple.paramName +
				        "/ValueDefault").toInt());
				m_paramMultiples.append(paramMultiple);

				TQObject::connect(comboBox, SIGNAL(activated(int)), this,
				        SLOT(handleChangedIndenterSettings()));
				TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings()));
			}
		}
	}

	// put a spacer at each page end
	for(IndenterParameterCategoryPage &categoryPage : m_indenterParameterCategoryPages)
	{
		categoryPage.vboxLayout->addStretch();
	}

	// Get rid of the dummy widget previously created
	m_indenterParameterCategoriesToolBox->removeItem(dummyWidget);
	delete dummyWidget;
}

/*
    \brief Searches and returns all indenters a configuration file is found for.

    Opens all uigui ini files found in the list \a m_indenterIniFileList, opens each ini file
    and reads the there defined real name of the indenter. These names are being returned as TQStringList.
 */
TQStringList IndentHandler::getAvailableIndenters()
{
	TQStringList indenterNamesList;

	// Loop for every existing uigui ini file
	for (const TQString indenterIniFile : m_indenterIniFileList)
	{
		// Open the ini file and search for the indenter name
		TQFile file(m_indenterDirectoryStr + "/" + indenterIniFile);
		if (file.open(IO_ReadOnly | IO_Translate))
		{
			int index = -1;
      TQTextStream stream(&file);
			TQString line;
			// Search for the string "indenterName=" and get the following string until line end.
			while (index == -1 && !file.atEnd())
			{
				line = stream.readLine();
				index = line.find("indenterName=", 0);
			}

			if (index == 0)
			{
				line = line.remove(0, 13);
				indenterNamesList << line.stripWhiteSpace();
			}
		}
		file.close();
	}
	return indenterNamesList;
}

/*
    \brief Deletes all elements in the toolbox and initializes the indenter selected by \a indenterID.
 */
void IndentHandler::setIndenter(int indenterID)
{
	TQApplication::setOverrideCursor(TQt::WaitCursor);

	// Generate the parameter string that will be saved to the indenters config file.
	TQString parameterString = getParameterString();
	if (!m_indenterFileName.isEmpty())
	{
		saveConfigFile(m_settingsDirectoryStr + "/" + m_indenterFileName + ".cfg", parameterString);
	}

	// Make sure the selected indenterID is valid
	if (indenterID < 0)
	{
		indenterID = 0;
	}
	if (indenterID >= m_indenterIniFileList.count())
	{
		indenterID = m_indenterIniFileList.count() - 1;
	}

	m_settings->setValueByName("SelectedIndenter", indenterID);

	// delete all toolbox pages and by this its children
	for (IndenterParameterCategoryPage &categoryPage : m_indenterParameterCategoryPages)
	{
		m_indenterParameterCategoriesToolBox->removeItem(categoryPage.widget);
		delete categoryPage.widget;
	}

	// empty all lists, which stored infos for the toolbox pages and its widgets
	m_indenterParameterCategoryPages.clear();
	m_paramStrings.clear();
	m_paramNumerics.clear();
	m_paramBooleans.clear();
	m_paramMultiples.clear();
	delete m_indenterSettings;

	readIndentIniFile(m_indenterDirectoryStr + "/" + m_indenterIniFileList[indenterID]);

	// Find out how the indenter can be executed.
	createIndenterCallString();

	// Load the users last settings made for this indenter.
	loadConfigFile(m_settingsDirectoryStr + "/" + m_indenterFileName + ".cfg");

	handleChangedIndenterSettings();

	TQApplication::restoreOverrideCursor();
}

//--- /*
//---     \brief Returns a string containing by the indenter supported file types/extensions divided by a space.
//---  */
//--- TQString IndentHandler::getPossibleIndenterFileExtensions()
//--- {
//--- 	return m_fileTypes;
//--- }

/*
    \brief Returns the path and filename of the current indenter config file.
 */
TQString IndentHandler::getIndenterCfgFile()
{
	TQFileInfo fileInfo(m_indenterDirectoryStr + "/" + m_globalConfigFilename);
	return fileInfo.absFilePath();
}

/*
    \brief Tries to create a call path string for the indenter executable. If successful returns true.
 */
bool IndentHandler::createIndenterCallString()
{
//--- 	TQProcess indentProcess;
//--- 
//--- 	if (m_indenterFileName.isEmpty())
//--- 	{
//--- 		return false;
//--- 	}
//--- 
//--- 	// First try to call the indenter inside of the data dir, using some suffix
//--- 	// ------------------------------------------------------------------------
//--- 
//--- 	// Set the directory for the indenter execution
//--- 	indentProcess.setWorkingDirectory(TQFileInfo(m_indenterDirectoryStr).absoluteFilePath());
//--- 
//--- 	foreach(TQString suffix, TQStringList() << "" << ".exe" << ".bat" << ".com" << ".sh")
//--- 	{
//--- 		m_indenterExecutableSuffix     = suffix;
//--- 		m_indenterExecutableCallString = TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/" +
//--- 		        m_indenterFileName;
//--- 		m_indenterExecutableCallString += suffix;
//--- 
//--- 		// Only try to call the indenter, if the file exists.
//--- 		if (TQFile::exists(m_indenterExecutableCallString))
//--- 		{
//--- 			// Only try to call the indenter directly if it is no php file
//--- 			if (TQFileInfo(m_indenterExecutableCallString).suffix().toLower() != "php")
//--- 			{
//--- 				indentProcess.start(
//--- 					"\"" + m_indenterExecutableCallString +  +"\" " + m_indenterShowHelpParameter);
//--- 				if (indentProcess.waitForFinished(2000))
//--- 				{
//--- 					m_indenterExecutableCallString = "\"" + m_indenterExecutableCallString + "\"";
//--- 					return true;
//--- 				}
//--- 				else if (indentProcess.error() == TQProcess::Timedout)
//--- 				{
//--- 					m_indenterExecutableCallString = "\"" + m_indenterExecutableCallString + "\"";
//--- 					return true;
//--- 				}
//--- 			}
//--- 
//--- 			// Test for needed interpreters
//--- 			// ----------------------------
//--- 			// If the file could not be executed, try to find a shebang at its start or test if its a php
//--- 			// file.
//--- 			TQString interpreterName = "";
//--- 			TQFile   indenterExecutable(m_indenterExecutableCallString);
//--- 
//--- 			// If indenter executable file has .php as suffix, use php as default interpreter
//--- 			if (TQFileInfo(m_indenterExecutableCallString).suffix().toLower() == "php")
//--- 			{
//--- 				interpreterName = "php -f";
//--- 			}
//--- 			// Else try to open the file and read the shebang.
//--- 			else if (indenterExecutable.open(TQFile::ReadOnly))
//--- 			{
//--- 				// Read the first line of the file.
//--- 				TQTextStream indenterExecutableContent(&indenterExecutable);
//--- 				TQString     firstLineOfIndenterExe = indenterExecutableContent.readLine(75);
//--- 				indenterExecutable.close();
//--- 
//--- 				// If the initial shebang is found, read the named intepreter. e.g. perl
//--- 				if (firstLineOfIndenterExe.startsWith("#!"))
//--- 				{
//--- 					// Get the rightmost word. by splitting the string into only full words.
//--- 					interpreterName = firstLineOfIndenterExe.split("/").last();
//--- 				}
//--- 			}
//--- 
//--- 			// Try to call the interpreter, if it exists.
//--- 			if (!interpreterName.isEmpty())
//--- 			{
//--- 				m_indenterExecutableCallString = interpreterName + " \"" + m_indenterExecutableCallString +
//--- 				        "\"";
//--- 				indentProcess.start(interpreterName + " -h");
//--- 				if (indentProcess.waitForFinished(2000))
//--- 				{
//--- 					return true;
//--- 				}
//--- 				else if (indentProcess.error() == TQProcess::Timedout)
//--- 				{
//--- 					return true;
//--- 				}
//--- 				// now we know an interpreter is needed but it could not be called, so inform the user.
//--- 				else
//--- 				{
//--- 					m_errorMessageDialog->showMessage(tr("Interpreter needed"), tr(
//--- 										"To use the selected indenter the program \"%1\" needs to be available in the global environment. You should add an entry to your path settings.").arg(
//--- 										interpreterName));
//--- 					return true;
//--- 				}
//--- 			}
//--- 		}
//--- 	}
//--- 
//--- 	// If unsuccessful try if the indenter executable is a JavaScript file
//--- 	// -------------------------------------------------------------------
//--- 	m_indenterExecutableSuffix     = ".js";
//--- 	m_indenterExecutableCallString = TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/" +
//--- 	        m_indenterFileName;
//--- 	m_indenterExecutableCallString += m_indenterExecutableSuffix;
//--- 	if (TQFile::exists(m_indenterExecutableCallString))
//--- 	{
//--- 		return true;
//--- 	}
//--- 
//--- 	// If unsuccessful try to call the indenter global, using some suffix
//--- 	// ------------------------------------------------------------------
//--- 	foreach(TQString suffix, TQStringList() << "" << ".exe" << ".bat" << ".com" << ".sh")
//--- 	{
//--- 		m_indenterExecutableSuffix     = suffix;
//--- 		m_indenterExecutableCallString = m_indenterFileName + suffix;
//--- 		indentProcess.start(m_indenterExecutableCallString + " " + m_indenterShowHelpParameter);
//--- 		if (indentProcess.waitForFinished(2000))
//--- 		{
//--- 			return true;
//--- 		}
//--- 		else if (indentProcess.error() == TQProcess::Timedout)
//--- 		{
//--- 			return true;
//--- 		}
//--- 	}
//--- 
//--- 	// If even globally calling the indenter fails, try calling .com and .exe via wine
//--- 	// -------------------------------------------------------------------------------
//--- 	m_indenterExecutableCallString = "\"" + TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/" +
//--- 	        m_indenterFileName;
//--- 
//--- 	foreach(TQString suffix, TQStringList() << ".exe" << ".com")
//--- 	{
//--- 		m_indenterExecutableSuffix = suffix;
//--- 		if (TQFile::exists(m_indenterDirectoryStr + "/" + m_indenterFileName + suffix))
//--- 		{
//--- 			TQProcess wineTestProcess;
//--- 			wineTestProcess.start("wine --version");
//--- 			// if the process of wine was not callable assume that wine is not installed
//--- 			if (!wineTestProcess.waitForFinished(2000))
//--- 			{
//--- 				m_errorMessageDialog->showMessage(tr("wine not installed"), tr(
//--- 									"There exists only a win32 executable of the indenter and wine does not seem to be installed. Please install wine to be able to run the indenter."));
//--- 				m_indenterExecutableCallString = "";
//--- 				return false;
//--- 			}
//--- 			else
//--- 			{
//--- 				m_indenterExecutableCallString = "\"" +
//--- 				        TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/";
//--- 				m_indenterExecutableCallString += m_indenterFileName + suffix + "\"";
//--- 				m_indenterExecutableCallString  = "wine " + m_indenterExecutableCallString;
//--- 
//--- 				return true;
//--- 			}
//--- 		}
//--- 	}
//--- 
//--- 	m_indenterExecutableCallString = "";
//--- 	m_indenterExecutableSuffix     = "";
	return false;
}

//--- /*
//---     \brief Returns a string that points to where the indenters manual can be found.
//---  */
//--- TQString IndentHandler::getManual()
//--- {
//--- 	if (m_indenterSettings != nullptr)
//--- 	{
//--- 		return m_indenterSettings->value("header/manual").toString();
//--- 	}
//--- 	else
//--- 	{
//--- 		return "";
//--- 	}
//--- }

/*
    \brief This slot gets the reference to the indenters manual and opens it.
 */
void IndentHandler::showIndenterManual() const
{
//--- 	TQString manualReference = getManual();
//--- 	TQDesktopServices::openUrl(manualReference);
}

/*
    \brief Returns the name of the currently selected indenter.
 */
TQString IndentHandler::getCurrentIndenterName()
{
	TQString currentIndenterName = m_indenterSelectionCombobox->currentText();

	// Remove the supported programming languages from indenters name, which are set in braces.
	if (currentIndenterName.find("(") > 0)
	{
		// Using index-1 to also leave out the blank before the brace.
		currentIndenterName = currentIndenterName.left(currentIndenterName.find("(") - 1);
	}

	return currentIndenterName;
}

/*
    \brief Shows a file open dialog to open an existing config file for the current indenter.
    If the file was successfully opened, the indent handler is called to load the settings
		and update itself.
*/
void IndentHandler::openConfigFileDialog()
{
	TQString configFilePath = TQFileDialog::getOpenFileName(getIndenterCfgFile(), tr("All files (*.*)"),
	        nullptr, nullptr, tr("Choose indenter config file"));

	if (!configFilePath.isEmpty())
	{
		// If the config file was loaded successfully, inform any who is interested about it.
		if (loadConfigFile(configFilePath))
		{
			handleChangedIndenterSettings();
		}
	}
}

/*
    \brief Calls the "save as" dialog to save the indenter config file under a chosen name.
    If the file already exists and it should be overwritten, a warning will be shown before.
*/
void IndentHandler::saveasIndentCfgFileDialog()
{
	TQString fileName = TQFileDialog::getSaveFileName(getIndenterCfgFile(), tr("All files (*.*)"),
	        nullptr, nullptr, tr("Save indent config file"));

	if (!fileName.isEmpty())
	{
		TQFile::remove(fileName);
		TQFile outCfgFile(fileName);
		outCfgFile.open(IO_ReadWrite | IO_Translate);
		TQCString paramCString = getParameterString().local8Bit();
		outCfgFile.writeBlock(paramCString.data(), paramCString.length());
		outCfgFile.close();
	}
}

/*
    \brief Invokes the indenter to create a shell script.
    Lets the indenter create a shell script for calling the indenter out of any
    other application and open a save dialog for saving the shell script.
*/
void IndentHandler::createIndenterCallShellScript()
{
	TQString shellScriptExtension;
	shellScriptExtension = "sh";

	TQString fileExtensions = tr("Shell Script") + " (*." + shellScriptExtension + ");;" + tr(
		"All files") + " (*.*)";

	TQString currentIndenterName = getCurrentIndenterName();
	currentIndenterName = currentIndenterName.replace(" ", "_");

	TQString indenterScriptName = "call_" + currentIndenterName + "." + shellScriptExtension;
	TQString shellScriptFileName = TQFileDialog::getSaveFileName(indenterScriptName,
	        fileExtensions, nullptr, nullptr, tr("Save shell script"));

	// Saving has been canceled if the filename is empty
	if (shellScriptFileName.isEmpty())
	{
		return;
	}

	// Delete any old file, write the new contents and set executable permissions.
	TQFile::remove(shellScriptFileName);
	TQFile outSrcFile(shellScriptFileName);
	if (outSrcFile.open(IO_ReadWrite | IO_Translate))
	{
		TQString shellScriptConfigFilename = TQFileInfo(shellScriptFileName).baseName() + "." +
		        TQFileInfo(m_globalConfigFilename).extension(false);

		// Get the content of the shell/batch script.
		TQString indenterCallShellScript = generateShellScript(shellScriptConfigFilename);

		// Replace placeholder for script name in script template.
		indenterCallShellScript = indenterCallShellScript.replace("__INDENTERCALLSTRINGSCRIPTNAME__",
		        TQFileInfo(shellScriptFileName).fileName());

		TQCString indenterString = indenterCallShellScript.local8Bit();
		outSrcFile.writeBlock(indenterString.data(), indenterString.length());
		// For non Windows systems set the files executable flag
		outSrcFile.close();
		int _ = std::system("chmod a+x " + shellScriptFileName.local8Bit());

		// Save the indenter config file to the same directory, where the shell srcipt was saved to,
		// because the script will reference it there via "./".
		if (!m_globalConfigFilename.isEmpty())
		{
			saveConfigFile(TQFileInfo(shellScriptFileName).dirPath(true) + "/" + shellScriptConfigFilename,
			        getParameterString());
		}
	}
}

/*
    \brief Resets all parameters to the indenter's default values as they are specified
		in the uigui ini file, but asks the user whether to do it really.
 */
void IndentHandler::resetIndenterParameter()
{
	int messageBoxAnswer = TQMessageBox::question(this, tr("Really reset parameters?"),
	        tr("Do you really want to reset the indenter parameters to the default values?"),
	        TQMessageBox::Yes, TQMessageBox::Cancel);
	if (messageBoxAnswer == TQMessageBox::Yes)
	{
		resetToDefaultValues();
	}
}

//--- /*
//---     \brief Catch some events and let some other be handled by the super class.
//--- 
//---     Is needed for use as Notepad++ plugin.
//---  */
//--- bool IndentHandler::event(TQEvent *event)
//--- {
//--- 	if (event->type() == TQEvent::WindowActivate)
//--- 	{
//--- 		event->accept();
//--- 		return true;
//--- 	}
//--- 	else if (event->type() == TQEvent::WindowDeactivate)
//--- 	{
//--- 		event->accept();
//--- 		return true;
//--- 	}
//--- 	else
//--- 	{
//--- 		event->ignore();
//--- 		return TQWidget::event(event);
//--- 	}
//--- }

/*
    \brief Emits the \a indenterSettingsChanged signal
 */
void IndentHandler::handleChangedIndenterSettings()
{
	emit(indenterSettingsChanged());
}

//--- /*!
//---     \brief Converts characters < > and & in the \a text to HTML codes &lt &gt and &amp.
//---  */
//--- TQString IndentHandler::encodeToHTML(const TQString &text)
//--- {
//--- 	TQString htmlText = text;
//--- 	htmlText.replace("&", "&amp;");
//--- 	htmlText.replace("<", "&lt;");
//--- 	htmlText.replace(">", "&gt;");
//--- 	htmlText.replace('"', "&quot;");
//--- 	htmlText.replace("'", "&#39;");
//--- 	htmlText.replace("^", "&circ;");
//--- 	htmlText.replace("~", "&tilde;");
//--- 	htmlText.replace("€", "&euro;");
//--- 	htmlText.replace("©", "&copy;");
//--- 	return htmlText;
//--- }

#include "IndentHandler.moc"