source: tags/1.4.0/Forms/UFormColumns.pas

Last change on this file was 138, checked in by chronos, 22 months ago
  • Added: Allow to configure visible columns in contacts table.
File size: 4.5 KB
Line 
1unit UFormColumns;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, UVCard;
7
8type
9
10 { TFormColumns }
11
12 TFormColumns = class(TForm)
13 ButtonUp: TButton;
14 ButtonToLeft: TButton;
15 ButtonCancel: TButton;
16 ButtonOk: TButton;
17 ButtonToRight: TButton;
18 ButtonDown: TButton;
19 Label1: TLabel;
20 Label2: TLabel;
21 ListBoxActive: TListBox;
22 ListBoxAvailable: TListBox;
23 procedure ButtonDownClick(Sender: TObject);
24 procedure ButtonOkClick(Sender: TObject);
25 procedure ButtonToLeftClick(Sender: TObject);
26 procedure ButtonToRightClick(Sender: TObject);
27 procedure ButtonUpClick(Sender: TObject);
28 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
29 procedure FormCreate(Sender: TObject);
30 procedure FormDestroy(Sender: TObject);
31 procedure FormShow(Sender: TObject);
32 procedure ListBoxActiveSelectionChange(Sender: TObject; User: boolean);
33 procedure ListBoxAvailableSelectionChange(Sender: TObject; User: boolean);
34 private
35 procedure SwapListItems(ListBox: TListBox; Index1, Index2: Integer);
36 public
37 ActiveColumns: TStringList;
38 AvailableColumns: TStringList;
39 procedure UpdateInterface;
40 end;
41
42var
43 FormColumns: TFormColumns;
44
45
46implementation
47
48{$R *.lfm}
49
50uses
51 UCore;
52
53{ TFormColumns }
54
55procedure TFormColumns.FormShow(Sender: TObject);
56var
57 I: Integer;
58begin
59 Core.PersistentForm1.Load(Self);
60
61 ListBoxActive.Items.Assign(ActiveColumns);
62 ListBoxAvailable.Items.Assign(AvailableColumns);
63 ListBoxAvailable.Sorted := True;
64
65 UpdateInterface;
66end;
67
68procedure TFormColumns.ListBoxActiveSelectionChange(Sender: TObject;
69 User: boolean);
70begin
71 UpdateInterface;
72end;
73
74procedure TFormColumns.ListBoxAvailableSelectionChange(Sender: TObject;
75 User: boolean);
76begin
77 UpdateInterface;
78end;
79
80procedure TFormColumns.SwapListItems(ListBox: TListBox; Index1, Index2: Integer
81 );
82var
83 Temp: string;
84 TempObject: TObject;
85begin
86 Temp := ListBox.Items[Index1];
87 ListBox.Items[Index1] := ListBox.Items[Index2];
88 ListBox.Items[Index2] := Temp;
89 TempObject := ListBox.Items.Objects[Index1];
90 ListBox.Items.Objects[Index1] := ListBox.Items.Objects[Index2];
91 ListBox.Items.Objects[Index2] := TempObject;
92end;
93
94procedure TFormColumns.FormClose(Sender: TObject; var CloseAction: TCloseAction
95 );
96begin
97 Core.PersistentForm1.Save(Self);
98end;
99
100procedure TFormColumns.ButtonUpClick(Sender: TObject);
101begin
102 if ListBoxActive.ItemIndex > 0 then begin
103 SwapListItems(ListBoxActive, ListBoxActive.ItemIndex, ListBoxActive.ItemIndex - 1);
104 ListBoxActive.ItemIndex := ListBoxActive.ItemIndex - 1;
105 end;
106end;
107
108procedure TFormColumns.ButtonDownClick(Sender: TObject);
109begin
110 if ListBoxActive.ItemIndex < ListBoxActive.Items.Count - 1 then begin
111 SwapListItems(ListBoxActive, ListBoxActive.ItemIndex, ListBoxActive.ItemIndex + 1);
112 ListBoxActive.ItemIndex := ListBoxActive.ItemIndex + 1;
113 end;
114end;
115
116procedure TFormColumns.ButtonOkClick(Sender: TObject);
117begin
118 ActiveColumns.Assign(ListBoxActive.Items);
119end;
120
121procedure TFormColumns.ButtonToLeftClick(Sender: TObject);
122begin
123 if ListBoxActive.ItemIndex = -1 then begin
124 ListBoxActive.Items.AddObject(ListBoxAvailable.Items[ListBoxAvailable.ItemIndex],
125 ListBoxAvailable.Items.Objects[ListBoxAvailable.ItemIndex])
126 end else begin
127 ListBoxActive.Items.InsertObject(ListBoxActive.ItemIndex,
128 ListBoxAvailable.Items[ListBoxAvailable.ItemIndex],
129 ListBoxAvailable.Items.Objects[ListBoxAvailable.ItemIndex]);
130 end;
131 ListBoxAvailable.Items.Delete(ListBoxAvailable.ItemIndex);
132end;
133
134procedure TFormColumns.ButtonToRightClick(Sender: TObject);
135begin
136 ListBoxAvailable.Items.AddObject(ListBoxActive.Items[ListBoxActive.ItemIndex],
137 ListBoxActive.Items.Objects[ListBoxActive.ItemIndex]);
138 ListBoxActive.Items.Delete(ListBoxActive.ItemIndex);
139end;
140
141procedure TFormColumns.FormCreate(Sender: TObject);
142begin
143 Core.Translator.TranslateComponentRecursive(Self);
144 Core.ThemeManager1.UseTheme(Self);
145 ActiveColumns := TStringList.Create;
146 AvailableColumns := TStringList.Create;
147end;
148
149procedure TFormColumns.FormDestroy(Sender: TObject);
150begin
151 FreeAndNil(ActiveColumns);
152 FreeAndNil(AvailableColumns);
153end;
154
155procedure TFormColumns.UpdateInterface;
156begin
157 ButtonToLeft.Enabled := ListBoxAvailable.ItemIndex <> -1;
158 ButtonToRight.Enabled := ListBoxActive.ItemIndex <> -1;
159 ButtonDown.Enabled := (ListBoxActive.ItemIndex <> -1) and (ListBoxActive.ItemIndex < ListBoxActive.Items.Count - 1);
160 ButtonUp.Enabled := (ListBoxActive.ItemIndex <> -1) and (ListBoxActive.ItemIndex > 0);
161end;
162
163end.
164
Note: See TracBrowser for help on using the repository browser.