| 1 | unit UFormMain;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
|
|---|
| 9 | ComCtrls, StdCtrls, ExtCtrls, ActnList, UAcronym, UPersistentForm, URegistry,
|
|---|
| 10 | ULastOpenedList, UListViewSort, UCoolTranslator, Registry,
|
|---|
| 11 | SpecializedList, LazUTF8;
|
|---|
| 12 |
|
|---|
| 13 | type
|
|---|
| 14 |
|
|---|
| 15 | { TFormMain }
|
|---|
| 16 |
|
|---|
| 17 | TFormMain = class(TForm)
|
|---|
| 18 | AProcessImports: TAction;
|
|---|
| 19 | AShowImportFormats: TAction;
|
|---|
| 20 | AShowAbout: TAction;
|
|---|
| 21 | AShowImportSources: TAction;
|
|---|
| 22 | AShowAcronyms: TAction;
|
|---|
| 23 | AShowCategories: TAction;
|
|---|
| 24 | ASettings: TAction;
|
|---|
| 25 | AFileSaveAs: TAction;
|
|---|
| 26 | AFileClose: TAction;
|
|---|
| 27 | AFileSave: TAction;
|
|---|
| 28 | AFileNew: TAction;
|
|---|
| 29 | AFileOpen: TAction;
|
|---|
| 30 | AManualImport: TAction;
|
|---|
| 31 | AShow: TAction;
|
|---|
| 32 | AExit: TAction;
|
|---|
| 33 | ActionList1: TActionList;
|
|---|
| 34 | CheckBoxExactMath: TCheckBox;
|
|---|
| 35 | CoolTranslator1: TCoolTranslator;
|
|---|
| 36 | ImageList1: TImageList;
|
|---|
| 37 | LastOpenedList1: TLastOpenedList;
|
|---|
| 38 | ListViewAcronyms: TListView;
|
|---|
| 39 | ListViewFilter1: TListViewFilter;
|
|---|
| 40 | ListViewSort1: TListViewSort;
|
|---|
| 41 | MainMenu1: TMainMenu;
|
|---|
| 42 | MenuItem1: TMenuItem;
|
|---|
| 43 | MenuItem10: TMenuItem;
|
|---|
| 44 | MenuItem11: TMenuItem;
|
|---|
| 45 | MenuItem12: TMenuItem;
|
|---|
| 46 | MenuItem13: TMenuItem;
|
|---|
| 47 | MenuItem14: TMenuItem;
|
|---|
| 48 | MenuItem15: TMenuItem;
|
|---|
| 49 | MenuItem16: TMenuItem;
|
|---|
| 50 | MenuItem17: TMenuItem;
|
|---|
| 51 | MenuItem18: TMenuItem;
|
|---|
| 52 | MenuItem19: TMenuItem;
|
|---|
| 53 | MenuItem20: TMenuItem;
|
|---|
| 54 | MenuItem21: TMenuItem;
|
|---|
| 55 | MenuItem22: TMenuItem;
|
|---|
| 56 | MenuItem23: TMenuItem;
|
|---|
| 57 | MenuItem24: TMenuItem;
|
|---|
| 58 | MenuItemToolbar: TMenuItem;
|
|---|
| 59 | MenuItem4: TMenuItem;
|
|---|
| 60 | MenuItem5: TMenuItem;
|
|---|
| 61 | MenuItem6: TMenuItem;
|
|---|
| 62 | MenuItem7: TMenuItem;
|
|---|
| 63 | MenuItemOpenRecent: TMenuItem;
|
|---|
| 64 | MenuItem2: TMenuItem;
|
|---|
| 65 | MenuItem3: TMenuItem;
|
|---|
| 66 | MenuItem8: TMenuItem;
|
|---|
| 67 | MenuItem9: TMenuItem;
|
|---|
| 68 | OpenDialog1: TOpenDialog;
|
|---|
| 69 | Panel1: TPanel;
|
|---|
| 70 | PersistentForm1: TPersistentForm;
|
|---|
| 71 | PopupMenuTryIcon: TPopupMenu;
|
|---|
| 72 | SaveDialog1: TSaveDialog;
|
|---|
| 73 | ToolBar1: TToolBar;
|
|---|
| 74 | ToolButton1: TToolButton;
|
|---|
| 75 | ToolButton2: TToolButton;
|
|---|
| 76 | ToolButton3: TToolButton;
|
|---|
| 77 | ToolButton4: TToolButton;
|
|---|
| 78 | ToolButton5: TToolButton;
|
|---|
| 79 | ToolButton6: TToolButton;
|
|---|
| 80 | ToolButton7: TToolButton;
|
|---|
| 81 | ToolButton8: TToolButton;
|
|---|
| 82 | TrayIcon1: TTrayIcon;
|
|---|
| 83 | procedure AExitExecute(Sender: TObject);
|
|---|
| 84 | procedure AFileCloseExecute(Sender: TObject);
|
|---|
| 85 | procedure AFileNewExecute(Sender: TObject);
|
|---|
| 86 | procedure AFileOpenExecute(Sender: TObject);
|
|---|
| 87 | procedure AFileSaveAsExecute(Sender: TObject);
|
|---|
| 88 | procedure AFileSaveExecute(Sender: TObject);
|
|---|
| 89 | procedure AManualImportExecute(Sender: TObject);
|
|---|
| 90 | procedure AProcessImportsExecute(Sender: TObject);
|
|---|
| 91 | procedure ASettingsExecute(Sender: TObject);
|
|---|
| 92 | procedure AShowAboutExecute(Sender: TObject);
|
|---|
| 93 | procedure AShowAcronymsExecute(Sender: TObject);
|
|---|
| 94 | procedure AShowCategoriesExecute(Sender: TObject);
|
|---|
| 95 | procedure AShowExecute(Sender: TObject);
|
|---|
| 96 | procedure AShowImportFormatsExecute(Sender: TObject);
|
|---|
| 97 | procedure AShowImportSourcesExecute(Sender: TObject);
|
|---|
| 98 | procedure CheckBoxExactMathChange(Sender: TObject);
|
|---|
| 99 | procedure EditSearchChange(Sender: TObject);
|
|---|
| 100 | procedure FormShow(Sender: TObject);
|
|---|
| 101 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 102 | procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
|---|
| 103 | procedure FormCreate(Sender: TObject);
|
|---|
| 104 | procedure FormDestroy(Sender: TObject);
|
|---|
| 105 | procedure LastOpenedList1Change(Sender: TObject);
|
|---|
| 106 | procedure ListViewAcronymsData(Sender: TObject; Item: TListItem);
|
|---|
| 107 | procedure ListViewAcronymsSelectItem(Sender: TObject; Item: TListItem;
|
|---|
| 108 | Selected: Boolean);
|
|---|
| 109 | procedure ListViewFilter1Change(Sender: TObject);
|
|---|
| 110 | function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
|
|---|
| 111 | procedure ListViewSort1Filter(ListViewSort: TListViewSort);
|
|---|
| 112 | procedure MenuItemToolbarClick(Sender: TObject);
|
|---|
| 113 | procedure TrayIcon1Click(Sender: TObject);
|
|---|
| 114 | private
|
|---|
| 115 | FAlwaysOnTop: Boolean;
|
|---|
| 116 | RegistryContext: TRegistryContext;
|
|---|
| 117 | ProjectClosed: Boolean;
|
|---|
| 118 | procedure SetAlwaysOnTop(AValue: Boolean);
|
|---|
| 119 | procedure FilterList(List: TListObject);
|
|---|
| 120 | procedure OpenRecentClick(Sender: TObject);
|
|---|
| 121 | procedure UpdateAcronymsList;
|
|---|
| 122 | procedure UpdateInterface;
|
|---|
| 123 | procedure LoadConfig;
|
|---|
| 124 | procedure SaveConfig;
|
|---|
| 125 | public
|
|---|
| 126 | AcronymDb: TAcronymDb;
|
|---|
| 127 | function CompareStrings(Strings1, Strings2: TStrings): Boolean;
|
|---|
| 128 | property AlwaysOnTop: Boolean read FAlwaysOnTop write SetAlwaysOnTop;
|
|---|
| 129 | end;
|
|---|
| 130 |
|
|---|
| 131 | var
|
|---|
| 132 | FormMain: TFormMain;
|
|---|
| 133 |
|
|---|
| 134 | resourcestring
|
|---|
| 135 | SAddedCount = 'Imported %d acronyms';
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 | implementation
|
|---|
| 139 |
|
|---|
| 140 | {$R *.lfm}
|
|---|
| 141 |
|
|---|
| 142 | uses
|
|---|
| 143 | UFormImport, UFormSettings, UFormCategories, UFormAcronyms,
|
|---|
| 144 | UFormImportSources, UFormAbout, UFormImportFormats;
|
|---|
| 145 |
|
|---|
| 146 | resourcestring
|
|---|
| 147 | SModified = 'modified';
|
|---|
| 148 | SAppExit = 'Application exit';
|
|---|
| 149 | SAppExitQuery = 'Acronyms were modified. Do you want to save them to file before exit?';
|
|---|
| 150 |
|
|---|
| 151 | const
|
|---|
| 152 | ProjectExt = '.adp';
|
|---|
| 153 | DefaultFileName = 'Acronyms' + ProjectExt;
|
|---|
| 154 | DefaultRegKey = '\Software\Acronym Decoder';
|
|---|
| 155 |
|
|---|
| 156 | { TFormMain }
|
|---|
| 157 |
|
|---|
| 158 | procedure TFormMain.FormCreate(Sender: TObject);
|
|---|
| 159 | begin
|
|---|
| 160 | AcronymDb := TAcronymDb.Create;
|
|---|
| 161 | end;
|
|---|
| 162 |
|
|---|
| 163 | procedure TFormMain.EditSearchChange(Sender: TObject);
|
|---|
| 164 | begin
|
|---|
| 165 | UpdateAcronymsList;
|
|---|
| 166 | end;
|
|---|
| 167 |
|
|---|
| 168 | procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 169 | begin
|
|---|
| 170 | PersistentForm1.Save(Self);
|
|---|
| 171 | SaveConfig;
|
|---|
| 172 | end;
|
|---|
| 173 |
|
|---|
| 174 | procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
|---|
| 175 | begin
|
|---|
| 176 | AFileClose.Execute;
|
|---|
| 177 | CanClose := ProjectClosed;
|
|---|
| 178 | end;
|
|---|
| 179 |
|
|---|
| 180 | procedure TFormMain.AExitExecute(Sender: TObject);
|
|---|
| 181 | begin
|
|---|
| 182 | Close;
|
|---|
| 183 | end;
|
|---|
| 184 |
|
|---|
| 185 | procedure TFormMain.AFileCloseExecute(Sender: TObject);
|
|---|
| 186 | var
|
|---|
| 187 | ModalResult: TModalResult;
|
|---|
| 188 | DoClose: Boolean;
|
|---|
| 189 | begin
|
|---|
| 190 | DoClose := False;
|
|---|
| 191 | if Assigned(AcronymDb) then begin
|
|---|
| 192 | if AcronymDb.Modified then begin
|
|---|
| 193 | ModalResult := MessageDlg(SAppExit, SAppExitQuery,
|
|---|
| 194 | mtConfirmation, [mbYes, mbNo, mbCancel], 0);
|
|---|
| 195 | if ModalResult = mrYes then begin
|
|---|
| 196 | AFileSave.Execute;
|
|---|
| 197 | DoClose := True;
|
|---|
| 198 | end
|
|---|
| 199 | else if ModalResult = mrNo then begin
|
|---|
| 200 | DoClose := True;
|
|---|
| 201 | end else ProjectClosed := False;
|
|---|
| 202 | end else DoClose := True;
|
|---|
| 203 | end;
|
|---|
| 204 | if DoClose then begin
|
|---|
| 205 | FreeAndNil(AcronymDb);
|
|---|
| 206 | UpdateAcronymsList;
|
|---|
| 207 | UpdateInterface;
|
|---|
| 208 | ProjectClosed := True;
|
|---|
| 209 | end;
|
|---|
| 210 | end;
|
|---|
| 211 |
|
|---|
| 212 | procedure TFormMain.AFileNewExecute(Sender: TObject);
|
|---|
| 213 | begin
|
|---|
| 214 | AFileClose.Execute;
|
|---|
| 215 | if ProjectClosed then begin
|
|---|
| 216 | AcronymDb := TAcronymDb.Create;
|
|---|
| 217 | AcronymDb.FileName := DefaultFileName;
|
|---|
| 218 | AcronymDb.Acronyms.Clear;
|
|---|
| 219 | UpdateAcronymsList;
|
|---|
| 220 | UpdateInterface;
|
|---|
| 221 | end;
|
|---|
| 222 | end;
|
|---|
| 223 |
|
|---|
| 224 | procedure TFormMain.AFileOpenExecute(Sender: TObject);
|
|---|
| 225 | begin
|
|---|
| 226 | OpenDialog1.DefaultExt := ProjectExt;
|
|---|
| 227 | if Assigned(AcronymDb) then
|
|---|
| 228 | OpenDialog1.FileName := AcronymDb.FileName;
|
|---|
| 229 | if OpenDialog1.Execute then begin
|
|---|
| 230 | AFileClose.Execute;
|
|---|
| 231 | if ProjectClosed then begin
|
|---|
| 232 | AFileNew.Execute;
|
|---|
| 233 | AcronymDb.LoadFromFile(OpenDialog1.FileName);
|
|---|
| 234 | LastOpenedList1.AddItem(OpenDialog1.FileName);
|
|---|
| 235 | UpdateAcronymsList;
|
|---|
| 236 | UpdateInterface;
|
|---|
| 237 | end;
|
|---|
| 238 | end;
|
|---|
| 239 | end;
|
|---|
| 240 |
|
|---|
| 241 | procedure TFormMain.AFileSaveAsExecute(Sender: TObject);
|
|---|
| 242 | begin
|
|---|
| 243 | SaveDialog1.DefaultExt := ProjectExt;
|
|---|
| 244 | SaveDialog1.FileName := AcronymDb.FileName;
|
|---|
| 245 | if SaveDialog1.Execute then begin
|
|---|
| 246 | AcronymDb.SaveToFile(SaveDialog1.FileName);
|
|---|
| 247 | LastOpenedList1.AddItem(SaveDialog1.FileName);
|
|---|
| 248 | UpdateInterface;
|
|---|
| 249 | end;
|
|---|
| 250 | end;
|
|---|
| 251 |
|
|---|
| 252 | procedure TFormMain.AFileSaveExecute(Sender: TObject);
|
|---|
| 253 | begin
|
|---|
| 254 | if FileExists(AcronymDb.FileName) then begin
|
|---|
| 255 | AcronymDb.SaveToFile(AcronymDb.FileName);
|
|---|
| 256 | LastOpenedList1.AddItem(AcronymDb.FileName);
|
|---|
| 257 | UpdateInterface;
|
|---|
| 258 | end else AFileSaveAs.Execute;
|
|---|
| 259 | end;
|
|---|
| 260 |
|
|---|
| 261 | procedure TFormMain.AManualImportExecute(Sender: TObject);
|
|---|
| 262 | begin
|
|---|
| 263 | FormImport.ShowModal;
|
|---|
| 264 | UpdateAcronymsList;
|
|---|
| 265 | UpdateInterface;
|
|---|
| 266 | end;
|
|---|
| 267 |
|
|---|
| 268 | procedure TFormMain.AProcessImportsExecute(Sender: TObject);
|
|---|
| 269 | var
|
|---|
| 270 | I: Integer;
|
|---|
| 271 | TotalItemCount: Integer;
|
|---|
| 272 | begin
|
|---|
| 273 | TotalItemCount := 0;
|
|---|
| 274 | for I := 0 to AcronymDb.ImportSources.Count - 1 do
|
|---|
| 275 | with TImportSource(AcronymDb.ImportSources[I]) do
|
|---|
| 276 | if Enabled then begin
|
|---|
| 277 | Process;
|
|---|
| 278 | TotalItemCount := TotalItemCount + ItemCount;
|
|---|
| 279 | end;
|
|---|
| 280 | ShowMessage(Format(SAddedCount, [TotalItemCount]));
|
|---|
| 281 | UpdateAcronymsList;
|
|---|
| 282 | UpdateInterface;
|
|---|
| 283 | end;
|
|---|
| 284 |
|
|---|
| 285 | procedure TFormMain.ASettingsExecute(Sender: TObject);
|
|---|
| 286 | begin
|
|---|
| 287 | FormSettings.Load;
|
|---|
| 288 | if FormSettings.ShowModal = mrOk then
|
|---|
| 289 | FormSettings.Save;
|
|---|
| 290 | end;
|
|---|
| 291 |
|
|---|
| 292 | procedure TFormMain.AShowAboutExecute(Sender: TObject);
|
|---|
| 293 | begin
|
|---|
| 294 | FormAbout.ShowModal;
|
|---|
| 295 | end;
|
|---|
| 296 |
|
|---|
| 297 | procedure TFormMain.AShowAcronymsExecute(Sender: TObject);
|
|---|
| 298 | begin
|
|---|
| 299 | FormAcronyms.ShowModal;
|
|---|
| 300 | UpdateInterface;
|
|---|
| 301 | end;
|
|---|
| 302 |
|
|---|
| 303 | procedure TFormMain.AShowCategoriesExecute(Sender: TObject);
|
|---|
| 304 | begin
|
|---|
| 305 | FormCategories.Categories := AcronymDb.Categories;
|
|---|
| 306 | FormCategories.ShowModal;
|
|---|
| 307 | UpdateAcronymsList;
|
|---|
| 308 | UpdateInterface;
|
|---|
| 309 | end;
|
|---|
| 310 |
|
|---|
| 311 | procedure TFormMain.AShowExecute(Sender: TObject);
|
|---|
| 312 | begin
|
|---|
| 313 | Show;
|
|---|
| 314 | end;
|
|---|
| 315 |
|
|---|
| 316 | procedure TFormMain.AShowImportFormatsExecute(Sender: TObject);
|
|---|
| 317 | begin
|
|---|
| 318 | FormImportFormats.ImportFormats := AcronymDb.ImportFormats;
|
|---|
| 319 | FormImportFormats.ShowModal;
|
|---|
| 320 | UpdateInterface;
|
|---|
| 321 | end;
|
|---|
| 322 |
|
|---|
| 323 | procedure TFormMain.AShowImportSourcesExecute(Sender: TObject);
|
|---|
| 324 | begin
|
|---|
| 325 | FormImportSources.ImportSources := AcronymDb.ImportSources;
|
|---|
| 326 | FormImportSources.ShowModal;
|
|---|
| 327 | UpdateInterface;
|
|---|
| 328 | end;
|
|---|
| 329 |
|
|---|
| 330 | procedure TFormMain.CheckBoxExactMathChange(Sender: TObject);
|
|---|
| 331 | begin
|
|---|
| 332 | UpdateAcronymsList;
|
|---|
| 333 | end;
|
|---|
| 334 |
|
|---|
| 335 | procedure TFormMain.FormDestroy(Sender: TObject);
|
|---|
| 336 | begin
|
|---|
| 337 | FreeAndNil(AcronymDb);
|
|---|
| 338 | end;
|
|---|
| 339 |
|
|---|
| 340 | procedure TFormMain.FormShow(Sender: TObject);
|
|---|
| 341 | var
|
|---|
| 342 | I: Integer;
|
|---|
| 343 | begin
|
|---|
| 344 | LoadConfig;
|
|---|
| 345 | PersistentForm1.Load(Self);
|
|---|
| 346 |
|
|---|
| 347 | if ParamCount > 0 then begin
|
|---|
| 348 | AcronymDB.LoadFromFile(ParamStr(1));
|
|---|
| 349 | LastOpenedList1.AddItem(OpenDialog1.FileName);
|
|---|
| 350 | end else
|
|---|
| 351 | if (LastOpenedList1.Items.Count > 0) and FileExists(LastOpenedList1.Items[0]) then
|
|---|
| 352 | AcronymDB.LoadFromFile(LastOpenedList1.Items[0]);
|
|---|
| 353 | UpdateAcronymsList;
|
|---|
| 354 | ListViewFilter1.UpdateFromListView(ListViewAcronyms);
|
|---|
| 355 | UpdateInterface;
|
|---|
| 356 | for I := 0 to ToolBar1.ButtonCount - 1 do
|
|---|
| 357 | ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
|
|---|
| 358 | end;
|
|---|
| 359 |
|
|---|
| 360 | procedure TFormMain.LastOpenedList1Change(Sender: TObject);
|
|---|
| 361 | begin
|
|---|
| 362 | LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, OpenRecentClick);
|
|---|
| 363 | end;
|
|---|
| 364 |
|
|---|
| 365 | procedure TFormMain.ListViewAcronymsData(Sender: TObject; Item: TListItem);
|
|---|
| 366 | begin
|
|---|
| 367 | if Item.Index < ListViewSort1.List.Count then
|
|---|
| 368 | with TAcronymMeaning(ListViewSort1.List[Item.Index]) do begin
|
|---|
| 369 | Item.Caption := Acronym.Name;
|
|---|
| 370 | Item.SubItems.Add(Name);
|
|---|
| 371 | Item.Data := TAcronymMeaning(ListViewSort1.List[Item.Index]);
|
|---|
| 372 | Item.SubItems.Add(Categories.GetString);
|
|---|
| 373 | end;
|
|---|
| 374 | end;
|
|---|
| 375 |
|
|---|
| 376 | procedure TFormMain.ListViewAcronymsSelectItem(Sender: TObject;
|
|---|
| 377 | Item: TListItem; Selected: Boolean);
|
|---|
| 378 | begin
|
|---|
| 379 | UpdateInterface;
|
|---|
| 380 | end;
|
|---|
| 381 |
|
|---|
| 382 | procedure TFormMain.ListViewFilter1Change(Sender: TObject);
|
|---|
| 383 | begin
|
|---|
| 384 | UpdateAcronymsList;
|
|---|
| 385 | end;
|
|---|
| 386 |
|
|---|
| 387 | function TFormMain.ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
|
|---|
| 388 | begin
|
|---|
| 389 | Result := 0;
|
|---|
| 390 | if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin
|
|---|
| 391 | with ListViewSort1 do
|
|---|
| 392 | case Column of
|
|---|
| 393 | 0: Result := CompareString(TAcronymMeaning(Item1).Acronym.Name, TAcronymMeaning(Item2).Acronym.Name);
|
|---|
| 394 | 1: Result := CompareString(TAcronymMeaning(Item1).Description, TAcronymMeaning(Item2).Description);
|
|---|
| 395 | 2: Result := CompareString(TAcronymMeaning(Item1).Categories.GetString, TAcronymMeaning(Item2).Categories.GetString);
|
|---|
| 396 | end;
|
|---|
| 397 | if ListViewSort1.Order = soDown then Result := -Result;
|
|---|
| 398 | end else Result := 0;
|
|---|
| 399 | end;
|
|---|
| 400 |
|
|---|
| 401 | procedure TFormMain.ListViewSort1Filter(ListViewSort: TListViewSort);
|
|---|
| 402 | begin
|
|---|
| 403 | AcronymDb.Acronyms.Sort(AcronymComparer);
|
|---|
| 404 | AcronymDb.AssignToList(ListViewSort1.List);
|
|---|
| 405 | FilterList(ListViewSort1.List);
|
|---|
| 406 | end;
|
|---|
| 407 |
|
|---|
| 408 | procedure TFormMain.MenuItemToolbarClick(Sender: TObject);
|
|---|
| 409 | begin
|
|---|
| 410 | MenuItemToolbar.Checked := not MenuItemToolbar.Checked;
|
|---|
| 411 | UpdateInterface;
|
|---|
| 412 | end;
|
|---|
| 413 |
|
|---|
| 414 | procedure TFormMain.TrayIcon1Click(Sender: TObject);
|
|---|
| 415 | begin
|
|---|
| 416 | Visible := not Visible;
|
|---|
| 417 | end;
|
|---|
| 418 |
|
|---|
| 419 | function TFormMain.CompareStrings(Strings1, Strings2: TStrings): Boolean;
|
|---|
| 420 | var
|
|---|
| 421 | I: Integer;
|
|---|
| 422 | begin
|
|---|
| 423 | Result := Strings1.Count = Strings2.Count;
|
|---|
| 424 | if not Result then Exit;
|
|---|
| 425 | for I := 0 to Strings1.Count - 1 do
|
|---|
| 426 | if (Strings1[I] <> Strings2[I]) or (Strings1.Objects[I] <> Strings2.Objects[I]) then begin
|
|---|
| 427 | Result := False;
|
|---|
| 428 | Exit;
|
|---|
| 429 | end;
|
|---|
| 430 | end;
|
|---|
| 431 |
|
|---|
| 432 | procedure TFormMain.SetAlwaysOnTop(AValue: Boolean);
|
|---|
| 433 | begin
|
|---|
| 434 | if FAlwaysOnTop = AValue then Exit;
|
|---|
| 435 | FAlwaysOnTop := AValue;
|
|---|
| 436 | if FAlwaysOnTop then FormStyle := fsSystemStayOnTop
|
|---|
| 437 | else FormStyle := fsNormal;
|
|---|
| 438 | end;
|
|---|
| 439 |
|
|---|
| 440 | procedure TFormMain.FilterList(List: TListObject);
|
|---|
| 441 | var
|
|---|
| 442 | I: Integer;
|
|---|
| 443 | FoundCount: Integer;
|
|---|
| 444 | EnteredCount: Integer;
|
|---|
| 445 | begin
|
|---|
| 446 | EnteredCount := ListViewFilter1.TextEnteredCount;
|
|---|
| 447 | for I := List.Count - 1 downto 0 do begin
|
|---|
| 448 | if List.Items[I] is TAcronymMeaning then begin
|
|---|
| 449 | with TAcronymMeaning(List.Items[I]) do begin
|
|---|
| 450 | with ListViewFilter1 do
|
|---|
| 451 | if Visible and (EnteredCount > 0) then begin
|
|---|
| 452 | FoundCount := 0;
|
|---|
| 453 | if CheckBoxExactMath.Checked then begin
|
|---|
| 454 | if TextEnteredColumn(0) and (StringGrid.Cells[0, 0] =
|
|---|
| 455 | TAcronymMeaning(List.Items[I]).Acronym.Name) then Inc(FoundCount);
|
|---|
| 456 | if TextEnteredColumn(1) and (StringGrid.Cells[1, 0] =
|
|---|
| 457 | TAcronymMeaning(List.Items[I]).Name) then Inc(FoundCount);
|
|---|
| 458 | if TextEnteredColumn(2) and (StringGrid.Cells[2, 0] =
|
|---|
| 459 | TAcronymMeaning(List.Items[I]).Categories.GetString) then Inc(FoundCount);
|
|---|
| 460 | end else begin
|
|---|
| 461 | if Pos(UTF8LowerCase(StringGrid.Cells[0, 0]),
|
|---|
| 462 | UTF8LowerCase(TAcronymMeaning(List.Items[I]).Acronym.Name)) > 0 then Inc(FoundCount);
|
|---|
| 463 | if Pos(UTF8LowerCase(StringGrid.Cells[1, 0]),
|
|---|
| 464 | UTF8LowerCase(TAcronymMeaning(List.Items[I]).Name)) > 0 then Inc(FoundCount);
|
|---|
| 465 | if Pos(UTF8LowerCase(StringGrid.Cells[2, 0]),
|
|---|
| 466 | UTF8LowerCase(TAcronymMeaning(List.Items[I]).Categories.GetString)) > 0 then Inc(FoundCount);
|
|---|
| 467 | end;
|
|---|
| 468 | if FoundCount <> EnteredCount then List.Delete(I);
|
|---|
| 469 | end else List.Delete(I);
|
|---|
| 470 | end;
|
|---|
| 471 | end else
|
|---|
| 472 | if TAcronymMeaning(List.Items[I]) is TAcronymMeaning then begin
|
|---|
| 473 | List.Delete(I);
|
|---|
| 474 | end;
|
|---|
| 475 | end;
|
|---|
| 476 | end;
|
|---|
| 477 |
|
|---|
| 478 | procedure TFormMain.OpenRecentClick(Sender: TObject);
|
|---|
| 479 | begin
|
|---|
| 480 | AFileClose.Execute;
|
|---|
| 481 | if ProjectClosed then begin
|
|---|
| 482 | AFileNew.Execute;
|
|---|
| 483 | AcronymDb.LoadFromFile(TMenuItem(Sender).Caption);
|
|---|
| 484 | LastOpenedList1.AddItem(TMenuItem(Sender).Caption);
|
|---|
| 485 | UpdateAcronymsList;
|
|---|
| 486 | UpdateInterface;
|
|---|
| 487 | end;
|
|---|
| 488 | end;
|
|---|
| 489 |
|
|---|
| 490 | procedure TFormMain.UpdateAcronymsList;
|
|---|
| 491 | begin
|
|---|
| 492 | if Assigned(AcronymDb) then begin
|
|---|
| 493 | ListViewSort1.Refresh;
|
|---|
| 494 | end else ListViewSort1.List.Clear;
|
|---|
| 495 | end;
|
|---|
| 496 |
|
|---|
| 497 | procedure TFormMain.UpdateInterface;
|
|---|
| 498 | var
|
|---|
| 499 | Title: string;
|
|---|
| 500 | begin
|
|---|
| 501 | ListViewAcronyms.Enabled := Assigned(AcronymDb);
|
|---|
| 502 | AFileClose.Enabled := Assigned(AcronymDb);
|
|---|
| 503 | AFileSave.Enabled := Assigned(AcronymDb) and AcronymDb.Modified;
|
|---|
| 504 | AFileSaveAs.Enabled := Assigned(AcronymDb);
|
|---|
| 505 | AManualImport.Enabled := Assigned(AcronymDb);
|
|---|
| 506 | AShowCategories.Enabled := Assigned(AcronymDb);
|
|---|
| 507 | AShowAcronyms.Enabled := Assigned(AcronymDb);
|
|---|
| 508 | AShowImportSources.Enabled := Assigned(AcronymDb);
|
|---|
| 509 | ToolBar1.Visible := MenuItemToolbar.Checked;
|
|---|
| 510 |
|
|---|
| 511 | Title := Application.Title;
|
|---|
| 512 | if Assigned(AcronymDb) then Title := Title + ' - ' + ExtractFileName(AcronymDb.FileName);
|
|---|
| 513 | if Assigned(AcronymDb) and AcronymDb.Modified then Title := Title + ' (' + SModified + ')';
|
|---|
| 514 | Caption := Title;
|
|---|
| 515 | end;
|
|---|
| 516 |
|
|---|
| 517 | procedure TFormMain.LoadConfig;
|
|---|
| 518 | begin
|
|---|
| 519 | RegistryContext := RegContext(HKEY_CURRENT_USER, DefaultRegKey);
|
|---|
| 520 | PersistentForm1.RegistryContext := RegistryContext;
|
|---|
| 521 | LastOpenedList1.LoadFromRegistry(RegistryContext);
|
|---|
| 522 |
|
|---|
| 523 | with TRegistryEx.Create do
|
|---|
| 524 | try
|
|---|
| 525 | RootKey := HKEY_CURRENT_USER;
|
|---|
| 526 | OpenKey(DefaultRegKey, True);
|
|---|
| 527 | if ValueExists('LanguageCode') then
|
|---|
| 528 | CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
|
|---|
| 529 | else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');
|
|---|
| 530 | AlwaysOnTop := ReadBoolWithDefault('AlwaysOnTop', False);
|
|---|
| 531 | CheckBoxExactMath.Checked := ReadBoolWithDefault('ExactMatch', False);
|
|---|
| 532 | MenuItemToolbar.Checked := ReadBoolWithDefault('ToolBarVisible', True);
|
|---|
| 533 | finally
|
|---|
| 534 | Free;
|
|---|
| 535 | end;
|
|---|
| 536 | end;
|
|---|
| 537 |
|
|---|
| 538 | procedure TFormMain.SaveConfig;
|
|---|
| 539 | begin
|
|---|
| 540 | LastOpenedList1.SaveToRegistry(RegistryContext);
|
|---|
| 541 |
|
|---|
| 542 | with TRegistryEx.Create do
|
|---|
| 543 | try
|
|---|
| 544 | RootKey := HKEY_CURRENT_USER;
|
|---|
| 545 | OpenKey(DefaultRegKey, True);
|
|---|
| 546 | if Assigned(CoolTranslator1.Language) and (CoolTranslator1.Language.Code <> '') then
|
|---|
| 547 | WriteString('LanguageCode', CoolTranslator1.Language.Code)
|
|---|
| 548 | else DeleteValue('LanguageCode');
|
|---|
| 549 | WriteBool('AlwaysOnTop', AlwaysOnTop);
|
|---|
| 550 | WriteBool('ExactMatch', CheckBoxExactMath.Checked);
|
|---|
| 551 | WriteBool('ToolBarVisible', MenuItemToolbar.Checked);
|
|---|
| 552 | finally
|
|---|
| 553 | Free;
|
|---|
| 554 | end;
|
|---|
| 555 | end;
|
|---|
| 556 |
|
|---|
| 557 | end.
|
|---|
| 558 |
|
|---|