IDE: Simplify PathEditorDialog. Move list of templates to a separate window.

git-svn-id: trunk@56826 -
This commit is contained in:
juha 2017-12-23 12:40:22 +00:00
parent 6add3b79ed
commit 025579133c
9 changed files with 262 additions and 174 deletions

2
.gitattributes vendored
View File

@ -6830,6 +6830,8 @@ ide/genericchecklist.lfm svneol=native#text/plain
ide/genericchecklist.pas svneol=native#text/plain
ide/genericlisteditor.lfm svneol=native#text/plain
ide/genericlisteditor.pas svneol=native#text/plain
ide/genericlistselect.lfm svneol=native#text/plain
ide/genericlistselect.pas svneol=native#text/pascal
ide/gotofrm.lfm svneol=native#text/plain
ide/gotofrm.pas svneol=native#text/plain
ide/helpfpcmessages.lfm svneol=native#text/plain

View File

@ -9,11 +9,11 @@ object GenericCheckListForm: TGenericCheckListForm
ClientWidth = 343
OnShow = FormShow
Position = poScreenCenter
LCLVersion = '1.5'
LCLVersion = '1.9.0.0'
object ButtonPanel1: TButtonPanel
Left = 6
Height = 29
Top = 242
Height = 30
Top = 241
Width = 331
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
@ -36,19 +36,18 @@ object GenericCheckListForm: TGenericCheckListForm
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 6
Height = 202
Top = 29
Height = 200
Top = 31
Width = 331
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 6
ItemHeight = 0
OnItemClick = CheckListBox1ItemClick
TabOrder = 1
TopIndex = -1
end
object InfoLabel: TLabel
Left = 6
Height = 17
Height = 19
Top = 6
Width = 331
Align = alTop

View File

@ -1,4 +1,3 @@
{ ToDo: move to lazcontrols }
unit GenericCheckList;
{$mode objfpc}{$H+}
@ -6,8 +5,10 @@ unit GenericCheckList;
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ButtonPanel,
CheckLst, Buttons, IDEImagesIntf, StdCtrls;
Classes, SysUtils,
Forms, Controls, StdCtrls, Dialogs, ButtonPanel, CheckLst, Buttons,
// IdeIntf
IDEImagesIntf;
type

View File

@ -7,11 +7,11 @@ object GenericListEditForm: TGenericListEditForm
ClientHeight = 301
ClientWidth = 343
Position = poScreenCenter
LCLVersion = '1.1'
LCLVersion = '1.9.0.0'
object ButtonPanel1: TButtonPanel
Left = 6
Height = 33
Top = 262
Height = 30
Top = 265
Width = 331
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
@ -29,7 +29,7 @@ object GenericListEditForm: TGenericListEditForm
end
object Memo1: TMemo
Left = 0
Height = 256
Height = 259
Top = 0
Width = 343
Align = alClient

View File

@ -5,8 +5,7 @@ unit GenericListEditor;
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ButtonPanel,
StdCtrls;
Forms, StdCtrls, ButtonPanel;
type

59
ide/genericlistselect.lfm Normal file
View File

@ -0,0 +1,59 @@
object GenericListSelectForm: TGenericListSelectForm
Left = 389
Height = 277
Top = 463
Width = 466
Caption = 'GenericCheckListForm'
ClientHeight = 277
ClientWidth = 466
OnShow = FormShow
Position = poScreenCenter
LCLVersion = '1.9.0.0'
object ButtonPanel1: TButtonPanel
Left = 6
Height = 30
Top = 241
Width = 454
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton'
HelpButton.DefaultCaption = True
HelpButton.Enabled = False
CloseButton.Name = 'CloseButton'
CloseButton.DefaultCaption = True
CloseButton.Enabled = False
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 0
ShowButtons = [pbOK, pbCancel]
ShowBevel = False
end
object InfoLabel: TLabel
Left = 6
Height = 19
Top = 6
Width = 454
Align = alTop
BorderSpacing.Around = 6
Caption = 'InfoLabel'
ParentColor = False
WordWrap = True
end
object ListBox: TListBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = InfoLabel
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 6
Height = 200
Top = 31
Width = 454
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 6
ItemHeight = 0
OnClick = ListBoxClick
OnDblClick = ListBoxDblClick
TabOrder = 1
end
end

72
ide/genericlistselect.pas Normal file
View File

@ -0,0 +1,72 @@
unit GenericListSelect;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
Controls, Forms, StdCtrls, Dialogs, ButtonPanel;
type
{ TGenericListSelectForm }
TGenericListSelectForm = class(TForm)
ButtonPanel1: TButtonPanel;
ListBox: TListBox;
InfoLabel: TLabel;
procedure FormShow(Sender: TObject);
procedure ListBoxClick(Sender: TObject);
procedure ListBoxDblClick(Sender: TObject);
private
procedure UpdateButtons;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;
var
GenericListSelectForm: TGenericListSelectForm;
implementation
{$R *.lfm}
{ TGenericListSelectForm }
constructor TGenericListSelectForm.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
InfoLabel.Caption := '';
end;
destructor TGenericListSelectForm.Destroy;
begin
inherited Destroy;
end;
procedure TGenericListSelectForm.FormShow(Sender: TObject);
begin
UpdateButtons;
end;
procedure TGenericListSelectForm.ListBoxClick(Sender: TObject);
begin
UpdateButtons;
end;
procedure TGenericListSelectForm.ListBoxDblClick(Sender: TObject);
begin
UpdateButtons;
ModalResult:=mrOK;
end;
procedure TGenericListSelectForm.UpdateButtons;
begin
ButtonPanel1.OKButton.Enabled := ListBox.ItemIndex >= 0;
//ListBox.Selected[1];
end;
end.

View File

