mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 20:40:33 +02:00
New files for a new "Manage example projects" feature.
git-svn-id: trunk@32807 -
This commit is contained in:
parent
f7688f9be6
commit
d7d7637619
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -4148,6 +4148,8 @@ ide/mainbase.pas svneol=native#text/pascal
|
||||
ide/mainintf.pas svneol=native#text/pascal
|
||||
ide/makeresstrdlg.lfm svneol=native#text/plain
|
||||
ide/makeresstrdlg.pas svneol=native#text/pascal
|
||||
ide/manageexamples.lfm svneol=native#text/plain
|
||||
ide/manageexamples.pas svneol=native#text/plain
|
||||
ide/miscoptions.pas svneol=native#text/pascal
|
||||
ide/mouseactiondialog.lfm svneol=native#text/plain
|
||||
ide/mouseactiondialog.pas svneol=native#text/pascal
|
||||
|
163
ide/manageexamples.lfm
Normal file
163
ide/manageexamples.lfm
Normal file
@ -0,0 +1,163 @@
|
||||
object ManageExamplesForm: TManageExamplesForm
|
||||
Left = 389
|
||||
Height = 416
|
||||
Top = 162
|
||||
Width = 768
|
||||
Caption = 'ManageExamplesForm'
|
||||
ClientHeight = 416
|
||||
ClientWidth = 768
|
||||
Position = poDesktopCenter
|
||||
LCLVersion = '0.9.31'
|
||||
object SettingsGroupBox: TGroupBox
|
||||
Left = 0
|
||||
Height = 80
|
||||
Top = 0
|
||||
Width = 768
|
||||
Align = alTop
|
||||
Caption = 'Settings'
|
||||
ClientHeight = 63
|
||||
ClientWidth = 764
|
||||
TabOrder = 0
|
||||
object RootDirectoryEdit: TDirectoryEdit
|
||||
AnchorSideLeft.Control = RootDirectoryLabel
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = RootDirectoryLabel
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 101
|
||||
Height = 23
|
||||
Top = 9
|
||||
Width = 480
|
||||
ShowHidden = False
|
||||
ButtonWidth = 23
|
||||
NumGlyphs = 0
|
||||
BorderSpacing.Left = 7
|
||||
MaxLength = 0
|
||||
TabOrder = 0
|
||||
OnChange = RootDirectoryEditChange
|
||||
end
|
||||
object RootDirectoryLabel: TLabel
|
||||
Left = 6
|
||||
Height = 16
|
||||
Top = 12
|
||||
Width = 88
|
||||
Caption = 'Root directory'
|
||||
ParentColor = False
|
||||
end
|
||||
end
|
||||
object ProjectsGroupBox: TGroupBox
|
||||
AnchorSideLeft.Control = SettingsGroupBox
|
||||
AnchorSideTop.Control = SettingsGroupBox
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ActionGroupBox
|
||||
AnchorSideBottom.Control = ButtonPanel1
|
||||
Left = 0
|
||||
Height = 290
|
||||
Top = 80
|
||||
Width = 549
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
Caption = 'Projects'
|
||||
ClientHeight = 273
|
||||
ClientWidth = 545
|
||||
TabOrder = 1
|
||||
object ProjectsListBox: TListBox
|
||||
Left = 0
|
||||
Height = 273
|
||||
Top = 0
|
||||
Width = 545
|
||||
Align = alClient
|
||||
ItemHeight = 0
|
||||
MultiSelect = True
|
||||
OnSelectionChange = ProjectsListBoxSelectionChange
|
||||
ScrollWidth = 541
|
||||
TabOrder = 0
|
||||
TopIndex = -1
|
||||
end
|
||||
end
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 34
|
||||
Top = 376
|
||||
Width = 756
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
HelpButton.Name = 'HelpButton'
|
||||
HelpButton.DefaultCaption = True
|
||||
CloseButton.Name = 'CloseButton'
|
||||
CloseButton.DefaultCaption = True
|
||||
CancelButton.Name = 'CancelButton'
|
||||
CancelButton.DefaultCaption = True
|
||||
TabOrder = 2
|
||||
ShowButtons = [pbClose, pbHelp]
|
||||
end
|
||||
object ActionGroupBox: TGroupBox
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = SettingsGroupBox
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = SettingsGroupBox
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = ProjectsGroupBox
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 552
|
||||
Height = 290
|
||||
Top = 80
|
||||
Width = 216
|
||||
Anchors = [akTop, akRight, akBottom]
|
||||
BorderSpacing.Left = 3
|
||||
Caption = 'Action'
|
||||
ClientHeight = 273
|
||||
ClientWidth = 212
|
||||
TabOrder = 3
|
||||
object Label1: TLabel
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 66
|
||||
Height = 16
|
||||
Top = 61
|
||||
Width = 131
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Right = 7
|
||||
Caption = '(under construction)'
|
||||
ParentColor = False
|
||||
end
|
||||
object OpenSelectedButton: TBitBtn
|
||||
Left = 9
|
||||
Height = 25
|
||||
Top = 8
|
||||
Width = 195
|
||||
BorderSpacing.Top = 4
|
||||
Caption = 'Open First Selected'
|
||||
Enabled = False
|
||||
OnClick = OpenSelectedButtonClick
|
||||
TabOrder = 0
|
||||
end
|
||||
object BuildAllSelectedButton: TBitBtn
|
||||
Left = 9
|
||||
Height = 25
|
||||
Top = 36
|
||||
Width = 195
|
||||
Caption = 'Build All Selected'
|
||||
Enabled = False
|
||||
OnClick = BuildAllSelectedButtonClick
|
||||
TabOrder = 1
|
||||
end
|
||||
object SelectAllButton: TBitBtn
|
||||
Left = 9
|
||||
Height = 25
|
||||
Top = 88
|
||||
Width = 195
|
||||
Caption = 'Select All'
|
||||
OnClick = SelectAllButtonClick
|
||||
TabOrder = 2
|
||||
end
|
||||
object SelectNoneButton: TBitBtn
|
||||
Left = 9
|
||||
Height = 25
|
||||
Top = 116
|
||||
Width = 195
|
||||
Caption = 'Select None'
|
||||
Enabled = False
|
||||
OnClick = SelectNoneButtonClick
|
||||
TabOrder = 3
|
||||
end
|
||||
end
|
||||
end
|
241
ide/manageexamples.pas
Normal file
241
ide/manageexamples.pas
Normal file
@ -0,0 +1,241 @@
|
||||
unit ManageExamples;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
||||
ExtCtrls, CheckLst, ButtonPanel, PairSplitter, EditBtn, LCLProc, AvgLvlTree,
|
||||
Buttons, LazIDEIntf, MainIntf, EnvironmentOpts, LazarusIDEStrConsts;
|
||||
|
||||
type
|
||||
|
||||
{ TManageExamplesForm }
|
||||
|
||||
TManageExamplesForm = class(TForm)
|
||||
BuildAllSelectedButton: TBitBtn;
|
||||
OpenSelectedButton: TBitBtn;
|
||||
Label1: TLabel;
|
||||
ProjectsListBox: TListBox;
|
||||
SelectAllButton: TBitBtn;
|
||||
ButtonPanel1: TButtonPanel;
|
||||
RootDirectoryEdit: TDirectoryEdit;
|
||||
ActionGroupBox: TGroupBox;
|
||||
RootDirectoryLabel: TLabel;
|
||||
SelectNoneButton: TBitBtn;
|
||||
SettingsGroupBox: TGroupBox;
|
||||
ProjectsGroupBox: TGroupBox;
|
||||
procedure BuildAllSelectedButtonClick(Sender: TObject);
|
||||
procedure OpenSelectedButtonClick(Sender: TObject);
|
||||
procedure ProjectsListBoxSelectionChange(Sender: TObject; User: boolean);
|
||||
procedure RootDirectoryEditChange(Sender: TObject);
|
||||
procedure SelectAllButtonClick(Sender: TObject);
|
||||
procedure SelectNoneButtonClick(Sender: TObject);
|
||||
procedure ShowPathCheckBoxChange(Sender: TObject);
|
||||
private
|
||||
fChangingSelections: Boolean;
|
||||
fUpdating: Boolean;
|
||||
fIdleConnected: boolean;
|
||||
fSelectedFilename: string;
|
||||
procedure FillProjectList(Immediately: boolean);
|
||||
procedure SetIdleConnected(const AValue: boolean);
|
||||
procedure OnIdle(Sender: TObject; var Done: Boolean);
|
||||
public
|
||||
constructor Create(AnOwner: TComponent);
|
||||
destructor Destroy; override;
|
||||
property IdleConnected: boolean read fIdleConnected write SetIdleConnected;
|
||||
end;
|
||||
|
||||
function ShowManageExamplesDlg: TModalResult;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
function ShowManageExamplesDlg: TModalResult;
|
||||
var
|
||||
theForm: TManageExamplesForm;
|
||||
path: String;
|
||||
begin
|
||||
Result:=mrCancel;
|
||||
theForm:=TManageExamplesForm.Create(Nil);
|
||||
try
|
||||
path:=EnvironmentOptions.LazarusDirectory+'examples';
|
||||
if DirectoryExistsUTF8(path) then begin
|
||||
theForm.RootDirectoryEdit.Text:=path;
|
||||
theForm.FillProjectList(False);
|
||||
end;
|
||||
Result:=theForm.ShowModal;
|
||||
if Result=mrYes then
|
||||
MainIDEInterface.DoOpenProjectFile(theForm.fSelectedFilename,
|
||||
[ofOnlyIfExists,ofAddToRecent,ofUseCache]);
|
||||
|
||||
finally
|
||||
theForm.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
type
|
||||
|
||||
{ TListFileSearcher }
|
||||
|
||||
TListFileSearcher = class(TFileSearcher)
|
||||
private
|
||||
fForm: TManageExamplesForm;
|
||||
protected
|
||||
procedure DoFileFound; override;
|
||||
public
|
||||
constructor Create(aForm: TManageExamplesForm);
|
||||
end;
|
||||
|
||||
{ TListFileSearcher }
|
||||
|
||||
procedure TListFileSearcher.DoFileFound;
|
||||
var
|
||||
ShortName, FilePath: String;
|
||||
begin
|
||||
fForm.ProjectsListBox.Items.Add(FileName)
|
||||
end;
|
||||
|
||||
constructor TListFileSearcher.Create(aForm: TManageExamplesForm);
|
||||
begin
|
||||
fForm := aForm;
|
||||
end;
|
||||
|
||||
{ TManageExamplesForm }
|
||||
|
||||
constructor TManageExamplesForm.Create(AnOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AnOwner);
|
||||
fChangingSelections:=False;
|
||||
fUpdating:=False;
|
||||
|
||||
OpenSelectedButton.Caption:=lisExamplesOpenFirstSelected;
|
||||
BuildAllSelectedButton.Caption:=lisExamplesBuildAllSelected;
|
||||
SelectAllButton.Caption:=lisMenuSelectAll;
|
||||
SelectNoneButton.Caption:=lisSAMSelectNone;
|
||||
|
||||
OpenSelectedButton.LoadGlyphFromLazarusResource('laz_open');
|
||||
BuildAllSelectedButton.LoadGlyphFromLazarusResource('menu_build_all');
|
||||
SelectAllButton.LoadGlyphFromLazarusResource('menu_select_all');
|
||||
SelectNoneButton.LoadGlyphFromLazarusResource('ce_default');
|
||||
end;
|
||||
|
||||
destructor TManageExamplesForm.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TManageExamplesForm.FillProjectList(Immediately: boolean);
|
||||
var
|
||||
Searcher: TListFileSearcher;
|
||||
begin
|
||||
if not Immediately then begin
|
||||
IdleConnected:=true;
|
||||
exit;
|
||||
end;
|
||||
if fUpdating then Exit;
|
||||
if RootDirectoryEdit.Text<>'' then
|
||||
try
|
||||
fUpdating:=True;
|
||||
ProjectsListBox.Items.Clear;
|
||||
Searcher:=TListFileSearcher.Create(Self);
|
||||
Searcher.Search(RootDirectoryEdit.Text, '*.lpi');
|
||||
finally
|
||||
Searcher.Free;
|
||||
fUpdating:=False;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TManageExamplesForm.SetIdleConnected(const AValue: boolean);
|
||||
begin
|
||||
if fIdleConnected=AValue then exit;
|
||||
fIdleConnected:=AValue;
|
||||
if fIdleConnected then
|
||||
Application.AddOnIdleHandler(@OnIdle)
|
||||
else
|
||||
Application.RemoveOnIdleHandler(@OnIdle);
|
||||
end;
|
||||
|
||||
procedure TManageExamplesForm.OnIdle(Sender: TObject; var Done: Boolean);
|
||||
begin
|
||||
if Done then ;
|
||||
IdleConnected:=false;
|
||||
FillProjectList(true);
|
||||
end;
|
||||
|
||||
procedure TManageExamplesForm.RootDirectoryEditChange(Sender: TObject);
|
||||
begin
|
||||
FillProjectList(False);
|
||||
end;
|
||||
|
||||
procedure TManageExamplesForm.ShowPathCheckBoxChange(Sender: TObject);
|
||||
begin
|
||||
FillProjectList(False);
|
||||
end;
|
||||
|
||||
procedure TManageExamplesForm.OpenSelectedButtonClick(Sender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
for i:=0 to ProjectsListBox.Items.Count-1 do begin
|
||||
if ProjectsListBox.Selected[i] then begin
|
||||
if FileExistsUTF8(ProjectsListBox.Items[i]) then begin
|
||||
fSelectedFilename:=ProjectsListBox.Items[i];
|
||||
ModalResult:=mrYes; // mrYes means the selected file will be opened.
|
||||
Break;
|
||||
end else begin
|
||||
ShowMessage(Format(lisFileNotFound3, [ProjectsListBox.Items[i]]));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TManageExamplesForm.BuildAllSelectedButtonClick(Sender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
for i:=0 to ProjectsListBox.Items.Count-1 do begin
|
||||
if ProjectsListBox.Selected[i] then begin
|
||||
; // ToDo
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TManageExamplesForm.SelectAllButtonClick(Sender: TObject);
|
||||
begin
|
||||
fChangingSelections:=True;
|
||||
ProjectsListBox.SelectAll;
|
||||
fChangingSelections:=False;
|
||||
ProjectsListBoxSelectionChange(ProjectsListBox, False); // In the end update buttons
|
||||
end;
|
||||
|
||||
procedure TManageExamplesForm.SelectNoneButtonClick(Sender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
fChangingSelections:=True;
|
||||
for i:=0 to ProjectsListBox.Items.Count-1 do
|
||||
ProjectsListBox.Selected[i]:=False;
|
||||
fChangingSelections:=False;
|
||||
ProjectsListBoxSelectionChange(ProjectsListBox, False);
|
||||
end;
|
||||
|
||||
// Project list selection changes. Adjust buttons.
|
||||
|
||||
procedure TManageExamplesForm.ProjectsListBoxSelectionChange(Sender: TObject; User: boolean);
|
||||
var
|
||||
HasSelected: Boolean;
|
||||
begin
|
||||
if not fChangingSelections then begin
|
||||
HasSelected := ProjectsListBox.SelCount > 0;
|
||||
OpenSelectedButton.Enabled := HasSelected;
|
||||
// BuildAllSelectedButton.Enabled := HasSelected;
|
||||
SelectNoneButton.Enabled := HasSelected;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user