OSDN Git Service

TEditor、TTaskTrayの配布先変更に追従
[winbottle/winbottle.git] / bottleclient / BottleChainRuleEditor.pas
1 unit BottleChainRuleEditor;
2
3 interface
4
5 uses
6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7   Dialogs, StdCtrls, CheckLst, ComCtrls, BottleChainRule;
8
9 type
10   TfrmBottleChainRuleEditor = class(TForm)
11     PageControl: TPageControl;
12     tstGeneral: TTabSheet;
13     tstCondition: TTabSheet;
14     tstAction: TTabSheet;
15     cbxRuleEnabled: TCheckBox;
16     lblTitle: TLabel;
17     edtTitle: TEdit;
18     btnOK: TButton;
19     memStringExpression: TMemo;
20     lstCondition: TCheckListBox;
21     lstAction: TCheckListBox;
22     Button1: TButton;
23     procedure btnOKClick(Sender: TObject);
24     procedure lstConditionClickCheck(Sender: TObject);
25     procedure lstActionClickCheck(Sender: TObject);
26     procedure lstConditionDblClick(Sender: TObject);
27     procedure lstActionDblClick(Sender: TObject);
28     procedure edtTitleChange(Sender: TObject);
29     procedure cbxRuleEnabledClick(Sender: TObject);
30     procedure Button1Click(Sender: TObject);
31   private
32     { Private \90é\8c¾ }
33     FRule: TBottleChainRule;
34     FConditionsCheckStatus: array [0..High(BottleChainConditions)] of boolean;
35     FActionsCheckStatus: array [0..High(BottleChainActions)] of boolean;
36     procedure lstConditionChecked(Index: integer; Checked: boolean);
37     procedure lstActionChecked(Index: integer; Checked: boolean);
38   public
39     { Public \90é\8c¾ }
40     procedure InitializeDisplay;
41     procedure UpdateDisplay;
42     function Execute(EditRule: TBottleChainRule): boolean;
43   end;
44
45 var
46   frmBottleChainRuleEditor: TfrmBottleChainRuleEditor;
47
48 implementation
49
50 {$R *.dfm}
51
52 { TfrmBottleChainListEditor }
53
54 function TfrmBottleChainRuleEditor.Execute(EditRule: TBottleChainRule): boolean;
55 begin
56   if EditRule = nil then raise Exception.Create('EditRule is null');
57   FRule := EditRule;
58   InitializeDisplay;
59   UpdateDisplay;
60   Result := ShowModal = mrOk;
61 end;
62
63 procedure TfrmBottleChainRuleEditor.UpdateDisplay;
64 var i, j: integer;
65     f: boolean;
66 begin
67   memStringExpression.Text := FRule.StringExpression;
68   edtTitle.Text := FRule.Title;
69   cbxRuleEnabled.Checked := FRule.Enabled;
70
71   for i := 0 to High(BottleChainConditions) do begin
72     f := false;
73     for j := 0 to FRule.Conditions.Count-1 do
74       if FRule.Conditions[j].ClassType = BottleChainConditions[i] then begin
75         f := true;
76         lstCondition.Items[i] := (FRule.Conditions[j] as TBottleChainCondition).StringExpression;
77         Break;
78       end;
79     lstCondition.Checked[i] := f;
80     FConditionsCheckStatus[i] := f;
81     if not f then
82       lstCondition.Items[i] := BottleChainConditions[i].Title;
83   end;
84
85   for i := 0 to High(BottleChainActions) do begin
86     f := false;
87     for j := 0 to FRule.Actions.Count-1 do
88       if FRule.Actions[j].ClassType = BottleChainActions[i] then begin
89         f := true;
90         lstAction.Items[i] := (FRule.Actions[j] as TBottleChainAction).StringExpression;
91         Break;
92       end;
93     lstAction.Checked[i] := f;
94     FActionsCheckStatus[i] := f;
95     if not f then
96       lstAction.Items[i] := BottleChainActions[i].Title;
97   end;
98 end;
99
100 procedure TfrmBottleChainRuleEditor.btnOKClick(Sender: TObject);
101 begin
102   ModalResult := mrOk;
103 end;
104
105 procedure TfrmBottleChainRuleEditor.InitializeDisplay;
106 var i: integer;
107     ConditionClass: TBottleChainConditionClass;
108     ActionClass: TBottleChainActionClass;
109 begin
110   lstCondition.Items.Clear;
111   for i := 0 to High(BottleChainConditions) do begin
112     ConditionClass := BottleChainConditions[i];
113     lstCondition.Items.Add(ConditionClass.Title);
114   end;
115   lstAction.Items.Clear;
116   for i := 0 to High(BottleChainActions) do begin
117     ActionClass := BottleChainActions[i];
118     lstAction.Items.Add(ActionClass.Title);
119   end;
120 end;
121
122 procedure TfrmBottleChainRuleEditor.lstConditionClickCheck(
123   Sender: TObject);
124 var i: integer;
125 begin
126   // \82±\82Ì\82Ü\82Ü\82¾\82Æ\95s\95Ö\82È\82Ì\82Å\8f\88\97\9d
127   for i := 0 to High(BottleChainConditions) do begin
128     if lstCondition.Checked[i] <> FConditionsCheckStatus[i] then
129       lstConditionChecked(i, lstCondition.Checked[i]);
130   end;
131 end;
132
133 procedure TfrmBottleChainRuleEditor.lstActionClickCheck(Sender: TObject);
134 var i: integer;
135 begin
136   // \82±\82Ì\82Ü\82Ü\82¾\82Æ\95s\95Ö\82È\82Ì\82Å\8f\88\97\9d
137   for i := 0 to High(BottleChainActions) do begin
138     if lstAction.Checked[i] <> FActionsCheckStatus[i] then
139       lstActionChecked(i, lstAction.Checked[i]);
140   end;
141 end;
142
143 procedure TfrmBottleChainRuleEditor.lstActionChecked(Index: integer;
144   Checked: boolean);
145 var Action: TBottleChainAction;
146     i: integer;
147 begin
148   if Checked then begin
149     Action := BottleChainActions[Index].Create(BottleChainRuleList);
150     Action.Rule := FRule;
151     if Action.Edit then begin
152     end else begin
153       Action.Free;
154       lstAction.Checked[Index] := false;
155     end;
156   end else begin
157     for i := FRule.Actions.Count-1 downto 0 do begin
158       if FRule.Actions[i].ClassType = BottleChainActions[Index] then
159         FRule.Actions[i].Free;
160     end;
161   end;
162   UpdateDisplay;
163 end;
164
165 procedure TfrmBottleChainRuleEditor.lstConditionChecked(Index: integer;
166   Checked: boolean);
167 var Condition: TBottleChainCondition;
168     i: integer;
169 begin
170   if Checked then begin
171     Condition := BottleChainConditions[Index].Create(BottleChainRuleList);
172     Condition.Rule := FRule;
173     if Condition.Edit then begin
174     end else begin
175       Condition.Free;
176       lstCondition.Checked[Index] := false;
177     end;
178   end else begin
179     for i := FRule.Conditions.Count-1 downto 0 do begin
180       if FRule.Conditions[i].ClassType = BottleChainConditions[Index] then
181         FRule.Conditions[i].Free;
182     end;
183   end;
184   UpdateDisplay;
185 end;
186
187
188 procedure TfrmBottleChainRuleEditor.lstConditionDblClick(Sender: TObject);
189 var index, i: integer;
190 begin
191   index := lstCondition.ItemIndex;
192   if Index < 0 then Exit;
193   if lstCondition.Checked[Index] then begin
194     for i := 0 to FRule.Conditions.Count-1 do
195       if FRule.Conditions[i].ClassType = BottleChainConditions[Index] then begin
196         (FRule.Conditions[i] as TBottleChainCondition).Edit;
197         Break;
198       end;
199   end else begin
200     lstCondition.Checked[Index] := true;
201     lstConditionChecked(Index, true);
202   end;
203   UpdateDisplay;
204 end;
205
206 procedure TfrmBottleChainRuleEditor.lstActionDblClick(Sender: TObject);
207 var index, i: integer;
208 begin
209   index := lstAction.ItemIndex;
210   if Index < 0 then Exit;
211   if lstAction.Checked[Index] then begin
212     for i := 0 to FRule.Actions.Count-1 do
213       if FRule.Actions[i].ClassType = BottleChainActions[Index] then begin
214         (FRule.Actions[i] as TBottleChainAction).Edit;
215         Break;
216       end;
217   end else begin
218     lstAction.Checked[Index] := true;
219     lstActionChecked(Index, true);
220   end;
221   UpdateDisplay;
222 end;
223
224 procedure TfrmBottleChainRuleEditor.edtTitleChange(Sender: TObject);
225 begin
226   FRule.Title := edtTitle.Text;
227 end;
228
229 procedure TfrmBottleChainRuleEditor.cbxRuleEnabledClick(Sender: TObject);
230 begin
231   FRule.Enabled := cbxRuleEnabled.Checked;
232 end;
233
234 procedure TfrmBottleChainRuleEditor.Button1Click(Sender: TObject);
235 begin
236   ModalResult := mrCancel;
237 end;
238
239 end.