📄 yrpasedit.pas
字号:
{YourPasEdit Verson 1.04
December 4, 1997
Copyright 1997 by D C AL CODA, Ken Hale and Coda Hale
This application is codeware, given to the Delphi community in thanks for being so
helpful. You are free to make any changes to the scource. But if you do, please
send us a copy of the changed and probably improved :-) project. We will keep the
changes on our web site and they will be available as an International Internet
tutorial.
Credits: I want to thank these people expecially because they offered help with
YourPasEdit.
Martin Waldenburg: for his PAS2RTF component
Andrius Adamonis: provided the code to open a file in the running instance
Giuseppe Madaffari: help with the RichEdit component
Tim Hayes: help with the runtime creation of PageControls and TabSheets
Shiv R. Kumar: help with the runtime creation of PageControls and TabSheets
Deepak Shenoy: sharing the open and save DFM code from his FormRead application
Ray Konopka: FormFileViewer project from the Dec/Jan 1998 issue of Visual Developer Magazine
The application and code are codeware and hopefully will find a useful home in your toolkit. It
may be freely distributed, as long as all the original files are kept intact.
The code can also be freely distribute, as long as all the original files are included
and comments are left intact.
Note: You may not use this project in a commercial application, unless it comprises
only about one-half of the total project. In other words you must write 50% new code in the
new application.
It would be very nice if others wanted to add their own personal touches to the application.
This project is very much a collaborative effort. We did not write the whole code.:-)
If you do make any corrections or additions, please include all these files and comments
and add your own. And send me a copy:-) to
kenhale@dcalcoda.com
We hope to have the latest copy on my web site:
http://www.dcalcoda.com/
Disclaimer:
This is FREEWARE. Any sale of this code is prohibited.
There is no warranty (expressed or implied) as to the workability,
merchantability, usefulness, fitness or anything else of these components.
D C AL CODA assumes no liability for damages, direct, real, imagined or
consequential, which may result from the use of this code.
We will also hopefully keep the latest copy on some of the very extensive Delphi web sites
Thank you,
Ken Hale
Coda Hale
History:
12/29/1997 := Version 1.04: added the ability to edit Delphi Form files (DFM and ~DF)
12/14/1997 := Version 1.03: Added code in the FormCreate to add the Alt+ F4 shortcut to the File Menu
12/12/1997 := Version 1.02: Removed yet another forgotten third party component the the AboutBox Uses clause
12/05/1997 := Version 1.01: Removed a few forgotten third party components from the AboutBox
12/4/1997 := Released basic project code as Codeware;
10/11/1997 := Immediately started adding options and third-party components;
10/10/1997 := Version 1.0; }
unit YrPasEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, mwPasToRtf, Menus, ExtCtrls, Printers;
const {Constants and variables used in the file association and running instance code}
WM_OPENEDITOR = WM_USER + 1;
WM_NOTEXISTS = WM_USER + 2;
WM_RESTOREAPP = WM_USER + 3;
MyUniqueConst = $123554;
var
WM_FINDINSTANCE: Integer;
R : TRect;
type
TPasConversionClass = class of TPasConversion;
TfrmYourPasEdit = class(TForm)
OpenDialog1: TOpenDialog;
pmActivePage: TPopupMenu;
pmaClosePage: TMenuItem;
PageControl1: TPageControl;
mmMainMenu: TMainMenu;
mmSearch: TMenuItem;
mmFind: TMenuItem;
mmReplace: TMenuItem;
mmFindAgain: TMenuItem;
mmFile: TMenuItem;
mmEdit: TMenuItem;
mmNew: TMenuItem;
mmOpen: TMenuItem;
mmClose: TMenuItem;
mmHelp: TMenuItem;
mmAbout: TMenuItem;
mmCut: TMenuItem;
mmCopy: TMenuItem;
mmPaste: TMenuItem;
pmaFind: TMenuItem;
N1: TMenuItem;
pmaOpen: TMenuItem;
pmaNew: TMenuItem;
mmMultiLine: TMenuItem;
pmaReplace: TMenuItem;
mmSave: TMenuItem;
N3: TMenuItem;
SaveDialog1: TSaveDialog;
mmSaveAs: TMenuItem;
N4: TMenuItem;
mmPrint: TMenuItem;
mmPrinterSetup: TMenuItem;
N5: TMenuItem;
mmExit: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
pmaExit: TMenuItem;
pmaCloseAllPages: TMenuItem;
N8: TMenuItem;
mmUndo: TMenuItem;
mmSelectAll: TMenuItem;
mmStatusBar: TMenuItem;
mmView: TMenuItem;
N9: TMenuItem;
PrinterSetupDialog: TPrinterSetupDialog;
PrintDialog: TPrintDialog;
FindDialog1: TFindDialog;
ReplaceDialog1: TReplaceDialog;
mmCloseAll: TMenuItem;
mmSaveAll: TMenuItem;
N2: TMenuItem;
pmaSave: TMenuItem;
pmaSaveAs: TMenuItem;
pmaSaveAll: TMenuItem;
StatusBar: TStatusBar;
procedure mmNewClick(Sender: TObject);
procedure mmOpenClick(Sender: TObject);
procedure pmaClosePageClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure mmFindClick(Sender: TObject);
procedure mmReplaceClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure mmMultiLineClick(Sender: TObject);
procedure mmSaveAsClick(Sender: TObject);
procedure mmExitClick(Sender: TObject);
procedure mmStatusBarClick(Sender: TObject);
procedure mmEditClick(Sender: TObject);
procedure mmSelectAllClick(Sender: TObject);
procedure mmUndoClick(Sender: TObject);
procedure mmCutClick(Sender: TObject);
procedure mmCopyClick(Sender: TObject);
procedure mmPasteClick(Sender: TObject);
procedure mmPrintClick(Sender: TObject);
procedure mmPrinterSetupClick(Sender: TObject);
procedure mmAboutClick(Sender: TObject);
procedure FindDialog1Find(Sender: TObject);
procedure ReplaceDialog1Replace(Sender: TObject);
procedure mmFindAgainClick(Sender: TObject);
procedure mmFileClick(Sender: TObject);
procedure mmSaveClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure mmCloseAllClick(Sender: TObject);
procedure mmSaveAllClick(Sender: TObject);
procedure NewRichEditChange(Sender: TObject);
procedure CheckStatus(Sender: TObject);
procedure NewRichEditSelectionChange(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var KEY: Word;
Shift: TShiftState);
procedure AppIdle(Sender: TObject; var Done: Boolean);
private
{ Private declarations }
protected
FFileName: string;
procedure DefaultHandler(var message); override;
procedure WMNotExists(var Msg: TMessage); message WM_NOTEXISTS;
procedure WMRestoreApp(var Msg: TMessage); message WM_RESTOREAPP;
public
{ Public declarations }
Margins: TRect;
Untitleds: Integer;
NewRichEdit: TRichEdit;
NewTabSheet: TTabSheet;
PasCon: TPasConversion;
procedure LoadFile(FName: string);
procedure LoadFilePT(FName: string);
procedure LoadFileDFM(FName: string);
procedure SaveFileToDFM(Filename: string);
procedure OpenFile(FName: string);
procedure DisplayHint(Sender: TObject);
procedure StartNew;
procedure UpdateControls;
procedure NewRichEditSetup(NewRE: TRichEdit);
procedure CheckCapslock;
end;
var
frmYourPasEdit: TfrmYourPasEdit;
implementation
uses ClipBrd, About;
{$R *.DFM}
procedure TfrmYourPasEdit.OpenFile(FName: string);
begin {checks to see if the file is a Delphi Pascal or Project file}
if (UpperCase(ExtractFileExt(FName)) = '.PAS') or (UpperCase(ExtractFileExt(FName)) = '.DPR')
or (UpperCase(ExtractFileExt(FName)) = '.~DP') or (UpperCase(ExtractFileExt(FName)) = '.~PA')
then
LoadFile(FName) {Loads it via the PasToRtf converter}
else {Or if it is a Delphi Form file}
if (UpperCase(ExtractFileExt(FName)) = '.DFM') or (UpperCase(ExtractFileExt(FName)) = '.~DF')
then
LoadFileDFM(FName) {Loads the DFM file}
else {otherwise load it as a plain text file}
LoadFilePT(FName);
end;
procedure TfrmYourPasEdit.UpdateControls;
begin {Enables menu controls, based on the existence of an ActivePage,
funny things happened if there was no ActivePage and RichEdit
and you tried to do a Find or something}
mmSearch.ENABLED := PageControl1.PageCount <> 0;
mmPrint.ENABLED := PageControl1.PageCount <> 0;
mmEdit.ENABLED := PageControl1.PageCount <> 0;
mmClose.ENABLED := PageControl1.PageCount <> 0;
mmCloseAll.ENABLED := PageControl1.PageCount <> 0;
mmSave.ENABLED := PageControl1.PageCount <> 0;
mmSaveAll.ENABLED := PageControl1.PageCount <> 0;
mmSaveAs.ENABLED := PageControl1.PageCount <> 0;
pmaFind.ENABLED := PageControl1.PageCount <> 0;
pmaReplace.ENABLED := PageControl1.PageCount <> 0;
end;
procedure TfrmYourPasEdit.NewRichEditSetup(NewRE: TRichEdit);
begin {Sets NewRichEdit properties for mmNewClick and StartNew}
with NewRE do
begin
Parent := NewTabSheet;
PageRect := Margins;
Align := alClient;
ScrollBars := ssBoth;
WordWrap := False;
WantTabs := True;
HideSelection := False;
ShowHint := False;
Modified := False;
MaxLength := 1200000;
OnChange := NewRichEditChange;
OnSelectionChange := NewRichEditSelectionChange;
end;
end;
procedure TfrmYourPasEdit.CheckCapslock;
begin
{The INS/OVR is somewhat inaccurate, it will often show OVR when the mode is
clearly in INS mode, and show INS when the mode is clearly in OVR. If you
figure out a way of accurately showing the state, please let us know.
This slightly modified example comes from Marco Cantu's Mastering Delphi 3 book}
if Odd(GetKeyState(VK_INSERT)) then
StatusBar.Panels[3].Text := 'INS'
else
StatusBar.Panels[3].Text := 'OVR';
if Odd(GetKeyState(VK_CAPITAL)) then
StatusBar.Panels[4].Text := 'CAP'
else
StatusBar.Panels[4].Text := '';
if Odd(GetKeyState(VK_NUMLOCK)) then
StatusBar.Panels[5].Text := 'NUM'
else
StatusBar.Panels[5].Text := '';
end;
procedure TfrmYourPasEdit.CheckStatus(Sender: TObject);
begin
CheckCapslock;
end;
procedure TfrmYourPasEdit.FormKeyDown(Sender: TObject; var KEY: Word;
Shift: TShiftState);
begin
CheckCapslock;
end;
procedure TfrmYourPasEdit.AppIdle(Sender: TObject; var Done: Boolean);
begin
Done := True;
CheckStatus(frmYourPasEdit);
end;
{The basic code contained in the next three procedures,
which works with the DPR code to allow file association
and open doubleclicked file in the running instance of app
was written by Andrius Adamonis}
procedure TfrmYourPasEdit.WMRestoreApp(var Msg: TMessage);
begin
if IsIconic(Application.Handle) then
Application.RESTORE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -