{*******************************************************}
{                                                       }
{       Pascal Script Source File                       }
{       Run by RemObjects Pascal Script in CnWizards    }
{                                                       }
{       Generated by CnPack IDE Wizards                 }
{                                                       }
{*******************************************************}

program AlignEvalCode;

uses
  Windows, SysUtils, Classes, CnCommon, CnWizIdeUtils;

var
  Lines: TStringList;
  I, EqualIdx, MaxEqualIdx, InsertPos: Integer;
  ALine: string;
begin
  Lines := TStringList.Create;
  try
    if IdeGetEditorSelectedLines(Lines) then
    begin
      MaxEqualIdx := 10;
      for I := 0 to Lines.Count - 1 do
      begin
        ALine := Lines[I];
        EqualIdx := Pos('=', ALine);
        if EqualIdx > MaxEqualIdx then  // 找到最大的等于号
          MaxEqualIdx := EqualIdx;
      end;

      if MaxEqualIdx = 0 then
      begin
        ErrorDlg('No Eval Found.');
        Exit;
      end;

      for I := 0 to Lines.Count - 1 do
      begin
        ALine := Lines[I];
        EqualIdx := Pos('=', ALine);
        if (EqualIdx > 0) and (EqualIdx < MaxEqualIdx) then  // 没到最大的等于号时，在等号前或等号前的冒号前插空格
        begin
          InsertPos := EqualIdx;
          if (InsertPos > 1) and (ALine[InsertPos - 1] = ':') then
            Dec(InsertPos);
          Insert(StringOfChar(' ', MaxEqualIdx - EqualIdx), ALine, InsertPos);
          Lines[I] := ALine;
        end;
      end;

      IdeSetEditorSelectedLines(Lines);
    end;
  finally
    Lines.Free;
  end;
end.