Changeset 66 for branches/Transpascal/Forms/UMainForm.pas
- Timestamp:
- Oct 18, 2010, 10:00:00 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Transpascal/Forms/UMainForm.pas
r64 r66 7 7 uses 8 8 SysUtils, Variants, Classes, Graphics, Controls, Forms, 9 Dialogs, StdCtrls, UCompiler, UProducerAsm8051, 9 Dialogs, StdCtrls, UCompiler, UProducerAsm8051, Registry, 10 10 UProducerC, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas, UProducerTreeView, 11 11 UProducerPascal, Contnrs, UProject, FileUtil, Menus, ActnList, UCoolDocking, 12 UCompiledForm, UCodeTreeForm ;12 UCompiledForm, UCodeTreeForm, URegistry, ULastOpenedList, UApplicationInfo; 13 13 14 14 const 15 ProjectDir = '../../Project/'; 15 RegistryRootKey = HKEY_CURRENT_USER; 16 RegistryKey = 'Software\Transpascal'; 16 17 17 18 type … … 40 41 MenuItem8: TMenuItem; 41 42 DockPanel: TPanel; 43 MenuItemOpenRecent: TMenuItem; 44 OpenDialog1: TOpenDialog; 45 SaveDialog1: TSaveDialog; 42 46 Splitter3: TSplitter; 43 47 ToolBar1: TToolBar; 48 procedure AProjectOpenExecute(Sender: TObject); 49 procedure AProjectSaveAsExecute(Sender: TObject); 44 50 procedure ComboBox1Change(Sender: TObject); 45 51 procedure ComboBoxTargetSelectionChange(Sender: TObject); … … 50 56 procedure FormDestroy(Sender: TObject); 51 57 private 58 LastOpenedFiles: TLastOpenedList; 59 ReopenLastOpenedFile: Boolean; 60 procedure OpenRecentClick(Sender: TObject); 52 61 procedure LoadErrorMessages; 53 procedure UpdateProjectTree;54 procedure UpdateProjectGroup(Node: TTreeNode; Group: TProjectGroup);55 62 procedure DockInit; 63 procedure LoadFromRegistry; 64 procedure SaveToRegistry; 65 procedure OpenProject(FileName: string); 56 66 public 57 67 Project: TProject; … … 96 106 Compiler.Init; 97 107 Compiler.Parser.OnGetSource := GetSource; 108 if Project.Items.Count > 0 then 98 109 with TProjectFile(Project.Items[0]) do begin 99 110 Compiler.Compile(Parent.GetDir + Name, Source); … … 117 128 end; 118 129 119 procedure TMainForm.UpdateProjectTree;120 var121 NewNode: TTreeNode;122 begin123 with ProjectManager, TreeViewProject, Items do begin124 BeginUpdate;125 Clear;126 NewNode := AddChild(nil, Project.Name);127 UpdateProjectGroup(NewNode, Project);128 NewNode.Expand(True);129 EndUpdate;130 TreeViewProject.TopItem.Items[0].Selected := True;131 end;132 end;133 134 procedure TMainForm.UpdateProjectGroup(Node: TTreeNode; Group: TProjectGroup);135 var136 I: Integer;137 NewNode: TTreeNode;138 begin139 with ProjectManager do140 for I := 0 to Group.Items.Count - 1 do begin141 NewNode := TreeViewProject.Items.AddChild(Node,142 TProjectNode(Group.Items[I]).Name);143 NewNode.Data := Pointer(Group.Items[I]);144 if TProjectNode(Group.Items[I]) is TProjectGroup then145 UpdateProjectGroup(NewNode, TProjectGroup(Group.Items[I]));146 end;147 end;148 149 130 function TMainForm.GetSource(Name: string; Source: TStringList): Boolean; 150 131 var … … 195 176 end; 196 177 178 procedure TMainForm.LoadFromRegistry; 179 begin 180 with TRegistryEx.Create do 181 try 182 RootKey := HKEY_CURRENT_USER; 183 OpenKey(RegistryKey, True); 184 ReopenLastOpenedFile := ReadBoolWithDefault('ReopenLastOpenedFile', True); 185 finally 186 Free; 187 end; 188 LastOpenedFiles.LoadFromRegistry(RegistryRootKey, RegistryKey); 189 end; 190 191 procedure TMainForm.SaveToRegistry; 192 begin 193 with TRegistryEx.Create do 194 try 195 RootKey := RegistryRootKey; 196 OpenKey(RegistryKey, True); 197 WriteBool('ReopenLastOpenedFile', ReopenLastOpenedFile); 198 finally 199 Free; 200 end; 201 LastOpenedFiles.SaveToRegistry(RegistryRootKey, RegistryKey); 202 LastOpenedFiles.ReloadMenu; 203 end; 204 205 procedure TMainForm.OpenProject(FileName: string); 206 begin 207 Project.LoadFromFile(FileName); 208 LastOpenedFiles.Add(FileName); 209 LastOpenedFiles.ReloadMenu; 210 ProjectManager.UpdateProjectTree; 211 Caption := ApplicationInfo.Name + ' - ' + Project.Name; 212 end; 213 197 214 procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction); 198 215 begin 199 216 Project.Save; 217 SaveToRegistry; 200 218 end; 201 219 … … 204 222 Compiler := TCompiler.Create; 205 223 Project := TProject.Create; 224 LastOpenedFiles := TLastOpenedList.Create; 225 LastOpenedFiles.MenuItem := MenuItemOpenRecent; 226 LastOpenedFiles.ClickAction := OpenRecentClick; 206 227 end; 207 228 208 229 procedure TMainForm.FormDestroy(Sender: TObject); 209 230 begin 231 LastOpenedFiles.Free; 210 232 Project.Free; 211 233 Compiler.Free; 212 234 end; 213 235 236 procedure TMainForm.OpenRecentClick(Sender: TObject); 237 begin 238 if Sender is TMenuItem then 239 OpenProject(StringReplace(TMenuItem(Sender).Caption, '&', '', [rfReplaceAll])); 240 end; 241 214 242 procedure TMainForm.FormShow(Sender: TObject); 215 243 var 216 244 NewProjectFile: TProjectFile; 217 245 begin 246 LoadFromRegistry; 218 247 DockInit; 219 248 220 Project.RootDir := '../../Project/'; 221 Project.Name := 'Project'; 222 223 NewProjectFile := TProjectFile.Create; 224 NewProjectFile.Parent := Project; 225 NewProjectFile.Name := 'Project.pas'; 226 Project.Items.Add(NewProjectFile); 227 228 NewProjectFile := TProjectFile.Create; 229 NewProjectFile.Parent := Project; 230 NewProjectFile.Name := 'System.pas'; 231 Project.Items.Add(NewProjectFile); 232 233 NewProjectFile := TProjectFile.Create; 234 NewProjectFile.Parent := Project; 235 NewProjectFile.Name := 'MemoryManager.pas'; 236 Project.Items.Add(NewProjectFile); 237 238 Project.Load; 239 UpdateProjectTree; 249 if ReopenLastOpenedFile and (LastOpenedFiles.Count > 0) then begin 250 OpenProject(LastOpenedFiles[0]); 251 end; 240 252 241 253 WindowState := wsMaximized; 254 end; 255 256 procedure TMainForm.ComboBox1Change(Sender: TObject); 257 begin 242 258 ButtonCompileClick(Self); 243 259 end; 244 260 245 procedure TMainForm.ComboBox1Change(Sender: TObject); 261 procedure TMainForm.AProjectOpenExecute(Sender: TObject); 262 begin 263 if OpenDialog1.Execute then begin 264 OpenProject(OpenDialog1.FileName); 265 end; 266 end; 267 268 procedure TMainForm.AProjectSaveAsExecute(Sender: TObject); 269 begin 270 if SaveDialog1.Execute then begin 271 Project.SaveToFile(SaveDialog1.FileName); 272 end; 273 end; 274 275 procedure TMainForm.ComboBoxTargetSelectionChange(Sender: TObject); 246 276 begin 247 277 ButtonCompileClick(Self); 248 278 end; 249 279 250 procedure TMainForm.ComboBoxTargetSelectionChange(Sender: TObject);251 begin252 ButtonCompileClick(Self);253 end;254 255 280 end.
Note:
See TracChangeset
for help on using the changeset viewer.