-
Notifications
You must be signed in to change notification settings - Fork 0
/
X11workbench.c
1457 lines (1193 loc) · 45.1 KB
/
X11workbench.c
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
/////////////////////////////////////////////////////////////////////////////////////////
// __ __ _ _ _ _ _ //
// \ \/ // |/ |__ __ ___ _ _ | | __| |__ ___ _ __ ___ | |__ ___ //
// \ / | || |\ \ /\ / // _ \ | '__|| |/ /| '_ \ / _ \| '_ \ / __|| '_ \ / __| //
// / \ | || | \ V V /| (_) || | | < | |_) || __/| | | || (__ | | | | _| (__ //
// /_/\_\|_||_| \_/\_/ \___/ |_| |_|\_\|_.__/ \___||_| |_| \___||_| |_|(_)\___| //
// //
// 'main' source for X11workbench //
// //
/////////////////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
X11workbench - X11 programmer's 'work bench' application and toolkit
Copyright (c) 2010-2019 by Bob Frazier (aka 'Big Bad Bombastic Bob')
all rights reserved
DISCLAIMER: The X11workbench application and toolkit software are supplied
'as-is', with no warranties, either implied or explicit.
BSD-like license:
There is no restriction as to what you can do with this software, so long
as you include the above copyright notice and DISCLAIMER for any distributed
work that is linked with, equivalent to, or derived from any portion of this
software, along with this paragraph that explains the terms of the license if
the source is also being made available. "Linked with" includes the use of a
portion of any of the source and/or header files, or their compiled binary
output, as a part of your application or library. A "derived work"
describes a work that uses a significant portion of the source files or the
algorithms that are included with this software.
EXCLUSIONS
Specifically excluded from this requirement are files that were generated by
the software, or anything that is included with the software that is part of
another package (such as files that were created or added during the
'configure' process).
DISTRIBUTION
The license also covers the use of part or all of any of the X11 workbench
toolkit source or header files in your distributed application, in source or
binary form. If you do not ship the source, the above copyright statement
and DISCLAIMER is still required to be placed in a reasonably prominent
place, such as documentation, splash screens, and/or 'about the application'
dialog boxes.
Use and distribution are in accordance with GPL, LGPL, and/or the above
BSD-like license. See COPYING and README.md files for more information.
Additionally, this software, in source or binary form, and in whole or in
part, may be used by explicit permission from the author, without the need
of a license.
Additional information at http://sourceforge.net/projects/X11workbench
and http://bombasticbob.github.io/X11workbench/
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <memory.h>
#include <string.h>
#include <strings.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
// project includes
#include "X11workbench.h"
#include "main_frame.h"
#include "gizzard.h"
#include "gdb_helper.h"
#include "refactor.h"
#include "context_help.h"
#include "resource_edit.h"
// X11workbench toolkit library includes (some already included from above, do it anyway)
#include "window_helper.h"
#include "pixmap_helper.h" // pixmap helpers, including pre-defined icons
#include "frame_window.h"
#include "edit_window.h" // edit (client) window
#include "dialog_window.h"
#include "file_help.h"
#include "conf_help.h"
#include "draw_text.h"
// pixmap data
#include "application_icon.xpm" /* 19x19 icon presented to the OS for alt-tab etc. */
#include "icon_app.xpm" /* application icon that's the same size as the others, 36x36 */
#include "textfiledoc.xpm"
#include "newdoc.xpm"
#include "clangdoc.xpm"
#include "makefiledoc.xpm"
//#define NO_SPLASH /* temporary, later put it as a configure option - need to get 'gleam' to work better */
//#define STRING "Hello, world"
//#define BORDER 32 /* was 1 */
//#define FONT "fixed"
#ifndef NO_SPLASH
#include "splash.xpm" // splash pixmap
#endif // NO_SPLASH
// copyright string '(c)' or the UTF8 symbol - if I support UTF8, use the circle-c version
#ifdef X_HAVE_UTF8_STRING
// 11 bits U+07FF 110xxxxx 10xxxxxx
// A9 --> 10101001 --> 11000010 10101001 --> C2 A9
#define UTF8_COPYRIGHT "\xc2""\xa9"
// TODO: any other UTF8-specific strings can be defined here
#endif // X_HAVE_UTF8_STRING
// function prototypes
static int do_main(int argc, char *argv[], char *envp[]);
static void SetSignalHandlers(void);
int DoFileOpen(WBFrameWindow *pMainFrame, const char *szFileName);
WBFILE_TYPE GetFileType(const char *szFileName); // return one of the WBFILE_TYPE constants
// global vars
int nCPU = 0;
// =======
// M A I N
// =======
void WBUsage(void)
{
fputs("X11workbench - Copyright (c) 2010-2019 by S.F.T. Inc. - all rights reserved\n\n"
"Usage: X11workbench [options] filename [filename [...]]\n"
" where 'filename' represents one or more files or workspaces to be opened on startup\n"
"\n"
"Standard X11workbench Options\n"
"-h display this message\n"
#ifndef NO_DEBUG
"-d dump settings on startup\n"
#endif // NO_DEBUG
#ifndef NO_SPLASH
"--nosplash Skip the 'splash' screen on startup\n"
#endif // !NO_SPLASH
"\n", stderr);
WBToolkitUsage();
}
int WBMain(int argc, char *argv[], char *envp[])
{
int iRval = 1;
iRval = do_main(argc, argv, envp);
if(iRval < 0)
{
WBUsage();
}
return iRval;
}
// static global variables that (may) need to be exposed via 'get' functions
static Display *pX11Display = NULL; /* X server connection */
static WBFrameWindow *pMainFrame = NULL;
static XColor clrGreen;
static const char szKnownFileTypes[] = // for 'File Open' dialog boxen
".txt\tText Files\n"
".c\tC language file\n"
".cpp\tC language file\n"
".h\tC language header\n"
"Makefile\tMake Files\n"
".mk\tMake 'include' Files\n"
".am\tAutotools File\n"
".*\tAll Files\n";
WBFrameWindow *GetFrameWindow()
{
return pMainFrame;
}
Display *GetX11Display()
{
return pX11Display;
}
Window GetFrameWindowID()
{
if(!pMainFrame)
{
return None;
}
return pMainFrame->wID;
}
const char * GetKnownFileTypes()
{
return szKnownFileTypes;
}
///////////////////////////////////////////////
// do_main - initialization, loop, termination
// (the classic top-down model)
///////////////////////////////////////////////
int do_main(int argc, char *argv[], char *envp[])
{
//unsigned long fg, bg, bd; /* Pixel values */
XEvent event; /* Event received */
XSizeHints xsh; /* Size hints for window manager */
//XSetWindowAttributes xswa; /* Temporary Set Window Attribute struct */
char szGreen[]="#00FF00"; // text color for green
Colormap colormap;
int i1, iMinHeight, iMinWidth;
#ifndef NO_DEBUG
int iDebugDumpConfig = 0;
#endif // NO_DEBUG
#ifndef NO_SPLASH
int bNoSplash = 0;
#endif // !NO_SPLASH
// as opposed to 'getarg' this method is system independent
// some POSIX systems don't support 'getarg' correctly
// TODO: put it in platform_helper.[ch] and use HAVE_GETARG
while(argc > 1)
{
if(argv[1][0] != '-' || !argv[1][1])
{
if(argv[1][0] == '-')
{
argv++;
argc--;
}
break;
}
if(argv[1][1] == '-') // a double-dash
{
// double-dash items go here. only 'one per'
if(!strcmp(&(argv[1][2]), "nosplash"))
{
bNoSplash = 1;
goto next_argument;
}
fprintf(stderr, "Unrecognized option \"%s\"\n", argv[1]);
WBUsage();
return 1; // illegal argument - show 'WBUsage' and return an error
}
for(i1=1; argv[1][i1]; i1++)
{
if(argv[1][i1] == 'h' ||
argv[1][i1] == 'H')
{
WBUsage();
return 0; // show 'WBUsage' but do NOT return an error
}
#ifndef NO_DEBUG
else if(argv[1][i1] == 'd')
{
iDebugDumpConfig = 1;
}
#endif // NO_DEBUG
else
{
fprintf(stderr, "Unrecognized option \"-%c\"\n", argv[1][i1]);
WBUsage();
return 1; // show 'WBUsage' and return an error
}
}
next_argument:
argv++;
argc--;
}
// initialization - set signal handlers, open display, etc.
SetSignalHandlers();
pX11Display = WBInit(NULL); // initialize X11 Work Bench Toolkit and obtain Display pointer
if(!pX11Display)
{
return 1; // can't open display, so byby!
}
PXM_RegisterAppIcons(icon_app_xpm, application_icon_xpm);
nCPU = WBCPUCount(); // get # of CPUs
#ifndef NO_DEBUG
// This DEBUG section dumps the config data when theh '-d' option was specified on the command line.
// it requires a Display object so I must do it HERE. Then I can call WBExit and bail out.
if(iDebugDumpConfig)
{
CHDumpConfig();
WBExit();
return 0;
}
#endif // NO_DEBUG
// SUPPLEMENTAL INITIALIZATION STUFF
// color selection
// bd = WhitePixel(pX11Display, DefaultScreen(pX11Display)); // border
// bg = BlackPixel(pX11Display, DefaultScreen(pX11Display)); // background
// fg = WhitePixel(pX11Display, DefaultScreen(pX11Display)); // foreground
// dont' forget the colormap
colormap = WBDefaultColormap(pX11Display);
// additional allocated colors - in this case, GREEN
XParseColor(pX11Display, colormap, szGreen, &clrGreen);
XAllocColor(pX11Display, colormap, &clrGreen); // NOTE: do I need 'XFreeColors' for 'clrGreen' ?
#ifndef NO_SPLASH
if(!bNoSplash)
{
char *pCopyright = WBCopyString(
#ifdef UTF8_COPYRIGHT
"Copyright " UTF8_COPYRIGHT " 2010-2019 by Big Bad Bombastic Bob\nwww.mrp3.com" // text string with unicode char in it U+00A9
#else // UTF8_COPYRIGHT
"Copyright (c) 2010-2019 by Big Bad Bombastic Bob\nwww.mrp3.com"
#endif // UTF8_COPYRIGHT
);
if(pCopyright && nCPU > 0)
{
char tbuf[32];
snprintf(tbuf, sizeof(tbuf), "%d **", nCPU);
WBCatString(&pCopyright, "\n** CPU Count: ");
if(pCopyright)
{
WBCatString(&pCopyright, tbuf);
}
}
if(pCopyright)
{
DLGSplashScreen(splash_xpm,
pCopyright, WhitePixel(pX11Display, DefaultScreen(pX11Display))); // white text
WBFree(pCopyright);
}
else
{
DLGSplashScreen(splash_xpm,
"Copyright (c) 2010-2019 by Big Bad Bombastic Bob\nwww.mrp3.com", // 1 or 2 lines only
WhitePixel(pX11Display, DefaultScreen(pX11Display))); // white text
}
}
#endif // NO_SPLASH
pMainFrame = DoCreateMainFrameWindow("X11workbench", // title
ID_APPLICATION, // icon
szAppMenu, // application menu
WBFrameWindow_APP_WINDOW // flags and attributes
| WBFrameWindow_VISIBLE
| WBFrameWindow_STATUS_BAR);
if(!pMainFrame)
{
WB_ERROR_PRINT("%s - Unable to create main frame window\n", __FUNCTION__);
WBExit();
return 2;
}
// open files specifed on command line
// TODO: if project file specified, open files based on project state
// Otherwise, open as "single file"
WBBeginWaitCursor(pMainFrame->wID);
while(argc > 1)
{
// TODO: is it a project file?
DoFileOpen(pMainFrame, argv[1]);
argc--;
argv++;
}
WBEndWaitCursor(pMainFrame->wID);
if(FWGetNumContWindows(pMainFrame) > 0) // if I opened anything, set focus to first one
{
FWSetFocusWindowIndex(pMainFrame, 0);
}
//=========================
// MAIN EVENT LOOP
//=========================
while (!bQuitFlag /*1*/)
{
if(!WBCheckGetEvent(pX11Display, &event))
{
// SLEEP if no event while in loop (function returns without blocking)
// otherwise I can do background tasks during this loop iteration.
// if I have NO BACKGROUND PROCESSES to do, I can use 'WBWaitForEvent'
// This function makes for an efficient 'wait for event'. Otherwise,
// I'll want to implement something that has WBDelay() calls when there
// is nothing to do...
// if(1)
// {
WBWaitForEvent(pX11Display);
// }
// else
// {
// WBDelay(100); // delay 100 microseconds (0.1 milliseconds)
// }
continue; // skip the 'WBDispatch' since there was no event
}
WBDispatch(&event);
}
if(pMainFrame)
{
WBDestroyWindow(pMainFrame->wID);
}
WB_DEBUG_PRINT(DebugLevel_Heavy | DebugSubSystem_Application,
"%s - Application about to exit\n", __FUNCTION__);
WBExit();
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////
// //
// _ _ _ _ _ _ _ _____ _ _ //
// | | | || |_ (_)| |(_)| |_ _ _ | ___|_ _ _ __ ___ | |_ (_) ___ _ __ ___ //
// | | | || __|| || || || __|| | | | | |_ | | | || '_ \ / __|| __|| | / _ \ | '_ \ / __| //
// | |_| || |_ | || || || |_ | |_| | | _| | |_| || | | || (__ | |_ | || (_) || | | |\__ \ //
// \___/ \__||_||_||_| \__| \__, | |_| \__,_||_| |_| \___| \__||_| \___/ |_| |_||___/ //
// |___/ //
// //
///////////////////////////////////////////////////////////////////////////////////////////////
// 'DoFileOpen()' - API to open a file and create a child frame derived tab for it
int DoFileOpen(WBFrameWindow *pMainFrame, const char *szFileName)
{
WBFILE_TYPE ft;
WBChildFrame *pCF;
int iTab, iLineEnd;
if(!pMainFrame || !szFileName || !*szFileName)
{
return -1;
}
pCF = NULL; // as a flag for later, make sure it's NULL
// create a new tab in the frame window using the correct type of child window
ft = GetFileType(szFileName);
if(ft == WBFILE_TYPE_PROJECT)
{
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Open", "'File _Open' project file not (yet) supported");
}
else if(ft == WBFILE_TYPE_RESOURCE)
{
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Open", "'File _Open' resource file not (yet) supported");
}
else if(ft == WBFILE_TYPE_PIXMAP)
{
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Open", "'File _Open' pixmap file not (yet) supported");
}
else if(ft == WBFILE_TYPE_DIALOG)
{
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Open", "'File _Open' dialog resource file not (yet) supported");
}
else if(ft == WBFILE_TYPE_MENU)
{
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Open", "'File _Open' menu resource file not (yet) supported");
}
else if(ft == WBFILE_TYPE_TOOLBAR)
{
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Open", "'File _Open' toolbar resource file not (yet) supported");
}
else
{
// All other files are assumed to be text files and will create a WBEditWindow as a new tab.
// 1st, create a new 'WBEditWindow', attaching it to the frame
WBEditWindow *pEW = DoCreateEditChildFrame(pMainFrame);
if(!pEW)
{
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Open", "'File _Open' unable to create edit window");
}
else
{
pCF = &(pEW->childframe);
WBBeginWaitCursor(pCF->wID);
// next, load the contents of the file into it
if(WBEditWindowLoadFile(pEW, szFileName))
{
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Open", "'File _Open' unable to read file into edit window");
}
}
// TODO: set up a few things based on the file type
// a) default line ending
// b) default unicode/UTF-8 [as required]
// c) default tab handling
// d) color highlighting
// etc.
// TODO: read this info from the config file, with defaults specified
// by the utility functions.
iLineEnd = GetDefaultLineEnding(ft); // read line ending info from config file, default to this
iTab = GetDefaultTabSetting(ft); // read tab info from config file, default to this
// TODO: scan file to see what the line endings REALLY are?
pEW->xTextObject.vtable->set_linefeed(&(pEW->xTextObject), iLineEnd);
if(ft == WBFILE_TYPE_MAKEFILE ||
ft == WBFILE_TYPE_AUTOCONF)
{
pEW->xTextObject.vtable->set_filetype(&(pEW->xTextObject),
FileType_MAKEFILE | FileType_HARDTAB); // always hard tabs
}
else if(ft == WBFILE_TYPE_CPROG || ft == WBFILE_TYPE_CPP ||
ft == WBFILE_TYPE_CHEADER || ft == WBFILE_TYPE_SHELL ||
ft == WBFILE_TYPE_PYTHON || ft == WBFILE_TYPE_PERL ||
ft == WBFILE_TYPE_ASM || ft == WBFILE_TYPE_JAVA ||
ft == WBFILE_TYPE_JS || ft == WBFILE_TYPE_PHP ||
ft == WBFILE_TYPE_ARDUINO)
{
// programming languages
if(iTab < 0) // hard tabs
{
pEW->xTextObject.vtable->set_filetype(&(pEW->xTextObject),
FileType_PROGRAM | FileType_HARDTAB); // use hard tabs
}
else
{
pEW->xTextObject.vtable->set_filetype(&(pEW->xTextObject),
FileType_PROGRAM); // use spaces
}
}
else if(ft == WBFILE_TYPE_HTML ||
ft == WBFILE_TYPE_XML)
{
// programming languages
if(iTab < 0) // hard tabs
{
pEW->xTextObject.vtable->set_filetype(&(pEW->xTextObject),
FileType_XML | FileType_HARDTAB); // use hard tabs
}
else
{
pEW->xTextObject.vtable->set_filetype(&(pEW->xTextObject),
FileType_XML); // use spaces
}
}
else // plain text
{
if(iTab < 0) // hard tabs
{
pEW->xTextObject.vtable->set_filetype(&(pEW->xTextObject),
FileType_PLAIN_TEXT | FileType_HARDTAB); // use hard tabs
}
else
{
pEW->xTextObject.vtable->set_filetype(&(pEW->xTextObject),
FileType_PLAIN_TEXT); // use spaces
}
}
pEW->xTextObject.vtable->set_tab(&(pEW->xTextObject), abs(iTab));
}
if(pCF) // did I create the new child frame??
{
const char *pDisplayName;
// display file name with no path info within tab
pDisplayName = szFileName + strlen(szFileName);
while(pDisplayName > szFileName && *(pDisplayName - 1) != '/')
{
pDisplayName--;
}
FWSetChildFrameDisplayName(pCF, pDisplayName);
WBEndWaitCursor(pCF->wID);
}
return pCF ? 0 : -1;
}
int DoFileSave(WBChildFrame *pCF)
{
//WBEditWindow *pEditWindow;
int iRval;
if(!pCF || !pCF->pUI || !pCF->pUI->save)
{
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Save As", "'File Save As' - no 'save-able' child frame");
return -1;
}
WBBeginWaitCursor(pCF->wID);
iRval = pCF->pUI->save(pCF, NULL);
WBEndWaitCursor(pCF->wID);
#if 0
pEditWindow = WBEditWindowFromWindowID(pCF->wID);
if(!pEditWindow || !WBIsValidEditWindow(pEditWindow))
return -1;
if(!pEditWindow->szFileName)
{
return -1; // for now; no file name!
}
return WBEditWindowSaveFile(pEditWindow, NULL);
#endif // 0
if(iRval)
{
char tbuf[256];
snprintf(tbuf, sizeof(tbuf), "'File Save As' - WBChildWindow::save() returned %d", iRval);
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Save", tbuf);
}
return iRval;
}
int DoFileSaveAs(WBChildFrame *pCF, const char *szFileName)
{
int iRval;
//WBEditWindow *pEditWindow;
if(!pCF || !pCF->pUI || !pCF->pUI->save)
{
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Save As", "'File Save As' - no 'save-able' child frame");
return -1;
}
WBBeginWaitCursor(pCF->wID);
iRval = pCF->pUI->save(pCF, szFileName);
WBEndWaitCursor(pCF->wID);
#if 0
// TODO: be more generic about whether it's an 'Edit WIndow' or not
pEditWindow = WBEditWindowFromWindowID(pCF->wID);
if(!pEditWindow || !WBIsValidEditWindow(pEditWindow))
{
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Save As", "'File Save As' - edit window not valid");
return -1;
}
WBBeginWaitCursor(pCF->wID);
iRval = WBEditWindowSaveFile(pEditWindow, szFileName);
WBEndWaitCursor(pCF->wID);
#endif // 0
if(iRval)
{
char tbuf[256];
snprintf(tbuf, sizeof(tbuf), "'File Save As' - WBChildWindow::save() returned %d", iRval);
DLGMessageBox(MessageBox_OK | MessageBox_Error, None,
"File Save As", tbuf);
}
else
{
const char *pDisplayName;
// display file name with no path info within tab
pDisplayName = szFileName + strlen(szFileName);
while(pDisplayName > szFileName && *(pDisplayName - 1) != '/')
{
pDisplayName--;
}
FWSetChildFrameDisplayName(pCF, pDisplayName);
}
return iRval;
}
WBFILE_TYPE GetFileType(const char *szFileName) // return one of the WBFILE_TYPE constants
{
const char *pFN, *pExt;
pFN = pExt = szFileName + strlen(szFileName);
while(pFN > szFileName && *(pFN - 1) != '/')
{
pFN--;
}
while(pExt > szFileName && *(pExt - 1) != '.')
{
pExt--;
}
if(pExt <= szFileName)
{
pExt = NULL; // no extension
}
// TODO: don't just check the extension, read the first few lines, check for
// invalid/unprintable characters, etc.
if(pExt && (!strcasecmp("makefile", pExt) || !strcasecmp("BSDmakefile", pExt)))
{
return WBFILE_TYPE_MAKEFILE;
}
else if(!strcmp("ini", pExt) || !strcmp("conf", pExt))
{
// TODO: see if this is a text or binary format file
// and handle it properly
return WBFILE_TYPE_CONF; // for now assume an INI-style formatted config file
}
else if(!strcmp("sh", pExt))
{
// TODO: look for hash-bang or if it is a binary file
// this can make a difference, as it might be Perl or Python, etc.
return WBFILE_TYPE_SHELL; // for now assume THIS
}
else if(!pExt)
{
// TODO: look for hash-bang or if it is a binary file
// also see if it's executable. Could also be a 'source' command file
//
// Additionally could be a C++ header file...
return WBFILE_TYPE_TEXT; // for now...
}
// ----------------------------
// Makefile and autoconf files
// ----------------------------
else if(!strcasecmp("mk", pExt)) // '.mk' '.Mk' or '.MK' (or even '.mK') extension
{
return WBFILE_TYPE_MAKEFILE;
}
else if(!strcasecmp("makefile", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_MAKEFILE;
}
else if(!strcmp("ac", pExt) || !strcmp("am", pExt))
{
// TODO: do I want to also include '.in' files?
// do I want to check the names, i.e. automake.am, config.ac, etc.
return WBFILE_TYPE_AUTOCONF;
}
// ----------------------------------
// Programming language source files
// ----------------------------------
else if(!strcasecmp("c", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_CPROG;
}
else if(!strcasecmp("h", pExt) || !strcasecmp("hpp", pExt)
|| !strcasecmp("h++", pExt) ) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_CHEADER;
}
else if(!strcasecmp("cpp", pExt) || !strcasecmp("c++", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_CPP;
}
else if(!strcasecmp("s", pExt) || !strcasecmp("asm", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_ASM;
}
else if(!strcasecmp("pde", pExt) || !strcasecmp("ino", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_ARDUINO; // arduino script may require some additional 'special help'
}
else if(!strcmp("java", pExt)) // for now I only do the lower-case extension naming here
{
return WBFILE_TYPE_JAVA;
}
else if(!strcmp("js", pExt)) // for now I only do the lower-case extension naming here
{
return WBFILE_TYPE_JS;
}
else if(!strcmp("pl", pExt)) // for now I only do the lower-case extension naming here
{
return WBFILE_TYPE_PERL;
}
else if(!strcasecmp("py", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_PYTHON;
}
else if(!strcasecmp("php", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_PHP;
}
else if(!strcasecmp("htm", pExt) || !strcasecmp("html", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_HTML;
}
// ---------------------------------
// standard text-based file formats
// ---------------------------------
else if(!strcasecmp("txt", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_TEXT; // TODO: should unicode-16 text be indicated differently?
}
else if(!strcmp("xpm", pExt)) // PIXMAP FILE - somewhat special, usually in C language
{
return WBFILE_TYPE_PIXMAP;
}
else if(!strcasecmp("xml", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_XML;
}
else if(!strcasecmp("json", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_JSON;
}
// ------------------------------------------
// X11workbench private file extension types
// ------------------------------------------
else if(!strcasecmp("xwb", pExt)) // also allow case-insensitive naming, in case 'windows'
{
return WBFILE_TYPE_PROJECT;
}
else if(!strcasecmp("xwbrc", pExt)) // also allow case-insensitive naming, in case 'windows'
{
// generic resource files
return WBFILE_TYPE_RESOURCE;
}
else if(!strcasecmp("xwbdlg", pExt)) // also allow case-insensitive naming, in case 'windows'
{
// dialog box resource files
return WBFILE_TYPE_DIALOG;
}
else if(!strcasecmp("xwbmenu", pExt)) // also allow case-insensitive naming, in case 'windows'
{
// menu resource files
return WBFILE_TYPE_MENU;
}
else if(!strcasecmp("xwbbar", pExt)) // also allow case-insensitive naming, in case 'windows'
{
// toolbar resource files
return WBFILE_TYPE_TOOLBAR;
}
return WBFILE_TYPE_TEXT; // default
}
int GetDefaultTabSetting(WBFILE_TYPE nFileType)
{
if(nFileType == WBFILE_TYPE_MAKEFILE || nFileType == WBFILE_TYPE_AUTOCONF)
{
return -8; // hard tab, 8 bytes (always)
}
// else if(nFileType == WBFILE_TYPE_HTML ||
// nFileType == WBFILE_TYPE_XML)
// {
// // TODO: read from config
//
// return 4; // 4 bytes, soft tab
// }
// TODO: read file-type from config and default tab size
return 4; // 4 bytes, soft tab (the default)
}
int GetDefaultLineEnding(WBFILE_TYPE nFileType)
{
if(nFileType == WBFILE_TYPE_HTML ||
nFileType == WBFILE_TYPE_XML)
{
return LineFeed_CRLF; // by convention for these (TODO: check settings?)
}
else if(nFileType == WBFILE_TYPE_MAKEFILE || nFileType == WBFILE_TYPE_AUTOCONF)
{
// TODO: what about windows nmake files?
return LineFeed_NEWLINE;
}
return LineFeed_DEFAULT;
}
const char *GetFileTypeDesc(WBFILE_TYPE nFileType)
{
static const char * const aszDesc[] =
{
"None",
"Text",
"C Program Source",
"C++ Program Source",
"C/C++ Header File",
"Make File",
"Auto-conf File",
"XWB Project File"
"Resource File",
"Pixmap File",
"Dialog Resource",
"Menu Resource",