source: trunk/StudioModules/LDModuleProject/ULDModuleProject.pas

Last change on this file was 18, checked in by chronos, 12 years ago
  • Used external packages are now stored in uncompressed form rather in zipped files. This allow better package version synchronisation.
File size: 5.5 KB
Line 
1unit ULDModuleProject;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, ActnList, Menus, Dialogs, UModularSystem,
9 ULastOpenedList, UProject, URegistry, USource;
10
11type
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
66var
67 DataModuleProject: TDataModuleProject;
68
69
70implementation
71
72uses
73 ULDStudioAPI, UFormProject;
74
75resourcestring
76 SProject = 'Project';
77
78{ TDataModuleProject }
79
80procedure TDataModuleProject.AProjectManagerExecute(Sender: TObject);
81begin
82 FormProject.Show;
83end;
84
85procedure TDataModuleProject.ASaveAsExecute(Sender: TObject);
86begin
87 SaveDialog1.FileName := Project.FileName;
88 if SaveDialog1.Execute then begin
89 Project.FileName := SaveDialog1.FileName;
90 Project.Save;
91 UpdateInterface;
92 end;
93end;
94
95procedure TDataModuleProject.ASaveExecute(Sender: TObject);
96begin
97 if Project.Modified then ASaveAs.Execute
98 else Project.Save;
99 UpdateInterface;
100end;
101
102procedure TDataModuleProject.DataModuleCreate(Sender: TObject);
103begin
104
105end;
106
107procedure TDataModuleProject.DataModuleDestroy(Sender: TObject);
108begin
109 AClose.Execute;
110end;
111
112procedure TDataModuleProject.LastOpenedList1Change(Sender: TObject);
113begin
114 LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, AOpenRecentExecute);
115end;
116
117procedure TDataModuleProject.UpdateInterface;
118begin
119 ASave.Enabled := Assigned(Project) and Project.Modified;
120 ASaveAs.Enabled := Assigned(Project);
121 AClose.Enabled := Assigned(Project);
122end;
123
124procedure TDataModuleProject.LoadFromRegistry(Context: TRegistryContext);
125begin
126 LastOpenedList1.LoadFromRegistry(RegContext(Context.RootKey, Context.Key + '\RecentFile'));
127end;
128
129procedure TDataModuleProject.SaveToRegistry(Context: TRegistryContext);
130begin
131 LastOpenedList1.SaveToRegistry(RegContext(Context.RootKey, Context.Key + '\RecentFile'));
132end;
133
134procedure TDataModuleProject.ACloseExecute(Sender: TObject);
135begin
136 if Assigned(Project) then begin
137 if Project.Modified then ASaveAs.Execute;
138 FreeAndNil(Project);
139 UpdateInterface;
140 end;
141end;
142
143procedure TDataModuleProject.ANewExecute(Sender: TObject);
144begin
145 Project := TProject.Create;
146 UpdateInterface;
147end;
148
149procedure TDataModuleProject.AOpenExecute(Sender: TObject);
150begin
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;
158end;
159
160procedure TDataModuleProject.AOpenRecentExecute(Sender: TObject);
161begin
162
163end;
164
165{ TLDModuleProject }
166
167constructor TLDModuleProject.Create(Owner: TComponent);
168begin
169 inherited;
170 Identification := 'Project';
171 Title := SProject;
172 Version := '0.1';
173 License := 'GNU/LGPLv3';
174 Dependencies.Add('Basic');
175end;
176
177procedure TLDModuleProject.Install;
178begin
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;
195end;
196
197procedure TLDModuleProject.Uninstall;
198begin
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;
209end;
210
211{$R *.lfm}
212
213end.
214
Note: See TracBrowser for help on using the repository browser.