easyeditorreg.pas.svn-base
来自「支持自定义语法高亮显示的编辑器控件」· SVN-BASE 代码 · 共 427 行
SVN-BASE
427 行
{***********************************************************}
{ }
{ module description }
{ }
{ Copyright (c) 1992-2002 Altium Limited }
{ All rights reserved. }
{ }
{ http://www.dream-com.com }
{ contact@dream-com.com }
{ }
{***********************************************************}
unit EasyEditorReg;
interface
{$I Easy.inc}
uses
Classes, SysUtils, EasyEditor, EasyEditSource, EasyBox, EasyParser,
EasyPopupMenu, EasySettings, EasyEditorSettings, EasyStrings, EasyControls,
EasyRtfExport, EasyHtmlExport
{$IFDEF EASY_RICHEDITOR}
,EasyRichEditor, EasyHtmlImport
{$ENDIF}
{$IFNDEF EASY_CLX}
,EasyPrint, Graphics
{$ELSE}
,QGraphics
{$ENDIF}
{$IFDEF EASY_DB}
,EasyDBEditor
{$IFDEF EASY_RICHEDITOR}
,EasyDBRichEditor
{$ENDIF}
{$ENDIF}
;
procedure Register;
implementation
{$R *.res}
uses
{$IFDEF _DELPHI6}
DesignIntf, DesignEditors,
{$ELSE}
DsgnIntf,
{$ENDIF}
Forms, TypInfo, Dialogs, Controls, StdCtrls, ExtCtrls
{$IFDEF _DELPHI4}, ImgList {$ENDIF};
type
TEasyComponentEditor = class(TComponentEditor)
private
function ShouldApplyImages : boolean;
public
function GetVerb(Index : integer): string; override;
function GetVerbCount : integer; override;
procedure ExecuteVerb(Index : integer); override;
end;
TEasyParserEditor = class(TComponentEditor)
public
function GetVerb(Index : integer): string; override;
function GetVerbCount : integer; override;
procedure ExecuteVerb(Index : integer); override;
end;
TPropertyWrapper = class
private
{$IFDEF _DELPHI6}
FPropEdit : IProperty;
{$ELSE}
FPropEdit : TPropertyEditor;
{$ENDIF}
FDesigner : {$IFDEF _DELPHI4} {$IFDEF _DELPHI6} IDesigner {$ELSE} IFormDesigner {$ENDIF} {$ELSE} TFormDesigner {$ENDIF};
public
PropName : string;
Instance : TPersistent;
procedure Execute;
{$IFDEF _DELPHI6}
procedure GetPropEdit(const Prop : IProperty);
{$ELSE}
procedure GetPropEdit(Prop : TPropertyEditor);
{$ENDIF}
end;
{$IFDEF EASY_WIDESTRINGS}
TWideStringsProperty = class(TClassProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
end;
{$ENDIF}
{$IFDEF _DELPHI5}
{$IFDEF _DELPHI6}
TComponentList = class(TDesignerSelections);
{$ELSE}
TComponentList = TDesignerSelectionList;
{$ENDIF}
{$ENDIF}
{$IFDEF EASY_WIDESTRINGS}
TEasyStringsEditForm = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel4: TPanel;
btOk: TButton;
btCansel: TButton;
btHelp: TButton;
Panel3: TPanel;
Panel5: TPanel;
Panel6: TPanel;
Panel7: TPanel;
GroupBox1: TGroupBox;
Panel8: TPanel;
Label1: TLabel;
Panel9: TPanel;
Panel10: TPanel;
Panel11: TPanel;
Memo1: TMemo;
procedure Memo1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{$ENDIF}
const
sEditLines = 'Edit Lines';
sEditRules = 'Edit Rules';
sLoadRules = 'Load from file';
sRulesFilter = 'Syntax Schemes (*.xs)|*.xs|All Files (*.*)|*.*';
sEditGutterImages = 'Edit Gutter Images';
sApplyImages = 'Apply images to global settings';
sLoadTemplatesFromFile = 'Load Templates From File';
sSaveTemplatesToFile = 'Save Templates To File';
sTplExt = 'tpl';
sEasyPage = 'Dream Editor';
sTemplatesFilter = 'Template Files|*.tpl|All Files|*.*';
sImagesApplied = 'Images are written to Global Settings';
{--------------------------------------------}
procedure EditProperty(P : TPersistent; Designer : {$IFDEF _DELPHI4} {$IFDEF _DELPHI6} IDesigner {$ELSE}
IFormDesigner {$ENDIF} {$ELSE} TFormDesigner {$ENDIF}; const APropname : string);
begin
if P <> nil then
with TPropertyWrapper.Create do
try
Instance := P;
FDesigner := Designer;
Propname := APropName;
Execute;
finally
Free;
end;
end;
{--------------------------------------------}
{$IFDEF EASY_WIDESTRINGS}
function EditLines(Lines : TEasyStrings) : boolean;
var
i : Integer;
begin
with TEasyStringsEditForm.Create(nil) do
try
with Memo1.Lines do
begin
BeginUpdate;
try
Clear;
for i := 0 to Lines.Count - 1 do
AddObject(Lines[i], Lines.Objects[i]);
finally
EndUpdate;
end;
end;
result := ShowModal = mrOk;
if result then
Lines.Assign(Memo1.Lines);
finally
Free;
end;
end;
{$ENDIF}
{---------TPropertyWrapper-------------------}
{$IFDEF _DELPHI6}
procedure TPropertyWrapper.GetPropEdit(const Prop : IProperty);
{$ELSE}
procedure TPropertyWrapper.GetPropEdit(Prop : TPropertyEditor);
{$ENDIF}
begin
if CompareText(Prop.GetName, PropName) = 0 then
FPropEdit := Prop
else
{$IFNDEF _DELPHI6}
Prop.Free;
{$ENDIF}
end;
{--------------------------------------------}
procedure TPropertyWrapper.Execute;
var
Clist : TComponentList;
begin
CList := TComponentList.Create;
try
Clist.Add(TComponent(Instance));
GetComponentProperties(Clist, tkAny, FDesigner, GetPropEdit);
if FPropEdit <> nil then
FPropEdit.Edit;
finally
Clist.Free;
{$IFDEF _DELPHI6}
FPropEdit := nil;
{$ELSE}
FPropEdit.Free;
{$ENDIF}
end;
end;
{---------TEasyComponentEditor---------------}
function TEasyComponentEditor.ShouldApplyImages : boolean;
begin
if Component is TCustomEasyEdit then
with TCustomEasyEdit(Component) do
result := UseGlobalSettings
else
result := false;
// and T_Gutter(Gutter).ImagesChanged;
end;
{--------------------------------------------}
function TEasyComponentEditor.GetVerb(Index : integer): string;
begin
if not ShouldApplyImages and (Index >= 2) then
Inc(Index);
result := '';
case Index of
0 : result := sEditLines;
1 : result := sEditGutterImages;
2 : result := sApplyImages;
3 : result := sLoadTemplatesFromFile;
4 : result := sSaveTemplatesToFile;
end;
end;
{--------------------------------------------}
function TEasyComponentEditor.GetVerbCount : integer;
begin
result := 4;
if ShouldApplyImages then
Inc(result);
end;
{--------------------------------------------}
type
T_Settings = class(TEasyEditSettings);
T_Gutter = class(TEasyEditorGutter);
procedure TEasyComponentEditor.ExecuteVerb(Index : integer);
var
{$IFDEF _DELPHI6}
CEdit : IComponentEditor;
{$ELSE}
CEdit : TComponentEditor;
{$ENDIF}
Settings : TEasyEditSettings;
begin
if not ShouldApplyImages and (Index >= 2) then
Inc(Index);
case Index of
0 :
{$IFDEF EASY_WIDESTRINGS}
if EditLines(TCustomEasyEdit(Component).Lines) then
Designer.Modified;
{$ELSE}
EditProperty(Component, Designer, 'Lines');
{$ENDIF}
1 :
begin
CEdit := GetComponentEditor(TCustomEasyEdit(Component).Gutter.Images, Designer);
if CEdit <> nil then
CEdit.ExecuteVerb(0);
end;
2 :
begin
Settings := EasyEditSettings;
Settings.Gutter.Images := TCustomEasyEdit(Component).Gutter.Images;
with T_Settings(Settings) do
SaveSettings;
ShowMessage(sImagesApplied);
end;
3 :
with TOpenDialog.Create(nil) do
try
DefaultExt := sTplExt;
Filter := sTemplatesFilter;
if Execute then
TCustomEasyEdit(Component).CodeTemplates.LoadFromFile(FileName);
finally
Free;
end;
4 :
with TSaveDialog.Create(nil) do
try
DefaultExt := sTplExt;
Filter := sTemplatesFilter;
if Execute then
TCustomEasyEdit(Component).CodeTemplates.SaveToFile(FileName);
finally
Free;
end;
end;
end;
{---------TEasyParserEditor------------------}
function TEasyParserEditor.GetVerb(Index : integer): string;
begin
case Index of
0 : result := sEditRules;
1 : result := sLoadRules;
else
result := '';
end;
// if Index = 0 then
// result := sEditRules
end;
{--------------------------------------------}
function TEasyParserEditor.GetVerbCount : integer;
begin
result := 2;
end;
{--------------------------------------------}
procedure TEasyParserEditor.ExecuteVerb(Index : integer);
begin
if Index = 0 then
EditProperty(Component, Designer, 'Rules');
if Index = 1 then
begin
with TOpenDialog.Create(nil) do
begin
Filter := sRulesFilter;
if Execute then
TEasyEditorParser(Component).Rules.LoadFromFile(FileName);
Free;
end;
end;
end;
{--------------------------------------------}
{$IFDEF EASY_WIDESTRINGS}
function TWideStringsProperty.GetAttributes: TPropertyAttributes;
begin
result := [paDialog];
end;
{--------------------------------------------}
procedure TWideStringsProperty.Edit;
var
P : TPersistent;
begin
P := TPersistent(GetOrdProp(GetComponent(0), GetPropInfo));
if P <> nil then
EditLines(TEasyStrings(P));
end;
{---------TEasyStringsEditForm------------------}
procedure TEasyStringsEditForm.Memo1Change(Sender: TObject);
begin
if Memo1.Lines.Count <> 1 then
Label1.Caption := IntToStr(Memo1.Lines.Count) + ' lines'
else
Label1.Caption := '1 line';
end;
{$ENDIF}
{--------------------------------------------}
procedure Register;
begin
RegisterComponents(sEasyPage, [TEasyEdit, TEasyEditSource,
{$IFDEF EASY_DB}
TEasyDBEdit, TEasyDBEditSource,
{$IFDEF EASY_RICHEDITOR}
TEasyDBRichEdit, TEasyDBRichEditSource,
{$ENDIF}
{$ENDIF}
{$IFDEF EASY_RICHEDITOR}
TEasyRichEdit, TEasyRichEditSource,
{$ENDIF}
{$IFNDEF EASY_CLX}
TEasyPrintPreview,
{$ENDIF}
TEasyEditorParser, TEasyEditorMenu, TEasyColorBox,
TEasyPenStyleBox, TEasyBrushStyleBox, TEasyHistoryEditor]);
RegisterComponentEditor(TCustomEasyEdit, TEasyComponentEditor);
RegisterComponentEditor(TEasyEditorParser, TEasyParserEditor);
RegisterPropertyEditor(TypeInfo(TImageList), TEasyEditorGutter, '', TClassProperty);
{$IFDEF EASY_WIDESTRINGS}
RegisterPropertyEditor(TypeInfo(TEasyStrings), nil, '', TWideStringsProperty);
{$ENDIF}
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?