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; function IsExcluded(const CurSubDir: string): boolean;
var var
i: Integer; i: Integer;
CurDir, ExcludeMask: String;
begin begin
for i:=0 to Excludes.Count-1 do CurDir:=ExtractFilename(CurSubDir);
if FilenameIsMatching(Excludes[i],CurSubDir,true) then 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); exit(true);
end;
Result:=false; Result:=false;
end; end;
@ -2453,6 +2458,7 @@ begin
FileStateCache.AddChangeTimeStampHandler(@OnFileStateCacheChangeTimeStamp); FileStateCache.AddChangeTimeStampHandler(@OnFileStateCacheChangeTimeStamp);
FStarDirectoryExcludes:=TStringListUTF8Fast.Create; FStarDirectoryExcludes:=TStringListUTF8Fast.Create;
FStarDirectoryExcludes.Delimiter:=';'; FStarDirectoryExcludes.Delimiter:=';';
FStarDirectoryExcludes.Add('.*');
end; end;
destructor TCTDirectoryCachePool.Destroy; 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; FoundFilename: String;
DirDef, UnitPathDef: TDefineTemplate; DirDef, UnitPathDef: TDefineTemplate;
DirCache: TCTDirectoryCachePool; DirCache: TCTDirectoryCachePool;
Cache: TCTStarDirectoryCache;
i: Integer;
begin begin
StarDir:=ExpandFileNameUTF8(SetDirSeparators('moduletests/star')); 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); DirDef:=TDefineTemplate.Create('TTestFindDeclaration_UnitSearch','','',StarDir,da_Directory);
try try
CodeToolBoss.DefineTree.Add(DirDef); CodeToolBoss.DefineTree.Add(DirDef);
@ -1294,8 +1300,6 @@ begin
UnitPath:=CodeToolBoss.GetUnitPathForDirectory(StarDir+PathDelim+'green'); UnitPath:=CodeToolBoss.GetUnitPathForDirectory(StarDir+PathDelim+'green');
AssertEquals('unit path',Expected,UnitPath); AssertEquals('unit path',Expected,UnitPath);
DirCache:=CodeToolBoss.DirectoryCachePool;
// searching a lowercase unit // searching a lowercase unit
anUnitName:='Star.Red1'; anUnitName:='Star.Red1';
InFilename:=''; InFilename:='';
@ -1316,6 +1320,17 @@ begin
FoundFilename:=DirCache.FindUnitSourceInCompletePath(StarDir,anUnitName,InFilename,true); FoundFilename:=DirCache.FindUnitSourceInCompletePath(StarDir,anUnitName,InFilename,true);
Expected:=StarDir+PathDelim+'green/Star.Green3.pas'; Expected:=StarDir+PathDelim+'green/Star.Green3.pas';
AssertEquals('searching '+anUnitName,Expected,FoundFilename); 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 finally
CodeToolBoss.DefineTree.RemoveDefineTemplate(DirDef); CodeToolBoss.DefineTree.RemoveDefineTemplate(DirDef);
end; end;
@ -1344,6 +1359,10 @@ var
begin begin
StarDir:=ExpandFileNameUTF8(SetDirSeparators('moduletests/star')); 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); DirDef:=TDefineTemplate.Create('TTestFindDeclaration_IncudeSearch','','',StarDir,da_Directory);
try try
CodeToolBoss.DefineTree.Add(DirDef); CodeToolBoss.DefineTree.Add(DirDef);
@ -1360,8 +1379,6 @@ begin
IncPath:=CodeToolBoss.GetIncludePathForDirectory(StarDir+PathDelim+'green'); IncPath:=CodeToolBoss.GetIncludePathForDirectory(StarDir+PathDelim+'green');
AssertEquals('include path',Expected,IncPath); AssertEquals('include path',Expected,IncPath);
DirCache:=CodeToolBoss.DirectoryCachePool;
// searching a lowercase include // searching a lowercase include
IncFilename:='Star.inc'; IncFilename:='Star.inc';
FoundFilename:=DirCache.FindIncludeFileInCompletePath(StarDir,IncFilename); FoundFilename:=DirCache.FindIncludeFileInCompletePath(StarDir,IncFilename);

View File

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

View File

