IDE: Refactor TPathEditorButton more. Copy values between dialog and edit here instead of clients' code.

git-svn-id: trunk@47491 -
This commit is contained in:
juha 2015-01-22 23:03:35 +00:00
parent bd0bafb893
commit 4d145caa9f
5 changed files with 83 additions and 209 deletions

View File

@ -320,8 +320,7 @@ begin
Result := lisGeneral;
end;
procedure TDebuggerGeneralOptionsFrame.Setup(
ADialog: TAbstractOptionsEditorDialog);
procedure TDebuggerGeneralOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
gbDebuggerType.Caption := dlgDebugType;
gbAdditionalSearchPath.Caption := lisDebugOptionsFrmAdditionalSearchPath;

View File

@ -53,7 +53,7 @@ type
out SrcPathChanged: boolean): boolean;
procedure FileBrowseBtnClick(Sender: TObject);
procedure PathEditBtnClick(Sender: TObject);
procedure PathEditBtnExecuted(Sender: TObject);
function PathEditBtnExecuted(Context: String; var NewPath: String): Boolean;
procedure DoShowOptions(Sender: TObject);
procedure DoCheck(Sender: TObject);
procedure DoImport(Sender: TObject);
@ -429,87 +429,18 @@ begin
end;
procedure TCompilerPathOptionsFrame.PathEditBtnClick(Sender: TObject);
var
AButton: TPathEditorButton;
OldPath: string;
begin
if Sender is TPathEditorButton then
begin
AButton := TPathEditorButton(Sender);
if AButton = OtherUnitsPathEditBtn then
OldPath := OtherUnitsEdit.Text
else
if AButton = IncludeFilesPathEditBtn then
OldPath := IncludeFilesEdit.Text
else
if AButton = OtherSourcesPathEditBtn then
OldPath := OtherSourcesEdit.Text
else
if AButton = LibrariesPathEditBtn then
OldPath := LibrariesEdit.Text
else
if AButton = DebugPathEditBtn then
OldPath := DebugPathEdit.Text
else
Exit;
AButton.CurrentPathEditor.BaseDirectory := FCompilerOpts.BaseDirectory;
AButton.CurrentPathEditor.Path := OldPath;
end;
TPathEditorButton(Sender).CurrentPathEditor.BaseDirectory := FCompilerOpts.BaseDirectory;
end;
procedure TCompilerPathOptionsFrame.PathEditBtnExecuted(Sender: TObject);
function CheckPath(const Context, NewPath: string): boolean;
var
ExpandedPath: string;
BaseDir: string;
begin
BaseDir := FCompilerOpts.BaseDirectory;
ExpandedPath := TrimSearchPath(NewPath, BaseDir, true);
Result := CheckSearchPath(Context, ExpandedPath, ccomlHints);
end;
function TCompilerPathOptionsFrame.PathEditBtnExecuted(Context: String; var NewPath: String): Boolean;
var
AButton: TPathEditorButton;
NewPath: string;
ExpandedPath: string;
begin
if Sender is TPathEditorButton then
begin
AButton := TPathEditorButton(Sender);
if AButton.CurrentPathEditor.ModalResult <> mrOk then
Exit;
NewPath := AButton.CurrentPathEditor.Path;
NewPath := FCompilerOpts.ShortenPath(NewPath, False);
if AButton = OtherUnitsPathEditBtn then
begin
if CheckPath(OtherUnitsLabel.Caption, NewPath) then
OtherUnitsEdit.Text := NewPath;
end
else
if AButton = IncludeFilesPathEditBtn then
begin
if CheckPath(IncludeFilesLabel.Caption, NewPath) then
IncludeFilesEdit.Text := NewPath;
end
else
if AButton = OtherSourcesPathEditBtn then
begin
if CheckPath(OtherSourcesLabel.Caption, NewPath) then
OtherSourcesEdit.Text := NewPath;
end
else
if AButton = LibrariesPathEditBtn then
begin
if CheckPath(LibrariesLabel.Caption, NewPath) then
LibrariesEdit.Text := NewPath;
end
else
if AButton = DebugPathEditBtn then
begin
if CheckPath(DebugPathLabel.Caption, NewPath) then
DebugPathEdit.Text := NewPath;
end;
end;
NewPath := FCompilerOpts.ShortenPath(NewPath, False);
ExpandedPath := TrimSearchPath(NewPath, FCompilerOpts.BaseDirectory, true);
Result := CheckSearchPath(Context, ExpandedPath, ccomlHints);
end;
procedure TCompilerPathOptionsFrame.FileBrowseBtnClick(Sender: TObject);
@ -572,6 +503,7 @@ begin
AnchorParallel(akRight, 0, Self);
AutoSize := True;
AssociatedEdit := OtherUnitsEdit;
ContextCaption := OtherUnitsLabel.Caption;
Templates:='$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)' +
';$(LazarusDir)/lcl/units/$(TargetCPU)-$(TargetOS)/$(LCLWidgetType)' +
';$(LazarusDir)/components/codetools/units/$(TargetCPU)-$(TargetOS)' +
@ -599,6 +531,7 @@ begin
AnchorParallel(akRight, 0, Self);
AutoSize := True;
AssociatedEdit := IncludeFilesEdit;
ContextCaption := IncludeFilesLabel.Caption;
Templates := 'include;inc';
OnClick := @PathEditBtnClick;
OnExecuted := @PathEditBtnExecuted;
@ -622,6 +555,7 @@ begin
AnchorParallel(akRight, 0, Self);
AutoSize := True;
AssociatedEdit := OtherSourcesEdit;
ContextCaption := OtherSourcesLabel.Caption;
Templates := '$(LazarusDir)/lcl' +
';$(LazarusDir)/lcl/interfaces/$(LCLWidgetType)' +
';$(LazarusDir)/components/synedit' +
@ -648,6 +582,7 @@ begin
AnchorParallel(akRight, 0, Self);
AutoSize := True;
AssociatedEdit := LibrariesEdit;
ContextCaption := LibrariesLabel.Caption;
Templates := '/usr/X11R6/lib;/sw/lib';
OnClick := @PathEditBtnClick;
OnExecuted := @PathEditBtnExecuted;
@ -693,6 +628,7 @@ begin
AnchorParallel(akRight, 0, Self);
AutoSize := True;
AssociatedEdit := DebugPathEdit;
ContextCaption := DebugPathLabel.Caption;
Templates := '$(LazarusDir)/lcl/include' +
';$(LazarusDir)/lcl/interfaces/$(LCLWidgetType)' +
';$(LazarusDir)/include';

