source: trunk/Core.pas

Last change on this file was 181, checked in by chronos, 3 months ago
  • Added: Windows installer for version 1.5.0.
  • Modified: Version 1.5.0 related updates.
  • Modified: Trunk pushed to 1.6.0 alfa version.
File size: 22.0 KB
Line 
1unit Core;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Controls, ActnList, Forms, Dialogs, ExtCtrls,
7 LastOpenedList, ApplicationInfo, PersistentForm, ScaleDPI, Common,
8 Translator, DataFile, VCard, Menus, RegistryEx, Theme, FormMain,
9 Registry, VCardFile, FormKeyShortcuts;
10
11type
12
13 { TCore }
14
15 TCore = class(TDataModule)
16 AAbout: TAction;
17 AKeyShortcuts: TAction;
18 AFullScreen: TAction;
19 AFileImport: TAction;
20 AFileExport: TAction;
21 ANormalize: TAction;
22 ARemoveExactDuplicates: TAction;
23 AFileCompare: TAction;
24 AViewSource: TAction;
25 ATest: TAction;
26 AFind: TAction;
27 AFileSplit: TAction;
28 AGenerate: TAction;
29 AFindDuplicate: TAction;
30 AFileCombine: TAction;
31 ASettings: TAction;
32 AFileOpenRecent: TAction;
33 AHomePage: TAction;
34 AFileClose: TAction;
35 AFileSaveAs: TAction;
36 AFileSave: TAction;
37 AFileOpen: TAction;
38 AFileNew: TAction;
39 AExit: TAction;
40 ActionList1: TActionList;
41 ApplicationInfo1: TApplicationInfo;
42 SelectDirectoryDialog1: TSelectDirectoryDialog;
43 Translator: TTranslator;
44 ImageList1: TImageList;
45 LastOpenedList1: TLastOpenedList;
46 OpenDialog1: TOpenDialog;
47 PersistentForm1: TPersistentForm;
48 SaveDialog1: TSaveDialog;
49 ScaleDPI1: TScaleDPI;
50 ThemeManager1: TThemeManager;
51 procedure AAboutExecute(Sender: TObject);
52 procedure AExitExecute(Sender: TObject);
53 procedure AFileCombineExecute(Sender: TObject);
54 procedure AFileCompareExecute(Sender: TObject);
55 procedure AFileExportExecute(Sender: TObject);
56 procedure AFileImportExecute(Sender: TObject);
57 procedure AFileNewExecute(Sender: TObject);
58 procedure AFileOpenExecute(Sender: TObject);
59 procedure AFileOpenRecentExecute(Sender: TObject);
60 procedure AFileSaveExecute(Sender: TObject);
61 procedure AFileSaveAsExecute(Sender: TObject);
62 procedure AFileCloseExecute(Sender: TObject);
63 procedure AFileSplitExecute(Sender: TObject);
64 procedure AFindDuplicateExecute(Sender: TObject);
65 procedure AFindExecute(Sender: TObject);
66 procedure AFullScreenExecute(Sender: TObject);
67 procedure AGenerateExecute(Sender: TObject);
68 procedure AHomePageExecute(Sender: TObject);
69 procedure AKeyShortcutsExecute(Sender: TObject);
70 procedure ANormalizeExecute(Sender: TObject);
71 procedure ARemoveExactDuplicatesExecute(Sender: TObject);
72 procedure ASettingsExecute(Sender: TObject);
73 procedure ATestExecute(Sender: TObject);
74 procedure AViewSourceExecute(Sender: TObject);
75 procedure DataModuleCreate(Sender: TObject);
76 procedure DataModuleDestroy(Sender: TObject);
77 procedure LastOpenedList1Change(Sender: TObject);
78 procedure TranslatorTranslate(Sender: TObject);
79 private
80 FOnDataFileChange: TNotifyEvent;
81 FOnLastOpenedListChange: TNotifyEvent;
82 InitializeStarted: Boolean;
83 InitializeFinished: Boolean;
84 LoadErrors: string;
85 ProfileImage: TImage;
86 LastSplitDir: string;
87 ProfilePhotoFileName: string;
88 RecentFileRegistryContext: TRegistryContext;
89 FormMain: TFormMain;
90 FormKeyShortcuts: TFormKeyShortcuts;
91 procedure FileModified(Sender: TObject);
92 function FindFirstNonOption: string;
93 procedure LoadConfig;
94 procedure SaveConfig;
95 procedure DoError(Text: string; Line: Integer);
96 procedure AddItemToLastOpenedList(FileName: string);
97 procedure DoDataFileChange;
98 function GetDefaultCompareTool: string;
99 public
100 DefaultDataFileClass: TDataFileClass;
101 DataFile: TDataFile;
102 FileClosed: Boolean;
103 ReopenLastFileOnStart: Boolean;
104 LastContactTabIndex: Integer;
105 LastContactFileName: string;
106 LastPhotoFileName: string;
107 LastQrCodeFileName: string;
108 LastPropertyValueFileName: string;
109 MapUrl: string;
110 GenerateCount: Integer;
111 ToolbarVisible: Boolean;
112 DefaultVcardVersion: string;
113 DefaultPhoneCountryCode: string;
114 DefaultInternationalCallPrefix: string;
115 CompareTool: string;
116 procedure UpdateFile;
117 function GetProfileImage: TImage;
118 function GetTempDir: string;
119 procedure FileNew;
120 procedure FileOpen(FileName: string);
121 procedure FileClose;
122 procedure Initialize;
123 procedure UpdateInterface;
124 property OnDataFileChange: TNotifyEvent read FOnDataFileChange
125 write FOnDataFileChange;
126 property OnLastOpenedListChange: TNotifyEvent read FOnLastOpenedListChange
127 write FOnLastOpenedListChange;
128 end;
129
130var
131 Core: TCore;
132
133
134implementation
135
136{$R *.lfm}
137
138uses
139 FormSettings, FormFindDuplicity, FormCompare, TestCase, FormNormalize,
140 FormGenerate, FormError, FormFind, FormSource, TestCases, FormExport, FormEx,
141 FormAbout, FormTests, FormImport;
142
143resourcestring
144 SAppExit = 'Application exit';
145 SAppExitQuery = 'File was modified. Do you want to save it before exit?';
146 SFileSplit = 'Contacts split';
147 SFileSplitFinishedOpenDirectory = 'Total %d contact files saved. Do you want to open the directory %s?';
148 SFileNotFound = 'File ''%s'' not found.';
149 SCombinedContacts = 'Combined %d contact files.';
150 SLine = 'Line %d: %s';
151 SRemovedDuplicates = 'Removed %d duplicates.';
152
153{ TCore }
154
155procedure TCore.AExitExecute(Sender: TObject);
156begin
157 FormMain.Close;
158 Application.Terminate;
159end;
160
161procedure TCore.AFileCombineExecute(Sender: TObject);
162var
163 TempFile: TDataFile;
164 I: Integer;
165 LoadedFiles: Integer;
166begin
167 TempFile := DefaultDataFileClass.Create(nil);
168 try
169 OpenDialog1.Filter := TempFile.GetFileFilter;
170 finally
171 TempFile.Free;
172 end;
173 OpenDialog1.DefaultExt := '';
174 if Assigned(DataFile) then begin
175 OpenDialog1.InitialDir := ExtractFileDir(DataFile.FileName);
176 OpenDialog1.FileName := ExtractFileName(DataFile.FileName);
177 end;
178 OpenDialog1.Options := OpenDialog1.Options + [ofAllowMultiSelect];
179 if OpenDialog1.Execute then begin
180 LoadedFiles := 0;
181 for I := 0 to OpenDialog1.Files.Count - 1 do begin
182 if FileExists(OpenDialog1.Files[I]) then begin
183 TempFile := TVCardFile.Create(nil);
184 try
185 TempFile.LoadFromFile(OpenDialog1.Files[I]);
186 TVCardFile(DataFile).VCard.Contacts.AddContacts(TVCardFile(TempFile).VCard.Contacts);
187 Inc(LoadedFiles);
188 finally
189 TempFile.Free;
190 end;
191 end;
192 end;
193 if LoadedFiles > 0 then TVCardFile(DataFile).Modified := True;
194 ShowMessage(Format(SCombinedContacts, [LoadedFiles]));
195 UpdateFile;
196 end;
197end;
198
199procedure TCore.AFileCompareExecute(Sender: TObject);
200var
201 FormCompare: TFormCompare;
202begin
203 FormCompare := TFormCompare.Create(nil);
204 try
205 FormCompare.ShowModal;
206 finally
207 FreeAndNil(FormCompare);
208 end;
209end;
210
211procedure TCore.AFileExportExecute(Sender: TObject);
212var
213 FormExport: TFormExport;
214begin
215 FormExport := TFormExport.Create(nil);
216 try
217 FormExport.ShowModal;
218 finally
219 FormExport.Free;
220 end;
221end;
222
223procedure TCore.AFileImportExecute(Sender: TObject);
224var
225 FormImport: TFormImport;
226begin
227 FormImport := TFormImport.Create(nil);
228 try
229 if FormImport.ShowModal = mrOK then begin
230 TVCardFile(DataFile).Modified := True;
231 UpdateFile;
232 end;
233 finally
234 FormImport.Free;
235 end;
236end;
237
238procedure TCore.AAboutExecute(Sender: TObject);
239var
240 FormAbout: TFormAbout;
241begin
242 FormAbout := TFormAbout.Create(nil);
243 FormAbout.ApplicationInfo := ApplicationInfo1;
244 FormAbout.ShowModal;
245 FreeAndNil(FormAbout);
246end;
247
248procedure TCore.AFileCloseExecute(Sender: TObject);
249begin
250 FileClose;
251 UpdateFile;
252end;
253
254procedure TCore.AFileSplitExecute(Sender: TObject);
255var
256 I: Integer;
257 C: Integer;
258 FileName: string;
259 ModalResult: TModalResult;
260begin
261 C := 0;
262 SelectDirectoryDialog1.FileName := LastSplitDir;
263 if SelectDirectoryDialog1.Execute then begin
264 LastSplitDir := SelectDirectoryDialog1.FileName;
265 with TVCardFile(DataFile).VCard.Contacts do
266 for I := 0 to Count - 1 do begin
267 if Items[I].Fields[cfFullName] <> '' then begin
268 FileName := SelectDirectoryDialog1.FileName + DirectorySeparator +
269 Items[I].FullNameToFileName + VCardFileExt;
270 Items[I].SaveToFile(FileName);
271 Inc(C);
272 end;
273 end;
274 ModalResult := MessageDlg(SFileSplit,
275 Format(SFileSplitFinishedOpenDirectory, [C,
276 SelectDirectoryDialog1.FileName]), mtConfirmation, [mbYes, mbNo], 0);
277 if ModalResult = mrYes then begin
278 {$IFDEF WINDOWS}
279 ExecuteProgram('explorer.exe', ['"' + SelectDirectoryDialog1.FileName + '"'], []);
280 {$ENDIF}
281 {$IFDEF UNIX}
282 ExecuteProgram('/usr/bin/xdg-open', [SelectDirectoryDialog1.FileName], []);
283 {$ENDIF}
284 end;
285 end;
286end;
287
288procedure TCore.AFindDuplicateExecute(Sender: TObject);
289begin
290 with TFormFindDuplicity.Create(nil) do
291 try
292 Contacts := TVCardFile(DataFile).VCard.Contacts;
293 ShowModal;
294 DoDataFileChange;
295 finally
296 Free;
297 end;
298end;
299
300procedure TCore.AFindExecute(Sender: TObject);
301begin
302 with TFormFind.Create(nil) do
303 try
304 Contacts := TVCardFile(DataFile).VCard.Contacts;
305 ShowModal;
306 DoDataFileChange;
307 finally
308 Free;
309 end;
310end;
311
312procedure TCore.AFullScreenExecute(Sender: TObject);
313begin
314 FormMain.ToggleFullScreen;
315end;
316
317procedure TCore.AGenerateExecute(Sender: TObject);
318begin
319 with TFormGenerate.Create(nil) do
320 try
321 Contacts := TVCardFile(DataFile).VCard.Contacts;
322 if ShowModal = mrOk then begin
323 DataFile.Modified := True;
324 DoDataFileChange;
325 end;
326 finally
327 Free;
328 end;
329end;
330
331procedure TCore.AHomePageExecute(Sender: TObject);
332begin
333 OpenWebPage(ApplicationInfo1.HomePage);
334end;
335
336procedure TCore.AKeyShortcutsExecute(Sender: TObject);
337begin
338 if not Assigned(FormKeyShortcuts) then
339 FormKeyShortcuts := TFormKeyShortcuts.Create(nil);
340 FormKeyShortcuts.ImageList := ImageList1;
341 FormKeyShortcuts.MainForm := FormMain;
342 FormKeyShortcuts.SourceComponents.Clear;
343 FormKeyShortcuts.SourceComponents.Add(Self);
344 FormKeyShortcuts.Show;
345end;
346
347procedure TCore.ANormalizeExecute(Sender: TObject);
348var
349 FormNormalize: TFormNormalize;
350begin
351 FormNormalize := TFormNormalize.Create(nil);
352 try
353 FormNormalize.ShowModal;
354 finally
355 FreeAndNil(FormNormalize);
356 end;
357end;
358
359procedure TCore.ARemoveExactDuplicatesExecute(Sender: TObject);
360var
361 RemovedCount: Integer;
362begin
363 RemovedCount := TVCardFile(DataFile).VCard.Contacts.RemoveExactDuplicates;
364 ShowMessage(Format(SRemovedDuplicates, [RemovedCount]));
365 if RemovedCount > 0 then begin
366 DataFile.Modified := True;
367 UpdateFile;
368 end;
369end;
370
371procedure TCore.ASettingsExecute(Sender: TObject);
372begin
373 with TFormSettings.Create(nil) do
374 try
375 LoadData;
376 if ShowModal = mrOK then begin
377 SaveData;
378 FormMain.SettingsChanged;
379 end;
380 finally
381 Free;
382 end;
383end;
384
385procedure TCore.ATestExecute(Sender: TObject);
386begin
387 with TFormTests.Create(nil) do
388 try
389 TestCases := InitTestCases;
390 try
391 ShowModal;
392 finally
393 TestCases.Free;
394 end;
395 finally
396 Free;
397 end;
398end;
399
400procedure TCore.AViewSourceExecute(Sender: TObject);
401begin
402 with TFormSource.Create(nil) do
403 try
404 Source := TVCardFile(DataFile).VCard.AsString;
405 if ShowModal = mrOk then begin
406 TVCardFile(DataFile).VCard.AsString := Source;
407 UpdateFile;
408 end;
409 finally
410 Free;
411 end;
412end;
413
414procedure TCore.AFileNewExecute(Sender: TObject);
415begin
416 FileNew;
417 UpdateFile;
418end;
419
420procedure TCore.AFileOpenExecute(Sender: TObject);
421var
422 TempFile: TDataFile;
423begin
424 TempFile := DefaultDataFileClass.Create(nil);
425 try
426 OpenDialog1.Filter := TempFile.GetFileFilter;
427 finally
428 TempFile.Free;
429 end;
430 OpenDialog1.DefaultExt := '';
431 if Assigned(DataFile) then begin
432 OpenDialog1.InitialDir := ExtractFileDir(DataFile.FileName);
433 OpenDialog1.FileName := ExtractFileName(DataFile.FileName);
434 end;
435 OpenDialog1.Options := OpenDialog1.Options - [ofAllowMultiSelect];
436 if OpenDialog1.Execute then begin
437 FileOpen(OpenDialog1.FileName);
438 UpdateFile;
439 end;
440end;
441
442procedure TCore.AFileOpenRecentExecute(Sender: TObject);
443begin
444 FileOpen(TMenuItem(Sender).Caption);
445 UpdateFile;
446end;
447
448procedure TCore.AFileSaveAsExecute(Sender: TObject);
449begin
450 SaveDialog1.DefaultExt := DataFile.GetFileExt;
451 SaveDialog1.Filter := DataFile.GetFileFilter;
452 SaveDialog1.InitialDir := ExtractFileDir(DataFile.FileName);
453 SaveDialog1.FileName := ExtractFileName(DataFile.FileName);
454 if SaveDialog1.Execute then begin
455 DataFile.SaveToFile(SaveDialog1.FileName);
456 AddItemToLastOpenedList(SaveDialog1.FileName);
457 UpdateFile;
458 end;
459end;
460
461procedure TCore.AFileSaveExecute(Sender: TObject);
462begin
463 if FileExists(DataFile.FileName) then begin
464 DataFile.SaveToFile(DataFile.FileName);
465 AddItemToLastOpenedList(DataFile.FileName);
466 UpdateFile;
467 end else AFileSaveAs.Execute;
468end;
469
470procedure TCore.DataModuleCreate(Sender: TObject);
471{$IFDEF UNIX}
472const
473 LinuxDataFilesDir = '/usr/share/vCardStudio';
474 LinuxLanguagesDir = LinuxDataFilesDir + '/Languages';
475 LinuxImagesDir = LinuxDataFilesDir + '/Images';
476{$ENDIF}
477begin
478 ProfilePhotoFileName := 'Images/Profile.png';
479 {$IFDEF UNIX}
480 // If installed in Linux system then use installation directory for po files
481 if not DirectoryExists(Translator.POFilesFolder) and DirectoryExists(LinuxLanguagesDir) then begin
482 Translator.POFilesFolder := LinuxLanguagesDir;
483 end;
484 // If installed in Linux system then use installation directory for images files
485 if not DirectoryExists('Images') and DirectoryExists(LinuxImagesDir) then begin
486 ProfilePhotoFileName := LinuxImagesDir + DirectorySeparator + 'Profile.png';
487 end;
488 {$ENDIF}
489
490 DataFile := nil;
491 DefaultDataFileClass := TVCardFile;
492 FileClosed := True;
493 RecentFileRegistryContext := TRegistryContext.Create(ApplicationInfo1.RegistryRoot,
494 ApplicationInfo1.RegistryKey + '\RecentFiles');
495 LoadConfig;
496
497 TFormEx.ScaleDPI := ScaleDPI1;
498 TFormEx.Translator := Translator;
499 TFormEx.ThemeManager := ThemeManager1;
500 TFormEx.PersistentForm := PersistentForm1;
501
502 Application.CreateForm(TFormMain, FormMain);
503 FormMain.Show;
504end;
505
506procedure TCore.DataModuleDestroy(Sender: TObject);
507begin
508 FileClose;
509 SaveConfig;
510 if Assigned(ProfileImage) then
511 FreeAndNil(ProfileImage);
512 if Assigned(FormKeyShortcuts) then
513 FreeAndNil(FormKeyShortcuts);
514end;
515
516procedure TCore.LastOpenedList1Change(Sender: TObject);
517begin
518 if Assigned(FOnLastOpenedListChange) then
519 FOnLastOpenedListChange(Self);
520end;
521
522procedure TCore.TranslatorTranslate(Sender: TObject);
523begin
524 TestCase.Translate;
525end;
526
527procedure TCore.FileModified(Sender: TObject);
528begin
529 UpdateFile;
530end;
531
532procedure TCore.FileOpen(FileName: string);
533var
534 FormError: TFormError;
535begin
536 if FileExists(FileName) then begin
537 FileClose;
538 if FileClosed then begin
539 FileNew;
540 LoadErrors := '';
541 DataFile.LoadFromFile(FileName);
542 AddItemToLastOpenedList(FileName);
543 if LoadErrors <> '' then begin
544 FormError := TFormError.Create(nil);
545 FormError.MemoErrors.Text := LoadErrors;
546 FormError.ShowModal;
547 FreeAndNil(FormError);
548 end;
549 end;
550 end else ShowMessage(Format(SFileNotFound, [FileName]));
551end;
552
553procedure TCore.FileClose;
554var
555 ModalResult: TModalResult;
556 DoClose: Boolean;
557begin
558 DoClose := False;
559 if Assigned(DataFile) then begin
560 if DataFile.Modified then begin
561 ModalResult := MessageDlg(SAppExit, SAppExitQuery,
562 mtConfirmation, [mbYes, mbNo, mbCancel], 0);
563 if ModalResult = mrYes then begin
564 AFileSave.Execute;
565 DoClose := True;
566 end
567 else if ModalResult = mrNo then begin
568 DoClose := True;
569 end else FileClosed := False;
570 end else DoClose := True;
571 end else DoClose := True;
572 if DoClose then begin
573 if Assigned(DataFile) then FreeAndNil(DataFile);
574 FileClosed := True;
575 UpdateFile;
576 end;
577end;
578
579procedure TCore.FileNew;
580begin
581 FileClose;
582 if FileClosed then begin
583 DataFile := DefaultDataFileClass.Create(nil);
584 DataFile.OnModify := FileModified;
585 TVCardFile(DataFile).VCard.OnError := DoError;
586 end;
587end;
588
589procedure TCore.UpdateFile;
590begin
591 UpdateInterface;
592 DoDataFileChange;
593end;
594
595procedure TCore.LoadConfig;
596begin
597 PersistentForm1.RegistryContext := ApplicationInfo1.GetRegistryContext;
598 LastOpenedList1.LoadFromRegistry(RecentFileRegistryContext);
599
600 with TRegistryEx.Create do
601 try
602 CurrentContext := ApplicationInfo1.GetRegistryContext;
603 if ValueExists('LanguageCode') then
604 Translator.Language := Translator.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
605 else Translator.Language := Translator.Languages.SearchByCode('');
606 if ValueExists('Theme') then
607 ThemeManager1.Theme := ThemeManager1.Themes.FindByName(ReadStringWithDefault('Theme', 'System'))
608 else ThemeManager1.Theme := ThemeManager1.Themes.FindByName('System');
609 ReopenLastFileOnStart := ReadBoolWithDefault('ReopenLastFileOnStart', True);
610 LastContactTabIndex := ReadIntegerWithDefault('LastContactTabIndex', 0);
611 LastContactFileName := ReadStringWithDefault('LastContactFileName', '');
612 LastSplitDir := ReadStringWithDefault('LastSplitDir', '');
613 LastPropertyValueFileName := ReadStringWithDefault('LastPropertyValueFileName', '');
614 GenerateCount := ReadIntegerWithDefault('GenerateCount', 1);
615 DefaultVcardVersion := ReadStringWithDefault('DefaultVcardVersion', '2.1');
616 MapUrl := ReadStringWithDefault('MapUrl', 'https://www.openstreetmap.org/search?query=');
617 LastPhotoFileName := ReadStringWithDefault('LastPhotoFileName', '');
618 LastQrCodeFileName := ReadStringWithDefault('LastQrCodeFileName', '');
619 CompareTool := ReadStringWithDefault('CompareTool', GetDefaultCompareTool);
620 DefaultPhoneCountryCode := ReadStringWithDefault('DefaultPhoneCountryPrefix', DefaultPhoneCountryCode);
621 DefaultInternationalCallPrefix := ReadStringWithDefault('DefaultInternationalCallPrefix', DefaultInternationalCallPrefix);
622 finally
623 Free;
624 end;
625end;
626
627procedure TCore.SaveConfig;
628begin
629 with TRegistryEx.Create do
630 try
631 CurrentContext := ApplicationInfo1.GetRegistryContext;
632 if Assigned(Translator.Language) and (Translator.Language.Code <> '') then
633 WriteString('LanguageCode', Translator.Language.Code)
634 else DeleteValue('LanguageCode');
635 if Assigned(ThemeManager1.Theme) and (ThemeManager1.Theme.Name <> '') then
636 WriteString('Theme', ThemeManager1.Theme.Name)
637 else DeleteValue('Theme');
638 WriteBool('ReopenLastFileOnStart', ReopenLastFileOnStart);
639 WriteInteger('LastContactTabIndex', LastContactTabIndex);
640 WriteString('LastContactFileName', LastContactFileName);
641 WriteString('LastSplitDir', LastSplitDir);
642 WriteString('LastPropertyValueFileName', LastPropertyValueFileName);
643 WriteInteger('GenerateCount', GenerateCount);
644 WriteString('DefaultVcardVersion', DefaultVcardVersion);
645 WriteString('MapUrl', MapUrl);
646 WriteString('LastPhotoFileName', LastPhotoFileName);
647 WriteString('LastQrCodeFileName', LastQrCodeFileName);
648 WriteString('CompareTool', CompareTool);
649 WriteString('DefaultPhoneCountryPrefix', DefaultPhoneCountryCode);
650 WriteString('DefaultInternationalCallPrefix', DefaultInternationalCallPrefix);
651 finally
652 Free;
653 end;
654end;
655
656procedure TCore.DoError(Text: string; Line: Integer);
657begin
658 LoadErrors := LoadErrors + Format(SLine, [Line, Text]) + LineEnding;
659end;
660
661procedure TCore.AddItemToLastOpenedList(FileName: string);
662begin
663 with LastOpenedList1 do begin
664 LoadFromRegistry(RecentFileRegistryContext);
665 AddItem(FileName);
666 SaveToRegistry(RecentFileRegistryContext);
667 end;
668end;
669
670procedure TCore.DoDataFileChange;
671begin
672 if Assigned(FOnDataFileChange) then
673 FOnDataFileChange(Self);
674end;
675
676function TCore.GetDefaultCompareTool: string;
677const
678 KDiff3 = '/usr/bin/kdiff3';
679 Kompare = '/usr/bin/kompare';
680 Meld = '/usr/bin/meld';
681 Diffuse = '/usr/bin/diffuse';
682 BeyondCompareLin = '/usr/bin/bcompare';
683 BeyondCompareWin3 = 'c:\Program Files\Beyond Compare 3\BCompare.exe';
684 BeyondCompareWin4 = 'c:\Program Files\Beyond Compare 4\BCompare.exe';
685 BeyondCompareWin5 = 'c:\Program Files\Beyond Compare 5\BCompare.exe';
686begin
687 if FileExists(KDiff3) then Result := KDiff3
688 else if FileExists(Meld) then Result := Meld
689 else if FileExists(Kompare) then Result := Kompare
690 else if FileExists(Diffuse) then Result := Diffuse
691 else if FileExists(BeyondCompareLin) then Result := BeyondCompareLin
692 else if FileExists(BeyondCompareWin5) then Result := BeyondCompareWin5
693 else if FileExists(BeyondCompareWin4) then Result := BeyondCompareWin4
694 else if FileExists(BeyondCompareWin3) then Result := BeyondCompareWin3
695 else Result := '';
696end;
697
698function TCore.GetProfileImage: TImage;
699begin
700 if not Assigned(ProfileImage) then begin
701 ProfileImage := TImage.Create(nil);
702 if FileExists(ProfilePhotoFileName) then
703 ProfileImage.Picture.LoadFromFile(ProfilePhotoFileName);
704 end;
705 Result := ProfileImage;
706end;
707
708function TCore.GetTempDir: string;
709begin
710 Result := SysUtils.GetTempDir + Application.Title;
711end;
712
713procedure TCore.UpdateInterface;
714begin
715 AFileSave.Enabled := Assigned(DataFile) and DataFile.Modified;
716 AFileSaveAs.Enabled := Assigned(DataFile);
717 AFileClose.Enabled := Assigned(DataFile);
718 AFileSplit.Enabled := Assigned(DataFile);
719 AFileCombine.Enabled := Assigned(DataFile);
720 AFileCompare.Enabled := Assigned(DataFile);
721 AFind.Enabled := Assigned(DataFile);
722 AFindDuplicate.Enabled := Assigned(DataFile);
723 AGenerate.Enabled := Assigned(DataFile);
724 {$IFOPT D+}
725 ATest.Enabled := True;
726 {$ENDIF}
727 {$IFOPT D-}
728 ATest.Enabled := False;
729 {$ENDIF}
730 ATest.Visible := ATest.Enabled;
731 AFileCompare.Visible := AFileCompare.Enabled;
732end;
733
734procedure TCore.Initialize;
735var
736 FileNameOption: string;
737begin
738 if not InitializeStarted then begin
739 InitializeStarted := True;
740
741 FileNameOption := FindFirstNonOption;
742 if FileNameOption <> '' then begin
743 // Open file specified as command line parameter
744 AFileNew.Execute;
745 DataFile.LoadFromFile(FileNameOption);
746 AddItemToLastOpenedList(FileNameOption);
747 end else
748 if ReopenLastFileOnStart and (LastOpenedList1.Items.Count > 0) and FileExists(LastOpenedList1.Items[0]) then begin
749 // Open last opened file
750 AFileNew.Execute;
751 DataFile.LoadFromFile(LastOpenedList1.Items[0])
752 end else AFileNew.Execute;
753
754 UpdateFile;
755 InitializeFinished := True;
756 end;
757end;
758
759function TCore.FindFirstNonOption: string;
760var
761 S: string;
762 I: Integer;
763begin
764 Result := '';
765 for I := 1 to Application.ParamCount do begin
766 S := Application.Params[I];
767 if S[1] = Application.OptionChar then Continue;
768 Result := S;
769 Break;
770 end;
771end;
772
773end.
774
Note: See TracBrowser for help on using the repository browser.