@ -10,23 +10,21 @@ object PathEditorDialog: TPathEditorDialog
Constraints.MinHeight = 400
Constraints.MinWidth = 500
OnCreate = FormCreate
OnDestroy = FormDestroy
OnResize = FormResize
OnShow = FormShow
Position = poScreenCenter
LCLVersion = '1.9.0.0'
object PathGroupBox: TGroupBox
AnchorSideBottom.Control = AddTemplateButton
Left = 6
Height = 237
Height = 366
Top = 6
Width = 558
Align = alClient
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Left = 6
BorderSpacing.Top = 6
BorderSpacing.Right = 6
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 6
Caption = 'PathGroupBox'
ClientHeight = 219
ClientHeight = 335
ClientWidth = 554
Constraints.MinHeight = 194
Constraints.MinWidth = 488
@ -36,10 +34,10 @@ object PathEditorDialog: TPathEditorDialog
AnchorSideLeft.Side = asrBottom
AnchorSideBottom.Control = PathGroupBox
AnchorSideBottom.Side = asrBottom
Left = 191
Height = 23
Top = 190
Width = 89
Left = 210
Height = 30
Top = 299
Width = 100
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Around = 6
@ -56,7 +54,7 @@ object PathEditorDialog: TPathEditorDialog
AnchorSideRight.Control = MoveUpButton
AnchorSideBottom.Control = DirectoryEdit
Left = 6
Height = 151
Height = 248
Top = 6
Width = 511
Anchors = [akTop, akLeft, akRight, akBottom]
@ -69,7 +67,6 @@ object PathEditorDialog: TPathEditorDialog
OnKeyDown = PathListBoxKeyDown
OnSelectionChange = PathListBoxSelectionChange
PopupMenu = PopupMenu1
ScrollWidth = 492
Style = lbOwnerDrawFixed
TabOrder = 0
end
@ -78,9 +75,9 @@ object PathEditorDialog: TPathEditorDialog
AnchorSideBottom.Control = PathGroupBox
AnchorSideBottom.Side = asrBottom
Left = 6
Height = 23
Top = 190
Width = 96
Height = 30
Top = 299
Width = 108
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Around = 6
@ -96,10 +93,10 @@ object PathEditorDialog: TPathEditorDialog
AnchorSideLeft.Side = asrBottom
AnchorSideBottom.Control = PathGroupBox
AnchorSideBottom.Side = asrBottom
Left = 108
Height = 23
Top = 190
Width = 77
Left = 120
Height = 30
Top = 299
Width = 84
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Around = 6
@ -115,10 +112,10 @@ object PathEditorDialog: TPathEditorDialog
AnchorSideLeft.Side = asrBottom
AnchorSideBottom.Control = PathGroupBox
AnchorSideBottom.Side = asrBottom
Left = 286
Height = 23
Top = 190
Width = 148
Left = 316
Height = 30
Top = 299
Width = 179
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Around = 6
@ -135,8 +132,8 @@ object PathEditorDialog: TPathEditorDialog
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ReplaceButton
Left = 6
Height = 21
Top = 163
Height = 33
Top = 260
Width = 511
OnAcceptDirectory = DirectoryEditAcceptDirectory
ShowHidden = False
@ -155,7 +152,7 @@ object PathEditorDialog: TPathEditorDialog
AnchorSideBottom.Side = asrBottom
Left = 523
Height = 25
Top = 49
Top = 81
Width = 25
Anchors = [akRight]
BorderSpacing.Around = 6
@ -172,7 +169,7 @@ object PathEditorDialog: TPathEditorDialog
AnchorSideBottom.Side = asrBottom
Left = 523
Height = 25
Top = 83
Top = 115
Width = 25
Anchors = [akTop, akRight]
BorderSpacing.Top = 9
@ -181,62 +178,10 @@ object PathEditorDialog: TPathEditorDialog
ParentShowHint = False
end
end
object TemplateGroupBox: TGroupBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 164
Top = 248
Width = 558
Align = alBottom
Anchors = []
BorderSpacing.Left = 6
BorderSpacing.Right = 6
BorderSpacing.Bottom = 6
Caption = 'TemplateGroupBox'
ClientHeight = 146
ClientWidth = 554
TabOrder = 1
object TemplatesListBox: TListBox
AnchorSideLeft.Control = TemplateGroupBox
AnchorSideTop.Control = TemplateGroupBox
AnchorSideRight.Control = TemplateGroupBox
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = AddTemplateButton
Left = 6
Height = 105
Top = 6
Width = 542
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Around = 6
ItemHeight = 0
MultiSelect = True
OnDblClick = TemplatesListBoxDblClick
OnSelectionChange = TemplatesListBoxSelectionChange
ScrollWidth = 523
TabOrder = 0
end
object AddTemplateButton: TBitBtn
AnchorSideLeft.Control = TemplateGroupBox
AnchorSideBottom.Control = TemplateGroupBox
AnchorSideBottom.Side = asrBottom
Left = 6
Height = 23
Top = 117
Width = 121
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Around = 6
Caption = 'AddTemplateButton'
OnClick = AddTemplateButtonClick
ParentShowHint = False
ShowHint = True
TabOrder = 1
end
end
object ButtonPanel1: TButtonPanel
Left = 6
Height = 26
Top = 418
Height = 30
Top = 414
Width = 558
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
@ -246,27 +191,33 @@ object PathEditorDialog: TPathEditorDialog
CloseButton.DefaultCaption = True
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 2
TabOrder = 1
ShowButtons = [pbOK, pbCancel]
ShowBevel = False
end
object Splitter1: TSplitter
Cursor = crVSplit
Left = 0
Height = 5
Top = 243
Width = 570
Align = alBottom
ResizeAnchor = akBottom
object AddTemplateButton: TBitBtn
AnchorSideBottom.Control = ButtonPanel1
Left = 16
Height = 30
Top = 378
Width = 142
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Around = 6
Caption = 'AddTemplateButton'
OnClick = AddTemplateButtonClick
ParentShowHint = False
ShowHint = True
TabOrder = 2
end
object BrowseDialog: TSelectDirectoryDialog
Options = [ofFileMustExist, ofEnableSizing, ofViewDetail]
left = 350
top = 50
Left = 350
Top = 50
end
object PopupMenu1: TPopupMenu
left = 130
top = 100
Left = 130
Top = 100
object CopyMenuItem: TMenuItem
Caption = 'Copy All'
OnClick = CopyMenuItemClick
@ -288,11 +239,11 @@ object PathEditorDialog: TPathEditorDialog
end
end
object OpenDialog1: TOpenDialog
left = 240
top = 100
Left = 240
Top = 100
end
object SaveDialog1: TSaveDialog
left = 350
top = 100
Left = 350
Top = 100
end
end

View File

