mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 21:42:51 +02:00
IDE: improve Path Edit dialog
git-svn-id: trunk@35338 -
This commit is contained in:
parent
0e6dea9e3e
commit
5b4d7f2b9a
@ -96,8 +96,10 @@ object PathEditorDialog: TPathEditorDialog
|
|||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
BorderSpacing.Around = 6
|
BorderSpacing.Around = 6
|
||||||
ItemHeight = 0
|
ItemHeight = 0
|
||||||
|
OnDrawItem = PathListBoxDrawItem
|
||||||
OnKeyDown = PathListBoxKeyDown
|
OnKeyDown = PathListBoxKeyDown
|
||||||
OnSelectionChange = PathListBoxSelectionChange
|
OnSelectionChange = PathListBoxSelectionChange
|
||||||
|
Style = lbOwnerDrawFixed
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
end
|
end
|
||||||
object DirectoryEdit: TDirectoryEdit
|
object DirectoryEdit: TDirectoryEdit
|
||||||
@ -198,6 +200,7 @@ object PathEditorDialog: TPathEditorDialog
|
|||||||
BorderSpacing.Around = 6
|
BorderSpacing.Around = 6
|
||||||
ItemHeight = 0
|
ItemHeight = 0
|
||||||
MultiSelect = True
|
MultiSelect = True
|
||||||
|
OnDblClick = TemplatesListBoxDblClick
|
||||||
OnSelectionChange = TemplatesListBoxSelectionChange
|
OnSelectionChange = TemplatesListBoxSelectionChange
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
end
|
end
|
||||||
|
@ -27,9 +27,9 @@ unit PathEditorDlg;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Forms, Controls, SynEdit, Buttons, StdCtrls, Dialogs,
|
Classes, SysUtils, Forms, Controls, Buttons, StdCtrls, Dialogs,
|
||||||
FileUtil, ButtonPanel, ExtCtrls, EditBtn, MacroIntf, LCLType,
|
FileUtil, ButtonPanel, ExtCtrls, EditBtn, MacroIntf, LCLType, Graphics,
|
||||||
LazarusIDEStrConsts, EditorOptions;
|
types, TransferMacros, LazarusIDEStrConsts;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -60,6 +60,8 @@ type
|
|||||||
procedure FormResize(Sender: TObject);
|
procedure FormResize(Sender: TObject);
|
||||||
procedure MoveDownButtonClick(Sender: TObject);
|
procedure MoveDownButtonClick(Sender: TObject);
|
||||||
procedure MoveUpButtonClick(Sender: TObject);
|
procedure MoveUpButtonClick(Sender: TObject);
|
||||||
|
procedure PathListBoxDrawItem(Control: TWinControl; Index: Integer;
|
||||||
|
ARect: TRect; State: TOwnerDrawState);
|
||||||
procedure PathListBoxKeyDown(Sender: TObject; var Key: Word;
|
procedure PathListBoxKeyDown(Sender: TObject; var Key: Word;
|
||||||
Shift: TShiftState);
|
Shift: TShiftState);
|
||||||
procedure PathListBoxSelectionChange(Sender: TObject; User: boolean);
|
procedure PathListBoxSelectionChange(Sender: TObject; User: boolean);
|
||||||
@ -72,8 +74,9 @@ type
|
|||||||
function GetPath: string;
|
function GetPath: string;
|
||||||
function GetTemplates: string;
|
function GetTemplates: string;
|
||||||
function PathToText(const APath: string): string;
|
function PathToText(const APath: string): string;
|
||||||
function RelativePathHelper: String;
|
function BaseRelative(const APath: string): String;
|
||||||
function AbsolutePathHelper: String;
|
function PathAsAbsolute(const APath: string): String;
|
||||||
|
function PathMayExist(APath: string): TObject;
|
||||||
procedure SetBaseDirectory(const AValue: string);
|
procedure SetBaseDirectory(const AValue: string);
|
||||||
procedure SetPath(const AValue: string);
|
procedure SetPath(const AValue: string);
|
||||||
procedure SetTemplates(const AValue: string);
|
procedure SetTemplates(const AValue: string);
|
||||||
@ -108,9 +111,6 @@ implementation
|
|||||||
|
|
||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
uses
|
|
||||||
Math;
|
|
||||||
|
|
||||||
var PathEditor: TPathEditorDialog;
|
var PathEditor: TPathEditorDialog;
|
||||||
|
|
||||||
function PathEditorDialog: TPathEditorDialog;
|
function PathEditorDialog: TPathEditorDialog;
|
||||||
@ -122,54 +122,76 @@ end;
|
|||||||
|
|
||||||
{ TPathEditorDialog }
|
{ TPathEditorDialog }
|
||||||
|
|
||||||
function TPathEditorDialog.RelativePathHelper: String;
|
function TPathEditorDialog.BaseRelative(const APath: string): String;
|
||||||
begin
|
begin
|
||||||
Result:=DirectoryEdit.Text;
|
Result:=Trim(APath);
|
||||||
if (FEffectiveBaseDirectory<>'') and FilenameIsAbsolute(FEffectiveBaseDirectory) then
|
if (FEffectiveBaseDirectory<>'') and FilenameIsAbsolute(FEffectiveBaseDirectory) then
|
||||||
Result:=CreateRelativePath(Result, FEffectiveBaseDirectory);
|
Result:=CreateRelativePath(Result, FEffectiveBaseDirectory);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TPathEditorDialog.AbsolutePathHelper: String;
|
function TPathEditorDialog.PathAsAbsolute(const APath: string): String;
|
||||||
begin
|
begin
|
||||||
Result:=PathListBox.Items[PathListBox.ItemIndex];
|
Result:=APath;
|
||||||
if (FEffectiveBaseDirectory<>'') and FilenameIsAbsolute(FEffectiveBaseDirectory) then
|
if not TTransferMacroList.StrHasMacros(Result) // not a template
|
||||||
|
and (FEffectiveBaseDirectory<>'') and FilenameIsAbsolute(FEffectiveBaseDirectory) then
|
||||||
Result:=CreateAbsolutePath(Result, FEffectiveBaseDirectory);
|
Result:=CreateAbsolutePath(Result, FEffectiveBaseDirectory);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TPathEditorDialog.PathMayExist(APath: string): TObject;
|
||||||
|
// Returns 1 if path exists or contains a macro, 0 otherwise.
|
||||||
|
// Result is casted to TObject to be used for Strings.Objects.
|
||||||
|
begin
|
||||||
|
if TTransferMacroList.StrHasMacros(APath) then
|
||||||
|
Exit(TObject(1));
|
||||||
|
Result:=TObject(0);
|
||||||
|
if (FEffectiveBaseDirectory<>'') and FilenameIsAbsolute(FEffectiveBaseDirectory) then
|
||||||
|
APath:=CreateAbsolutePath(APath, FEffectiveBaseDirectory);
|
||||||
|
if DirectoryExists(APath) then
|
||||||
|
Result:=TObject(1);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPathEditorDialog.AddButtonClick(Sender: TObject);
|
procedure TPathEditorDialog.AddButtonClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
y: integer;
|
y: integer;
|
||||||
|
RelPath: String;
|
||||||
begin
|
begin
|
||||||
y:=PathListBox.ItemIndex+1;
|
with PathListBox do begin
|
||||||
if y=0 then
|
y:=ItemIndex+1;
|
||||||
y:=PathListBox.Count;
|
if y=0 then
|
||||||
PathListBox.Items.Insert(y,Trim(RelativePathHelper));
|
y:=Count;
|
||||||
PathListBox.ItemIndex:=y;
|
RelPath:=BaseRelative(DirectoryEdit.Text);
|
||||||
UpdateButtons;
|
Items.InsertObject(y, RelPath, PathMayExist(DirectoryEdit.Text));
|
||||||
|
ItemIndex:=y;
|
||||||
|
UpdateButtons;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPathEditorDialog.ReplaceButtonClick(Sender: TObject);
|
procedure TPathEditorDialog.ReplaceButtonClick(Sender: TObject);
|
||||||
|
var
|
||||||
|
RelPath: String;
|
||||||
begin
|
begin
|
||||||
if PathListBox.ItemIndex>-1 then begin
|
with PathListBox do begin
|
||||||
PathListBox.Items[PathListBox.ItemIndex]:=Trim(RelativePathHelper);
|
RelPath:=BaseRelative(DirectoryEdit.Text);
|
||||||
|
Items[ItemIndex]:=RelPath;
|
||||||
|
Items.Objects[ItemIndex]:=PathMayExist(DirectoryEdit.Text);
|
||||||
UpdateButtons;
|
UpdateButtons;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPathEditorDialog.DeleteButtonClick(Sender: TObject);
|
procedure TPathEditorDialog.DeleteButtonClick(Sender: TObject);
|
||||||
var
|
|
||||||
y: integer;
|
|
||||||
begin
|
begin
|
||||||
y:=PathListBox.ItemIndex;
|
PathListBox.Items.Delete(PathListBox.ItemIndex);
|
||||||
if (y>=0) and (y<PathListBox.Count) then begin
|
UpdateButtons;
|
||||||
PathListBox.Items.Delete(y);
|
|
||||||
UpdateButtons;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPathEditorDialog.DeleteInvalidPathsButtonClick(Sender: TObject);
|
procedure TPathEditorDialog.DeleteInvalidPathsButtonClick(Sender: TObject);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
;
|
with PathListBox do
|
||||||
|
for i:=Items.Count-1 downto 0 do
|
||||||
|
if PtrInt(Items.Objects[i])=0 then
|
||||||
|
Items.Delete(i);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPathEditorDialog.AddTemplateButtonClick(Sender: TObject);
|
procedure TPathEditorDialog.AddTemplateButtonClick(Sender: TObject);
|
||||||
@ -180,13 +202,14 @@ begin
|
|||||||
for i:=0 to TemplatesListBox.Items.Count-1 do begin
|
for i:=0 to TemplatesListBox.Items.Count-1 do begin
|
||||||
if TemplatesListBox.Selected[i]
|
if TemplatesListBox.Selected[i]
|
||||||
and (PathListBox.Items.IndexOf(TemplatesListBox.Items[i])=-1) then begin
|
and (PathListBox.Items.IndexOf(TemplatesListBox.Items[i])=-1) then begin
|
||||||
PathListBox.Items.Add(TemplatesListBox.Items[i]);
|
PathListBox.Items.AddObject(TemplatesListBox.Items[i], TObject(1));
|
||||||
y:=PathListBox.Count-1;
|
y:=PathListBox.Count-1;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
if y>=1 then
|
if y>=1 then begin
|
||||||
PathListBox.ItemIndex:=y;
|
PathListBox.ItemIndex:=y;
|
||||||
UpdateButtons;
|
UpdateButtons;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPathEditorDialog.DirectoryEditChange(Sender: TObject);
|
procedure TPathEditorDialog.DirectoryEditChange(Sender: TObject);
|
||||||
@ -194,6 +217,25 @@ begin
|
|||||||
UpdateButtons;
|
UpdateButtons;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPathEditorDialog.PathListBoxSelectionChange(Sender: TObject; User: boolean);
|
||||||
|
begin
|
||||||
|
with PathListBox do
|
||||||
|
if ItemIndex>-1 then begin
|
||||||
|
DirectoryEdit.Text:=PathAsAbsolute(Items[ItemIndex]);
|
||||||
|
UpdateButtons;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TPathEditorDialog.TemplatesListBoxSelectionChange(Sender: TObject; User: boolean);
|
||||||
|
begin
|
||||||
|
UpdateButtons;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TPathEditorDialog.TemplatesListBoxDblClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
AddTemplateButtonClick(Nil);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPathEditorDialog.FormCreate(Sender: TObject);
|
procedure TPathEditorDialog.FormCreate(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
Caption:=dlgDebugOptionsPathEditorDlgCaption;
|
Caption:=dlgDebugOptionsPathEditorDlgCaption;
|
||||||
@ -257,6 +299,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPathEditorDialog.PathListBoxDrawItem(Control: TWinControl;
|
||||||
|
Index: Integer; ARect: TRect; State: TOwnerDrawState);
|
||||||
|
begin
|
||||||
|
if Index < 0 then Exit;
|
||||||
|
with PathListBox do begin
|
||||||
|
Canvas.FillRect(ARect);
|
||||||
|
if PtrInt(Items.Objects[Index]) = 0 then
|
||||||
|
Canvas.Font.Color := clGray;
|
||||||
|
Canvas.TextRect(ARect, ARect.Left, ARect.Top, Items[Index]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPathEditorDialog.PathListBoxKeyDown(Sender: TObject; var Key: Word;
|
procedure TPathEditorDialog.PathListBoxKeyDown(Sender: TObject; var Key: Word;
|
||||||
Shift: TShiftState);
|
Shift: TShiftState);
|
||||||
begin
|
begin
|
||||||
@ -269,31 +323,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPathEditorDialog.PathListBoxSelectionChange(Sender: TObject; User: boolean);
|
|
||||||
begin
|
|
||||||
if PathListBox.ItemIndex>-1 then begin
|
|
||||||
DirectoryEdit.Text:=AbsolutePathHelper;
|
|
||||||
UpdateButtons;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TPathEditorDialog.TemplatesListBoxSelectionChange(Sender: TObject; User: boolean);
|
|
||||||
begin
|
|
||||||
UpdateButtons;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TPathEditorDialog.TemplatesListBoxDblClick(Sender: TObject);
|
|
||||||
var
|
|
||||||
i: integer;
|
|
||||||
begin
|
|
||||||
i := TemplatesListBox.ItemIndex;
|
|
||||||
if i>=0 then begin
|
|
||||||
PathListBox.Items.Add(TemplatesListBox.Items[i]);
|
|
||||||
PathListBox.ItemIndex:=PathListBox.Count-1;
|
|
||||||
UpdateButtons;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TPathEditorDialog.GetPath: string;
|
function TPathEditorDialog.GetPath: string;
|
||||||
begin
|
begin
|
||||||
Result:=TextToPath(PathListBox.Items.Text);
|
Result:=TextToPath(PathListBox.Items.Text);
|
||||||
@ -305,8 +334,21 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPathEditorDialog.SetPath(const AValue: string);
|
procedure TPathEditorDialog.SetPath(const AValue: string);
|
||||||
|
var
|
||||||
|
sl: TStringList;
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
PathListBox.Items.Text:=PathToText(AValue);
|
DirectoryEdit.Text:='';
|
||||||
|
PathListBox.Items.Clear;
|
||||||
|
sl:=TstringList.Create();
|
||||||
|
try
|
||||||
|
sl.Text:=PathToText(AValue);
|
||||||
|
for i:=0 to sl.Count-1 do
|
||||||
|
PathListBox.Items.AddObject(sl[i], PathMayExist(sl[i]));
|
||||||
|
PathListBox.ItemIndex:=-1;
|
||||||
|
finally
|
||||||
|
sl.Free;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPathEditorDialog.SetTemplates(const AValue: string);
|
procedure TPathEditorDialog.SetTemplates(const AValue: string);
|
||||||
@ -376,15 +418,23 @@ end;
|
|||||||
procedure TPathEditorDialog.UpdateButtons;
|
procedure TPathEditorDialog.UpdateButtons;
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
|
InValidPathsExist: Boolean;
|
||||||
begin
|
begin
|
||||||
// Replace / add / delete / Delete Invalid Paths
|
// Replace / add / delete / Delete Invalid Paths
|
||||||
ReplaceButton.Enabled:=(DirectoryEdit.Text<>'') and (DirectoryEdit.Text<>FEffectiveBaseDirectory)
|
ReplaceButton.Enabled:=(DirectoryEdit.Text<>'') and (DirectoryEdit.Text<>FEffectiveBaseDirectory)
|
||||||
and (PathListBox.Items.IndexOf(RelativePathHelper)=-1);
|
and (PathListBox.Items.IndexOf(BaseRelative(DirectoryEdit.Text))=-1);
|
||||||
AddButton.Enabled:=ReplaceButton.Enabled;
|
AddButton.Enabled:=ReplaceButton.Enabled;
|
||||||
DeleteButton.Enabled:=PathListBox.ItemIndex>-1;
|
DeleteButton.Enabled:=PathListBox.ItemIndex>-1;
|
||||||
DeleteInvalidPathsButton.Enabled:=False;
|
|
||||||
AddTemplateButton.Enabled:=(TemplatesListBox.SelCount>1) or ((TemplatesListBox.ItemIndex>-1)
|
AddTemplateButton.Enabled:=(TemplatesListBox.SelCount>1) or ((TemplatesListBox.ItemIndex>-1)
|
||||||
and (PathListBox.Items.IndexOf(TemplatesListBox.Items[TemplatesListBox.ItemIndex])=-1));
|
and (PathListBox.Items.IndexOf(TemplatesListBox.Items[TemplatesListBox.ItemIndex])=-1));
|
||||||
|
// Delete non-existent paths button. Check if there are any.
|
||||||
|
InValidPathsExist:=False;
|
||||||
|
for i:=0 to PathListBox.Items.Count-1 do
|
||||||
|
if PtrInt(PathListBox.Items.Objects[i])=0 then begin
|
||||||
|
InValidPathsExist:=True;
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
DeleteInvalidPathsButton.Enabled:=InValidPathsExist;
|
||||||
// Move up / down buttons
|
// Move up / down buttons
|
||||||
i := PathListBox.ItemIndex;
|
i := PathListBox.ItemIndex;
|
||||||
MoveUpButton.Enabled := i > 0;
|
MoveUpButton.Enabled := i > 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user