1 | unit ULDModuleProject;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, ActnList, Menus, Dialogs, UModularSystem,
|
---|
9 | ULastOpenedList, UProject, URegistry, USource;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TDataModuleProject }
|
---|
14 |
|
---|
15 | TDataModuleProject = class(TDataModule)
|
---|
16 | AClose: TAction;
|
---|
17 | AProjectManager: TAction;
|
---|
18 | ASaveAs: TAction;
|
---|
19 | ASave: TAction;
|
---|
20 | AOpenRecent: TAction;
|
---|
21 | AOpen: TAction;
|
---|
22 | ANew: TAction;
|
---|
23 | ActionList1: TActionList;
|
---|
24 | LastOpenedList1: TLastOpenedList;
|
---|
25 | MenuItem1: TMenuItem;
|
---|
26 | MenuItem2: TMenuItem;
|
---|
27 | MenuItemOpenRecent: TMenuItem;
|
---|
28 | MenuItem4: TMenuItem;
|
---|
29 | MenuItem5: TMenuItem;
|
---|
30 | MenuItem6: TMenuItem;
|
---|
31 | MenuItem7: TMenuItem;
|
---|
32 | MenuItem8: TMenuItem;
|
---|
33 | OpenDialog1: TOpenDialog;
|
---|
34 | PopupMenu1: TPopupMenu;
|
---|
35 | SaveDialog1: TSaveDialog;
|
---|
36 | procedure ACloseExecute(Sender: TObject);
|
---|
37 | procedure ANewExecute(Sender: TObject);
|
---|
38 | procedure AOpenExecute(Sender: TObject);
|
---|
39 | procedure AOpenRecentExecute(Sender: TObject);
|
---|
40 | procedure AProjectManagerExecute(Sender: TObject);
|
---|
41 | procedure ASaveAsExecute(Sender: TObject);
|
---|
42 | procedure ASaveExecute(Sender: TObject);
|
---|
43 | procedure DataModuleCreate(Sender: TObject);
|
---|
44 | procedure DataModuleDestroy(Sender: TObject);
|
---|
45 | procedure LastOpenedList1Change(Sender: TObject);
|
---|
46 | private
|
---|
47 | { private declarations }
|
---|
48 | public
|
---|
49 | Project: TProject;
|
---|
50 | procedure UpdateInterface;
|
---|
51 | procedure LoadFromRegistry(Context: TRegistryContext);
|
---|
52 | procedure SaveToRegistry(Context: TRegistryContext);
|
---|
53 | end;
|
---|
54 |
|
---|
55 | { TLDModuleProject }
|
---|
56 |
|
---|
57 | TLDModuleProject = class(TModule)
|
---|
58 | private
|
---|
59 | ProjectFileType: TSourceType;
|
---|
60 | public
|
---|
61 | constructor Create(Owner: TComponent); override;
|
---|
62 | procedure Install; override;
|
---|
63 | procedure Uninstall; override;
|
---|
64 | end;
|
---|
65 |
|
---|
66 | var
|
---|
67 | DataModuleProject: TDataModuleProject;
|
---|
68 |
|
---|
69 |
|
---|
70 | implementation
|
---|
71 |
|
---|
72 | uses
|
---|
73 | ULDStudioAPI, UFormProject;
|
---|
74 |
|
---|
75 | resourcestring
|
---|
76 | SProject = 'Project';
|
---|
77 |
|
---|
78 | { TDataModuleProject }
|
---|
79 |
|
---|
80 | procedure TDataModuleProject.AProjectManagerExecute(Sender: TObject);
|
---|
81 | begin
|
---|
82 | FormProject.Show;
|
---|
83 | end;
|
---|
84 |
|
---|
85 | procedure TDataModuleProject.ASaveAsExecute(Sender: TObject);
|
---|
86 | begin
|
---|
87 | SaveDialog1.FileName := Project.FileName;
|
---|
88 | if SaveDialog1.Execute then begin
|
---|
89 | Project.FileName := SaveDialog1.FileName;
|
---|
90 | Project.Save;
|
---|
91 | UpdateInterface;
|
---|
92 | end;
|
---|
93 | end;
|
---|
94 |
|
---|
95 | procedure TDataModuleProject.ASaveExecute(Sender: TObject);
|
---|
96 | begin
|
---|
97 | if Project.Modified then ASaveAs.Execute
|
---|
98 | else Project.Save;
|
---|
99 | UpdateInterface;
|
---|
100 | end;
|
---|
101 |
|
---|
102 | procedure TDataModuleProject.DataModuleCreate(Sender: TObject);
|
---|
103 | begin
|
---|
104 |
|
---|
105 | end;
|
---|
106 |
|
---|
107 | procedure TDataModuleProject.DataModuleDestroy(Sender: TObject);
|
---|
108 | begin
|
---|
109 | AClose.Execute;
|
---|
110 | end;
|
---|
111 |
|
---|
112 | procedure TDataModuleProject.LastOpenedList1Change(Sender: TObject);
|
---|
113 | begin
|
---|
114 | LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, AOpenRecentExecute);
|
---|
115 | end;
|
---|
116 |
|
---|
117 | procedure TDataModuleProject.UpdateInterface;
|
---|
118 | begin
|
---|
119 | ASave.Enabled := Assigned(Project) and Project.Modified;
|
---|
120 | ASaveAs.Enabled := Assigned(Project);
|
---|
121 | AClose.Enabled := Assigned(Project);
|
---|
122 | end;
|
---|
123 |
|
---|
124 | procedure TDataModuleProject.LoadFromRegistry(Context: TRegistryContext);
|
---|
125 | begin
|
---|
126 | LastOpenedList1.LoadFromRegistry(RegContext(Context.RootKey, Context.Key + '\RecentFile'));
|
---|
127 | end;
|
---|
128 |
|
---|
129 | procedure TDataModuleProject.SaveToRegistry(Context: TRegistryContext);
|
---|
130 | begin
|
---|
131 | LastOpenedList1.SaveToRegistry(RegContext(Context.RootKey, Context.Key + '\RecentFile'));
|
---|
132 | end;
|
---|
133 |
|
---|
134 | procedure TDataModuleProject.ACloseExecute(Sender: TObject);
|
---|
135 | begin
|
---|
136 | if Assigned(Project) then begin
|
---|
137 | if Project.Modified then ASaveAs.Execute;
|
---|
138 | FreeAndNil(Project);
|
---|
139 | UpdateInterface;
|
---|
140 | end;
|
---|
141 | end;
|
---|
142 |
|
---|
143 | procedure TDataModuleProject.ANewExecute(Sender: TObject);
|
---|
144 | begin
|
---|
145 | Project := TProject.Create;
|
---|
146 | UpdateInterface;
|
---|
147 | end;
|
---|
148 |
|
---|
149 | procedure TDataModuleProject.AOpenExecute(Sender: TObject);
|
---|
150 | begin
|
---|
151 | if Assigned(Project) then
|
---|
152 | OpenDialog1.FileName := Project.FileName;
|
---|
153 | if OpenDialog1.Execute then begin
|
---|
154 | Project.FileName := OpenDialog1.FileName;
|
---|
155 | Project.Load;
|
---|
156 | UpdateInterface;
|
---|
157 | end;
|
---|
158 | end;
|
---|
159 |
|
---|
160 | procedure TDataModuleProject.AOpenRecentExecute(Sender: TObject);
|
---|
161 | begin
|
---|
162 |
|
---|
163 | end;
|
---|
164 |
|
---|
165 | { TLDModuleProject }
|
---|
166 |
|
---|
167 | constructor TLDModuleProject.Create(Owner: TComponent);
|
---|
168 | begin
|
---|
169 | inherited;
|
---|
170 | Identification := 'Project';
|
---|
171 | Title := SProject;
|
---|
172 | Version := '0.1';
|
---|
173 | License := 'GNU/LGPLv3';
|
---|
174 | Dependencies.Add('Basic');
|
---|
175 | end;
|
---|
176 |
|
---|
177 | procedure TLDModuleProject.Install;
|
---|
178 | begin
|
---|
179 | with TLDStudioAPI(API) do begin
|
---|
180 | DataModuleProject := TDataModuleProject.Create(nil);
|
---|
181 | FormProject := TFormProject.Create(nil);
|
---|
182 | FormProject.API := TLDStudioAPI(API);
|
---|
183 | DockForm(FormProject, dtRight);
|
---|
184 | DataModuleProject.PopupMenu1.Items.Caption := SProject;
|
---|
185 | RegisterMainMenuItem(DataModuleProject.PopupMenu1.Items, nil, 1);
|
---|
186 | DataModuleProject.LoadFromRegistry(RegContext(GetRegistryContext.RootKey,
|
---|
187 | GetRegistryContext.Key + '\Project'));
|
---|
188 | DataModuleProject.UpdateInterface;
|
---|
189 | ProjectFileType := TSourceType.Create;
|
---|
190 | ProjectFileType.Extension := '.ldp';
|
---|
191 | ProjectFileType.Title := 'LibreDevelop project';
|
---|
192 | RegisterFileType(ProjectFileType);
|
---|
193 | end;
|
---|
194 | inherited;
|
---|
195 | end;
|
---|
196 |
|
---|
197 | procedure TLDModuleProject.Uninstall;
|
---|
198 | begin
|
---|
199 | inherited;
|
---|
200 | with TLDStudioAPI(API) do begin
|
---|
201 | UnregisterFileType(ProjectFileType);
|
---|
202 | FreeAndNil(ProjectFileType);
|
---|
203 | DataModuleProject.SaveToRegistry(RegContext(GetRegistryContext.RootKey,
|
---|
204 | GetRegistryContext.Key + '\Project'));
|
---|
205 | UnregisterMainMenuItem(DataModuleProject.PopupMenu1.Items);
|
---|
206 | FreeAndNil(DataModuleProject);
|
---|
207 | FreeAndNil(FormProject);
|
---|
208 | end;
|
---|
209 | end;
|
---|
210 |
|
---|
211 | {$R *.lfm}
|
---|
212 |
|
---|
213 | end.
|
---|
214 |
|
---|