unit FolderDlgWin;

{$WARN UNIT_PLATFORM OFF}
{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Windows, SysUtils, Forms, Classes, Controls, StdCtrls, Buttons, ComCtrls,
  _SimpleDialog,_const, FileCtrl;

type
  TFolderDlg = class(TForm)
    DriveLst: TDriveComboBox;
    DirectoryLst: TDirectoryListBox;
    OKBtn: TBitBtn;
    CancelBtn: TBitBtn;
    StatusBar: TStatusBar;
    FileLst: TFileListBox;
    CreateBtn: TBitBtn;
    procedure FormResize(Sender: TObject);
    procedure DirectoryLstChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CreateBtnClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private 宣言 }
    DecDirLstHeight:integer;
    DecBtnTop:integer;
    StartDir:string;
  public
    { Public 宣言 }
    procedure OpenDlg(DefPath:string);
  end;

var
  FolderDlg: TFolderDlg;

implementation

{$R *.DFM}

procedure TFolderDlg.OpenDlg(DefPath:string);
begin
  if DirectoryExists(DefPath)=False then DefPath:=StartDir;
  DriveLst.Drive:=DefPath[1];
  DirectoryLst.Directory:=DefPath;
  FolderDlg.Visible:=False;
end;

procedure TFolderDlg.FormResize(Sender: TObject);
var
  Width,Height:integer;
begin
  Width:=FolderDlg.ClientWidth;
  Height:=FolderDlg.ClientHeight;

  DriveLst.Width:=Width;
  DirectoryLst.Width:=Width div 2;
  DirectoryLst.Height:=Height-DecDirLstHeight;
  FileLst.Left:=Width div 2;
  FileLst.Width:=Width div 2;
  FileLst.Height:=Height-DecDirLstHeight;
  DirectoryLst.Height:=Height-DecDirLstHeight;
  OKBtn.Top:=Height-DecBtnTop;
  CancelBtn.Top:=OKBtn.Top;
end;

procedure TFolderDlg.DirectoryLstChange(Sender: TObject);
begin
  StatusBar.SimpleText:=DirectoryLst.Directory;
end;

procedure TFolderDlg.FormCreate(Sender: TObject);
begin
  StartDir:=ExtractFileDir(Application.ExeName)+'\';
  DecDirLstHeight:=FolderDlg.ClientHeight-DirectoryLst.Height;
  DecBtnTop:=FolderDlg.ClientHeight-OKBtn.Top;
end;

procedure TFolderDlg.CreateBtnClick(Sender: TObject);
var
  NewDir:string;
begin
  NewDir:='';
  if InputQuery('フォルダの新規作成','作成するフォルダ名を入力してください。',NewDir)=True then begin
    if NewDir='' then exit;
    if (AnsiPos('\',NewDir)<>0) or (AnsiPos('.',NewDir)<>0) or (AnsiPos('/',NewDir)<>0) or (AnsiPos('.',NewDir)<>0) then begin
      ShowMessage('MDXWin.exe','フォルダ名に使用不可能な文字があります。');
      exit;
    end;
    NewDir:=DirectoryLst.Directory+'\'+NewDir;
    if DirectoryExists(NewDir)=True then begin
      ShowMessage('MDXWin.exe','指定されたフォルダ名は既に存在します。');
      exit;
    end;
    if CreateDir(NewDir)=False then begin
      ShowMessage('MDXWin.exe','定義されていないエラーによってフォルダが作成できませんでした。');
      end else begin
      ShowMessage('MDXWin.exe','フォルダ['+NewDir+']を作成しました。');
      DirectoryLst.Directory:=NewDir;
      DirectoryLst.Update;
    end;
  end;
end;

procedure TFolderDlg.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FolderDlg.Release;
end;

end.
