mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-22 01:59:12 +02:00
ide: TPathEditorButton.AssociatedComboBox
This commit is contained in:
parent
fbb3adf777
commit
dc9124cb4e
@ -108,24 +108,28 @@ type
|
|||||||
|
|
||||||
TPathEditorButton = class(TButton)
|
TPathEditorButton = class(TButton)
|
||||||
private
|
private
|
||||||
|
FAssociatedComboBox: TCustomComboBox;
|
||||||
FCurrentPathEditor: TPathEditorDialog;
|
FCurrentPathEditor: TPathEditorDialog;
|
||||||
FAssociatedEdit: TCustomEdit;
|
FAssociatedEdit: TCustomEdit;
|
||||||
FContextCaption: String;
|
FContextCaption: String;
|
||||||
FTemplates: String;
|
FTemplates: String;
|
||||||
FOnExecuted: TOnPathEditorExecuted;
|
FOnExecuted: TOnPathEditorExecuted;
|
||||||
|
function GetAssociatedText: string;
|
||||||
protected
|
protected
|
||||||
procedure DoOnPathEditorExecuted;
|
procedure DoOnPathEditorExecuted;
|
||||||
public
|
public
|
||||||
procedure Click; override;
|
procedure Click; override;
|
||||||
property CurrentPathEditor: TPathEditorDialog read FCurrentPathEditor;
|
property CurrentPathEditor: TPathEditorDialog read FCurrentPathEditor;
|
||||||
|
property AssociatedComboBox: TCustomComboBox read FAssociatedComboBox write FAssociatedComboBox;
|
||||||
property AssociatedEdit: TCustomEdit read FAssociatedEdit write FAssociatedEdit;
|
property AssociatedEdit: TCustomEdit read FAssociatedEdit write FAssociatedEdit;
|
||||||
|
property AssociatedText: string read GetAssociatedText;
|
||||||
property ContextCaption: String read FContextCaption write FContextCaption;
|
property ContextCaption: String read FContextCaption write FContextCaption;
|
||||||
property Templates: String read FTemplates write FTemplates;
|
property Templates: String read FTemplates write FTemplates;
|
||||||
property OnExecuted: TOnPathEditorExecuted read FOnExecuted write FOnExecuted;
|
property OnExecuted: TOnPathEditorExecuted read FOnExecuted write FOnExecuted;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function PathEditorDialog: TPathEditorDialog;
|
function PathEditorDialog: TPathEditorDialog;
|
||||||
procedure SetPathTextAndHint(aPath: String; aEdit: TCustomEdit);
|
procedure SetPathTextAndHint(aPath: String; aEdit: TWinControl);
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -185,11 +189,14 @@ begin
|
|||||||
SetLength(Result,j-1);
|
SetLength(Result,j-1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetPathTextAndHint(aPath: String; aEdit: TCustomEdit);
|
procedure SetPathTextAndHint(aPath: String; aEdit: TWinControl);
|
||||||
var
|
var
|
||||||
sl: TStrings;
|
sl: TStrings;
|
||||||
begin
|
begin
|
||||||
aEdit.Text := aPath;
|
if aEdit is TCustomEdit then
|
||||||
|
TCustomEdit(aEdit).Text := aPath
|
||||||
|
else if aEdit is TCustomComboBox then
|
||||||
|
TCustomComboBox(aEdit).Text := aPath;
|
||||||
if Pos(';', aPath) > 0 then
|
if Pos(';', aPath) > 0 then
|
||||||
begin
|
begin
|
||||||
sl := SplitString(aPath, ';');
|
sl := SplitString(aPath, ';');
|
||||||
@ -577,7 +584,7 @@ begin
|
|||||||
try
|
try
|
||||||
inherited Click;
|
inherited Click;
|
||||||
FCurrentPathEditor.Templates := FTemplates;
|
FCurrentPathEditor.Templates := FTemplates;
|
||||||
FCurrentPathEditor.Path := AssociatedEdit.Text;
|
FCurrentPathEditor.Path := AssociatedText;
|
||||||
FCurrentPathEditor.ShowModal;
|
FCurrentPathEditor.ShowModal;
|
||||||
DoOnPathEditorExecuted;
|
DoOnPathEditorExecuted;
|
||||||
finally
|
finally
|
||||||
@ -585,18 +592,31 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TPathEditorButton.GetAssociatedText: string;
|
||||||
|
begin
|
||||||
|
if AssociatedEdit<>nil then
|
||||||
|
Result:=AssociatedEdit.Text
|
||||||
|
else if AssociatedComboBox<>nil then
|
||||||
|
Result:=AssociatedComboBox.Text
|
||||||
|
else
|
||||||
|
Result:='';
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPathEditorButton.DoOnPathEditorExecuted;
|
procedure TPathEditorButton.DoOnPathEditorExecuted;
|
||||||
var
|
var
|
||||||
Ok: Boolean;
|
Ok: Boolean;
|
||||||
NewPath: String;
|
NewPath: String;
|
||||||
begin
|
begin
|
||||||
NewPath := FCurrentPathEditor.Path;
|
NewPath := FCurrentPathEditor.Path;
|
||||||
Ok := (FCurrentPathEditor.ModalResult = mrOk) and (AssociatedEdit.Text <> NewPath);
|
Ok := (FCurrentPathEditor.ModalResult = mrOk) and (AssociatedText <> NewPath);
|
||||||
if Ok and Assigned(OnExecuted) then
|
if Ok and Assigned(OnExecuted) then
|
||||||
Ok := OnExecuted(ContextCaption, NewPath);
|
Ok := OnExecuted(ContextCaption, NewPath);
|
||||||
// Assign value only if old <> new and OnExecuted allows it.
|
// Assign value only if old <> new and OnExecuted allows it.
|
||||||
if Ok then
|
if not Ok then exit;
|
||||||
SetPathTextAndHint(NewPath, AssociatedEdit);
|
if AssociatedEdit<>nil then
|
||||||
|
SetPathTextAndHint(NewPath, AssociatedEdit)
|
||||||
|
else if AssociatedComboBox<>nil then
|
||||||
|
SetPathTextAndHint(NewPath, AssociatedComboBox);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user