diff --git a/src/ce_common.pas b/src/ce_common.pas index 4c5591fc..96dc02f9 100644 --- a/src/ce_common.pas +++ b/src/ce_common.pas @@ -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. diff --git a/src/ce_dmdwrap.pas b/src/ce_dmdwrap.pas index 883973a1..9ab24ee0 100644 --- a/src/ce_dmdwrap.pas +++ b/src/ce_dmdwrap.pas @@ -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)); diff --git a/src/ce_messages.pas b/src/ce_messages.pas index 4dd3be69..67aa7772 100644 --- a/src/ce_messages.pas +++ b/src/ce_messages.pas @@ -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; diff --git a/src/ce_nativeproject.pas b/src/ce_nativeproject.pas index 6ca41827..beb8b8a9 100644 --- a/src/ce_nativeproject.pas +++ b/src/ce_nativeproject.pas @@ -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); diff --git a/src/ce_projinspect.pas b/src/ce_projinspect.pas index 7f19248e..37d35ef5 100644 --- a/src/ce_projinspect.pas +++ b/src/ce_projinspect.pas @@ -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 diff --git a/src/ce_symstring.pas b/src/ce_symstring.pas index 9b841f6d..3ca1f4f9 100644 --- a/src/ce_symstring.pas +++ b/src/ce_symstring.pas @@ -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; diff --git a/src/ce_synmemo.pas b/src/ce_synmemo.pas index 6c8f6601..dbcaa731 100644 --- a/src/ce_synmemo.pas +++ b/src/ce_synmemo.pas @@ -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;