| 1 | unit FormMain;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, LazFileUtils, Forms, Controls, Graphics, Dialogs, Menus,
|
|---|
| 7 | ComCtrls, FormContacts, FormEx;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 |
|
|---|
| 11 | { TFormMain }
|
|---|
| 12 |
|
|---|
| 13 | TFormMain = class(TFormEx)
|
|---|
| 14 | CoolBar1: TCoolBar;
|
|---|
| 15 | MainMenu1: TMainMenu;
|
|---|
| 16 | MenuItem1: TMenuItem;
|
|---|
| 17 | MenuItem10: TMenuItem;
|
|---|
| 18 | MenuItem11: TMenuItem;
|
|---|
| 19 | MenuItem12: TMenuItem;
|
|---|
| 20 | MenuItem13: TMenuItem;
|
|---|
| 21 | MenuItem14: TMenuItem;
|
|---|
| 22 | MenuItem15: TMenuItem;
|
|---|
| 23 | MenuItem16: TMenuItem;
|
|---|
| 24 | MenuItem17: TMenuItem;
|
|---|
| 25 | MenuItem18: TMenuItem;
|
|---|
| 26 | MenuItemColumns: TMenuItem;
|
|---|
| 27 | MenuItem3: TMenuItem;
|
|---|
| 28 | MenuItem4: TMenuItem;
|
|---|
| 29 | MenuItem5: TMenuItem;
|
|---|
| 30 | MenuItem6: TMenuItem;
|
|---|
| 31 | MenuItem7: TMenuItem;
|
|---|
| 32 | MenuItem8: TMenuItem;
|
|---|
| 33 | MenuItem9: TMenuItem;
|
|---|
| 34 | MenuItemToolbar: TMenuItem;
|
|---|
| 35 | MenuItemView: TMenuItem;
|
|---|
| 36 | MenuItemExit: TMenuItem;
|
|---|
| 37 | MenuItemHomePage: TMenuItem;
|
|---|
| 38 | MenuItemAbout: TMenuItem;
|
|---|
| 39 | MenuItem2: TMenuItem;
|
|---|
| 40 | MenuItemFileNew: TMenuItem;
|
|---|
| 41 | MenuItemFileOpen: TMenuItem;
|
|---|
| 42 | MenuItemSettings: TMenuItem;
|
|---|
| 43 | MenuItemTools: TMenuItem;
|
|---|
| 44 | MenuItemFileOpenRecent: TMenuItem;
|
|---|
| 45 | MenuItemFileSave: TMenuItem;
|
|---|
| 46 | MenuItemFileSaveAs: TMenuItem;
|
|---|
| 47 | MenuItemFileClose: TMenuItem;
|
|---|
| 48 | MenuItemHelp: TMenuItem;
|
|---|
| 49 | MenuItemFile: TMenuItem;
|
|---|
| 50 | PopupMenuOpenRecent: TPopupMenu;
|
|---|
| 51 | Separator1: TMenuItem;
|
|---|
| 52 | Separator2: TMenuItem;
|
|---|
| 53 | ToolBarOther: TToolBar;
|
|---|
| 54 | ToolBarFile: TToolBar;
|
|---|
| 55 | ToolButton1: TToolButton;
|
|---|
| 56 | ToolButton2: TToolButton;
|
|---|
| 57 | ToolButton3: TToolButton;
|
|---|
| 58 | ToolButton4: TToolButton;
|
|---|
| 59 | ToolButton5: TToolButton;
|
|---|
| 60 | ToolButton6: TToolButton;
|
|---|
| 61 | ToolButton7: TToolButton;
|
|---|
| 62 | ToolButton8: TToolButton;
|
|---|
| 63 | procedure FormActivate(Sender: TObject);
|
|---|
| 64 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 65 | procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
|---|
| 66 | procedure FormCreate(Sender: TObject);
|
|---|
| 67 | procedure FormDestroy(Sender: TObject);
|
|---|
| 68 | procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
|
|---|
| 69 | procedure FormResize(Sender: TObject);
|
|---|
| 70 | procedure FormShow(Sender: TObject);
|
|---|
| 71 | procedure MenuItemColumnsClick(Sender: TObject);
|
|---|
| 72 | procedure MenuItemToolbarClick(Sender: TObject);
|
|---|
| 73 | private
|
|---|
| 74 | procedure SetToolbarHints;
|
|---|
| 75 | procedure UpdateFormTitle;
|
|---|
| 76 | procedure DataFileChangeExecute(Sender: TObject);
|
|---|
| 77 | procedure LastOpenedFileChangeExecute(Sender: TObject);
|
|---|
| 78 | procedure LoadConfig;
|
|---|
| 79 | procedure SaveConfig;
|
|---|
| 80 | public
|
|---|
| 81 | FormContacts: TFormContacts;
|
|---|
| 82 | procedure UpdateInterface;
|
|---|
| 83 | procedure SettingsChanged;
|
|---|
| 84 | procedure ToggleFullScreen;
|
|---|
| 85 | end;
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | implementation
|
|---|
| 89 |
|
|---|
| 90 | {$R *.lfm}
|
|---|
| 91 |
|
|---|
| 92 | uses
|
|---|
| 93 | Core, VCard, VCardFile, RegistryEx;
|
|---|
| 94 |
|
|---|
| 95 | resourcestring
|
|---|
| 96 | SModified = 'Modified';
|
|---|
| 97 | SOnlyOneFileCanBeDropped = 'Only one file can be dropped at once.';
|
|---|
| 98 |
|
|---|
| 99 | { TFormMain }
|
|---|
| 100 |
|
|---|
| 101 | procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 102 | begin
|
|---|
| 103 | SaveConfig;
|
|---|
| 104 | FormContacts.Close;
|
|---|
| 105 | Application.Terminate;
|
|---|
| 106 | end;
|
|---|
| 107 |
|
|---|
| 108 | procedure TFormMain.FormActivate(Sender: TObject);
|
|---|
| 109 | begin
|
|---|
| 110 | Core.Core.Initialize;
|
|---|
| 111 | end;
|
|---|
| 112 |
|
|---|
| 113 | procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
|---|
| 114 | begin
|
|---|
| 115 | Core.Core.AFileClose.Execute;
|
|---|
| 116 | CanClose := Core.Core.FileClosed;
|
|---|
| 117 | end;
|
|---|
| 118 |
|
|---|
| 119 | procedure TFormMain.FormCreate(Sender: TObject);
|
|---|
| 120 | begin
|
|---|
| 121 | FormContacts := TFormContacts.Create(nil);
|
|---|
| 122 | Core.Core.OnDataFileChange := DataFileChangeExecute;
|
|---|
| 123 | Core.Core.OnLastOpenedListChange := LastOpenedFileChangeExecute;
|
|---|
| 124 | LastOpenedFileChangeExecute(Self);
|
|---|
| 125 | LoadConfig;
|
|---|
| 126 | end;
|
|---|
| 127 |
|
|---|
| 128 | procedure TFormMain.FormDestroy(Sender: TObject);
|
|---|
| 129 | begin
|
|---|
| 130 | Core.Core.OnDataFileChange := nil;
|
|---|
| 131 | Core.Core.OnLastOpenedListChange := nil;
|
|---|
| 132 | FreeAndNil(FormContacts);
|
|---|
| 133 | end;
|
|---|
| 134 |
|
|---|
| 135 | procedure TFormMain.FormDropFiles(Sender: TObject;
|
|---|
| 136 | const FileNames: array of string);
|
|---|
| 137 | begin
|
|---|
| 138 | if Length(FileNames) <> 1 then ShowMessage(SOnlyOneFileCanBeDropped)
|
|---|
| 139 | else begin
|
|---|
| 140 | Core.Core.FileOpen(FileNames[0]);
|
|---|
| 141 | Core.Core.UpdateFile;
|
|---|
| 142 | end;
|
|---|
| 143 | end;
|
|---|
| 144 |
|
|---|
| 145 | procedure TFormMain.FormResize(Sender: TObject);
|
|---|
| 146 | begin
|
|---|
| 147 | CoolBar1.AutosizeBands;
|
|---|
| 148 | end;
|
|---|
| 149 |
|
|---|
| 150 | procedure TFormMain.FormShow(Sender: TObject);
|
|---|
| 151 | begin
|
|---|
| 152 | FormContacts.BeginUpdate;
|
|---|
| 153 | try
|
|---|
| 154 | SetToolbarHints;
|
|---|
| 155 | ScaleDPI.ScaleControl(CoolBar1, Core.Core.ScaleDPI1.DesignDPI);
|
|---|
| 156 | CoolBar1.AutosizeBands;
|
|---|
| 157 |
|
|---|
| 158 | FormContacts.Context := TRegistryContext.Create(Core.Core.ApplicationInfo1.RegistryRoot,
|
|---|
| 159 | Core.Core.ApplicationInfo1.RegistryKey + '\ContactsColumns');
|
|---|
| 160 | FormContacts.ManualDock(Self, nil, alClient);
|
|---|
| 161 | FormContacts.Align := alClient;
|
|---|
| 162 | FormContacts.Show;
|
|---|
| 163 | finally
|
|---|
| 164 | FormContacts.EndUpdate;
|
|---|
| 165 | end;
|
|---|
| 166 | end;
|
|---|
| 167 |
|
|---|
| 168 | procedure TFormMain.MenuItemColumnsClick(Sender: TObject);
|
|---|
| 169 | begin
|
|---|
| 170 | FormContacts.AColumns.Execute;
|
|---|
| 171 | end;
|
|---|
| 172 |
|
|---|
| 173 | procedure TFormMain.MenuItemToolbarClick(Sender: TObject);
|
|---|
| 174 | begin
|
|---|
| 175 | UpdateInterface;
|
|---|
| 176 | end;
|
|---|
| 177 |
|
|---|
| 178 | procedure TFormMain.SetToolbarHints;
|
|---|
| 179 | var
|
|---|
| 180 | I: Integer;
|
|---|
| 181 | J: Integer;
|
|---|
| 182 | Control: TControl;
|
|---|
| 183 | begin
|
|---|
| 184 | for J := 0 to CoolBar1.ControlCount - 1 do begin
|
|---|
| 185 | Control := CoolBar1.Controls[J];
|
|---|
| 186 | if Control is TToolBar then begin
|
|---|
| 187 | for I := 0 to TToolBar(Control).ButtonCount - 1 do begin
|
|---|
| 188 | TToolBar(Control).Buttons[I].ShowHint := True;
|
|---|
| 189 | TToolBar(Control).Buttons[I].Hint := TToolBar(Control).Buttons[I].Caption;
|
|---|
| 190 | end;
|
|---|
| 191 | end;
|
|---|
| 192 | end;
|
|---|
| 193 | end;
|
|---|
| 194 |
|
|---|
| 195 | procedure TFormMain.UpdateFormTitle;
|
|---|
| 196 | var
|
|---|
| 197 | Title: string;
|
|---|
| 198 | begin
|
|---|
| 199 | Title := '';
|
|---|
| 200 | if Assigned(Core.Core.DataFile) and
|
|---|
| 201 | (ExtractFileNameWithoutExt(ExtractFileName(Core.Core.DataFile.FileName)) <> '') then
|
|---|
| 202 | Title := Title + ExtractFileNameWithoutExt(ExtractFileName(Core.Core.DataFile.FileName));
|
|---|
| 203 | if Assigned(Core.Core.DataFile) and Core.Core.DataFile.Modified then
|
|---|
| 204 | Title := Title + ' (' + SModified + ')';
|
|---|
| 205 | if Title <> '' then Title := Title + ' - ';
|
|---|
| 206 | Title := Title + Core.Core.ApplicationInfo1.AppName;
|
|---|
| 207 | //Application.Title := Title;
|
|---|
| 208 | Caption := Title;
|
|---|
| 209 | end;
|
|---|
| 210 |
|
|---|
| 211 | procedure TFormMain.DataFileChangeExecute(Sender: TObject);
|
|---|
| 212 | begin
|
|---|
| 213 | if Assigned(FormContacts) then begin
|
|---|
| 214 | if Assigned(Core.Core.DataFile) then
|
|---|
| 215 | FormContacts.Contacts := TVCardFile(Core.Core.DataFile).VCard.Contacts
|
|---|
| 216 | else FormContacts.Contacts := nil;
|
|---|
| 217 | end;
|
|---|
| 218 |
|
|---|
| 219 | FormContacts.ReloadList;
|
|---|
| 220 | FormContacts.UpdateInterface;
|
|---|
| 221 | UpdateInterface;
|
|---|
| 222 | end;
|
|---|
| 223 |
|
|---|
| 224 | procedure TFormMain.LastOpenedFileChangeExecute(Sender: TObject);
|
|---|
| 225 | begin
|
|---|
| 226 | Core.Core.LastOpenedList1.LoadToMenuItem(MenuItemFileOpenRecent, Core.Core.AFileOpenRecentExecute);
|
|---|
| 227 | Core.Core.LastOpenedList1.LoadToMenuItem(PopupMenuOpenRecent.Items, Core.Core.AFileOpenRecentExecute);
|
|---|
| 228 | end;
|
|---|
| 229 |
|
|---|
| 230 | procedure TFormMain.LoadConfig;
|
|---|
| 231 | begin
|
|---|
| 232 | with TRegistryEx.Create do
|
|---|
| 233 | try
|
|---|
| 234 | CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
|
|---|
| 235 | MenuItemToolbar.Checked := ReadBoolWithDefault('ToolBarVisible', True);
|
|---|
| 236 | finally
|
|---|
| 237 | Free;
|
|---|
| 238 | end;
|
|---|
| 239 | end;
|
|---|
| 240 |
|
|---|
| 241 | procedure TFormMain.SaveConfig;
|
|---|
| 242 | begin
|
|---|
| 243 | with TRegistryEx.Create do
|
|---|
| 244 | try
|
|---|
| 245 | CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
|
|---|
| 246 | WriteBool('ToolBarVisible', MenuItemToolbar.Checked);
|
|---|
| 247 | finally
|
|---|
| 248 | Free;
|
|---|
| 249 | end;
|
|---|
| 250 | end;
|
|---|
| 251 |
|
|---|
| 252 | procedure TFormMain.UpdateInterface;
|
|---|
| 253 | begin
|
|---|
| 254 | UpdateFormTitle;
|
|---|
| 255 | CoolBar1.Visible := MenuItemToolbar.Checked;
|
|---|
| 256 | Core.Core.AFullScreen.Checked := FullScreen;
|
|---|
| 257 | end;
|
|---|
| 258 |
|
|---|
| 259 | procedure TFormMain.SettingsChanged;
|
|---|
| 260 | begin
|
|---|
| 261 | ThemeManager.UseTheme(Self);
|
|---|
| 262 | Translator.TranslateComponentRecursive(Self);
|
|---|
| 263 | FormContacts.ThemeManager.UseTheme(FormContacts);
|
|---|
| 264 | FormContacts.Translator.TranslateComponentRecursive(FormContacts);
|
|---|
| 265 | end;
|
|---|
| 266 |
|
|---|
| 267 | procedure TFormMain.ToggleFullScreen;
|
|---|
| 268 | begin
|
|---|
| 269 | FullScreen := not FullScreen;
|
|---|
| 270 | Core.Core.AFullScreen.Checked := FullScreen;
|
|---|
| 271 | TFormEx.PersistentForm.Save(Self);
|
|---|
| 272 | TFormEx.PersistentForm.SetFullScreen(FullScreen);
|
|---|
| 273 | UpdateInterface;
|
|---|
| 274 | end;
|
|---|
| 275 |
|
|---|
| 276 | end.
|
|---|
| 277 |
|
|---|