View File

@ -100,7 +100,7 @@ type
property Templates: string read GetTemplates write SetTemplates;
end;
TOnPathEditorExecuted = TNotifyEvent;
TOnPathEditorExecuted = function (Context: String; var NewPath: String): Boolean of object;
{ TPathEditorButton }
@ -108,6 +108,7 @@ type
private
FCurrentPathEditor: TPathEditorDialog;
FAssociatedEdit: TCustomEdit;
FContextCaption: String;
FTemplates: String;
FOnExecuted: TOnPathEditorExecuted;
protected
@ -116,6 +117,7 @@ type
procedure Click; override;
property CurrentPathEditor: TPathEditorDialog read FCurrentPathEditor;
property AssociatedEdit: TCustomEdit read FAssociatedEdit write FAssociatedEdit;
property ContextCaption: String read FContextCaption write FContextCaption;
property Templates: String read FTemplates write FTemplates;
property OnExecuted: TOnPathEditorExecuted read FOnExecuted write FOnExecuted;
end;
@ -593,6 +595,7 @@ begin
try
inherited Click;
FCurrentPathEditor.Templates := SetDirSeparators(FTemplates);
FCurrentPathEditor.Path := AssociatedEdit.Text;
FCurrentPathEditor.ShowModal;
DoOnPathEditorExecuted;
finally
@ -601,8 +604,17 @@ begin
end;
procedure TPathEditorButton.DoOnPathEditorExecuted;
var
Ok: Boolean;
NewPath: String;
begin
if Assigned(OnExecuted) then OnExecuted(Self);
NewPath := FCurrentPathEditor.Path;
Ok := (FCurrentPathEditor.ModalResult = mrOk) and (AssociatedEdit.Text <> NewPath);
if Ok and Assigned(OnExecuted) then
Ok := OnExecuted(ContextCaption, NewPath);
// Assign value only if old <> new and OnExecuted allows it.
if Ok then
AssociatedEdit.Text := NewPath;
end;
end.

View File

