diff --git a/ide/examplemanager.lfm b/ide/examplemanager.lfm index 018dcfd5b3..32f6eb8c99 100644 --- a/ide/examplemanager.lfm +++ b/ide/examplemanager.lfm @@ -1,25 +1,25 @@ object ExampleManagerForm: TExampleManagerForm Left = 356 - Height = 491 + Height = 495 Top = 130 - Width = 837 + Width = 870 Caption = 'ExampleManagerForm' - ClientHeight = 491 - ClientWidth = 837 + ClientHeight = 495 + ClientWidth = 870 OnClose = FormClose OnCreate = FormCreate Position = poDesktopCenter LCLVersion = '1.1' object ProjectsGroupBox: TGroupBox Left = 0 - Height = 338 - Top = 107 - Width = 424 + Height = 326 + Top = 123 + Width = 457 Align = alClient BorderSpacing.Top = 3 Caption = 'Projects' - ClientHeight = 309 - ClientWidth = 418 + ClientHeight = 297 + ClientWidth = 451 TabOrder = 0 object ProjectsListBox: TListBox AnchorSideLeft.Control = ProjectsGroupBox @@ -30,9 +30,9 @@ object ExampleManagerForm: TExampleManagerForm AnchorSideBottom.Control = ProjectsGroupBox AnchorSideBottom.Side = asrBottom Left = 0 - Height = 280 + Height = 268 Top = 29 - Width = 418 + Width = 451 Anchors = [akTop, akLeft, akRight, akBottom] BorderSpacing.Top = 5 ItemHeight = 0 @@ -46,6 +46,7 @@ object ExampleManagerForm: TExampleManagerForm Height = 23 Top = 1 Width = 221 + OnAfterFilter = ProjectFilterAfterFilter ButtonWidth = 23 NumGlyphs = 1 MaxLength = 0 @@ -71,8 +72,8 @@ object ExampleManagerForm: TExampleManagerForm object ButtonPanel1: TButtonPanel Left = 6 Height = 34 - Top = 451 - Width = 825 + Top = 455 + Width = 858 OKButton.Name = 'OKButton' OKButton.DefaultCaption = True HelpButton.Name = 'HelpButton' @@ -86,19 +87,19 @@ object ExampleManagerForm: TExampleManagerForm end object ActionGroupBox: TGroupBox AnchorSideLeft.Side = asrBottom - Left = 432 - Height = 338 - Top = 107 + Left = 465 + Height = 326 + Top = 123 Width = 405 Align = alRight Anchors = [] BorderSpacing.Left = 3 BorderSpacing.Top = 3 Caption = 'Action' - ClientHeight = 309 + ClientHeight = 297 ClientWidth = 399 TabOrder = 2 - object Label1: TLabel + object lbConstruction: TLabel AnchorSideTop.Control = BuildAllSelectedButton AnchorSideTop.Side = asrBottom AnchorSideRight.Control = BuildAllSelectedButton @@ -187,7 +188,7 @@ object ExampleManagerForm: TExampleManagerForm AnchorSideBottom.Control = ActionGroupBox AnchorSideBottom.Side = asrBottom Left = 2 - Height = 229 + Height = 217 Top = 78 Width = 395 Anchors = [akTop, akLeft, akRight, akBottom] @@ -200,49 +201,54 @@ object ExampleManagerForm: TExampleManagerForm end object SelectPanel: TPanel Left = 0 - Height = 104 + Height = 120 Top = 0 - Width = 837 + Width = 870 Align = alTop - ClientHeight = 104 - ClientWidth = 837 + ClientHeight = 120 + ClientWidth = 870 TabOrder = 3 - object TestCaseCheckBox: TCheckBox - AnchorSideLeft.Control = ExamplesCheckBox - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = ExamplesCheckBox - AnchorSideTop.Side = asrCenter - Left = 419 + object cbIncludeAllDirs: TCheckBox + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = edRootDirectory + AnchorSideRight.Side = asrBottom + Left = 282 Height = 21 - Top = 5 - Width = 136 - BorderSpacing.Left = 33 - Caption = 'Include Testcases' - OnChange = ExamplesCheckBoxChange + Top = 56 + Width = 182 + Anchors = [akTop, akRight] + BorderSpacing.Top = 3 + Caption = 'Include all subdirectories' + OnClick = cbIncludeAllDirsClick TabOrder = 0 end - object ExamplesCheckBox: TCheckBox - AnchorSideLeft.Control = DirectoryComboBox + object edRootDirectory: TDirectoryEdit + AnchorSideLeft.Control = lbRootDirectory AnchorSideTop.Side = asrBottom - Left = 253 - Height = 21 - Top = 5 - Width = 133 - BorderSpacing.Top = 3 - Caption = 'Include Examples' - Checked = True - OnChange = ExamplesCheckBoxChange - State = cbChecked + AnchorSideRight.Side = asrBottom + Left = 8 + Height = 23 + Top = 24 + Width = 456 + ShowHidden = False + ButtonWidth = 23 + NumGlyphs = 1 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 7 + MaxLength = 0 TabOrder = 1 + OnChange = edRootDirectoryChange end - object RootRadioGroup: TRadioGroup - Left = 64 - Height = 99 + object cgIncludedDirs: TCheckGroup + AnchorSideBottom.Control = SelectPanel + AnchorSideBottom.Side = asrBottom + Left = 496 + Height = 114 Top = 5 - Width = 184 + Width = 369 + Anchors = [akTop, akRight, akBottom] AutoFill = True - BorderSpacing.Top = 5 - Caption = 'Search projects from' + Caption = 'Include subdirectories' ChildSizing.LeftRightSpacing = 6 ChildSizing.TopBottomSpacing = 6 ChildSizing.EnlargeHorizontal = crsHomogenousChildResize @@ -250,50 +256,52 @@ object ExampleManagerForm: TExampleManagerForm ChildSizing.ShrinkHorizontal = crsScaleChilds ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.Layout = cclLeftToRightThenTopToBottom - ChildSizing.ControlsPerLine = 1 - OnClick = RootRadioGroupClick + ChildSizing.ControlsPerLine = 4 + ClientHeight = 85 + ClientWidth = 363 + Columns = 4 + Items.Strings = ( + 'example' + 'sample' + 'demo' + 'test' + 'examples' + 'samples' + 'demos' + 'tests' + ) + OnItemClick = cgIncludedDirsItemClick TabOrder = 2 + Data = { + 080000000202020202020202 + } end - object RootDirectoryEdit: TDirectoryEdit - AnchorSideLeft.Control = DirectoryComboBox - AnchorSideTop.Control = DirectoryComboBox - AnchorSideTop.Side = asrBottom - AnchorSideRight.Side = asrBottom - Left = 253 - Height = 23 - Top = 57 - Width = 542 - ShowHidden = False - ButtonWidth = 23 - NumGlyphs = 1 - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Top = 7 - MaxLength = 0 - TabOrder = 3 - OnChange = RootDirectoryEditChange + object lbRootDirectory: TLabel + Left = 8 + Height = 15 + Top = 8 + Width = 89 + Caption = 'Root Directory' + ParentColor = False end - object DirectoryComboBox: TComboBox - AnchorSideLeft.Control = RootRadioGroup - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = ExamplesCheckBox - AnchorSideTop.Side = asrBottom - AnchorSideRight.Side = asrBottom - Left = 253 - Height = 23 - Top = 27 - Width = 566 - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Left = 5 - BorderSpacing.Top = 1 - ItemHeight = 0 - OnChange = DirectoryComboBoxChange - TabOrder = 4 + object lbProjectCount: TLabel + AnchorSideLeft.Control = edRootDirectory + AnchorSideBottom.Control = SelectPanel + AnchorSideBottom.Side = asrBottom + Left = 8 + Height = 15 + Top = 93 + Width = 92 + Anchors = [akLeft, akBottom] + BorderSpacing.Bottom = 11 + Caption = 'lbProjectCount' + ParentColor = False end end object Splitter1: TSplitter - Left = 424 - Height = 341 - Top = 104 + Left = 457 + Height = 329 + Top = 120 Width = 5 Align = alRight ResizeAnchor = akRight diff --git a/ide/examplemanager.pas b/ide/examplemanager.pas index 9da86c9771..50bcfbaf07 100644 --- a/ide/examplemanager.pas +++ b/ide/examplemanager.pas @@ -15,45 +15,41 @@ type TExampleManagerForm = class(TForm) BuildAllSelectedButton: TBitBtn; + cgIncludedDirs: TCheckGroup; + lbProjectCount: TLabel; + lbRootDirectory: TLabel; SelectPanel: TPanel; RelativeCheckBox: TCheckBox; DescriptionMemo: TMemo; Splitter1: TSplitter; - TestCaseCheckBox: TCheckBox; - ExamplesCheckBox: TCheckBox; - DirectoryComboBox: TComboBox; + cbIncludeAllDirs: TCheckBox; ProjectFilter: TListFilterEdit; OpenSelectedButton: TBitBtn; - Label1: TLabel; + lbConstruction: TLabel; ProjectsListBox: TListBox; - RootRadioGroup: TRadioGroup; SelectAllButton: TBitBtn; ButtonPanel1: TButtonPanel; - RootDirectoryEdit: TDirectoryEdit; + edRootDirectory: TDirectoryEdit; ActionGroupBox: TGroupBox; SelectNoneButton: TBitBtn; ProjectsGroupBox: TGroupBox; + procedure cbIncludeAllDirsClick(Sender: TObject); + procedure cgIncludedDirsItemClick(Sender: TObject; Index: integer); procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure BuildAllSelectedButtonClick(Sender: TObject); procedure OpenSelectedButtonClick(Sender: TObject); + procedure ProjectFilterAfterFilter(Sender: TObject); procedure ProjectsListBoxSelectionChange(Sender: TObject; User: boolean); procedure RelativeCheckBoxClick(Sender: TObject); - procedure RootRadioGroupClick(Sender: TObject); - procedure DirectoryComboBoxChange(Sender: TObject); - procedure RootDirectoryEditChange(Sender: TObject); + procedure edRootDirectoryChange(Sender: TObject); procedure SelectAllButtonClick(Sender: TObject); procedure SelectNoneButtonClick(Sender: TObject); - procedure ExamplesCheckBoxChange(Sender: TObject); private fSelectedFilename: string; fFirstSelectedIndex: Integer; fChangingSelections: Boolean; - fNeedsFindDirectories: Boolean; - fNeedsFindProjects: Boolean; - fUpdating: Boolean; fIdleConnected: boolean; - procedure FillDirectoriesPending; procedure FillProjectsPending; procedure SetIdleConnected(const AValue: boolean); procedure OnIdle(Sender: TObject; var Done: Boolean); @@ -70,6 +66,18 @@ implementation {$R *.lfm} +const + DirectoryChoices: array[0..7] of string = ( + 'example', // 1st row + 'sample', + 'demo', + 'test', + 'examples', // 2nd row + 'samples', + 'demos', + 'tests' + ); + function ShowExampleManagerDlg: TModalResult; var theForm: TExampleManagerForm; @@ -110,30 +118,34 @@ end; constructor TListFileSearcher.Create(aForm: TExampleManagerForm); begin inherited Create; - fForm := aForm; + fForm:=aForm; end; { TExampleManagerForm } constructor TExampleManagerForm.Create(AnOwner: TComponent); +var + i: Integer; begin inherited Create(AnOwner); fFirstSelectedIndex:=-1; fChangingSelections:=False; - fUpdating:=False; - fNeedsFindDirectories:=False; - fNeedsFindProjects:=False; Caption:=lisKMExampleProjects; - ExamplesCheckBox.Caption:=lisIncludeExamples; - TestCaseCheckBox.Caption:=lisIncludeTestcases; + cbIncludeAllDirs.Caption:=lisIncludeAllSubDirectories; + cgIncludedDirs.Caption:=lisIncludeSubDirectories; - RootRadioGroup.Caption:=lisSearchProjectsFrom; - RootRadioGroup.Items.Add(lisLazarusSource); - RootRadioGroup.Items.Add(lisCEOtherGroup); - RootRadioGroup.ItemIndex:=0; - RootRadioGroupClick(RootRadioGroup); + // Add potential included directories to CheckGroup + cgIncludedDirs.Items.Clear; + for i := Low(DirectoryChoices) to High(DirectoryChoices) do + begin + cgIncludedDirs.Items.Add(DirectoryChoices[i]); + cgIncludedDirs.Checked[i]:=True; + end; + cbIncludeAllDirsClick(cbIncludeAllDirs); + lbProjectCount.Caption:=''; + // Projects and their Actions ProjectsGroupBox.Caption:=lisMEProjects; ActionGroupBox.Caption:=lisMEAction; @@ -148,7 +160,7 @@ begin SelectAllButton.LoadGlyphFromLazarusResource('menu_select_all'); SelectNoneButton.LoadGlyphFromLazarusResource('ce_default'); - FillDirectoriesPending; + edRootDirectory.Text:=EnvironmentOptions.GetParsedLazarusDirectory; FillProjectsPending; end; @@ -167,15 +179,8 @@ begin IDEDialogLayoutList.SaveLayout(Self); end; -procedure TExampleManagerForm.FillDirectoriesPending; -begin - fNeedsFindDirectories:=True; - IdleConnected:=True; -end; - procedure TExampleManagerForm.FillProjectsPending; begin - fNeedsFindProjects:=True; IdleConnected:=True; end; @@ -192,101 +197,92 @@ end; procedure TExampleManagerForm.OnIdle(Sender: TObject; var Done: Boolean); var Searcher: TListFileSearcher; - AllDirs: TStringList; - i: Integer; + AllDirs, IncludedDirs: TStringList; + i, j: Integer; LastDir: String; begin - IdleConnected:=false; - if fUpdating then Exit; - fUpdating:=True; - if fNeedsFindDirectories then begin - Screen.Cursor:=crHourGlass; - Application.ProcessMessages; - DirectoryComboBox.Items.Clear; - DirectoryComboBox.Text:=''; - RootDirectoryEdit.Text:=''; - AllDirs:=FindAllDirectories(EnvironmentOptions.GetParsedLazarusDirectory); - try - for i:=0 to AllDirs.Count-1 do begin - LastDir:=ExtractFileName(AllDirs[i]); - if (ExamplesCheckBox.Checked and ((LastDir='examples') or (LastDir='samples'))) - 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; - Screen.Cursor:=crDefault; - end; - end; - if fNeedsFindProjects and (RootDirectoryEdit.Text<>'') then + Screen.Cursor:=crHourGlass; + Searcher:=TListFileSearcher.Create(Self); + IncludedDirs:=TStringList.Create; + AllDirs:=Nil; try - Screen.Cursor:=crHourGlass; - Application.ProcessMessages; + // Collect each matching directory name to a list. + if (edRootDirectory.Text<>'') and not cbIncludeAllDirs.Checked then + begin + AllDirs:=FindAllDirectories(edRootDirectory.Text); + for i:=0 to AllDirs.Count-1 do + begin + LastDir:=ExtractFileName(AllDirs[i]); + for j:=Low(DirectoryChoices) to High(DirectoryChoices) do + begin + if cgIncludedDirs.Checked[j] and (LastDir=DirectoryChoices[j]) then + begin + IncludedDirs.Add(AllDirs[i]); + Break; + end; + end; + end; + end + // Add only the root directory name to list. Will find all projects in one go. + else if cbIncludeAllDirs.Checked then + IncludedDirs.Add(edRootDirectory.Text); ProjectFilter.Items.Clear; - Searcher:=TListFileSearcher.Create(Self); - Searcher.Search(RootDirectoryEdit.Text, '*.lpi'); + // Find projects in all included directories. + for i:=0 to IncludedDirs.Count-1 do + Searcher.Search(IncludedDirs[i], '*.lpi'); ProjectFilter.InvalidateFilter; DescriptionMemo.Clear; + IdleConnected:=false; finally + AllDirs.Free; + IncludedDirs.Free; Searcher.Free; - fNeedsFindProjects:=False; Screen.Cursor:=crDefault; end; - fUpdating:=False; end; -procedure TExampleManagerForm.RootRadioGroupClick(Sender: TObject); -var - LazSrc: Boolean; -begin - LazSrc:=RootRadioGroup.ItemIndex=0; - ExamplesCheckBox.Enabled:=LazSrc; - TestCaseCheckBox.Enabled:=LazSrc; - DirectoryComboBox.Enabled:=LazSrc; - RootDirectoryEdit.Enabled:=not LazSrc; -end; - -procedure TExampleManagerForm.DirectoryComboBoxChange(Sender: TObject); -begin - if DirectoryExists(DirectoryComboBox.Text) then begin - RootDirectoryEdit.Text:=DirectoryComboBox.Text; - FillProjectsPending; - end; -end; - -procedure TExampleManagerForm.RootDirectoryEditChange(Sender: TObject); +procedure TExampleManagerForm.edRootDirectoryChange(Sender: TObject); begin FillProjectsPending; end; -procedure TExampleManagerForm.ExamplesCheckBoxChange(Sender: TObject); +procedure TExampleManagerForm.cbIncludeAllDirsClick(Sender: TObject); begin - FillDirectoriesPending; + cgIncludedDirs.Enabled:=not (Sender as TCheckBox).Checked; + FillProjectsPending; +end; + +procedure TExampleManagerForm.cgIncludedDirsItemClick(Sender: TObject; Index: integer); +begin + FillProjectsPending; end; procedure TExampleManagerForm.OpenSelectedButtonClick(Sender: TObject); begin - if fFirstSelectedIndex <> -1 then begin - if FileExistsUTF8(ProjectsListBox.Items[fFirstSelectedIndex]) then begin + 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 + end + else begin ShowMessage(Format(lisFileNotFound3, [ProjectsListBox.Items[fFirstSelectedIndex]])); end; end; end; +procedure TExampleManagerForm.ProjectFilterAfterFilter(Sender: TObject); +begin + lbProjectCount.Caption:=IntToStr(ProjectsListBox.Count)+lisProjectCount; +end; + procedure TExampleManagerForm.BuildAllSelectedButtonClick(Sender: TObject); var i: Integer; begin - for i:=0 to ProjectsListBox.Items.Count-1 do begin + for i:=0 to ProjectsListBox.Items.Count-1 do + begin if ProjectsListBox.Selected[i] then begin ; // ToDo end; @@ -324,7 +320,8 @@ var ReadMe, RealReadMe: String; i: Integer; begin - if not fChangingSelections then begin + if not fChangingSelections then + begin HasSelected := ProjectsListBox.SelCount > 0; OpenSelectedButton.Enabled := HasSelected; // BuildAllSelectedButton.Enabled := HasSelected; @@ -332,7 +329,8 @@ begin // 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 + if ProjectsListBox.Selected[i] then + begin fFirstSelectedIndex:=i; ReadMe:=ExtractFilePath(ProjectsListBox.Items[i])+'README.txt'; RealReadMe:=FindDiskFileCaseInsensitive(ReadMe); diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index a92ff3cefa..bc06a5d761 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -485,13 +485,12 @@ resourcestring lisMenuConfigureBuildLazarus = 'Configure "Build Lazarus" ...'; lisDlgEditorWindowManager = 'Editor Window Manager ...'; lisEditorWindowManager = 'Editor Window Manager'; - - lisSearchProjectsFrom = 'Search projects from'; + lisProjectCount = ' projects'; + lisIncludeSubDirectories = 'Include subdirectories'; + lisIncludeAllSubDirectories = 'Include all subdirectories'; lisMEOther = 'Other tabs'; lisTabsFor = 'Tabs for %s'; lisRecentTabs = 'Recent tabs'; - lisIncludeExamples = 'Include Examples'; - lisIncludeTestcases = 'Include Testcases'; lisMEProjects = 'Projects'; lisMEAction = 'Action'; lisMenuGeneralOptions = 'Options ...'; @@ -3063,7 +3062,6 @@ 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';