@ -9,11 +9,15 @@ object FileFiltersOptionsFrame: TFileFiltersOptionsFrame
DesignLeft = 386 DesignLeft = 386
DesignTop = 179 DesignTop = 179
object grdFileFilters: TStringGrid object grdFileFilters: TStringGrid
AnchorSideTop.Control = lblFileDlgFilters
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = lblStarDirExcludes
Left = 8 Left = 8
Height = 281 Height = 223
Top = 32 Top = 27
Width = 440 Width = 440
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 6
ColCount = 3 ColCount = 3
Columns = < Columns = <
item item
@ -30,16 +34,48 @@ object FileFiltersOptionsFrame: TFileFiltersOptionsFrame
TabOrder = 0 TabOrder = 0
OnKeyDown = grdFileFiltersKeyDown OnKeyDown = grdFileFiltersKeyDown
end end
object lblTitle: TLabel object lblFileDlgFilters: TLabel
Left = 8 Left = 6
Height = 20 Height = 15
Top = 9 Top = 6
Width = 46 Width = 85
Caption = 'lblTitle' 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 end
object pmGrid: TPopupMenu object pmGrid: TPopupMenu
left = 205 Left = 205
top = 75 Top = 75
object pmiAddRow: TMenuItem object pmiAddRow: TMenuItem
Caption = 'Add row' Caption = 'Add row'
OnClick = pmiAddRowClick 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+} {$mode objfpc}{$H+}
@ -17,19 +22,22 @@ uses
const const
FileDialogFilterConfigFile = 'filefilters.xml'; FileDialogFilterConfigFile = 'filefilters.xml';
type type
{ TFileFiltersOptionsFrame } { TFileFiltersOptionsFrame }
TFileFiltersOptionsFrame = class(TAbstractIDEOptionsEditor) TFileFiltersOptionsFrame = class(TAbstractIDEOptionsEditor)
edStarDirExcludes: TEdit;
grdFileFilters: TStringGrid; grdFileFilters: TStringGrid;
lblStarDirExcludes: TLabel;
MenuItem1: TMenuItem; MenuItem1: TMenuItem;
SetDefaultMenuItem: TMenuItem; SetDefaultMenuItem: TMenuItem;
pmGrid: TPopupMenu; pmGrid: TPopupMenu;
pmiAddRow: TMenuItem; pmiAddRow: TMenuItem;
pmiDelRow: TMenuItem; pmiDelRow: TMenuItem;
pmiInsRow: TMenuItem; pmiInsRow: TMenuItem;
lblTitle: TLabel; lblFileDlgFilters: TLabel;
procedure grdFileFiltersKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState); procedure grdFileFiltersKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
procedure pmiAddRowClick(Sender: TObject); procedure pmiAddRowClick(Sender: TObject);
procedure pmiDelRowClick(Sender: TObject); procedure pmiDelRowClick(Sender: TObject);
@ -46,7 +54,6 @@ type
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override; class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
end; end;
procedure LoadFileDialogFilter; procedure LoadFileDialogFilter;
procedure SaveFileDialogFilter; procedure SaveFileDialogFilter;
function GetDefaultFileDialogFilter: string; function GetDefaultFileDialogFilter: string;
@ -64,7 +71,6 @@ const
KeyFilterName = 'Name'; KeyFilterName = 'Name';
KeyFilterMask = 'Mask'; KeyFilterMask = 'Mask';
procedure LoadFileDialogFilter; procedure LoadFileDialogFilter;
var var
cfg: TConfigStorage; cfg: TConfigStorage;
@ -278,7 +284,7 @@ end;
procedure TFileFiltersOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog); procedure TFileFiltersOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin begin
lblTitle.Caption := lisFileFiltersTitle; lblFileDlgFilters.Caption := lisFileFiltersTitle;
grdFileFilters.DefaultColWidth := 40; grdFileFilters.DefaultColWidth := 40;
grdFileFilters.RowCount := 1; grdFileFilters.RowCount := 1;
@ -290,6 +296,8 @@ begin
pmiInsRow.Caption := lisFileFiltersInsertRow; pmiInsRow.Caption := lisFileFiltersInsertRow;
SetDefaultMenuItem.Caption := lisFileFiltersSetDefaults; SetDefaultMenuItem.Caption := lisFileFiltersSetDefaults;
lblStarDirExcludes.Caption:='Excludes for * and ** in unit and include search paths';
end; end;
procedure TFileFiltersOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions); procedure TFileFiltersOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
@ -298,6 +306,8 @@ begin
fLoaded:=true; fLoaded:=true;
LoadGridFromFileDialogFilter(grdFileFilters,EnvironmentOptions.FileDialogFilter,false); LoadGridFromFileDialogFilter(grdFileFilters,EnvironmentOptions.FileDialogFilter,false);
edStarDirExcludes.Text:=EnvironmentOptions.StarDirectoryExcludes;
end; end;
procedure TFileFiltersOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions); procedure TFileFiltersOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
@ -314,6 +324,8 @@ begin
EnvironmentOptions.FileDialogFilter:=Filter; EnvironmentOptions.FileDialogFilter:=Filter;
SaveFileDialogFilter; SaveFileDialogFilter;
end; end;
EnvironmentOptions.StarDirectoryExcludes:=edStarDirExcludes.Text;
end; end;
class function TFileFiltersOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass; class function TFileFiltersOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;

View File

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

View File

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

View File

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

View File

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