IDE: Improve ManageExamples dialog. Get list of dirs dynamically. Show README.txt.

git-svn-id: trunk@32956 -
This commit is contained in:
juha 2011-10-18 11:27:17 +00:00
parent 61a8bcf484
commit a9fc743264
3 changed files with 321 additions and 131 deletions

View File

@ -420,7 +420,9 @@ resourcestring
lisMenuBuildLazarusProf = 'Build Lazarus with profile: %s';
lisMenuConfigureBuildLazarus = 'Configure "Build Lazarus" ...';
lisRootDirectoryForProjects = 'Root directory for projects';
lisSearchProjectsFrom = 'Search projects from';
lisIncludeExamples = 'Include Examples';
lisIncludeTestcases = 'Include Testcases';
lisMenuGeneralOptions = 'Options ...';
lisMenuEditCodeTemplates = 'Code Templates ...';
lisMenuCodeToolsDefinesEditor = 'CodeTools defines editor ...';
@ -2837,6 +2839,7 @@ resourcestring
lisConfirmBuildAllProfiles = 'Lazarus will be rebuilt with the following profiles:%sContinue?';
lisNoBuildProfilesSelected = 'No profiles are selected to be built.';
lisCleanLazarusSource = 'Clean Lazarus Source';
lisLazarusSource = 'Lazarus Source';
lisMakeNotFound = 'Make not found';
lisTheProgramMakeWasNotFoundThisToolIsNeededToBuildLa = 'The program %smake%'
+'s was not found.%sThis tool is needed to build lazarus.%s';

View File

