unit GroupDialogUnit; interface uses Groups, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ActnList; Type { This interface is useful for docking windows. A parent window knows which ones of its childen support groups. That way it can, optionally, make sure the children are all in the same group. This interface is used by the Group Dialog, and some other units. This interface is not required or used by the groups unit. } IHasGroup = Interface(IUnknown) ['{951AB1B0-9EE9-4A0A-BB95-FB499DBB1D94}'] Function GetGroup : String; Procedure SetGroup(Group : String); End; TGroupDialoglAction = Class(TAction) Public Constructor Create(AOwner: TComponent); override; Private Procedure DisplayDialog(Sender : TObject); End; type TGroupDialog = class(TForm) OK: TButton; Cancel: TButton; SetGroupFor: TRadioGroup; GroupBox1: TGroupBox; GroupName: TComboBox; NewGroup: TButton; NoGroupName: TButton; procedure FormShow(Sender: TObject); procedure SetGroupForClick(Sender: TObject); procedure GroupNameChange(Sender: TObject); procedure NoGroupNameClick(Sender: TObject); procedure NewGroupClick(Sender: TObject); procedure OKClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure GroupNameCloseUp(Sender: TObject); procedure FormHide(Sender: TObject); private GroupNames : TStrings; CallingPanel, CallingWindow : IHasGroup; Procedure SetupGroupNamePanel; Procedure SetInitialWindow(InitialWindow : TComponent); Function EntireWindow : Boolean; //Function PanelOnly : Boolean; public { Public declarations } end; Function AnnotatedGroupName(Group : String) : String; var GroupDialog: TGroupDialog; implementation {$R *.dfm} Uses Menus; Function AnnotatedGroupName(Group : String) : String; Var Symbol : String; Begin Symbol := TGroupList.Instance.GetSymbol(Group); If Symbol = '' Then Result := Group Else Result := Group + ' (' + Symbol + ')' End; Constructor TGroupDialoglAction.Create(AOwner: TComponent); Begin Inherited; Caption := 'Set Group...'; ShortCut := Menus.ShortCut(Word('G'), [ssCtrl]); OnExecute := DisplayDialog End; Procedure TGroupDialoglAction.DisplayDialog(Sender : TObject); Begin GroupDialog.SetInitialWindow(Owner); GroupDialog.ShowModal End; Procedure TGroupDialog.SetInitialWindow(InitialWindow : TComponent); Var NextComponent : TWinControl; Begin CallingPanel := Nil; CallingWindow := Nil; If Not (InitialWindow Is TWinControl) Then Exit; NextComponent := InitialWindow As TWinControl; While Assigned(NextComponent) Do Begin If Supports(NextComponent, IHasGroup) Then If CallingPanel = Nil Then CallingPanel := NextComponent As IHasGroup Else CallingWindow := NextComponent As IHasGroup; NextComponent := NextComponent.Parent End End; Procedure TGroupDialog.FormShow(Sender: TObject); Var I : Integer; Begin GroupNames.Assign(TGroupList.Instance.GroupNames); GroupName.Items.Clear; For I := 0 To Pred(GroupNames.Count) Do GroupName.Items.Add(AnnotatedGroupName(GroupNames[I])); If Not Assigned(CallingPanel) Then Begin SetGroupFor.ItemIndex := 0; SetGroupFor.Enabled := False End Else If Not Assigned(CallingWindow) Then Begin SetGroupFor.ItemIndex := 1; SetGroupFor.Enabled := False End Else Begin If CallingWindow.GetGroup = '' Then SetGroupFor.ItemIndex := 1 Else SetGroupFor.ItemIndex := 0; SetGroupFor.Enabled := True End; SetupGroupNamePanel End; Procedure TGroupDialog.SetGroupForClick(Sender: TObject); Begin SetupGroupNamePanel End; Function TGroupDialog.EntireWindow : Boolean; Begin Result := SetGroupFor.ItemIndex = 0 End; {Function TGroupDialog.PanelOnly : Boolean; Begin Result := SetGroupFor.ItemIndex = 1 End;} Procedure TGroupDialog.SetupGroupNamePanel; Var Index : Integer; Begin If EntireWindow Then Begin Index := GroupNames.IndexOf(CallingWindow.GetGroup); GroupName.ItemIndex := Index; If Index = -1 Then GroupName.Text := CallingWindow.GetGroup; NoGroupName.Enabled := True End Else Begin Index := GroupNames.IndexOf(CallingPanel.GetGroup); If Index = -1 Then GroupName.Text := CallingPanel.GetGroup Else GroupName.ItemIndex := Index; NoGroupName.Enabled := False End; GroupNameChange(Nil) End; Procedure TGroupDialog.GroupNameChange(Sender: TObject); Begin OK.Enabled := EntireWindow Or (GroupName.Text <> '') End; procedure TGroupDialog.NoGroupNameClick(Sender: TObject); begin GroupName.ItemIndex := -1; GroupName.Text := '' end; procedure TGroupDialog.NewGroupClick(Sender: TObject); begin GroupName.ItemIndex := -1; GroupName.Text := TGroupList.Instance.NewGroup end; procedure TGroupDialog.OKClick(Sender: TObject); Var RealGroupName : String; begin If GroupName.ItemIndex = -1 Then RealGroupName := GroupName.Text Else RealGroupName := GroupNames[GroupName.ItemIndex]; If EntireWindow Then CallingWindow.SetGroup(RealGroupName) Else Begin If Assigned(CallingWindow) Then CallingWindow.SetGroup(''); CallingPanel.SetGroup(RealGroupName) End end; procedure TGroupDialog.FormCreate(Sender: TObject); begin GroupNames := TStringList.Create end; procedure TGroupDialog.GroupNameCloseUp(Sender: TObject); begin // If GroupName.ItemIndex >= 0 Then // GroupName.Text := GroupNames[GroupName.ItemIndex] end; procedure TGroupDialog.FormHide(Sender: TObject); begin CallingPanel := Nil; CallingWindow := Nil end; End.