📄 stdactns.pas
字号:
begin
if Assigned(FBeforeExecute) then
FBeforeExecute(Self);
FExecuteResult := FDialog.Execute;
if FExecuteResult then
DoAccept
else
DoCancel;
end;
end;
function TCommonDialogAction.GetDialogClass: TCommonDialogClass;
begin
Result := nil;
end;
function TCommonDialogAction.Handlestarget(Target: TObject): Boolean;
begin
Result := True;
end;
procedure TCommonDialogAction.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if not (csDestroying in ComponentState) and (Operation = opRemove) and
(AComponent = FDialog) then
SetupDialog;
end;
procedure TCommonDialogAction.SetupDialog;
var
DialogClass: TCommonDialogClass;
begin
DialogClass := GetDialogClass;
if Assigned(DialogClass) then
begin
FDialog := DialogClass.Create(Self);
FDialog.Name := Copy(DialogClass.ClassName, 2, Length(DialogClass.ClassName));
FDialog.SetSubComponent(True);
FDialog.FreeNotification(Self);
end;
end;
{ TFileAction }
function TFileAction.GetDialog: TOpenDialog;
begin
Result := TOpenDialog(FDialog);
end;
function TFileAction.GetFileName: TFileName;
begin
Result := GetDialog.FileName;
end;
procedure TFileAction.SetFileName(const Value: TFileName);
begin
GetDialog.FileName := Value;
end;
{ TFileOpen }
constructor TFileOpen.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDialog.Name := 'OpenDialog';
end;
procedure TFileOpen.ExecuteTarget(Target: TObject);
begin
inherited ExecuteTarget(Target);
if FExecuteResult and FUseDefaultApp then
ShellExecute(0, nil, PChar(Dialog.FileName), nil, nil, SW_SHOW)
end;
function TFileOpen.GetDialogClass: TCommonDialogClass;
begin
Result := TOpenDialog;
end;
{ TFileOpenWith }
procedure TFileOpenWith.ExecuteTarget(Target: TObject);
begin
if (Length(FFileName) = 0) or not FileExists(FFileName) then
begin
inherited;
FFileName := Dialog.FileName;
end
else
FExecuteResult := True;
if FExecuteResult then
ShellExecute(0, 'open', 'rundll32.exe', { do not localize}
PChar(Format('shell32.dll,OpenAs_RunDLL %s', [FFileName])), nil, { do not localize}
SW_SHOW);
if Assigned(FAfterOpen) then
FAfterOpen(Self);
end;
{ TFileSaveAs }
constructor TFileSaveAs.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDialog.Name := 'SaveDialog';
end;
function TFileSaveAs.GetDialogClass: TCommonDialogClass;
begin
Result := TSaveDialog;
end;
function TFileSaveAs.GetSaveDialog: TSaveDialog;
begin
Result := TSaveDialog(FDialog);
end;
{ TFilePrintSetup }
function TFilePrintSetup.GetDialog: TPrinterSetupDialog;
begin
Result := TPrinterSetupDialog(FDialog);
end;
function TFilePrintSetup.GetDialogClass: TCommonDialogClass;
begin
Result := TPrinterSetupDialog;
end;
{ TFilePageSetup }
function TFilePageSetup.GetDialog: TPageSetupDialog;
begin
Result := TPageSetupDialog(FDialog);
end;
function TFilePageSetup.GetDialogClass: TCommonDialogClass;
begin
Result := TPageSetupDialog;
end;
{ TFileExit }
procedure TFileExit.ExecuteTarget(Target: TObject);
begin
if Assigned(Application.MainForm) then
begin
Application.HelpCommand(HELP_QUIT, 0);
Application.MainForm.Close;
end;
end;
function TFileExit.HandlesTarget(Target: TObject): Boolean;
begin
Result := True;
end;
{ SearchEdit scans the text of a TCustomEdit-derived component for a given
search string. The search starts at the current caret position in the
control unless FindFirst is true then the search starts at the beginning.
The Options parameter determines whether the search runs forward
(frDown) or backward from the caret position, whether or not the text
comparison is case sensitive, and whether the matching string must be a
whole word. If text is already selected in the control, the search starts
at the 'far end' of the selection (SelStart if searching backwards, SelEnd
if searching forwards). If a match is found, the control's text selection
is changed to select the found text and the function returns True. If no
match is found, the function returns False. }
function SearchEdit(EditControl: TCustomEdit; const SearchString: String;
Options: TFindOptions; FindFirst: Boolean = False): Boolean;
var
Buffer, P: PChar;
Size: Word;
SearchOptions: TStringSearchOptions;
begin
Result := False;
if (Length(SearchString) = 0) then Exit;
Size := EditControl.GetTextLen;
if (Size = 0) then Exit;
Buffer := StrAlloc(Size + 1);
try
SearchOptions := [];
if frDown in Options then
Include(SearchOptions, soDown);
if frMatchCase in Options then
Include(SearchOptions, soMatchCase);
if frWholeWord in Options then
Include(SearchOptions, soWholeWord);
EditControl.GetTextBuf(Buffer, Size + 1);
if FindFirst then
P := SearchBuf(Buffer, Size, 0, EditControl.SelLength,
SearchString, SearchOptions)
else
P := SearchBuf(Buffer, Size, EditControl.SelStart, EditControl.SelLength,
SearchString, SearchOptions);
if P <> nil then
begin
EditControl.SelStart := P - Buffer;
EditControl.SelLength := Length(SearchString);
Result := True;
end;
finally
StrDispose(Buffer);
end;
end;
{ TSearchAction }
constructor TSearchAction.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
TFindDialog(FDialog).OnFind := Search;
FFindFirst := False;
end;
destructor TSearchAction.Destroy;
begin
if Assigned(FControl) then
FControl.RemoveFreeNotification(Self);
inherited;
end;
procedure TSearchAction.ExecuteTarget(Target: TObject);
begin
FControl := TCustomEdit(Target);
if Assigned(FControl) then
FControl.FreeNotification(Self);
inherited ExecuteTarget(Target);
end;
function TSearchAction.HandlesTarget(Target: TObject): Boolean;
begin
Result := Screen.ActiveControl is TCustomEdit;
if not Result then
Enabled := False;
end;
procedure TSearchAction.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (Operation = opRemove) and (AComponent = FControl) then
FControl := nil;
end;
procedure TSearchAction.Search(Sender: TObject);
begin
// FControl gets set in ExecuteTarget
if Assigned(FControl) then
if not SearchEdit(FControl, TFindDialog(FDialog).FindText,
TFindDialog(FDialog).Options, FFindFirst) then
ShowMessage(Format(STextNotFound, [TFindDialog(FDialog).FindText]));
end;
procedure TSearchAction.UpdateTarget(Target: TObject);
begin
Enabled := Target is TCustomEdit and (TCustomEdit(Target).GetTextLen > 0);
end;
{ TSearchFind }
function TSearchFind.GetDialogClass: TCommonDialogClass;
begin
Result := TFindDialog;
end;
function TSearchFind.GetFindDialog: TFindDialog;
begin
Result := TFindDialog(FDialog);
end;
{ TSearchReplace }
procedure TSearchReplace.ExecuteTarget(Target: TObject);
begin
inherited ExecuteTarget(Target);
TReplaceDialog(FDialog).OnReplace := Replace;
end;
function TSearchReplace.GetDialogClass: TCommonDialogClass;
begin
Result := TReplaceDialog;
end;
function TSearchReplace.GetReplaceDialog: TReplaceDialog;
begin
Result := TReplaceDialog(FDialog);
end;
procedure TSearchReplace.Replace(Sender: TObject);
var
Found: Boolean;
FoundCount: Integer;
begin
// FControl gets set in ExecuteTarget
Found := False;
FoundCount := 0;
if Assigned(FControl) then
with Sender as TReplaceDialog do
begin
if (Length(FControl.SelText) > 0) and
(not (frReplaceAll in Dialog.Options) and
(AnsiCompareText(FControl.SelText, FindText) = 0) or
(frReplaceAll in Dialog.Options) and (FControl.SelText = FindText)) then
begin
FControl.SelText := ReplaceText;
SearchEdit(FControl, Dialog.FindText, Dialog.Options, FFindFirst);
if not (frReplaceAll in Dialog.Options) then exit;
end;
repeat
Found := SearchEdit(FControl, Dialog.FindText, Dialog.Options, FFindFirst);
if Found then
begin
FControl.SelText := ReplaceText;
Inc(FoundCount);
end;
until not Found or not (frReplaceAll in Dialog.Options);
end;
if not Found and (FoundCount = 0) then
ShowMessage(Format(STextNotFound, [Dialog.FindText]));
end;
{ TSearchFindFirst }
constructor TSearchFindFirst.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FFindFirst := True;
end;
{ TSearchFindNext }
constructor TSearchFindNext.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
DisableIfNoHandler := False;
end;
procedure TSearchFindNext.ExecuteTarget(Target: TObject);
begin
FSearchFind.FControl := TCustomEdit(Target);
if not Assigned(FSearchFind) then exit;
FSearchFind.Search(Target);
end;
function TSearchFindNext.HandlesTarget(Target: TObject): Boolean;
begin
Result := Assigned(FSearchFind) and FSearchFind.Enabled and
(Length(TFindDialog(FSearchFind.Dialog).FindText) <> 0);
Enabled := Result;
end;
procedure TSearchFindNext.UpdateTarget(Target: TObject);
begin
if Assigned(FSearchFind) then
Enabled := FSearchFind.Enabled and (Length(TFindDialog(FSearchFind.Dialog).FindText) <> 0)
else
Enabled := False;
end;
{ TFontEdit }
function TFontEdit.GetDialog: TFontDialog;
begin
Result := TFontDialog(FDialog);
end;
function TFontEdit.GetDialogClass: TCommonDialogClass;
begin
Result := TFontDialog;
end;
{ TColorSelect }
function TColorSelect.GetDialog: TColorDialog;
begin
Result := TColorDialog(FDialog);
end;
function TColorSelect.GetDialogClass: TCommonDialogClass;
begin
Result := TColorDialog;
end;
{ TPrintDlg }
function TPrintDlg.GetDialog: TPrintDialog;
begin
Result := TPrintDialog(FDialog);
end;
function TPrintDlg.Getdialogclass: TCommonDialogClass;
begin
Result := TPrintDialog;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -