ce_synmemo: support for external modification tracking

This commit is contained in:
Basile Burg 2014-07-16 18:15:18 +02:00
parent a1fbd92fdb
commit 2cc2ad3b9d
2 changed files with 39 additions and 4 deletions

View File

@ -121,7 +121,11 @@ begin
curr := getCurrentEditor;
macRecorder.Editor := curr;
fSyncEdit.Editor := curr;
identifierToD2Syn(curr);
if curr <> nil then
begin
identifierToD2Syn(curr);
curr.checkFileDate;
end;
//
if pageControl.ActivePageIndex <> -1 then
mainForm.docFocusedNotify(Self, pageControl.ActivePageIndex);

View File

@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils, SynEdit, SynMemo, ce_d2syn,
SynPluginSyncroEdit, SynEditKeyCmds, ce_project;
SynPluginSyncroEdit, SynEditKeyCmds, ce_project, ce_common;
type
@ -14,13 +14,17 @@ type
private
fFilename: string;
fModified: boolean;
fNoDateCheck: boolean;
fFileDate: double;
fAssocProject: TCEProject;
function getIfDSource: Boolean;
function getIfConfig: Boolean;
procedure setFilename(const aValue: string);
public
constructor Create(aOwner: TComponent); override;
procedure checkFileDate;
//
property fileName: string read fFilename write fFilename;
property fileName: string read fFilename write setFilename;
property modified: boolean read fModified write fModified;
property project: TCEProject read fAssocProject write fAssocProject;
//
@ -34,7 +38,7 @@ var
implementation
uses
graphics, ce_main;
graphics, ce_main, controls;
constructor TCESynMemo.Create(aOwner: TComponent);
begin
@ -57,6 +61,33 @@ begin
Highlighter := D2Syn;
end;
procedure TCESynMemo.setFilename(const aValue: string);
begin
if fFilename = aValue then exit;
fNoDateCheck := false;
fFilename := aValue;
FileAge(fFilename, fFileDate);
end;
procedure TCESynMemo.checkFileDate;
var
newDate: double;
begin
if not FileAge(fFilename, newDate) then exit;
if fFileDate = newDate then exit;
if fFileDate <> 0.0 then
begin
if dlgOkCancel(format('"%s" has been modified by another program, load the new version ?',
[shortenPath(fFilename)])) = mrOk then
begin
Lines.LoadFromFile(fFilename);
fModified := false;
end
else fNoDateCheck := true;
end;
fFileDate := newDate;
end;
function TCESynMemo.getIfDSource: Boolean;
begin
exit(Highlighter = D2Syn);