unit uMessages;
{$INCLUDE 'DirSync.inc'}

interface

uses
  {$IFDEF FAR3} Plugin3, {$ELSE} PluginW, {$ENDIF} FarKeysW, FarColor,
  uSystem, uFAR, uLog,
  uDirSyncConsts;

type
  TMessages = (
    MNoLngStringDefined = -1,
    //
    MTitle = 0,
    MOK,
    MCancel,
    MSkip,
    MSkipAll,
    MErase,
    MEraseAll,
    MRetry,
    MCmpTitle,
    MProcessBox,
    MProcessSubfolders,
    MUseMaxScanDepth,
    MProcessSelected,
    MCompareBox,
    MCompareTime,
    MCompareLowPrecision,
    MCompareIgnoreTimeZone,
    MCompareSize,
    MCompareContents,
    MCompareContentsIgnore,
    MCompareIgnoreNewLines,
    MCompareIgnoreWhitespace,
    MMessageWhenNoDiff,
    MUseSelfSettings,
    MFilePanelsRequired,
    MComparing,
    MComparingWith,
    MComparingFiles,
    MNoDiffTitle,
    MNoDiffBody,
    MNoMemTitle,
    MNoMemBody,
    MOldFARTitle,
    MOldFARBody,
    MEscTitle,
    MEscBody,
    MShowReport,
    MSynchronizeDirs,
    MCopying,
    MCopyingTo,
    MWarning,
    MLeftFileAlreadyExists,
    MRightFileAlreadyExists,
    MLeftFileReadonly,
    MRightFileReadonly,
    MLeftDirReadonly,
    MRightDirReadonly,
    MLeftFileAbsent,
    MRightFileAbsent,
    MLeftDirAbsent,
    MRightDirAbsent,
    MLeftFileErase,
    MRightFileErase,
    MLeftDirErase,
    MRightDirErase,
    MCantCreateDirectory,
    MSameFileAlreadyExists,
    MNew,
    MExisting,
    MEraseFile,
    MEraseDir,
    MDirectory,
    MOverwrite,
    MOverwriteAll,
    MFailedCopySrcFile,
    MFailedOpenSrcFile,
    MFailedOpenDstFile,
    MFailedCreateDstFile,
    MFailedEraseFile,
    MFailedEraseDir,
    MFailedCopyDstFile,
    MCopyRightToLeft,
    MOverwriteRightToLeft,
    MCopyLeftToRight,
    MOverwriteLeftToRight,
    MEraseAbsentFiles,
    MEraseAbsentFilesLeft,
    MEraseAbsentFilesRight,
    MReportFileTitle,
    MReportFileNotes1,
    MReportFileNotes2,
    MOpenErrorTitle,
    MOpenErrorBody,
    MCreateResultsFailed,
    MCreateTempFailed,
    MDeletingFile,
    MDeletingDirectory,
    MFilesAreDifferent,
    MLeftFileName,
    MRightFileName,
    MOverwriteLeft,
    MOverwriteRight,
    MAlwaysOverwriteLeft,
    MAlwaysOverwriteRight,
    MAlwaysSkip,
    MCompare,
    MBothFilesExist,
    MBothFilesExistSameDate,
    MOverwriteLeft2,
    MOverwriteRight2,
    MAskUser,
    MEditLeft,
    MEditRight,
    MCompareCommand,
    MCompareCommandArguments,
    MCompareCommandAcceptsNTFileNames,
    MVisualCompareNotSetUp,
    MKeyOverwriteLeft,
    MKeyOverwriteLeftLong,
    MKeyOverwriteRight,
    MKeyOverwriteRightLong,
    MKeyCompare,
    MKeyCompareLong,
    MKeyEditLeft,
    MKeyEditLeftLong,
    MKeyEditRight,
    MKeyEditRightLong,
    MRememberChoice,
    // These must be at the end!! They are not expected to be translated
    MExtraString1,
    MExtraString2,
    MExtraString3
  );

type
  TPFarCharArray = array of PFarChar;

function GetMsg(MsgId: TMessages): PFarChar; overload;
function GetMsg(MsgId: TMessages; const Strings: array of PFarChar): PFarChar; overload;
function GetMsgPas(MsgId: TMessages): string;
function FarMessage(const Msg: array of TMessages; Flags: TFarMessageFlags; ButtonCount: integer): integer; overload;
function FarMessage(const Msg: array of TMessages; const Strings: array of PFarChar; Flags: TFarMessageFlags; ButtonCount: integer): integer; overload;

implementation

const
  NO_MESSAGE = '';

function GetMsg(MsgId: TMessages; const Strings: array of PFarChar): PFarChar;
var
  StrIdx: integer;
begin
  if MsgId = MNoLngStringDefined then
    Result := NO_MESSAGE
  else if MsgId >= MExtraString1 then begin
    StrIdx := Integer(MsgId) - Integer(MExtraString1);
    if StrIdx < Length(Strings) then
      Result := Strings[StrIdx]
    else
      Result := NO_MESSAGE;
  end
  else
    //Result := FarApi.GetMsg( {$IFDEF FAR3} PLUGIN_GUID {$ELSE} FarApi.ModuleNumber {$ENDIF} , Integer(MsgId));
    Result := TFarUtils.GetMsg(Integer(MsgId));
end;

function GetMsg(MsgId: TMessages): PFarChar;
begin
  Result := GetMsg(MsgId, []);
end;

function GetMsgPas(MsgId: TMessages): string;
begin
  Result := TFarUtils.CopyString(GetMsg(MsgId));
end;

function FarMessage(const Msg: array of TMessages; const Strings: array of PFarChar; Flags: TFarMessageFlags; ButtonCount: integer): integer;
var
  RealMsg: array of PFarChar;
  i, n: integer;
begin
  n := Length(Msg);
  SetLength(RealMsg, n);
  for i := 0 to Pred(n) do
    RealMsg[i] := GetMsg(Msg[i], Strings);
  Result := TFarUtils.ShowMessage(RealMsg, Flags, ButtonCount);
end;

function FarMessage(const Msg: array of TMessages; Flags: TFarMessageFlags; ButtonCount: integer): integer;
begin
  Result := FarMessage(Msg, [], Flags, ButtonCount);
end;

end.
