-
Notifications
You must be signed in to change notification settings - Fork 351
/
Copy pathconfigmanager.cpp
3887 lines (3509 loc) · 170 KB
/
configmanager.cpp
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
#include "configmanager.h"
#include "configdialog.h"
#include "filedialog.h"
#include "latexeditorview.h"
#include "latexpackage.h"
#include "latexcompleter_config.h"
#include "latexeditorview_config.h"
#include "webpublishdialog_config.h"
#include "insertgraphics_config.h"
#include "grammarcheck_config.h"
#include "PDFDocument_config.h"
#include "terminal_config.h"
#include "encoding.h"
#include "codesnippet.h"
#include "updatechecker.h"
#include "utilsVersion.h"
#include "utilsUI.h"
#include <QDomElement>
#if (QT_VERSION >= 0x060500)
#include <QStyleHints>
#endif
#if (QT_VERSION<QT_VERSION_CHECK(6,0,0))
#include <QDesktopWidget>
#endif
#include "qformatconfig.h"
#include "manhattanstyle.h"
#ifdef ADWAITA
#include "adwaitastyle.h"
#endif
const QString TXS_AUTO_REPLACE_QUOTE_OPEN = "TMX:Replace Quote Open";
const QString TXS_AUTO_REPLACE_QUOTE_CLOSE = "TMX:Replace Quote Close";
const char *PROPERTY_COMMAND_ID = "cmdID";
const char *PROPERTY_NAME_WIDGET = "nameWidget";
const char *PROPERTY_WIDGET_TYPE = "widgetType";
const char *PROPERTY_ASSOCIATED_INPUT = "associatedInput";
const char *PROPERTY_ADD_BUTTON = "addButton";
Q_DECLARE_METATYPE(QPushButton *)
ManagedProperty::ManagedProperty(): storage(nullptr), type(PT_VOID), widgetOffset(0)
{
}
#define CONSTRUCTOR(TYPE, ID) \
ManagedProperty::ManagedProperty(TYPE* storage, QVariant def, ptrdiff_t widgetOffset)\
: storage(storage), type(ID), def(def), widgetOffset(widgetOffset){} \
ManagedProperty ManagedProperty::fromValue(TYPE value) { \
ManagedProperty res; \
res.storage = new TYPE; \
*(static_cast<TYPE*>(res.storage)) = value; \
res.type = ID; \
res.def = res.valueToQVariant(); \
res.widgetOffset = 0; \
return res; \
}
PROPERTY_TYPE_FOREACH_MACRO(CONSTRUCTOR)
#undef CONSTRUCTOR
void ManagedProperty::deallocate()
{
switch (type) {
#define CASE(TYPE, ID) case ID: delete (static_cast<TYPE*>(storage)); break;
PROPERTY_TYPE_FOREACH_MACRO(CASE)
#undef CASE
default:
Q_ASSERT(false);
}
storage = nullptr;
}
static ConfigManager *globalConfigManager = nullptr;
ConfigManagerInterface *ConfigManagerInterface::getInstance()
{
Q_ASSERT(globalConfigManager);
return globalConfigManager;
}
Q_DECLARE_METATYPE(ManagedProperty *)
Q_DECLARE_METATYPE(StringStringMap)
ManagedToolBar::ManagedToolBar(const QString &newName, const QStringList &defs): name(newName), defaults(defs), toolbar(nullptr) {}
QVariant ManagedProperty::valueToQVariant() const
{
Q_ASSERT(storage);
if (!storage) return QVariant();
switch (type) {
#define CONVERT(TYPE, ID) case ID: return *(static_cast<TYPE*>(storage));
PROPERTY_TYPE_FOREACH_MACRO_SIMPLE(CONVERT)
#undef CONVERT
#define CONVERT(TYPE, ID) case ID: return QVariant::fromValue<TYPE>(*(static_cast<TYPE*>(storage)));
PROPERTY_TYPE_FOREACH_MACRO_COMPLEX(CONVERT)
#undef CONVERT
default:
Q_ASSERT(false);
return QVariant();
}
}
void ManagedProperty::valueFromQVariant(const QVariant v)
{
Q_ASSERT(storage);
if (!storage) return;
switch (type) {
case PT_VARIANT:
*(static_cast<QVariant *>(storage)) = v;
break;
case PT_INT:
*(static_cast<int *>(storage)) = v.toInt();
break;
case PT_BOOL:
*(static_cast<bool *>(storage)) = v.toBool();
break;
case PT_STRING:
*(static_cast<QString *>(storage)) = v.toString();
break;
case PT_STRINGLIST:
*(static_cast<QStringList *>(storage)) = v.toStringList();
break;
case PT_DATETIME:
*(static_cast<QDateTime *>(storage)) = v.toDateTime();
break;
case PT_FLOAT:
*(static_cast<float *>(storage)) = v.toFloat();
break;
case PT_DOUBLE:
*(static_cast<double *>(storage)) = v.toDouble();
break;
case PT_BYTEARRAY:
*(static_cast<QByteArray *>(storage)) = v.toByteArray();
break;
case PT_LIST:
*(static_cast<QList<QVariant> *>(storage)) = v.toList();
break;
case PT_MAP_STRING_STRING:
*(static_cast<StringStringMap *>(storage)) = v.value<StringStringMap>();
break;
default:
Q_ASSERT(false);
}
}
void ManagedProperty::writeToObject(QObject *w) const
{
Q_ASSERT(storage && w);
if (!storage || !w) return;
QCheckBox *checkBox = qobject_cast<QCheckBox *>(w);
if (checkBox) {
Q_ASSERT(type == PT_BOOL);
checkBox->setChecked(*(static_cast<bool *>(storage)));
return;
}
QToolButton *toolButton = qobject_cast<QToolButton *>(w);
if (toolButton) {
Q_ASSERT(type == PT_BOOL);
toolButton->setChecked(*(static_cast<bool *>(storage)));
return;
}
QLineEdit *edit = qobject_cast<QLineEdit *>(w);
if (edit) {
Q_ASSERT(type == PT_STRING);
edit->setText(*(static_cast<QString *>(storage)));
return;
}
/*QTextEdit* tedit = qobject_cast<QTextEdit*>(w);
if (tedit){
*((QString*)storage) = tedit->toPlainText();
continue;
}*/
QSpinBox *spinBox = qobject_cast<QSpinBox *>(w);
if (spinBox) {
Q_ASSERT(type == PT_INT);
spinBox->setValue(*(static_cast<int *>(storage)));
return;
}
QComboBox *comboBox = qobject_cast<QComboBox *>(w);
if (comboBox) {
switch (type) {
case PT_BOOL:
comboBox->setCurrentIndex(*(static_cast<bool *>(storage)) ? 1 : 0);
return;
case PT_INT:
comboBox->setCurrentIndex(*(static_cast<int *>(storage)));
return;
case PT_STRING: {
int index = comboBox->findText(*static_cast<QString *>(storage));
if (index > 0) comboBox->setCurrentIndex(index);
if (comboBox->isEditable()) comboBox->setEditText(*static_cast<QString *>(storage));
return;
}
case PT_STRINGLIST: {
QStringList &sl = *static_cast<QStringList *>(storage);
int cp = comboBox->lineEdit() ? comboBox->lineEdit()->cursorPosition() : -1000;
while (comboBox->count() > sl.size())
comboBox->removeItem(comboBox->count() - 1);
for (int i = 0; i < qMin(sl.size(), comboBox->count()); i++)
if (comboBox->itemText(i) != sl[i])
comboBox->setItemText(i, sl[i]);
for (int i = comboBox->count(); i < sl.size(); i++)
comboBox->addItem(sl[i]);
if (cp != -1000) {
//combobox visible (i.e. as used in search panel)
if (!sl.isEmpty() && comboBox->currentText() != sl.last() && comboBox->currentIndex() != sl.size() - 1)
comboBox->setCurrentIndex(sl.size() - 1);
comboBox->lineEdit()->setCursorPosition(cp);
} // else: combobox invisible (i.e. as used in universal input dialog)
return;
}
default:
Q_ASSERT(false);
}
}
QDoubleSpinBox *doubleSpinBox = qobject_cast<QDoubleSpinBox *>(w);
if (doubleSpinBox) {
switch (type) {
case PT_DOUBLE:
doubleSpinBox->setValue(*(static_cast<double *>(storage)));
break;
case PT_FLOAT:
doubleSpinBox->setValue(*(static_cast<float *>(storage)));
break;
default:
Q_ASSERT(false);
}
return;
}
QAction *action = qobject_cast<QAction *>(w);
if (action) {
Q_ASSERT(type == PT_BOOL);
action->setChecked(*(static_cast<bool *>(storage)));
return;
}
QTextEdit *textEdit = qobject_cast<QTextEdit *>(w);
if (textEdit) {
switch (type) {
case PT_STRING:
textEdit->setPlainText(*(static_cast<QString *>(storage)));
break;
case PT_STRINGLIST:
textEdit->setPlainText((static_cast<QStringList *>(storage))->join("\n"));
break;
default:
Q_ASSERT(false);
}
return;
}
Q_ASSERT(false);
}
bool ManagedProperty::readFromObject(const QObject *w)
{
#define READ_FROM_OBJECT(TYPE, VALUE) { \
TYPE oldvalue = *(static_cast<TYPE*>(storage)); \
*(static_cast<TYPE*>(storage)) = VALUE; \
return oldvalue != *(static_cast<TYPE*>(storage)); \
}
Q_ASSERT(storage);
if (!storage) return false;
const QCheckBox *checkBox = qobject_cast<const QCheckBox *>(w);
if (checkBox) {
Q_ASSERT(type == PT_BOOL);
READ_FROM_OBJECT(bool, checkBox->isChecked())
}
const QToolButton *toolButton = qobject_cast<const QToolButton *>(w);
if (toolButton) {
Q_ASSERT(type == PT_BOOL);
READ_FROM_OBJECT(bool, toolButton->isChecked())
}
const QLineEdit *edit = qobject_cast<const QLineEdit *>(w);
if (edit) {
Q_ASSERT(type == PT_STRING);
READ_FROM_OBJECT(QString, edit->text())
}
/*QTextEdit* tedit = qobject_cast<QTextEdit*>(w);
if (tedit){
*((QString*)storage) = tedit->toPlainText();
continue;
}*/
const QSpinBox *spinBox = qobject_cast<const QSpinBox *>(w);
if (spinBox) {
Q_ASSERT(type == PT_INT);
READ_FROM_OBJECT(int, spinBox->value())
}
const QComboBox *comboBox = qobject_cast<const QComboBox *>(w);
if (comboBox) {
switch (type) {
case PT_BOOL:
READ_FROM_OBJECT(bool, comboBox->currentIndex() != 0)
case PT_INT:
READ_FROM_OBJECT(int, comboBox->currentIndex())
case PT_STRING:
READ_FROM_OBJECT(QString, comboBox->currentText())
case PT_STRINGLIST: {
QString oldvalue;
if (!(static_cast<QStringList *>(storage))->isEmpty())
oldvalue = (static_cast<QStringList *>(storage))->first();
*(static_cast<QStringList *>(storage)) = QStringList(comboBox->currentText());
return oldvalue != comboBox->currentText();
}
default:
Q_ASSERT(false);
}
}
const QDoubleSpinBox *doubleSpinBox = qobject_cast<const QDoubleSpinBox *>(w);
if (doubleSpinBox) {
switch (type) {
case PT_DOUBLE:
READ_FROM_OBJECT(double, doubleSpinBox->value())
case PT_FLOAT:
READ_FROM_OBJECT(float, doubleSpinBox->value())
default:
Q_ASSERT(false);
}
}
const QAction *action = qobject_cast<const QAction *>(w);
if (action) {
Q_ASSERT(type == PT_BOOL);
Q_ASSERT(action->isCheckable());
READ_FROM_OBJECT(bool, action->isChecked())
}
const QTextEdit *textEdit = qobject_cast<const QTextEdit *>(w);
if (textEdit) {
switch (type) {
case PT_STRING:
READ_FROM_OBJECT(QString, textEdit->toPlainText())
case PT_STRINGLIST:
READ_FROM_OBJECT(QStringList, textEdit->toPlainText().split("\n"))
default:
Q_ASSERT(false);
}
}
Q_ASSERT(false);
return false;
}
#undef READ_FROM_OBJECT
const int ConfigManager::MAX_NUM_MACROS;
QTextCodec *ConfigManager::newFileEncoding = nullptr;
QString ConfigManager::configDirOverride;
bool ConfigManager::dontRestoreSession=false;
int ConfigManager::RUNAWAYLIMIT=50;
QString getText(QWidget *w)
{
if (qobject_cast<QLineEdit *>(w)) return qobject_cast<QLineEdit *>(w)->text();
else if (qobject_cast<QComboBox *>(w)) return qobject_cast<QComboBox *>(w)->currentText();
else REQUIRE_RET(false, "");
}
void setText(QWidget *w, const QString &t)
{
if (qobject_cast<QLineEdit *>(w)) qobject_cast<QLineEdit *>(w)->setText(t);
else if (qobject_cast<QComboBox *>(w)) {
QComboBox * cb=qobject_cast<QComboBox *>(w);
if(!cb->isEditable())
cb->setEditable(true);
cb->setEditText(t);
}
else REQUIRE(false);
}
void assignNameWidget(QWidget *w, QWidget *nameWidget)
{
w->setProperty(PROPERTY_NAME_WIDGET, QVariant::fromValue<QWidget *>(nameWidget));
QString cmdID = nameWidget->property(PROPERTY_COMMAND_ID).toString();
if (!cmdID.isEmpty()) {
// user commands don't store the ID in the property, because it's editable
// In builtin commmands, the ID is fixed, so we can directly assign it to the widget.
// this speeds up lookup in getCmdID
w->setProperty(PROPERTY_COMMAND_ID, cmdID);
}
}
QString getCmdID(QWidget *w)
{
QString cmdID = w->property(PROPERTY_COMMAND_ID).toString();
if (!cmdID.isEmpty()) return cmdID;
QWidget *nameWidget = w->property(PROPERTY_NAME_WIDGET).value<QWidget *>();
if (!nameWidget) nameWidget = w;
cmdID = nameWidget->property(PROPERTY_COMMAND_ID).toString();
if (!cmdID.isEmpty()) return cmdID;
// user commands don't store the ID in the property, because it's editable
QLineEdit *le = qobject_cast<QLineEdit *>(nameWidget);
REQUIRE_RET(le, "");
QString combinedName = le->text();
int pos = combinedName.indexOf(":");
cmdID = (pos == -1) ? combinedName : combinedName.left(pos);
return cmdID;
}
ConfigManager::ConfigManager(QObject *parent): QObject (parent),
buildManager(nullptr), editorConfig(new LatexEditorViewConfig),
completerConfig (new LatexCompleterConfig),
webPublishDialogConfig (new WebPublishDialogConfig),
pdfDocumentConfig(new PDFDocumentConfig),
insertGraphicsConfig(new InsertGraphicsConfig),
grammarCheckerConfig(new GrammarCheckerConfig),
terminalConfig(new InternalTerminalConfig),
menuParent(nullptr), menuParentsBar(nullptr), modifyMenuContentsFirstCall(true), pdflatexEdit(nullptr), persistentConfig(nullptr)
{
Q_ASSERT(!globalConfigManager);
globalConfigManager = this;
//interface - store these values once before they are overwritten by some customizaton
systemPalette = QApplication::palette();
defaultStyleName = QApplication::style()->objectName();
#if QT_VERSION>=QT_VERSION_CHECK(6,0,0)
qRegisterMetaType<StringStringMap>("StringStringMap");
#else
qRegisterMetaTypeStreamOperators<StringStringMap>("StringStringMap");
#endif
managedToolBars.append(ManagedToolBar("Custom", QStringList()));
managedToolBars.append(ManagedToolBar("File", QStringList() << "main/file/new" << "main/file/open" << "main/file/save" << "main/file/close"));
managedToolBars.append(ManagedToolBar("Edit", QStringList() << "main/edit/undo" << "main/edit/redo" << "main/edit/copy" << "main/edit/cut" << "main/edit/paste"));
managedToolBars.append(ManagedToolBar("Tools", QStringList() << "main/tools/quickbuild" << "main/tools/compile" << "main/tools/stopcompile" << "main/tools/view" << "main/tools/viewlog"));
managedToolBars.append(ManagedToolBar("Math", QStringList() << "tags/brackets/left" << "separator" << "tags/brackets/right"));
managedToolBars.append(ManagedToolBar("Format", QStringList() << "main/latex/sectioning" << "separator" << "main/latex/references" << "separator" << "main/latex/fontsizes"));
managedToolBars.append(ManagedToolBar("Table", QStringList() << "main/latex/tabularmanipulation/addRow" << "main/latex/tabularmanipulation/addColumn" << "main/latex/tabularmanipulation/pasteColumn" << "main/latex/tabularmanipulation/removeRow" << "main/latex/tabularmanipulation/removeColumn" << "main/latex/tabularmanipulation/cutColumn" << "main/latex/tabularmanipulation/alignColumns"));
managedToolBars.append(ManagedToolBar("Diff", QStringList() << "main/file/svn/prevdiff" << "main/file/svn/nextdiff" ));
managedToolBars.append(ManagedToolBar("Review", QStringList() << "main/latex/review/alert" << "main/latex/review/comment" << "main/latex/review/add" << "main/latex/review/delete" << "main/latex/review/replace" ));
managedToolBars.append(ManagedToolBar("Central", QStringList() << "main/edit/goto/goback" << "main/edit/goto/goforward" << "separator" << "main/latex/fontstyles/textbf" << "main/latex/fontstyles/textit" << "main/latex/fontstyles/underline" << "main/latex/environment/flushleft" << "main/latex/environment/center" << "main/latex/environment/flushright" << "separator" <<
"main/latex/verticalSpacing/newline" << "separator" <<
"main/math/mathmode" << "main/math/subscript" << "main/math/superscript" << "main/math/frac" << "main/math/dfrac" << "main/math/sqrt"));
Ui::ConfigDialog *pseudoDialog = static_cast<Ui::ConfigDialog *>(nullptr);
registerOption("Startup/CheckLatexConfiguration", &checkLatexConfiguration, true, &pseudoDialog->checkBoxCheckLatexConfiguration);
registerOption("ToolBar/CentralVisible", ¢ralVisible, true);
registerOption("StructureView/ShowLinenumbers", &showLineNumbersInStructure, false);
registerOption("StructureView/Indentation", &indentationInStructure, -1);
registerOption("StructureView/IndentIncludes", &indentIncludesInStructure, false, &pseudoDialog->checkBoxIndentIncludesInStructureTree);
registerOption("Structure/ShowElementsInComments", &showCommentedElementsInStructure, false); //, &pseudoDialog->checkBoxShowCommentedElementsInStructure); config element removed as it is not working
registerOption("Structure/MarkStructureElementsBeyondEnd", &markStructureElementsBeyondEnd, true, &pseudoDialog->checkBoxMarkStructureElementsBeyondEnd);
registerOption("Structure/MarkStructureElementsInAppendix", &markStructureElementsInAppendix, true, &pseudoDialog->checkBoxMarkStructureElementsInAppendix);
registerOption("StructureView/ReferenceCommandsInContextMenu", &referenceCommandsInContextMenu, "\\ref", &pseudoDialog->leReferenceCommandsInContextMenu);
registerOption("StructureView/BackgroundColorInGlobalTOC", &globalTOCbackgroundOptions, 1, &pseudoDialog->comboBoxTOCBackgroundColor);
registerOption("StructureView/SingleDocMode", &structureShowSingleDoc, false);
registerOption("StructureView/ScrollToCurrentPosition", &structureScrollToCurrentPosition, true, &pseudoDialog->checkBoxScrollToCurrentPosition);
registerOption("MacroEditor/LineWrap", ¯oEditorUsesLineWrap, false);
//files
registerOption("Files/New File Encoding", &newFileEncodingName, "utf-8", &pseudoDialog->comboBoxEncoding); //check
registerOption("Files/AutoDetectEncodingFromChars", &autoDetectEncodingFromChars, true, &pseudoDialog->checkBoxAutoDetectEncodingFromChars);
registerOption("Files/AutoDetectEncodingFromLatex", &autoDetectEncodingFromLatex, true, &pseudoDialog->checkBoxAutoDetectEncodingFromLatex);
registerOption("Common Encodings", &commonEncodings, QStringList() << "UTF-8" << "ISO-8859-1" << "windows-1252" << "Apple Roman");
//recent files
registerOption("Files/Max Recent Files", &maxRecentFiles, 5, &pseudoDialog->spinBoxMaxRecentFiles);
registerOption("Files/Max Recent Projects", &maxRecentProjects, 3, &pseudoDialog->spinBoxMaxRecentProjects);
registerOption("Files/Max Recent Sessions", &maxRecentSessions, 5);
registerOption("Files/Recent Files", &recentFilesList);
registerOption("Files/Recent Project Files", &recentProjectList);
registerOption("Files/Recent Session Files", &recentSessionList);
registerOption("Files/Remember File Filter", &rememberFileFilter, true, &pseudoDialog->checkBoxRememberFileFilter);
registerOption("Files/Use Native File Dialog", &useNativeFileDialog, true, &pseudoDialog->checkBoxUseNativeFileDialog);
registerOption("Files/Recent Files Highlighting", &recentFileHighlightLanguage);
registerOption("Files/RestoreSession", &sessionRestore, true, &pseudoDialog->checkBoxRestoreSession);
registerOption("Files/Last Document", &lastDocument);
registerOption("Files/Parse BibTeX", &parseBibTeX, true, &pseudoDialog->checkBoxParseBibTeX);
registerOption("Bibliography/BibFileEncoding", &bibFileEncoding, "UTF-8", &pseudoDialog->comboBoxBibFileEncoding);
registerOption("Files/Parse Master", &parseMaster, true, &pseudoDialog->checkBoxParseRootDoc);
registerOption("Files/Autosave", &autosaveEveryMinutes, 0);
registerOption("Files/Autoload", &autoLoadChildren, true, &pseudoDialog->checkBoxAutoLoad);
registerOption("Files/CacheStructure", &cacheDocuments, true, &pseudoDialog->checkBoxUseCache);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
registerOption("Files/Bib Paths", &additionalBibPaths, env.value("BIBINPUTS", ""), &pseudoDialog->lineEditPathBib);
registerOption("Files/Image Paths", &additionalImagePaths, env.value("TEXINPUTS", ""), &pseudoDialog->lineEditPathImages);
registerOption("Session/StoreRelativePaths", &sessionStoreRelativePaths, true, &pseudoDialog->checkBoxSessionStoreRelativePaths);
registerOption("Editor/GoToErrorWhenDisplayingLog", &goToErrorWhenDisplayingLog , true, &pseudoDialog->checkBoxGoToErrorWhenDisplayingLog);
registerOption("Editor/ShowLogMarkersWhenClickingLogEntry", &showLogMarkersWhenClickingLogEntry , true, &pseudoDialog->checkBoxShowLogMarkersWhenClickingLogEntry);
registerOption("Editor/LogFileEncoding", &logFileEncoding, "Document", &pseudoDialog->comboBoxLogFileEncoding);
registerOption("Editor/ScanInstalledLatexPackages", &scanInstalledLatexPackages, true, &pseudoDialog->checkBoxScanInstalledLatexPackages);
registerOption("Tools/Insert Unicode From SymbolGrid", &insertSymbolsAsUnicode, false, &pseudoDialog->checkBoxInsertSymbolAsUCS);
registerOption("Tools/SymbolGrid Splitter", &stateSymbolsWidget, QByteArray());
registerOption("Spell/DictionaryDir", &spellDictDir, "", &pseudoDialog->leDictDir); //don't translate it
registerOption("Spell/Language", &spellLanguage, "<none>", &pseudoDialog->comboBoxSpellcheckLang);
registerOption("Spell/Dic", &spell_dic, "<dic not found>", nullptr);
registerOption("Thesaurus/Database", &thesaurus_database, "<dic not found>", &pseudoDialog->comboBoxThesaurusFileName);
registerOption("Spell/UsedLanguages", &previouslyUsedDictionaries, QStringList{"en_US","fr_FR","de_DE"}, nullptr);
//macro repository
registerOption("Macros/RepositoryURL", &URLmacroRepository, "https://api.github.com/repos/texstudio-org/texstudio-macro/contents/", nullptr);
//updates
registerOption("Update/AutoCheck", &autoUpdateCheck, true, &pseudoDialog->checkBoxAutoUpdateCheck);
registerOption("Update/UpdateLevel", &updateLevel, 0, &pseudoDialog->comboBoxUpdateLevel);
registerOption("Update/AutoCheckInvervalDays", &autoUpdateCheckIntervalDays, 7, &pseudoDialog->spinBoxAutoUpdateCheckIntervalDays);
registerOption("Update/LastCheck", &lastUpdateCheck, QDateTime());
//editor
registerOption("Editor/WordWrapMode", &editorConfig->wordwrap, 1, &pseudoDialog->comboBoxLineWrap);
registerOption("Editor/WrapLineWidth", &editorConfig->lineWidth, 80, &pseudoDialog->spinBoxWrapLineWidth);
registerOption("Editor/Parentheses Matching", &editorConfig->parenmatch, true); //TODO: checkbox?
registerOption("Editor/Parentheses Completion", &editorConfig->parenComplete, true, &pseudoDialog->checkBoxAutoCompleteParens);
registerOption("Editor/Line Number Multiples", &editorConfig->showlinemultiples, 0);
registerOption("Editor/Cursor Surrounding Lines", &editorConfig->cursorSurroundLines, 5);
registerOption("Editor/BoldCursor", &editorConfig->boldCursor, true, &pseudoDialog->checkBoxBoldCursor);
registerOption("Editor/CenterDocumentInEditor", &editorConfig->centerDocumentInEditor, false, &pseudoDialog->checkBoxCenterDocumentInEditor);
registerOption("Editor/Auto Indent", &editorConfig->autoindent, true);
registerOption("Editor/Weak Indent", &editorConfig->weakindent, false);
registerOption("Editor/Indent with Spaces", &editorConfig->replaceIndentTabs, false, &pseudoDialog->checkBoxReplaceIndentTabByWhitespace);
registerOption("Editor/ReplaceTextTabs", &editorConfig->replaceTextTabs, false, &pseudoDialog->checkBoxReplaceTextTabByWhitespace);
registerOption("Editor/RemoveTrailingWsOnSave", &editorConfig->removeTrailingWsOnSave, false, &pseudoDialog->checkboxRemoveTrailingWsOnSave);
registerOption("Editor/Folding", &editorConfig->folding, true, &pseudoDialog->checkBoxFolding);
registerOption("Editor/Show Line State", &editorConfig->showlinestate, true, &pseudoDialog->checkBoxLineState);
registerOption("Editor/Show Cursor State", &editorConfig->showcursorstate, true, &pseudoDialog->checkBoxState);
registerOption("Editor/Real-Time Spellchecking", &editorConfig->realtimeChecking, true, &pseudoDialog->checkBoxRealTimeCheck); //named for compatibility reasons with older txs versions
registerOption("Editor/Check Spelling", &editorConfig->inlineSpellChecking, true, &pseudoDialog->checkBoxInlineSpellCheck);
registerOption("Editor/Check Citations", &editorConfig->inlineCitationChecking, true, &pseudoDialog->checkBoxInlineCitationCheck);
registerOption("Editor/Check References", &editorConfig->inlineReferenceChecking, true, &pseudoDialog->checkBoxInlineReferenceCheck);
registerOption("Editor/Check Syntax", &editorConfig->inlineSyntaxChecking, true, &pseudoDialog->checkBoxInlineSyntaxCheck);
registerOption("Editor/Check Grammar", &editorConfig->inlineGrammarChecking, true, &pseudoDialog->checkBoxInlineGrammarCheck);
registerOption("Editor/Check Package", &editorConfig->inlinePackageChecking, true, &pseudoDialog->checkBoxInlinePackageCheck);
registerOption("Editor/Check In Non TeX Files", &editorConfig->inlineCheckNonTeXFiles, true, &pseudoDialog->checkBoxInlineCheckNonTeXFiles);
registerOption("Editor/Hide Spelling Errors in Non Text", &editorConfig->hideNonTextSpellingErrors, true, &pseudoDialog->checkBoxHideSpellingErrorsInNonText);
registerOption("Editor/Hide Grammar Errors in Non Text", &editorConfig->hideNonTextGrammarErrors, true, &pseudoDialog->checkBoxHideGrammarErrorsInNonText);
registerOption("Editor/Show Whitespace", &editorConfig->showWhitespace, false, &pseudoDialog->checkBoxShowWhitespace);
registerOption("Editor/TabStop", &editorConfig->tabStop, 4 , &pseudoDialog->sbTabSpace);
registerOption("Editor/ToolTip Help", &editorConfig->toolTipHelp, true, &pseudoDialog->checkBoxToolTipHelp2);
registerOption("Editor/ToolTip Preview", &editorConfig->toolTipPreview, true, &pseudoDialog->checkBoxToolTipPreview);
registerOption("Editor/ImageToolTip", &editorConfig->imageToolTip, true, &pseudoDialog->checkBoxImageToolTip);
registerOption("Editor/MaxImageTooltipWidth", &editorConfig->maxImageTooltipWidth, 400);
registerOption("Editor/ContextMenuKeyboardModifiers", &editorConfig->contextMenuKeyboardModifiers, Qt::ShiftModifier);
registerOption("Editor/ContextMenuSpellcheckingEntryLocation", &editorConfig->contextMenuSpellcheckingEntryLocation, 0, &pseudoDialog->comboBoxContextMenuSpellcheckingEntryLocation);
registerOption("Editor/TexDoc Help Internal", &editorConfig->texdocHelpInInternalViewer, true , &pseudoDialog->checkBoxTexDocInternal);
registerOption("Editor/MonitorFilesForExternalChanges", &editorConfig->monitorFilesForExternalChanges, true, &pseudoDialog->checkBoxMonitorFilesForExternalChanges);
registerOption("Editor/SilentReload", &editorConfig->silentReload, false, &pseudoDialog->checkBoxSilentReload);
#ifdef Q_OS_WIN
// QSaveFile does not work with dropbox on windows: https://sourceforge.net/p/texstudio/bugs/1933/, https://bugreports.qt.io/browse/QTBUG-57299
// We disable usage of QSaveFile and revert to our own file saving mechanism until the problem gets fixed.
// Note: When deleting this, also delete ui.checkBoxUseQSaveWrite->setVisible(false);
editorConfig->useQSaveFile = false;
#else
registerOption("Editor/UseQSaveFile", &editorConfig->useQSaveFile, true, &pseudoDialog->checkBoxUseQSaveWrite);
#endif
registerOption("Editor/Replace Quotes", &replaceQuotes, 0 , &pseudoDialog->comboBoxReplaceQuotes);
registerOption("Editor/Close Search Replace Together", &editorConfig->closeSearchAndReplace, true, &pseudoDialog->checkBoxCloseSearchReplaceTogether);
registerOption("Editor/Use Line For Search", &editorConfig->useLineForSearch, true, &pseudoDialog->checkBoxUseLineForSearch);
registerOption("Editor/Search Only In Selection", &editorConfig->searchOnlyInSelection, true, &pseudoDialog->checkBoxSearchOnlyInSelection);
registerOption("Editor/Auto Replace Commands", &CodeSnippet::autoReplaceCommands, true, &pseudoDialog->checkBoxAutoReplaceCommands);
registerOption("Editor/OnlyMonospacedFonts", &onlyMonospacedFonts, false, &pseudoDialog->checkBoxShowOnlyMonospacedFonts);
registerOption("Editor/Font Family", &editorConfig->fontFamily, "", &pseudoDialog->comboBoxFont);
registerOption("Editor/Font Size", &editorConfig->fontSize, -1, &pseudoDialog->spinBoxSize);
registerOption("Editor/Line Spacing Percent", &editorConfig->lineSpacingPercent, 100, &pseudoDialog->spinBoxLineSpacingPercent);
registerOption("Editor/Esc for closing log", &useEscForClosingLog, false, &pseudoDialog->checkBoxCloseLogByEsc);
registerOption("Editor/UseEscForClosingEmbeddedViewer", &useEscForClosingEmbeddedViewer, true, &pseudoDialog->checkBoxCloseEmbeddedViewerByEsc);
registerOption("Editor/UseEscForClosingFullscreen", &useEscForClosingFullscreen, true, &pseudoDialog->checkBoxCloseFullscreenByEsc);
registerOption("Editor/ShowShortcutsInTooltips", &showShortcutsInTooltips, true, &pseudoDialog->checkBoxShowShortcutsInTooltips);
registerOption("Editor/AllowDragAndDrop", &editorConfig->allowDragAndDrop, true, &pseudoDialog->checkBoxAllowDragAndDrop);
registerOption("Editor/Mouse Wheel Zoom", &editorConfig->mouseWheelZoom, true, &pseudoDialog->checkBoxMouseWheelZoom);
registerOption("Editor/Smooth Scrolling", &editorConfig->smoothScrolling, true, &pseudoDialog->checkBoxSmoothScrolling);
registerOption("Editor/Vertical Over Scroll", &editorConfig->verticalOverScroll, false, &pseudoDialog->checkBoxVerticalOverScroll);
registerOption("Editor/Hack Auto Choose", &editorConfig->hackAutoChoose, true, &pseudoDialog->checkBoxHackAutoRendering);
registerOption("Editor/Hack Disable Fixed Pitch", &editorConfig->hackDisableFixedPitch, false, &pseudoDialog->checkBoxHackDisableFixedPitch);
registerOption("Editor/Hack Disable Width Cache", &editorConfig->hackDisableWidthCache, false, &pseudoDialog->checkBoxHackDisableWidthCache);
registerOption("Editor/Hack Disable Line Cache", &editorConfig->hackDisableLineCache, false, &pseudoDialog->checkBoxHackDisableLineCache);
registerOption("Editor/Hack Disable Accent Workaround", &editorConfig->hackDisableAccentWorkaround, false, &pseudoDialog->checkBoxHackDisableAccentWorkaround);
registerOption("Editor/Hack Render Mode", &editorConfig->hackRenderingMode, 0, &pseudoDialog->comboBoxHackRenderMode);
registerOption("Editor/Hack QImage Cache", &editorConfig->hackQImageCache, false, &pseudoDialog->checkBoxHackQImageCache);
//completion
registerOption("Editor/Completion", &completerConfig->enabled, true, &pseudoDialog->checkBoxCompletion);
Q_ASSERT(sizeof(int) == sizeof(LatexCompleterConfig::CaseSensitive));
registerOption("Editor/Completion Case Sensitive", reinterpret_cast<int *>(&completerConfig->caseSensitive), 2);
registerOption("Editor/Completion Complete Common Prefix", &completerConfig->completeCommonPrefix, true, &pseudoDialog->checkBoxCompletePrefix);
registerOption("Editor/Completion EOW Completes", &completerConfig->eowCompletes, false, &pseudoDialog->checkBoxEOWCompletes);
registerOption("Editor/Completion Enable Tooltip Help", &completerConfig->tooltipHelp, true, &pseudoDialog->checkBoxToolTipHelp);
registerOption("Editor/Completion Enable Tooltip Preview", &completerConfig->tooltipPreview, true, &pseudoDialog->checkBoxToolTipCompletePreview);
registerOption("Editor/Completion Use Placeholders", &completerConfig->usePlaceholders, true, &pseudoDialog->checkBoxUsePlaceholders);
registerOption("Editor/Completion Show Placeholders", &editorConfig->showPlaceholders, true, &pseudoDialog->checkBoxShowPlaceholders);
registerOption("Editor/Completion Prefered Tab", reinterpret_cast<int *>(&completerConfig->preferedCompletionTab), 0, &pseudoDialog->comboBoxPreferedTab);
registerOption("Editor/Completion Tab Relative Font Size Percent", &completerConfig->tabRelFontSizePercent, 100, &pseudoDialog->spinBoxTabRelFontSize);
registerOption("Editor/Completion Auto Insert Math", &completerConfig->autoInsertMathDelimiters, true, &pseudoDialog->checkBoxAutoInsertMathDelimiters);
registerOption("Editor/Completion Auto Insert Math Start", &completerConfig->startMathDelimiter,"$");
registerOption("Editor/Completion Auto Insert Math Stop", &completerConfig->stopMathDelimiter,"$");
registerOption("Editor/Auto Insert LRM", &editorConfig->autoInsertLRM, false, &pseudoDialog->checkBoxAutoLRM);
registerOption("Editor/Visual Column Mode", &editorConfig->visualColumnMode, true, &pseudoDialog->checkBoxVisualColumnMode);
registerOption("Editor/Auto Switch Language Direction", &editorConfig->switchLanguagesDirection, true, &pseudoDialog->checkBoxSwitchLanguagesDirection);
registerOption("Editor/Auto Switch Language Math", &editorConfig->switchLanguagesMath, false, &pseudoDialog->checkBoxSwitchLanguagesMath);
registerOption("Editor/Overwrite Opening Bracket Followed By Placeholder", &editorConfig->overwriteOpeningBracketFollowedByPlaceholder, true, &pseudoDialog->checkOverwriteOpeningBracketFollowedByPlaceholder);
registerOption("Editor/Overwrite Closing Bracket Following Placeholder", &editorConfig->overwriteClosingBracketFollowingPlaceholder, true, &pseudoDialog->checkOverwriteClosingBracketFollowingPlaceholder);
registerOption("Editor/Double-click Selection Includes Leading Backslash", &editorConfig->doubleClickSelectionIncludeLeadingBackslash, true, &pseudoDialog->checkBoxDoubleClickSelectionIncludeLeadingBackslash);
registerOption("Editor/TripleClickSelection", &editorConfig->tripleClickSelectionIndex, 4, &pseudoDialog->comboBoxTripleClickSelection);
registerOption("Editor/todo comment regExp", &editorConfig->regExpTodoComment, "%\\s*(TODO|todo)",&pseudoDialog->leRegExpTODO);
registerOption("Editor/insertCiteCommand",&citeCommand,"\\cite",&pseudoDialog->lineEditCiteCommand);
//table autoformating
registerOption("TableAutoformat/Special Commands", &tableAutoFormatSpecialCommands, "\\hline,\\cline,\\intertext,\\shortintertext,\\toprule,\\midrule,\\cmidrule,\\bottomrule", &pseudoDialog->leTableFormatingSpecialCommands);
registerOption("TableAutoformat/Special Command Position", &tableAutoFormatSpecialCommandPos, 0, &pseudoDialog->cbTableFormatingSpecialCommandPos);
registerOption("TableAutoformat/One Line Per Cell", &tableAutoFormatOneLinePerCell, false, &pseudoDialog->cbTableFormatingOneLinePerCell);
//grammar
registerOption("Grammar/Long Repetition Check", &grammarCheckerConfig->longRangeRepetitionCheck, true, &pseudoDialog->checkBoxGrammarRepetitionCheck);
registerOption("Grammar/Bad Word Check", &grammarCheckerConfig->badWordCheck, true, &pseudoDialog->checkBoxGrammarBadWordCheck);
registerOption("Grammar/Long Repetition Check Distance", &grammarCheckerConfig->maxRepetitionDelta, 3, &pseudoDialog->spinBoxGrammarRepetitionDistance);
registerOption("Grammar/Very Long Repetition Check Distance", &grammarCheckerConfig->maxRepetitionLongRangeDelta, 10, &pseudoDialog->spinBoxGrammarLongRangeRepetition);
registerOption("Grammar/Very Long Repetition Check Min Length", &grammarCheckerConfig->maxRepetitionLongRangeMinWordLength, 6, &pseudoDialog->spinBoxGrammarLongRangeRepetitionMinLength);
registerOption("Grammar/Word Lists Dir", &grammarCheckerConfig->wordlistsDir, "", &pseudoDialog->lineEditGrammarWordlists);
#ifdef Q_OS_WIN
registerOption("Grammar/Language Tool URL", &grammarCheckerConfig->languageToolURL, "", &pseudoDialog->lineEditGrammarLTUrl);
#else
registerOption("Grammar/Language Tool URL", &grammarCheckerConfig->languageToolURL, "http://localhost:8081/", &pseudoDialog->lineEditGrammarLTUrl);
#endif
registerOption("Grammar/Language Tool Path", &grammarCheckerConfig->languageToolPath, "", &pseudoDialog->lineEditGrammarLTPath);
registerOption("Grammar/Language Tool Arguments", &grammarCheckerConfig->languageToolArguments, "org.languagetool.server.HTTPServer -p 8081", &pseudoDialog->lineEditGrammarLTArguments);
registerOption("Grammar/Language Tool Java Path", &grammarCheckerConfig->languageToolJavaPath, "java", &pseudoDialog->lineEditGrammarLTJava);
registerOption("Grammar/Language Tool Autorun", &grammarCheckerConfig->languageToolAutorun, true, &pseudoDialog->checkBoxGrammarLTAutorun);
registerOption("Grammar/Language Tool Ignored Rules", &grammarCheckerConfig->languageToolIgnoredRules, "", &pseudoDialog->lineEditGrammarLTIgnoredRules);
#define TEMP(ID) registerOption("Grammar/Special Rules" #ID, &grammarCheckerConfig->specialIds##ID, "", &pseudoDialog->lineEditGrammarSpecialRules##ID)
TEMP(1);
TEMP(2);
TEMP(3);
TEMP(4);
#undef TEMP
// add basic path info into grammarcheckconfig to avoid further use of globals
grammarCheckerConfig->appDir=removePathDelim(QCoreApplication::applicationDirPath());
grammarCheckerConfig->configDir=removePathDelim(configBaseDir);
//other dialogs
registerOption("Dialogs/Last Hard Wrap Column", &lastHardWrapColumn, 80);
registerOption("Dialogs/Last Hard Wrap Smart Scope Selection", &lastHardWrapSmartScopeSelection, false);
registerOption("Dialogs/Last Hard Wrap Join Lines", &lastHardWrapJoinLines, false);
registerOption("Dialogs/Show config dialog maximized",&showConfigMaximized,false);
//build commands
registerOption("Tools/SingleViewerInstance", &BuildManager::singleViewerInstance, false, &pseudoDialog->checkBoxSingleInstanceViewer);
registerOption("Tools/Show Messages When Compiling", &showMessagesWhenCompiling, true, &pseudoDialog->checkBoxShowMessagesOnCompile);
registerOption("Tools/Show Stdout", &showStdoutOption, 1, &pseudoDialog->comboBoxShowStdout);
registerOption("Tools/Automatic Rerun Times", &BuildManager::autoRerunLatex, 5, &pseudoDialog->spinBoxRerunLatex);
registerOption("Tools/ShowLogInCaseOfCompileError", &BuildManager::showLogInCaseOfCompileError, true, &pseudoDialog->checkBoxShowLogInCaseOfCompileError);
registerOption("Tools/ReplaceEnvironmentVariables", &BuildManager::m_replaceEnvironmentVariables, true, &pseudoDialog->checkBoxReplaceEnvironmentVariables);
registerOption("Tools/InterpetCommandDefinitionInMagicComment", &BuildManager::m_interpetCommandDefinitionInMagicComment, true, &pseudoDialog->checkBoxInterpetCommandDefinitionInMagicComment);
registerOption("Tools/SupportShellStyleLiteralQuotes", &BuildManager::m_supportShellStyleLiteralQuotes, true);
//Paths
QString defaultSearchPaths;
registerOption("Tools/Search Paths", &BuildManager::additionalSearchPaths, defaultSearchPaths, &pseudoDialog->lineEditPathCommands);
registerOption("Tools/Log Paths", &BuildManager::additionalLogPaths, "", &pseudoDialog->lineEditPathLog);
registerOption("Tools/PDF Paths", &BuildManager::additionalPdfPaths, "", &pseudoDialog->lineEditPathPDF);
//SVN/GIT
//registerOption("Tools/Auto Checkin after Save", &autoCheckinAfterSave, false, &pseudoDialog->cbAutoCheckin);
registerOption("Tools/UseVCS", &useVCS, 0, &pseudoDialog->comboBoxUseVCS);
registerOption("Tools/Auto Checkin after Save level", &autoCheckinAfterSaveLevel, 0, &pseudoDialog->comboBoxAutoCheckinLevel);
registerOption("Tools/SVN Undo", &svnUndo, false, &pseudoDialog->cbSVNUndo);
registerOption("Tools/SVN KeywordSubstitution", &svnKeywordSubstitution, false, &pseudoDialog->cbKeywordSubstitution);
registerOption("Tools/SVN Search Path Depth", &svnSearchPathDepth, 2, &pseudoDialog->sbDirSearchDepth);
#ifdef INTERNAL_TERMINAL
registerOption("Terminal/ColorScheme", &terminalConfig->terminalColorScheme, "Linux", &pseudoDialog->comboBoxTerminalColorScheme);
registerOption("Terminal/Font Family", &terminalConfig->terminalFontFamily, "", &pseudoDialog->comboBoxTerminalFont);
registerOption("Terminal/Font Size", &terminalConfig->terminalFontSize, -1, &pseudoDialog->spinBoxTerminalFontSize);
registerOption("Terminal/Shell", &terminalConfig->terminalShell, "/bin/bash", &pseudoDialog->lineEditTerminalShell);
#endif
//interfaces
int defaultStyle=0;
registerOption("GUI/Style", &modernStyle, defaultStyle, &pseudoDialog->comboBoxInterfaceModernStyle);
registerOption("GUI/Icon Theme", &iconTheme, 0, &pseudoDialog->comboBoxInterfaceIconTheme);
#if defined Q_WS_X11 || defined Q_OS_LINUX
interfaceFontFamily = "<later>";
interfaceStyle = "<later>";
#else
interfaceFontFamily = QApplication::font().family();
interfaceStyle = "";
#endif
registerOption("GUI/Texmaker Palette", &useTexmakerPalette, false, &pseudoDialog->checkBoxUseTexmakerPalette);
registerOption("GUI/Use System Theme", &useSystemTheme, true, &pseudoDialog->checkBoxUseSystemTheme);
registerOption("X11/Font Family", &interfaceFontFamily, interfaceFontFamily, &pseudoDialog->comboBoxInterfaceFont); //named X11 for backward compatibility
registerOption("X11/Font Size", &interfaceFontSize, QApplication::font().pointSize(), &pseudoDialog->spinBoxInterfaceFontSize);
registerOption("X11/Style", &interfaceStyle, interfaceStyle, &pseudoDialog->comboBoxInterfaceStyle);
registerOption("GUI/ToobarIconSize", &guiToolbarIconSize, 24);
registerOption("GUI/SymbolSize", &guiSymbolGridIconSize, 32);
registerOption("GUI/SecondaryToobarIconSize", &guiSecondaryToolbarIconSize, 16);
registerOption("GUI/PDFToobarIconSize", &guiPDFToolbarIconSize, 16);
registerOption("GUI/ConfigShorcutColumnWidth", &guiConfigShortcutColumnWidth, 200);
registerOption("View/ShowStatusbar", &showStatusbar, true);
registerOption("Interface/Config Show Advanced Options", &configShowAdvancedOptions, false, &pseudoDialog->checkBoxShowAdvancedOptions);
registerOption("Interface/Config Riddled", &configRiddled, false);
registerOption("Interface/MRU Document Chooser", &mruDocumentChooser, false, &pseudoDialog->checkBoxMRUDocumentChooser);
//language
registerOption("Interface/Language", &language, "", &pseudoDialog->comboBoxLanguage);
//preview
registerOption("Preview/Mode", reinterpret_cast<int *>(&previewMode), static_cast<int>(PM_INLINE), &pseudoDialog->comboBoxPreviewMode);
registerOption("Preview/Auto Preview", reinterpret_cast<int *>(&autoPreview), 1, &pseudoDialog->comboBoxAutoPreview);
registerOption("Preview/Auto Preview Delay", &autoPreviewDelay, 300, &pseudoDialog->spinBoxAutoPreviewDelay);
registerOption("Preview/SegmentPreviewScalePercent", &segmentPreviewScalePercent, 150, &pseudoDialog->spinBoxSegmentPreviewScalePercent);
//pdf preview
QRect screen = QGuiApplication::primaryScreen()->availableGeometry();
registerOption("Geometries/PdfViewerLeft", &pdfDocumentConfig->windowLeft, screen.left() + screen.width() * 2 / 3);
registerOption("Geometries/PdfViewerTop", &pdfDocumentConfig->windowTop, screen.top() + 10);
registerOption("Geometries/PdfViewerWidth", &pdfDocumentConfig->windowWidth, screen.width() / 3 - 26);
registerOption("Geometries/PdfViewerHeight", &pdfDocumentConfig->windowHeight, screen.height() - 100);
registerOption("Geometries/PdfViewerMaximized", &pdfDocumentConfig->windowMaximized, false);
registerOption("Geometries/PdfViewerState", &pdfDocumentConfig->windowState, QByteArray());
registerOption("Preview/ToolbarVisible", &pdfDocumentConfig->toolbarVisible, true);
registerOption("Preview/AnnotationPanelVisible", &pdfDocumentConfig->annotationPanelVisible, false);
registerOption("Preview/CacheSize", &pdfDocumentConfig->cacheSizeMB, 512, &pseudoDialog->spinBoxCacheSizeMB);
registerOption("Preview/LoadStrategy", &pdfDocumentConfig->loadStrategy, 2, &pseudoDialog->comboBoxPDFLoadStrategy);
registerOption("Preview/RenderBackend", &pdfDocumentConfig->renderBackend, 0, &pseudoDialog->comboBoxPDFRenderBackend);
registerOption("Preview/LimitRenderQueues", &pdfDocumentConfig->limitThreadNumber, -8); // hidden config to limit renderQueues i.e. parallel threads to render PDF. Default set numberOfThreads=qMin(8, number of cores)
#if (QT_VERSION<QT_VERSION_CHECK(6,0,0))
int dpi=QApplication::desktop()->logicalDpiX();
#else
int dpi = qRound(QGuiApplication::primaryScreen()->physicalDotsPerInch()); // main screen dpi
if (dpi < 10 || dpi > 1000)
dpi = 96;
#endif
registerOption("Preview/DPI", &pdfDocumentConfig->dpi, dpi, &pseudoDialog->spinBoxPreviewDPI);
registerOption("Preview/Scale Option", &pdfDocumentConfig->scaleOption, 1, &pseudoDialog->comboBoxPreviewScale);
registerOption("Preview/Scale", &pdfDocumentConfig->scale, 100, &pseudoDialog->spinBoxPreviewScale);
registerOption("Preview/", &pdfDocumentConfig->disableHorizontalScrollingForFitToTextWidth, true, &pseudoDialog->checkBoxDisableHorizontalScrollingForFitToTextWidth);
registerOption("Preview/ZoomStepFactor", &pdfDocumentConfig->zoomStepFactor, 1.4142135); // sqrt(2)
registerOption("Preview/Magnifier Size", &pdfDocumentConfig->magnifierSize, 300, &pseudoDialog->spinBoxPreviewMagnifierSize);
registerOption("Preview/Magnifier Shape", reinterpret_cast<int *>(&pdfDocumentConfig->magnifierShape), static_cast<int>(PDFDocumentConfig::Circle), &pseudoDialog->comboBoxPreviewMagnifierShape);
registerOption("Preview/Magnifier Shadow", &pdfDocumentConfig->magnifierShadow, true, &pseudoDialog->checkBoxPreviewMagnifierShadow);
registerOption("Preview/Magnifier Border", &pdfDocumentConfig->magnifierBorder, false, &pseudoDialog->checkBoxPreviewMagnifierBorder);
registerOption("Preview/Laser Pointer Size", &pdfDocumentConfig->laserPointerSize, 25, &pseudoDialog->spinBoxPreviewLaserPointerSize);
registerOption("Preview/Laser Pointer Color", &pdfDocumentConfig->laserPointerColor, "#FF0000", &pseudoDialog->lineEditLaserPointerColor);
registerOption("Preview/PaperColor", &pdfDocumentConfig->paperColor, "#FFFFFF", &pseudoDialog->lineEditPaperColor);
registerOption("Preview/HighlightColor", &pdfDocumentConfig->highlightColor, "#FFFF003F", &pseudoDialog->lineEditHighlightColor);
registerOption("Preview/HighlightDuration", &pdfDocumentConfig->highlightDuration, 2000, &pseudoDialog->spinBoxHighlightDuration);
registerOption("Preview/Sync File Mask", &pdfDocumentConfig->syncFileMask, "*.tex;*.tikz;*.pdf_tex;*.ctx", &pseudoDialog->lineEditPreviewSyncFileMask);
registerOption("Preview/AutoHideToolbars", &pdfDocumentConfig->autoHideToolbars, false, &pseudoDialog->autoHideToolbars);
registerOption("Preview/Auto Full Recompile", &editorConfig->fullCompilePreview, false, &pseudoDialog->autoRecompileFullDocument);
registerOption("Preview/EnlargedEmbedded", &viewerEnlarged, false);
// LogView
registerOption("LogView/WarnIfFileSizeLargerMB", &logViewWarnIfFileSizeLargerMB, 2.0);
registerOption("LogView/RememberChoiceLargeFile", &logViewRememberChoice, 0);
#ifndef QT_NO_DEBUG
registerOption("Debug/Last Application Modification", &debugLastFileModification);
registerOption("Debug/Last Full Test Run", &debugLastFullTestRun);
#endif
// runaway limit for lexing
registerOption("Editor/RUNAWAYLIMIT", &RUNAWAYLIMIT , 30);
}
ConfigManager::~ConfigManager()
{
delete editorConfig;
delete completerConfig;
delete webPublishDialogConfig;
delete insertGraphicsConfig;
delete persistentConfig;
delete terminalConfig;
globalConfigManager = nullptr;
}
QString ConfigManager::iniPath()
{
if (!persistentConfig) {
QString configDir = configDirOverride;
if (configDir.isEmpty()) configDir = portableConfigDir();
return configDir + "/texstudio.ini";
}
return configFileName;
}
QString ConfigManager::portableConfigDir()
{
return QCoreApplication::applicationDirPath() + "/config";
}
bool ConfigManager::isPortableMode()
{
return (QDir(portableConfigDir()).exists() || !configDirOverride.isEmpty());
}
/*!
* Returns a QSettings instance tor the location in which current settings are / should be stored.
*/
QSettings *ConfigManager::newQSettings()
{
if (isPortableMode()) {
return new QSettings(iniPath(), QSettings::IniFormat);
} else {
return new QSettings(QSettings::IniFormat, QSettings::UserScope, "texstudio", "texstudio");
}
}
QSettings *ConfigManager::readSettings(bool reread)
{
//load config
QSettings *config = persistentConfig;
bool portableMode = isPortableMode();
if (!config) {
config = newQSettings();
configFileName = config->fileName();
configFileNameBase = configFileName;
configBaseDir = ensureTrailingDirSeparator(QFileInfo(configFileName).absolutePath());
completerConfig->importedCwlBaseDir = configBaseDir; // set in LatexCompleterConfig to get access from LatexDocument
if (configFileNameBase.endsWith(".ini")) configFileNameBase = configFileNameBase.replace(QString(".ini"), "");
persistentConfig = config;
setupDirectoryStructure();
moveCwls();
}
if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) && (config->value("version/written_by_Qt_version").toInt()) < QT_VERSION_CHECK(5, 9, 0)) {
// workaround for bug 2175: crash when loading some old config that was created with Qt < 5.9 and now reading with Qt 5.9.
// Likely a Qt bug because restoreState() should simply.
// return false for invalid input. Assuming that some change in the layout of the splitter is incompatible with
// a previous state. We don't know exactly what this caused and it's not worth digging into this. Therefore we just
// reset this option when loading any old config.
config->remove("texmaker/centralVSplitterState");
}
config->beginGroup("texmaker");
if (config->contains("Files/Auto Detect Encoding Of Loaded Files")) { // import old setting
bool b = config->value("Files/Auto Detect Encoding Of Loaded Files").toBool();
if (!config->contains("Files/AutoDetectEncodingFromChars")) config->setValue("Files/AutoDetectEncodingFromChars", b);
if (!config->contains("Files/AutoDetectEncodingFromLatex")) config->setValue("Files/AutoDetectEncodingFromLatex", b);
config->remove("Files/Auto Detect Encoding Of Loaded Files");
}
//----------managed properties--------------------
for (int i = 0; i < managedProperties.size(); i++)
managedProperties[i].valueFromQVariant(config->value(managedProperties[i].name, managedProperties[i].def));
//language
appTranslator = new QTranslator(this);
basicTranslator = new QTranslator(this);
loadTranslations(language);
QCoreApplication::installTranslator(appTranslator);
QCoreApplication::installTranslator(basicTranslator);
//------------------files--------------------
newFileEncoding = QTextCodec::codecForName(newFileEncodingName.toLatin1().data());
//----------------------------dictionaries-------------------------
if (spellDictDir.isEmpty()) {
// non-existent or invalid settings for dictionary
// try restore from old format where there was only one dictionary - spell_dic can be removed later when users have migrated to the new version
QString dic = spell_dic;
if (!QFileInfo::exists(dic)) {
// fallback to defaults
QStringList temp;
QStringList fallBackPaths;
#ifdef Q_OS_WIN32
fallBackPaths << parseDir("[txs-settings-dir]/dictionaries") << parseDir("[txs-app-dir]/dictionaries");
#endif
#ifndef Q_OS_WIN32
#ifndef PREFIX
#define PREFIX
#endif
fallBackPaths << PREFIX"/share/hunspell" << PREFIX"/share/myspell"
<< "/usr/share/hunspell" << "/usr/share/myspell"
<< parseDir("[txs-app-dir]/../share/texstudio") ;
#endif
#ifdef Q_OS_MAC
fallBackPaths << parseDir("[txs-app-dir]/../Resources") << "/Applications/texstudio.app/Contents/Resources";
#endif
dic = findResourceFile(QString(QLocale::system().name()) + ".dic", true, temp, fallBackPaths);
if (dic == "") dic = findResourceFile("en_US.dic", true, temp, fallBackPaths);
if (dic == "") dic = findResourceFile("en_GB.dic", true, temp, fallBackPaths);
if (dic == "") dic = findResourceFile("fr_FR.dic", true, temp, fallBackPaths);
if (dic == "") dic = findResourceFile("de_DE.dic", true, temp, fallBackPaths);
}
QFileInfo fi(dic);
if (fi.exists()) {
spellDictDir = QDir::toNativeSeparators(fi.absolutePath());
if (portableMode) {
spellDictDir = reverseParseDir(spellDictDir);
}
spellLanguage = fi.baseName();
}
}
if (grammarCheckerConfig->wordlistsDir.isEmpty()) {
QString sw = findResourceFile("de.stopWords", true, QStringList(), parseDirList(spellDictDir));
if (sw == "") sw = findResourceFile("en.stopWords", true, QStringList(), QStringList() << parseDirList(spellDictDir));
if (QFileInfo::exists(sw)) grammarCheckerConfig->wordlistsDir = QDir::toNativeSeparators(QFileInfo(sw).absolutePath());
}
if (thesaurus_database == "<dic not found>") {
thesaurus_database = "";
}
if (thesaurus_database != "") {
QFileInfo fi(parseDir(thesaurus_database));
if (!fi.exists()) { // try finding the file in other directories (e.g. after update tmx->txs
thesaurus_database = findResourceFile(fi.fileName(), true, QStringList(), QStringList() << parseDir(thesaurus_database));
}
}
if (thesaurus_database == "") { // fall back to system or fixed language
QStringList preferredPaths = QStringList() << parseDir("[txs-settings-dir]/dictionaries");
QStringList fallBackPaths;
#ifdef Q_OS_LINUX
fallBackPaths << PREFIX"/share/mythes" << "/usr/share/mythes"
<< parseDir("[txs-app-dir]/../share/texstudio") ;
#endif
thesaurus_database = findResourceFile("th_" + QString(QLocale::system().name()) + "_v2.dat", true, preferredPaths, fallBackPaths);
if (thesaurus_database == "") thesaurus_database = findResourceFile("th_en_US_v2.dat", true, preferredPaths, fallBackPaths);
if (thesaurus_database == "") thesaurus_database = findResourceFile("th_en_GB_v2.dat", true, preferredPaths, fallBackPaths);
if (thesaurus_database == "") thesaurus_database = findResourceFile("th_fr_FR_v2.dat", true, preferredPaths, fallBackPaths);
if (thesaurus_database == "") thesaurus_database = findResourceFile("th_de_DE_v2.dat", true, preferredPaths, fallBackPaths);
}
if (!thesaurus_database.isEmpty()) {
if (portableMode) {
thesaurus_database = reverseParseDir(thesaurus_database);
}
thesaurus_database = QDir::toNativeSeparators(thesaurus_database);
}
//----------------------------editor--------------------
//completion
QStringList cwlFiles = config->value("Editor/Completion Files", QStringList() << "tex.cwl" << "latex-document.cwl" << "latex-dev.cwl").toStringList();
//completerConfig->words=loadCwlFiles(cwlFiles,ltxCommands,completerConfig);
LatexParser &latexParser = LatexParser::getInstance();
// read usageCount from file of its own.
// needs to be done before reading cwl files
if (!reread) {
QFile file(configBaseDir + "wordCount.usage");
if (file.open(QIODevice::ReadOnly)) {
QDataStream in(&file);
quint32 magicNumer, version;
in >> magicNumer >> version;
if (magicNumer == static_cast<quint32>(0xA0B0C0D0) && version == 1) {
in.setVersion(QDataStream::Qt_4_0);
uint key;
int length, usage;
completerConfig->usage.clear();
while (!in.atEnd()) {
in >> key >> length >> usage;
if (usage > 0) {
completerConfig->usage.insert(key, qMakePair(length, usage));
}
}
}
}
}
completerConfig->words.clear();
QSet<QString>loadedFiles;
QStringList tobeLoaded=cwlFiles;
//foreach (const QString &cwlFile, cwlFiles) {
while(!tobeLoaded.isEmpty()){
QString cwlFile=tobeLoaded.takeFirst();
if(loadedFiles.contains(cwlFile))
continue;
loadedFiles.insert(cwlFile);
LatexPackage pck = loadCwlFile(cwlFile, completerConfig);
tobeLoaded.append(pck.requiredPackages);