IDE: added option for global star directory excludes

This commit is contained in:
mattias 2023-07-09 22:20:56 +02:00
parent 41d9d4c12f
commit 0cf38f57c7
12 changed files with 119 additions and 25 deletions

View File

@ -2162,10 +2162,15 @@ var
function IsExcluded(const CurSubDir: string): boolean;
var
i: Integer;
CurDir, ExcludeMask: String;
begin
for i:=0 to Excludes.Count-1 do
if FilenameIsMatching(Excludes[i],CurSubDir,true) then
CurDir:=ExtractFilename(CurSubDir);
for i:=0 to Excludes.Count-1 do begin
ExcludeMask:=Excludes[i];
if FilenameIsMatching(ExcludeMask,CurSubDir,true)
or FilenameIsMatching(ExcludeMask,CurDir,true) then
exit(true);
end;
Result:=false;
end;
@ -2453,6 +2458,7 @@ begin
FileStateCache.AddChangeTimeStampHandler(@OnFileStateCacheChangeTimeStamp);
FStarDirectoryExcludes:=TStringListUTF8Fast.Create;
FStarDirectoryExcludes.Delimiter:=';';
FStarDirectoryExcludes.Add('.*');
end;
destructor TCTDirectoryCachePool.Destroy;

View File

@ -0,0 +1 @@
var Green: word;

View File

@ -0,0 +1,11 @@
unit star.main;
interface
uses star.red1, star.green1, star.green2, star.orange1;
{$I green/Green.inc}
implementation
end.

View File

@ -1275,9 +1275,15 @@ var
FoundFilename: String;
DirDef, UnitPathDef: TDefineTemplate;
DirCache: TCTDirectoryCachePool;
Cache: TCTStarDirectoryCache;
i: Integer;
begin
StarDir:=ExpandFileNameUTF8(SetDirSeparators('moduletests/star'));
DirCache:=CodeToolBoss.DirectoryCachePool;
if DirCache.StarDirectoryExcludes.IndexOf('ignore')<0 then
DirCache.StarDirectoryExcludes.Add('ignore');
DirDef:=TDefineTemplate.Create('TTestFindDeclaration_UnitSearch','','',StarDir,da_Directory);
try
CodeToolBoss.DefineTree.Add(DirDef);
@ -1294,8 +1300,6 @@ begin
UnitPath:=CodeToolBoss.GetUnitPathForDirectory(StarDir+PathDelim+'green');
AssertEquals('unit path',Expected,UnitPath);
DirCache:=CodeToolBoss.DirectoryCachePool;
// searching a lowercase unit
anUnitName:='Star.Red1';
InFilename:='';
@ -1316,6 +1320,17 @@ begin
FoundFilename:=DirCache.FindUnitSourceInCompletePath(StarDir,anUnitName,InFilename,true);
Expected:=StarDir+PathDelim+'green/Star.Green3.pas';
AssertEquals('searching '+anUnitName,Expected,FoundFilename);
// check excludes
Cache:=DirCache.GetStarCache(StarDir,ctsdStarStar);
for i:=0 to Cache.Listing.Count-1 do begin
FoundFilename:=Cache.Listing.GetSubDirFilename(i);
if (FoundFilename[1]='.')
or (Pos(PathDelim+'.',FoundFilename)>0)
or (Pos('ignore',FoundFilename)>0) then
Fail('Failed to exclude "'+FoundFilename+'"');
end;
finally
CodeToolBoss.DefineTree.RemoveDefineTemplate(DirDef);
end;
@ -1344,6 +1359,10 @@ var
begin
StarDir:=ExpandFileNameUTF8(SetDirSeparators('moduletests/star'));
DirCache:=CodeToolBoss.DirectoryCachePool;
if DirCache.StarDirectoryExcludes.IndexOf('ignore')<0 then
DirCache.StarDirectoryExcludes.Add('ignore');
DirDef:=TDefineTemplate.Create('TTestFindDeclaration_IncudeSearch','','',StarDir,da_Directory);
try
CodeToolBoss.DefineTree.Add(DirDef);
@ -1360,8 +1379,6 @@ begin
IncPath:=CodeToolBoss.GetIncludePathForDirectory(StarDir+PathDelim+'green');
AssertEquals('include path',Expected,IncPath);
DirCache:=CodeToolBoss.DirectoryCachePool;
// searching a lowercase include
IncFilename:='Star.inc';
FoundFilename:=DirCache.FindIncludeFileInCompletePath(StarDir,IncFilename);

View File

@ -8,7 +8,7 @@
Author: Mattias Gaertner
Abtract:
Abstract:
Registers a new designer base class (like TForm or TDataModule) in the IDE.
}
unit CustomComponentClass;

View File

