Skip to content

Commit ceec9d2

Browse files
Rico-Rodriguezollydev
authored andcommitted
Add external file change detection before Run/Compile
1 parent 6e7f95b commit ceec9d2

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Source/ide/simba.form_tabs.pas

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ TSimbaTabsForm = class(TForm)
8989
procedure Find;
9090
procedure FindNext;
9191
procedure FindPrevious;
92+
function CheckForFileChanges: Boolean;
9293

9394
function AddTab: TSimbaScriptTab;
9495
function FindTab(ID: Integer): TSimbaScriptTab;
@@ -523,6 +524,28 @@ procedure TSimbaTabsForm.FindPrevious;
523524
FEditorFind.FindPrev(CurrentEditor);
524525
end;
525526

527+
function TSimbaTabsForm.CheckForFileChanges: Boolean;
528+
var
529+
Tab: TSimbaScriptTab;
530+
begin
531+
Result := False;
532+
Tab := CurrentTab;
533+
if (Tab = nil) or (Tab.ScriptFileName = '') or (not FileExists(Tab.ScriptFileName)) then
534+
Exit;
535+
536+
if (FileDateToDateTime(FileAge(Tab.ScriptFileName)) > Tab.DiskAge) then
537+
begin
538+
if MessageDlg('File "' + Tab.ScriptFileName + '" has changed on disk.' + sLineBreak + 'Do you want to reload it?',
539+
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
540+
begin
541+
Tab.Load(Tab.ScriptFileName);
542+
Result := True;
543+
end
544+
else
545+
Tab.UpdateDiskAge();
546+
end;
547+
end;
548+
526549
function TSimbaTabsForm.AddTab: TSimbaScriptTab;
527550
begin
528551
Result := FTabControl.AddTab() as TSimbaScriptTab;

Source/ide/simba.ide_tab.pas

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,13 @@ TSimbaScriptTab = class(TSimbaTab)
8484
FSavedText: String;
8585
FScriptFileName: String;
8686
FScriptTitle: String;
87+
FDiskAge: TDateTime;
8788

8889
FScriptRunner: TSimbaScriptTabRunner;
8990

9091
FOutputBox: TSimbaOutputBox;
9192

93+
procedure UpdateDiskAge;
9294
procedure LoadDefaultScript;
9395
procedure FindDeclarationAtCaretASync(Data: PtrInt);
9496

@@ -114,7 +116,9 @@ TSimbaScriptTab = class(TSimbaTab)
114116
property ScriptChanged: Boolean read GetScriptChanged;
115117
property Script: String read GetScript;
116118
property Editor: TSimbaEditor read FEditor;
119+
property DiskAge: TDateTime read FDiskAge;
117120

121+
procedure UpdateDiskAge;
118122
function SaveAsDialog: String;
119123

120124
function Save(FileName: String): Boolean;
@@ -342,6 +346,14 @@ function TSimbaScriptTab.GetScriptChanged: Boolean;
342346
Result := FEditor.Text <> FSavedText;
343347
end;
344348

349+
procedure TSimbaScriptTab.UpdateDiskAge;
350+
begin
351+
if (FScriptFileName <> '') and FileExists(FScriptFileName) then
352+
FDiskAge := FileDateToDateTime(FileAge(FScriptFileName))
353+
else
354+
FDiskAge := 0;
355+
end;
356+
345357
procedure TSimbaScriptTab.LoadDefaultScript;
346358
begin
347359
case SimbaSettings.Editor.DefaultScriptType.Value of
@@ -460,6 +472,7 @@ function TSimbaScriptTab.Save(FileName: String): Boolean;
460472
FScriptTitle := FScriptTitle.Before('.simba');
461473

462474
Caption := FScriptTitle;
475+
UpdateDiskAge();
463476
end;
464477

465478
function TSimbaScriptTab.Load(FileName: String): Boolean;
@@ -490,6 +503,7 @@ function TSimbaScriptTab.Load(FileName: String): Boolean;
490503
FScriptTitle := FScriptTitle.Before('.simba');
491504

492505
Caption := FScriptTitle;
506+
UpdateDiskAge();
493507
if Result then
494508
SimbaIDEEvents.Notify(SimbaIDEEvent.TAB_LOADED, Self);
495509
end;
@@ -573,6 +587,9 @@ procedure TSimbaScriptTab.Run(Target: TWindowHandle);
573587
begin
574588
//DebugLn('TSimbaScriptTab.Run :: ' + ScriptTitle + ' ' + ScriptFileName);
575589

590+
if SimbaTabsForm.CheckForFileChanges() then
591+
Exit;
592+
576593
if (FScriptRunner <> nil) then
577594
FScriptRunner.Resume()
578595
else
@@ -592,6 +609,9 @@ procedure TSimbaScriptTab.Compile;
592609
begin
593610
//DebugLn('TSimbaScriptTab.Compile :: ' + ScriptTitle + ' ' + ScriptFileName);
594611

612+
if SimbaTabsForm.CheckForFileChanges() then
613+
Exit;
614+
595615
if (FScriptRunner = nil) then
596616
begin
597617
if (not FEditor.ReadOnly) and (FScriptFileName <> '') then

0 commit comments

Comments
 (0)