//kt -- Modified with SourceScanner on 8/28/2007
unit fNoteIDParents;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  fAutoSz, ORCtrls, ComCtrls, StdCtrls, ORFn, DKLang;

type
  TfrmNoteIDParents = class(TfrmAutoSz)
    cmdOK: TButton;
    cmdCancel: TButton;
    lstIDParents: TORListBox;
    lblSelectParent: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure cmdCancelClick(Sender: TObject);
    procedure cmdOKClick(Sender: TObject);
  private
    //kt Begin Mod (change Consts to Vars) 8/28/2007
    TX_ATTACH_FAILURE  : string;  //kt
    //kt End Mod -------------------
    FParentNode: string;
  public
    { Public declarations }
  end;

function SelectParentNodeFromList(ATree: TORTreeView): string;

implementation

{$R *.DFM}

uses
  uTIU, rTIU, uConst;

function SelectParentNodeFromList(ATree: TORTreeView): string;
var
  frmNoteIDParents: TfrmNoteIDParents;
  i, AnImg: integer;
  x: string;
  tmpList: TStringList;
begin
  frmNoteIDParents := TfrmNoteIDParents.Create(Application);
  tmpList := TStringList.Create;
  try
    ResizeFormToFont(TForm(frmNoteIDParents));
    for i := 0 to ATree.Items.Count - 1 do
      begin
        AnImg := TORTreeNode(ATree.Items.Item[i]).ImageIndex;
        if AnImg in [IMG_SINGLE, IMG_PARENT,IMG_IDNOTE_SHUT, IMG_IDNOTE_OPEN,
                         IMG_IDPAR_ADDENDA_SHUT, IMG_IDPAR_ADDENDA_OPEN] then
          begin
            x := TORTreeNode(ATree.Items.Item[i]).Stringdata;
            tmpList.Add(Piece(x, U, 1) + U + MakeNoteDisplayText(x) + U + Piece(x, U, 3));
          end;
      end;
    SortByPiece(tmpList, U, 3);
    InvertStringList(tmpList);
    frmNoteIDParents.lstIDParents.Items.Assign(tmpList);
    frmNoteIDParents.ShowModal;
    Result := frmNoteIDParents.FParentNode;
  finally
    tmpList.Free;
    frmNoteIDParents.Release;
  end;
end;

procedure TfrmNoteIDParents.FormCreate(Sender: TObject);
begin
  inherited;
  FParentNode := '';
end;

procedure TfrmNoteIDParents.cmdCancelClick(Sender: TObject);
begin
  inherited;
  FParentNode := '';
  Close;
end;

procedure TfrmNoteIDParents.cmdOKClick(Sender: TObject);
//const
//TX_ATTACH_FAILURE = 'Attachment failed';  <-- original line.  //kt 8/28/2007
var
  WhyNot, ErrMsg: string;
  TX_ATTACH_FAILURE : string; //kt
begin
  inherited;
  TX_ATTACH_FAILURE := DKLangConstW('fNoteIDParents_Attachment_failed');
  ErrMsg := '';
  if not CanReceiveAttachment(lstIDParents.ItemID, WhyNot) then
    ErrMsg := ErrMsg + WhyNot;
  if ErrMsg <> '' then
    begin
      InfoBox(ErrMsg, TX_ATTACH_FAILURE, MB_OK);
      Exit;
    end;
  FParentNode := lstIDParents.ItemID;
  Close;
end;

end.
