| 1 | unit UFormMain;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, LazFileUtils, Forms, Controls, Graphics, Dialogs, Menus,
|
|---|
| 9 | ComCtrls;
|
|---|
| 10 |
|
|---|
| 11 | type
|
|---|
| 12 |
|
|---|
| 13 | { TFormMain }
|
|---|
| 14 |
|
|---|
| 15 | TFormMain = class(TForm)
|
|---|
| 16 | CoolBar1: TCoolBar;
|
|---|
| 17 | MainMenu1: TMainMenu;
|
|---|
| 18 | MenuItem1: TMenuItem;
|
|---|
| 19 | MenuItem10: TMenuItem;
|
|---|
| 20 | MenuItem3: TMenuItem;
|
|---|
| 21 | MenuItem5: TMenuItem;
|
|---|
| 22 | MenuItem6: TMenuItem;
|
|---|
| 23 | MenuItem7: TMenuItem;
|
|---|
| 24 | MenuItem8: TMenuItem;
|
|---|
| 25 | MenuItem9: TMenuItem;
|
|---|
| 26 | MenuItemToolbar: TMenuItem;
|
|---|
| 27 | MenuItemView: TMenuItem;
|
|---|
| 28 | MenuItemExit: TMenuItem;
|
|---|
| 29 | MenuItemHomePage: TMenuItem;
|
|---|
| 30 | MenuItemAbout: TMenuItem;
|
|---|
| 31 | MenuItem2: TMenuItem;
|
|---|
| 32 | MenuItemFileNew: TMenuItem;
|
|---|
| 33 | MenuItemFileOpen: TMenuItem;
|
|---|
| 34 | MenuItemSettings: TMenuItem;
|
|---|
| 35 | MenuItemTools: TMenuItem;
|
|---|
| 36 | MenuItemFileOpenRecent: TMenuItem;
|
|---|
| 37 | MenuItemFileSave: TMenuItem;
|
|---|
| 38 | MenuItemFileSaveAs: TMenuItem;
|
|---|
| 39 | MenuItemFileClose: TMenuItem;
|
|---|
| 40 | MenuItemHelp: TMenuItem;
|
|---|
| 41 | MenuItemFile: TMenuItem;
|
|---|
| 42 | PopupMenuOpenRecent: TPopupMenu;
|
|---|
| 43 | ToolBarOther: TToolBar;
|
|---|
| 44 | ToolBarFile: TToolBar;
|
|---|
| 45 | ToolButton1: TToolButton;
|
|---|
| 46 | ToolButton2: TToolButton;
|
|---|
| 47 | ToolButton3: TToolButton;
|
|---|
| 48 | ToolButton4: TToolButton;
|
|---|
| 49 | ToolButton5: TToolButton;
|
|---|
| 50 | ToolButton6: TToolButton;
|
|---|
| 51 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 52 | procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
|---|
| 53 | procedure FormCreate(Sender: TObject);
|
|---|
| 54 | procedure FormDestroy(Sender: TObject);
|
|---|
| 55 | procedure FormResize(Sender: TObject);
|
|---|
| 56 | procedure FormShow(Sender: TObject);
|
|---|
| 57 | procedure MenuItemToolbarClick(Sender: TObject);
|
|---|
| 58 | private
|
|---|
| 59 | procedure SetToolbarHints;
|
|---|
| 60 | procedure UpdateFormTitle;
|
|---|
| 61 | public
|
|---|
| 62 | procedure UpdateInterface;
|
|---|
| 63 | end;
|
|---|
| 64 |
|
|---|
| 65 | var
|
|---|
| 66 | FormMain: TFormMain;
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | implementation
|
|---|
| 70 |
|
|---|
| 71 | {$R *.lfm}
|
|---|
| 72 |
|
|---|
| 73 | uses
|
|---|
| 74 | UCore, UFormContacts, UContact;
|
|---|
| 75 |
|
|---|
| 76 | resourcestring
|
|---|
| 77 | SModified = 'Modified';
|
|---|
| 78 |
|
|---|
| 79 | { TFormMain }
|
|---|
| 80 |
|
|---|
| 81 | procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 82 | begin
|
|---|
| 83 | FormContacts.Close;
|
|---|
| 84 | Core.PersistentForm1.Save(Self);
|
|---|
| 85 | end;
|
|---|
| 86 |
|
|---|
| 87 | procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
|---|
| 88 | begin
|
|---|
| 89 | Core.AFileClose.Execute;
|
|---|
| 90 | CanClose := Core.FileClosed;
|
|---|
| 91 | end;
|
|---|
| 92 |
|
|---|
| 93 | procedure TFormMain.FormCreate(Sender: TObject);
|
|---|
| 94 | begin
|
|---|
| 95 | FormContacts := TFormContacts.Create(nil);
|
|---|
| 96 | end;
|
|---|
| 97 |
|
|---|
| 98 | procedure TFormMain.FormDestroy(Sender: TObject);
|
|---|
| 99 | begin
|
|---|
| 100 | FreeAndNil(FormContacts);
|
|---|
| 101 | end;
|
|---|
| 102 |
|
|---|
| 103 | procedure TFormMain.FormResize(Sender: TObject);
|
|---|
| 104 | begin
|
|---|
| 105 | CoolBar1.AutosizeBands;
|
|---|
| 106 | end;
|
|---|
| 107 |
|
|---|
| 108 | procedure TFormMain.FormShow(Sender: TObject);
|
|---|
| 109 | begin
|
|---|
| 110 | SetToolbarHints;
|
|---|
| 111 | Core.Initialize;
|
|---|
| 112 | Core.ThemeManager1.UseTheme(Self);
|
|---|
| 113 | Core.PersistentForm1.Load(Self);
|
|---|
| 114 | Core.ScaleDPI1.ScaleControl(CoolBar1, Core.ScaleDPI1.DesignDPI);
|
|---|
| 115 | CoolBar1.AutosizeBands;
|
|---|
| 116 |
|
|---|
| 117 | FormContacts.Contacts := TContactsFile(Core.DataFile).Contacts;
|
|---|
| 118 | FormContacts.ManualDock(Self, nil, alClient);
|
|---|
| 119 | FormContacts.Align := alClient;
|
|---|
| 120 | FormContacts.Show;
|
|---|
| 121 | end;
|
|---|
| 122 |
|
|---|
| 123 | procedure TFormMain.MenuItemToolbarClick(Sender: TObject);
|
|---|
| 124 | begin
|
|---|
| 125 | UpdateInterface;
|
|---|
| 126 | end;
|
|---|
| 127 |
|
|---|
| 128 | procedure TFormMain.SetToolbarHints;
|
|---|
| 129 | var
|
|---|
| 130 | I: Integer;
|
|---|
| 131 | J: Integer;
|
|---|
| 132 | Control: TControl;
|
|---|
| 133 | begin
|
|---|
| 134 | for J := 0 to CoolBar1.ControlCount - 1 do begin
|
|---|
| 135 | Control := CoolBar1.Controls[J];
|
|---|
| 136 | if Control is TToolBar then begin
|
|---|
| 137 | for I := 0 to TToolBar(Control).ButtonCount - 1 do begin
|
|---|
| 138 | TToolBar(Control).Buttons[I].ShowHint := True;
|
|---|
| 139 | TToolBar(Control).Buttons[I].Hint := TToolBar(Control).Buttons[I].Caption;
|
|---|
| 140 | end;
|
|---|
| 141 | end;
|
|---|
| 142 | end;
|
|---|
| 143 | end;
|
|---|
| 144 |
|
|---|
| 145 | procedure TFormMain.UpdateFormTitle;
|
|---|
| 146 | var
|
|---|
| 147 | Title: string;
|
|---|
| 148 | begin
|
|---|
| 149 | Title := '';
|
|---|
| 150 | if Assigned(Core.DataFile) and
|
|---|
| 151 | (ExtractFileNameWithoutExt(ExtractFileName(Core.DataFile.FileName)) <> '') then
|
|---|
| 152 | Title := Title + ExtractFileNameWithoutExt(ExtractFileName(Core.DataFile.FileName));
|
|---|
| 153 | if Assigned(Core.DataFile) and Core.DataFile.Modified then
|
|---|
| 154 | Title := Title + ' (' + SModified + ')';
|
|---|
| 155 | if Title <> '' then Title := Title + ' - ';
|
|---|
| 156 | Title := Title + Core.ApplicationInfo1.AppName;
|
|---|
| 157 | //Application.Title := Title;
|
|---|
| 158 | Caption := Title;
|
|---|
| 159 | end;
|
|---|
| 160 |
|
|---|
| 161 | procedure TFormMain.UpdateInterface;
|
|---|
| 162 | begin
|
|---|
| 163 | UpdateFormTitle;
|
|---|
| 164 | CoolBar1.Visible := MenuItemToolbar.Checked;
|
|---|
| 165 | end;
|
|---|
| 166 |
|
|---|
| 167 | end.
|
|---|
| 168 |
|
|---|