tvplanit: Cosmetic changes in WavDlg (use ModalResult)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4745 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-06-14 10:33:10 +00:00
parent 8c34f2a85a
commit 4493e26898
3 changed files with 42 additions and 83 deletions

View File

@ -670,21 +670,20 @@ procedure TDlgEventEdit.SoundFinderBtnClick(Sender: TObject);
var var
SoundFinder: TfrmSoundDialog; SoundFinder: TfrmSoundDialog;
begin begin
Application.CreateForm(TfrmSoundDialog, SoundFinder); SoundFinder := TFrmSoundDialog.Create(nil);
try try
SoundFinder.DingPath := AlarmWavPath; SoundFinder.DingPath := AlarmWavPath;
SoundFinder.MediaFolder := Datastore.MediaFolder; SoundFinder.MediaFolder := Datastore.MediaFolder;
SoundFinder.OnPlaySound := DoPlaySound; SoundFinder.OnPlaySound := DoPlaySound;
SoundFinder.Populate; SoundFinder.Populate;
SoundFinder.ShowModal; if SoundFinder.ShowModal = mrOK then begin
if SoundFinder.ReturnCode = TvpEditorReturnCode(rtCommit) then begin
if SoundFinder.CBDefault.Checked then if SoundFinder.CBDefault.Checked then
AlarmWavPath := '' AlarmWavPath := ''
else else
AlarmWavPath := SoundFinder.GetSelectedFilename; AlarmWavPath := SoundFinder.GetSelectedFilename;
end; end;
finally finally
SoundFinder.Release; SoundFinder.Free;
end; end;
end; end;
{=====} {=====}

View File

@ -10,7 +10,6 @@ object FrmSoundDialog: TFrmSoundDialog
ClientWidth = 736 ClientWidth = 736
KeyPreview = True KeyPreview = True
OnCreate = FormCreate OnCreate = FormCreate
OnKeyDown = FormKeyDown
Position = poScreenCenter Position = poScreenCenter
LCLVersion = '1.7' LCLVersion = '1.7'
object PageControl1: TPageControl object PageControl1: TPageControl
@ -102,7 +101,7 @@ object FrmSoundDialog: TFrmSoundDialog
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
Caption = 'OkBtn' Caption = 'OkBtn'
Default = True Default = True
OnClick = OkBtnClick ModalResult = 1
TabOrder = 0 TabOrder = 0
end end
object CancelBtn: TButton object CancelBtn: TButton
@ -111,8 +110,9 @@ object FrmSoundDialog: TFrmSoundDialog
Top = 8 Top = 8
Width = 75 Width = 75
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
Cancel = True
Caption = 'CancelBtn' Caption = 'CancelBtn'
OnClick = CancelBtnClick ModalResult = 2
TabOrder = 1 TabOrder = 1
end end
end end

View File

