lcl: Standard File Actions

git-svn-id: trunk@15110 -
This commit is contained in:
paul 2008-05-13 02:38:38 +00:00
parent 51461c2471
commit 93831090cb
6 changed files with 186 additions and 96 deletions

View File

@ -4,10 +4,12 @@ object Form1: TForm1
Top = 164
Width = 277
HorzScrollBar.Page = 276
VertScrollBar.Page = 163
VertScrollBar.Page = 143
Caption = 'Standard actions demo'
ClientHeight = 164
ClientHeight = 144
ClientWidth = 277
Menu = MainMenu1
OnCloseQuery = FormCloseQuery
LCLVersion = '0.9.25'
object Edit1: TEdit
AnchorSideLeft.Control = Owner
@ -79,7 +81,7 @@ object Form1: TForm1
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 5
Height = 100
Height = 80
Top = 59
Width = 267
Anchors = [akTop, akLeft, akRight, akBottom]
@ -137,5 +139,66 @@ object Form1: TForm1
Hint = 'Delete'
ShortCut = 46
end
object FileOpen1: TFileOpen
Category = 'File'
Caption = '&Open...'
Hint = 'Open'
ShortCut = 16463
end
object FileOpenWith1: TFileOpenWith
Category = 'File'
Caption = 'Open with...'
Hint = 'Open'
end
object FileSaveAs1: TFileSaveAs
Category = 'File'
Caption = 'Save &As...'
Hint = 'Save As'
end
object FileExit1: TFileExit
Category = 'File'
Caption = 'E&xit'
Hint = 'Exit'
end
end
object MainMenu1: TMainMenu
left = 213
top = 32
object MenuItem8: TMenuItem
Caption = 'File'
object MenuItem11: TMenuItem
Action = FileOpen1
end
object MenuItem13: TMenuItem
Action = FileOpenWith1
end
object MenuItem16: TMenuItem
Action = FileSaveAs1
end
object MenuItem17: TMenuItem
Action = FileExit1
end
end
object MenuItem1: TMenuItem
Caption = 'Edit'
object MenuItem2: TMenuItem
Action = EditCut1
end
object MenuItem3: TMenuItem
Action = EditCopy1
end
object MenuItem4: TMenuItem
Action = EditPaste1
end
object MenuItem5: TMenuItem
Action = EditSelectAll1
end
object MenuItem6: TMenuItem
Action = EditDelete1
end
object MenuItem7: TMenuItem
Action = EditUndo1
end
end
end
end

View File