@ -9,11 +9,15 @@ object FileFiltersOptionsFrame: TFileFiltersOptionsFrame
DesignLeft = 386
DesignTop = 179
object grdFileFilters: TStringGrid
AnchorSideTop.Control = lblFileDlgFilters
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = lblStarDirExcludes
Left = 8
Height = 281
Top = 32
Height = 223
Top = 27
Width = 440
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 6
ColCount = 3
Columns = <
item
@ -30,16 +34,48 @@ object FileFiltersOptionsFrame: TFileFiltersOptionsFrame
TabOrder = 0
OnKeyDown = grdFileFiltersKeyDown
end
object lblTitle: TLabel
Left = 8
Height = 20
Top = 9
Width = 46
Caption = 'lblTitle'
object lblFileDlgFilters: TLabel
Left = 6
Height = 15
Top = 6
Width = 85
Caption = 'lblFileDlgFilters'
end
object lblStarDirExcludes: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = edStarDirExcludes
Left = 6
Height = 15
Top = 260
Width = 100
Anchors = [akLeft, akBottom]
BorderSpacing.Left = 6
BorderSpacing.Top = 10
BorderSpacing.Bottom = 6
Caption = 'lblStarDirExcludes'
end
object edStarDirExcludes: TEdit
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = lblStarDirExcludes
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 6
Height = 32
Top = 281
Width = 443
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 6
BorderSpacing.Right = 6
BorderSpacing.Bottom = 6
TabOrder = 1
end
object pmGrid: TPopupMenu
left = 205
top = 75
Left = 205
Top = 75
object pmiAddRow: TMenuItem
Caption = 'Add row'
OnClick = pmiAddRowClick

View File

@ -1,4 +1,9 @@
unit env_file_filters;
{
Abstract:
Frame for environment options for main paths, like
Lazarus directory, compiler path.
}
unit Env_File_Filters;
{$mode objfpc}{$H+}
@ -17,19 +22,22 @@ uses
const
FileDialogFilterConfigFile = 'filefilters.xml';
type
{ TFileFiltersOptionsFrame }
TFileFiltersOptionsFrame = class(TAbstractIDEOptionsEditor)
edStarDirExcludes: TEdit;
grdFileFilters: TStringGrid;
lblStarDirExcludes: TLabel;
MenuItem1: TMenuItem;
SetDefaultMenuItem: TMenuItem;
pmGrid: TPopupMenu;
pmiAddRow: TMenuItem;
pmiDelRow: TMenuItem;
pmiInsRow: TMenuItem;
lblTitle: TLabel;
lblFileDlgFilters: TLabel;
procedure grdFileFiltersKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
procedure pmiAddRowClick(Sender: TObject);
procedure pmiDelRowClick(Sender: TObject);
@ -46,7 +54,6 @@ type
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
end;
procedure LoadFileDialogFilter;
procedure SaveFileDialogFilter;
function GetDefaultFileDialogFilter: string;
@ -64,7 +71,6 @@ const
KeyFilterName = 'Name';
KeyFilterMask = 'Mask';
procedure LoadFileDialogFilter;
var
cfg: TConfigStorage;
@ -278,7 +284,7 @@ end;
procedure TFileFiltersOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
lblTitle.Caption := lisFileFiltersTitle;
lblFileDlgFilters.Caption := lisFileFiltersTitle;
grdFileFilters.DefaultColWidth := 40;
grdFileFilters.RowCount := 1;
@ -290,6 +296,8 @@ begin
pmiInsRow.Caption := lisFileFiltersInsertRow;
SetDefaultMenuItem.Caption := lisFileFiltersSetDefaults;
lblStarDirExcludes.Caption:='Excludes for * and ** in unit and include search paths';
end;
procedure TFileFiltersOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
@ -298,6 +306,8 @@ begin
fLoaded:=true;
LoadGridFromFileDialogFilter(grdFileFilters,EnvironmentOptions.FileDialogFilter,false);
edStarDirExcludes.Text:=EnvironmentOptions.StarDirectoryExcludes;
end;
procedure TFileFiltersOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
@ -314,6 +324,8 @@ begin
EnvironmentOptions.FileDialogFilter:=Filter;
SaveFileDialogFilter;
end;
EnvironmentOptions.StarDirectoryExcludes:=edStarDirExcludes.Text;
end;
class function TFileFiltersOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;

View File

@ -18,7 +18,7 @@
* *
***************************************************************************
Abtract:
Abstract:
Frame for environment options for main paths, like
Lazarus directory, compiler path.
}

View File

@ -18,7 +18,7 @@
* *
***************************************************************************
Abtract:
Abstract:
Frame for environment options for things happening during startup.
- Single Lazarus IDE instance / multiple instances.
- The project that gets opened or created.

View File