@ -1,48 +1,82 @@
object ManageExamplesForm: TManageExamplesForm
Left = 378
Height = 416
Top = 161
Width = 790
Left = 326
Height = 490
Top = 102
Width = 798
Caption = 'ManageExamplesForm'
ClientHeight = 416
ClientWidth = 790
ClientHeight = 490
ClientWidth = 798
Position = poDesktopCenter
LCLVersion = '0.9.31'
object ProjectsGroupBox: TGroupBox
AnchorSideLeft.Control = RootRadioGroup
AnchorSideTop.Control = RootDirectoryEdit
AnchorSideTop.Control = RootRadioGroup
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ActionGroupBox
AnchorSideBottom.Control = ButtonPanel1
Left = 1
Height = 227
Top = 143
Width = 564
Height = 351
Top = 93
Width = 444
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 13
BorderSpacing.Top = 5
Caption = 'Projects'
ClientHeight = 210
ClientWidth = 560
ClientHeight = 334
ClientWidth = 440
TabOrder = 0
object ProjectsListBox: TListBox
AnchorSideLeft.Control = ProjectsGroupBox
AnchorSideTop.Control = ProjectFilter
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ProjectsGroupBox
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ProjectsGroupBox
AnchorSideBottom.Side = asrBottom
Left = 0
Height = 210
Top = 0
Width = 560
Align = alClient
Height = 305
Top = 29
Width = 440
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 5
ItemHeight = 0
MultiSelect = True
OnSelectionChange = ProjectsListBoxSelectionChange
ScrollWidth = 556
ScrollWidth = 436
TabOrder = 0
TopIndex = -1
end
object ProjectFilter: TListFilterEdit
AnchorSideLeft.Control = ProjectsListBox
Left = 0
Height = 23
Top = 1
Width = 197
ButtonWidth = 23
NumGlyphs = 0
MaxLength = 0
TabOrder = 1
FilteredListbox = ProjectsListBox
end
object RelativeCheckBox: TCheckBox
AnchorSideLeft.Control = ProjectFilter
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ProjectFilter
AnchorSideTop.Side = asrCenter
Left = 270
Height = 26
Top = -1
Width = 116
BorderSpacing.Left = 73
Caption = 'Relative paths'
OnClick = RelativeCheckBoxClick
TabOrder = 2
Visible = False
end
end
object ButtonPanel1: TButtonPanel
Left = 6
Height = 34
Top = 376
Width = 778
Top = 450
Width = 786
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton'
@ -57,26 +91,27 @@ object ManageExamplesForm: TManageExamplesForm
object ActionGroupBox: TGroupBox
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ProjectsGroupBox
AnchorSideRight.Control = RootRadioGroup
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ProjectsGroupBox
AnchorSideBottom.Side = asrBottom
Left = 568
Height = 227
Top = 143
Width = 216
Left = 448
Height = 351
Top = 93
Width = 344
Anchors = [akTop, akRight, akBottom]
BorderSpacing.Left = 3
Caption = 'Action'
ClientHeight = 210
ClientWidth = 212
ClientHeight = 334
ClientWidth = 340
TabOrder = 2
object Label1: TLabel
AnchorSideTop.Control = BuildAllSelectedButton
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = BuildAllSelectedButton
AnchorSideRight.Side = asrBottom
Left = 66
Left = 195
Height = 16
Top = 61
Top = 55
Width = 131
Anchors = [akTop, akRight]
BorderSpacing.Right = 7
@ -84,55 +119,119 @@ object ManageExamplesForm: TManageExamplesForm
ParentColor = False
end
object OpenSelectedButton: TBitBtn
Left = 9
AnchorSideLeft.Control = ActionGroupBox
AnchorSideTop.Control = ActionGroupBox
AnchorSideRight.Control = ActionGroupBox
AnchorSideRight.Side = asrBottom
Left = 7
Height = 25
Top = 8
Width = 195
BorderSpacing.Top = 4
Top = 2
Width = 326
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 7
BorderSpacing.Top = 2
BorderSpacing.Right = 7
Caption = 'Open First Selected'
Enabled = False
OnClick = OpenSelectedButtonClick
TabOrder = 0
end
object BuildAllSelectedButton: TBitBtn
Left = 9
AnchorSideLeft.Control = OpenSelectedButton
AnchorSideTop.Control = OpenSelectedButton
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = OpenSelectedButton
AnchorSideRight.Side = asrBottom
Left = 7
Height = 25
Top = 36
Width = 195
Top = 30
Width = 326
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 3
Caption = 'Build All Selected'
Enabled = False
OnClick = BuildAllSelectedButtonClick
TabOrder = 1
end
object SelectAllButton: TBitBtn
Left = 9
AnchorSideLeft.Control = OpenSelectedButton
AnchorSideTop.Control = BuildAllSelectedButton
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = OpenSelectedButton
AnchorSideRight.Side = asrBottom
Left = 7
Height = 25
Top = 88
Width = 195
Top = 72
Width = 326
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 17
Caption = 'Select All'
OnClick = SelectAllButtonClick
TabOrder = 2
end
object SelectNoneButton: TBitBtn
Left = 9
AnchorSideLeft.Control = OpenSelectedButton
AnchorSideTop.Control = SelectAllButton
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = OpenSelectedButton
AnchorSideRight.Side = asrBottom
Left = 7
Height = 25
Top = 116
Width = 195
Top = 100
Width = 326
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 3
Caption = 'Select None'
Enabled = False
OnClick = SelectNoneButtonClick
TabOrder = 3
end
object DescriptionMemo: TMemo
AnchorSideLeft.Control = ActionGroupBox
AnchorSideTop.Control = SelectNoneButton
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ActionGroupBox
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ActionGroupBox
AnchorSideBottom.Side = asrBottom
Left = 2
Height = 202
Top = 130
Width = 336
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 3
BorderSpacing.Around = 2
ScrollBars = ssAutoBoth
TabOrder = 4
end
end
object RootDirectoryEdit: TDirectoryEdit
AnchorSideLeft.Control = DirectoryComboBox
AnchorSideTop.Control = DirectoryComboBox
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 269
Height = 23
Top = 65
Width = 488
ShowHidden = False
ButtonWidth = 23
NumGlyphs = 0
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 3
MaxLength = 0
TabOrder = 3
OnChange = RootDirectoryEditChange
end
object RootRadioGroup: TRadioGroup
Left = 1
Height = 97
Top = 5
Width = 783
Height = 86
Top = 2
Width = 263
Anchors = [akTop, akLeft, akRight]
AutoFill = True
BorderSpacing.Top = 5
Caption = 'Root directory for projects'
Caption = 'Search projects from'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
@ -140,28 +239,54 @@ object ManageExamplesForm: TManageExamplesForm
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 2
Columns = 2
ChildSizing.ControlsPerLine = 1
OnClick = RootRadioGroupClick
TabOrder = 3
TabOrder = 4
end
object RootDirectoryEdit: TDirectoryEdit
object DirectoryComboBox: TComboBox
AnchorSideLeft.Control = RootRadioGroup
AnchorSideTop.Control = RootRadioGroup
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ExamplesCheckBox
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 4
Left = 269
Height = 23
Top = 107
Width = 743
ShowHidden = False
ButtonWidth = 23
NumGlyphs = 0
Top = 39
Width = 488
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 3
BorderSpacing.Top = 5
MaxLength = 0
TabOrder = 4
OnChange = RootDirectoryEditChange
BorderSpacing.Left = 5
BorderSpacing.Top = 3
ItemHeight = 0
OnChange = DirectoryComboBoxChange
TabOrder = 5
end
object ExamplesCheckBox: TCheckBox
AnchorSideLeft.Control = DirectoryComboBox
AnchorSideTop.Side = asrBottom
Left = 269
Height = 26
Top = 10
Width = 136
Anchors = [akLeft]
BorderSpacing.Top = 3
Caption = 'Include Examples'
Checked = True
OnChange = ExamplesCheckBoxChange
State = cbChecked
TabOrder = 6
end
object TestCaseCheckBox: TCheckBox
AnchorSideLeft.Control = ExamplesCheckBox
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ExamplesCheckBox
AnchorSideTop.Side = asrCenter
Left = 438
Height = 26
Top = 10
Width = 139
BorderSpacing.Left = 33
Caption = 'Include Testcases'
OnChange = ExamplesCheckBoxChange
TabOrder = 7
end
end