@ -2,42 +2,59 @@
LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'"'#1#6'Height'#3#164#0#3'Top'#3#164#0#5'W'
+'idth'#3#21#1#18'HorzScrollBar.Page'#3#20#1#18'VertScrollBar.Page'#3#163#0#7
+'Caption'#6#21'Standard actions demo'#12'ClientHeight'#3#164#0#11'ClientWidt'
+'h'#3#21#1#10'LCLVersion'#6#6'0.9.25'#0#5'TEdit'#5'Edit1'#22'AnchorSideLeft.'
+'Control'#7#5'Owner'#21'AnchorSideTop.Control'#7#8'ToolBar1'#18'AnchorSideTo'
+'p.Side'#7#9'asrBottom'#23'AnchorSideRight.Control'#7#5'Owner'#20'AnchorSide'
+'Right.Side'#7#9'asrBottom'#4'Left'#2#5#6'Height'#2#23#3'Top'#2#31#5'Width'#3
+#11#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#18'BorderSpacing.Left'#2
+#5#17'BorderSpacing.Top'#2#5#19'BorderSpacing.Right'#2#5#8'TabOrder'#2#0#4'T'
+'ext'#6#5'Edit1'#0#0#8'TToolBar'#8'ToolBar1'#6'Height'#2#26#5'Width'#3#21#1#7
+'Caption'#6#8'ToolBar1'#4'Flat'#9#12'ShowCaptions'#9#8'TabOrder'#2#1#0#11'TT'
+'oolButton'#11'ToolButton1'#4'Left'#2#1#4'Hint'#6#3'Cut'#3'Top'#2#2#6'Action'
+#7#8'EditCut1'#0#0#11'TToolButton'#11'ToolButton2'#4'Left'#2'!'#4'Hint'#6#4
+'Copy'#3'Top'#2#2#6'Action'#7#9'EditCopy1'#0#0#11'TToolButton'#11'ToolButton'
+'3'#4'Left'#2'I'#4'Hint'#6#5'Paste'#3'Top'#2#2#6'Action'#7#10'EditPaste1'#0#0
+#11'TToolButton'#11'ToolButton4'#4'Left'#2's'#4'Hint'#6#10'Select All'#3'Top'
+#2#2#6'Action'#7#14'EditSelectAll1'#0#0#11'TToolButton'#11'ToolButton5'#4'Le'
+'ft'#3#173#0#4'Hint'#6#6'Delete'#3'Top'#2#2#6'Action'#7#11'EditDelete1'#0#0
+#11'TToolButton'#11'ToolButton6'#4'Left'#3#219#0#4'Hint'#6#4'Undo'#3'Top'#2#2
+#6'Action'#7#9'EditUndo1'#0#0#0#5'TMemo'#5'Memo1'#22'AnchorSideLeft.Control'
+#7#5'Owner'#21'AnchorSideTop.Control'#7#5'Edit1'#18'AnchorSideTop.Side'#7#9
+'asrBottom'#23'AnchorSideRight.Control'#7#5'Owner'#20'AnchorSideRight.Side'#7
+#9'asrBottom'#24'AnchorSideBottom.Control'#7#5'Owner'#21'AnchorSideBottom.Si'
+'de'#7#9'asrBottom'#4'Left'#2#5#6'Height'#2'd'#3'Top'#2';'#5'Width'#3#11#1#7
+'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#18'BorderSpacing.Le'
+'ft'#2#5#17'BorderSpacing.Top'#2#5#19'BorderSpacing.Right'#2#5#20'BorderSpac'
+'ing.Bottom'#2#5#13'Lines.Strings'#1#6#5'Memo1'#0#8'TabOrder'#2#2#0#0#11'TAc'
+'tionList'#11'ActionList1'#4'left'#3#184#0#3'top'#2' '#0#8'TEditCut'#8'EditC'
+'ut1'#8'Category'#6#4'Edit'#7'Caption'#6#4'Cu&t'#18'DisableIfNoHandler'#9#4
+'Hint'#6#3'Cut'#8'ShortCut'#3'X@'#0#0#9'TEditCopy'#9'EditCopy1'#8'Category'#6
+#4'Edit'#7'Caption'#6#5'&Copy'#18'DisableIfNoHandler'#9#4'Hint'#6#4'Copy'#8
+'ShortCut'#3'C@'#0#0#10'TEditPaste'#10'EditPaste1'#8'Category'#6#4'Edit'#7'C'
+'aption'#6#6'&Paste'#18'DisableIfNoHandler'#9#4'Hint'#6#5'Paste'#8'ShortCut'
+#3'V@'#0#0#14'TEditSelectAll'#14'EditSelectAll1'#8'Category'#6#4'Edit'#7'Cap'
+'tion'#6#11'Select &All'#18'DisableIfNoHandler'#9#4'Hint'#6#10'Select All'#8
+'ShortCut'#3'A@'#0#0#9'TEditUndo'#9'EditUndo1'#8'Category'#6#4'Edit'#7'Capti'
+'on'#6#5'&Undo'#18'DisableIfNoHandler'#9#4'Hint'#6#4'Undo'#8'ShortCut'#3'Z@'
+#0#0#11'TEditDelete'#11'EditDelete1'#8'Category'#6#4'Edit'#7'Caption'#6#7'&D'
+'elete'#18'DisableIfNoHandler'#9#4'Hint'#6#6'Delete'#8'ShortCut'#2'.'#0#0#0#0
+'idth'#3#21#1#18'HorzScrollBar.Page'#3#20#1#18'VertScrollBar.Page'#3#143#0#7
+'Caption'#6#21'Standard actions demo'#12'ClientHeight'#3#144#0#11'ClientWidt'
+'h'#3#21#1#4'Menu'#7#9'MainMenu1'#12'OnCloseQuery'#7#14'FormCloseQuery'#10'L'
+'CLVersion'#6#6'0.9.25'#0#5'TEdit'#5'Edit1'#22'AnchorSideLeft.Control'#7#5'O'
+'wner'#21'AnchorSideTop.Control'#7#8'ToolBar1'#18'AnchorSideTop.Side'#7#9'as'
+'rBottom'#23'AnchorSideRight.Control'#7#5'Owner'#20'AnchorSideRight.Side'#7#9
+'asrBottom'#4'Left'#2#5#6'Height'#2#23#3'Top'#2#31#5'Width'#3#11#1#7'Anchors'
+#11#5'akTop'#6'akLeft'#7'akRight'#0#18'BorderSpacing.Left'#2#5#17'BorderSpac'
+'ing.Top'#2#5#19'BorderSpacing.Right'#2#5#8'TabOrder'#2#0#4'Text'#6#5'Edit1'
+#0#0#8'TToolBar'#8'ToolBar1'#6'Height'#2#26#5'Width'#3#21#1#7'Caption'#6#8'T'
+'oolBar1'#4'Flat'#9#12'ShowCaptions'#9#8'TabOrder'#2#1#0#11'TToolButton'#11
+'ToolButton1'#4'Left'#2#1#4'Hint'#6#3'Cut'#3'Top'#2#2#6'Action'#7#8'EditCut1'
+#0#0#11'TToolButton'#11'ToolButton2'#4'Left'#2'!'#4'Hint'#6#4'Copy'#3'Top'#2
+#2#6'Action'#7#9'EditCopy1'#0#0#11'TToolButton'#11'ToolButton3'#4'Left'#2'I'
+#4'Hint'#6#5'Paste'#3'Top'#2#2#6'Action'#7#10'EditPaste1'#0#0#11'TToolButton'
+#11'ToolButton4'#4'Left'#2's'#4'Hint'#6#10'Select All'#3'Top'#2#2#6'Action'#7
+#14'EditSelectAll1'#0#0#11'TToolButton'#11'ToolButton5'#4'Left'#3#173#0#4'Hi'
+'nt'#6#6'Delete'#3'Top'#2#2#6'Action'#7#11'EditDelete1'#0#0#11'TToolButton'
+#11'ToolButton6'#4'Left'#3#219#0#4'Hint'#6#4'Undo'#3'Top'#2#2#6'Action'#7#9
+'EditUndo1'#0#0#0#5'TMemo'#5'Memo1'#22'AnchorSideLeft.Control'#7#5'Owner'#21
+'AnchorSideTop.Control'#7#5'Edit1'#18'AnchorSideTop.Side'#7#9'asrBottom'#23
+'AnchorSideRight.Control'#7#5'Owner'#20'AnchorSideRight.Side'#7#9'asrBottom'
+#24'AnchorSideBottom.Control'#7#5'Owner'#21'AnchorSideBottom.Side'#7#9'asrBo'
+'ttom'#4'Left'#2#5#6'Height'#2'P'#3'Top'#2';'#5'Width'#3#11#1#7'Anchors'#11#5
+'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#18'BorderSpacing.Left'#2#5#17'Bor'
+'derSpacing.Top'#2#5#19'BorderSpacing.Right'#2#5#20'BorderSpacing.Bottom'#2#5
+#13'Lines.Strings'#1#6#5'Memo1'#0#8'TabOrder'#2#2#0#0#11'TActionList'#11'Act'
+'ionList1'#4'left'#3#184#0#3'top'#2' '#0#8'TEditCut'#8'EditCut1'#8'Category'
+#6#4'Edit'#7'Caption'#6#4'Cu&t'#18'DisableIfNoHandler'#9#4'Hint'#6#3'Cut'#8
+'ShortCut'#3'X@'#0#0#9'TEditCopy'#9'EditCopy1'#8'Category'#6#4'Edit'#7'Capti'
+'on'#6#5'&Copy'#18'DisableIfNoHandler'#9#4'Hint'#6#4'Copy'#8'ShortCut'#3'C@'
+#0#0#10'TEditPaste'#10'EditPaste1'#8'Category'#6#4'Edit'#7'Caption'#6#6'&Pas'
+'te'#18'DisableIfNoHandler'#9#4'Hint'#6#5'Paste'#8'ShortCut'#3'V@'#0#0#14'TE'
+'ditSelectAll'#14'EditSelectAll1'#8'Category'#6#4'Edit'#7'Caption'#6#11'Sele'
+'ct &All'#18'DisableIfNoHandler'#9#4'Hint'#6#10'Select All'#8'ShortCut'#3'A@'
+#0#0#9'TEditUndo'#9'EditUndo1'#8'Category'#6#4'Edit'#7'Caption'#6#5'&Undo'#18
+'DisableIfNoHandler'#9#4'Hint'#6#4'Undo'#8'ShortCut'#3'Z@'#0#0#11'TEditDelet'
+'e'#11'EditDelete1'#8'Category'#6#4'Edit'#7'Caption'#6#7'&Delete'#18'Disable'
+'IfNoHandler'#9#4'Hint'#6#6'Delete'#8'ShortCut'#2'.'#0#0#9'TFileOpen'#9'File'
+'Open1'#8'Category'#6#4'File'#7'Caption'#6#8'&Open...'#4'Hint'#6#4'Open'#8'S'
+'hortCut'#3'O@'#0#0#13'TFileOpenWith'#13'FileOpenWith1'#8'Category'#6#4'File'
+#7'Caption'#6#12'Open with...'#4'Hint'#6#4'Open'#0#0#11'TFileSaveAs'#11'File'
+'SaveAs1'#8'Category'#6#4'File'#7'Caption'#6#11'Save &As...'#4'Hint'#6#7'Sav'
+'e As'#0#0#9'TFileExit'#9'FileExit1'#8'Category'#6#4'File'#7'Caption'#6#5'E&'
+'xit'#4'Hint'#6#4'Exit'#0#0#0#9'TMainMenu'#9'MainMenu1'#4'left'#3#213#0#3'to'
+'p'#2' '#0#9'TMenuItem'#9'MenuItem8'#7'Caption'#6#4'File'#0#9'TMenuItem'#10
+'MenuItem11'#6'Action'#7#9'FileOpen1'#0#0#9'TMenuItem'#10'MenuItem13'#6'Acti'
+'on'#7#13'FileOpenWith1'#0#0#9'TMenuItem'#10'MenuItem16'#6'Action'#7#11'File'
+'SaveAs1'#0#0#9'TMenuItem'#10'MenuItem17'#6'Action'#7#9'FileExit1'#0#0#0#9'T'
+'MenuItem'#9'MenuItem1'#7'Caption'#6#4'Edit'#0#9'TMenuItem'#9'MenuItem2'#6'A'
+'ction'#7#8'EditCut1'#0#0#9'TMenuItem'#9'MenuItem3'#6'Action'#7#9'EditCopy1'
+#0#0#9'TMenuItem'#9'MenuItem4'#6'Action'#7#10'EditPaste1'#0#0#9'TMenuItem'#9
+'MenuItem5'#6'Action'#7#14'EditSelectAll1'#0#0#9'TMenuItem'#9'MenuItem6'#6'A'
+'ction'#7#11'EditDelete1'#0#0#9'TMenuItem'#9'MenuItem7'#6'Action'#7#9'EditUn'
+'do1'#0#0#0#0#0
]);

