refact, dExtList replaces with several function that test the exts

* hasDlangSyntax
* isDlangCompilable
* isEditable
This commit is contained in:
Basile Burg 2015-08-24 07:15:31 +02:00
parent 6d59b11178
commit 0bbbebd061
7 changed files with 65 additions and 36 deletions

View File

@ -24,8 +24,6 @@ const
dynExt = {$IFDEF WINDOWS} '.dll' {$ENDIF} {$IFDEF LINUX}'.so'{$ENDIF} {$IFDEF DARWIN}'.dylib'{$ENDIF};
var
dExtList: TStringList;
DCompiler: string = 'dmd';
type
@ -220,6 +218,21 @@ type
*)
function commonFolder(const someFiles: TStringList): string;
(**
* Returns true if ext matches a file extension whose type is highlightable
*)
function hasDlangSyntax(const ext: string): boolean;
(**
* Returns true if ext matches a file extension whose type can be passed as source.
*)
function isDlangCompilable(const ext: string): boolean;
(**
* Returns true if ext matches a file extension whose type is editable in Coedit
*)
function isEditable(const ext: string): boolean;
implementation
@ -990,18 +1003,36 @@ begin
end;
{$ENDIF}
function AppIsRunning(const ExeName: string):Boolean;
begin
Result:= internalAppIsRunning(ExeName) > 0;
end;
function hasDlangSyntax(const ext: string): boolean;
begin
result := false;
case ext of
'.d', '.di': result := true;
end;
end;
function isDlangCompilable(const ext: string): boolean;
begin
result := false;
case ext of
'.d', '.di', '.dd', '.obj', '.o', '.a', '.lib': result := true;
end;
end;
function isEditable(const ext: string): boolean;
begin
result := false;
case ext of
'.d', '.di', '.dd': result := true;
end;
end;
initialization
dExtList := TStringList.Create;
dExtList.AddStrings(['.d', '.di', '.dd']);
registerClasses([TCEPersistentShortcut]);
finalization
dExtList.Free;
end.

View File

@ -828,12 +828,19 @@ end;
procedure TPathsOpts.getOpts(const aList: TStrings);
var
str: string;
exts: TStringList;
begin
for str in fExtraSrcs do
begin
str := symbolExpander.get(str);
if not listAsteriskPath(str, aList, dExtList) then
aList.Add(str);
exts := TStringList.Create;
try
exts.AddStrings(['.d', '.di', '.dd']);
for str in fExtraSrcs do
begin
str := symbolExpander.get(str);
if not listAsteriskPath(str, aList, exts) then
aList.Add(str);
end;
finally
exts.Free;
end;
for str in fImpMod do
aList.Add('-I'+ symbolExpander.get(str));

View File

@ -899,7 +899,6 @@ function openFileFromDmdMessage(const aMessage: string): boolean;
var
i: Integer;
ident: string;
ext: string;
begin
ident := '';
i := 0;
@ -913,8 +912,7 @@ begin
begin
if not fileExists(ident) then
exit;
ext := extractFileExt(ident);
if dExtList.IndexOf(ext) = -1 then
if not isEditable(extractFileExt(ident)) then
exit;
getMultiDocHandler.openDocument(ident);
result := true;

View File

@ -161,13 +161,10 @@ end;
procedure TCENativeProject.addSource(const aFilename: string);
var
relSrc, absSrc, ext: string;
relSrc, absSrc: string;
begin
ext := ExtractFileExt(aFilename);
if (dExtList.IndexOf(ext) = -1) and
(ext <> '.obj') and (ext <> '.o')
and (ext <> '.lib') and (ext <> '.a') then
exit;
if not isDlangCompilable(ExtractFileExt(aFilename)) then
exit;
for relSrc in fSrcs do
begin
absSrc := expandFilenameEx(fBasePath,relsrc);

View File

@ -223,9 +223,8 @@ begin
i := fProject.Sources.IndexOf(fname);
if i > -1 then
fname := fProject.getAbsoluteSourceName(i);
if dExtList.IndexOf(ExtractFileExt(fname)) <> -1 then
if fileExists(fname) then
getMultiDocHandler.openDocument(fname);
if isEditable(ExtractFileExt(fname)) and fileExists(fname) then
getMultiDocHandler.openDocument(fname);
end
else if Tree.Selected.Parent = fConfNode then
begin
@ -267,7 +266,7 @@ end;
procedure TCEProjectInspectWidget.btnAddFoldClick(Sender: TObject);
var
dir, fname, ext: string;
dir, fname: string;
lst: TStringList;
i: NativeInt;
begin
@ -289,8 +288,7 @@ begin
for i := 0 to lst.Count-1 do
begin
fname := lst.Strings[i];
ext := extractFileExt(fname);
if dExtList.IndexOf(ext) <> -1 then
if isDlangCompilable(extractFileExt(fname)) then
fProject.addSource(fname);
end;
finally
@ -349,12 +347,10 @@ var
ext: string;
begin
ext := ExtractFileExt(aFilename);
if (dExtList.IndexOf(ext) = -1)
and (ext <> '.obj') and (ext <> '.o')
and (ext <> '.a') and (ext <> '.lib') then
exit;
if not isDlangCompilable(ext) then
exit;
fProject.addSource(aFilename);
if (dExtList.IndexOf(ext) <> -1) then
if isEditable(ext) then
getMultiDocHandler.openDocument(aFilename);
end;
var

View File

@ -212,7 +212,7 @@ begin
for i := 0 to fProj.Sources.Count-1 do
begin
fname := fProj.getAbsoluteSourceName(i);
if dExtList.IndexOf(ExtractFileExt(fname)) = -1 then
if not isEditable(ExtractFileExt(fname)) then
continue;
str.Add(fname);
end;

View File

@ -739,7 +739,7 @@ var
ext: string;
begin
ext := extractFileExt(aFilename);
if (dExtList.IndexOf(ext) = -1) or (ext = '.dd') then
if not hasDlangSyntax(ext) then
Highlighter := TxtSyn;
Lines.LoadFromFile(aFilename);
fFilename := aFilename;
@ -759,7 +759,7 @@ begin
Lines.SaveToFile(aFilename);
fFilename := aFilename;
ext := extractFileExt(aFilename);
if dExtList.IndexOf(ext) <> -1 then
if hasDlangSyntax(ext) then
Highlighter := fD2Highlighter;
FileAge(fFilename, fFileDate);
fModified := false;