Changeset 4 for trunk


Ignore:
Timestamp:
Apr 20, 2016, 11:11:26 PM (9 years ago)
Author:
chronos
Message:
  • Added: Now it is possible to add, modify, remove and remove all acronyms.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/AcronymDecoder.lpi

    r3 r4  
    8686      </Item4>
    8787    </RequiredPackages>
    88     <Units Count="4">
     88    <Units Count="5">
    8989      <Unit0>
    9090        <Filename Value="AcronymDecoder.lpr"/>
     
    109109        <ResourceBaseClass Value="Form"/>
    110110      </Unit3>
     111      <Unit4>
     112        <Filename Value="UFormAcronym.pas"/>
     113        <IsPartOfProject Value="True"/>
     114        <ComponentName Value="FormAcronym"/>
     115        <ResourceBaseClass Value="Form"/>
     116      </Unit4>
    111117    </Units>
    112118  </ProjectOptions>
  • trunk/AcronymDecoder.lpr

    r3 r4  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, UFormMain, UAcronym, synapse, UFormImport, Common, TemplateGenerics
     10  Forms, UFormMain, UAcronym, synapse, UFormImport, Common, TemplateGenerics,
     11  UFormAcronym
    1112  { you can add units after this };
    1213
     
    1920  Application.CreateForm(TFormMain, FormMain);
    2021  Application.CreateForm(TFormImport, FormImport);
     22  Application.CreateForm(TFormAcronym, FormAcronym);
    2123  Application.Run;
    2224end.
  • trunk/UAcronym.pas

    r1 r4  
    4242  TAcronymMeanings = class(TObjectList)
    4343    function SearchByName(Name: string): TAcronymMeaning;
     44    function AddMeaning(Name: string): TAcronymMeaning;
    4445  end;
    4546
     
    4849  TAcronyms = class(TObjectList)
    4950    function SearchByName(Name: string): TAcronym;
     51    function AddAcronym(Name: string): TAcronym;
    5052  end;
    5153
     
    6365  TAcronymContexts = class(TObjectList)
    6466    function SearchByName(Name: string): TAcronymContext;
     67    function AddContext(Name: string): TAcronymContext;
     68  end;
     69
     70  TAcronymEntry = class
     71    Name: string;
     72    Meaning: string;
    6573  end;
    6674
     
    7684    procedure SaveToFile(FileName: string);
    7785    procedure FilterList(AName: string; Items: TAcronymMeanings);
     86    procedure AddAcronym(AcronymName, MeaningName: string);
     87    procedure RemoveAcronym(AcronymName, MeaningName: string);
    7888  end;
    7989
     
    92102end;
    93103
     104function TAcronymMeanings.AddMeaning(Name: string): TAcronymMeaning;
     105begin
     106  Result := TAcronymMeaning.Create;
     107  Result.Name := Name;
     108  Add(Result);
     109end;
     110
    94111{ TAcronymMeaning }
    95112
     
    117134end;
    118135
     136function TAcronyms.AddAcronym(Name: string): TAcronym;
     137begin
     138  Result := TAcronym.Create;
     139  Result.Name := Name;
     140  Add(Result);
     141end;
     142
    119143{ TAcronymContexts }
    120144
     
    127151  if I < Count then Result := TAcronymContext(Items[I])
    128152    else Result := nil;
     153end;
     154
     155function TAcronymContexts.AddContext(Name: string): TAcronymContext;
     156begin
     157  Result := TAcronymContext.Create;
     158  Result.Name := Name;
     159  Add(Result);
    129160end;
    130161
     
    280311end;
    281312
     313procedure TAcronymDb.AddAcronym(AcronymName, MeaningName: string);
     314var
     315  Acronym: TAcronym;
     316  Meaning: TAcronymMeaning;
     317begin
     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;
     331end;
     332
     333procedure TAcronymDb.RemoveAcronym(AcronymName, MeaningName: string);
     334var
     335  Acronym: TAcronym;
     336  Meaning: TAcronymMeaning;
     337begin
     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;
     347end;
     348
    282349end.
    283350
  • trunk/UFormMain.lfm

    r3 r4  
    11object FormMain: TFormMain
    2   Left = 517
     2  Left = 762
    33  Height = 446
    4   Top = 386
     4  Top = 587
    55  Width = 631
    66  Caption = 'Acronym Decoder'
     
    3333      end>
    3434    OwnerData = True
     35    PopupMenu = PopupMenuAcronym
    3536    ReadOnly = True
    3637    RowSelect = True
     
    3839    ViewStyle = vsReport
    3940    OnData = ListViewAcronymsData
     41    OnDblClick = ListViewAcronymsDblClick
     42    OnKeyPress = ListViewAcronymsKeyPress
     43    OnSelectItem = ListViewAcronymsSelectItem
    4044  end
    4145  object EditSearch: TEdit
     
    4953  end
    5054  object TrayIcon1: TTrayIcon
    51     PopUpMenu = PopupMenu1
     55    PopUpMenu = PopupMenuTryIcon
    5256    Icon.Data = {
    5357      501702000000010006000000000001002000E291000066000000808000000100
     
    43374341    Visible = True
    43384342    OnClick = TrayIcon1Click
    4339     left = 273
    4340     top = 188
     4343    left = 152
     4344    top = 256
    43414345  end
    4342   object PopupMenu1: TPopupMenu
     4346  object PopupMenuTryIcon: TPopupMenu
    43434347    left = 144
    43444348    top = 192
    43454349    object MenuItem2: TMenuItem
    4346       Action = ActionShow
     4350      Action = AShow
    43474351      Default = True
    43484352    end
    43494353    object MenuItem3: TMenuItem
    4350       Action = ActionImport
     4354      Action = AImport
    43514355    end
    43524356    object MenuItem1: TMenuItem
    4353       Action = ActionExit
     4357      Action = AExit
    43544358    end
    43554359  end
     
    43574361    left = 465
    43584362    top = 171
    4359     object ActionExit: TAction
     4363    object AExit: TAction
    43604364      Caption = 'Exit'
    4361       OnExecute = ActionExitExecute
     4365      OnExecute = AExitExecute
    43624366    end
    4363     object ActionShow: TAction
     4367    object AShow: TAction
    43644368      Caption = 'Show'
    4365       OnExecute = ActionShowExecute
     4369      OnExecute = AShowExecute
    43664370    end
    4367     object ActionImport: TAction
     4371    object AImport: TAction
    43684372      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
    43704393    end
    43714394  end
     
    43764399    top = 128
    43774400  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
    43784417end
  • trunk/UFormMain.pas

    r3 r4  
    1515
    1616  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;
    2024    ActionList1: TActionList;
    2125    EditSearch: TEdit;
     
    2428    MenuItem2: TMenuItem;
    2529    MenuItem3: TMenuItem;
     30    MenuItem4: TMenuItem;
     31    MenuItem5: TMenuItem;
     32    MenuItem6: TMenuItem;
     33    MenuItem7: TMenuItem;
    2634    PersistentForm1: TPersistentForm;
    27     PopupMenu1: TPopupMenu;
     35    PopupMenuAcronym: TPopupMenu;
     36    PopupMenuTryIcon: TPopupMenu;
    2837    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);
    3245    procedure EditSearchChange(Sender: TObject);
    3346    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     
    3750    procedure FormShow(Sender: TObject);
    3851    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);
    3956    procedure TrayIcon1Click(Sender: TObject);
    4057  private
    4158    FoundAcronyms: TAcronymMeanings;
    4259    procedure UpdateAcronymsList;
     60    procedure UpdateInterface;
    4361  public
    4462    AcronymDb: TAcronymDb;
     
    5371
    5472uses
    55   UFormImport;
     73  UFormImport, UFormAcronym;
    5674
    5775const
     
    6886procedure TFormMain.EditSearchChange(Sender: TObject);
    6987begin
    70   AcronymDb.FilterList(EditSearch.Text, FoundAcronyms);
    7188  UpdateAcronymsList;
    7289end;
     
    8299end;
    83100
    84 procedure TFormMain.ActionExitExecute(Sender: TObject);
     101procedure TFormMain.AExitExecute(Sender: TObject);
    85102begin
    86103  Close;
    87104end;
    88105
    89 procedure TFormMain.ActionImportExecute(Sender: TObject);
     106procedure TFormMain.AAcronymModifyExecute(Sender: TObject);
     107var
     108  TempEntry: TAcronymEntry;
     109begin
     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;
     128end;
     129
     130procedure TFormMain.AAcronymRemoveAllExecute(Sender: TObject);
     131begin
     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;
     138end;
     139
     140procedure TFormMain.AAcronymRemoveExecute(Sender: TObject);
     141begin
     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;
     151end;
     152
     153procedure TFormMain.AAcronymAddExecute(Sender: TObject);
     154var
     155  TempEntry: TAcronymEntry;
     156begin
     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;
     167end;
     168
     169procedure TFormMain.AImportExecute(Sender: TObject);
    90170begin
    91171  FormImport.ShowModal;
    92   AcronymDb.FilterList(EditSearch.Text, FoundAcronyms);
    93172  UpdateAcronymsList;
    94173end;
    95174
    96 procedure TFormMain.ActionShowExecute(Sender: TObject);
     175procedure TFormMain.AShowExecute(Sender: TObject);
    97176begin
    98177  Show;
     
    115194  AcronymDb.FilterList(EditSearch.Text, FoundAcronyms);
    116195  UpdateAcronymsList;
     196  UpdateInterface;
    117197end;
    118198
     
    126206    Item.Caption := Acronym.Name;
    127207    Item.SubItems.Add(Name);
     208    Item.Data := TAcronymMeaning(FoundAcronyms[Item.Index]);
    128209    ContextCombined := '';
    129210    for I := 0 to Contexts.Count - 1 do
     
    134215end;
    135216
     217procedure TFormMain.ListViewAcronymsDblClick(Sender: TObject);
     218begin
     219  AAcronymModify.Execute;
     220end;
     221
     222procedure TFormMain.ListViewAcronymsKeyPress(Sender: TObject; var Key: char);
     223begin
     224end;
     225
     226procedure TFormMain.ListViewAcronymsSelectItem(Sender: TObject;
     227  Item: TListItem; Selected: Boolean);
     228begin
     229  UpdateInterface;
     230end;
     231
    136232procedure TFormMain.TrayIcon1Click(Sender: TObject);
    137233begin
     
    141237procedure TFormMain.UpdateAcronymsList;
    142238begin
     239  AcronymDb.FilterList(EditSearch.Text, FoundAcronyms);
    143240  ListViewAcronyms.Items.Count := FoundAcronyms.Count;
    144241  ListViewAcronyms.Refresh;
    145242end;
    146243
     244procedure TFormMain.UpdateInterface;
     245begin
     246  AAcronymRemove.Enabled := Assigned(ListViewAcronyms.Selected);
     247end;
     248
    147249end.
    148250
Note: See TracChangeset for help on using the changeset viewer.