-
-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathdlgTriggerEditor.cpp
More file actions
15045 lines (13340 loc) · 628 KB
/
dlgTriggerEditor.cpp
File metadata and controls
15045 lines (13340 loc) · 628 KB
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
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2014-2024 by Stephen Lyons - slysven@virginmedia.com *
* Copyright (C) 2016 by Owen Davison - odavison@cs.dal.ca *
* Copyright (C) 2016-2020 by Ian Adkins - ieadkins@gmail.com *
* Copyright (C) 2017 by Tom Scheper - scheper@gmail.com *
* Copyright (C) 2023-2025 by Lecker Kebap - Leris@mudlet.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "dlgTriggerEditor.h"
#include "Host.h"
#include "LuaInterface.h"
#include "TConsole.h"
#include "TDebug.h"
#include "TEasyButtonBar.h"
#include "TTextEdit.h"
#include "TToolBar.h"
#include "VarUnit.h"
#include "XMLimport.h"
#include "XMLexport.h"
#include "dlgActionMainArea.h"
#include "dlgAliasMainArea.h"
#include "dlgColorTrigger.h"
#include "dlgKeysMainArea.h"
#include "dlgPackageExporter.h"
#include "dlgProfilePreferences.h"
#include "dlgScriptsMainArea.h"
#include "dlgTriggerPatternEdit.h"
#include "SingleLineTextEdit.h"
#include "TrailingWhitespaceMarker.h"
#include "EditorAddItemCommand.h"
#include "EditorDeleteItemCommand.h"
#include "EditorItemXMLHelpers.h"
#include "EditorModifyPropertyCommand.h"
#include "EditorMoveItemCommand.h"
#include "EditorToggleActiveCommand.h"
#include "mudlet.h"
#include "utils.h"
#include "edbee/models/textdocumentscopes.h"
#include <QCheckBox>
#include <QAbstractButton>
#include <QColorDialog>
#include <QDialogButtonBox>
#include <QFileDialog>
#include <QFont>
#include <QFrame>
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
#include <QMessageBox>
#include <QMetaEnum>
#include <QPalette>
#include <QScrollBar>
#include <QShortcut>
#include <QSpinBox>
#include <QStyle>
#include <QTextCursor>
#include <QShowEvent>
#include <QRegularExpression>
#include <QToolButton>
#include <QToolBar>
#include <sstream>
#include <pugixml.hpp>
#include <QVBoxLayout>
// Forward declaration for undo/redo test suite (implemented in test/dlgTriggerEditorUndoRedoTest.cpp)
void runUndoRedoTestSuite(dlgTriggerEditor* editor);
// Forward declaration for per-property undo helper (defined later in this file)
static void pushKeyPropertyCommand(EditorUndoStack* undoStack, Host* host, int keyID, const QString& keyName, const QString& propertyName, const QString& oldStateXML, const QString& newStateXML);
using namespace std::chrono_literals;
// Used as a QObject::property so that we can keep track of the color for the
// trigger colorizer buttons loaded from a trigger even if the user disables
// and then reenables the colorizer function (and we "grey out" the color while
// it is disabled):
static const char* cButtonBaseColor = "baseColor";
// Track whether the shared auto-complete provider has been initialized
bool dlgTriggerEditor::smAutoCompleteInitialized = false;
dlgTriggerEditor::dlgTriggerEditor(Host* pH)
: mpHost(pH)
, mSearchOptions(pH->mSearchOptions)
{
// init generated dialog
setupUi(this);
// clang-format off
introAddItem.insert(EditorViewType::cmAliasView, {
//: Headline for the Alias intro
tr("Alias react on user input."), {
//: Name of a selectable option for the Alias intro
{qsl("alias1"), tr("How to add a new alias now"),
//: Help contents of a selectable option for the Alias intro
tr("<ol><li>Click on the 'Add Item' icon above.</li>"
"<li>Define an input <strong>pattern</strong> either literally or with a Perl regular expression.</li>"
"<li>Define a 'substitution' <strong>command</strong> to send to the game in clear text <strong>instead of the alias pattern</strong>, or write a script for more complicated needs.</li>"
"<li><strong>Activate</strong> the alias.</li></ol>")},
//: Name of a selectable option for the Alias intro
{qsl("alias2"), tr("How to add a new alias from the input line"),
qsl("%1%2%3%4").arg(
//: Help contents of a selectable option for the Alias intro
qsl("<p>%1</p>").arg(tr("There are a <a href='https://forums.mudlet.org/viewtopic.php?f=6&t=22609'>couple</a> of <a href='https://forums.mudlet.org/viewtopic.php?f=6&t=16462'>packages</a> that can help you.")),
//: Part of the Alias intro - This introductory text will be followed by a Lua code example for a trigger.
qsl("<p>%1</p>").arg(tr("Alias can also be defined from the input line in the main profile window like this:")),
qsl("<p><code>%1</code></p>").arg(qsl("lua permAlias("%1", "", "%2", function() send("%3") echo("%4") end)").arg(
//: Part of the Alias intro, code example for an alias - This is the name of the alias which reacts on the player typing "hi" by saying "Greetings, traveller!" in game.
tr("My greetings"),
//: Part of the Alias intro, code example for an alias - This is the text input from the player which will be reacted on by saying "Greetings, traveller!" in game.
tr("hi"),
//: Part of the Alias intro, code example for an alias - This is the command that Mudlet will send to the game after the player typed "hi".
tr("say Greetings, traveller!"),
//: Part of the Alias intro, code example for an alias - This is the confirmation text shown to the player after they typed "hi" and we said "Greetings, traveller!" in game.
tr("We said hi!"))),
//: Part of the Alias intro - This is the conclusion after the code example for an alias which reacts on the player typing "hi" by saying "Greetings, traveller!" in game.
qsl("<p>%1</p>").arg("You can now greet by typing 'hi'"))},
{qsl("alias3"), tr("Where to find more information"),
qsl("<ul>%1%2%3%4</ul>").arg( // reduce clutter for translators
qsl("<li><p>%1</p><li>").arg(tr("Watch a <a href='%1'>video demonstration</a> of the basic functionality.")
.arg(qsl("https://youtu.be/Uz6EDvZYNvE"))),
qsl("<li><p>%1</p></li>").arg(tr("Read the <a href='http://wiki.mudlet.org/w/Manual:Introduction#Aliases'>Introduction to Aliases</a> for a detailed overview.")),
qsl("<li><p>%1</p>").arg(tr("Do you maybe have any other suggestions, questions or doubts?")),
qsl("<p>%1</p></li>").arg(tr("Join our community on <a href='https://www.mudlet.org/chat'>Discord</a> or in <a href='https://forums.mudlet.org/'>Mudlet forums</a> - See you there!")))}}});
introAddItem.insert(EditorViewType::cmTriggerView, {
//: Headline for the Trigger intro
tr("Triggers react on game output."), {
//: Name of a selectable option for the Trigger intro
{qsl("trigger1"), tr("How to add a new trigger now"),
//: Help contents of a selectable option for the Trigger intro
tr("<ol><li>Click on the 'Add Item' icon above.</li>"
"<li>Define a <strong>pattern</strong> that you want to trigger on.</li>"
"<li>Select the appropriate pattern <strong>type</strong>.</li>"
"<li>Define a clear text <strong>command</strong> that you want to send to the game if the trigger finds the pattern in the text from the game, or write a script for more complicated needs..</li>"
"<li><strong>Activate</strong> the trigger.</li></ol>")},
//: Name of a selectable option for the Trigger intro
{qsl("trigger2"), tr("How to add a new trigger from the input line"),
qsl("%1%2%3%4").arg(
//: Help contents of a selectable option for the Trigger intro
qsl("<p>%1</p>").arg(tr("There are a <a href='https://forums.mudlet.org/viewtopic.php?f=6&t=22609'>couple</a> of <a href='https://forums.mudlet.org/viewtopic.php?f=6&t=16462'>packages</a> that can help you.")),
//: Part of the Trigger intro - This introductory text will be followed by a Lua code example for a trigger.
qsl("<p>%1</p>").arg(tr("Triggers can also be defined from the input line in the main profile window like this:")),
qsl("<p><code>%1</code></p>").arg(qsl("lua permSubstringTrigger("%1", "", "%2", function() send("%3") end)").arg(
//: Part of the Trigger intro, code example for a trigger - This is the name of the trigger which reacts on "You are thirsty" with "drink water".
tr("My drink trigger"),
//: Part of the Trigger intro, code example for a trigger - This is the text from game which will be triggered on, and reacted to with "drink water".
tr("You are thirsty."),
//: Part of the Trigger intro, code example for a trigger - This is the command sent to game after we triggered on text "You are thirsty." from game.
tr("drink water"))),
//: Part of the Trigger intro - This is the conclusion after the code example for a trigger which reacts on "You are thirsty" with "drink water".
qsl("<p>%1</p>").arg("This will keep you refreshed."))},
{qsl("trigger3"), tr("Where to find more information"),
qsl("<ul>%1%2%3%4</ul>").arg( // reduce clutter for translators
qsl("<li><p>%1</p><li>").arg(tr("Watch a <a href='%1'>video demonstration</a> of the basic functionality.")
.arg(qsl("https://youtu.be/jYjop54-Y3I"))),
qsl("<li><p>%1</p></li>").arg(tr("Read the <a href='http://wiki.mudlet.org/w/Manual:Introduction#Triggers'>Introduction to Triggers</a> for a detailed overview.")),
qsl("<li><p>%1</p>").arg(tr("Do you maybe have any other suggestions, questions or doubts?")),
qsl("<p>%1</p></li>").arg(tr("Join our community on <a href='https://www.mudlet.org/chat'>Discord</a> or in <a href='https://forums.mudlet.org/'>Mudlet forums</a> - See you there!")))}}});
introAddItem.insert(EditorViewType::cmScriptView, {
//: Headline for the Script intro
tr("Scripts organize code and can react to events."), {
//: Name of a selectable option for the Script intro
{qsl("script1"), tr("How to add a new script now"),
//: Help contents of a selectable option for the Script intro
tr("<ol><li>Click on the 'Add Item' icon above.</li>"
"<li>Enter a script in the box below. You can for example define <strong>functions</strong> to be called by other triggers, aliases, etc.</li>"
"<li>If you write lua <strong>commands</strong> without defining a function, they will be run on Mudlet startup and each time you open the script for editing.</li>"
"<li><strong>Activate</strong> the script.</li></ol>"
"<p><strong>Note:</strong> Scripts are run automatically when viewed, even if they are deactivated.</p>")},
//: Name of a selectable option for the Script intro
{qsl("script2"), tr("How to have a script react to events"),
//: Help contents of a selectable option for the Script intro
tr("<p>You can register a list of <strong>events</strong> with the + and - symbols. If one of these events take place, the function with the same name as the script item itself will be called.</p>"
"<p><strong>Note:</strong> Events can also be added to a script from the command line in the main profile window like this:</p>"
"<p><code>lua registerAnonymousEventHandler("nameOfTheMudletEvent", "nameOfYourFunctionToBeCalled")</code></p>")},
{qsl("script3"), tr("Where to find more information"),
qsl("<ul>%1%2%3%4</ul>").arg( // reduce clutter for translators
qsl("<li><p>%1</p><li>").arg(tr("Watch a <a href='%1'>video demonstration</a> of the basic functionality.")
.arg(qsl("https://youtu.be/10mJUh4Hq-A"))),
qsl("<li><p>%1</p></li>").arg(tr("Read the <a href='http://wiki.mudlet.org/w/Manual:Introduction#Scripts'>Introduction to Scripts</a> for a detailed overview.")),
qsl("<li><p>%1</p>").arg(tr("Do you maybe have any other suggestions, questions or doubts?")),
qsl("<p>%1</p></li>").arg(tr("Join our community on <a href='https://www.mudlet.org/chat'>Discord</a> or in <a href='https://forums.mudlet.org/'>Mudlet forums</a> - See you there!")))}}});
introAddItem.insert(EditorViewType::cmTimerView, {
//: Headline for the Timer intro
tr("Timers react after a timespan once or regularly."), {
//: Name of a selectable option for the Timer intro
{qsl("timer1"), tr("How to add a new timer now"),
//: Help contents of a selectable option for the Timer intro
tr("<ol><li>Click on the 'Add Item' icon above.</li>"
"<li>Define the <strong>timespan</strong> after which the timer should react in a this format: hours : minutes : seconds.</li>"
"<li>Define a clear text <strong>command</strong> that you want to send to the game when the time has passed, or write a script for more complicated needs.</li>"
"<li><strong>Activate</strong> the timer.</li></ol>"
"<p><strong>Note:</strong> If you want the trigger to react only once and not regularly, use the Lua tempTimer() function instead.</p>")},
//: Name of a selectable option for the Timer intro
{qsl("timer2"), tr("How to add a new timer from the input line"),
//: Help contents of a selectable option for the Timer intro
tr("<p>Timers can also be defined from the input line in the main profile window like this:</p>"
"<p><code>lua tempTimer(3, function() echo("hello!\n") end)</code></p>"
"<p>This will greet you exactly 3 seconds after it was made.</p>")},
{qsl("timer3"), tr("Where to find more information"),
qsl("<ul>%1%2%3</ul>").arg( // reduce clutter for translators
qsl("<li><p>%1</p></li>").arg(tr("Read the <a href='http://wiki.mudlet.org/w/Manual:Introduction#Timers'>Introduction to Timers</a> for a detailed overview.")),
qsl("<li><p>%1</p>").arg(tr("Do you maybe have any other suggestions, questions or doubts?")),
qsl("<p>%1</p></li>").arg(tr("Join our community on <a href='https://www.mudlet.org/chat'>Discord</a> or in <a href='https://forums.mudlet.org/'>Mudlet forums</a> - See you there!")))}}});
introAddItem.insert(EditorViewType::cmActionView, {
//: Headline for the Button intro
tr("Buttons react on mouse clicks."), {
//: Name of a selectable option for the Button intro
{qsl("button1"), tr("How to add a new button now"),
//: Help contents of a selectable option for the Button intro
tr("<ol><li>Add a new group to define a new <strong>button bar</strong> in case you don't have any.</li>"
"<li>Add new groups as <strong>menus</strong> to a button bar or sub-menus to menus.<li>"
"<li>Add new items as <strong>buttons</strong> to a button bar or menu or sub-menu.</li>"
"<li>Define a clear text <strong>command</strong> that you want to send to the game if the button is pressed, or write a script for more complicated needs.</li>"
"<li><strong>Activate</strong> the toolbar, menu or button. </li></ol>"
"<p><strong>Note:</strong> Deactivated items will be hidden and if they are toolbars or menus then all the items they contain will be also be hidden.</p>"
"<p><strong>Note:</strong> If a button is made a <strong>click-down</strong> button then you may also define a clear text command that you want to send to the game when the button is pressed a second time to uncheck it or to write a script to run when it happens - within such a script the Lua 'getButtonState()' function reports whether the button is up or down.</p>")},
// {qsl("button2"), tr("How to add a new button from the input line"),
// tr("")},
{qsl("button3"), tr("Where to find more information"),
qsl("<ul>%1%2%3</ul>").arg( // reduce clutter for translators
qsl("<li><p>%1</p></li>").arg(tr("Read the <a href='http://wiki.mudlet.org/w/Manual:Introduction#Buttons'>Introduction to Buttons</a> for a detailed overview.")),
qsl("<li><p>%1</p>").arg(tr("Do you maybe have any other suggestions, questions or doubts?")),
qsl("<p>%1</p></li>").arg(tr("Join our community on <a href='https://www.mudlet.org/chat'>Discord</a> or in <a href='https://forums.mudlet.org/'>Mudlet forums</a> - See you there!")))}}});
introAddItem.insert(EditorViewType::cmKeysView, {
//: Headline for the Keys intro
tr("Keys react on keyboard presses."), {
//: Name of a selectable option for the Keys intro
{qsl("key1"), tr("How to add a new keybinding now"),
//: Help contents of a selectable option for the Keys intro
tr("<ol><li>Click on the 'Add Item' icon above.</li>"
"<li>Click on <strong>'grab key'</strong> and then press your key combination, e.g. including modifier keys like Control, Shift, etc.</li>"
"<li>Define a clear text <strong>command</strong> that you want to send to the game if the button is pressed, or write a script for more complicated needs.</li>"
"<li><strong>Activate</strong> the new key binding.</li></ol>")},
//: Name of a selectable option for the Keys intro
{qsl("key2"), tr("How to add a new keybinding from the input line"),
//: Help contents of a selectable option for the Keys intro
tr("<p>Keys can be defined from the input line in the main profile window like this:</p>"
"<p><code>lua permKey("my jump key", "", mudlet.key.F8, [[send("jump"]]) end)</code></p>"
"<p>Pressing F8 will make you jump.</p>")},
{qsl("key3"), tr("Where to find more information"),
qsl("<ul>%1%2%3%4</ul>").arg( // reduce clutter for translators
qsl("<li><p>%1</p><li>").arg(tr("Watch a <a href='%1'>video demonstration</a> of the basic functionality.")
.arg(qsl("https://youtu.be/ZYRPZ-8fJWA"))),
qsl("<li><p>%1</p></li>").arg(tr("Read the <a href='http://wiki.mudlet.org/w/Manual:Introduction#Keybindings'>Introduction to Keybindings</a> for a detailed overview.")),
qsl("<li><p>%1</p>").arg(tr("Do you maybe have any other suggestions, questions or doubts?")),
qsl("<p>%1</p></li>").arg(tr("Join our community on <a href='https://www.mudlet.org/chat'>Discord</a> or in <a href='https://forums.mudlet.org/'>Mudlet forums</a> - See you there!")))}}});
introAddItem.insert(EditorViewType::cmVarsView, {
//: Headline for the Variable intro
tr("Variables store information."), {
//: Name of a selectable option for the Variable intro
{qsl("variable1"), tr("How to add a new variable now"),
//: Help contents of a selectable option for the Variable intro
tr("<ol><li>Click on the 'Add Item' icon above. To add a table instead click 'Add Group'.</li>"
"<li>Select type of variable value (can be a string, integer, boolean)</li>"
"<li>Enter the value you want to store in this variable.</li>"
"<li>If you want to keep the variable in your next Mudlet sessions, check the checkbox in the list of variables to the left.</li>"
"<li>To remove a variable manually, set it to 'nil' or click on the 'Delete' icon above.</li></ol>"
"<p><strong>Note:</strong> Variables created here won't be saved when Mudlet shuts down unless you check their checkbox in the list of variables to the left. You could also create scripts with the variables instead.</p>")},
//: Name of a selectable option for the Variable intro
{qsl("variable2"), tr("How to add a new variable from the input line"),
//: Help contents of a selectable option for the Variable intro
tr("<p>Variables and tables can also be defined from the input line in the main profile window like this:</p>"
"<p><code>lua foo = "bar"</code></p>"
"<p>This will create a string called 'foo' with 'bar' as its value.</p>")},
{qsl("variable3"), tr("Where to find more information"),
qsl("<ul>%1%2%3</ul>").arg( // reduce clutter for translators
qsl("<li><p>%1</p></li>").arg(tr("Read the <a href='http://wiki.mudlet.org/w/Manual:Introduction#Variables'>Introduction to Variables</a> for a detailed overview.")),
qsl("<li><p>%1</p>").arg(tr("Do you maybe have any other suggestions, questions or doubts?")),
qsl("<p>%1</p></li>").arg(tr("Join our community on <a href='https://www.mudlet.org/chat'>Discord</a> or in <a href='https://forums.mudlet.org/'>Mudlet forums</a> - See you there!")))}}});
// clang-format on
// Descriptions for screen readers, clarify to translators that the context of "activated" is current status and not confirmation of toggle.
//: Item is currently on, short enough to be spoken
descActive = tr("activated");
//: Item is currently off, short enough to be spoken
descInactive = tr("deactivated");
//: Folder is currently turned on
descActiveFolder = tr("activated folder");
//: Folder is currently turned off
descInactiveFolder = tr("deactivated folder");
//: Item is currently inactive because of errors, short enough to be spoken
descError = tr("deactivated due to error");
//: Item is currently turned on individually, but is member of an inactive group
descInactiveParent = tr("%1 in a deactivated group");
//: A trigger that unlocks other triggers is currently turned on, short enough to be spoken
descActiveFilterChain = tr("activated filter chain");
//: A trigger that unlocks other triggers is currently turned off, short enough to be spoken
descInactiveFilterChain = tr("deactivated filter chain");
//: A timer that starts after another timer is currently turned on
descActiveOffsetTimer = tr("activated offset timer");
//: A timer that starts after another timer is currently turned off
descInactiveOffsetTimer = tr("deactivated offset timer");
//: Accessible description for a newly created folder, shown after the folder name
descNewFolder = tr("new folder");
//: Accessible description for a newly created item, shown after the item name
descNewItem = tr("new item");
//: Accessible description indicating an item belongs to a package, shown after the item name. Keep short, as it's appended to other descriptions like "activated, package item"
descPackageItem = tr("package item");
setUnifiedTitleAndToolBarOnMac(true); //MAC OSX: make window moveable
const QString hostName{mpHost->getName()};
setWindowTitle(tr("%1 - Editor").arg(hostName));
setWindowIcon(QIcon(qsl(":/icons/mudlet_editor.png")));
auto statusBar = new QStatusBar(this);
statusBar->setSizeGripEnabled(true);
setStatusBar(statusBar);
statusBar->show();
mpNonCodeWidgets = new QWidget(this);
auto* layoutColumn = new QVBoxLayout(mpNonCodeWidgets);
splitter_right->addWidget(mpNonCodeWidgets);
// system message area
mpSystemMessageArea = new dlgSystemMessageArea(this);
mpSystemMessageArea->setObjectName(qsl("mpSystemMessageArea"));
mpSystemMessageArea->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Minimum);
// set the stretch factor of the message area to 0 and everything else to 1,
// so our errors box doesn't stretch to produce a grey area
layoutColumn->addWidget(mpSystemMessageArea, 0);
connect(mpSystemMessageArea->messageAreaCloseButton, &QAbstractButton::clicked, this, &dlgTriggerEditor::hideSystemMessageArea);
connect(mpSystemMessageArea->notificationAreaMessageBox, &QLabel::linkActivated, this, &dlgTriggerEditor::slot_clickedMessageBox);
// main areas
mpTriggersMainArea = new dlgTriggersMainArea(this);
layoutColumn->addWidget(mpTriggersMainArea, 1);
connect(mpTriggersMainArea->pushButtonFgColor, &QAbstractButton::clicked, this, &dlgTriggerEditor::slot_colorizeTriggerSetFgColor);
connect(mpTriggersMainArea->pushButtonBgColor, &QAbstractButton::clicked, this, &dlgTriggerEditor::slot_colorizeTriggerSetBgColor);
connect(mpTriggersMainArea->pushButtonSound, &QAbstractButton::clicked, this, &dlgTriggerEditor::slot_soundTrigger);
connect(mpTriggersMainArea->groupBox_triggerColorizer, &QGroupBox::clicked, this, &dlgTriggerEditor::slot_toggleGroupBoxColorizeTrigger);
connect(mpTriggersMainArea->toolButton_clearSoundFile, &QAbstractButton::clicked, this, &dlgTriggerEditor::slot_clearSoundFile);
mpTimersMainArea = new dlgTimersMainArea(this);
layoutColumn->addWidget(mpTimersMainArea, 1);
mpAliasMainArea = new dlgAliasMainArea(this);
layoutColumn->addWidget(mpAliasMainArea, 1);
mpActionsMainArea = new dlgActionMainArea(this);
layoutColumn->addWidget(mpActionsMainArea, 1);
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
connect(mpActionsMainArea->checkBox_action_button_isPushDown, &QCheckBox::checkStateChanged, this, &dlgTriggerEditor::slot_toggleIsPushDownButton);
#else
connect(mpActionsMainArea->checkBox_action_button_isPushDown, &QCheckBox::stateChanged, this, &dlgTriggerEditor::slot_toggleIsPushDownButton);
#endif
mpKeysMainArea = new dlgKeysMainArea(this);
layoutColumn->addWidget(mpKeysMainArea, 1);
connect(mpKeysMainArea->pushButton_key_grabKey, &QAbstractButton::clicked, this, &dlgTriggerEditor::slot_keyGrab);
mpVarsMainArea = new dlgVarsMainArea(this);
layoutColumn->addWidget(mpVarsMainArea, 1);
mpScriptsMainArea = new dlgScriptsMainArea(this);
layoutColumn->addWidget(mpScriptsMainArea, 1);
connect(mpScriptsMainArea->lineEdit_script_event_handler_entry, &QLineEdit::returnPressed, this, &dlgTriggerEditor::slot_scriptMainAreaAddHandler);
connect(mpScriptsMainArea->listWidget_script_registered_event_handlers, &QListWidget::itemSelectionChanged, this, &dlgTriggerEditor::slot_scriptMainAreaEditHandler);
connect(mpScriptsMainArea->listWidget_script_registered_event_handlers, &QListWidget::itemActivated, this, &dlgTriggerEditor::slot_scriptMainAreaClearHandlerSelection);
// source editor area
mpSourceEditorArea = new dlgSourceEditorArea(this);
splitter_right->addWidget(mpSourceEditorArea);
// And the edbee widget
mpSourceEditorEdbee = mpSourceEditorArea->edbeeEditorWidget;
mpSourceEditorEdbee->setAutoScrollMargin(20);
mpSourceEditorEdbee->setPlaceholderText(tr("-- add your Lua code here"));
mpSourceEditorEdbeeDocument = mpSourceEditorEdbee->textDocument();
// Update the status bar on changes
connect(mpSourceEditorEdbee->controller(), &edbee::TextEditorController::updateStatusTextSignal, this, &dlgTriggerEditor::slot_updateStatusBar);
mpSourceEditorEdbee->controller()->setAutoScrollToCaret(edbee::TextEditorController::AutoScrollWhenFocus);
// Update the editor preferences
connect(mudlet::self(), &mudlet::signal_editorTextOptionsChanged, this, &dlgTriggerEditor::slot_changeEditorTextOptions);
mudlet::loadEdbeeTheme(mpHost->mEditorTheme, mpHost->mEditorThemeFile);
// edbee editor find area
mpSourceEditorFindArea = new dlgSourceEditorFindArea(mpSourceEditorEdbee);
mpSourceEditorEdbee->horizontalScrollBar()->installEventFilter(mpSourceEditorFindArea);
mpSourceEditorEdbee->verticalScrollBar()->installEventFilter(mpSourceEditorFindArea);
mpSourceEditorFindArea->hide();
connect(mpSourceEditorFindArea->lineEdit_findText, &QLineEdit::textChanged, this, &dlgTriggerEditor::slot_sourceFindTextChanges);
connect(mpSourceEditorFindArea, &dlgSourceEditorFindArea::signal_sourceEditorMovementNecessary, this, &dlgTriggerEditor::slot_sourceFindMove);
connect(mpSourceEditorFindArea->pushButton_findPrevious, &QPushButton::clicked, this, &dlgTriggerEditor::slot_sourceFindPrevious);
connect(mpSourceEditorFindArea->pushButton_findNext, &QPushButton::clicked, this, &dlgTriggerEditor::slot_sourceFindNext);
connect(mpSourceEditorFindArea->pushButton_replace, &QPushButton::clicked, this, &dlgTriggerEditor::slot_sourceReplace);
connect(mpSourceEditorFindArea, &dlgSourceEditorFindArea::signal_sourceEditorFindPrevious, this, &dlgTriggerEditor::slot_sourceFindPrevious);
connect(mpSourceEditorFindArea, &dlgSourceEditorFindArea::signal_sourceEditorFindNext, this, &dlgTriggerEditor::slot_sourceFindNext);
connect(mpSourceEditorFindArea, &dlgSourceEditorFindArea::signal_sourceEditorReplace, this, &dlgTriggerEditor::slot_sourceReplace);
connect(mpSourceEditorFindArea->pushButton_close, &QPushButton::clicked, this, &dlgTriggerEditor::slot_closeSourceFind);
auto openSourceFindAction = new QAction(this);
openSourceFindAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
openSourceFindAction->setShortcut(QKeySequence(QKeySequence::Find));
mpSourceEditorArea->addAction(openSourceFindAction);
connect(openSourceFindAction, &QAction::triggered, this, &dlgTriggerEditor::slot_openSourceFind);
QAction* closeSourceFindAction = new QAction(this);
closeSourceFindAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
closeSourceFindAction->setShortcut(QKeySequence(QKeySequence::Cancel));
mpSourceEditorArea->addAction(closeSourceFindAction);
connect(closeSourceFindAction, &QAction::triggered, this, &dlgTriggerEditor::slot_closeSourceFind);
QAction* sourceFindNextAction = new QAction(this);
sourceFindNextAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
sourceFindNextAction->setShortcut(QKeySequence(QKeySequence::FindNext));
mpSourceEditorArea->addAction(sourceFindNextAction);
connect(sourceFindNextAction, &QAction::triggered, this, &dlgTriggerEditor::slot_sourceFindNext);
QAction* sourceFindPreviousAction = new QAction(this);
sourceFindPreviousAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
sourceFindPreviousAction->setShortcut(QKeySequence(QKeySequence::FindPrevious));
mpSourceEditorArea->addAction(sourceFindPreviousAction);
connect(sourceFindPreviousAction, &QAction::triggered, this, &dlgTriggerEditor::slot_sourceFindPrevious);
mpUndoStack = new EditorUndoStack(this);
mpUndoStack->setUndoLimit(50);
// These route to either text editor or item operations based on focus
mpUndoAction = new QAction(QIcon::fromTheme(qsl("edit-undo"), QIcon(qsl(":/icons/edit-undo.png"))), tr("Undo"), this);
mpUndoAction->setShortcut(QKeySequence(QKeySequence::Undo)); // Ctrl+Z
mpUndoAction->setShortcutContext(Qt::WindowShortcut);
mpUndoAction->setEnabled(false);
this->addAction(mpUndoAction);
connect(mpUndoAction, &QAction::triggered, this, &dlgTriggerEditor::slot_smartUndo);
mpRedoAction = new QAction(QIcon::fromTheme(qsl("edit-redo"), QIcon(qsl(":/icons/edit-redo.png"))), tr("Redo"), this);
mpRedoAction->setShortcut(QKeySequence(QKeySequence::Redo)); // Ctrl+Y or Ctrl+Shift+Z
mpRedoAction->setShortcutContext(Qt::WindowShortcut);
mpRedoAction->setEnabled(false);
this->addAction(mpRedoAction);
connect(mpRedoAction, &QAction::triggered, this, &dlgTriggerEditor::slot_smartRedo);
connect(mpUndoStack, &QUndoStack::canUndoChanged, this, &dlgTriggerEditor::slot_updateUndoRedoButtonStates);
connect(mpUndoStack, &QUndoStack::canRedoChanged, this, &dlgTriggerEditor::slot_updateUndoRedoButtonStates);
connect(mpUndoStack, &QUndoStack::undoTextChanged, this, [this](const QString& text) {
QString shortcut = mpUndoAction->shortcut().toString(QKeySequence::NativeText);
if (!text.isEmpty()) {
//: Tooltip for undo action. %1 is the action being undone (e.g., "Activate trigger \"foo\""), %2 is the keyboard shortcut
QString undoText = tr("Undo: %1 (%2)").arg(text, shortcut);
mpUndoAction->setToolTip(utils::richText(undoText));
mpUndoAction->setStatusTip(undoText);
} else {
//: Tooltip for undo action when no specific action. %1 is the keyboard shortcut
QString undoText = tr("Undo (%1)").arg(shortcut);
mpUndoAction->setToolTip(utils::richText(undoText));
mpUndoAction->setStatusTip(undoText);
}
});
connect(mpUndoStack, &QUndoStack::redoTextChanged, this, [this](const QString& text) {
QString shortcut = mpRedoAction->shortcut().toString(QKeySequence::NativeText);
if (!text.isEmpty()) {
//: Tooltip for redo action. %1 is the action being redone (e.g., "Activate trigger \"foo\""), %2 is the keyboard shortcut
QString redoText = tr("Redo: %1 (%2)").arg(text, shortcut);
mpRedoAction->setToolTip(utils::richText(redoText));
mpRedoAction->setStatusTip(redoText);
} else {
//: Tooltip for redo action when no specific action. %1 is the keyboard shortcut
QString redoText = tr("Redo (%1)").arg(shortcut);
mpRedoAction->setToolTip(utils::richText(redoText));
mpRedoAction->setStatusTip(redoText);
}
});
// Store guarded pointer to text editor's undo stack for safe signal connections
mpTextUndoStack = mpSourceEditorEdbee->controller()->textDocument()->textUndoStack();
connect(mpTextUndoStack, &edbee::TextUndoStack::undoExecuted, this, &dlgTriggerEditor::slot_updateUndoRedoButtonStates);
connect(mpTextUndoStack, &edbee::TextUndoStack::redoExecuted, this, &dlgTriggerEditor::slot_updateUndoRedoButtonStates);
connect(mpTextUndoStack, &edbee::TextUndoStack::changeAdded, this, &dlgTriggerEditor::slot_updateUndoRedoButtonStates);
slot_updateUndoRedoButtonStates();
connect(mpUndoStack, &EditorUndoStack::itemsChanged, this, &dlgTriggerEditor::slot_itemsChanged);
if (!smAutoCompleteInitialized) {
auto* provider = new edbee::StringTextAutoCompleteProvider();
// Add lua functions and reserved lua terms to an AutoComplete provider
for (const QString& key : mudlet::smLuaFunctionNames.keys()) {
provider->add(key, 3, mudlet::smLuaFunctionNames.value(key).toString());
}
// Lua reserved keywords (highest priority for basic syntax)
provider->add(qsl("and"), 14);
provider->add(qsl("break"), 14);
provider->add(qsl("else"), 14);
provider->add(qsl("elseif"), 14);
provider->add(qsl("end"), 14);
provider->add(qsl("false"), 14);
provider->add(qsl("for"), 14);
provider->add(qsl("function"), 14);
provider->add(qsl("goto"), 14);
provider->add(qsl("local"), 14);
provider->add(qsl("nil"), 14);
provider->add(qsl("not"), 14);
provider->add(qsl("repeat"), 14);
provider->add(qsl("return"), 14);
provider->add(qsl("then"), 14);
provider->add(qsl("true"), 14);
provider->add(qsl("until"), 14);
provider->add(qsl("while"), 14);
// Standard Lua library functions (priority 4 - between Mudlet functions and keywords)
// String library
provider->add(qsl("string.byte"), 4, qsl("string.byte(s [, i [, j]])"));
provider->add(qsl("string.char"), 4, qsl("string.char(...)"));
provider->add(qsl("string.dump"), 4, qsl("string.dump(function)"));
provider->add(qsl("string.find"), 4, qsl("string.find(s, pattern [, init [, plain]])"));
provider->add(qsl("string.format"), 4, qsl("string.format(formatstring, ...)"));
provider->add(qsl("string.gmatch"), 4, qsl("string.gmatch(s, pattern)"));
provider->add(qsl("string.gsub"), 4, qsl("string.gsub(s, pattern, repl [, n])"));
provider->add(qsl("string.len"), 4, qsl("string.len(s)"));
provider->add(qsl("string.lower"), 4, qsl("string.lower(s)"));
provider->add(qsl("string.match"), 4, qsl("string.match(s, pattern [, init])"));
provider->add(qsl("string.rep"), 4, qsl("string.rep(s, n)"));
provider->add(qsl("string.reverse"), 4, qsl("string.reverse(s)"));
provider->add(qsl("string.sub"), 4, qsl("string.sub(s, i [, j])"));
provider->add(qsl("string.upper"), 4, qsl("string.upper(s)"));
// Table library
provider->add(qsl("table.concat"), 4, qsl("table.concat(list [, sep [, i [, j]]])"));
provider->add(qsl("table.insert"), 4, qsl("table.insert(list, [pos,] value)"));
provider->add(qsl("table.pack"), 4, qsl("table.pack(...)"));
provider->add(qsl("table.remove"), 4, qsl("table.remove(list [, pos])"));
provider->add(qsl("table.sort"), 4, qsl("table.sort(list [, comp])"));
provider->add(qsl("table.unpack"), 4, qsl("table.unpack(list [, i [, j]])"));
// Math library
provider->add(qsl("math.abs"), 4, qsl("math.abs(x)"));
provider->add(qsl("math.acos"), 4, qsl("math.acos(x)"));
provider->add(qsl("math.asin"), 4, qsl("math.asin(x)"));
provider->add(qsl("math.atan"), 4, qsl("math.atan(x)"));
provider->add(qsl("math.atan2"), 4, qsl("math.atan2(y, x)"));
provider->add(qsl("math.ceil"), 4, qsl("math.ceil(x)"));
provider->add(qsl("math.cos"), 4, qsl("math.cos(x)"));
provider->add(qsl("math.cosh"), 4, qsl("math.cosh(x)"));
provider->add(qsl("math.deg"), 4, qsl("math.deg(x)"));
provider->add(qsl("math.exp"), 4, qsl("math.exp(x)"));
provider->add(qsl("math.floor"), 4, qsl("math.floor(x)"));
provider->add(qsl("math.fmod"), 4, qsl("math.fmod(x, y)"));
provider->add(qsl("math.frexp"), 4, qsl("math.frexp(x)"));
provider->add(qsl("math.huge"), 4, qsl("math.huge"));
provider->add(qsl("math.ldexp"), 4, qsl("math.ldexp(m, e)"));
provider->add(qsl("math.log"), 4, qsl("math.log(x [, base])"));
provider->add(qsl("math.log10"), 4, qsl("math.log10(x)"));
provider->add(qsl("math.max"), 4, qsl("math.max(x, ...)"));
provider->add(qsl("math.min"), 4, qsl("math.min(x, ...)"));
provider->add(qsl("math.modf"), 4, qsl("math.modf(x)"));
provider->add(qsl("math.pi"), 4, qsl("math.pi"));
provider->add(qsl("math.pow"), 4, qsl("math.pow(x, y)"));
provider->add(qsl("math.rad"), 4, qsl("math.rad(x)"));
provider->add(qsl("math.random"), 4, qsl("math.random([m [, n]])"));
provider->add(qsl("math.randomseed"), 4, qsl("math.randomseed(x)"));
provider->add(qsl("math.sin"), 4, qsl("math.sin(x)"));
provider->add(qsl("math.sinh"), 4, qsl("math.sinh(x)"));
provider->add(qsl("math.sqrt"), 4, qsl("math.sqrt(x)"));
provider->add(qsl("math.tan"), 4, qsl("math.tan(x)"));
provider->add(qsl("math.tanh"), 4, qsl("math.tanh(x)"));
// IO library
provider->add(qsl("io.close"), 4, qsl("io.close([file])"));
provider->add(qsl("io.flush"), 4, qsl("io.flush()"));
provider->add(qsl("io.input"), 4, qsl("io.input([file])"));
provider->add(qsl("io.lines"), 4, qsl("io.lines([filename, ...])"));
provider->add(qsl("io.open"), 4, qsl("io.open(filename [, mode])"));
provider->add(qsl("io.output"), 4, qsl("io.output([file])"));
provider->add(qsl("io.popen"), 4, qsl("io.popen(prog [, mode])"));
provider->add(qsl("io.read"), 4, qsl("io.read(...)"));
provider->add(qsl("io.tmpfile"), 4, qsl("io.tmpfile()"));
provider->add(qsl("io.type"), 4, qsl("io.type(obj)"));
provider->add(qsl("io.write"), 4, qsl("io.write(...)"));
// OS library
provider->add(qsl("os.clock"), 4, qsl("os.clock()"));
provider->add(qsl("os.date"), 4, qsl("os.date([format [, time]])"));
provider->add(qsl("os.difftime"), 4, qsl("os.difftime(t2, t1)"));
provider->add(qsl("os.execute"), 4, qsl("os.execute([command])"));
provider->add(qsl("os.exit"), 4, qsl("os.exit([code [, close]])"));
provider->add(qsl("os.getenv"), 4, qsl("os.getenv(varname)"));
provider->add(qsl("os.remove"), 4, qsl("os.remove(filename)"));
provider->add(qsl("os.rename"), 4, qsl("os.rename(oldname, newname)"));
provider->add(qsl("os.setlocale"), 4, qsl("os.setlocale(locale [, category])"));
provider->add(qsl("os.time"), 4, qsl("os.time([table])"));
provider->add(qsl("os.tmpname"), 4, qsl("os.tmpname()"));
// Coroutine library
provider->add(qsl("coroutine.create"), 4, qsl("coroutine.create(f)"));
provider->add(qsl("coroutine.resume"), 4, qsl("coroutine.resume(co [, val1, ...])"));
provider->add(qsl("coroutine.running"), 4, qsl("coroutine.running()"));
provider->add(qsl("coroutine.status"), 4, qsl("coroutine.status(co)"));
provider->add(qsl("coroutine.wrap"), 4, qsl("coroutine.wrap(f)"));
provider->add(qsl("coroutine.yield"), 4, qsl("coroutine.yield(...)"));
// Debug library
provider->add(qsl("debug.debug"), 4, qsl("debug.debug()"));
provider->add(qsl("debug.gethook"), 4, qsl("debug.gethook([thread])"));
provider->add(qsl("debug.getinfo"), 4, qsl("debug.getinfo([thread,] f [, what])"));
provider->add(qsl("debug.getlocal"), 4, qsl("debug.getlocal([thread,] f, local)"));
provider->add(qsl("debug.getmetatable"), 4, qsl("debug.getmetatable(value)"));
provider->add(qsl("debug.getregistry"), 4, qsl("debug.getregistry()"));
provider->add(qsl("debug.getupvalue"), 4, qsl("debug.getupvalue(f, up)"));
provider->add(qsl("debug.getuservalue"), 4, qsl("debug.getuservalue(u)"));
provider->add(qsl("debug.sethook"), 4, qsl("debug.sethook([thread,] hook, mask [, count])"));
provider->add(qsl("debug.setlocal"), 4, qsl("debug.setlocal([thread,] level, local, value)"));
provider->add(qsl("debug.setmetatable"), 4, qsl("debug.setmetatable(value, table)"));
provider->add(qsl("debug.setupvalue"), 4, qsl("debug.setupvalue(f, up, value)"));
provider->add(qsl("debug.setuservalue"), 4, qsl("debug.setuservalue(udata, value)"));
provider->add(qsl("debug.traceback"), 4, qsl("debug.traceback([thread,] [message [, level]])"));
provider->add(qsl("debug.upvalueid"), 4, qsl("debug.upvalueid(f, n)"));
provider->add(qsl("debug.upvaluejoin"), 4, qsl("debug.upvaluejoin(f1, n1, f2, n2)"));
// Package library
provider->add(qsl("package.config"), 4, qsl("package.config"));
provider->add(qsl("package.cpath"), 4, qsl("package.cpath"));
provider->add(qsl("package.loaded"), 4, qsl("package.loaded"));
provider->add(qsl("package.loadlib"), 4, qsl("package.loadlib(libname, funcname)"));
provider->add(qsl("package.path"), 4, qsl("package.path"));
provider->add(qsl("package.preload"), 4, qsl("package.preload"));
provider->add(qsl("package.searchers"), 4, qsl("package.searchers"));
provider->add(qsl("package.searchpath"), 4, qsl("package.searchpath(name, path [, sep [, rep]])"));
// Mudlet framework namespaced functions (priority 4 - same as Lua stdlib)
// Geyser UI Framework
provider->add(qsl("Geyser.Container:new"), 4, qsl("Geyser.Container:new(cons, container)"));
provider->add(qsl("Geyser.Window:new"), 4, qsl("Geyser.Window:new(cons, container)"));
provider->add(qsl("Geyser.Label:new"), 4, qsl("Geyser.Label:new(cons, container)"));
provider->add(qsl("Geyser.MiniConsole:new"), 4, qsl("Geyser.MiniConsole:new(cons, container)"));
provider->add(qsl("Geyser.Button:new"), 4, qsl("Geyser.Button:new(cons, container)"));
provider->add(qsl("Geyser.Gauge:new"), 4, qsl("Geyser.Gauge:new(cons, container)"));
provider->add(qsl("Geyser.Mapper:new"), 4, qsl("Geyser.Mapper:new(cons, container)"));
provider->add(qsl("Geyser.UserWindow:new"), 4, qsl("Geyser.UserWindow:new(cons)"));
provider->add(qsl("Geyser.CommandLine:new"), 4, qsl("Geyser.CommandLine:new(cons, container)"));
provider->add(qsl("Geyser.HBox:new"), 4, qsl("Geyser.HBox:new(cons, container)"));
provider->add(qsl("Geyser.VBox:new"), 4, qsl("Geyser.VBox:new(cons, container)"));
provider->add(qsl("Geyser.ScrollBox:new"), 4, qsl("Geyser.ScrollBox:new(cons, container)"));
provider->add(qsl("Geyser.ScrollBox:new2"), 4, qsl("Geyser.ScrollBox:new2()"));
provider->add(qsl("Geyser.StyleSheet:new"), 4, qsl("Geyser.StyleSheet:new(stylesheet, parent, target)"));
// Geyser namespace functions
provider->add(qsl("Geyser.Color.parse"), 4, qsl("Geyser.Color.parse(color)"));
provider->add(qsl("Geyser.Color.hex"), 4, qsl("Geyser.Color.hex(color)"));
provider->add(qsl("Geyser.Color.hexa"), 4, qsl("Geyser.Color.hexa(color)"));
provider->add(qsl("Geyser.Color.hhex"), 4, qsl("Geyser.Color.hhex(color)"));
provider->add(qsl("Geyser.Color.hhexa"), 4, qsl("Geyser.Color.hhexa(color)"));
provider->add(qsl("Geyser.Color.hdec"), 4, qsl("Geyser.Color.hdec(color)"));
provider->add(qsl("Geyser.Color.hdeca"), 4, qsl("Geyser.Color.hdeca(color)"));
// Adjustable Container Framework
provider->add(qsl("Adjustable.Container:new"), 4, qsl("Adjustable.Container:new(cons, container)"));
// Database Framework
provider->add(qsl("db.create"), 4, qsl("db.create(db_name, schema)"));
provider->add(qsl("db.query"), 4, qsl("db.query(db_name, query, ...)"));
provider->add(qsl("db.insert"), 4, qsl("db.insert(db_name, sheet_name, values)"));
provider->add(qsl("db.update"), 4, qsl("db.update(db_name, sheet_name, values, query)"));
provider->add(qsl("db.delete"), 4, qsl("db.delete(db_name, sheet_name, query)"));
provider->add(qsl("db.fetch"), 4, qsl("db.fetch(db_name, query, ...)"));
provider->add(qsl("db.aggregate"), 4, qsl("db.aggregate(db_name, query, ...)"));
// DateTime utilities
provider->add(qsl("datetime.parse"), 4, qsl("datetime.parse(format, date_string)"));
// Transfer ownership to Edbee - deleted automatically at app shutdown
edbee::Edbee::instance()->autoCompleteProviderList()->giveProvider(provider);
smAutoCompleteInitialized = true;
}
mpSourceEditorEdbee->textEditorComponent()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mpSourceEditorEdbee->textEditorComponent(), &QWidget::customContextMenuRequested, this, &dlgTriggerEditor::slot_editorContextMenu);
// option areas
mpErrorConsole = new TConsole(mpHost, qsl("errors_%1").arg(hostName), TConsole::ErrorConsole, this);
mpErrorConsole->setWrapAt(100);
mpErrorConsole->slot_toggleTimeStamps(true);
mpErrorConsole->print(qsl("%1\n").arg(tr("*** starting new session ***")));
mpErrorConsole->setMinimumHeight(100);
mpErrorConsole->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Minimum);
splitter_right->addWidget(mpErrorConsole);
splitter_right->setStretchFactor(0, 1); // mpNonCodeWidgets
splitter_right->setCollapsible(0, false);
splitter_right->setStretchFactor(1, 1); // mpSourceEditorArea
splitter_right->setCollapsible(1, false);
splitter_right->setStretchFactor(2, 1); // mpErrorConsole
splitter_right->setCollapsible(2, false);
mpErrorConsole->hide();
connect(mpTriggersMainArea->toolButton_toggleExtraControls, &QAbstractButton::clicked, this, &dlgTriggerEditor::slot_showAllTriggerControls);
slot_showAllTriggerControls(true);
connect(splitter_right, &QSplitter::splitterMoved, this, &dlgTriggerEditor::slot_rightSplitterMoved);
// additional settings
treeWidget_triggers->setColumnCount(1);
treeWidget_triggers->setTreeType(TreeType::Trigger);
treeWidget_triggers->setRootIsDecorated(false);
treeWidget_triggers->setHost(mpHost);
treeWidget_triggers->header()->hide();
treeWidget_triggers->setContextMenuPolicy(Qt::ActionsContextMenu);
treeWidget_aliases->hide();
treeWidget_aliases->setHost(mpHost);
treeWidget_aliases->setTreeType(TreeType::Alias);
treeWidget_aliases->setColumnCount(1);
treeWidget_aliases->header()->hide();
treeWidget_aliases->setRootIsDecorated(false);
treeWidget_aliases->setContextMenuPolicy(Qt::ActionsContextMenu);
treeWidget_actions->hide();
treeWidget_actions->setHost(mpHost);
treeWidget_actions->setTreeType(TreeType::Action);
treeWidget_actions->setColumnCount(1);
treeWidget_actions->header()->hide();
treeWidget_actions->setRootIsDecorated(false);
treeWidget_actions->setContextMenuPolicy(Qt::ActionsContextMenu);
treeWidget_timers->hide();
treeWidget_timers->setHost(mpHost);
treeWidget_timers->setTreeType(TreeType::Timer);
treeWidget_timers->setColumnCount(1);
treeWidget_timers->header()->hide();
treeWidget_timers->setRootIsDecorated(false);
treeWidget_timers->setContextMenuPolicy(Qt::ActionsContextMenu);
treeWidget_variables->hide();
treeWidget_variables->setHost(mpHost);
treeWidget_variables->setTreeType(TreeType::Var);
treeWidget_variables->setColumnCount(2);
treeWidget_variables->hideColumn(1);
treeWidget_variables->header()->hide();
treeWidget_variables->setRootIsDecorated(false);
treeWidget_variables->setContextMenuPolicy(Qt::ActionsContextMenu);
treeWidget_keys->hide();
treeWidget_keys->setHost(mpHost);
treeWidget_keys->setTreeType(TreeType::Key);
treeWidget_keys->setColumnCount(1);
treeWidget_keys->header()->hide();
treeWidget_keys->setRootIsDecorated(false);
treeWidget_keys->setContextMenuPolicy(Qt::ActionsContextMenu);
treeWidget_scripts->hide();
treeWidget_scripts->setHost(mpHost);
treeWidget_scripts->setTreeType(TreeType::Script);
treeWidget_scripts->setColumnCount(1);
treeWidget_scripts->header()->hide();
treeWidget_scripts->setRootIsDecorated(false);
treeWidget_scripts->setContextMenuPolicy(Qt::ActionsContextMenu);
QAction* viewTriggerAction = new QAction(QIcon(qsl(":/icons/tools-wizard.png")), tr("Triggers"), this);
viewTriggerAction->setStatusTip(tr("Show Triggers"));
viewTriggerAction->setToolTip(qsl("%1 (%2)").arg(tr("Show Triggers"), QKeySequence(Qt::CTRL | Qt::Key_1).toString(QKeySequence::NativeText)));
connect(viewTriggerAction, &QAction::triggered, this, &dlgTriggerEditor::slot_showTriggers);
QAction* viewAliasAction = new QAction(QIcon(qsl(":/icons/system-users.png")), tr("Aliases"), this);
viewAliasAction->setStatusTip(tr("Show Aliases"));
viewAliasAction->setToolTip(qsl("%1 (%2)").arg(tr("Show Aliases"), QKeySequence(Qt::CTRL | Qt::Key_2).toString(QKeySequence::NativeText)));
connect(viewAliasAction, &QAction::triggered, this, &dlgTriggerEditor::slot_showAliases);
QAction* viewScriptsAction = new QAction(QIcon(qsl(":/icons/document-properties.png")), tr("Scripts"), this);
viewScriptsAction->setStatusTip(tr("Show Scripts"));
viewScriptsAction->setToolTip(qsl("%1 (%2)").arg(tr("Show Scripts"), QKeySequence(Qt::CTRL | Qt::Key_3).toString(QKeySequence::NativeText)));
connect(viewScriptsAction, &QAction::triggered, this, &dlgTriggerEditor::slot_showScripts);
QAction* showTimersAction = new QAction(QIcon(qsl(":/icons/chronometer.png")), tr("Timers"), this);
showTimersAction->setStatusTip(tr("Show Timers"));
showTimersAction->setToolTip(qsl("%1 (%2)").arg(tr("Show Timers"), QKeySequence(Qt::CTRL | Qt::Key_4).toString(QKeySequence::NativeText)));
connect(showTimersAction, &QAction::triggered, this, &dlgTriggerEditor::slot_showTimers);
QAction* viewKeysAction = new QAction(QIcon(qsl(":/icons/preferences-desktop-keyboard.png")), tr("Keys"), this);
viewKeysAction->setStatusTip(tr("Show Keybindings"));
viewKeysAction->setToolTip(qsl("%1 (%2)").arg(tr("Show Keybindings"), QKeySequence(Qt::CTRL | Qt::Key_5).toString(QKeySequence::NativeText)));
connect(viewKeysAction, &QAction::triggered, this, &dlgTriggerEditor::slot_showKeys);
QAction* viewVarsAction = new QAction(QIcon(qsl(":/icons/variables.png")), tr("Variables"), this);
viewVarsAction->setStatusTip(tr("Show Variables"));
viewVarsAction->setToolTip(qsl("%1 (%2)").arg(tr("Show Variables"), QKeySequence(Qt::CTRL | Qt::Key_6).toString(QKeySequence::NativeText)));
connect(viewVarsAction, &QAction::triggered, this, &dlgTriggerEditor::slot_showVariables);
QAction* viewActionAction = new QAction(QIcon(qsl(":/icons/bookmarks.png")), tr("Buttons"), this);
viewActionAction->setStatusTip(tr("Show Buttons"));
viewActionAction->setToolTip(qsl("%1 (%2)").arg(tr("Show Buttons"), QKeySequence(Qt::CTRL | Qt::Key_7).toString(QKeySequence::NativeText)));
connect(viewActionAction, &QAction::triggered, this, &dlgTriggerEditor::slot_showActions);
QAction* viewErrorsAction = new QAction(QIcon(qsl(":/icons/errors.png")), tr("Errors"), this);
viewErrorsAction->setStatusTip(tr("Show/Hide the errors console in the bottom right of this editor."));
viewErrorsAction->setToolTip(qsl("%1 (%2)").arg(tr("Show/Hide errors console"), QKeySequence(Qt::CTRL | Qt::Key_8).toString(QKeySequence::NativeText)));
connect(viewErrorsAction, &QAction::triggered, this, &dlgTriggerEditor::slot_viewErrorsAction);
QAction* viewStatsAction = new QAction(QIcon(qsl(":/icons/view-statistics.png")), tr("Statistics"), this);
viewStatsAction->setStatusTip(tr("Generate a statistics summary display on the main profile console."));
viewStatsAction->setToolTip(qsl("%1 (%2)").arg(tr("Generate statistics"), QKeySequence(Qt::CTRL | Qt::Key_9).toString(QKeySequence::NativeText)));
connect(viewStatsAction, &QAction::triggered, this, &dlgTriggerEditor::slot_viewStatsAction);
QAction* showDebugAreaAction = new QAction(QIcon(qsl(":/icons/tools-report-bug.png")), tr("Debug"), this);
showDebugAreaAction->setStatusTip(tr("Show/Hide the separate Central Debug Console - when being displayed the system will be slower."));
//: %1 is a keyboard shortcut, e.g. 'Ctrl+0' on Windows/Linux or '⌘0' on macOS
showDebugAreaAction->setToolTip(
utils::richText(tr("Show/Hide Debug Console (%1) -> system will be <b><i>slower</i></b>.").arg(QKeySequence(Qt::CTRL | Qt::Key_0).toString(QKeySequence::NativeText))));
connect(showDebugAreaAction, &QAction::triggered, this, &dlgTriggerEditor::slot_toggleCentralDebugConsole);
// Only show undo/redo test button in "Mudlet self-test" profile (tests are destructive)
if (hostName == qsl("Mudlet self-test")) {
mpRunUndoRedoTestsAction = new QAction(QIcon(qsl(":/icons/view-statistics.png")), tr("Test Undo/Redo"), this);
mpRunUndoRedoTestsAction->setStatusTip(tr("Run internal undo/redo tests and output results to console"));
mpRunUndoRedoTestsAction->setToolTip(tr("Run Undo/Redo Tests"));
connect(mpRunUndoRedoTestsAction, &QAction::triggered, this, &dlgTriggerEditor::slot_runUndoRedoTests);
}
mpAction_toggleActive = new QAction(QIcon(qsl(":/icons/document-encrypt.png")), tr("Activate"), this);
mpAction_toggleActive->setStatusTip(tr("Toggle Active or Non-Active Mode for Triggers, Scripts etc."));
connect(mpAction_toggleActive, &QAction::triggered, this, &dlgTriggerEditor::slot_toggleItemOrGroupActiveFlag);
connect(treeWidget_triggers, &QTreeWidget::itemActivated, this, &dlgTriggerEditor::slot_toggleItemOrGroupActiveFlag);
connect(treeWidget_aliases, &QTreeWidget::itemActivated, this, &dlgTriggerEditor::slot_toggleItemOrGroupActiveFlag);
connect(treeWidget_timers, &QTreeWidget::itemActivated, this, &dlgTriggerEditor::slot_toggleItemOrGroupActiveFlag);
connect(treeWidget_scripts, &QTreeWidget::itemActivated, this, &dlgTriggerEditor::slot_toggleItemOrGroupActiveFlag);
connect(treeWidget_actions, &QTreeWidget::itemActivated, this, &dlgTriggerEditor::slot_toggleItemOrGroupActiveFlag);
connect(treeWidget_keys, &QTreeWidget::itemActivated, this, &dlgTriggerEditor::slot_toggleItemOrGroupActiveFlag);
mAddItem = new QAction(QIcon(qsl(":/icons/document-new.png")), QString(), this);
mAddItem->setToolTip(qsl("<p>%1 (%2)</p>").arg(tr("Add Item"), QKeySequence(QKeySequence::New).toString()));
mAddItem->setShortcutContext(Qt::WidgetWithChildrenShortcut);
mAddItem->setShortcut(QKeySequence(QKeySequence::New));
frame_left->addAction(mAddItem);
connect(mAddItem, &QAction::triggered, this, &dlgTriggerEditor::slot_addNewItem);
mDeleteItem = new QAction(QIcon::fromTheme(qsl(":/icons/edit-delete"), QIcon(qsl(":/icons/edit-delete.png"))), QString(), this);
mDeleteItem->setToolTip(qsl("<p>%1 (%2)</p>").arg(tr("Delete Item"), QKeySequence(QKeySequence::Delete).toString()));
mDeleteItem->setShortcutContext(Qt::WidgetWithChildrenShortcut);
mDeleteItem->setShortcut(QKeySequence(QKeySequence::Delete));
frame_left->addAction(mDeleteItem);
connect(mDeleteItem, &QAction::triggered, this, &dlgTriggerEditor::slot_deleteItemOrGroup);
mAddGroup = new QAction(QIcon(qsl(":/icons/folder-new.png")), QString(), this);
//: %1 is a keyboard shortcut, e.g. 'Ctrl+Shift+N' on Windows/Linux or '⌘⇧N' on macOS
mAddGroup->setToolTip(tr("Add Group (%1)").arg(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_N).toString(QKeySequence::NativeText)));
mAddGroup->setShortcutContext(Qt::WidgetWithChildrenShortcut);
mAddGroup->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_N));
frame_left->addAction(mAddGroup);
connect(mAddGroup, &QAction::triggered, this, &dlgTriggerEditor::slot_addNewGroup);
// 'Save Item' does not see to be translated as it is only ever used programmatically and not visible to the player
// PLACEMARKER 1/3 save button texts need to be kept in sync
mSaveItem = new QAction(QIcon(qsl(":/icons/document-save-as.png")), qsl("Save Item"), this);
//: %1 is a keyboard shortcut, e.g. 'Ctrl+S' on Windows/Linux or '⌘S' on macOS
mSaveItem->setToolTip(tr("<p>Saves the selected item. (%1)</p>"
"<p>Saving causes any changes to the item to take effect. It will not save to disk, "
"so changes will be lost in case of a computer/program crash (but Save Profile to the right will be secure.)</p>")
.arg(QKeySequence(QKeySequence::Save).toString(QKeySequence::NativeText)));
connect(mSaveItem, &QAction::triggered, this, &dlgTriggerEditor::slot_saveEdits);
QAction* copyAction = new QAction(tr("Copy"), this);
copyAction->setShortcut(QKeySequence(QKeySequence::Copy));
// only take effect if the treeview is selected, otherwise it hijacks the shortcut from edbee
copyAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
copyAction->setToolTip(utils::richText(tr("Copy the trigger/script/alias/etc")));
copyAction->setStatusTip(tr("Copy the trigger/script/alias/etc"));
treeWidget_triggers->addAction(copyAction);
treeWidget_aliases->addAction(copyAction);
treeWidget_timers->addAction(copyAction);
treeWidget_scripts->addAction(copyAction);
treeWidget_actions->addAction(copyAction);
treeWidget_keys->addAction(copyAction);
connect(copyAction, &QAction::triggered, this, &dlgTriggerEditor::slot_copyXml);
QAction* pasteAction = new QAction(tr("Paste"), this);
pasteAction->setShortcut(QKeySequence(QKeySequence::Paste));
// only take effect if the treeview is selected, otherwise it hijacks the shortcut from edbee
pasteAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
pasteAction->setToolTip(tr("Paste triggers/scripts/aliases/etc from the clipboard"));
pasteAction->setStatusTip(tr("Paste triggers/scripts/aliases/etc from the clipboard"));
treeWidget_triggers->addAction(pasteAction);
treeWidget_aliases->addAction(pasteAction);
treeWidget_timers->addAction(pasteAction);
treeWidget_scripts->addAction(pasteAction);
treeWidget_actions->addAction(pasteAction);
treeWidget_keys->addAction(pasteAction);
connect(pasteAction, &QAction::triggered, this, &dlgTriggerEditor::slot_pasteXml);
// Add delete action to all tree widgets for right-click context menu
treeWidget_triggers->addAction(mDeleteItem);
treeWidget_aliases->addAction(mDeleteItem);
treeWidget_timers->addAction(mDeleteItem);
treeWidget_scripts->addAction(mDeleteItem);
treeWidget_actions->addAction(mDeleteItem);
treeWidget_keys->addAction(mDeleteItem);
treeWidget_variables->addAction(mDeleteItem);
// Add separators and additional actions to context menu
QAction* separator1 = new QAction(this);
separator1->setSeparator(true);
QAction* separator2 = new QAction(this);
separator2->setSeparator(true);
// Add context menu actions to all tree widgets
QList<QTreeWidget*> treeWidgets = {treeWidget_triggers, treeWidget_aliases, treeWidget_timers, treeWidget_scripts, treeWidget_actions, treeWidget_keys, treeWidget_variables};
for (QTreeWidget* widget : treeWidgets) {
widget->addAction(mAddItem);
widget->addAction(mAddGroup);
widget->addAction(separator1);
// Copy, Paste, Delete are already added above
widget->addAction(separator2);
}
if (!qApp->testAttribute(Qt::AA_DontShowIconsInMenus)) {
copyAction->setIcon(QIcon::fromTheme(qsl("edit-copy"), QIcon(qsl(":/icons/edit-copy.png"))));
pasteAction->setIcon(QIcon::fromTheme(qsl("edit-paste"), QIcon(qsl(":/icons/edit-paste.png"))));
}
QAction* importAction = new QAction(QIcon(qsl(":/icons/import.png")), tr("Import"), this);
importAction->setEnabled(true);
connect(importAction, &QAction::triggered, this, &dlgTriggerEditor::slot_import);
mpExportAction = new QAction(QIcon(qsl(":/icons/export.png")), tr("Export"), this);
mpExportAction->setEnabled(true);
connect(mpExportAction, &QAction::triggered, this, &dlgTriggerEditor::slot_export);
mpCreateModuleAction = new QAction(QIcon(qsl(":/icons/package-exporter.png")), tr("Create Module"), this);
mpCreateModuleAction->setEnabled(true);
mpCreateModuleAction->setToolTip(tr("<p>Create a module from selected items</p>"));
connect(mpCreateModuleAction, &QAction::triggered, this, &dlgTriggerEditor::slot_createModule);
mProfileSaveAction = new QAction(QIcon(qsl(":/icons/document-save-all.png")), tr("Save Profile"), this);
//: %1 is a keyboard shortcut, e.g. 'Ctrl+Shift+S' on Windows/Linux or '⌘⇧S' on macOS
mProfileSaveAction->setToolTip(tr("<p>Saves your profile. (%1)</p>"
"<p>Saves your entire profile (triggers, aliases, scripts, timers, buttons and "
"keys, but not the map or script-specific settings) to your computer disk, so "
"in case of a computer or program crash, all changes you have done will be "
"retained.</p>"
"<p>It also makes a backup of your profile, you can load an older version of it "
"when connecting.</p>"
"<p>Should there be any modules that are marked to be \"<i>synced</i>\" this will "
"also cause them to be saved and reloaded into other profiles if they too are "
"active.</p>")
.arg(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_S).toString(QKeySequence::NativeText)));
mProfileSaveAction->setStatusTip(
tr(R"(Saves your entire profile (triggers, aliases, scripts, timers, buttons and keys, but not the map or script-specific settings); also "synchronizes" modules that are so marked.)"));
mProfileSaveAsAction = new QAction(QIcon(qsl(":/icons/utilities-file-archiver.png")), tr("Save Profile As"), this);
if (mpHost->mLoadedOk) {
connect(mProfileSaveAction, &QAction::triggered, this, &dlgTriggerEditor::slot_profileSaveAction);
connect(mProfileSaveAsAction, &QAction::triggered, this, &dlgTriggerEditor::slot_profileSaveAsAction);
} else {
mProfileSaveAction->setDisabled(true);
mProfileSaveAsAction->setDisabled(true);
auto disabledSaving = tr("Something went wrong loading your Mudlet profile and it could not be loaded. "
"Try loading an older version in 'Connect - Options - Profile history'");
mProfileSaveAction->setToolTip(disabledSaving);
mProfileSaveAsAction->setToolTip(disabledSaving);
}
auto* nextSectionShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Tab), this);
QObject::connect(nextSectionShortcut, &QShortcut::activated, this, &dlgTriggerEditor::slot_nextSection);
QShortcut* previousSectionShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab), this);
connect(previousSectionShortcut, &QShortcut::activated, this, &dlgTriggerEditor::slot_previousSection);
QShortcut* activateMainWindowAction = new QShortcut(QKeySequence((Qt::ALT | Qt::Key_E)), this);
connect(activateMainWindowAction, &QShortcut::activated, this, &dlgTriggerEditor::slot_activateMainWindow);
toolBar = new QToolBar();
toolBar2 = new QToolBar();