-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsitemenusunit1.pas
254 lines (217 loc) · 7.28 KB
/
websitemenusunit1.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
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
{==============================================================================}
{ Copyright (c) 2010, 2011, 2012 by Donald R. Ziesig. All Rights Reserved. }
{==============================================================================}
{ This file is part of MagicWebsiteBuilder. }
{ }
{ MagicWebsiteBuilder is free software: you can redistribute it and/or modify }
{ it under the terms of the GNU General Public License as published by }
{ the Free Software Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ }
{ MagicWebsiteBuilder is distributed in the hope that it will be useful, }
{ but WITHOUT ANY WARRANTY; without even the implied warranty of }
{ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the }
{ GNU General Public License for more details. }
{ }
{ You should have received a copy of the GNU General Public License }
{ along with MagicWebsiteBuilder in file COPYING. If not, see }
{ <http://www.gnu.org/licenses/>. }
{==============================================================================}
unit WebsiteMenusUnit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
Persists1, TextIO1,
WebsiteRootUnit1, GeneralCSSUnit1, MenuCSSUnit1, IDXHdrFtrUnit1,
TCWMenuUnit1;
type
{ TWebsiteMenuData }
TWebsiteMenuData = class( TWebsiteRoot )
private
procedure SetMenuPosition(const AValue: String);
protected
fMenuPosition : String; // String because the secondary menu's
// position list varies based on the primary
// menu's position.
fGeneralCSSData : TGeneralCSSData;
fMenuCSSData : TMenuCSSData;
fIDXHdrFtrData : TIDXHdrFtr;
fTCWMenuData : TTCWMenuData;
public
procedure MakeNew; override;
procedure Save( TextIO : TTextIO ); override;
procedure Read( TextIO : TTextIO; Version : Integer ); override;
procedure BuildVarlist; override;
function Find(Variable : String; var Gotit : Boolean ) :String; override;
function IsModified : Boolean; override;
property MenuPosition : String read fMenuPosition write SetMenuPosition;
property GeneralCSSData : TGeneralCSSData read fGeneralCSSData;
property MenuCSSData : TMenuCSSData read fMenuCSSData;
property IDXHdrFtrData : TIDXHdrFtr read fIDXHdrFtrData;
property TCWMenuData : TTCWMenuData read fTCWMenuData;
end;
{ TWebsiteMenusData }
TWebsiteMenusData = class( TWebsiteRoot )
private
protected
fPrimaryMenu : TWebsiteMenuData;
fSecondaryMenu : TWebsiteMenuData;
public
procedure MakeNew; override;
procedure Save( TextIO : TTextIO ); override;
procedure Read( TextIO : TTextIO; Version : Integer ); override;
function IsModified : Boolean; override;
procedure BuildVarlist; override;
property PrimaryMenu : TWebsiteMenuData read fPrimaryMenu;
property SecondaryMenu : TWebsiteMenuData read fSecondaryMenu;
end;
implementation
uses
ObjectFactory1, Common1, NamedFunctionUnit1, StringSubs;
const
MenuVersion = 5;
{ TWebsiteMenuData }
procedure TWebsiteMenuData.SetMenuPosition(const AValue: String);
begin
if Empty(fMenuPosition) then
fMenuPosition := AValue
else
Update(fMenuPosition,AValue);
end;
procedure TWebsiteMenuData.BuildVarList;
begin
inherited;
end;
function TWebsiteMenuData.Find(Variable: String; var Gotit: Boolean): String;
begin
Result := fGeneralCSSData.Find( Variable, GotIt );
if not GotIt then
Result := fMenuCSSData.Find( Variable, GotIt );
if not GotIt then
Result := fIDXHdrFtrData.Find( Variable, GotIt );
if not GotIt then
Result := fTCWMenuData.Find( Variable, GotIt );
end;
procedure TWebsiteMenuData.MakeNew;
begin
inherited MakeNew;
if fName = 'PrimaryMenu' then
fMenuPosition := 'Top'
else if fName = 'SecondaryMenu' then
fMenuPosition := 'None'
else
fMenuPosition := ''; // Empty string is undefined
fGeneralCSSData := TGeneralCSSData.Create( Parent, Name, self );
fMenuCSSData := TMenuCssData.Create( Parent, Name, self );
fIDXHdrFtrData := TIDXHdrFtr.Create( Parent, Name, self );
fTCWMenuData := TTCWMenuData.Create( Parent, Name, self );
fModified := False;
end;
procedure TWebsiteMenuData.Save(TextIO: TTextIO);
begin
SaveHeader( TextIO, MenuVersion );
TextIO.WriteLn( fMenuPosition );
// MenuVersion 2
fGeneralCSSData.Save( TextIO );
// MenuVersion 3
fMenuCssData.Save( TextIO );
// MenuVersion 4
fIDXHdrFtrData.Save( TextIO );
// MenuVersion 5
fTCWMenuData.Save( TextIO );
UNMODIFY;
SaveTrailer( TextIO );
end;
procedure TWebsiteMenuData.Read(TextIO: TTextIO; Version: Integer);
var
T : TPersists;
N : String;
begin
MakeNew;
if Version >= 1 then
begin
TextIO.ReadLn( fMenuPosition );
end;
if Version >= 2 then
begin
fGeneralCSSData.Free;
fGeneralCSSData := TGeneralCSSData.Load( TextIO ) as TGeneralCSSData;
// fGeneralCSSData.Name := 'GeneralCSSData';
fGeneralCSSData.RootMenu := self;
end;
if Version >= 3 then
begin
fMenuCssData.Free;
fMenuCssData := TMenuCSSData.Load( TextIO ) as TMenuCSSData;
// fMenuCSSData.Name := 'MenuCSSData';
fMenuCssData.RootMenu := self;
end;
if Version >= 4 then
begin
fIDXHdrFtrData.Free;
fIDXHdrFtrData := TIDXHdrFtr.Load( TextIO ) as TIDXHdrFtr;
// fIDXHdrFtrData.Name := 'IDXHdrFtrData';
fIDXHdrFtrData.RootMenu := self;
end;
if Version >= 5 then
begin
fTCWMenuData.Free;
// fTCWMenuData := TTCWMenuData.Load( TextIO ) as TTCWMenuData;
T := TTCWMenuData.Load( TextIO );
N := T.ClassName;
fTCWMenuData := T as TTCWMenuData;
// fTCWMenuData.Name := 'TCWMenuData';
fTCWMenuData.RootMenu := self;
end;
end;
function TWebsiteMenuData.IsModified: Boolean;
begin
Result:=inherited IsModified;
Result := Result or fGeneralCSSData.Modified;
Result := Result or fMenuCSSData.Modified;
Result := Result or fIDXHdrFtrData.Modified;
Result := Result or fTCWMenuData.Modified;
end;
{ TWebsiteMenusData }
const
MenusVersion = 1;
procedure TWebsiteMenusData.MakeNew;
begin
inherited MakeNew;
fPrimaryMenu := TWebsiteMenuData.Create( Parent, 'PrimaryMenu' );
fSecondaryMenu := TWebsiteMenuData.Create( Parent, 'SecondaryMenu' );
BuildVarlist;
end;
procedure TWebsiteMenusData.Save(TextIO: TTextIO);
begin
SaveHeader( TextIO, MenusVersion );
fPrimaryMenu.Save( TextIO );
fSecondaryMenu.Save( TextIO );
SaveTrailer( TextIO );
end;
procedure TWebsiteMenusData.Read(TextIO: TTextIO; Version: Integer);
begin
MakeNew;
if Version >= 1 then
begin
fPrimaryMenu.Free;
fSecondaryMenu.Free;
fPrimaryMenu := TWebsiteMenuData.Load( TextIO ) as TWebsiteMenuData;
fSecondaryMenu := TWebsiteMenuData.Load( TextIO ) as TWebsiteMenuData;
end;
end;
function TWebsiteMenusData.IsModified: Boolean;
begin
Result:=inherited IsModified;
Result := Result or PrimaryMenu.Modified;
Result := Result or SecondaryMenu.Modified;;
end;
procedure TWebsiteMenusData.BuildVarlist;
begin
inherited;
end;
initialization
ObjectFactory.RegisterClass( TWebsiteMenusData );
ObjectFactory.RegisterClass( TWebsiteMenuData );
end.