{ Double Commander ------------------------------------------------------------------------- Filepanel columns implementation unit Copyright (C) 2008 Dmitry Kolomiets (B4rr4cuda@rambler.ru) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA } unit uFileFunctions; {$mode objfpc}{$H+} interface uses Classes, SysUtils, uFile, uFileProperty, uFileSource; type TFileFunction = (fsfName, fsfExtension, fsfSize, fsfAttr, fsfPath, fsfGroup, fsfOwner, fsfModificationTime, fsfCreationTime, fsfLastAccessTime, fsfLinkTo, fsfNameNoExtension, fsfType, fsfComment, fsfInvalid); TFileFunctions = array of TFileFunction; const TFileFunctionStrings: array [TFileFunction] of string = ('GETFILENAME', 'GETFILEEXT', 'GETFILESIZE', 'GETFILEATTR', 'GETFILEPATH', 'GETFILEGROUP', 'GETFILEOWNER', 'GETFILETIME', 'GETFILECREATIONTIME', 'GETFILELASTACCESSTIME', 'GETFILELINKTO', 'GETFILENAMENOEXT', 'GETFILETYPE', 'GETFILECOMMENT', '' // fsfInvalid ); // Which file properties must be supported for each file function to work. const TFileFunctionToProperty: array [TFileFunction] of TFilePropertiesTypes = ([fpName], [fpName], [fpSize], [fpAttributes], [] { path }, [fpOwner], [fpOwner], [fpModificationTime], [fpCreationTime], [fpLastAccessTime], [fpLink], [fpName], [fpType], [fpComment], [] { invalid }); function FormatFileFunction(FuncS: string; AFile: TFile; const AFileSource: IFileSource): string; function GetFileFunctionByName(FuncS: string): TFileFunction; const sFuncTypeDC = 'DC'; sFuncTypePlugin = 'PLUGIN'; var FileFunctionsStr: TStringList; implementation uses uGlobs, uDefaultFilePropertyFormatter, uFileSourceProperty; //Return type (Script or DC or Plugin etc) function GetModType(str: String): String; begin if pos('(', Str) > 0 then Result := Copy(Str, 1, pos('(', Str) - 1) else Result := EmptyStr; end; //Return name in (). (SriptName or PluginName etc) function GetModName(str: String): String; var s: String; begin s := str; if pos('(', S) > 0 then Delete(s, 1, pos('(', S)) else Exit(EmptyStr); if pos(')', s) > 0 then Result := Copy(s, 1, pos(')', s) - 1); end; //Return function name (DCFunction,PluginFunction etc) function GetModFunctionName(str: String): String; var s: String; begin s := str; if pos('.', S) > 0 then Delete(s, 1, pos('.', S)) else Exit(EmptyStr); if pos('{', S) > 0 then Result := Copy(s, 1, pos('{', S) - 1); end; // Return function parameters function GetModFunctionParams(str: String): String; var I: Integer; S: String; begin S := str; I := pos('{', S); if I < 0 then Exit(EmptyStr); Delete(S, 1, I); I := pos('}', S); if I < 0 then Exit(EmptyStr); Result := Copy(S, 1, I - 1); end; function FormatFileFunction(FuncS: String; AFile: TFile; const AFileSource: IFileSource): String; var AType, AName, AFunc, AParam: String; begin Result := EmptyStr; //--------------------- AType := upcase(GetModType(FuncS)); AName := upcase(GetModName(FuncS)); AFunc := upcase(GetModFunctionName(FuncS)); AParam := upcase(GetModFunctionParams(FuncS)); //--------------------- //Internal doublecmd function //------------------------------------------------------ if AType = sFuncTypeDC then begin case TFileFunction(FileFunctionsStr.IndexOf(AFunc)) of fsfName: begin // Show square brackets around directories if gDirBrackets and (AFile.IsDirectory or AFile.IsLinkToDirectory) then Result := '[' + AFile.Name + ']' else Result := AFile.Name; end; fsfExtension: begin if AFile.Extension <> '' then Result := '.' + AFile.Extension; end; fsfSize: begin if (AFile.IsDirectory or AFile.IsLinkToDirectory) and ((not (fpSize in AFile.SupportedProperties)) or (AFile.Size = 0)) then Result := '