Changeset 8
- Timestamp:
- Apr 21, 2016, 1:12:45 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UAcronym.pas
r6 r8 30 30 TAcronymMeaning = class 31 31 Name: string; 32 Description: string; 32 33 Language: string; 33 34 Acronym: TAcronym; … … 71 72 Name: string; 72 73 Meaning: string; 74 Description: string; 73 75 end; 74 76 … … 86 88 procedure SaveToFile(FileName: string); 87 89 procedure FilterList(AName: string; Items: TAcronymMeanings); 88 procedure AddAcronym(AcronymName, MeaningName: string);90 function AddAcronym(AcronymName, MeaningName: string): TAcronymMeaning; 89 91 procedure RemoveAcronym(AcronymName, MeaningName: string); 90 92 end; … … 324 326 end; 325 327 326 procedure TAcronymDb.AddAcronym(AcronymName, MeaningName: string);328 function TAcronymDb.AddAcronym(AcronymName, MeaningName: string): TAcronymMeaning; 327 329 var 328 330 Acronym: TAcronym; … … 342 344 Acronym.Meanings.Add(Meaning); 343 345 end; 346 Result := Meaning; 344 347 Modified := True; 345 348 end; -
trunk/UFormAcronym.lfm
r7 r8 1 1 object FormAcronym: TFormAcronym 2 Left = 4932 Left = 554 3 3 Height = 296 4 4 Top = 409 … … 7 7 ClientHeight = 296 8 8 ClientWidth = 420 9 OnClose = FormClose 9 10 OnKeyUp = FormKeyUp 10 Position = poScreenCenter11 OnShow = FormShow 11 12 LCLVersion = '1.6.0.4' 12 13 object Label1: TLabel … … 30 31 Left = 8 31 32 Height = 20 32 Top = 5733 Top = 49 33 34 Width = 61 34 35 Caption = 'Meaning:' … … 38 39 Left = 136 39 40 Height = 28 40 Top = 5641 Top = 49 41 42 Width = 272 42 43 Anchors = [akTop, akLeft, akRight] … … 66 67 TabOrder = 3 67 68 end 69 object Label3: TLabel 70 Left = 8 71 Height = 20 72 Top = 88 73 Width = 79 74 Caption = 'Description:' 75 ParentColor = False 76 end 77 object MemoDescription: TMemo 78 Left = 136 79 Height = 114 80 Top = 88 81 Width = 272 82 Anchors = [akTop, akLeft, akRight] 83 ScrollBars = ssAutoBoth 84 TabOrder = 4 85 end 68 86 end -
trunk/UFormAcronym.pas
r5 r8 20 20 Label1: TLabel; 21 21 Label2: TLabel; 22 Label3: TLabel; 23 MemoDescription: TMemo; 24 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 22 25 procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 26 procedure FormShow(Sender: TObject); 23 27 private 24 28 { private declarations } … … 35 39 {$R *.lfm} 36 40 41 uses 42 UFormMain; 43 37 44 { TFormAcronym } 38 45 … … 44 51 end; 45 52 53 procedure TFormAcronym.FormClose(Sender: TObject; var CloseAction: TCloseAction 54 ); 55 begin 56 FormMain.PersistentForm1.Save(Self); 57 end; 58 59 procedure TFormAcronym.FormShow(Sender: TObject); 60 begin 61 FormMain.PersistentForm1.Load(Self); 62 end; 63 46 64 procedure TFormAcronym.Load(Entry: TAcronymEntry); 47 65 begin 48 66 EditAcronym.Text := Entry.Name; 49 67 EditMeaning.Text := Entry.Meaning; 68 MemoDescription.Text := Entry.Description; 50 69 end; 51 70 … … 54 73 Entry.Name := EditAcronym.Text; 55 74 Entry.Meaning := EditMeaning.Text; 75 Entry.Description := MemoDescription.Text; 56 76 end; 57 77 -
trunk/UFormImport.lfm
r7 r8 27 27 TabOrder = 1 28 28 end 29 object ComboBoxDataFormat: TComboBox 30 Left = 256 31 Height = 28 32 Top = 5 33 Width = 140 34 ItemHeight = 20 35 ItemIndex = 0 36 Items.Strings = ( 37 'CSV' 38 'MediaWiki' 39 ) 40 Style = csDropDownList 41 TabOrder = 2 42 Text = 'CSV' 43 end 44 object Label1: TLabel 45 Left = 153 46 Height = 20 47 Top = 9 48 Width = 84 49 Caption = 'Data format:' 50 ParentColor = False 51 end 52 object ButtonLoadFromFile: TButton 53 Left = 504 54 Height = 25 55 Top = 8 56 Width = 139 57 Anchors = [akTop, akRight] 58 Caption = 'Load from file' 59 OnClick = ButtonLoadFromFileClick 60 TabOrder = 3 61 end 62 object OpenDialog1: TOpenDialog 63 left = 331 64 top = 187 65 end 29 66 end -
trunk/UFormImport.pas
r6 r8 14 14 15 15 TFormImport = class(TForm) 16 ButtonLoadFromFile: TButton; 16 17 ButtonImport: TButton; 18 ComboBoxDataFormat: TComboBox; 19 Label1: TLabel; 17 20 Memo1: TMemo; 21 OpenDialog1: TOpenDialog; 18 22 procedure ButtonImportClick(Sender: TObject); 23 procedure ButtonLoadFromFileClick(Sender: TObject); 19 24 private 20 { private declarations } 25 procedure ImportMediaWiki; 26 procedure ImportCSV; 21 27 public 22 28 { public declarations } … … 55 61 56 62 procedure TFormImport.ButtonImportClick(Sender: TObject); 63 begin 64 if ComboBoxDataFormat.ItemIndex = 0 then ImportCSV; 65 if ComboBoxDataFormat.ItemIndex = 1 then ImportMediaWiki; 66 end; 67 68 procedure TFormImport.ButtonLoadFromFileClick(Sender: TObject); 69 begin 70 if OpenDialog1.Execute then 71 Memo1.Lines.LoadFromFile(OpenDialog1.FileName); 72 end; 73 74 procedure TFormImport.ImportMediaWiki; 57 75 var 58 76 I: Integer; 59 77 Line: string; 60 78 AcronymName: string; 61 Acronym Description: string;79 AcronymMeaning: string; 62 80 AddedCount: Integer; 63 81 Acronym: TAcronym; … … 74 92 end; 75 93 if Copy(Line, 1, 1) = ':' then begin 76 Acronym Description:= Trim(Copy(Line, 2, Length(Line)));77 if AcronymName <> ''then begin94 AcronymMeaning := Trim(Copy(Line, 2, Length(Line))); 95 if (AcronymName <> '') and (AcronymMeaning <> '') then begin 78 96 Acronym := FormMain.AcronymDb.Acronyms.SearchByName(AcronymName); 79 97 if not Assigned(Acronym) then begin … … 82 100 FormMain.AcronymDb.Acronyms.Add(Acronym); 83 101 end; 84 Meaning := Acronym.Meanings.SearchByName(Acronym Description);102 Meaning := Acronym.Meanings.SearchByName(AcronymMeaning); 85 103 if not Assigned(Meaning) then begin 86 104 Meaning := TAcronymMeaning.Create; 87 Meaning.Name := Acronym Description;105 Meaning.Name := AcronymMeaning; 88 106 Meaning.Acronym := Acronym; 89 107 Acronym.Meanings.Add(Meaning); … … 97 115 end; 98 116 117 procedure TFormImport.ImportCSV; 118 var 119 I: Integer; 120 Line: string; 121 Columns: TStringList; 122 Acronym: TAcronym; 123 Meaning: TAcronymMeaning; 124 AcronymName: string; 125 AcronymMeaning: string; 126 AcronymDescription: string; 127 AddedCount: Integer; 128 begin 129 AddedCount := 0; 130 Columns := TStringList.Create; 131 Columns.StrictDelimiter := True; 132 for I := 0 to Memo1.Lines.Count - 1 do begin 133 Line := Trim(Memo1.Lines[I]); 134 Columns.DelimitedText := Line; 135 if Columns.Count > 0 then AcronymName := Trim(Columns[0]) 136 else AcronymName := ''; 137 if Columns.Count > 1 then AcronymMeaning := Trim(Columns[1]) 138 else AcronymMeaning := ''; 139 if Columns.Count > 2 then AcronymDescription := Trim(Columns[2]) 140 else AcronymDescription := ''; 141 if (AcronymName <> '') and (AcronymDescription <> '') then begin 142 Acronym := FormMain.AcronymDb.Acronyms.SearchByName(AcronymName); 143 if not Assigned(Acronym) then begin 144 Acronym := TAcronym.Create; 145 Acronym.Name := AcronymName; 146 FormMain.AcronymDb.Acronyms.Add(Acronym); 147 end; 148 Meaning := Acronym.Meanings.SearchByName(AcronymDescription); 149 if not Assigned(Meaning) then begin 150 Meaning := TAcronymMeaning.Create; 151 Meaning.Name := AcronymMeaning; 152 Meaning.Description := AcronymDescription; 153 Meaning.Acronym := Acronym; 154 Acronym.Meanings.Add(Meaning); 155 Inc(AddedCount) 156 end; 157 end; 158 end; 159 Columns.Free; 160 if AddedCount > 0 then FormMain.AcronymDb.Modified := True; 161 ShowMessage(Format('Imported %d new acronyms.', [AddedCount])); 162 end; 163 99 164 end. 100 165 -
trunk/UFormMain.pas
r7 r8 136 136 'Acronyms were modified. Do you want to save them to file before exit?', 137 137 mtConfirmation, [mbYes, mbNo, mbCancel], 0); 138 if ModalResult = mrYes then AFileSave.Execute 139 else if ModalResult = mrNo then CanClose := True 140 else CanClose := False; 138 if ModalResult = mrYes then begin 139 AFileSave.Execute; 140 CanClose := True; 141 end 142 else if ModalResult = mrNo then begin 143 CanClose := True; 144 AcronymDb.Modified := False; 145 end else CanClose := False; 141 146 end; 142 147 end; … … 202 207 var 203 208 TempEntry: TAcronymEntry; 209 Meaning: TAcronymMeaning; 204 210 begin 205 211 if Assigned(ListViewAcronyms.Selected) then … … 208 214 TempEntry.Name := Acronym.Name; 209 215 TempEntry.Meaning := Name; 216 TempEntry.Description := Description; 210 217 FormAcronym.Load(TempEntry); 211 218 if FormAcronym.ShowModal = mrOk then begin 212 219 FormAcronym.Save(TempEntry); 213 220 if (TempEntry.Name <> Acronym.Name) or 214 (TempEntry.Meaning <> Name) then begin 221 (TempEntry.Meaning <> Name) or 222 (TempEntry.Description <> Description) then begin 215 223 // TODO: Update item inplace if possible 216 224 AcronymDb.RemoveAcronym(Acronym.Name, Name); 217 AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning); 225 Meaning := AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning); 226 Meaning.Description := TempEntry.Description; 218 227 UpdateAcronymsList; 219 228 UpdateInterface; … … 250 259 var 251 260 TempEntry: TAcronymEntry; 261 Meaning: TAcronymMeaning; 252 262 begin 253 263 TempEntry := TAcronymEntry.Create; 254 264 TempEntry.Name := ''; 255 265 TempEntry.Meaning := ''; 266 TempEntry.Description := ''; 256 267 FormAcronym.Load(TempEntry); 257 268 if FormAcronym.ShowModal = mrOk then begin 258 269 FormAcronym.Save(TempEntry); 259 AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning); 270 Meaning := AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning); 271 Meaning.Description := TempEntry.Description; 260 272 UpdateAcronymsList; 261 273 UpdateInterface; … … 267 279 FormImport.ShowModal; 268 280 UpdateAcronymsList; 281 UpdateInterface; 269 282 end; 270 283
Note:
See TracChangeset
for help on using the changeset viewer.