Changeset 15 for trunk/StudioPackage/UDataModule.pas
- Timestamp:
- Aug 6, 2012, 2:35:22 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/StudioPackage/UDataModule.pas
r14 r15 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, ActnList, Controls, SpecializedList, 9 USource, UModularSystem, ULDStudioAPI, Menus, ComCtrls; 9 USource, UModularSystem, UCoolTranslator, ULDStudioAPI, Menus, ComCtrls, 10 Registry, URegistry, UApplicationInfo; 10 11 11 12 type 12 13 13 { T OpenedFile }14 15 T OpenedFile = class16 private17 FFileName: string;18 procedure SetFileName(AValue: string); 19 public20 Modified: Boolean; 21 Form: TForm;22 property FileName: string read FFileName write SetFileName;14 { TTextTemplate } 15 16 TTextTemplate = class(TFileTemplate) 17 constructor Create; override; 18 end; 19 20 { TTextFileType } 21 22 TTextFileType = class(TSourceType) 23 constructor Create; override; 23 24 end; 24 25 … … 29 30 FOnChange: TNotifyEvent; 30 31 public 31 Selected: TOpenedFile; 32 function FindByFileName(Value: string): TOpenedFile; 33 procedure CloseFile(FileName: string); 34 procedure OpenFile(FileName: string); 32 Selected: TSource; 33 function FindByFileName(Value: string): TSource; 34 procedure CloseFile(Source: TSource); 35 procedure OpenFileName(FileName: string); 36 procedure OpenFile(Source: TSource); 35 37 procedure NewFile; 36 38 property OnChange: TNotifyEvent read FOnChange write FOnChange; … … 42 44 published 43 45 ActionListRegistred: TActionList; 46 ApplicationInfo1: TApplicationInfo; 47 CoolTranslator1: TCoolTranslator; 44 48 ImageListMain: TImageList; 45 49 API: TLDStudioAPI; 46 50 procedure APIDockForm(Form: TForm; Target: TDockTarget); 51 function APIGetRegistryContext: TRegistryContext; 52 procedure APIRegisterFileTemplate(Template: TFileTemplate); 47 53 procedure APIRegisterFileType(FileType: TSourceType); 48 54 procedure APIRegisterForm(Form: TForm); … … 50 56 ParentItem: TMenuItem; Index: Integer); 51 57 procedure APIUnregisterAction(Action: TAction); 58 procedure APIUnregisterFileTemplate(Template: TFileTemplate); 52 59 procedure APIUnregisterFileType(FileType: TSourceType); 53 60 procedure APIUnregisterForm(Form: TForm); 54 61 procedure APIUnregisterMainMenuItem(MenuItem: TMenuItem); 62 procedure APIOpenFile(FileName: string); 63 procedure APIRegisterAction(Action: TAction); 55 64 procedure DataModuleCreate(Sender: TObject); 56 65 procedure DataModuleDestroy(Sender: TObject); 57 procedure APIOpenFile(FileName: string);58 procedure APIRegisterAction(Action: TAction);59 66 private 67 TextFileType: TSourceType; 68 TextFileTemplate: TTextTemplate; 69 procedure AutoOpen; 60 70 procedure DockToPageControl(PageControl: TPageControl; Form: TForm); 61 71 public 62 72 ModuleManager: TModuleManager; 63 73 FileTypes: TFileTypes; 74 FileTemplates: TFileTemplates; 64 75 OpenedFiles: TOpenedFiles; 65 end; 76 procedure LoadFromRegistry(Context: TRegistryContext); 77 procedure SaveToRegistry(Context: TRegistryContext); 78 end; 79 66 80 67 81 var … … 74 88 75 89 uses 76 UFormSourceCode, UFormMain, UFormSettings, UFormModuleList ;90 UFormSourceCode, UFormMain, UFormSettings, UFormModuleList, UFormNewFile; 77 91 78 92 resourcestring 79 93 SNewFile = 'New file'; 80 81 procedure TOpenedFile.SetFileName(AValue: string); 82 begin 83 if FFileName = AValue then Exit; 84 FFileName := AValue; 85 if Assigned(Form) then 86 Form.Caption := ExtractFileName(FFileName); 87 end; 94 STextFile = 'Text file'; 95 96 { TTextFileType } 97 98 constructor TTextFileType.Create; 99 begin 100 inherited Create; 101 Extension := '.txt'; 102 Title := 'Text file';; 103 end; 104 105 { TTextTemplate } 106 107 constructor TTextTemplate.Create; 108 begin 109 inherited Create; 110 Name := STextFile; 111 end; 112 88 113 89 114 { TOpenedFiles } 90 115 91 function TOpenedFiles.FindByFileName(Value: string): T OpenedFile;116 function TOpenedFiles.FindByFileName(Value: string): TSource; 92 117 var 93 118 I: Integer; 94 119 begin 95 120 I := 0; 96 while (I < Count) and (T OpenedFile(Items[I]).FileName <> Value) do Inc(I);97 if I < Count then Result := T OpenedFile(Items[I])121 while (I < Count) and (TSource(Items[I]).Name <> Value) do Inc(I); 122 if I < Count then Result := TSource(Items[I]) 98 123 else Result := nil; 99 124 end; 100 125 101 procedure TOpenedFiles.CloseFile(FileName: string); 102 var 103 OpenedFile: TOpenedFile; 104 begin 105 OpenedFile := FindByFileName(FileName); 106 FreeAndNil(OpenedFile.Form); 107 Remove(OpenedFile); 126 procedure TOpenedFiles.CloseFile(Source: TSource); 127 begin 128 FreeAndNil(Source.Form); 129 Remove(Source); 108 130 if Assigned(FOnChange) then FOnChange(Self); 109 131 end; 110 132 111 procedure TOpenedFiles.OpenFile(FileName: string); 112 var 113 NewFile: TOpenedFile; 114 begin 115 NewFile := TOpenedFile(AddNew(TOpenedFile.Create)); 116 NewFile.FileName := FileName; 133 procedure TOpenedFiles.OpenFileName(FileName: string); 134 var 135 NewFile: TSourceText; 136 begin 137 NewFile := TSourceText.Create; 138 NewFile.Name := FileName; 139 OpenFile(NewFile); 140 end; 141 142 procedure TOpenedFiles.OpenFile(Source: TSource); 143 begin 144 AddNew(Source); 145 Source.Form := TFormSourceCode.Create(nil); 146 Source.Form.Caption := ExtractFileName(Source.Name); 147 Source.Form.Visible := True; 148 Selected := Source; 149 if Assigned(FOnChange) then FOnChange(Self); 150 end; 151 152 procedure TOpenedFiles.NewFile; 153 var 154 NewFile: TSource; 155 begin 156 NewFile := TSourceText(AddNew(TSource.Create)); 157 NewFile.Name := SNewFile; 117 158 NewFile.Form := TFormSourceCode.Create(nil); 118 NewFile.Form.Caption := ExtractFileName(NewFile. FileName);159 NewFile.Form.Caption := ExtractFileName(NewFile.Name); 119 160 NewFile.Form.Visible := True; 120 161 Selected := NewFile; … … 122 163 end; 123 164 124 procedure TOpenedFiles.NewFile;125 var126 NewFile: TOpenedFile;127 begin128 NewFile := TOpenedFile(AddNew(TOpenedFile.Create));129 NewFile.FileName := SNewFile;130 NewFile.Form := TFormSourceCode.Create(nil);131 NewFile.Form.Caption := ExtractFileName(NewFile.FileName);132 NewFile.Form.Visible := True;133 Selected := NewFile;134 if Assigned(FOnChange) then FOnChange(Self);135 end;136 137 165 { TDataModule1 } 138 166 139 167 procedure TDataModule1.DataModuleCreate(Sender: TObject); 140 168 begin 169 FileTemplates := TFileTemplates.Create; 170 FileTemplates.OwnsObjects := False; 141 171 FileTypes := TFileTypes.Create; 142 172 FileTypes.OwnsObjects := False; … … 144 174 ModuleManager := TModuleManager.Create(nil); 145 175 ModuleManager.API := API; 176 177 TextFileType := TTextFileType.Create; 178 API.RegisterFileType(TextFileType); 179 TextFileTemplate := TTextTemplate.Create; 180 API.RegisterFileTemplate(TextFileTemplate); 146 181 147 182 FormMain := TFormMain.Create(nil); … … 151 186 FormSettings := TFormSettings.Create(nil); 152 187 FormModuleList := TFormModuleList.Create(nil); 153 188 FormNewFile := TFormNewFile.Create(nil); 189 190 LoadFromRegistry(RegContext(HKEY(ApplicationInfo1.RegistryRoot), ApplicationInfo1.RegistryKey)); 191 192 DataModule1 := Self; 154 193 FormMain.Show; 194 AutoOpen; 155 195 end; 156 196 … … 191 231 end; 192 232 233 procedure TDataModule1.LoadFromRegistry(Context: TRegistryContext); 234 begin 235 with TRegistryEx.Create do 236 try 237 RootKey := Context.RootKey; 238 OpenKey(Context.Key, True); 239 240 finally 241 Free; 242 end; 243 FormMain.LoadFromRegistry(Context); 244 end; 245 246 procedure TDataModule1.SaveToRegistry(Context: TRegistryContext); 247 begin 248 with TRegistryEx.Create do 249 try 250 RootKey := Context.RootKey; 251 OpenKey(Context.Key, True); 252 253 finally 254 Free; 255 end; 256 FormMain.SaveToRegistry(Context); 257 end; 258 193 259 procedure TDataModule1.APIDockForm(Form: TForm; Target: TDockTarget); 194 260 begin … … 203 269 end; 204 270 271 function TDataModule1.APIGetRegistryContext: TRegistryContext; 272 begin 273 Result := RegContext(HKEY(ApplicationInfo1.RegistryRoot), ApplicationInfo1.RegistryKey); 274 end; 275 276 procedure TDataModule1.APIRegisterFileTemplate(Template: TFileTemplate); 277 begin 278 FileTemplates.Add(Template); 279 end; 280 205 281 procedure TDataModule1.APIUnregisterAction(Action: TAction); 206 282 begin … … 208 284 end; 209 285 286 procedure TDataModule1.APIUnregisterFileTemplate(Template: TFileTemplate); 287 begin 288 FileTemplates.Remove(Template); 289 end; 290 210 291 procedure TDataModule1.APIUnregisterFileType(FileType: TSourceType); 211 292 begin … … 220 301 procedure TDataModule1.DataModuleDestroy(Sender: TObject); 221 302 begin 303 API.UnregisterFileType(TextFileType); 304 FreeAndNil(TextFileType); 305 API.UnregisterFileTemplate(TextFileTemplate); 306 FreeAndNil(TextFileTemplate); 307 308 SaveToRegistry(RegContext(HKEY(ApplicationInfo1.RegistryRoot), ApplicationInfo1.RegistryKey)); 222 309 FreeAndNil(ModuleManager); 310 FreeAndNil(FormNewFile); 223 311 FreeAndNil(FormMain); 224 312 FreeAndNil(FormSourceCode); … … 227 315 FreeAndNil(OpenedFiles); 228 316 FreeAndNil(FileTypes); 317 FreeAndNil(FileTemplates); 318 end; 319 320 procedure TDataModule1.AutoOpen; 321 var 322 FileName: string; 323 begin 324 if (ParamCount > 0) then begin 325 FileName := UTF8Encode(ParamStr(1)); 326 if FileExistsUTF8(FileName) then begin 327 OpenedFiles.OpenFileName(FileName); 328 end; 329 end; 229 330 end; 230 331 231 332 procedure TDataModule1.APIOpenFile(FileName: string); 232 333 begin 233 OpenedFiles.OpenFile (FileName);334 OpenedFiles.OpenFileName(FileName); 234 335 end; 235 336
Note:
See TracChangeset
for help on using the changeset viewer.