@ -21,9 +21,18 @@ unit PathEditorDlg;
interface
uses
Classes, SysUtils, types, Forms, Controls, Buttons, StdCtrls, Dialogs, Graphics,
Menus, ButtonPanel, ExtCtrls, FileUtil, LazFileUtils, MacroIntf, IDEImagesIntf,
LCLType, TransferMacros, LazarusIDEStrConsts, ShortPathEdit, Clipbrd, LCLProc;
Classes, SysUtils, types,
// LCL
LCLType, LCLProc, Forms, Controls, Buttons, StdCtrls, Dialogs, Menus, Graphics,
ButtonPanel, Clipbrd,
// LazUtils
FileUtil, LazFileUtils,
// LazControls
ShortPathEdit,
// IdeIntf
MacroIntf, IDEImagesIntf,
// IDE
TransferMacros, GenericListSelect, LazarusIDEStrConsts;
type
@ -46,17 +55,15 @@ type
AddButton: TBitBtn;
DeleteInvalidPathsButton: TBitBtn;
DirectoryEdit: TShortPathEdit;
Splitter1: TSplitter;
DeleteButton: TBitBtn;
PathListBox: TListBox;
TemplatesListBox: TListBox;
TemplateGroupBox: TGroupBox;
PathGroupBox: TGroupBox;
BrowseDialog: TSelectDirectoryDialog;
procedure AddButtonClick(Sender: TObject);
procedure AddTemplateButtonClick(Sender: TObject);
procedure CopyMenuItemClick(Sender: TObject);
procedure ExportMenuItemClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PasteMenuItemClick(Sender: TObject);
procedure DeleteInvalidPathsButtonClick(Sender: TObject);
procedure DeleteButtonClick(Sender: TObject);
@ -79,6 +86,8 @@ type
private
FBaseDirectory: string;
FEffectiveBaseDirectory: string;
FTemplateList: TStringList;
procedure AddPath(aPath: String; aObject: TObject);
function GetPath: string;
function GetTemplates: string;
function BaseRelative(const APath: string): String;
@ -231,20 +240,21 @@ begin
Result:=TObject(1);
end;
procedure TPathEditorDialog.AddButtonClick(Sender: TObject);
procedure TPathEditorDialog.AddPath(aPath: String; aObject: TObject);
var
y: integer;
RelPath: String;
begin
with PathListBox do begin
y:=ItemIndex+1;
if y=0 then
y:=Count;
RelPath:=BaseRelative(DirectoryEdit.Text);
Items.InsertObject(y, RelPath, PathMayExist(DirectoryEdit.Text));
ItemIndex:=y;
UpdateButtons;
end;
y:=PathListBox.ItemIndex+1;
if y=0 then
y:=PathListBox.Count;
PathListBox.Items.InsertObject(y, aPath, aObject);
PathListBox.ItemIndex:=y;
UpdateButtons;
end;
procedure TPathEditorDialog.AddButtonClick(Sender: TObject);
begin
AddPath(BaseRelative(DirectoryEdit.Text), PathMayExist(DirectoryEdit.Text));
end;
procedure TPathEditorDialog.ReplaceButtonClick(Sender: TObject);
@ -286,19 +296,20 @@ end;
procedure TPathEditorDialog.AddTemplateButtonClick(Sender: TObject);
var
i, y: integer;
TemplateForm: TGenericListSelectForm;
i: Integer;
begin
y:=-1;
for i:=0 to TemplatesListBox.Items.Count-1 do begin
if TemplatesListBox.Selected[i]
and (PathListBox.Items.IndexOf(TemplatesListBox.Items[i])=-1) then begin
PathListBox.Items.AddObject(TemplatesListBox.Items[i], TObject(1));
y:=PathListBox.Count-1;
end;
end;
if y>=1 then begin
PathListBox.ItemIndex:=y;
UpdateButtons;
TemplateForm := TGenericListSelectForm.Create(Nil);
try
// Let a user select only templates which are not in the list already.
for i := 0 to FTemplateList.Count-1 do
if PathListBox.Items.IndexOf(FTemplateList[i]) = -1 then
TemplateForm.ListBox.Items.Add(FTemplateList[i]);
if TemplateForm.ShowModal = mrOK then
with TemplateForm.ListBox do
AddPath(Items[ItemIndex], TObject(1));
finally
TemplateForm.Free;
end;
end;
@ -356,7 +367,6 @@ begin
PathListBox.Items.InsertObject(y, BaseRelative(s), PathMayExist(s));
end;
end;
//PathListBox.ItemIndex := y;
UpdateButtons;
end;
@ -420,12 +430,11 @@ procedure TPathEditorDialog.FormCreate(Sender: TObject);
const
Filt = 'Text file (*.txt)|*.txt|All files (*)|*';
begin
FTemplateList := TStringList.Create;
Caption:=dlgDebugOptionsPathEditorDlgCaption;
PathGroupBox.Caption:=lisPathEditSearchPaths;
MoveUpButton.Hint:=lisPathEditMovePathUp;
MoveDownButton.Hint:=lisPathEditMovePathDown;
ReplaceButton.Caption:=lisReplace;
ReplaceButton.Hint:=lisPathEditorReplaceHint;
AddButton.Caption:=lisAdd;
@ -434,8 +443,6 @@ begin
DeleteButton.Hint:=lisPathEditorDeleteHint;
DeleteInvalidPathsButton.Caption:=lisPathEditDeleteInvalidPaths;
DeleteInvalidPathsButton.Hint:=lisPathEditorDeleteInvalidHint;
TemplateGroupBox.Caption:=lisPathEditPathTemplates;
AddTemplateButton.Caption:=lisCodeTemplAdd;
AddTemplateButton.Hint:=lisPathEditorTemplAddHint;
@ -461,6 +468,17 @@ begin
TIDEImages.AssignImage(AddTemplateButton.Glyph, 'laz_add');
end;
procedure TPathEditorDialog.FormDestroy(Sender: TObject);
begin
FTemplateList.Free;
end;
procedure TPathEditorDialog.FormShow(Sender: TObject);
begin
PathListBox.ItemIndex:=-1;
UpdateButtons;
end;
procedure TPathEditorDialog.FormResize(Sender: TObject);
var
PathGroupBoxHeight: integer;
@ -471,13 +489,6 @@ begin
PathGroupBox.Height:=PathGroupBoxHeight;
end;
procedure TPathEditorDialog.FormShow(Sender: TObject);
begin
PathListBox.ItemIndex:=-1;
TemplatesListBox.ItemIndex:=-1;
UpdateButtons;
end;
procedure TPathEditorDialog.MoveDownButtonClick(Sender: TObject);
var
y: integer;
@ -531,11 +542,6 @@ begin
Result:=TextToPath(PathListBox.Items.Text);
end;
function TPathEditorDialog.GetTemplates: string;
begin
Result:=TextToPath(TemplatesListBox.Items.Text);
end;
procedure TPathEditorDialog.SetPath(const AValue: string);
var
sl: TStringList;
@ -554,16 +560,17 @@ begin
end;
end;
procedure TPathEditorDialog.SetTemplates(const AValue: string);
var
NewVis: Boolean;
function TPathEditorDialog.GetTemplates: string;
begin
TemplatesListBox.Items.Text := PathToText(AValue);
NewVis := TemplatesListBox.Count > 0;
if NewVis = TemplateGroupBox.Visible then Exit;
TemplateGroupBox.Visible := NewVis;
if NewVis then
TemplateGroupBox.Top:=0;
raise Exception.Create('TPathEditorDialog.GetTemplates is called.');
//Result := TextToPath(FTemplateList.Text);
end;
procedure TPathEditorDialog.SetTemplates(const AValue: string);
begin
// ToDo: Split the path directly to StringList without Text property.
FTemplateList.Text := PathToText(GetForcedPathDelims(AValue));
AddTemplateButton.Enabled := FTemplateList.Count > 0;
end;
procedure TPathEditorDialog.UpdateButtons;
@ -576,8 +583,6 @@ begin
and (PathListBox.Items.IndexOf(BaseRelative(DirectoryEdit.Text))=-1);
ReplaceButton.Enabled:=AddButton.Enabled and (PathListBox.ItemIndex>-1) ;
DeleteButton.Enabled:=PathListBox.SelCount=1; // or ItemIndex>-1; ?
AddTemplateButton.Enabled:=(TemplatesListBox.SelCount>1) or ((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
@ -608,7 +613,7 @@ begin
FCurrentPathEditor:=PathEditorDialog;
try
inherited Click;
FCurrentPathEditor.Templates := GetForcedPathDelims(FTemplates);
FCurrentPathEditor.Templates := FTemplates;
FCurrentPathEditor.Path := AssociatedEdit.Text;
FCurrentPathEditor.ShowModal;
DoOnPathEditorExecuted;