Changeset 13 for trunk/UFormAcronym.pas


Ignore:
Timestamp:
Apr 28, 2016, 10:09:02 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Acronym meaning context items renamed to categories.
  • Added: Ability to select categories for meanings.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UFormAcronym.pas

    r8 r13  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
    9   StdCtrls, UAcronym;
     9  StdCtrls, ActnList, UAcronym;
    1010
    1111type
     
    1414
    1515  TFormAcronym = class(TForm)
     16    ACategoryRemove: TAction;
     17    ACategoryAdd: TAction;
     18    ActionList1: TActionList;
     19    Button1: TButton;
     20    Button2: TButton;
    1621    ButtonOk: TButton;
    1722    ButtonCancel: TButton;
     
    2126    Label2: TLabel;
    2227    Label3: TLabel;
     28    Label4: TLabel;
     29    ListBox1: TListBox;
    2330    MemoDescription: TMemo;
     31    PopupMenuCategory: TPopupMenu;
     32    procedure ACategoryAddExecute(Sender: TObject);
     33    procedure ACategoryRemoveExecute(Sender: TObject);
    2434    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    2535    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    2636    procedure FormShow(Sender: TObject);
     37    procedure ListBox1SelectionChange(Sender: TObject; User: boolean);
    2738  private
    28     { private declarations }
     39    procedure UpdateInterface;
    2940  public
    3041    procedure Load(Entry: TAcronymEntry);
     
    4051
    4152uses
    42   UFormMain;
     53  UFormMain, UFormCategorySelect;
     54
     55resourcestring
     56  SCategory = 'Category';
     57  SRemoveCategory = 'Remove categories';
     58  SRemoveCategoryQuery = 'Do you really want to remove selected categories?';
    4359
    4460{ TFormAcronym }
     
    5773end;
    5874
     75procedure TFormAcronym.ACategoryAddExecute(Sender: TObject);
     76var
     77  I: Integer;
     78begin
     79  FormCategorySelect.Load(ListBox1.Items);
     80  if FormCategorySelect.ShowModal = mrOk then begin
     81    for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
     82      if FormCategorySelect.ListBox1.Selected[I] then begin
     83        ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
     84      end;
     85  end;
     86end;
     87
     88procedure TFormAcronym.ACategoryRemoveExecute(Sender: TObject);
     89var
     90  I: Integer;
     91begin
     92  if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
     93  TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
     94    for I := ListBox1.Items.Count - 1 downto 0 do
     95    if ListBox1.Selected[I] then
     96      ListBox1.Items.Delete(I);
     97    UpdateInterface;
     98  end;
     99end;
     100
    59101procedure TFormAcronym.FormShow(Sender: TObject);
    60102begin
    61103  FormMain.PersistentForm1.Load(Self);
     104  UpdateInterface;
     105end;
     106
     107procedure TFormAcronym.ListBox1SelectionChange(Sender: TObject; User: boolean);
     108begin
     109  UpdateInterface;
     110end;
     111
     112procedure TFormAcronym.UpdateInterface;
     113begin
     114  ACategoryRemove.Enabled := ListBox1.ItemIndex <> -1;
    62115end;
    63116
     
    67120  EditMeaning.Text := Entry.Meaning;
    68121  MemoDescription.Text := Entry.Description;
     122  ListBox1.Items.Assign(Entry.Categories);
    69123end;
    70124
     
    74128  Entry.Meaning := EditMeaning.Text;
    75129  Entry.Description := MemoDescription.Text;
     130  Entry.Categories.Assign(ListBox1.Items);
    76131end;
    77132
Note: See TracChangeset for help on using the changeset viewer.