Changeset 19 for trunk/Forms/UFormAcronyms.pas
- Timestamp:
- May 4, 2016, 12:54:09 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormAcronyms.pas
r18 r19 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 Menus, UListViewSort, UAcronym, LazUTF8, SpecializedList;9 Menus, ActnList, UListViewSort, UAcronym, LazUTF8, SpecializedList; 10 10 11 11 type … … 14 14 15 15 TFormAcronyms = class(TForm) 16 AAdd: TAction; 17 ASelectAll: TAction; 18 AModify: TAction; 19 ARemove: TAction; 20 ActionList1: TActionList; 16 21 ListViewAcronyms: TListView; 17 22 ListViewFilter1: TListViewFilter; 18 23 ListViewSort1: TListViewSort; 24 MenuItem4: TMenuItem; 25 MenuItem5: TMenuItem; 26 MenuItem6: TMenuItem; 27 MenuItem7: TMenuItem; 28 PopupMenuAcronym: TPopupMenu; 29 procedure AAddExecute(Sender: TObject); 30 procedure AModifyExecute(Sender: TObject); 31 procedure ARemoveExecute(Sender: TObject); 32 procedure ASelectAllExecute(Sender: TObject); 19 33 procedure FormShow(Sender: TObject); 20 34 procedure ListViewAcronymsData(Sender: TObject; Item: TListItem); 35 procedure ListViewAcronymsDblClick(Sender: TObject); 21 36 procedure ListViewAcronymsResize(Sender: TObject); 37 procedure ListViewAcronymsSelectItem(Sender: TObject; Item: TListItem; 38 Selected: Boolean); 22 39 procedure ListViewFilter1Change(Sender: TObject); 23 40 function ListViewSort1CompareItem(Item1, Item2: TObject): Integer; … … 25 42 private 26 43 procedure FilterList(List: TListObject); 44 procedure UpdateAcronymsList; 27 45 public 28 { public declarations }46 procedure UpdateInterface; 29 47 end; 30 48 … … 37 55 38 56 uses 39 UFormMain; 57 UFormMain, UFormAcronym; 58 59 resourcestring 60 SRemoveAllAcronyms = 'Remove all acronyms'; 61 SRemoveAllAcronymsQuery = 'Do you want to remove all acronyms?'; 62 SRemoveAcronym = 'Remove acronym'; 63 SRemoveAcronymQuery = 'Do you want to remove selected acronym?'; 64 40 65 41 66 { TFormAcronyms } … … 52 77 end; 53 78 79 procedure TFormAcronyms.ListViewAcronymsDblClick(Sender: TObject); 80 begin 81 AModify.Execute; 82 end; 83 54 84 procedure TFormAcronyms.ListViewAcronymsResize(Sender: TObject); 55 85 begin … … 57 87 end; 58 88 89 procedure TFormAcronyms.ListViewAcronymsSelectItem(Sender: TObject; 90 Item: TListItem; Selected: Boolean); 91 begin 92 UpdateInterface; 93 end; 94 59 95 procedure TFormAcronyms.FormShow(Sender: TObject); 60 96 begin 61 97 ListViewFilter1.UpdateFromListView(ListViewAcronyms); 62 ListViewSort1.Refresh; 98 UpdateAcronymsList; 99 end; 100 101 procedure TFormAcronyms.AAddExecute(Sender: TObject); 102 var 103 TempEntry: TAcronymEntry; 104 Meaning: TAcronymMeaning; 105 I: Integer; 106 begin 107 TempEntry := TAcronymEntry.Create; 108 TempEntry.Name := ''; 109 TempEntry.Meaning := ''; 110 TempEntry.Description := ''; 111 FormAcronym.Load(TempEntry); 112 if FormAcronym.ShowModal = mrOk then begin 113 FormAcronym.Save(TempEntry); 114 Meaning := FormMain.AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning); 115 Meaning.Description := TempEntry.Description; 116 Meaning.Categories.AssignFromStrings(TempEntry.Categories); 117 for I := 0 to Meaning.Categories.Count - 1 do 118 TAcronymCategory(Meaning.Categories.Items[I]).AcronymMeanings.Add(Meaning); 119 UpdateAcronymsList; 120 UpdateInterface; 121 end; 122 TempEntry.Free; 123 end; 124 125 procedure TFormAcronyms.AModifyExecute(Sender: TObject); 126 var 127 TempEntry: TAcronymEntry; 128 TempCategories: TStringList; 129 Meaning: TAcronymMeaning; 130 I: Integer; 131 begin 132 if Assigned(ListViewAcronyms.Selected) then 133 with TAcronymMeaning(ListViewAcronyms.Selected.Data) do begin 134 TempEntry := TAcronymEntry.Create; 135 TempEntry.Name := Acronym.Name; 136 TempEntry.Meaning := Name; 137 TempEntry.Description := Description; 138 Categories.AssignToStrings(TempEntry.Categories); 139 TempCategories := TStringList.Create; 140 TempCategories.Assign(TempEntry.Categories); 141 FormAcronym.Load(TempEntry); 142 if FormAcronym.ShowModal = mrOk then begin 143 FormAcronym.Save(TempEntry); 144 if (TempEntry.Name <> Acronym.Name) or 145 (TempEntry.Meaning <> Name) or 146 (TempEntry.Description <> Description) or 147 not FormMain.CompareStrings(TempEntry.Categories, TempCategories) then begin 148 // TODO: Update item inplace if possible 149 FormMain.AcronymDb.RemoveAcronym(Acronym.Name, Name); 150 Meaning := FormMain.AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning); 151 Meaning.Description := TempEntry.Description; 152 Meaning.Categories.AssignFromStrings(TempEntry.Categories); 153 for I := 0 to Meaning.Categories.Count - 1 do 154 TAcronymCategory(Meaning.Categories.Items[I]).AcronymMeanings.Add(Meaning); 155 UpdateAcronymsList; 156 UpdateInterface; 157 end; 158 end; 159 TempEntry.Free; 160 TempCategories.Free; 161 end; 162 end; 163 164 procedure TFormAcronyms.ARemoveExecute(Sender: TObject); 165 var 166 I: Integer; 167 begin 168 if Assigned(ListViewAcronyms.Selected) then begin 169 if MessageDlg(SRemoveAcronym, SRemoveAcronymQuery, 170 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin 171 for I := ListViewAcronyms.Items.Count - 1 downto 0 do 172 if ListViewAcronyms.Items[I].Selected then begin 173 ListViewAcronyms.Items[I].Selected := False; 174 FormMain.AcronymDb.RemoveAcronym( 175 TAcronymMeaning(ListViewAcronyms.Items[I].Data).Acronym.Name, 176 TAcronymMeaning(ListViewAcronyms.Items[I].Data).Name); 177 end; 178 UpdateAcronymsList; 179 UpdateInterface; 180 end; 181 end; 182 end; 183 184 procedure TFormAcronyms.ASelectAllExecute(Sender: TObject); 185 var 186 I: Integer; 187 begin 188 for I := 0 to ListViewAcronyms.Items.Count - 1 do 189 ListViewAcronyms.Items[I].Selected := True; 63 190 end; 64 191 65 192 procedure TFormAcronyms.ListViewFilter1Change(Sender: TObject); 66 193 begin 67 ListViewSort1.Refresh;194 UpdateAcronymsList; 68 195 end; 69 196 … … 118 245 end; 119 246 247 procedure TFormAcronyms.UpdateAcronymsList; 248 begin 249 ListViewSort1.Refresh; 250 UpdateInterface; 251 end; 252 253 procedure TFormAcronyms.UpdateInterface; 254 begin 255 ARemove.Enabled := Assigned(FormMain.AcronymDb) and Assigned(ListViewAcronyms.Selected); 256 AModify.Enabled := Assigned(FormMain.AcronymDb) and Assigned(ListViewAcronyms.Selected); 257 AAdd.Enabled := Assigned(FormMain.AcronymDb); 258 end; 259 120 260 end. 121 261
Note:
See TracChangeset
for help on using the changeset viewer.