Changeset 86 for trunk/Forms/UFormMain.pas
- Timestamp:
- Aug 8, 2016, 1:41:25 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.pas
r83 r86 120 120 procedure TrayIcon1Click(Sender: TObject); 121 121 private 122 InitializeStarted: Boolean;123 InitializeFinished: Boolean;124 FAlwaysOnTop: Boolean;125 122 RegistryContext: TRegistryContext; 126 123 ProjectClosed: Boolean; 127 124 ImportTotalItemCount: Integer; 128 function FindFirstNonOption: string;129 procedure ProjectOpen(FileName: string);130 procedure Initialize;131 125 procedure ProcessImportsJob(Job: TJob); 132 procedure SetAlwaysOnTop(AValue: Boolean);133 126 procedure FilterList(List: TListObject); 134 127 procedure OpenRecentClick(Sender: TObject); 128 public 129 procedure LoadConfig; 130 procedure SaveConfig; 135 131 procedure UpdateAcronymsList; 136 132 procedure UpdateInterface; 137 procedure LoadConfig; 138 procedure SaveConfig; 139 public 140 AcronymDb: TAcronymDb; 141 StartOnLogon: Boolean; 142 StartMinimizedToTray: Boolean; 133 procedure ProjectOpen(FileName: string); 143 134 function CompareStrings(Strings1, Strings2: TStrings): Boolean; 144 property AlwaysOnTop: Boolean read FAlwaysOnTop write SetAlwaysOnTop;145 135 end; 146 136 … … 159 149 uses 160 150 UFormImport, UFormSettings, UFormCategories, UFormAcronyms, 161 UFormImportSources, UFormAbout, UFormImportFormats ;151 UFormImportSources, UFormAbout, UFormImportFormats, UCore; 162 152 163 153 resourcestring … … 171 161 DefaultRegKey = '\Software\Chronosoft\Acronym Decoder'; 172 162 RegistryRunKey = '\Software\Microsoft\Windows\CurrentVersion\Run'; 173 ExampleFile = 'Example acronyms.adp';174 163 175 164 { TFormMain } … … 179 168 I: Integer; 180 169 begin 181 AcronymDb := TAcronymDb.Create;182 InitializeStarted := False;183 InitializeFinished := False;184 170 for I := 0 to ToolBar1.ButtonCount - 1 do 185 171 ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption; … … 193 179 procedure TFormMain.FormHide(Sender: TObject); 194 180 begin 195 if InitializeFinished then PersistentForm1.Save(Self);181 if Core.InitializeFinished then PersistentForm1.Save(Self); 196 182 end; 197 183 … … 199 185 begin 200 186 PersistentForm1.Save(Self); 201 SaveConfig;187 Core.SaveConfig; 202 188 end; 203 189 … … 219 205 begin 220 206 DoClose := False; 221 if Assigned( AcronymDb) then begin222 if AcronymDb.Modified then begin207 if Assigned(Core.AcronymDb) then begin 208 if Core.AcronymDb.Modified then begin 223 209 ModalResult := MessageDlg(SAppExit, SAppExitQuery, 224 210 mtConfirmation, [mbYes, mbNo, mbCancel], 0); … … 233 219 end; 234 220 if DoClose then begin 235 FreeAndNil( AcronymDb);221 FreeAndNil(Core.AcronymDb); 236 222 UpdateAcronymsList; 237 223 UpdateInterface; … … 244 230 AFileClose.Execute; 245 231 if ProjectClosed then begin 246 AcronymDb := TAcronymDb.Create;247 AcronymDb.FileName := DefaultFileName;248 AcronymDb.Acronyms.Clear;232 Core.AcronymDb := TAcronymDb.Create; 233 Core.AcronymDb.FileName := DefaultFileName; 234 Core.AcronymDb.Acronyms.Clear; 249 235 UpdateAcronymsList; 250 236 UpdateInterface; … … 255 241 begin 256 242 OpenDialog1.DefaultExt := ProjectExt; 257 if Assigned( AcronymDb) then258 OpenDialog1.FileName := AcronymDb.FileName;243 if Assigned(Core.AcronymDb) then 244 OpenDialog1.FileName := Core.AcronymDb.FileName; 259 245 if OpenDialog1.Execute then begin 260 246 ProjectOpen(OpenDialog1.FileName); … … 265 251 begin 266 252 SaveDialog1.DefaultExt := ProjectExt; 267 SaveDialog1.FileName := AcronymDb.FileName;253 SaveDialog1.FileName := Core.AcronymDb.FileName; 268 254 if SaveDialog1.Execute then begin 269 AcronymDb.SaveToFile(SaveDialog1.FileName);255 Core.AcronymDb.SaveToFile(SaveDialog1.FileName); 270 256 LastOpenedList1.AddItem(SaveDialog1.FileName); 271 257 UpdateInterface; … … 275 261 procedure TFormMain.AFileSaveExecute(Sender: TObject); 276 262 begin 277 if FileExists( AcronymDb.FileName) then begin278 AcronymDb.SaveToFile(AcronymDb.FileName);279 LastOpenedList1.AddItem( AcronymDb.FileName);263 if FileExists(Core.AcronymDb.FileName) then begin 264 Core.AcronymDb.SaveToFile(Core.AcronymDb.FileName); 265 LastOpenedList1.AddItem(Core.AcronymDb.FileName); 280 266 UpdateInterface; 281 267 end else AFileSaveAs.Execute; … … 292 278 begin 293 279 ImportTotalItemCount := 0; 294 AcronymDb.AddedCount := 0;280 Core.AcronymDb.AddedCount := 0; 295 281 JobProgressView1.AddJob(SProcessImportSources, ProcessImportsJob); 296 282 JobProgressView1.Start; 297 ShowMessage(Format(SAddedCount, [ImportTotalItemCount, AcronymDb.AddedCount]));283 ShowMessage(Format(SAddedCount, [ImportTotalItemCount, Core.AcronymDb.AddedCount])); 298 284 UpdateAcronymsList; 299 285 UpdateInterface; … … 304 290 I: Integer; 305 291 begin 306 for I := 0 to AcronymDb.ImportSources.Count - 1 do307 with TImportSource( AcronymDb.ImportSources[I]) do292 for I := 0 to Core.AcronymDb.ImportSources.Count - 1 do 293 with TImportSource(Core.AcronymDb.ImportSources[I]) do 308 294 if Enabled then begin 309 295 Process; 310 296 ImportTotalItemCount := ImportTotalItemCount + ItemCount; 311 Job.Progress.Max := AcronymDb.ImportSources.Count;297 Job.Progress.Max := Core.AcronymDb.ImportSources.Count; 312 298 Job.Progress.Value := I; 313 299 if Job.Terminate then Break; … … 320 306 if FormSettings.ShowModal = mrOk then begin 321 307 FormSettings.Save; 322 SaveConfig;308 Core.SaveConfig; 323 309 end; 324 310 end; … … 338 324 procedure TFormMain.AShowCategoriesExecute(Sender: TObject); 339 325 begin 340 FormCategories.Categories := AcronymDb.Categories;326 FormCategories.Categories := Core.AcronymDb.Categories; 341 327 FormCategories.ShowModal; 342 328 UpdateAcronymsList; … … 352 338 procedure TFormMain.AShowImportFormatsExecute(Sender: TObject); 353 339 begin 354 FormImportFormats.ImportFormats := AcronymDb.ImportFormats;340 FormImportFormats.ImportFormats := Core.AcronymDb.ImportFormats; 355 341 FormImportFormats.ShowModal; 356 342 UpdateInterface; … … 359 345 procedure TFormMain.AShowImportSourcesExecute(Sender: TObject); 360 346 begin 361 FormImportSources.ImportSources := AcronymDb.ImportSources;347 FormImportSources.ImportSources := Core.AcronymDb.ImportSources; 362 348 FormImportSources.ShowModal; 363 349 UpdateAcronymsList; … … 377 363 procedure TFormMain.FormDestroy(Sender: TObject); 378 364 begin 379 FreeAndNil(AcronymDb);380 365 end; 381 366 382 367 procedure TFormMain.FormShow(Sender: TObject); 383 368 begin 384 Initialize;369 Core.Initialize; 385 370 386 371 if Visible then begin … … 442 427 procedure TFormMain.ListViewSort1Filter(ListViewSort: TListViewSort); 443 428 begin 444 AcronymDb.AssignToList(ListViewSort1.List);429 Core.AcronymDb.AssignToList(ListViewSort1.List); 445 430 FilterList(ListViewSort1.List); 446 431 end; … … 456 441 if not Visible then AShow.Execute 457 442 else Hide; 458 end;459 460 function TFormMain.FindFirstNonOption: string;461 var462 S: string;463 I: Integer;464 begin465 Result := '';466 for I := 1 to Application.ParamCount do begin467 S := Application.Params[I];468 if S[1] = Application.OptionChar then Continue;469 Result := S;470 Break;471 end;472 443 end; 473 444 … … 478 449 try 479 450 AFileNew.Execute; 480 AcronymDb.LoadFromFile(FileName);451 Core.AcronymDb.LoadFromFile(FileName); 481 452 LastOpenedList1.AddItem(FileName); 482 453 finally … … 484 455 UpdateInterface; 485 456 end; 486 end;487 end;488 489 procedure TFormMain.Initialize;490 var491 FileNameOption: string;492 begin493 if not InitializeStarted then begin494 InitializeStarted := True;495 LoadConfig;496 497 {$IFDEF 0}498 if Application.HasOption('h', 'help') then begin499 WriteLn('AcronymDecoder <project file>');500 WriteLn(' -t --tray Start minimized in system tray');501 WriteLn(' -h --help Show this help');502 Application.Terminate;503 Exit;504 end;505 {$ENDIF}506 507 if Application.HasOption('t', 'tray') then begin508 Visible := False;509 end;510 511 FileNameOption := FindFirstNonOption;512 if FileNameOption <> '' then begin513 // Open file specified as command line parameter514 AcronymDB.LoadFromFile(FileNameOption);515 LastOpenedList1.AddItem(OpenDialog1.FileName);516 end else517 if (LastOpenedList1.Items.Count > 0) and FileExists(LastOpenedList1.Items[0]) then begin518 // Open last opened file519 AcronymDB.LoadFromFile(LastOpenedList1.Items[0])520 end else begin521 // Open default database with examples if no item is in recent openned history522 FileNameOption := ExtractFileDir(Application.ExeName) + DirectorySeparator + ExampleFile;523 {$IFDEF Linux}524 // If installed in Linux system then use installation directory for po files525 if Application.ExeName = '/usr/bin/' + ExtractFileNameOnly(Application.ExeName) then526 FileNameOption := '/usr/share/' + ExtractFileNameOnly(Application.ExeName) + '/Examples/' + ExampleFile;527 {$ENDIF}528 ProjectOpen(FileNameOption);529 end;530 UpdateAcronymsList;531 ListViewFilter1.UpdateFromListView(ListViewAcronyms);532 InitializeFinished := True;533 457 end; 534 458 end; … … 545 469 Exit; 546 470 end; 547 end;548 549 procedure TFormMain.SetAlwaysOnTop(AValue: Boolean);550 begin551 if FAlwaysOnTop = AValue then Exit;552 FAlwaysOnTop := AValue;553 if FAlwaysOnTop then FormStyle := fsSystemStayOnTop554 else FormStyle := fsNormal;555 471 end; 556 472 … … 598 514 if ProjectClosed then begin 599 515 AFileNew.Execute; 600 AcronymDb.LoadFromFile(TMenuItem(Sender).Caption);516 Core.AcronymDb.LoadFromFile(TMenuItem(Sender).Caption); 601 517 LastOpenedList1.AddItem(TMenuItem(Sender).Caption); 602 518 UpdateAcronymsList; … … 607 523 procedure TFormMain.UpdateAcronymsList; 608 524 begin 609 if Assigned( AcronymDb) then begin525 if Assigned(Core.AcronymDb) then begin 610 526 ListViewSort1.Refresh; 611 527 end else begin … … 620 536 Title: string; 621 537 begin 622 ListViewAcronyms.Enabled := Assigned( AcronymDb);623 AFileClose.Enabled := Assigned( AcronymDb);624 AFileSave.Enabled := Assigned( AcronymDb) andAcronymDb.Modified;625 AFileSaveAs.Enabled := Assigned( AcronymDb);626 AManualImport.Enabled := Assigned( AcronymDb);627 AProcessImports.Enabled := Assigned( AcronymDb);628 AShowCategories.Enabled := Assigned( AcronymDb);629 AShowAcronyms.Enabled := Assigned( AcronymDb);630 AShowCategories.Enabled := Assigned( AcronymDb);631 AShowImportSources.Enabled := Assigned( AcronymDb);632 AShowImportFormats.Enabled := Assigned( AcronymDb);538 ListViewAcronyms.Enabled := Assigned(Core.AcronymDb); 539 AFileClose.Enabled := Assigned(Core.AcronymDb); 540 AFileSave.Enabled := Assigned(Core.AcronymDb) and Core.AcronymDb.Modified; 541 AFileSaveAs.Enabled := Assigned(Core.AcronymDb); 542 AManualImport.Enabled := Assigned(Core.AcronymDb); 543 AProcessImports.Enabled := Assigned(Core.AcronymDb); 544 AShowCategories.Enabled := Assigned(Core.AcronymDb); 545 AShowAcronyms.Enabled := Assigned(Core.AcronymDb); 546 AShowCategories.Enabled := Assigned(Core.AcronymDb); 547 AShowImportSources.Enabled := Assigned(Core.AcronymDb); 548 AShowImportFormats.Enabled := Assigned(Core.AcronymDb); 633 549 ToolBar1.Visible := MenuItemToolbar.Checked; 634 550 635 551 Title := Application.Title; 636 if Assigned( AcronymDb) and (ExtractFileName(AcronymDb.FileName) <> '') then637 if Assigned( AcronymDb) then Title := Title + ' - ' + ExtractFileName(AcronymDb.FileName);638 if Assigned( AcronymDb) andAcronymDb.Modified then Title := Title + ' (' + SModified + ')';552 if Assigned(Core.AcronymDb) and (ExtractFileName(Core.AcronymDb.FileName) <> '') then 553 if Assigned(Core.AcronymDb) then Title := Title + ' - ' + ExtractFileName(Core.AcronymDb.FileName); 554 if Assigned(Core.AcronymDb) and Core.AcronymDb.Modified then Title := Title + ' (' + SModified + ')'; 639 555 Caption := Title; 640 556 end; … … 660 576 CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', '')) 661 577 else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(''); 662 AlwaysOnTop := ReadBoolWithDefault('AlwaysOnTop', False);663 StartMinimizedToTray := ReadBoolWithDefault('StartMinimizedToTray', False);578 Core.AlwaysOnTop := ReadBoolWithDefault('AlwaysOnTop', False); 579 Core.StartMinimizedToTray := ReadBoolWithDefault('StartMinimizedToTray', False); 664 580 CheckBoxExactMath.Checked := ReadBoolWithDefault('ExactMatch', False); 665 581 MenuItemToolbar.Checked := ReadBoolWithDefault('ToolBarVisible', True); … … 672 588 RootKey := HKEY_CURRENT_USER; 673 589 OpenKey(RegistryRunKey, True); 674 StartOnLogon := ValueExists('Acronym Decoder');590 Core.StartOnLogon := ValueExists('Acronym Decoder'); 675 591 finally 676 592 Free; … … 690 606 WriteString('LanguageCode', CoolTranslator1.Language.Code) 691 607 else DeleteValue('LanguageCode'); 692 WriteBool('AlwaysOnTop', AlwaysOnTop);693 WriteBool('StartMinimizedToTray', StartMinimizedToTray);608 WriteBool('AlwaysOnTop', Core.AlwaysOnTop); 609 WriteBool('StartMinimizedToTray', Core.StartMinimizedToTray); 694 610 WriteBool('ExactMatch', CheckBoxExactMath.Checked); 695 611 WriteBool('ToolBarVisible', MenuItemToolbar.Checked); … … 702 618 RootKey := HKEY_CURRENT_USER; 703 619 OpenKey(RegistryRunKey, True); 704 if StartOnLogon then begin705 if StartMinimizedToTray then WriteString('Acronym Decoder', Application.ExeName + ' ' + Application.OptionChar + 't')620 if Core.StartOnLogon then begin 621 if Core.StartMinimizedToTray then WriteString('Acronym Decoder', Application.ExeName + ' ' + Application.OptionChar + 't') 706 622 else WriteString('Acronym Decoder', Application.ExeName) 707 623 end else DeleteValue('Acronym Decoder');
Note:
See TracChangeset
for help on using the changeset viewer.