@ -62,24 +62,17 @@ type
CBDefault: TCheckBox; CBDefault: TCheckBox;
OkBtn: TButton; OkBtn: TButton;
CancelBtn: TButton; CancelBtn: TButton;
procedure FileListBox1Change(Sender: TObject);
procedure PlayButtonClick(Sender: TObject);
procedure CBDefaultClick(Sender: TObject); procedure CBDefaultClick(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure OkBtnClick(Sender: TObject); procedure PlayButtonClick(Sender: TObject);
procedure CancelBtnClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private private
FMediaFolder: String;
FOnPlaySound: TVpPlaySoundEvent; FOnPlaySound: TVpPlaySoundEvent;
function FindFileItem(AFilename: String): TListItem; function FindFileItem(AFilename: String): TListItem;
public public
DingPath: string; DingPath: string;
ReturnCode : TVpEditorReturnCode; MediaFolder: String;
function GetSelectedFileName: String; function GetSelectedFileName: String;
procedure Populate; procedure Populate;
property MediaFolder: String read FMediaFolder write FMediaFolder;
property OnPlaySound: TVpPlaySoundEvent read FOnPlaySound write FOnPlaySound; property OnPlaySound: TVpPlaySoundEvent read FOnPlaySound write FOnPlaySound;
end; end;
@ -95,25 +88,13 @@ uses
{$R *.dfm} {$R *.dfm}
{$ENDIF} {$ENDIF}
procedure TFrmSoundDialog.FileListBox1Change(Sender: TObject); procedure TFrmSoundDialog.CBDefaultClick(Sender: TObject);
begin begin
if ShellListview.Items.Count > 0 then begin ShellTreeview.Visible := not CBDefault.Checked;
PlayButton.Enabled := true; ShellListview.Visible := not CBDefault.Checked;
DingPath := GetSelectedFileName; Panel3.Visible := CBDefault.Checked;
end else begin Panel4.Visible := CBDefault.Checked;
PlayButton.Enabled := false; PlayButton.Visible := not CBDefault.Checked;
DingPath := '';
end;
end;
{=====}
procedure TFrmSoundDialog.PlayButtonClick(Sender: TObject);
begin
if Assigned(FOnPlaySound) then begin
PlayButton.Enabled := false;
FOnPlaySound(self, GetSelectedFileName, psmSync);
PlayButton.Enabled := true;
end;
end; end;
{=====} {=====}
@ -130,6 +111,32 @@ begin
Result := nil; Result := nil;
end; end;
procedure TFrmSoundDialog.FormCreate(Sender: TObject);
begin
Panel3.Align := alClient;
Panel4.Align := alClient;
end;
{=====}
function TFrmSoundDialog.GetSelectedFileName: String;
begin
if ShellListview.Selected <> nil then
Result := IncludeTrailingPathDelimiter(ShellTreeView.Path) + ShellListview.Selected.Caption
else
Result := '';
end;
procedure TFrmSoundDialog.PlayButtonClick(Sender: TObject);
begin
DingPath := GetSelectedFileName;
if Assigned(FOnPlaySound) then begin
PlayButton.Enabled := false;
FOnPlaySound(self, DingPath, psmSync);
PlayButton.Enabled := true;
end;
end;
{=====}
procedure TFrmSoundDialog.Populate; procedure TFrmSoundDialog.Populate;
begin begin
TabSheet1.Caption := RSSelectASound; TabSheet1.Caption := RSSelectASound;
@ -141,64 +148,17 @@ begin
Panel4.Caption := RSNothingToSelectFrom; Panel4.Caption := RSNothingToSelectFrom;
if DingPath = '' then begin if DingPath = '' then begin
CBDefault.Checked := true; CBDefault.Checked := true;
ShellTreeView.Path := FMediaFolder; //ExtractFileDir(ParamStr(0)); ShellTreeView.Path := MediaFolder;
end else end else
if FileExists(DingPath) then begin if FileExists(DingPath) then begin
ShellTreeview.Path := ExtractFileDir(DingPath); ShellTreeview.Path := ExtractFileDir(DingPath);
ShellListview.Selected := FindFileItem(DingPath); ShellListview.Selected := FindFileItem(DingPath);
end else begin end else begin
ShellTreeView.Path := FMediaFolder; //ExtractFileDir(ParamStr(0)); ShellTreeView.Path := MediaFolder;
end; end;
CBDefaultClick(nil); CBDefaultClick(nil);
end; end;
{=====} {=====}
procedure TFrmSoundDialog.CBDefaultClick(Sender: TObject);
begin
ShellTreeview.Visible := not CBDefault.Checked;
ShellListview.Visible := not CBDefault.Checked;
Panel3.Visible := CBDefault.Checked;
Panel4.Visible := CBDefault.Checked;
PlayButton.Visible := not CBDefault.Checked;
end;
{=====}
procedure TFrmSoundDialog.FormCreate(Sender: TObject);
begin
Panel3.Align := alClient;
Panel4.Align := alClient;
ReturnCode := rtAbandon;
end;
{=====}
procedure TFrmSoundDialog.OkBtnClick(Sender: TObject);
begin
ReturnCode := rtCommit;
Close;
end;
{=====}
procedure TFrmSoundDialog.CancelBtnClick(Sender: TObject);
begin
Close;
end;
{=====}
procedure TFrmSoundDialog.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_ESCAPE then
Close;
end;
function TFrmSoundDialog.GetSelectedFileName: String;
begin
if ShellListview.ItemFocused <> nil then
Result := IncludeTrailingPathDelimiter(ShellTreeView.Path) + ShellListview.ItemFocused.Caption
else
Result := '';
end;
end. end.