View File

@ -1,13 +1,14 @@
unit ManageExamples;
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;
Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls, Graphics,
Dialogs, StdCtrls, ExtCtrls, ButtonPanel, //FileUtil,
LCLProc, Buttons, EditBtn, LazIDEIntf, MainIntf, EnvironmentOpts, //AvgLvlTree,
LazarusIDEStrConsts;
type
@ -15,6 +16,12 @@ type
TManageExamplesForm = class(TForm)
BuildAllSelectedButton: TBitBtn;
RelativeCheckBox: TCheckBox;
DescriptionMemo: TMemo;
TestCaseCheckBox: TCheckBox;
ExamplesCheckBox: TCheckBox;
DirectoryComboBox: TComboBox;
ProjectFilter: TListFilterEdit;
OpenSelectedButton: TBitBtn;
Label1: TLabel;
ProjectsListBox: TListBox;
@ -28,18 +35,23 @@ type
procedure BuildAllSelectedButtonClick(Sender: TObject);
procedure OpenSelectedButtonClick(Sender: TObject);
procedure ProjectsListBoxSelectionChange(Sender: TObject; User: boolean);
procedure RootDirectoryEditChange(Sender: TObject);
procedure RelativeCheckBoxClick(Sender: TObject);
procedure RootRadioGroupClick(Sender: TObject);
procedure DirectoryComboBoxChange(Sender: TObject);
procedure RootDirectoryEditChange(Sender: TObject);
procedure SelectAllButtonClick(Sender: TObject);
procedure SelectNoneButtonClick(Sender: TObject);
procedure ShowPathCheckBoxChange(Sender: TObject);
procedure ExamplesCheckBoxChange(Sender: TObject);
private
fOtherPathIndex: Integer;
fSelectedFilename: string;
fFirstSelectedIndex: Integer;
fChangingSelections: Boolean;
fNeedsFindDirectories: Boolean;
fNeedsFindProjects: Boolean;
fUpdating: Boolean;
fIdleConnected: boolean;
procedure FillProjectList(Immediately: boolean);
procedure FillDirectoriesBending;
procedure FillProjectsBending;
procedure SetIdleConnected(const AValue: boolean);
procedure OnIdle(Sender: TObject; var Done: Boolean);
public
@ -89,7 +101,7 @@ type
procedure TListFileSearcher.DoFileFound;
begin
fForm.ProjectsListBox.Items.Add(FileName)
fForm.ProjectFilter.Data.Add(FileName) // fForm.ProjectsListBox.Items.Add(FileName)
end;
constructor TListFileSearcher.Create(aForm: TManageExamplesForm);
@ -104,27 +116,23 @@ var
path: String;
begin
inherited Create(AnOwner);
fFirstSelectedIndex:=-1;
fChangingSelections:=False;
fUpdating:=False;
fNeedsFindDirectories:=False;
fNeedsFindProjects:=False;
Caption:=lisKMExampleProjects;
RootRadioGroup.Caption:=lisRootDirectoryForProjects;
ExamplesCheckBox.Caption:=lisIncludeExamples;
TestCaseCheckBox.Caption:=lisIncludeTestcases;
// Add some paths for example projects
RootRadioGroup.Items.Add(EnvironmentOptions.LazarusDirectory); // Lazarus root
path:=EnvironmentOptions.LazarusDirectory+'examples';
if DirectoryExistsUTF8(path) then // Select this one
RootRadioGroup.ItemIndex:=RootRadioGroup.Items.Add(path);
path:=EnvironmentOptions.LazarusDirectory+'components/codetools/examples/';
if DirectoryExistsUTF8(path) then
RootRadioGroup.Items.Add(path);
fOtherPathIndex:=RootRadioGroup.Items.Add('Other');
RootDirectoryEdit.Text:=RootRadioGroup.Items[RootRadioGroup.ItemIndex];
FillProjectList(False);
RootRadioGroup.Caption:=lisSearchProjectsFrom;
RootRadioGroup.Items.Add(lisLazarusSource);
RootRadioGroup.Items.Add(dlgCOOther); // could use lisCEOtherGroup
RootRadioGroup.ItemIndex:=0;
RootRadioGroupClick(RootRadioGroup);
RelativeCheckBox.Caption:=lisRelativePaths;
OpenSelectedButton.Caption:=lisExamplesOpenFirstSelected;
BuildAllSelectedButton.Caption:=lisExamplesBuildAllSelected;
SelectAllButton.Caption:=lisMenuSelectAll;
@ -134,6 +142,9 @@ begin
BuildAllSelectedButton.LoadGlyphFromLazarusResource('menu_build_all');
SelectAllButton.LoadGlyphFromLazarusResource('menu_select_all');
SelectNoneButton.LoadGlyphFromLazarusResource('ce_default');
FillDirectoriesBending;
FillProjectsBending;
end;
destructor TManageExamplesForm.Destroy;
@ -141,25 +152,16 @@ begin
inherited Destroy;
end;
procedure TManageExamplesForm.FillProjectList(Immediately: boolean);
var
Searcher: TListFileSearcher;
procedure TManageExamplesForm.FillDirectoriesBending;
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;
fNeedsFindDirectories:=True;
IdleConnected:=True;
end;
procedure TManageExamplesForm.FillProjectsBending;
begin
fNeedsFindProjects:=True;
IdleConnected:=True;
end;
procedure TManageExamplesForm.SetIdleConnected(const AValue: boolean);
@ -173,44 +175,82 @@ begin
end;
procedure TManageExamplesForm.OnIdle(Sender: TObject; var Done: Boolean);
var
Searcher: TListFileSearcher;
AllDirs: TStringList;
i: Integer;
LastDir: String;
begin
IdleConnected:=false;
FillProjectList(true);
end;
procedure TManageExamplesForm.RootDirectoryEditChange(Sender: TObject);
begin
FillProjectList(False);
if fUpdating then Exit;
fUpdating:=True;
if fNeedsFindDirectories then begin
DirectoryComboBox.Items.Clear;
DirectoryComboBox.Text:='';
RootDirectoryEdit.Text:='';
AllDirs:=FindAllDirectories(EnvironmentOptions.LazarusDirectory);
try
for i:=0 to AllDirs.Count-1 do begin
LastDir:=ExtractFileName(AllDirs[i]);
if (ExamplesCheckBox.Checked and (LastDir='examples'))
or (TestCaseCheckBox.Checked and (LastDir='tests')) then
DirectoryComboBox.Items.Add(AllDirs[i]);
end;
// Add something to combobox to prevent crash with GTK2.
if DirectoryComboBox.Items.Count = 0 then
DirectoryComboBox.Items.Add('[empty]');
DirectoryComboBox.ItemIndex:=0;
DirectoryComboBoxChange(DirectoryComboBox);
finally
AllDirs.Free;
fNeedsFindDirectories:=False;
end;
end;
if fNeedsFindProjects and (RootDirectoryEdit.Text<>'') then
try
ProjectFilter.Data.Clear; // ProjectsListBox.Items.Clear;
Searcher:=TListFileSearcher.Create(Self);
Searcher.Search(RootDirectoryEdit.Text, '*.lpi');
ProjectFilter.InvalidateFilter;
finally
Searcher.Free;
fNeedsFindProjects:=False;
end;
fUpdating:=False;
end;
procedure TManageExamplesForm.RootRadioGroupClick(Sender: TObject);
begin
if RootRadioGroup.ItemIndex=fOtherPathIndex then
RootDirectoryEdit.Enabled:=True
else begin
RootDirectoryEdit.Enabled:=False;
RootDirectoryEdit.Text:=RootRadioGroup.Items[RootRadioGroup.ItemIndex];
DirectoryComboBox.Enabled:=RootRadioGroup.ItemIndex=0;
RootDirectoryEdit.Enabled:=RootRadioGroup.ItemIndex=1;
end;
procedure TManageExamplesForm.DirectoryComboBoxChange(Sender: TObject);
begin
if DirectoryExists(DirectoryComboBox.Text) then begin
RootDirectoryEdit.Text:=DirectoryComboBox.Text;
FillProjectsBending;
end;
end;
procedure TManageExamplesForm.ShowPathCheckBoxChange(Sender: TObject);
procedure TManageExamplesForm.RootDirectoryEditChange(Sender: TObject);
begin
FillProjectList(False);
FillProjectsBending;
end;
procedure TManageExamplesForm.ExamplesCheckBoxChange(Sender: TObject);
begin
FillDirectoriesBending;
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;
if fFirstSelectedIndex <> -1 then begin
if FileExistsUTF8(ProjectsListBox.Items[fFirstSelectedIndex]) then begin
fSelectedFilename:=ProjectsListBox.Items[fFirstSelectedIndex];
ModalResult:=mrYes; // mrYes means the selected file will be opened.
end else begin
ShowMessage(Format(lisFileNotFound3, [ProjectsListBox.Items[fFirstSelectedIndex]]));
end;
end;
end;
@ -245,17 +285,39 @@ begin
ProjectsListBoxSelectionChange(ProjectsListBox, False);
end;
procedure TManageExamplesForm.RelativeCheckBoxClick(Sender: TObject);
begin
;
end;
// Project list selection changes. Adjust buttons.
procedure TManageExamplesForm.ProjectsListBoxSelectionChange(Sender: TObject; User: boolean);
var
HasSelected: Boolean;
ReadMe, RealReadMe: String;
i: Integer;
begin
if not fChangingSelections then begin
HasSelected := ProjectsListBox.SelCount > 0;
OpenSelectedButton.Enabled := HasSelected;
// BuildAllSelectedButton.Enabled := HasSelected;
SelectNoneButton.Enabled := HasSelected;
// Find the first selected item and show README.txt contents.
if HasSelected then
for i:=0 to ProjectsListBox.Items.Count-1 do
if ProjectsListBox.Selected[i] then begin
fFirstSelectedIndex:=i;
ReadMe:=ExtractFilePath(ProjectsListBox.Items[i])+'README.txt';
RealReadMe:=FindDiskFileCaseInsensitive(ReadMe);
if RealReadMe <> '' then
DescriptionMemo.Lines.LoadFromFile(RealReadMe)
else
DescriptionMemo.Clear;
Break;
end
else
fFirstSelectedIndex:=-1;
end;
end;