-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIdeUnit.pas
134 lines (115 loc) · 2.84 KB
/
IdeUnit.pas
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
unit IdeUnit;
interface
uses
Classes, Types, SynEdit;
type
TIDEUnit = class
private
FSavePath: string;
FCaption: string;
FImageIndex: Integer;
FSourceLink: TStrings;
FOnRename: TNotifyEvent;
FExtension: string;
FOnAfterSave: TNotifyEvent;
FOnAfterLoad: TNotifyEvent;
function GetFileName: string;
procedure DoOnRename();
procedure SetSourceLink(const Value: TStrings);
procedure SetCaption(const Value: string);
procedure SetFileName(const Value: string);
procedure DoAfterLoad();
procedure DoAfterSave();
function GetIsOpen: Boolean;
public
constructor Create();
destructor Destroy(); override;
procedure Save();
procedure Load();
property Caption: string read FCaption write SetCaption;
property SavePath: string read FSavePath write FSavePath;
property FileName: string read GetFileName write SetFileName;
property ImageIndex: Integer read FImageIndex write FImageIndex;
property SourceLink: TStrings read FSourceLink write SetSourceLink;
property OnRename: TNotifyEvent read FOnRename write FOnRename;
property IsOpen: Boolean read GetIsOpen;
property OnAfterSave: TNotifyEvent read FOnAfterSave write FOnAfterSave;
property OnAfterLoad: TNotifyEvent read FOnAfterLoad write FOnAfterLoad;
end;
implementation
uses
Windows, SysUtils;
{ TIDEUnit }
constructor TIDEUnit.Create;
begin
FExtension := '.pas';
end;
destructor TIDEUnit.Destroy;
begin
inherited;
end;
procedure TIDEUnit.DoAfterLoad;
begin
if Assigned(FOnAfterLoad) then
begin
FOnAfterLoad(Self);
end;
end;
procedure TIDEUnit.DoAfterSave;
begin
if Assigned(FOnAfterSave) then
begin
FOnAfterSave(Self);
end;
end;
procedure TIDEUnit.DoOnRename;
begin
if Assigned(FOnRename) then
begin
FOnRename(Self);
end;
end;
function TIDEUnit.GetFileName: string;
begin
Result := ChangeFileExt(IncludeTrailingBackslash(FSavePath) + FCaption, FExtension);
end;
function TIDEUnit.GetIsOpen: Boolean;
begin
Result := Assigned(FSourceLink);
end;
procedure TIDEUnit.Load;
begin
if IsOpen then
begin
FSourceLink.LoadFromFile(FileName);
DoAfterLoad();
end;
end;
procedure TIDEUnit.Save;
begin
if IsOpen then
begin
FSourceLink.SaveToFile(FileName);
DoAfterSave();
end;
end;
procedure TIDEUnit.SetCaption(const Value: string);
begin
FCaption := Value;
DoOnRename();
end;
procedure TIDEUnit.SetFileName(const Value: string);
begin
FSavePath := ExtractFilePath(Value);
Caption := ChangeFileExt(ExtractFileName(Value), '');
FExtension := ExtractFileExt(Value);
end;
procedure TIDEUnit.SetSourceLink(const Value: TStrings);
begin
FSourceLink := Value;
if FileExists(FileName) then
begin
Load();
end;
end;
end.