mirror of https://gitlab.com/basile.b/dexed.git
style modernisation using helpers for file name manip
This commit is contained in:
parent
bc295d3939
commit
5e2a1b8290
|
@ -48,9 +48,15 @@ type
|
|||
function isNotNil: boolean;
|
||||
end;
|
||||
|
||||
// sugar for strings
|
||||
TStringHelper = type helper for string
|
||||
function isEmpty: boolean;
|
||||
function isNotEmpty: boolean;
|
||||
function extractFileName: string;
|
||||
function extractFileExt: string;
|
||||
function extractFilePath: string;
|
||||
function fileExists: boolean;
|
||||
function dirExists: boolean;
|
||||
end;
|
||||
|
||||
(**
|
||||
|
@ -331,6 +337,31 @@ begin
|
|||
exit(self <> '');
|
||||
end;
|
||||
|
||||
function TStringHelper.extractFileName: string;
|
||||
begin
|
||||
exit(sysutils.extractFileName(self));
|
||||
end;
|
||||
|
||||
function TStringHelper.extractFileExt: string;
|
||||
begin
|
||||
exit(sysutils.extractFileExt(self));
|
||||
end;
|
||||
|
||||
function TStringHelper.extractFilePath: string;
|
||||
begin
|
||||
exit(sysutils.extractFilePath(self));
|
||||
end;
|
||||
|
||||
function TStringHelper.fileExists: boolean;
|
||||
begin
|
||||
exit(sysutils.FileExists(self));
|
||||
end;
|
||||
|
||||
function TStringHelper.dirExists: boolean;
|
||||
begin
|
||||
exit(sysutils.DirectoryExists(self));
|
||||
end;
|
||||
|
||||
{$IFDEF LINUX}
|
||||
constructor TCheckedAsyncProcess.Create(aOwner: TComponent);
|
||||
begin
|
||||
|
@ -399,7 +430,7 @@ begin
|
|||
str1.WriteComponent(aComp);
|
||||
str1.Position := 0;
|
||||
ObjectBinaryToText(str1,str2);
|
||||
ForceDirectories(ExtractFilePath(aFilename));
|
||||
ForceDirectories(aFilename.extractFilePath);
|
||||
str2.SaveToFile(aFilename);
|
||||
finally
|
||||
str1.Free;
|
||||
|
@ -777,16 +808,16 @@ begin
|
|||
if ext.isEmpty then
|
||||
anExeName += exeExt;
|
||||
//full path already specified
|
||||
if FileExists(anExeName) and (not FileExists(ExtractFileName(anExeName))) then
|
||||
if anExeName.fileExists and (not anExeName.extractFileName.fileExists) then
|
||||
exit(anExeName);
|
||||
//
|
||||
env := sysutils.GetEnvironmentVariable('PATH');
|
||||
// maybe in current dir
|
||||
if FileExists(anExeName) then
|
||||
if anExeName.fileExists then
|
||||
env += PathSeparator + GetCurrentDir;
|
||||
{$IFNDEF CEBUILD}
|
||||
if Application <> nil then
|
||||
env += PathSeparator + ExtractFileDir(ExtractFilePath(application.ExeName));
|
||||
env += PathSeparator + ExtractFileDir(application.ExeName.ExtractFilePath);
|
||||
{$ENDIF}
|
||||
exit(ExeSearch(anExeName, env));
|
||||
end;
|
||||
|
@ -950,7 +981,7 @@ begin
|
|||
try
|
||||
sink.Assign(someFiles);
|
||||
for i := sink.Count-1 downto 0 do
|
||||
if (not FileExists(sink.Strings[i])) and (not DirectoryExists(sink.Strings[i])) then
|
||||
if (not sink.Strings[i].fileExists) and (not DirectoryExists(sink.Strings[i])) then
|
||||
sink.Delete(i);
|
||||
// folders count
|
||||
cnt := 256;
|
||||
|
|
|
@ -144,7 +144,7 @@ begin
|
|||
try
|
||||
for i:= 0 to fProj.sourcesCount-1 do
|
||||
begin
|
||||
fold := extractFilePath(fProj.sourceAbsolute(i));
|
||||
fold := fProj.sourceAbsolute(i).extractFilePath;
|
||||
if folds.IndexOf(fold) = -1 then
|
||||
folds.Add(fold);
|
||||
end;
|
||||
|
|
|
@ -443,7 +443,7 @@ begin
|
|||
fTokList.Clear;
|
||||
fErrList.Clear;
|
||||
end;
|
||||
if md.isEmpty then md := extractFileName(fDoc.fileName);
|
||||
if md.isEmpty then md := fDoc.fileName.extractFileName;
|
||||
pageControl.currentPage.Caption := md;
|
||||
end;
|
||||
end;
|
||||
|
@ -481,7 +481,7 @@ begin
|
|||
fErrList.Clear;
|
||||
end;
|
||||
if md.isEmpty then
|
||||
md := extractFileName(fDoc.fileName);
|
||||
md := fDoc.fileName.extractFileName;
|
||||
pageControl.currentPage.Caption := md;
|
||||
end;
|
||||
{$ENDREGION}
|
||||
|
|
|
@ -189,7 +189,7 @@ begin
|
|||
case fType of
|
||||
ptFile:
|
||||
with TOpenDialog.create(nil) do try
|
||||
InitialDir := ExtractFileName(GetValue);
|
||||
InitialDir := GetValue.extractFileName;
|
||||
FileName := GetValue;
|
||||
if Execute then SetValue(FileName);
|
||||
finally
|
||||
|
|
|
@ -438,13 +438,13 @@ begin
|
|||
filename := ini;
|
||||
if Execute then
|
||||
begin
|
||||
if not fileExists(filename) then
|
||||
List.Selected.SubItems[0] := extractFilePath(filename)
|
||||
if not filename.fileExists then
|
||||
List.Selected.SubItems[0] := filename.extractFilePath
|
||||
else
|
||||
begin
|
||||
List.Selected.SubItems[0] := filename;
|
||||
if (List.Selected.Caption.isEmpty) or (List.Selected.Caption = notav) then
|
||||
List.Selected.Caption := ChangeFileExt(extractFileName(filename), '');
|
||||
List.Selected.Caption := ChangeFileExt(filename.extractFileName, '');
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
|
|
|
@ -1470,7 +1470,7 @@ object CEMainForm: TCEMainForm
|
|||
OnCloseQuery = FormCloseQuery
|
||||
OnDropFiles = FormDropFiles
|
||||
ShowHint = True
|
||||
LCLVersion = '1.6.0.1'
|
||||
LCLVersion = '1.6.0.2'
|
||||
Visible = False
|
||||
object mainMenu: TMainMenu
|
||||
Images = imgList
|
||||
|
|
|
@ -1077,9 +1077,8 @@ begin
|
|||
getprocInputHandler.addProcess(nil);
|
||||
end;
|
||||
killProcess(fRunProc);
|
||||
if fileExists(fname) then
|
||||
if ExtractFilePath(fname) = GetTempDir(false) then
|
||||
sysutils.DeleteFile(fname);
|
||||
if fname.fileExists and (fname.extractFilePath = GetTempDir(false)) then
|
||||
sysutils.DeleteFile(fname);
|
||||
end;
|
||||
|
||||
procedure TCEMainForm.SaveLastDocsAndProj;
|
||||
|
@ -1504,7 +1503,7 @@ begin
|
|||
if not fileExists(fProjectInterface.filename) then exit;
|
||||
//
|
||||
DockMaster.GetAnchorSite(fExplWidg).Show;
|
||||
fExplWidg.expandPath(extractFilePath(fProjectInterface.filename));
|
||||
fExplWidg.expandPath(fProjectInterface.filename.extractFilePath);
|
||||
end;
|
||||
|
||||
procedure TCEMainForm.actFileNewExecute(Sender: TObject);
|
||||
|
@ -1856,7 +1855,7 @@ begin
|
|||
dmdproc.Options := [poUsePipes, poStderrToOutPut];
|
||||
dmdproc.Executable := 'dmd';
|
||||
dmdproc.Parameters.Add(fDoc.fileName);
|
||||
dmdproc.Parameters.Add('-J' + ExtractFilePath(fDoc.fileName));
|
||||
dmdproc.Parameters.Add('-J' + fDoc.fileName.extractFilePath);
|
||||
dmdproc.Parameters.AddText(fRunnableSw);
|
||||
CommandToList(firstlineFlags, extraArgs);
|
||||
dmdproc.Parameters.AddStrings(extraArgs);
|
||||
|
@ -1934,7 +1933,7 @@ begin
|
|||
if not fileExists(fDoc.fileName) then exit;
|
||||
//
|
||||
DockMaster.GetAnchorSite(fExplWidg).Show;
|
||||
fExplWidg.expandPath(extractFilePath(fDoc.fileName));
|
||||
fExplWidg.expandPath(fDoc.fileName.extractFilePath);
|
||||
end;
|
||||
|
||||
procedure TCEMainForm.actProjCompileExecute(Sender: TObject);
|
||||
|
@ -2045,7 +2044,7 @@ begin
|
|||
DockMaster.GetAnchorSite(fWidgList.widget[i]).Close;
|
||||
end;
|
||||
//
|
||||
forceDirectory(extractFilePath(aFilename));
|
||||
forceDirectory(aFilename.extractFilePath);
|
||||
xcfg := TXMLConfigStorage.Create(aFilename + '.tmp', false);
|
||||
try
|
||||
DockMaster.SaveLayoutToConfig(xcfg);
|
||||
|
@ -2088,7 +2087,7 @@ begin
|
|||
for i := 0 to lst.Count-1 do
|
||||
begin
|
||||
itm := TMenuItem.Create(self);
|
||||
itm.Caption := extractFileName(lst.Strings[i]);
|
||||
itm.Caption := lst.Strings[i].extractFileName;
|
||||
itm.Caption := stripFileExt(itm.Caption);
|
||||
itm.OnClick := @layoutMnuItemClick;
|
||||
itm.ImageIndex := 32;
|
||||
|
@ -2112,8 +2111,8 @@ begin
|
|||
if not InputQuery('New layout name', '', fname) then
|
||||
exit;
|
||||
//
|
||||
fname := extractFileName(fname);
|
||||
if extractFileExt(fname) <> '.xml' then
|
||||
fname := fname.extractFileName;
|
||||
if fname.extractFileExt <> '.xml' then
|
||||
fname += '.xml';
|
||||
layoutSaveToFile(getCoeditDocPath + 'layouts' + DirectorySeparator + fname);
|
||||
layoutUpdateMenu;
|
||||
|
|
|
@ -320,7 +320,7 @@ begin
|
|||
lstFiles.BeginUpdate;
|
||||
for fname in aList do
|
||||
begin
|
||||
itemText := extractFileName(fname);
|
||||
itemText := fname.extractFileName;
|
||||
if noFilter or AnsiContainsText(itemText,lstFilter.Filter) then
|
||||
begin
|
||||
itm := lstFiles.Items.Add;
|
||||
|
@ -484,7 +484,7 @@ begin
|
|||
listFolders(lst, PString(aRoot.Data)^ + directorySeparator);
|
||||
for fold in lst do
|
||||
begin
|
||||
itm := Tree.Items.AddChild(aRoot, extractFileName(fold));
|
||||
itm := Tree.Items.AddChild(aRoot, fold.extractFileName);
|
||||
itm.Data := NewStr(fold);
|
||||
itm.ImageIndex := 1;
|
||||
itm.SelectedIndex := 1;
|
||||
|
|
|
@ -228,7 +228,7 @@ begin
|
|||
|
||||
fFilename := aValue;
|
||||
oldBase := fBasePath;
|
||||
fBasePath := extractFilePath(fFilename);
|
||||
fBasePath := fFilename.extractFilePath;
|
||||
//
|
||||
for i:= 0 to fSrcs.Count-1 do
|
||||
begin
|
||||
|
@ -414,7 +414,7 @@ begin
|
|||
begin
|
||||
abs := expandFilenameEx(fBasePath, rel);
|
||||
if ex_files.IndexOf(abs) = -1 then
|
||||
if ex_folds.IndexOf(ExtractFilePath(abs)) = -1
|
||||
if ex_folds.IndexOf(abs.extractFilePath) = -1
|
||||
then aList.Add(abs); // note: process.inc ln 249. double quotes are added if there's a space.
|
||||
end;
|
||||
// libraries: an asterisk in list selects all the entries
|
||||
|
@ -493,7 +493,7 @@ var
|
|||
dirHint := fSrcs.Strings[i];
|
||||
while (dirHint[1] = '.') or (dirHint[1] = DirectorySeparator) do
|
||||
dirHint := dirHint[2..length(dirHint)];
|
||||
ini := extractFilePath(fFilename);
|
||||
ini := fFilename.extractFilePath;
|
||||
if not selectDirectory( format('select the folder (that contains "%s")',[dirHint]), ini, newdir) then
|
||||
exit;
|
||||
for i := 0 to fSrcs.Count-1 do
|
||||
|
@ -524,11 +524,11 @@ var
|
|||
//
|
||||
opendlg := TOpenDialog.Create(nil);
|
||||
try
|
||||
opendlg.InitialDir := extractFilePath(fFilename);
|
||||
opendlg.InitialDir := fFilename.extractFilePath;
|
||||
opendlg.FileName := fSrcs[i];
|
||||
if opendlg.execute then
|
||||
begin
|
||||
if ExtractFileName(oldsrc) <> ExtractFileName(opendlg.filename) then
|
||||
if oldsrc.extractFileName <> opendlg.filename.extractFileName then
|
||||
if dlgOkCancel('the filenames are different, replace the old file ?') <> mrOk then
|
||||
continue;
|
||||
fSrcs[i] := ExtractRelativepath(fBasePath, opendlg.Filename);
|
||||
|
@ -625,10 +625,10 @@ begin
|
|||
else if Sources.Count > 0 then
|
||||
begin
|
||||
// ideally, main() should be searched for, when project binaryKind is executable
|
||||
fOutputFilename := extractFilename(Sources.Strings[0]);
|
||||
fOutputFilename := Sources.Strings[0].extractFileName;
|
||||
fOutputFilename := stripFileExt(fOutputFilename);
|
||||
if FileExists(fileName) then
|
||||
fOutputFilename := extractFilePath(fileName) + fOutputFilename
|
||||
if fileName.fileExists then
|
||||
fOutputFilename := fileName.extractFilePath + fOutputFilename
|
||||
else
|
||||
fOutputFilename := GetTempDir(false) + fOutputFilename;
|
||||
// force extension
|
||||
|
@ -701,7 +701,7 @@ begin
|
|||
msgs.clearByData(self as ICECommonProject);
|
||||
subjProjCompiling(fProjectSubject, Self);
|
||||
//
|
||||
prjpath := extractFilePath(fFileName);
|
||||
prjpath := fFileName.extractFilePath;
|
||||
oldCwd := GetCurrentDir;
|
||||
SetCurrentDir(prjpath);
|
||||
//
|
||||
|
@ -789,7 +789,7 @@ begin
|
|||
if fRunner.CurrentDirectory.isEmpty then
|
||||
begin
|
||||
fRunnerOldCwd := GetCurrentDir;
|
||||
cwd := extractFilePath(fRunner.Executable);
|
||||
cwd := fRunner.Executable.extractFilePath;
|
||||
chDir(cwd);
|
||||
fRunner.CurrentDirectory := cwd;
|
||||
end;
|
||||
|
|
|
@ -28,7 +28,7 @@ inherited CEProjectInspectWidget: TCEProjectInspectWidget
|
|||
Align = alClient
|
||||
AutoExpand = True
|
||||
BorderSpacing.Around = 2
|
||||
DefaultItemHeight = 16
|
||||
DefaultItemHeight = 18
|
||||
Images = imgList
|
||||
ReadOnly = True
|
||||
RightClickSelect = True
|
||||
|
|
|
@ -243,9 +243,9 @@ begin
|
|||
//
|
||||
with TOpenDialog.Create(nil) do
|
||||
try
|
||||
if FileExists(fLastFileOrFolder) then
|
||||
InitialDir := ExtractFilePath(fLastFileOrFolder)
|
||||
else if DirectoryExists(fLastFileOrFolder) then
|
||||
if fLastFileOrFolder.fileExists then
|
||||
InitialDir := fLastFileOrFolder.extractFilePath
|
||||
else if fLastFileOrFolder.dirExists then
|
||||
InitialDir := fLastFileOrFolder;
|
||||
filter := DdiagFilter;
|
||||
if execute then
|
||||
|
@ -268,12 +268,12 @@ begin
|
|||
if fProject.isNil then exit;
|
||||
//
|
||||
dir := '';
|
||||
if FileExists(fLastFileOrFolder) then
|
||||
dir := extractFilePath(fLastFileOrFolder)
|
||||
else if DirectoryExists(fLastFileOrFolder) then
|
||||
if fLastFileOrFolder.fileExists then
|
||||
dir := fLastFileOrFolder.extractFilePath
|
||||
else if fLastFileOrFolder.dirExists then
|
||||
dir := fLastFileOrFolder
|
||||
else if fileExists(fProject.fileName) then
|
||||
dir := extractFilePath(fProject.fileName);
|
||||
else if fProject.fileName.fileExists then
|
||||
dir := fProject.fileName.extractFilePath;
|
||||
if selectDirectory('sources', dir, dir, true, 0) then
|
||||
begin
|
||||
fProject.beginUpdate;
|
||||
|
@ -306,12 +306,12 @@ begin
|
|||
i := fProject.Sources.IndexOf(fname);
|
||||
if i = -1 then exit;
|
||||
fname := fProject.sourceAbsolute(i);
|
||||
dir := extractFilePath(fname);
|
||||
if not DirectoryExists(dir) then exit;
|
||||
dir := fname.extractFilePath;
|
||||
if not dir.dirExists then exit;
|
||||
//
|
||||
fProject.beginUpdate;
|
||||
for i:= fProject.Sources.Count-1 downto 0 do
|
||||
if extractFilePath(fProject.sourceAbsolute(i)) = dir then
|
||||
if fProject.sourceAbsolute(i).extractFilePath = dir then
|
||||
fProject.Sources.Delete(i);
|
||||
fProject.endUpdate;
|
||||
end;
|
||||
|
|
|
@ -167,14 +167,14 @@ begin
|
|||
//
|
||||
// application
|
||||
fSymbols[CAF] := Application.ExeName;
|
||||
fSymbols[CAP] := ExtractFilePath(fSymbols[CAF]);
|
||||
fSymbols[CAP] := fSymbols[CAF].extractFilePath;
|
||||
// document
|
||||
if hasDoc then
|
||||
begin
|
||||
if not fileExists(fDoc.fileName) then
|
||||
fDoc.saveTempFile;
|
||||
fSymbols[CFF] := fDoc.fileName;
|
||||
fSymbols[CFP] := ExtractFilePath(fDoc.fileName);
|
||||
fSymbols[CFP] := fDoc.fileName.extractFilePath;
|
||||
if fDoc.Identifier.isNotEmpty then
|
||||
fSymbols[CI] := fDoc.Identifier;
|
||||
end;
|
||||
|
@ -183,8 +183,8 @@ begin
|
|||
begin
|
||||
fname := fProjInterface.filename;
|
||||
fSymbols[CPF] := fname;
|
||||
fSymbols[CPP] := ExtractFilePath(fSymbols[CPF]);
|
||||
fSymbols[CPN] := stripFileExt(extractFileName(fSymbols[CPF]));
|
||||
fSymbols[CPP] := fSymbols[CPF].extractFilePath;
|
||||
fSymbols[CPN] := stripFileExt(fSymbols[CPF].extractFileName);
|
||||
fSymbols[CPO] := fProjInterface.outputFilename;
|
||||
if fProjInterface.sourcesCount <> 0 then
|
||||
begin
|
||||
|
@ -193,7 +193,7 @@ begin
|
|||
for i := 0 to fProjInterface.sourcesCount-1 do
|
||||
begin
|
||||
fname := fProjInterface.sourceAbsolute(i);
|
||||
if not isEditable(ExtractFileExt(fname)) then
|
||||
if not isEditable(fname.extractFileExt) then
|
||||
continue;
|
||||
str.Add(fname);
|
||||
end;
|
||||
|
|
Loading…
Reference in New Issue