View File

@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
ActnList, StdActns, ComCtrls;
ActnList, StdActns, ComCtrls, Menus;
type
@ -21,7 +21,24 @@ type
EditPaste1: TEditPaste;
EditSelectAll1: TEditSelectAll;
EditUndo1: TEditUndo;
FileExit1: TFileExit;
FileOpen1: TFileOpen;
FileOpenWith1: TFileOpenWith;
FileSaveAs1: TFileSaveAs;
MainMenu1: TMainMenu;
Memo1: TMemo;
MenuItem1: TMenuItem;
MenuItem11: TMenuItem;
MenuItem13: TMenuItem;
MenuItem16: TMenuItem;
MenuItem17: TMenuItem;
MenuItem2: TMenuItem;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
MenuItem5: TMenuItem;
MenuItem6: TMenuItem;
MenuItem7: TMenuItem;
MenuItem8: TMenuItem;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
@ -29,6 +46,7 @@ type
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
private
{ private declarations }
public
@ -40,6 +58,13 @@ var
implementation
{ TForm1 }
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
CanClose := MessageDlg('Do you want to exit?', mtConfirmation, [mbYes, mbNo], 0) = mrYes;
end;
initialization
{$I unit1.lrs}

View File

@ -191,6 +191,7 @@ begin
fActStdProperty.Add(THelpOnHelp, oiStdActHelpHelpHelpHeadLine, '', oiStdActHelpHelpHelpHint);
fActStdProperty.Add(TFileOpen, oiStdActFileOpenHeadLine, oiStdActFileOpenShortCut, oiStdActFileOpenHint);
fActStdProperty.Add(TFileOpenWith, oiStdActFileOpenWithHeadLine, '', oiStdActFileOpenHint);
fActStdProperty.Add(TFileSaveAs, oiStdActFileSaveAsHeadLine, '', oiStdActFileSaveAsHint);
fActStdProperty.Add(TFileExit, oiStdActFileExitHeadLine, '', oiStdActFileExitHint);

