-
Notifications
You must be signed in to change notification settings - Fork 0
/
SciTeGTK.cxx
5500 lines (4741 loc) · 176 KB
/
SciTeGTK.cxx
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
// SciTE - Scintilla based Text Editor
// SciTEGTK.cxx - main code for the GTK version of the editor
// Copyright 1998-2004 by Neil Hodgson <[email protected]>
// The License.txt file describes the conditions under which this software may be distributed.
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdarg>
#include <ctime>
#include <cerrno>
#include <csignal>
#include <tuple>
#include <string>
#include <string_view>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <memory>
#include <chrono>
#include <atomic>
#include <mutex>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "ILexer.h"
#include "ScintillaTypes.h"
#include "ScintillaMessages.h"
#include "ScintillaCall.h"
#include "Scintilla.h"
#include "ScintillaWidget.h"
#include "Lexilla.h"
#include "LexillaAccess.h"
#include "GUI.h"
#include "ScintillaWindow.h"
#include "StringList.h"
#include "StringHelpers.h"
#include "FilePath.h"
#include "StyleDefinition.h"
#include "PropSetFile.h"
#include "Extender.h"
#include "SciTE.h"
#include "JobQueue.h"
#include "pixmapsGNOME.h"
#include "SciIcon.h"
#include "Widget.h"
#include "Cookie.h"
#include "Worker.h"
#include "MatchMarker.h"
#include "SciTEBase.h"
#include "StripDefinition.h"
#include "SciTEKeys.h"
#ifndef NO_EXTENSIONS
#include "MultiplexExtension.h"
#ifndef NO_FILER
#include "DirectorExtension.h"
#endif
#ifndef NO_LUA
#include "LuaExtension.h"
#endif
#endif
enum { mbsAboutBox = 0x100000 };
// Key names are longer for GTK 3
#if GTK_CHECK_VERSION(3,0,0)
#define GKEY_Escape GDK_KEY_Escape
#define GKEY_Tab GDK_KEY_Tab
#define GKEY_ISO_Left_Tab GDK_KEY_ISO_Left_Tab
#define GKEY_KP_Enter GDK_KEY_KP_Enter
#define GKEY_KP_Multiply GDK_KEY_KP_Multiply
#define GKEY_Control_L GDK_KEY_Control_L
#define GKEY_Control_R GDK_KEY_Control_R
#define GKEY_F1 GDK_KEY_F1
#define GKEY_F2 GDK_KEY_F2
#define GKEY_F3 GDK_KEY_F3
#define GKEY_F4 GDK_KEY_F4
#else
#define GKEY_Escape GDK_Escape
#define GKEY_Tab GDK_Tab
#define GKEY_ISO_Left_Tab GDK_ISO_Left_Tab
#define GKEY_KP_Enter GDK_KP_Enter
#define GKEY_KP_Multiply GDK_KP_Multiply
#define GKEY_Control_L GDK_Control_L
#define GKEY_Control_R GDK_Control_R
#define GKEY_F1 GDK_F1
#define GKEY_F2 GDK_F2
#define GKEY_F3 GDK_F3
#define GKEY_F4 GDK_F4
#endif
static GdkWindow *WindowFromWidget(GtkWidget *w) {
return gtk_widget_get_window(w);
}
const char appName[] = "SciTE";
static GtkWidget *PWidget(const GUI::Window &w) {
return static_cast<GtkWidget *>(w.GetID());
}
class SciTEGTK;
typedef void (*SigFunction)(GtkWidget *w, SciTEGTK *app);
// Callback thunk class connects GTK signals to a SciTEGTK instance method.
template< void (SciTEGTK::*method)() >
class Signal {
public:
static void Function(GtkWidget */*w*/, SciTEGTK *app) {
(app->*method)();
}
};
// Callback thunk class connects GTK signals to a SciTEGTK instance method.
template< void (SciTEGTK::*method)(int responseID) >
class ResponseSignal {
public:
static void Function(GtkDialog */*w*/, gint responseID, SciTEGTK *app) {
(app->*method)(responseID);
}
};
template< void (SciTEGTK::*method)(int responseID) >
inline void AttachResponse(GtkWidget *w, SciTEGTK *object) {
ResponseSignal <method> sig;
g_signal_connect(G_OBJECT(w), "response", G_CALLBACK(sig.Function), object);
}
// Field added to GTK 1.x ItemFactoryEntry for 2.x so have a struct that is the same as 1.x
struct SciTEItemFactoryEntry {
const char *path;
const char *accelerator;
GCallback callback;
int callback_action;
const char *item_type;
};
long SciTEKeys::ParseKeyCode(const char *mnemonic) {
int modsInKey = 0;
int keyval = -1;
if (mnemonic && *mnemonic) {
std::string sKey = mnemonic;
if (RemoveStringOnce(sKey, "Ctrl+"))
modsInKey |= GDK_CONTROL_MASK;
if (RemoveStringOnce(sKey, "Shift+"))
modsInKey |= GDK_SHIFT_MASK;
if (RemoveStringOnce(sKey, "Alt+"))
modsInKey |= GDK_MOD1_MASK;
if (RemoveStringOnce(sKey, "Super+"))
modsInKey |= GDK_MOD4_MASK;
if (sKey.length() == 1) {
if (modsInKey & GDK_CONTROL_MASK && !(modsInKey & GDK_SHIFT_MASK))
LowerCaseAZ(sKey);
keyval = sKey[0];
} else if ((sKey.length() > 1)) {
if ((sKey[0] == 'F') && (IsADigit(sKey[1]))) {
sKey.erase(0, 1);
int fkeyNum = atoi(sKey.c_str());
if (fkeyNum >= 1 && fkeyNum <= 12)
#if GTK_CHECK_VERSION(3,0,0)
keyval = fkeyNum - 1 + GDK_KEY_F1;
#else
keyval = fkeyNum - 1 + GDK_F1;
#endif
} else {
#if GTK_CHECK_VERSION(3,0,0)
if (sKey == "Left") {
keyval = GDK_KEY_Left;
} else if (sKey == "Right") {
keyval = GDK_KEY_Right;
} else if (sKey == "Up") {
keyval = GDK_KEY_Up;
} else if (sKey == "Down") {
keyval = GDK_KEY_Down;
} else if (sKey == "Insert") {
keyval = GDK_KEY_Insert;
} else if (sKey == "End") {
keyval = GDK_KEY_End;
} else if (sKey == "Home") {
keyval = GDK_KEY_Home;
} else if (sKey == "Enter") {
keyval = GDK_KEY_Return;
} else if (sKey == "Space") {
keyval = GDK_KEY_space;
} else if (sKey == "Tab") {
keyval = GDK_KEY_Tab;
} else if (sKey == "KeypadPlus") {
keyval = GDK_KEY_KP_Add;
} else if (sKey == "KeypadMinus") {
keyval = GDK_KEY_KP_Subtract;
} else if (sKey == "KeypadMultiply") {
keyval = GDK_KEY_KP_Multiply;
} else if (sKey == "KeypadDivide") {
keyval = GDK_KEY_KP_Divide;
} else if (sKey == "Escape") {
keyval = GDK_KEY_Escape;
} else if (sKey == "Delete") {
keyval = GDK_KEY_Delete;
} else if (sKey == "PageUp") {
keyval = GDK_KEY_Page_Up;
} else if (sKey == "PageDown") {
keyval = GDK_KEY_Page_Down;
} else if (sKey == "Slash") {
keyval = GDK_KEY_slash;
} else if (sKey == "Question") {
keyval = GDK_KEY_question;
} else if (sKey == "Equal") {
keyval = GDK_KEY_equal;
} else if (sKey == "Win") {
keyval = GDK_KEY_Super_L;
} else if (sKey == "Menu") {
keyval = GDK_KEY_Menu;
}
#else
if (sKey == "Left") {
keyval = GDK_Left;
} else if (sKey == "Right") {
keyval = GDK_Right;
} else if (sKey == "Up") {
keyval = GDK_Up;
} else if (sKey == "Down") {
keyval = GDK_Down;
} else if (sKey == "Insert") {
keyval = GDK_Insert;
} else if (sKey == "End") {
keyval = GDK_End;
} else if (sKey == "Home") {
keyval = GDK_Home;
} else if (sKey == "Enter") {
keyval = GDK_Return;
} else if (sKey == "Space") {
keyval = GDK_space;
} else if (sKey == "Tab") {
keyval = GDK_Tab;
} else if (sKey == "KeypadPlus") {
keyval = GDK_KP_Add;
} else if (sKey == "KeypadMinus") {
keyval = GDK_KP_Subtract;
} else if (sKey == "KeypadMultiply") {
keyval = GDK_KP_Multiply;
} else if (sKey == "KeypadDivide") {
keyval = GDK_KP_Divide;
} else if (sKey == "Escape") {
keyval = GDK_Escape;
} else if (sKey == "Delete") {
keyval = GDK_Delete;
} else if (sKey == "PageUp") {
keyval = GDK_Page_Up;
} else if (sKey == "PageDown") {
keyval = GDK_Page_Down;
} else if (sKey == "Slash") {
keyval = GDK_slash;
} else if (sKey == "Question") {
keyval = GDK_question;
} else if (sKey == "Equal") {
keyval = GDK_equal;
} else if (sKey == "Win") {
keyval = GDK_Super_L;
} else if (sKey == "Menu") {
keyval = GDK_Menu;
}
#endif
}
}
}
return (keyval > 0) ? (keyval | (modsInKey<<16)) : 0;
}
bool SciTEKeys::MatchKeyCode(long parsedKeyCode, int keyval, int modifiers) noexcept {
return parsedKeyCode && !(0xFFFF0000 & (keyval | modifiers)) && (parsedKeyCode == (keyval | (modifiers<<16)));
}
class BackgroundStrip : public Strip {
public:
WStatic wExplanation;
WProgress wProgress;
BackgroundStrip() {
}
void Creation(GtkWidget *container) override;
void SetProgress(const GUI::gui_string &explanation, size_t size, size_t progress);
};
class DialogGoto : public Dialog {
public:
WEntry entryGoto;
};
class DialogAbbrev : public Dialog {
public:
WComboBoxEntry comboAbbrev;
};
class DialogTabSize : public Dialog {
public:
WEntry entryTabSize;
WEntry entryIndentSize;
WToggle toggleUseTabs;
};
class DialogParameters : public Dialog {
public:
bool paramDialogCanceled;
WEntry entryParam[SciTEBase::maxParam];
DialogParameters() : paramDialogCanceled(true) {
}
};
class FindDialog : public Dialog {
public:
virtual void FillCombosInDialog()=0;
};
class DialogFindInFiles : public FindDialog, public SearchUI {
public:
WComboBoxEntry wComboFiles;
WComboBoxEntry wComboFindInFiles;
WComboBoxEntry comboDir;
WToggle toggleWord;
WToggle toggleCase;
WButton btnDotDot;
WButton btnBrowse;
void GrabFields();
void FillFields();
void FillCombosInDialog() override;
};
class DialogFindReplace : public FindDialog, public SearchUI {
public:
WStatic labelFind;
WComboBoxEntry wComboFind;
WStatic labelReplace;
WComboBoxEntry wComboReplace;
WToggle toggleWord;
WToggle toggleCase;
WToggle toggleRegExp;
WToggle toggleWrap;
WToggle toggleUnSlash;
WToggle toggleReverse;
void GrabFields();
void FillFields();
void FillCombosInDialog() override;
};
class FindReplaceStrip : public Strip, public SearchUI {
public:
WComboBoxEntry wComboFind;
bool initializingSearch;
enum IncrementalBehaviour { simple, incremental, showAllMatches };
IncrementalBehaviour incrementalBehaviour;
FindReplaceStrip() : initializingSearch(false), incrementalBehaviour(simple) {
}
void SetIncrementalBehaviour(int behaviour);
void MarkIncremental();
void NextIncremental();
};
class FindStrip : public FindReplaceStrip {
public:
WStatic wStaticFind;
WButton wButton;
WButton wButtonMarkAll;
enum { checks = 6 };
WCheckDraw wCheck[checks];
FindStrip() {
}
void Creation(GtkWidget *container) override;
virtual void Destruction();
void Show(int buttonHeight) override;
void Close() override;
bool KeyDown(GdkEventKey *event) override;
void MenuAction(guint action) override;
static void ActivateSignal(GtkWidget *w, FindStrip *pStrip);
static void FindComboChanged(GtkEditable *, FindStrip *pStrip);
static void ToggleChanged(WCheckDraw *, void *user);
static gboolean EscapeSignal(GtkWidget *w, GdkEventKey *event, FindStrip *pStrip);
void GrabFields();
void GrabToggles();
void SetToggles();
void ShowPopup() override;
void FindNextCmd();
void MarkAllCmd();
void ChildFocus(GtkWidget *widget) override;
gboolean Focus(GtkDirectionType direction) override;
};
class ReplaceStrip : public FindReplaceStrip {
public:
WStatic wStaticFind;
WButton wButtonFind;
WButton wButtonReplaceAll;
WStatic wStaticReplace;
WComboBoxEntry wComboReplace;
WButton wButtonReplace;
WButton wButtonReplaceInSelection;
enum { checks = 5 };
WCheckDraw wCheck[checks];
ReplaceStrip() {
}
void Creation(GtkWidget *container) override;
virtual void Destruction();
void Show(int buttonHeight) override;
void Close() override;
bool KeyDown(GdkEventKey *event) override;
void MenuAction(guint action) override;
static void ActivateSignal(GtkWidget *w, ReplaceStrip *pStrip);
static void FindComboChanged(GtkEditable *, ReplaceStrip *pStrip);
static void ToggleChanged(WCheckDraw *, void *user);
static gboolean EscapeSignal(GtkWidget *w, GdkEventKey *event, ReplaceStrip *pStrip);
void GrabFields();
void GrabToggles();
void SetToggles();
void FindCmd();
void ReplaceAllCmd();
void ReplaceCmd();
void ReplaceInSelectionCmd();
void ShowPopup() override;
void ChildFocus(GtkWidget *widget) override;
gboolean Focus(GtkDirectionType direction) override;
};
class UserStrip : public Strip {
public:
StripDefinition *psd;
Extension *extender;
SciTEGTK *pSciTEGTK;
WTable tableUser;
UserStrip() : psd(0), extender(0), pSciTEGTK(0), tableUser(1, 1){
}
void Creation(GtkWidget *container) override;
virtual void Destruction();
void Show(int buttonHeight) override;
void Close() override;
bool KeyDown(GdkEventKey *event) override;
static void ActivateSignal(GtkWidget *w, UserStrip *pStrip);
static gboolean EscapeSignal(GtkWidget *w, GdkEventKey *event, UserStrip *pStrip);
void ClickThis(GtkWidget *w);
static void ClickSignal(GtkWidget *w, UserStrip *pStrip);
void ChildFocus(GtkWidget *widget) override;
gboolean Focus(GtkDirectionType direction) override;
void SetDescription(const char *description);
void SetExtender(Extension *extender_);
void SetSciTE(SciTEGTK *pSciTEGTK_);
void Set(int control, const char *value);
void SetList(int control, const char *value);
std::string GetValue(int control);
};
// Manage the use of the GDK thread lock within glib signal handlers
class ThreadLockMinder {
public:
#ifndef GDK_VERSION_3_6
ThreadLockMinder() {
gdk_threads_enter();
}
~ThreadLockMinder() {
gdk_threads_leave();
}
#endif
};
class SciTEGTK : public SciTEBase {
friend class UserStrip;
protected:
GtkWidget *splitPane;
guint sbContextID;
GUI::Window wToolBarBox;
int toolbarDetachable;
int menuSource;
// Control of sub process
FilePath sciteExecutable;
size_t icmd;
int originalEnd;
int fdFIFO;
GPid pidShell;
bool triedKill;
int exitStatus;
guint pollID;
int inputHandle;
GIOChannel *inputChannel;
GUI::ElapsedTime commandTime;
std::string lastOutput;
int lastFlags;
// For single instance
std::string uniqueInstance;
guint32 startupTimestamp;
guint timerID;
guint idlerID;
BackgroundStrip backgroundStrip;
UserStrip userStrip;
enum FileFormat { sfSource, sfCopy, sfHTML, sfRTF, sfPDF, sfTEX, sfXML } saveFormat;
Dialog dlgFileSelector;
DialogFindInFiles dlgFindInFiles;
DialogGoto dlgGoto;
DialogAbbrev dlgAbbrev;
DialogTabSize dlgTabSize;
GtkWidget *wIncrementPanel;
GtkWidget *IncSearchEntry;
GtkWidget *IncSearchBtnNext;
FindStrip findStrip;
ReplaceStrip replaceStrip;
DialogFindReplace dlgFindReplace;
DialogParameters dlgParameters;
GtkWidget *btnCompile;
GtkWidget *btnBuild;
GtkWidget *btnStop;
GtkWidget *menuBar;
std::map<std::string, GtkWidget *> pulldowns;
std::map<std::string, GSList *> radiogroups;
std::map<int, GtkWidget *> mapMenuItemFromId;
GtkAccelGroup *accelGroup;
gint fileSelectorWidth;
gint fileSelectorHeight;
GtkSettings *settings;
GtkPrintSettings *printSettings;
GtkPageSetup *pageSetup;
std::vector<int> pageStarts;
// Fullscreen handling
GdkRectangle saved;
GtkWidget *AddMBButton(GtkWidget *dialog, const char *label,
int val, GtkAccelGroup *accel_group, bool isDefault = false);
void SetIcon();
void ReadLocalization() override;
void ReadPropertiesInitial() override;
void ReadProperties() override;
static gboolean TimerTick(gpointer pSciTE);
void TimerStart(int mask) override;
void TimerEnd(int mask) override;
static gboolean IdlerTick(gpointer pSciTE);
void SetIdler(bool on) override;
void GetWindowPosition(int *left, int *top, int *width, int *height, int *maximize) override;
void SizeContentWindows() override;
void SizeSubWindows() override;
bool UpdateOutputSize();
GtkWidget *MenuItemFromAction(int itemID);
void SetMenuItem(int menuNumber, int position, int itemID,
const char *text, const char *mnemonic = 0) override;
void DestroyMenuItem(int menuNumber, int itemID) override;
void CheckAMenuItem(int wIDCheckItem, bool val) override;
void EnableAMenuItem(int wIDCheckItem, bool val) override;
void CheckMenusClipboard() override;
void CheckMenus() override;
static void PopUpCmd(GtkMenuItem *menuItem, SciTEGTK *scitew);
void AddToPopUp(const char *label, int cmd = 0, bool enabled = true) override;
void ExecuteNext();
void ResetExecution();
void OpenUriList(const char *list) override;
bool OpenDialog(const FilePath &directory, const char *filesFilter) override;
bool HandleSaveAs(const char *savePath);
bool SaveAsXXX(FileFormat fmt, const char *title, const char *ext=0);
bool SaveAsDialog() override;
void SaveACopy() override;
void SaveAsHTML() override;
void SaveAsRTF() override;
void SaveAsPDF() override;
void SaveAsTEX() override;
void SaveAsXML() override;
void LoadSessionDialog() override;
void SaveSessionDialog() override;
void SetupFormat(Sci_RangeToFormat &frPrint, GtkPrintContext *context);
void BeginPrintThis(GtkPrintOperation *operation, GtkPrintContext *context);
static void BeginPrint(GtkPrintOperation *operation, GtkPrintContext *context, SciTEGTK *scitew);
void DrawPageThis(GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr);
static void DrawPage(GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, SciTEGTK *scitew);
void Print(bool) override;
void PrintSetup() override;
std::string GetRangeInUIEncoding(GUI::ScintillaWindow &win, SA::Span span) override;
MessageBoxChoice WindowMessageBox(GUI::Window &w, const GUI::gui_string &msg, int style = mbsIconWarning) override;
void FindMessageBox(const std::string &msg, const std::string *findItem=0) override;
void AboutDialog() override;
void QuitProgram() override;
std::string EncodeString(const std::string &s) override;
void FindReplaceGrabFields();
void Find() override;
void UIClosed() override;
void UIHasFocus() override;
GtkWidget *TranslatedLabel(const char *original);
void FindIncrement() override;
void FindInFilesResponse(int responseID);
void FindInFiles() override;
void Replace() override;
void FindReplaceResponse(int responseID);
void FindReplace(bool replace) override;
void DestroyFindReplace() override;
void GoLineDialog() override;
bool AbbrevDialog() override;
void TabSizeDialog() override;
bool ParametersDialog(bool modal) override;
FilePath GetDefaultDirectory() override;
FilePath GetSciteDefaultHome() override;
FilePath GetSciteUserHome() override;
void SetStatusBarText(const char *s) override;
void TabInsert(int index, const GUI::gui_char *title) override;
void TabSelect(int index) override;
void RemoveAllTabs() override;
void SetFileProperties(PropSetFile &ps) override;
void UpdateStatusBar(bool bUpdateSlowData) override;
void Notify(SCNotification *notification) override;
void ShowToolBar() override;
void ShowTabBar() override;
void ShowStatusBar() override;
void ActivateWindow(const char *timestamp) override;
void CopyPath() override;
bool &FlagFromCmd(int cmd);
void Command(unsigned long wParam, long lParam = 0);
void ContinueExecute(int fromPoll);
void UserStripShow(const char *description) override;
void UserStripSet(int control, const char *value) override;
void UserStripSetList(int control, const char *value) override;
std::string UserStripValue(int control) override;
void UserStripClosed();
void ShowBackgroundProgress(const GUI::gui_string &explanation, size_t size, size_t progress) override;
// Single instance
void SendFileName(int sendPipe, const char* filename);
bool CheckForRunningInstance(int argc, char* argv[]);
// GTK Signal Handlers
void FindInFilesCmd();
void FindInFilesDotDot();
void FindInFilesBrowse();
void GotoCmd();
void GotoResponse(int responseID);
void AbbrevCmd();
void AbbrevResponse(int responseID);
void TabSizeSet(int &tabSize, bool &useTabs);
void TabSizeCmd();
void TabSizeConvertCmd();
void TabSizeResponse(int responseID);
void FindIncrementSetColour(bool valid);
void FindIncrementNext(bool select);
void FindIncrementChanged();
void FindIncrementCompleteCmd();
static gboolean FindIncrementFocusOutSignal(GtkWidget *w);
static gboolean FindIncrementEscapeSignal(GtkWidget *w, GdkEventKey *event, SciTEGTK *scitew);
void FRFindCmd();
void FRReplaceCmd();
void FRReplaceAllCmd();
void FRReplaceInSelectionCmd();
void FRReplaceInBuffersCmd();
void FRMarkAllCmd();
void FillCombos(FindDialog &dlg);
void FillCombosForGrep();
bool ParametersOpen() override;
void ParamGrab() override;
void ParamCancelCmd();
void ParamCmd();
void ParamResponse(int responseID);
static void PanePositionChanged(GObject *object, GParamSpec *pspec, SciTEGTK *scitew);
static gint PaneButtonRelease(GtkWidget *widget, GdkEvent *event, SciTEGTK *scitew);
static gboolean IOSignal(GIOChannel *source, GIOCondition condition, SciTEGTK *scitew);
static gint QuitSignal(GtkWidget *w, GdkEventAny *e, SciTEGTK *scitew);
static void ButtonSignal(GtkWidget *widget, gpointer data);
static void MenuSignal(GtkMenuItem *menuitem, SciTEGTK *scitew);
static void NotifySignal(GtkWidget *w, gint wParam, SCNotification *notification, SciTEGTK *scitew);
static gint KeyPress(GtkWidget *widget, GdkEventKey *event, SciTEGTK *scitew);
static gint KeyRelease(GtkWidget *widget, GdkEventKey *event, SciTEGTK *scitew);
gint Key(GdkEventKey *event);
static gint MousePress(GtkWidget *widget, GdkEventButton *event, SciTEGTK *scitew);
gint Mouse(GdkEventButton *event);
static void DragDataReceived(GtkWidget *widget, GdkDragContext *context,
gint x, gint y, GtkSelectionData *selectionData, guint info, guint time, SciTEGTK *scitew);
gint TabBarRelease(GtkNotebook *notebook, GdkEventButton *event);
gint TabBarScroll(GdkEventScroll *event);
static gint TabBarReleaseSignal(GtkNotebook *notebook, GdkEventButton *event, SciTEGTK *scitew) {
return scitew->TabBarRelease(notebook, event);
}
static gint TabBarScrollSignal(GtkNotebook *, GdkEventScroll *event, SciTEGTK *scitew) {
return scitew->TabBarScroll(event);
}
SystemAppearance CurrentAppearance() const noexcept override;
static void ThemeSignal(GObject *, GParamSpec *, SciTEGTK *scitew) {
scitew->CheckAppearanceChanged();
}
public:
// TODO: get rid of this - use callback argument to find SciTEGTK
static SciTEGTK *instance;
explicit SciTEGTK(Extension *ext = 0);
~SciTEGTK() override;
void WarnUser(int warnID) override;
GtkWidget *AddToolButton(const char *text, int cmd, GtkWidget *toolbar_icon);
void AddToolBar();
std::string TranslatePath(const char *path);
void CreateTranslatedMenu(int n, const SciTEItemFactoryEntry items[],
int nRepeats = 0, const char *prefix = 0, int startNum = 0,
int startID = 0, const char *radioStart = 0);
void CreateMenu();
void CreateStrips(GtkWidget *boxMain);
bool StripHasFocus() const;
void CreateUI();
void LayoutUI();
void Run(int argc, char *argv[]);
void Execute() override;
void StopExecute() override;
static int PollTool(SciTEGTK *scitew);
static void ReapChild(GPid, gint, gpointer);
void PostOnMainThread(int cmd, Worker *pWorker) override;
static gboolean PostCallback(void *ptr);
// Single instance
void SetStartupTime(const char *timestamp);
};
SciTEGTK *SciTEGTK::instance;
SciTEGTK::SciTEGTK(Extension *ext) : SciTEBase(ext) {
toolbarDetachable = 0;
menuSource = 0;
// Control of sub process
icmd = 0;
originalEnd = 0;
fdFIFO = 0;
pidShell = 0;
triedKill = false;
exitStatus = 0;
pollID = 0;
inputHandle = 0;
inputChannel = 0;
lastFlags = 0;
startupTimestamp = 0;
timerID = 0;
PropSetFile::SetCaseSensitiveFilenames(true);
propsPlatform.Set("PLAT_GTK", "1");
propsPlatform.Set("PLAT_UNIX", "1");
ReadEnvironment();
pathAbbreviations = GetAbbrevPropertiesFileName();
settings = gtk_settings_get_default();
appearance = CurrentAppearance();
g_signal_connect(settings, "notify::gtk-theme-name", G_CALLBACK(ThemeSignal), this);
ReadGlobalPropFile();
ReadAbbrevPropFile();
saveFormat = sfSource;
wIncrementPanel = 0;
IncSearchEntry = 0;
IncSearchBtnNext = 0;
btnCompile = 0;
btnBuild = 0;
btnStop = 0;
menuBar = 0;
accelGroup = 0;
splitPane = 0;
heightBar = 0;
fileSelectorWidth = 580;
fileSelectorHeight = 480;
printSettings = NULL;
pageSetup = NULL;
// Fullscreen handling
fullScreen = false;
instance = this;
}
SciTEGTK::~SciTEGTK() {
g_object_unref(settings);
}
static void destroyDialog(GtkWidget *, gpointer *window) {
if (window) {
GUI::Window *pwin = reinterpret_cast<GUI::Window *>(window);
*(pwin) = 0;
}
}
static void destroyDialogFindReplace(GtkWidget *, gpointer *window) {
if (window) {
DialogFindReplace *dlg = reinterpret_cast<DialogFindReplace *>(window);
*((GUI::Window *)dlg) = 0;
}
}
void SciTEGTK::WarnUser(int) {}
static GtkWidget *messageBoxDialog = 0;
static int messageBoxResult = 0;
static gint messageBoxKey(GtkWidget *w, GdkEventKey *event, gpointer p) {
if (event->keyval == GKEY_Escape) {
g_signal_stop_emission_by_name(G_OBJECT(w), "key_press_event");
gtk_widget_destroy(GTK_WIDGET(w));
messageBoxDialog = 0;
messageBoxResult = GPOINTER_TO_INT(p);
}
return FALSE;
}
static void messageBoxDestroy(GtkWidget *, gpointer *) {
messageBoxDialog = 0;
messageBoxResult = 0;
}
static void messageBoxOK(GtkWidget *, gpointer p) {
gtk_widget_destroy(GTK_WIDGET(messageBoxDialog));
messageBoxDialog = 0;
messageBoxResult = GPOINTER_TO_INT(p);
}
GtkWidget *SciTEGTK::AddMBButton(GtkWidget *dialog, const char *label,
int val, GtkAccelGroup *accel_group, bool isDefault) {
GUI::gui_string translated = localiser.Text(label);
#if GTK_CHECK_VERSION(3,14,0)
GtkWidget *button = gtk_dialog_add_button(GTK_DIALOG(dialog), translated.c_str(), val);
#else
GtkWidget *button = gtk_button_new_with_mnemonic(translated.c_str());
#endif
gtk_widget_set_can_default(button, TRUE);
size_t posMnemonic = translated.find('_');
if (posMnemonic != GUI::gui_string::npos) {
// With a "Yes" button want to respond to pressing "y" as well as standard "Alt+y"
guint key = MakeLowerCase(translated[posMnemonic + 1]);
gtk_widget_add_accelerator(button, "clicked", accel_group,
key, GdkModifierType(0), (GtkAccelFlags)0);
}
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(messageBoxOK), GINT_TO_POINTER(val));
#if GTK_CHECK_VERSION(3,0,0)
#if !GTK_CHECK_VERSION(3,14,0)
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_action_area(GTK_DIALOG(dialog))),
button, TRUE, TRUE, 0);
#endif
#else
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
button, TRUE, TRUE, 0);
#endif
if (isDefault) {
gtk_widget_grab_default(GTK_WIDGET(button));
}
gtk_widget_show(button);
return button;
}
FilePath executableDirectory;
FilePath SciTEGTK::GetDefaultDirectory() {
const char *where = getenv("SciTE_HOME");
#ifdef SYSCONF_PATH
if (!where) {
where = SYSCONF_PATH;
}
#else
if (!where) {
where = getenv("HOME");
}
#endif
if (where) {
return FilePath(where);
}
return FilePath("");
}
FilePath SciTEGTK::GetSciteDefaultHome() {
const char *where = getenv("SciTE_HOME");
#ifdef SYSCONF_PATH
if (!where) {
where = SYSCONF_PATH;
}
#else
if (!where) {
where = getenv("HOME");
}
#endif
if (where) {
return FilePath(where);
}
return FilePath("");
}
FilePath SciTEGTK::GetSciteUserHome() {
// First looking for environment variable $SciTE_USERHOME
// to set SciteUserHome. If not present we look for $SciTE_HOME
// then defaulting to $HOME
char *where = getenv("SciTE_USERHOME");
if (!where) {
where = getenv("SciTE_HOME");
if (!where) {
where = getenv("HOME");
}
}
return FilePath(where);
}
void SciTEGTK::SetStatusBarText(const char *s) {
gtk_statusbar_pop(GTK_STATUSBAR(PWidget(wStatusBar)), sbContextID);
gtk_statusbar_push(GTK_STATUSBAR(PWidget(wStatusBar)), sbContextID, s);
}
void SciTEGTK::TabInsert(int index, const GUI::gui_char *title) {
if (wTabBar.GetID()) {
GtkWidget *tablabel = gtk_label_new(title);
GtkWidget *tabcontent;
if (props.GetInt("pathbar.visible")) {
const FilePath &fp = buffers.buffers[index].file;
if (fp.IsUntitled())
tabcontent = gtk_label_new(localiser.Text("Untitled").c_str());
else
tabcontent = gtk_label_new(fp.AsInternal());
} else {
// No path bar
tabcontent = gtk_image_new();
gtk_image_set_pixel_size(GTK_IMAGE(tabcontent), 0);
}
gtk_widget_show(tablabel);
gtk_widget_show(tabcontent);
gtk_notebook_append_page(GTK_NOTEBOOK(wTabBar.GetID()), tabcontent, tablabel);
}