forked from gphilippot/purebasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectManagement.pb
2744 lines (2246 loc) · 108 KB
/
ProjectManagement.pb
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) Fantaisie Software. All rights reserved.
; Dual licensed under the GPL and Fantaisie Software licenses.
; See LICENSE and LICENSE-FANTAISIE in the project root for license information.
;--------------------------------------------------------------------------------------------
#Project_Version = 100
#Project_VersionString = "1.0"
#Project_Open_LoadLast = 0
#Project_Open_LoadAll = 1
#Project_Open_LoadDefault = 2
#Project_Open_LoadMain = 3
#Project_Open_LoadNone = 4
; Some helpers for the XML reading/writing
;
Procedure NewSection(*Main, Name$)
*Section = CreateXMLNode(*Main, "section", -1)
SetXMLAttribute(*Section, "name", Name$)
ProcedureReturn *Section
EndProcedure
Procedure AppendNode(*Parent, Name$, Text$="")
*Node = CreateXMLNode(*Parent, Name$, -1)
SetXMLNodeText(*Node, Text$)
ProcedureReturn *Node
EndProcedure
Procedure GetSection(*Main, Name$)
*Section = ChildXMLNode(*Main)
While *Section
If XMLNodeType(*Section) = #PB_XML_Normal And GetXMLNodeName(*Section) = "section" And GetXMLAttribute(*Section, "name") = Name$
If GetXMLAttribute(*Section, "minversion") = "" Or Int(ValD(GetXMLAttribute(*Section, "minversion")) * 100.0) <= #Project_Version
ProcedureReturn *Section
Else
ProcedureReturn 0
EndIf
EndIf
*Section = NextXMLNode(*Section)
Wend
ProcedureReturn 0
EndProcedure
Procedure.s ReadNode(*Section, Path$)
*Node = XMLNodeFromPath(*Section, Path$)
If *Node
ProcedureReturn GetXMLNodeText(*Node)
Else
ProcedureReturn ""
EndIf
EndProcedure
; for simpler XML reading
;
Procedure.s Xml_SingleLine(Input$) ; simply cuts all newline and trims spaces
Input$ = RemoveString(Input$, Chr(13))
Input$ = RemoveString(Input$, Chr(10))
ProcedureReturn Trim(Input$)
EndProcedure
Procedure.s Xml_MultiLine(Input$) ; cuts newline at beginning and end and trims space on every line
; replace all newline by chr(10)
Input$ = ReplaceString(Input$, Chr(13)+Chr(10), Chr(10))
Input$ = ReplaceString(Input$, Chr(13), Chr(10))
; remove empty lines at beginning and end
Input$ = Trim(Input$)
While Left(Input$, 1) = Chr(10)
Input$ = LTrim(Right(Input$, Len(Input$)-1))
Wend
While Right(Input$, 1) = Chr(10)
Input$ = RTrim(Left(Input$, Len(Input$)-1))
Wend
; trim spaces in between lines, and put back system newline
Count = CountString(Input$, Chr(10))+1
Output$ = ""
For i = 1 To Count
Output$ + #NewLine + Trim(StringField(Input$, i, Chr(10)))
Next i
If Output$ <> ""
Output$ = Right(Output$, Len(Output$)-Len(#NewLine))
EndIf
ProcedureReturn Output$
EndProcedure
Procedure Xml_Integer(Input$, Fallback = 0) ; reads an integer value (returns fallback for empty string)
Length = Len(Input$)
Value$ = ""
For i = 1 To Length
If FindString("1234567890+-$%.eE", Mid(Input$, i, 1), 1) <> 0 ; cut all unwanted characters
Value$ + Mid(Input$, i, 1)
EndIf
Next i
If Input$ = ""
ProcedureReturn Fallback
Else
ProcedureReturn Val(Value$)
EndIf
EndProcedure
Procedure Xml_Boolean(Input$, Fallback = 0) ; returns 0 or 1 always
If Xml_Integer(Input$, 0)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure AddProjectDefaultMenuEntries()
If IsProject
ForEach ProjectTargets()
Index = ListIndex(ProjectTargets())
If Index < #MAX_MenuTargets
MenuItem(#MENU_DefaultTarget_Start+Index, ProjectTargets()\Name$)
; mark the default item
If ProjectTargets()\IsDefault
SetMenuItemState(#MENU, #MENU_DefaultTarget_Start+Index, #True)
EndIf
EndIf
Next ProjectTargets()
EndIf
EndProcedure
Procedure AddProjectBuildMenuEntries()
If IsProject
ForEach ProjectTargets()
Index = ListIndex(ProjectTargets())
If Index < #MAX_MenuTargets
MenuItem(#MENU_BuildTarget_Start+Index, ProjectTargets()\Name$)
EndIf
Next ProjectTargets()
EndIf
EndProcedure
Procedure IsProjectFile(FileName$)
Protected Result = #False
; Note: We can not share the loaded #XML with the LoadProject() (which would save a re-parse)
; because LoadSourceFile() calls IsProjectFile() too, and this would invalidate
; the #XML from the LoadProject(), so just parse it twice (its small anyway)
; This bug took a long time to track down.
; Sanity size check to not forever try to parse a very large file
; Only .pbp/.sbp are recognized as projects to have a faster check
;
If "."+LCase(GetExtensionPart(FileName$)) = #ProjectFileExtension And FileSize(FileName$) < 1024*1024*10
; Just parse the XML and check whether the main node and namespace are ok.
; Project files are rather small, so this is ok
;
If LoadXML(#XML_CheckProject, FileName$)
If XMLStatus(#XML_CheckProject) = #PB_XML_Success And MainXMLNode(#XML_CheckProject)
If ResolveXMLNodeName(MainXMLNode(#XML_CheckProject), "/") = #ProjectFileNamespace$ + "/project"
Result = #True
EndIf
EndIf
FreeXML(#XML_CheckProject)
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Procedure.s ProjectName(FileName$) ; Get the project name from a project file
Result$ = ""
If LoadXML(#XML_CheckProject, FileName$)
If XMLStatus(#XML_CheckProject) = #PB_XML_Success And MainXMLNode(#XML_CheckProject)
If ResolveXMLNodeName(MainXMLNode(#XML_CheckProject), "/") = #ProjectFileNamespace$ + "/project"
*Config = GetSection(MainXMLNode(#XML_CheckProject), "config")
If *Config
*Options = XMLNodeFromPath(*Config, "options")
If *Options
Result$ = Xml_SingleLine(GetXMLAttribute(*Options, "name"))
EndIf
EndIf
EndIf
EndIf
FreeXML(#XML_CheckProject)
EndIf
ProcedureReturn Result$
EndProcedure
; Provides a guess whether a file may be a sourcecode or not for the purpose of AutoComplete scanning
; Also used to decide whether a file should be highlighted or not
; Accept both PB/SB files here, to make it more comfortable to edit an SB file in the PB IDE for example
;
Procedure IsCodeFile(FileName$)
Ext$ = UCase(GetExtensionPart(FileName$))
If Ext$ = ""
ProcedureReturn #False
EndIf
; PB and SB extensions always work
If Ext$ = "PB" Or Ext$ = "PBI" Or Ext$ = "PBF" Or Ext$ = "SB" Or Ext$ = "SBI" Or Ext$ = "SBF"
ProcedureReturn #True
EndIf
; Check custom extensions from the preferences
Count = CountString(CodeFileExtensions$, ",") + 1
For i = 1 To Count
If Ext$ = UCase(Trim(StringField(CodeFileExtensions$, i, ",")))
ProcedureReturn #True
EndIf
Next i
ProcedureReturn #False
EndProcedure
; Decides whether to add a 'PB' icon to a file in the project panel/explorer
; Only allow PB or SB here depending on the mode
;
Procedure IsPureBasicFile(FileName$)
Ext$ = UCase(GetExtensionPart(FileName$))
CompilerIf #SpiderBasic
If Ext$ = "SB" Or Ext$ = "SBI" Or Ext$ = "SBF" Or Ext$ = "SBP"
ProcedureReturn #True
EndIf
CompilerElse
If Ext$ = "PB" Or Ext$ = "PBI" Or Ext$ = "PBF" Or Ext$ = "PBP"
ProcedureReturn #True
EndIf
CompilerEndIf
ProcedureReturn #False
EndProcedure
; copy the config data part of a project file
;
Procedure CopyProjectConfig(*Source.ProjectFileConfig, *Dest.ProjectFileConfig)
*Dest\FileName$ = *Source\FileName$
*Dest\AutoLoad = *Source\AutoLoad
*Dest\AutoScan = *Source\AutoScan
*Dest\ShowPanel = *Source\ShowPanel
*Dest\ShowWarning = *Source\ShowWarning
EndProcedure
; Clear any allocated data in a project filelist file before removing it
;
Procedure ClearProjectFile(*File.ProjectFile)
FreeSourceItemArray(@*File\Parser) ; has a 0-check and sets the value to 0
EndProcedure
; Unlink file from project. Set KeepData=#true if the project will not be closed
; (so #false on project close or IDE close)
;
Procedure UnlinkSourceFromProject(*Source.SourceFile, RescanFile)
If *Source\ProjectFile
*File.ProjectFile = *Source\ProjectFile
*File\Source = 0
*Source\ProjectFile = 0
RefreshSourceTitle(*Source)
If *Source = *ActiveSource
UpdateMenuStates()
UpdateMainWindowTitle()
ErrorLog_SyncState()
EndIf
; Re-scan the file from disk if the project data is still needed
;
If RescanFile And *File\AutoScan
ScanFile(*File\FileName$, @*File\Parser)
EndIf
EndIf
EndProcedure
; Link a sourcefile to the project
; Just call this on all sourcefiles opened. Files outside of the project are handled correctly
;
Procedure LinkSourceToProject(*Source.SourceFile, *File.ProjectFile = 0)
If *Source\FileName$ ; cannot link a non-saved file
; find project file (if not specified)
If *File = 0
ForEach ProjectFiles()
If IsEqualFile(*Source\FileName$, ProjectFiles()\FileName$)
*File = @ProjectFiles()
Break
EndIf
Next ProjectFiles()
EndIf
If *Source\ProjectFile And *Source\ProjectFile <> *File
UnlinkSourceFromProject(*Source, #True)
EndIf
; check again, as the file may not be in the project at all
If *File
*Source\ProjectFile = *File
*File\Source = *Source
FreeSourceItemArray(@*File\Parser) ; free any data we have from a previous scan
RefreshSourceTitle(*Source)
If *Source = *ActiveSource
UpdateMenuStates()
UpdateMainWindowTitle()
ErrorLog_SyncState() ; the state may change as now the ProjectShowLog counts
EndIf
EndIf
EndIf
EndProcedure
; Update the data kept on the project file, including the link to a sourcefile
Procedure UpdateProjectFile(*File.ProjectFile)
; clear any data scanned from disk
FreeSourceItemArray(@*File\Parser) ; has a 0-check and sets the value to 0
; find the source that represents this file (if any)
*Source.SourceFile = 0
ForEach FileList()
If @FileList() <> *ProjectInfo And FileList()\FileName$ <> "" And IsEqualFile(*File\FileName$, FileList()\FileName$)
*Source = @FileList()
Break
EndIf
Next FileList()
ChangeCurrentElement(FileList(), *ActiveSource)
If *Source
If *Source\ProjectFile And *Source\ProjectFile <> *File
UnlinkSourceFromProject(*Source, #True)
EndIf
If *Source\ProjectFile = 0 ; if nonzero, it equals our *File, so ok
LinkSourceToProject(*Source, *File)
EndIf
Else
*File\Source = 0
; scan the autocomplete info from disk if required
If *File\AutoScan
ScanFile(*File\Filename$, @*File\Parser)
EndIf
EndIf
EndProcedure
; Sets the default target from the target list, creating it if there is none
;
Procedure SetProjectDefaultTarget()
If ListSize(ProjectTargets()) = 0
; No targets are present, create a new default one
;
AddElement(ProjectTargets())
SetCompileTargetDefaults(@ProjectTargets()) ; preference default values
ProjectTargets()\ID = GetUniqueID()
; Set project specific stuff within the target
;
ProjectTargets()\IsProject = #True
ProjectTargets()\Name$ = Language("Compiler", "DefaultTargetName")
ProjectTargets()\IsEnabled = #True
ProjectTargets()\IsDefault = #True
*DefaultTarget = @ProjectTargets()
Else
FirstElement(ProjectTargets())
*DefaultTarget = @ProjectTargets() ; fallback, if no target has the default flag
ForEach ProjectTargets()
If ProjectTargets()\IsDefault
*DefaultTarget = @ProjectTargets()
Break
EndIf
Next ProjectTargets()
; make sure the flag value is consistent
ForEach ProjectTargets()
If *DefaultTarget = @ProjectTargets()
ProjectTargets()\IsDefault = #True
Else
ProjectTargets()\IsDefault = #False
EndIf
Next ProjectTargets()
EndIf
EndProcedure
Procedure ResizeProjectInfo(Width, Height)
GetRequiredSize(#GADGET_ProjectInfo_OpenOptions, @Button1Width.l, @Button1Height.l)
GetRequiredSize(#GADGET_ProjectInfo_OpenCompilerOptions, @Button2Width.l, @Button2Height.l)
ButtonWidth = Max(Button1Width, Max(Button2Width, 100))
; calculate height for info part
TextHeight = GetRequiredHeight(#GADGET_ProjectInfo_Info)
TextHeight = Max(TextHeight, Button1Height+Button2Height+5)
InfoHeight = 15 + ProjectInfoFrameHeight + TextHeight
If InfoHeight > (Height-60) / 2
; info size too great, cap it
InfoHeight = (Height-60) / 2
EndIf
CompilerIf #CompileMacCocoa
BorderOffset = 8
CompilerElse
BorderOffset = 0
CompilerEndIf
; size for other parts
PartHeight = (Height-60-InfoHeight) / 2
ResizeGadget(#GADGET_ProjectInfo_FrameProject, 20-BorderOffset, 20-BorderOffset, Width-40, InfoHeight)
ResizeGadget(#GADGET_ProjectInfo_Info, 30-BorderOffset, 25+ProjectInfoFrameHeight-BorderOffset, Width-65-ButtonWidth, InfoHeight-15-ProjectInfoFrameHeight)
ResizeGadget(#GADGET_ProjectInfo_OpenOptions, Width-30-ButtonWidth-BorderOffset, 25+ProjectInfoFrameHeight-BorderOffset, ButtonWidth, Button1Height)
ResizeGadget(#GADGET_ProjectInfo_OpenCompilerOptions, Width-30-ButtonWidth-BorderOffset, 30+ProjectInfoFrameHeight+Button1Height-BorderOffset, ButtonWidth, Button1Height)
ResizeGadget(#GADGET_ProjectInfo_FrameFiles, 20-BorderOffset, InfoHeight+30-BorderOffset, Width-40, PartHeight)
ResizeGadget(#GADGET_ProjectInfo_Files, 30-BorderOffset, InfoHeight+35+ProjectInfoFrameHeight-BorderOffset, Width-60, PartHeight-15-ProjectInfoFrameHeight)
ResizeGadget(#GADGET_ProjectInfo_FrameTargets, 20-BorderOffset, InfoHeight+PartHeight+40-BorderOffset, Width-40, PartHeight)
ResizeGadget(#GADGET_ProjectInfo_Targets, 30-BorderOffset, InfoHeight+PartHeight+45+ProjectInfoFrameHeight-BorderOffset, Width-60, PartHeight-15-ProjectInfoFrameHeight)
CompilerIf #CompileWindows
; Will size the middle columns small, and the last as big as possible
For i = 1 To 6
If i <> 5 ; leave the "size" column alone
SendMessage_(GadgetID(#GADGET_ProjectInfo_Files), #LVM_SETCOLUMNWIDTH, i, #LVSCW_AUTOSIZE_USEHEADER)
EndIf
Next i
For i = 1 To 8
If i <> 7 ; leave the "format" column alone
SendMessage_(GadgetID(#GADGET_ProjectInfo_Targets), #LVM_SETCOLUMNWIDTH, i, #LVSCW_AUTOSIZE_USEHEADER)
EndIf
Next i
CompilerEndIf
EndProcedure
Procedure.s ProjectInfo_Boolean(Input)
If Input
ProcedureReturn Language("Misc","Yes")
Else
ProcedureReturn ""
EndIf
EndProcedure
; Apply project data changes
Procedure UpdateProjectInfo()
If *ProjectInfo
; Project Info
;
Text$ = Language("Project","ProjectName")+": " + ProjectName$ + #NewLine
Text$ + Language("Project","ProjectFile")+": " + ProjectFile$
If ProjectLastOpenDate
Text$ + #NewLine + #NewLine
Text$ + Language("Project","LastOpen")+": " + ReplaceString(ReplaceString(ReplaceString(Language("Project","LastOpenText"), "%date%", FormatDate(Language("Project","FileDateFormat"), ProjectLastOpenDate)), "%user%", ProjectLastOpenUser$), "%host%", ProjectLastOpenHost$) + #NewLine
Text$ + Language("Project","LastOpenEditor")+": " + ProjectLastOpenEditor$
EndIf
If Trim(ProjectComments$) <> ""
Text$ + #NewLine + #NewLine
Text$ + Language("Project","Comments")+": "+#NewLine
Text$ + ProjectComments$
EndIf
SetGadgetText(#GADGET_ProjectInfo_Info, Text$)
; File List
;
ClearGadgetItems(#GADGET_ProjectInfo_Files)
ForEach ProjectFiles()
Text$ = CreateRelativePath(GetPathPart(ProjectFile$), ProjectFiles()\Filename$) + Chr(10)
Text$ + ProjectInfo_Boolean(ProjectFiles()\AutoLoad) + Chr(10)
Text$ + ProjectInfo_Boolean(ProjectFiles()\ShowWarning) + Chr(10)
Text$ + ProjectInfo_Boolean(ProjectFiles()\AutoScan) + Chr(10)
Text$ + ProjectInfo_Boolean(ProjectFiles()\ShowPanel) + Chr(10)
Size = FileSize(ProjectFiles()\Filename$)
If Size < 0 ; file missing
Text$ + Chr(10) + Chr(10)
Else
Text$ + StrByteSize(Size) + Chr(10)
Text$ + FormatDate(Language("Project","FileDateFormat"), GetFileDate(ProjectFiles()\Filename$, #PB_Date_Modified))
EndIf
If ProjectFiles()\AutoScan
ImageID = OptionalImageID(#IMAGE_ProjectPanel_FileScanned)
Else
ImageID = OptionalImageID(#IMAGE_ProjectPanel_File)
EndIf
AddGadgetItem(#GADGET_ProjectInfo_Files, -1, Text$, ImageID)
; Associate the ProjectFile structure (for the Popup menu)
SetGadgetItemData(#GADGET_ProjectInfo_Files, CountGadgetItems(#GADGET_ProjectInfo_Files)-1, @ProjectFiles())
Next ProjectFiles()
; Target list
;
ClearGadgetItems(#GADGET_ProjectInfo_Targets)
ForEach ProjectTargets()
Text$ = ProjectTargets()\Name$ + Chr(10)
Text$ + ProjectInfo_Boolean(ProjectTargets()\Debugger) + Chr(10)
Text$ + ProjectInfo_Boolean(ProjectTargets()\EnableThread) + Chr(10)
Text$ + ProjectInfo_Boolean(ProjectTargets()\EnableASM) + Chr(10)
Text$ + ProjectInfo_Boolean(ProjectTargets()\EnableOnError) + Chr(10)
If ProjectTargets()\UseCompileCount
Text$ + Str(ProjectTargets()\CompileCount) + Chr(10)
Else
Text$ + Chr(10)
EndIf
If ProjectTargets()\UseBuildCount
Text$ + Str(ProjectTargets()\BuildCount) + Chr(10)
Else
Text$ + Chr(10)
EndIf
; These are also not localized in the Compile Options/Preferences
;
Select ProjectTargets()\ExecutableFormat
CompilerIf #CompileWindows
Case 0: Text$ + "Windows" + Chr(10)
Case 1: Text$ + "Console" + Chr(10)
Case 2: Text$ + "Dll" + Chr(10)
CompilerEndIf
CompilerIf #CompileLinux
Case 0: Text$ + "Linux" + Chr(10)
Case 1: Text$ + "Console" + Chr(10)
Case 2: Text$ + ".so" + Chr(10)
CompilerEndIf
CompilerIf #CompileMac
Case 0: Text$ + "MacOS" + Chr(10)
Case 1: Text$ + "Console" + Chr(10)
Case 2: Text$ + ".dylib" + Chr(10)
CompilerEndIf
EndSelect
Text$ + ProjectTargets()\MainFile$
AddGadgetItem(#GADGET_ProjectInfo_Targets, -1, Text$, ProjectTargetImage(@ProjectTargets()))
Next ProjectTargets()
ResizeProjectInfo(GadgetWidth(#GADGET_ProjectInfo), GadgetHeight(#GADGET_ProjectInfo))
EndIf
EndProcedure
; Apply preferences changes
Procedure UpdateProjectInfoPreferences()
If *ProjectInfo
SetTabBarGadgetItemText(#GADGET_FilesPanel, 0, "> " + Language("Project","TabTitle"))
SetGadgetText(#GADGET_ProjectInfo_FrameProject, Language("Project","ProjectInfo"))
SetGadgetText(#GADGET_ProjectInfo_FrameFiles, Language("Project","FileTab"))
SetGadgetText(#GADGET_ProjectInfo_FrameTargets, Language("Project","ProjectTargets"))
SetGadgetText(#GADGET_ProjectInfo_OpenOptions, Language("Project","ProjectOptions"))
SetGadgetText(#GADGET_ProjectInfo_OpenCompilerOptions, Language("Project","CompilerOptions"))
SetGadgetItemText(#GADGET_ProjectInfo_Files, -1, Language("Project","Filename"), 0)
SetGadgetItemText(#GADGET_ProjectInfo_Files, -1, Language("Project","FileLoadShort"), 1)
SetGadgetItemText(#GADGET_ProjectInfo_Files, -1, Language("Project","FileWarnShort"), 2)
SetGadgetItemText(#GADGET_ProjectInfo_Files, -1, Language("Project","FileScanShort"), 3)
SetGadgetItemText(#GADGET_ProjectInfo_Files, -1, Language("Project","FilePanelShort"), 4)
SetGadgetItemText(#GADGET_ProjectInfo_Files, -1, Language("Project","FileSize"), 5)
SetGadgetItemText(#GADGET_ProjectInfo_Files, -1, Language("Project","FileModified"), 6)
SetGadgetItemText(#GADGET_ProjectInfo_Targets, -1, Language("Project","TargetShort"), 0)
SetGadgetItemText(#GADGET_ProjectInfo_Targets, -1, Language("Project","DebugShort"), 1)
SetGadgetItemText(#GADGET_ProjectInfo_Targets, -1, Language("Project","ThreadShort"), 2)
SetGadgetItemText(#GADGET_ProjectInfo_Targets, -1, Language("Project","AsmShort"), 3)
SetGadgetItemText(#GADGET_ProjectInfo_Targets, -1, Language("Project","OnErrorShort"), 4)
SetGadgetItemText(#GADGET_ProjectInfo_Targets, -1, Language("Project","CompileCountShort"), 5)
SetGadgetItemText(#GADGET_ProjectInfo_Targets, -1, Language("Project","BuildCountShort"), 6)
SetGadgetItemText(#GADGET_ProjectInfo_Targets, -1, Language("Project","FormatShort"), 7)
SetGadgetItemText(#GADGET_ProjectInfo_Targets, -1, Language("Project","InputFile"), 8)
; to autosize the columns on Windows
ResizeProjectInfo(GadgetWidth(#GADGET_ProjectInfo), GadgetHeight(#GADGET_ProjectInfo))
; Theme icons and content get changed in a normal update
UpdateProjectInfo()
EndIf
EndProcedure
Procedure AddProjectInfo()
If *ProjectInfo = 0
; The Project info is always at the beginning
FirstElement(FileList())
*ProjectInfo = InsertElement(FileList())
If *ProjectInfo
OpenGadgetList(#GADGET_SourceContainer)
; Create the ProjectInfo gadgets
;
ContainerGadget(#GADGET_ProjectInfo, 0, 0, 0, 0, #PB_Container_Double)
FrameGadget(#GADGET_ProjectInfo_FrameProject, 0, 0, 0, 0, Language("Project","ProjectInfo"))
CompilerIf #CompileWindows
ProjectInfoFlags = #SS_LEFTNOWORDWRAP
CompilerEndIf
TextGadget(#GADGET_ProjectInfo_Info, 0, 0, 0, 0, "", ProjectInfoFlags)
ButtonGadget(#GADGET_ProjectInfo_OpenOptions, 0, 0, 0, 0, Language("Project","ProjectOptions"))
ButtonGadget(#GADGET_ProjectInfo_OpenCompilerOptions, 0, 0, 0, 0, Language("Project","CompilerOptions"))
FrameGadget(#GADGET_ProjectInfo_FrameFiles, 0, 0, 0, 0, Language("Project","FileTab"))
ListIconGadget(#GADGET_ProjectInfo_Files, 0, 0, 0, 0, Language("Project","Filename"), 300, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_MultiSelect)
AddGadgetColumn(#GADGET_ProjectInfo_Files, 1, Language("Project","FileLoadShort"), 60)
AddGadgetColumn(#GADGET_ProjectInfo_Files, 2, Language("Project","FileWarnShort"), 60)
AddGadgetColumn(#GADGET_ProjectInfo_Files, 3, Language("Project","FileScanShort"), 60)
AddGadgetColumn(#GADGET_ProjectInfo_Files, 4, Language("Project","FilePanelShort"), 60)
AddGadgetColumn(#GADGET_ProjectInfo_Files, 5, Language("Project","FileSize"), 80)
AddGadgetColumn(#GADGET_ProjectInfo_Files, 6, Language("Project","FileModified"), 60)
CompilerIf #CompileWindows
; Make the settings columns centered for a better look
For i = 1 To 4
column.LVCOLUMN\mask = #LVCF_FMT
column\fmt = #LVCFMT_CENTER
SendMessage_(GadgetID(#GADGET_ProjectInfo_Files), #LVM_SETCOLUMN, i, @column)
Next i
CompilerEndIf
FrameGadget(#GADGET_ProjectInfo_FrameTargets, 0, 0, 0, 0, Language("Project","ProjectTargets"))
ListIconGadget(#GADGET_ProjectInfo_Targets, 0, 0, 0, 0, Language("Project","TargetShort"), 200, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(#GADGET_ProjectInfo_Targets, 1, Language("Project","DebugShort"), 60)
AddGadgetColumn(#GADGET_ProjectInfo_Targets, 2, Language("Project","ThreadShort"), 60)
AddGadgetColumn(#GADGET_ProjectInfo_Targets, 3, Language("Project","AsmShort"), 60)
AddGadgetColumn(#GADGET_ProjectInfo_Targets, 4, Language("Project","OnErrorShort"), 60)
AddGadgetColumn(#GADGET_ProjectInfo_Targets, 5, Language("Project","CompileCountShort"), 60)
AddGadgetColumn(#GADGET_ProjectInfo_Targets, 6, Language("Project","BuildCountShort"), 60)
AddGadgetColumn(#GADGET_ProjectInfo_Targets, 7, Language("Project","FormatShort"), 60)
AddGadgetColumn(#GADGET_ProjectInfo_Targets, 8, Language("Project","InputFile"), 200)
CompilerIf #CompileWindows
; Make the settings columns centered for a better look
For i = 1 To 7
column.LVCOLUMN\mask = #LVCF_FMT
column\fmt = #LVCFMT_CENTER
SendMessage_(GadgetID(#GADGET_ProjectInfo_Targets), #LVM_SETCOLUMN, i, @column)
Next i
CompilerEndIf
CloseGadgetList()
HideGadget(#GADGET_ProjectInfo, 1)
ProjectInfoFrameHeight = Max(GadgetHeight(#GADGET_ProjectInfo_FrameProject, #PB_Gadget_RequiredSize) + 3, 10)
; *ActiveSource is modified in CreateEditorGadget()
*RealActiveSource = *ActiveSource
; This creates a full Scintilla with the big callback, but it is never shown,
; and so it doesn't matter. This way, the code that expects a Scintilla to be
; present will work without crashing
;
CreateEditorGadget()
HideEditorGadget(*ProjectInfo\EditorGadget, 1) ; this is never visible
; Back to the active source.
*ActiveSource = *RealActiveSource
CloseGadgetList()
; Note:
; The TabBarGadget cannot handle an Add with a number beyond the count of items
; Probably a bug that should be fixed there. But this workaround will do the trick
If CountTabBarGadgetItems(#GADGET_FilesPanel) = 0
; first item, use #PB_Default
AddTabBarGadgetItem(#GADGET_FilesPanel, #PB_Default, Language("Project", "TabTitle"))
Else
; items exist: using 0 works
AddTabBarGadgetItem(#GADGET_FilesPanel, 0, Language("Project", "TabTitle"))
EndIf
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
SetTabBarGadgetItemColor(#GADGET_FilesPanel, 0, #PB_Gadget_FrontColor, GetCocoaColor("textColor"))
SetTabBarGadgetItemColor(#GADGET_FilesPanel, 0, #PB_Gadget_BackColor, GetCocoaColor("controlAccentColor"))
CompilerElse
SetTabBarGadgetItemColor(#GADGET_FilesPanel, 0, #PB_Gadget_FrontColor, #COLOR_FilePanelFront)
SetTabBarGadgetItemColor(#GADGET_FilesPanel, 0, #PB_Gadget_BackColor, #COLOR_ProjectInfo)
CompilerEndIf
SetTabBarGadgetItemImage(#GADGET_FilesPanel, 0, OptionalImageID(#IMAGE_FilePanel_Project))
UpdateProjectInfo()
ResizeMainWindow()
EndIf
EndIf
EndProcedure
Procedure RemoveProjectInfo()
If *ProjectInfo
Gadget = *ProjectInfo\EditorGadget
ChangeCurrentElement(FileList(), *ProjectInfo)
Index = ListIndex(FileList())
DeleteElement(FileList())
If *ActiveSource = *ProjectInfo ; currently visible
FirstElement(FileList())
*ActiveSource = 0
Else
ChangeCurrentElement(FileList(), *ActiveSource)
EndIf
RemoveTabBarGadgetItem(#GADGET_FilesPanel, Index)
; Its important to 0 this before the next ChangeActiveSourcecode()
*ProjectInfo = 0
ChangeActiveSourcecode()
FreeEditorGadget(Gadget)
If *ActiveSource
SetActiveGadget(*ActiveSource\EditorGadget)
EndIf
FreeGadget(#GADGET_ProjectInfo)
EndIf
EndProcedure
; Check the project version on the XML
; returns true/false to load/not load
;
Procedure CheckProjectVersion(Filename$)
VersionString$ = GetXMLAttribute(MainXMLNode(#XML_LoadProject), "version")
Creator$ = GetXMLAttribute(MainXMLNode(#XML_LoadProject), "creator")
version = Int(ValD(VersionString$) * 100.0)
If GetXMLAttribute(MainXMLNode(#XML_LoadProject), "minversion") = ""
minversion = 0
Else
minversion = Int(ValD(GetXMLAttribute(MainXMLNode(#XML_LoadProject), "minversion")) * 100.0)
EndIf
If version < #Project_Version
Text$ = Language("Project","VersionLow") + #NewLine
Text$ + #NewLine + Language("Project","ProjectFile") + ": " + Filename$ + #NewLine
Text$ + Language("Project","ProjectVersion") + ": " + VersionString$ + #NewLine
Text$ + Language("Project","CurrentVersion") + ": " + #Project_VersionString + #NewLine
Text$ + Language("Project","LastWrittenBy") + ": " + Creator$ + #NewLine
If CommandlineBuild = 0
Text$ + #NewLine + Language("Project", "LoadAnyway")
If MessageRequester(Language("Project","TitleShort"), Text$, #FLAG_Question|#PB_MessageRequester_YesNo) = #PB_MessageRequester_No
ProcedureReturn #False
EndIf
Else
PrintN(Text$)
ProcedureReturn #False
EndIf
ElseIf version > #Project_Version And minversion <= #Project_Version
Text$ = Language("Project","VersionHigh") + #NewLine
Text$ + #NewLine + Language("Project","ProjectFile") + ": " + Filename$ + #NewLine
Text$ + Language("Project","ProjectVersion") + ": " + VersionString$ + #NewLine
Text$ + Language("Project","CurrentVersion") + ": " + #Project_VersionString + #NewLine
Text$ + Language("Project","LastWrittenBy") + ": " + Creator$ + #NewLine
If CommandlineBuild = 0
Text$ + #NewLine + Language("Project", "LoadAnyway")
If MessageRequester(Language("Project","TitleShort"), Text$, #FLAG_Question|#PB_MessageRequester_YesNo) = #PB_MessageRequester_No
ProcedureReturn #False
EndIf
Else
PrintN(Text$)
ProcedureReturn #False
EndIf
ElseIf version > #Project_Version
Text$ = Language("Project","VersionTooHigh") + #NewLine
Text$ + #NewLine + Language("Project","ProjectFile") + ": " + Filename$ + #NewLine
Text$ + Language("Project","ProjectVersion") + ": " + VersionString$ + #NewLine
Text$ + Language("Project","CurrentVersion") + ": " + #Project_VersionString + #NewLine
Text$ + Language("Project","LastWrittenBy") + ": " + Creator$
If CommandlineBuild = 0
MessageRequester(Language("Project","TitleShort"), Text$, #FLAG_Error)
Else
PrintN(Text$)
EndIf
ProcedureReturn #False
EndIf
ProcedureReturn #True
EndProcedure
; displays an error if it fails, returns true/false
;
Procedure LoadProject(Filename$)
Error$ = ""
Success = #False
If IsProject And IsEqualFile(Filename$, ProjectFile$)
ProcedureReturn #True ; there is no sense in reloading the project (it even causes trouble, as we load before we close/save)
EndIf
WarnFiles$ = "" ; files that were modified while closed
; Load the XML and validate the main node and namespace
;
IsLoaded = 0
If LoadXML(#XML_LoadProject, FileName$)
If XMLStatus(#XML_LoadProject) = #PB_XML_Success And MainXMLNode(#XML_LoadProject)
If ResolveXMLNodeName(MainXMLNode(#XML_LoadProject), "/") = #ProjectFileNamespace$ + "/project"
IsLoaded = 1
EndIf
EndIf
EndIf
If IsLoaded
If CheckProjectVersion(FileName$) And CloseProject() ; Close the previous project (If any). If the user cancel the previous project closing, we have to stop.
Success = #True
*Main = MainXMLNode(#XML_LoadProject)
; add new project to "Recent projects"
;
If CommandlineBuild = 0
RecentFiles_AddFile(FileName$, #True)
EndIf
; Set the project default options, in case some key is not present
IsProject = 1
IsProjectCreation = 0
ProjectLastOpenDate = 0
ProjectLastOpenHost$ = ""
ProjectLastOpenUser$ = ""
ProjectLastOpenEditor$ = Xml_SingleLine(GetXMLAttribute(*Main, "creator"))
ProjectFile$ = FileName$
ProjectName$ = Language("Project","DefaultName")
ProjectComments$ = ""
ProjectCloseFiles = 1
ProjectOpenMode = #Project_Open_LoadLast
ProjectShowLog = 1
AutoCloseBuildWindow = 0
ResetList(ProjectFiles())
BasePath$ = GetPathPart(FileName$)
; User-changable configuration
;
*Config = GetSection(*Main, "config")
If *Config
*Options = XMLNodeFromPath(*Config, "options")
If *Options
ProjectName$ = Xml_SingleLine(GetXMLAttribute(*Options, "name"))
ProjectCloseFiles = Xml_Boolean(GetXMLAttribute(*Options, "closefiles"), ProjectCloseFiles)
ProjectOpenMode = Xml_Integer(GetXMLAttribute(*Options, "openmode"))
EndIf
ProjectComments$ = Xml_MultiLine(ReadNode(*Config, "comment"))
*BuildWindow = XMLNodeFromPath(*Config, "buildwindow")
If *BuildWindow
AutoCloseBuildWindow = Xml_Boolean(GetXMLAttribute(*BuildWindow, "autoclose"), AutoCloseBuildWindow)
EndIf
EndIf
; Automatically managed data
;
*ConfigData = GetSection(*Main, "data")
If *ConfigData
*ViewPath = XMLNodeFromPath(*ConfigData, "explorer")
If *ViewPath
ProjectExplorerPath$ = ResolveRelativePath(BasePath$, Xml_SingleLine(GetXMLAttribute(*ViewPath, "view")))
ProjectExplorerPattern = Xml_Integer(GetXMLAttribute(*ViewPath, "pattern"))
EndIf
*ShowLog = XMLNodeFromPath(*ConfigData, "log")
If *ShowLog
ProjectShowLog = Xml_Boolean(GetXMLAttribute(*ShowLog, "show"), ProjectShowLog)
EndIf
*LastOpen = XMLNodeFromPath(*ConfigData, "lastopen")
If *LastOpen
Date$ = XML_SingleLine(GetXMLAttribute(*LastOpen, "date"))
If Date$ <> ""
ProjectLastOpenDate = ParseDate("%yyyy-%mm-%dd %hh:%ii", Date$)
EndIf
ProjectLastOpenHost$ = Xml_SingleLine(GetXMLAttribute(*LastOpen, "host"))
ProjectLastOpenUser$ = Xml_SingleLine(GetXMLAttribute(*LastOpen, "user"))
EndIf
EndIf
; This is important to set to 0 as when we load one of the project files below
; we have no target info yet, and this could be set from an old Project to an invalid address!
;
*DefaultTarget = 0
; Project file list
; (load this even in commandline build mode, so the project is correctly saved back!)
;
*Files = GetSection(*Main, "files")
If *Files
*File = ChildXMLNode(*Files)
While *File
If XMLNodeType(*File) = #PB_XML_Normal And GetXMLNodeName(*File) = "file"
AddElement(ProjectFiles())
ProjectFiles()\Filename$ = ResolveRelativePath(BasePath$, Xml_SingleLine(GetXMLAttribute(*File, "name")))
*Config = XMLNodeFromPath(*File, "config")
If *Config
ProjectFiles()\AutoLoad = Xml_Boolean(GetXMLAttribute(*Config, "load"))
ProjectFiles()\AutoScan = Xml_Boolean(GetXMLAttribute(*Config, "scan"))
ProjectFiles()\ShowPanel = Xml_Boolean(GetXMLAttribute(*Config, "panel"))
ProjectFiles()\ShowWarning = Xml_Boolean(GetXMLAttribute(*Config, "warn"))
ProjectFiles()\LastOpen = Xml_Boolean(GetXMLAttribute(*Config, "lastopen"))
ProjectFiles()\PanelState$ = Xml_SingleLine(GetXMLAttribute(*Config, "panelstate")) ; the default for this is "all open", so need no backward compatibility here
Else
ProjectFiles()\AutoLoad = 0
ProjectFiles()\AutoScan = IsCodeFile(ProjectFiles()\Filename$)
ProjectFiles()\ShowPanel = 1
ProjectFiles()\ShowWarning = 1
ProjectFiles()\LastOpen = 0
ProjectFiles()\PanelState$ = ""
EndIf
*Fingerprint = XMLNodeFromPath(*File, "fingerprint")
If *Fingerprint
ProjectFiles()\Md5$ = LCase(Xml_SingleLine(GetXMLAttribute(*Fingerprint, "md5")))
EndIf
EndIf
*File = NextXMLNode(*File)
Wend
EndIf
; Project targets
;
ClearList(ProjectTargets())
*Targets = GetSection(*Main, "targets")
If *Targets
*Target = ChildXMLNode(*Targets)
While *Target
If XMLNodeType(*Target) = #PB_XML_Normal And GetXMLNodeName(*Target) = "target"
AddElement(ProjectTargets())
ProjectTargets()\ID = GetUniqueID()
ProjectTargets()\IsProject = #True
ProjectTargets()\IsEnabled = Xml_Boolean(GetXMLAttribute(*Target, "enabled"))
ProjectTargets()\IsDefault = Xml_Boolean(GetXMLAttribute(*Target, "default"))
ProjectTargets()\Name$ = Xml_SingleLine(GetXMLAttribute(*Target, "name"))
; loop through the entries
;
*Entry = ChildXMLNode(*Target)
While *Entry
If XMLNodeType(*Entry) = #PB_XML_Normal
Select GetXMLNodeName(*Entry)
Case "inputfile" : ProjectTargets()\MainFile$ = Xml_SingleLine(GetXMLAttribute(*Entry, "value"))
Case "outputfile": ProjectTargets()\OutputFile$ = Xml_SingleLine(GetXMLAttribute(*Entry, "value"))
Case "commandline": ProjectTargets()\Commandline$ = Xml_SingleLine(GetXMLAttribute(*Entry, "value"))
Case "executable": ProjectTargets()\ExecutableName$ = ResolveRelativePath(BasePath$, Xml_SingleLine(GetXMLAttribute(*Entry, "value")))
Case "directory": ProjectTargets()\CurrentDirectory$ = Xml_SingleLine(GetXMLAttribute(*Entry, "value"))
Case "subsystem": ProjectTargets()\Subsystem$ = Xml_SingleLine(GetXMLAttribute(*Entry, "value"))
Case "linker": ProjectTargets()\LinkerOptions$ = Xml_SingleLine(GetXMLAttribute(*Entry, "value"))