@ -33,8 +33,7 @@ type
FPDocPathButton: TPathEditorButton;
FStoredPkgType: TLazPackageType;
function GetSelectedPkgType: TLazPackageType;
procedure PathEditBtnClick(Sender: TObject);
procedure PathEditBtnExecuted(Sender: TObject);
function PathEditBtnExecuted(Context: String; var NewPath: String): Boolean;
procedure SetSelectedPkgType(PkgType: TLazPackageType);
function ShowMsgPackageTypeMustBeDesign: boolean;
function GetFPDocPkgNameEditValue: string;
@ -83,11 +82,6 @@ begin
FPDocPackageNameEdit.Text:=GetFPDocPkgNameEditValue;
end;
procedure TPackageIntegrationOptionsFrame.PathEditBtnClick(Sender: TObject);
begin
(Sender as TPathEditorButton).CurrentPathEditor.Path := FPDocSearchPathsEdit.Text;
end;
function TPackageIntegrationOptionsFrame.GetSelectedPkgType: TLazPackageType;
begin
if RunTimeOnlyRadioButton.Checked then
@ -100,59 +94,44 @@ begin
Result:=lptRunAndDesignTime;
end;
procedure TPackageIntegrationOptionsFrame.PathEditBtnExecuted(Sender: TObject);
function TPackageIntegrationOptionsFrame.PathEditBtnExecuted(Context: String;
var NewPath: String): Boolean;
var
AButton: TPathEditorButton absolute Sender;
NewPath: string;
OldPath: string;
CurDir: string;
StartPos: integer;
StartPos, OldStartPos: integer;
DlgResult: TModalResult;
OldStartPos: longint;
begin
if AButton.CurrentPathEditor.ModalResult <> mrOk then
Exit;
NewPath := AButton.CurrentPathEditor.Path;
OldPath := FPDocSearchPathsEdit.Text;
if OldPath <> NewPath then
begin
// check NewPath
StartPos := 1;
repeat
OldStartPos := StartPos;
CurDir := GetNextDirectoryInSearchPath(NewPath, StartPos);
if CurDir <> '' then
// check NewPath
StartPos := 1;
repeat
OldStartPos := StartPos;
CurDir := GetNextDirectoryInSearchPath(NewPath, StartPos);
if CurDir <> '' then
begin
IDEMacros.SubstituteMacros(CurDir);
FLazPackage.LongenFilename(CurDir);
if not DirPathExists(CurDir) then
begin
IDEMacros.SubstituteMacros(CurDir);
FLazPackage.LongenFilename(CurDir);
if not DirPathExists(CurDir) then
begin
DlgResult := QuestionDlg(lisEnvOptDlgDirectoryNotFound,
Format(lisDirectoryNotFound, [CurDir]),
mtError, [mrIgnore, mrYes, lisRemoveFromSearchPath, mrCancel], 0);
case DlgResult of
mrIgnore: ;
mrYes:
begin
// remove directory from search path
NewPath := copy(NewPath, 1, OldStartPos - 1) +
copy(NewPath, StartPos, length(NewPath));
StartPos := OldStartPos;
end;
else
// undo
NewPath := OldPath;
break;
DlgResult := QuestionDlg(lisEnvOptDlgDirectoryNotFound,
Format(lisDirectoryNotFound, [CurDir]),
mtError, [mrIgnore, mrYes, lisRemoveFromSearchPath, mrCancel], 0);
case DlgResult of
mrIgnore: ;
mrYes:
begin // remove directory from search path
NewPath := copy(NewPath,1,OldStartPos-1) + copy(NewPath,StartPos,length(NewPath));
StartPos := OldStartPos;
end;
else // undo
Exit(False);
end;
end;
until StartPos > length(NewPath);
end;
FPDocSearchPathsEdit.Text := NewPath;
end;
until StartPos > length(NewPath);
Result := True;
end;
procedure TPackageIntegrationOptionsFrame.SetSelectedPkgType(
PkgType: TLazPackageType);
procedure TPackageIntegrationOptionsFrame.SetSelectedPkgType(PkgType: TLazPackageType);
begin
case PkgType of
lptRunTime: RunTimeRadioButton.Checked:=true;
@ -202,7 +181,6 @@ begin
AnchorParallel(akTop, 0, FPDocSearchPathsEdit);
AnchorParallel(akBottom, 0, FPDocSearchPathsEdit);
AssociatedEdit := FPDocSearchPathsEdit;
OnClick := @PathEditBtnClick;
OnExecuted := @PathEditBtnExecuted;
Parent := DocGroupBox;
end;

View File