@ -5112,6 +5112,7 @@ begin
FPCSrcDirChanged:=false;
FPCCompilerChanged:=OldCompilerFilename<>EnvironmentOptions.CompilerFilename;
LazarusSrcDirChanged:=false;
CodeToolBoss.DirectoryCachePool.StarDirectoryExcludes.DelimitedText:=EnvironmentOptions.StarDirectoryExcludes;
ChangeMacroValue('LazarusDir',EnvironmentOptions.GetParsedLazarusDirectory);
ChangeMacroValue('FPCSrcDir',EnvironmentOptions.GetParsedFPCSourceDirectory);
MainBuildBoss.EnvOptsChanged;
@ -9786,11 +9787,12 @@ begin
Variables[ExternalMacroStart+'LCLWidgetType']:=GetLCLWidgetTypeName;
Variables[ExternalMacroStart+'FPCSrcDir']:=EnvironmentOptions.GetParsedFPCSourceDirectory;
end;
CodeToolBoss.DirectoryCachePool.StarDirectoryExcludes.DelimitedText:=EnvironmentOptions.StarDirectoryExcludes;
// the first template is the "use default" flag
CreateUseDefaultsFlagTemplate;
// load include file relationships
// load cached include file relationships
AFilename:=AppendPathDelim(GetPrimaryConfigPath)+CodeToolsIncludeLinkFile;
if FileExistsCached(AFilename) then
CodeToolBoss.SourceCache.LoadIncludeLinksFromFile(AFilename);

View File

@ -108,6 +108,7 @@ const
DefaultBackupAddExt = 'bak';
DefaultBackupMaxCounter = 9;
DefaultBackupSubDirectory = 'backup';
DefaultStarDirectoryExcludes = '.*;'+DefaultBackupSubDirectory;
{ Naming }
@ -255,6 +256,7 @@ type
FFileHasChangedOnDisk: boolean;
FMaxExtToolsInParallel: integer;
FOldLazarusVersion: string;
FStarDirectoryExcludes: string;
FXMLCfg: TRttiXMLConfig;
FConfigStore: TXMLOptionsStorage;
// auto save
@ -435,6 +437,8 @@ type
property CompilerMessagesFileHistory: TStringList read FCompilerMessagesFileHistory;
// ToDo: Remove this from trunk after Lazarus 2.2.0 is out. Now for backwards compatibility.
property ManyBuildModesSelection: TStringList read FManyBuildModesSelection;
// global excludes for * and ** in unit paths
property StarDirectoryExcludes: string read FStarDirectoryExcludes write FStarDirectoryExcludes;
// Primary-config verification
property LastCalledByLazarusFullPath: String read FLastCalledByLazarusFullPath write FLastCalledByLazarusFullPath;
@ -516,6 +520,8 @@ type
// default template for each 'new item' category: Name=Path, Value=TemplateName
property NewFormTemplate: string read FNewFormTemplate write FNewFormTemplate;
property NewUnitTemplate: string read FNewUnitTemplate write FNewUnitTemplate;
// file filters
property FileDialogFilter: string read FFileDialogFilter write FFileDialogFilter;
end;
@ -704,6 +710,7 @@ begin
CompilerMessagesFilename:='';
FCompilerMessagesFileHistory:=TStringList.Create;
FManyBuildModesSelection:=TStringList.Create;
FStarDirectoryExcludes:=DefaultStarDirectoryExcludes;
// recent files and directories
FRecentOpenFiles:=TStringList.Create;
@ -917,6 +924,7 @@ begin
CompilerMessagesFilename:=FXMLCfg.GetValue(Path+'CompilerMessagesFilename/Value',CompilerMessagesFilename);
LoadRecentList(FXMLCfg,FCompilerMessagesFileHistory,Path+'CompilerMessagesFilename/History/',rltFile);
LoadRecentList(FXMLCfg,FManyBuildModesSelection,Path+'ManyBuildModesSelection/',rltCaseInsensitive);
StarDirectoryExcludes:=FXMLCfg.GetValue(Path+'StarDirExcludes/Value',DefaultStarDirectoryExcludes);
// Primary-config verification
FLastCalledByLazarusFullPath:=FXMLCfg.GetValue(Path+'LastCalledByLazarusFullPath/Value','');
@ -1139,6 +1147,7 @@ begin
FXMLCfg.SetDeleteValue(Path+'FppkgConfigFile/Value',FppkgConfigFile,'');
SaveRecentList(FXMLCfg,FFppkgConfigFileHistory,Path+'FppkgConfigFile/History/');
// Note: ManyBuildModesSelection is not stored here any more. Moved to project settings.
FXMLCfg.SetDeleteValue(Path+'StarDirExcludes/Value',StarDirectoryExcludes,DefaultStarDirectoryExcludes);
// Primary-config verification
FXMLCfg.SetDeleteValue(Path+'LastCalledByLazarusFullPath/Value',FLastCalledByLazarusFullPath,'');