Changeset 4 for trunk/UFormMain.pas


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

Legend:

Unmodified
Added
Removed
  • 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.