- Timestamp:
- Apr 20, 2016, 11:11:26 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/AcronymDecoder.lpi
r3 r4 86 86 </Item4> 87 87 </RequiredPackages> 88 <Units Count=" 4">88 <Units Count="5"> 89 89 <Unit0> 90 90 <Filename Value="AcronymDecoder.lpr"/> … … 109 109 <ResourceBaseClass Value="Form"/> 110 110 </Unit3> 111 <Unit4> 112 <Filename Value="UFormAcronym.pas"/> 113 <IsPartOfProject Value="True"/> 114 <ComponentName Value="FormAcronym"/> 115 <ResourceBaseClass Value="Form"/> 116 </Unit4> 111 117 </Units> 112 118 </ProjectOptions> -
trunk/AcronymDecoder.lpr
r3 r4 8 8 {$ENDIF}{$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, UFormMain, UAcronym, synapse, UFormImport, Common, TemplateGenerics 10 Forms, UFormMain, UAcronym, synapse, UFormImport, Common, TemplateGenerics, 11 UFormAcronym 11 12 { you can add units after this }; 12 13 … … 19 20 Application.CreateForm(TFormMain, FormMain); 20 21 Application.CreateForm(TFormImport, FormImport); 22 Application.CreateForm(TFormAcronym, FormAcronym); 21 23 Application.Run; 22 24 end. -
trunk/UAcronym.pas
r1 r4 42 42 TAcronymMeanings = class(TObjectList) 43 43 function SearchByName(Name: string): TAcronymMeaning; 44 function AddMeaning(Name: string): TAcronymMeaning; 44 45 end; 45 46 … … 48 49 TAcronyms = class(TObjectList) 49 50 function SearchByName(Name: string): TAcronym; 51 function AddAcronym(Name: string): TAcronym; 50 52 end; 51 53 … … 63 65 TAcronymContexts = class(TObjectList) 64 66 function SearchByName(Name: string): TAcronymContext; 67 function AddContext(Name: string): TAcronymContext; 68 end; 69 70 TAcronymEntry = class 71 Name: string; 72 Meaning: string; 65 73 end; 66 74 … … 76 84 procedure SaveToFile(FileName: string); 77 85 procedure FilterList(AName: string; Items: TAcronymMeanings); 86 procedure AddAcronym(AcronymName, MeaningName: string); 87 procedure RemoveAcronym(AcronymName, MeaningName: string); 78 88 end; 79 89 … … 92 102 end; 93 103 104 function TAcronymMeanings.AddMeaning(Name: string): TAcronymMeaning; 105 begin 106 Result := TAcronymMeaning.Create; 107 Result.Name := Name; 108 Add(Result); 109 end; 110 94 111 { TAcronymMeaning } 95 112 … … 117 134 end; 118 135 136 function TAcronyms.AddAcronym(Name: string): TAcronym; 137 begin 138 Result := TAcronym.Create; 139 Result.Name := Name; 140 Add(Result); 141 end; 142 119 143 { TAcronymContexts } 120 144 … … 127 151 if I < Count then Result := TAcronymContext(Items[I]) 128 152 else Result := nil; 153 end; 154 155 function TAcronymContexts.AddContext(Name: string): TAcronymContext; 156 begin 157 Result := TAcronymContext.Create; 158 Result.Name := Name; 159 Add(Result); 129 160 end; 130 161 … … 280 311 end; 281 312 313 procedure TAcronymDb.AddAcronym(AcronymName, MeaningName: string); 314 var 315 Acronym: TAcronym; 316 Meaning: TAcronymMeaning; 317 begin 318 Acronym := Acronyms.SearchByName(AcronymName); 319 if not Assigned(Acronym) then begin 320 Acronym := TAcronym.Create; 321 Acronym.Name := AcronymName; 322 Acronyms.Add(Acronym); 323 end; 324 Meaning := Acronym.Meanings.SearchByName(MeaningName); 325 if not Assigned(Meaning) then begin 326 Meaning := TAcronymMeaning.Create; 327 Meaning.Name := MeaningName; 328 Meaning.Acronym := Acronym; 329 Acronym.Meanings.Add(Meaning); 330 end; 331 end; 332 333 procedure TAcronymDb.RemoveAcronym(AcronymName, MeaningName: string); 334 var 335 Acronym: TAcronym; 336 Meaning: TAcronymMeaning; 337 begin 338 Acronym := Acronyms.SearchByName(AcronymName); 339 if Assigned(Acronym) then begin 340 Meaning := Acronym.Meanings.SearchByName(MeaningName); 341 if Assigned(Meaning) then begin 342 Acronym.Meanings.Remove(Meaning); 343 if Acronym.Meanings.Count = 0 then 344 Acronyms.Remove(Acronym); 345 end; 346 end; 347 end; 348 282 349 end. 283 350 -
trunk/UFormMain.lfm
r3 r4 1 1 object FormMain: TFormMain 2 Left = 5172 Left = 762 3 3 Height = 446 4 Top = 3864 Top = 587 5 5 Width = 631 6 6 Caption = 'Acronym Decoder' … … 33 33 end> 34 34 OwnerData = True 35 PopupMenu = PopupMenuAcronym 35 36 ReadOnly = True 36 37 RowSelect = True … … 38 39 ViewStyle = vsReport 39 40 OnData = ListViewAcronymsData 41 OnDblClick = ListViewAcronymsDblClick 42 OnKeyPress = ListViewAcronymsKeyPress 43 OnSelectItem = ListViewAcronymsSelectItem 40 44 end 41 45 object EditSearch: TEdit … … 49 53 end 50 54 object TrayIcon1: TTrayIcon 51 PopUpMenu = PopupMenu 155 PopUpMenu = PopupMenuTryIcon 52 56 Icon.Data = { 53 57 501702000000010006000000000001002000E291000066000000808000000100 … … 4337 4341 Visible = True 4338 4342 OnClick = TrayIcon1Click 4339 left = 2734340 top = 1884343 left = 152 4344 top = 256 4341 4345 end 4342 object PopupMenu 1: TPopupMenu4346 object PopupMenuTryIcon: TPopupMenu 4343 4347 left = 144 4344 4348 top = 192 4345 4349 object MenuItem2: TMenuItem 4346 Action = A ctionShow4350 Action = AShow 4347 4351 Default = True 4348 4352 end 4349 4353 object MenuItem3: TMenuItem 4350 Action = A ctionImport4354 Action = AImport 4351 4355 end 4352 4356 object MenuItem1: TMenuItem 4353 Action = A ctionExit4357 Action = AExit 4354 4358 end 4355 4359 end … … 4357 4361 left = 465 4358 4362 top = 171 4359 object A ctionExit: TAction4363 object AExit: TAction 4360 4364 Caption = 'Exit' 4361 OnExecute = A ctionExitExecute4365 OnExecute = AExitExecute 4362 4366 end 4363 object A ctionShow: TAction4367 object AShow: TAction 4364 4368 Caption = 'Show' 4365 OnExecute = A ctionShowExecute4369 OnExecute = AShowExecute 4366 4370 end 4367 object A ctionImport: TAction4371 object AImport: TAction 4368 4372 Caption = 'Import' 4369 OnExecute = ActionImportExecute 4373 OnExecute = AImportExecute 4374 end 4375 object AAcronymAdd: TAction 4376 Caption = 'Add' 4377 OnExecute = AAcronymAddExecute 4378 ShortCut = 45 4379 end 4380 object AAcronymModify: TAction 4381 Caption = 'Modify' 4382 OnExecute = AAcronymModifyExecute 4383 ShortCut = 13 4384 end 4385 object AAcronymRemove: TAction 4386 Caption = 'Remove' 4387 OnExecute = AAcronymRemoveExecute 4388 ShortCut = 46 4389 end 4390 object AAcronymRemoveAll: TAction 4391 Caption = 'Remove all' 4392 OnExecute = AAcronymRemoveAllExecute 4370 4393 end 4371 4394 end … … 4376 4399 top = 128 4377 4400 end 4401 object PopupMenuAcronym: TPopupMenu 4402 left = 359 4403 top = 263 4404 object MenuItem4: TMenuItem 4405 Action = AAcronymAdd 4406 end 4407 object MenuItem5: TMenuItem 4408 Action = AAcronymModify 4409 end 4410 object MenuItem6: TMenuItem 4411 Action = AAcronymRemove 4412 end 4413 object MenuItem7: TMenuItem 4414 Action = AAcronymRemoveAll 4415 end 4416 end 4378 4417 end -
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.