diff --git a/.gitattributes b/.gitattributes index 8b947bc65f..bf10755c27 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1823,6 +1823,8 @@ components/ideintf/actionseditor.pas svneol=native#text/pascal components/ideintf/actionseditorstd.lfm svneol=native#text/plain components/ideintf/actionseditorstd.pas svneol=native#text/pascal components/ideintf/baseideintf.pas svneol=native#text/plain +components/ideintf/changeparentdlg.lfm svneol=native#text/plain +components/ideintf/changeparentdlg.pas svneol=native#text/pascal components/ideintf/checkgroupeditordlg.lfm svneol=native#text/plain components/ideintf/checkgroupeditordlg.pas svneol=native#text/plain components/ideintf/checklistboxeditordlg.lfm svneol=native#text/plain diff --git a/components/ideintf/changeparentdlg.lfm b/components/ideintf/changeparentdlg.lfm new file mode 100644 index 0000000000..7ecd8b0992 --- /dev/null +++ b/components/ideintf/changeparentdlg.lfm @@ -0,0 +1,110 @@ +object ChangeParentDlg: TChangeParentDlg + Left = 550 + Height = 386 + Top = 217 + Width = 248 + BorderIcons = [biSystemMenu, biMaximize] + Caption = 'ChangeParentDlg' + ClientHeight = 386 + ClientWidth = 248 + OnClose = FormClose + OnCreate = FormCreate + Position = poScreenCenter + LCLVersion = '1.7' + object ListFilterEdit: TListFilterEdit + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = Owner + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + Left = 6 + Height = 21 + Top = 6 + Width = 236 + OnAfterFilter = ListFilterEditAfterFilter + ButtonWidth = 23 + NumGlyphs = 1 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Around = 6 + MaxLength = 0 + TabOrder = 0 + end + object ListBox: TListBox + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = ListFilterEdit + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = chShowClasses + Left = 6 + Height = 260 + Top = 33 + Width = 236 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Around = 6 + ItemHeight = 0 + OnDblClick = ListBoxDblClick + OnSelectionChange = ListBoxSelectionChange + TabOrder = 1 + end + object ButtonPanel: TButtonPanel + Left = 6 + Height = 26 + Top = 354 + Width = 236 + OKButton.Name = 'OKButton' + OKButton.DefaultCaption = True + OKButton.OnClick = OKButtonClick + HelpButton.Name = 'HelpButton' + HelpButton.DefaultCaption = True + CloseButton.Name = 'CloseButton' + CloseButton.DefaultCaption = True + CancelButton.Name = 'CancelButton' + CancelButton.DefaultCaption = True + TabOrder = 2 + ShowButtons = [pbOK, pbCancel] + ShowBevel = False + end + object lblSelectedControls: TLabel + AnchorSideLeft.Control = ListBox + AnchorSideRight.Control = ListBox + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = lblCurentParents + Left = 6 + Height = 13 + Top = 319 + Width = 236 + Anchors = [akLeft, akRight, akBottom] + BorderSpacing.Bottom = 3 + Caption = 'lblSelectedControls' + ParentColor = False + ParentFont = False + WordWrap = True + end + object lblCurentParents: TLabel + AnchorSideLeft.Control = ListBox + AnchorSideRight.Control = ListBox + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = ButtonPanel + Left = 6 + Height = 13 + Top = 335 + Width = 236 + Anchors = [akLeft, akRight, akBottom] + Caption = 'lblCurentParents' + ParentColor = False + WordWrap = True + end + object chShowClasses: TCheckBox + AnchorSideLeft.Control = ListBox + AnchorSideBottom.Control = lblSelectedControls + Left = 6 + Height = 17 + Top = 299 + Width = 91 + Anchors = [akLeft, akBottom] + BorderSpacing.Bottom = 3 + Caption = 'chShowClasses' + OnClick = chShowClassesClick + TabOrder = 3 + end +end diff --git a/components/ideintf/changeparentdlg.pas b/components/ideintf/changeparentdlg.pas new file mode 100644 index 0000000000..449e7c516a --- /dev/null +++ b/components/ideintf/changeparentdlg.pas @@ -0,0 +1,269 @@ +{ + ***************************************************************************** + See the file COPYING.modifiedLGPL.txt, included in this distribution, + for details about the license. + ***************************************************************************** + + Author: FTurtle + + Abstract: + Dialog for choosing new parent name. +} + +unit ChangeParentDlg; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, strutils, FileUtil, ListFilterEdit, PropEditUtils, Forms, + Controls, Graphics, Dialogs, StdCtrls, ButtonPanel; + +type + + { TChangeParentDlg } + + TChangeParentDlg = class(TForm) + ButtonPanel: TButtonPanel; + chShowClasses: TCheckBox; + lblSelectedControls: TLabel; + lblCurentParents: TLabel; + ListBox: TListBox; + ListFilterEdit: TListFilterEdit; + procedure chShowClassesClick(Sender: TObject); + procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); + procedure FormCreate(Sender: TObject); + procedure ListBoxDblClick(Sender: TObject); + procedure ListBoxSelectionChange(Sender: TObject; User: boolean); + procedure ListFilterEditAfterFilter(Sender: TObject); + procedure OKButtonClick(Sender: TObject); + private + class var + FSavedWidth: Integer; + FSavedHeight: Integer; + FSavedShowClasses: Boolean; + private + FCandidates: TFPList; + FIgnoredCandidateName: string; + function GetSelectedItem: string; + procedure RefreshList; + procedure SetSelection(ASelection: TPersistentSelectionList); + procedure UpdateOKButtonState; + public + function ShowModal: Integer; override; + public + property SelectedItem: string read GetSelectedItem; + property Selection: TPersistentSelectionList write SetSelection; + property Candidates: TFPList write FCandidates; + end; + +function ShowChangeParentDlg(ASelection: TPersistentSelectionList; + ACandidates: TFPList; out ANewParentName: string): Boolean; + + +implementation + +uses LCLIntf, ObjInspStrConsts; + +{$R *.lfm} + +{ TChangeParentDlg } + +const + colon = ': '; + +function ShowChangeParentDlg(ASelection: TPersistentSelectionList; + ACandidates: TFPList; out ANewParentName: string): Boolean; +begin + if not Assigned(ASelection) or not Assigned(ACandidates) then + Exit(False); + + with TChangeParentDlg.Create(nil) do + try + Selection := ASelection; + Candidates := ACandidates; + Result := (ShowModal = mrOK); + if Result then + ANewParentName := SelectedItem; + finally + Free; + end; +end; + + +procedure TChangeParentDlg.FormCreate(Sender: TObject); +begin + Constraints.MinHeight := 250; + Constraints.MinWidth := 175; + + Height := FSavedHeight; // see "initialization" + Width := FSavedWidth; + chShowClasses.Checked := FSavedShowClasses; + + Caption := oisChangeParent; + chShowClasses.Caption := oisShowClasses; +end; + +{$HINTS OFF} +procedure TChangeParentDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction); +begin + FSavedHeight := Height; + FSavedWidth := Width; + FSavedShowClasses := chShowClasses.Checked; +end; +{$HINTS ON} + +procedure TChangeParentDlg.chShowClassesClick(Sender: TObject); +begin + if Assigned(FCandidates) then + RefreshList; +end; + +procedure TChangeParentDlg.ListBoxDblClick(Sender: TObject); +begin + ButtonPanel.OKButton.Click; +end; + +{$HINTS OFF} +procedure TChangeParentDlg.ListBoxSelectionChange(Sender: TObject; User: boolean); +begin + UpdateOKButtonState; +end; +{$HINTS ON} + +procedure TChangeParentDlg.ListFilterEditAfterFilter(Sender: TObject); +begin + UpdateOKButtonState; +end; + +procedure TChangeParentDlg.OKButtonClick(Sender: TObject); +begin + if ListBox.ItemIndex < 0 then + ModalResult := mrNone; +end; + +function TChangeParentDlg.GetSelectedItem: string; +var + n: Integer; +begin + if ListBox.ItemIndex < 0 then + Exit(''); + Result := ListBox.Items[ListBox.ItemIndex]; + n := Pos(colon, Result); + if n>0 then + SetLength(Result, n-1); +end; + +procedure TChangeParentDlg.RefreshList; +var + i: Integer; + OldIndex: Integer; + + function MakeItem(ACandidate: TWinControl): string; + begin + if chShowClasses.Checked then + Result := ACandidate.Name + colon + ACandidate.ClassName + else + Result := ACandidate.Name; + end; + + function IsIgnoredName: Boolean; + begin + Result := (TWinControl(FCandidates.Items[i]).Name = FIgnoredCandidateName); + end; + +begin + OldIndex := ListBox.ItemIndex; + ListFilterEdit.FilteredListbox := nil; + ListBox.Items.Clear; + for i:=0 to FCandidates.Count-1 do + if not IsIgnoredName then + ListBox.Items.Add(MakeItem(TWinControl(FCandidates.Items[i]))); + ListBox.ItemIndex := OldIndex; // if list was filtered it may select other item + ListFilterEdit.FilteredListbox := ListBox; + ListFilterEdit.Text := ''; + UpdateOKButtonState; +end; + +procedure TChangeParentDlg.SetSelection(ASelection: TPersistentSelectionList); +var + i, ControlsCount: Integer; + sControls, sParents: string; + CurParentNameList: TStringList; + + procedure AddControlName(AControlName: string); + begin + Inc(ControlsCount); + if ControlsCount = 1 then + sControls := AControlName + else + sControls := sControls + ', ' + AControlName; + end; + + procedure TryAddParentName(AParentName: string); + begin + if CurParentNameList.IndexOf(AParentName) < 0 then + CurParentNameList.Append(AParentName); + end; + + procedure SetIgnoredCandidateName; + var + j: Integer; + begin + FIgnoredCandidateName := CurParentNameList[0]; + for j:=1 to CurParentNameList.Count-1 do + if FIgnoredCandidateName <> CurParentNameList[j] then + begin + FIgnoredCandidateName := ''; + Break; + end; + end; + +begin + ControlsCount := 0; + CurParentNameList := TStringList.Create; + + for i:=0 to ASelection.Count-1 do + if ASelection.Items[i] is TControl then + begin + AddControlName(TControl(ASelection.Items[i]).Name); + TryAddParentName(TControl(ASelection.Items[i]).Parent.Name); + end; + + sControls := IfThen(ControlsCount > 1, oisSelectedControls, oisSelectedControl) + + ': ' + sControls; + + if CurParentNameList.Count > 0 then + begin + sParents := IfThen(CurParentNameList.Count > 1, oisCurrentParents, oisCurrentParent) + + ': ' + CurParentNameList[0]; + for i:=1 to CurParentNameList.Count-1 do + sParents := sParents + ', ' + CurParentNameList[i]; + SetIgnoredCandidateName; + end; + + lblSelectedControls.Caption := sControls; + lblCurentParents.Caption := sParents; + + CurParentNameList.Free; +end; + +procedure TChangeParentDlg.UpdateOKButtonState; +begin + ButtonPanel.OKButton.Enabled := (ListBox.ItemIndex > -1); +end; + +function TChangeParentDlg.ShowModal: Integer; +begin + RefreshList; + Result := inherited ShowModal; +end; + +initialization + TChangeParentDlg.FSavedWidth := 250; + TChangeParentDlg.FSavedHeight := 390; + TChangeParentDlg.FSavedShowClasses := False; + +end. +