View File

@ -231,6 +231,7 @@ resourcestring
oiStdActHelpTopicSearchHeadLine = '&Topic Search';
oiStdActHelpHelpHelpHeadLine = '&Help on Help';
oiStdActFileOpenHeadLine = '&Open...';
oiStdActFileOpenWithHeadLine = 'Open with...';
oiStdActFileSaveAsHeadLine = 'Save &As...';
oiStdActFileExitHeadLine = 'E&xit';
oiStdActColorSelect1HeadLine = 'Select &Color...';
@ -265,6 +266,7 @@ resourcestring
oiStdActHelpTopicSearchHint = 'Topic Search';
oiStdActHelpHelpHelpHint = 'Help on help';
oiStdActFileOpenHint = 'Open';
oiStdActFileOpenWithHint = 'Open with';
oiStdActFileSaveAsHint = 'Save As';
oiStdActFileExitHint = 'Exit';
oiStdActColorSelectHint = 'Color Select';

View File

@ -140,10 +140,9 @@ type
protected
FDialog: TCommonDialog;
procedure DoAccept;
procedure DoBeforeExecute;
procedure DoCancel;
function GetDialogClass: TCommonDialogClass; virtual;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetupDialog;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
@ -173,12 +172,9 @@ type
function GetDialog: TOpenDialog;
protected
function GetDialogClass: TCommonDialogClass; override;
public
constructor Create(TheOwner: TComponent); override;
procedure ExecuteTarget(Target: TObject); override;
property Dialog: TOpenDialog read GetDialog;
published
property Caption;
property Dialog: TOpenDialog read GetDialog;
property Enabled;
property HelpContext;
property HelpKeyword;
@ -200,8 +196,6 @@ type
private
FAfterOpen: TNotifyEvent;
FFileName: TFileName;
public
procedure ExecuteTarget(Target: TObject); override;
published
property FileName: TFileName read FFileName write FFileName;
property HelpContext;
@ -216,11 +210,9 @@ type
function GetSaveDialog: TSaveDialog;
protected
function GetDialogClass: TCommonDialogClass; override;
public
constructor Create(TheOwner: TComponent); override;
property Dialog: TSaveDialog read GetSaveDialog;
published
property Caption;
property Dialog: TSaveDialog read GetSaveDialog;
property Enabled;
property HelpContext;
property Hint;
@ -650,28 +642,25 @@ end;
procedure TCommonDialogAction.DoAccept;
begin
if Assigned(FOnAccept) then
OnAccept(Self);
end;
procedure TCommonDialogAction.DoBeforeExecute;
begin
if Assigned(FBeforeExecute) then
BeforeExecute(Self);
end;
procedure TCommonDialogAction.DoCancel;
begin
if Assigned(FOnCancel) then
OnCancel(Self);
end;
function TCommonDialogAction.GetDialogClass: TCommonDialogClass;
begin
Result:=nil;
end;
procedure TCommonDialogAction.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
end;
procedure TCommonDialogAction.SetupDialog;
begin
Result := nil;
end;
constructor TCommonDialogAction.Create(TheOwner: TComponent);
@ -680,8 +669,11 @@ var
begin
inherited Create(TheOwner);
DlgClass := GetDialogClass;
if Assigned(DlgClass)
then FDialog := DlgClass.Create(Self);
if Assigned(DlgClass) then
begin
FDialog := DlgClass.Create(Self);
FDialog.Name := DlgClass.ClassName;
end;
DisableIfNoHandler := False;
Enabled := True;
@ -694,12 +686,18 @@ end;
function TCommonDialogAction.Handlestarget(Target: TObject): Boolean;
begin
Result:=inherited Handlestarget(Target);
// no target
Result := True;
end;
procedure TCommonDialogAction.ExecuteTarget(Target: TObject);
begin
inherited ExecuteTarget(Target);
DoBeforeExecute;
FExecuteResult := FDialog.Execute;
if FExecuteResult then
DoAccept
else
DoCancel;
end;
{ TFileAction }
@ -728,24 +726,7 @@ end;
function TFileOpen.GetDialogClass: TCommonDialogClass;
begin
Result:=inherited GetDialogClass;
end;
constructor TFileOpen.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
end;
procedure TFileOpen.ExecuteTarget(Target: TObject);
begin
inherited ExecuteTarget(Target);
end;
{ TFileOpenWith }
procedure TFileOpenWith.ExecuteTarget(Target: TObject);
begin
inherited ExecuteTarget(Target);
Result := TOpenDialog;
end;
{ TFileSaveAs }
@ -757,24 +738,25 @@ end;
function TFileSaveAs.GetDialogClass: TCommonDialogClass;
begin
Result:=inherited GetDialogClass;
end;
constructor TFileSaveAs.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
Result := TSaveDialog;
end;
{ TFileExit }
function TFileExit.HandlesTarget(Target: TObject): Boolean;
begin
Result:=inherited HandlesTarget(Target);
Result := True;
end;
procedure TFileExit.ExecuteTarget(Target: TObject);
begin
inherited ExecuteTarget(Target);
if Assigned(Application) then
if Assigned(Application.MainForm) then
Application.MainForm.Close
else
Application.Terminate
else
halt(0);
end;
{ TSearchAction }