Changeset 4 for trunk/UFormMain.pas
- Timestamp:
- Apr 20, 2016, 11:11:26 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UFormMain.pas
r3 r4 15 15 16 16 TFormMain = class(TForm) 17 ActionImport: TAction; 18 ActionShow: TAction; 19 ActionExit: TAction; 17 AAcronymAdd: TAction; 18 AAcronymModify: TAction; 19 AAcronymRemove: TAction; 20 AAcronymRemoveAll: TAction; 21 AImport: TAction; 22 AShow: TAction; 23 AExit: TAction; 20 24 ActionList1: TActionList; 21 25 EditSearch: TEdit; … … 24 28 MenuItem2: TMenuItem; 25 29 MenuItem3: TMenuItem; 30 MenuItem4: TMenuItem; 31 MenuItem5: TMenuItem; 32 MenuItem6: TMenuItem; 33 MenuItem7: TMenuItem; 26 34 PersistentForm1: TPersistentForm; 27 PopupMenu1: TPopupMenu; 35 PopupMenuAcronym: TPopupMenu; 36 PopupMenuTryIcon: TPopupMenu; 28 37 TrayIcon1: TTrayIcon; 29 procedure ActionExitExecute(Sender: TObject); 30 procedure ActionImportExecute(Sender: TObject); 31 procedure ActionShowExecute(Sender: TObject); 38 procedure AAcronymAddExecute(Sender: TObject); 39 procedure AAcronymModifyExecute(Sender: TObject); 40 procedure AAcronymRemoveAllExecute(Sender: TObject); 41 procedure AAcronymRemoveExecute(Sender: TObject); 42 procedure AExitExecute(Sender: TObject); 43 procedure AImportExecute(Sender: TObject); 44 procedure AShowExecute(Sender: TObject); 32 45 procedure EditSearchChange(Sender: TObject); 33 46 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); … … 37 50 procedure FormShow(Sender: TObject); 38 51 procedure ListViewAcronymsData(Sender: TObject; Item: TListItem); 52 procedure ListViewAcronymsDblClick(Sender: TObject); 53 procedure ListViewAcronymsKeyPress(Sender: TObject; var Key: char); 54 procedure ListViewAcronymsSelectItem(Sender: TObject; Item: TListItem; 55 Selected: Boolean); 39 56 procedure TrayIcon1Click(Sender: TObject); 40 57 private 41 58 FoundAcronyms: TAcronymMeanings; 42 59 procedure UpdateAcronymsList; 60 procedure UpdateInterface; 43 61 public 44 62 AcronymDb: TAcronymDb; … … 53 71 54 72 uses 55 UFormImport ;73 UFormImport, UFormAcronym; 56 74 57 75 const … … 68 86 procedure TFormMain.EditSearchChange(Sender: TObject); 69 87 begin 70 AcronymDb.FilterList(EditSearch.Text, FoundAcronyms);71 88 UpdateAcronymsList; 72 89 end; … … 82 99 end; 83 100 84 procedure TFormMain.A ctionExitExecute(Sender: TObject);101 procedure TFormMain.AExitExecute(Sender: TObject); 85 102 begin 86 103 Close; 87 104 end; 88 105 89 procedure TFormMain.ActionImportExecute(Sender: TObject); 106 procedure TFormMain.AAcronymModifyExecute(Sender: TObject); 107 var 108 TempEntry: TAcronymEntry; 109 begin 110 if Assigned(ListViewAcronyms.Selected) then 111 with TAcronymMeaning(ListViewAcronyms.Selected.Data) do begin 112 TempEntry := TAcronymEntry.Create; 113 TempEntry.Name := Acronym.Name; 114 TempEntry.Meaning := Name; 115 FormAcronym.Load(TempEntry); 116 if FormAcronym.ShowModal = mrOk then begin 117 FormAcronym.Save(TempEntry); 118 if (TempEntry.Name <> Acronym.Name) or 119 (TempEntry.Meaning <> Name) then begin 120 // TODO: Update item inplace if possible 121 AcronymDb.RemoveAcronym(Acronym.Name, Name); 122 AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning); 123 UpdateAcronymsList; 124 UpdateInterface; 125 end; 126 end; 127 end; 128 end; 129 130 procedure TFormMain.AAcronymRemoveAllExecute(Sender: TObject); 131 begin 132 if MessageDlg('Remove all acronyms', 'Do you want to remove all acronyms?', 133 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin 134 AcronymDb.Acronyms.Clear; 135 UpdateAcronymsList; 136 UpdateInterface; 137 end; 138 end; 139 140 procedure TFormMain.AAcronymRemoveExecute(Sender: TObject); 141 begin 142 if Assigned(ListViewAcronyms.Selected) then begin 143 if MessageDlg('Remove acronym', 'Do you want to remove selected acronym?', 144 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin 145 AcronymDb.RemoveAcronym(TAcronymMeaning(ListViewAcronyms.Selected.Data).Acronym.Name, 146 TAcronymMeaning(ListViewAcronyms.Selected.Data).Name); 147 UpdateAcronymsList; 148 UpdateInterface; 149 end; 150 end; 151 end; 152 153 procedure TFormMain.AAcronymAddExecute(Sender: TObject); 154 var 155 TempEntry: TAcronymEntry; 156 begin 157 TempEntry := TAcronymEntry.Create; 158 TempEntry.Name := ''; 159 TempEntry.Meaning := ''; 160 FormAcronym.Load(TempEntry); 161 if FormAcronym.ShowModal = mrOk then begin 162 FormAcronym.Save(TempEntry); 163 AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning); 164 UpdateAcronymsList; 165 UpdateInterface; 166 end else TempEntry.Free; 167 end; 168 169 procedure TFormMain.AImportExecute(Sender: TObject); 90 170 begin 91 171 FormImport.ShowModal; 92 AcronymDb.FilterList(EditSearch.Text, FoundAcronyms);93 172 UpdateAcronymsList; 94 173 end; 95 174 96 procedure TFormMain.A ctionShowExecute(Sender: TObject);175 procedure TFormMain.AShowExecute(Sender: TObject); 97 176 begin 98 177 Show; … … 115 194 AcronymDb.FilterList(EditSearch.Text, FoundAcronyms); 116 195 UpdateAcronymsList; 196 UpdateInterface; 117 197 end; 118 198 … … 126 206 Item.Caption := Acronym.Name; 127 207 Item.SubItems.Add(Name); 208 Item.Data := TAcronymMeaning(FoundAcronyms[Item.Index]); 128 209 ContextCombined := ''; 129 210 for I := 0 to Contexts.Count - 1 do … … 134 215 end; 135 216 217 procedure TFormMain.ListViewAcronymsDblClick(Sender: TObject); 218 begin 219 AAcronymModify.Execute; 220 end; 221 222 procedure TFormMain.ListViewAcronymsKeyPress(Sender: TObject; var Key: char); 223 begin 224 end; 225 226 procedure TFormMain.ListViewAcronymsSelectItem(Sender: TObject; 227 Item: TListItem; Selected: Boolean); 228 begin 229 UpdateInterface; 230 end; 231 136 232 procedure TFormMain.TrayIcon1Click(Sender: TObject); 137 233 begin … … 141 237 procedure TFormMain.UpdateAcronymsList; 142 238 begin 239 AcronymDb.FilterList(EditSearch.Text, FoundAcronyms); 143 240 ListViewAcronyms.Items.Count := FoundAcronyms.Count; 144 241 ListViewAcronyms.Refresh; 145 242 end; 146 243 244 procedure TFormMain.UpdateInterface; 245 begin 246 AAcronymRemove.Enabled := Assigned(ListViewAcronyms.Selected); 247 end; 248 147 249 end. 148 250
Note:
See TracChangeset
for help on using the changeset viewer.