@ -36,9 +36,7 @@ type
ObjectPathButton: TPathEditorButton;
LibraryPathButton: TPathEditorButton;
FLazPackage: TLazPackage;
procedure PathEditBtnClick(Sender: TObject);
procedure PathEditBtnExecuted(Sender: TObject);
function GetEditForPathButton(AButton: TPathEditorButton): TEdit;
function PathEditBtnExecuted(Context: String; var NewPath: String): Boolean;
public
function GetTitle: string; override;
procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
@ -53,85 +51,40 @@ implementation
{ TPackageUsageOptionsFrame }
procedure TPackageUsageOptionsFrame.PathEditBtnClick(Sender: TObject);
function TPackageUsageOptionsFrame.PathEditBtnExecuted(Context: String; var NewPath: String): Boolean;
var
AButton: TPathEditorButton;
AnEdit: TEdit;
begin
if not (Sender is TPathEditorButton) then exit;
AButton := TPathEditorButton(Sender);
AnEdit := GetEditForPathButton(AButton);
AButton.CurrentPathEditor.Path := AnEdit.Text;
end;
procedure TPackageUsageOptionsFrame.PathEditBtnExecuted(Sender: TObject);
var
AButton: TPathEditorButton;
NewPath: string;
AnEdit: TEdit;
OldPath: string;
CurDir: string;
StartPos: integer;
StartPos, OldStartPos: integer;
DlgResult: TModalResult;
OldStartPos: longint;
begin
if not (Sender is TPathEditorButton) then
exit;
AButton := TPathEditorButton(Sender);
if AButton.CurrentPathEditor.ModalResult <> mrOk then
exit;
NewPath := AButton.CurrentPathEditor.Path;
AnEdit := GetEditForPathButton(AButton);
OldPath := AnEdit.Text;
if OldPath <> NewPath then
begin
// check NewPath
StartPos := 1;
repeat
OldStartPos := StartPos;
CurDir := GetNextDirectoryInSearchPath(NewPath, StartPos);
if CurDir <> '' then
// check NewPath
StartPos := 1;
repeat
OldStartPos := StartPos;
CurDir := GetNextDirectoryInSearchPath(NewPath, StartPos);
if CurDir <> '' then
begin
IDEMacros.SubstituteMacros(CurDir);
FLazPackage.LongenFilename(CurDir);
if not DirPathExists(CurDir) then
begin
IDEMacros.SubstituteMacros(CurDir);
FLazPackage.LongenFilename(CurDir);
if not DirPathExists(CurDir) then
begin
DlgResult := QuestionDlg(lisEnvOptDlgDirectoryNotFound,
Format(lisDirectoryNotFound, [CurDir]),
mtError, [mrIgnore, mrYes, lisRemoveFromSearchPath, mrCancel], 0);
case DlgResult of
mrIgnore: ;
mrYes:
begin
// remove directory from search path
NewPath := copy(NewPath,1,OldStartPos-1) + copy(NewPath,StartPos,length(NewPath));
StartPos := OldStartPos;
end;
else
// undo
NewPath := OldPath;
break;
DlgResult := QuestionDlg(lisEnvOptDlgDirectoryNotFound,
Format(lisDirectoryNotFound, [CurDir]),
mtError, [mrIgnore, mrYes, lisRemoveFromSearchPath, mrCancel], 0);
case DlgResult of
mrIgnore: ;
mrYes:
begin // remove directory from search path
NewPath := copy(NewPath,1,OldStartPos-1) + copy(NewPath,StartPos,length(NewPath));
StartPos := OldStartPos;
end;
else // undo
Exit(False);
end;
end;
until StartPos > length(NewPath);
end;
AnEdit.Text := NewPath;
end;
function TPackageUsageOptionsFrame.GetEditForPathButton(
AButton: TPathEditorButton): TEdit;
begin
if AButton = UnitPathButton then
Result := UnitPathEdit
else if AButton = IncludePathButton then
Result := IncludePathEdit
else if AButton = ObjectPathButton then
Result := ObjectPathEdit
else if AButton = LibraryPathButton then
Result := LibraryPathEdit
else
Result := nil;
end;
until StartPos > length(NewPath);
Result := True;
end;
function TPackageUsageOptionsFrame.GetTitle: string;
@ -168,7 +121,6 @@ begin
';$(LazarusDir)/components/codetools/units/$(TargetCPU)-$(TargetOS)' +
';$(LazarusDir)/components/custom' +
';$(LazarusDir)/packager/units/$(TargetCPU)-$(TargetOS)';
OnClick := @PathEditBtnClick;
OnExecuted := @PathEditBtnExecuted;
end;
UnitPathEdit.AnchorToNeighbour(akRight,0,UnitPathButton);
@ -186,7 +138,6 @@ begin
AnchorParallel(akBottom, 0, IncludePathEdit);
AssociatedEdit := IncludePathEdit;
Templates := 'include';
OnClick := @PathEditBtnClick;
OnExecuted := @PathEditBtnExecuted;
end;
IncludePathEdit.AnchorToNeighbour(akRight,0,IncludePathButton);
@ -204,7 +155,6 @@ begin
AnchorParallel(akBottom, 0, ObjectPathEdit);
AssociatedEdit := ObjectPathEdit;
Templates := 'objects';
OnClick := @PathEditBtnClick;
OnExecuted := @PathEditBtnExecuted;
end;
ObjectPathEdit.AnchorToNeighbour(akRight,0,ObjectPathButton);
@ -221,7 +171,6 @@ begin
AnchorParallel(akTop, 0, LibraryPathEdit);
AnchorParallel(akBottom, 0, LibraryPathEdit);
AssociatedEdit := LibraryPathEdit;
OnClick := @PathEditBtnClick;
OnExecuted := @PathEditBtnExecuted;
end;
LibraryPathEdit.AnchorToNeighbour(akRight,0,LibraryPathButton);