📄 syneditsource.pas
字号:
{-------------------------------------------------------------------------------
单元: SynEditSource.pas
作者: 姚乔锋
日期: 2005-05-17 17:20
说明: 提供存储TSynEdit可用属性
版本: 1.00
-------------------------------------------------------------------------------}
unit SynEditSource;
{$I SynEdit.inc}
interface
uses
Windows, Classes, SysUtils, Graphics, Dialogs, Forms, Controls, StdCtrls,
Clipbrd, IniFiles, SynEdit, SynEditTypes, SynEditKeyCmds, SynEditMiscClasses,
SynEditTextBuffer, SynEditHighlighter, Menus;
type
TSynEditSourceMask = (
{$IFDEF CODEFOLDING}
//### Code Folding ###
smCodeFolding,
//### End Code Folding ###
{$ENDIF}
smBackground,
smActiveLine, smBlockWidth, smBookMarkOptions, smBorderStyle,
smColor, smFont, smGutter, smHideSelection, smHighlighter,
smInsertCaret, smInsertMode, smKeystrokes, smLines,
smLineDivider, smLineSpacing, smLineSpacingRule,
smMaxScrollWidth, smMaxUndo, smOptions, smOverwriteCaret,
smPopupMenu, smReadOnly, smRightEdge, smSelectedColor, smSelectionMode,
smScrollBars, smTabWidth, smWantTabs, smWordWrap);
TSynEditSourceMasks = set of TSynEditSourceMask;
const
DefaultSynEditSourceMask = [
{$IFDEF CODEFOLDING}
//### Code Folding ###
smCodeFolding,
//### End Code Folding ###
{$ENDIF}
smActiveLine, smBlockWidth, smBookMarkOptions, smBorderStyle,
smColor, smFont, smGutter, smHideSelection, smHighlighter,
smInsertCaret, smInsertMode, smKeystrokes, smLines,
smLineDivider, smLineSpacing, smLineSpacingRule,
smMaxScrollWidth, smMaxUndo, smOptions, smOverwriteCaret,
smPopupMenu, smReadOnly, smRightEdge, smSelectedColor, smSelectionMode,
smScrollBars, smTabWidth, smWantTabs, smWordWrap];
type
TSynEditSource = class(TComponent)
private
FMask : TSynEditSourceMasks;
FMaxScrollWidth: Integer;
FKeystrokes: TSynEditKeyStrokes;
FBookmarks: TSynBookMarkOpt;
FHideSelection: Boolean;
FMaxUndo: Integer;
FTabWidth: Integer;
FSelectedColor: TSynSelectedColor;
FFont: TFont;
FWantTabs: Boolean;
FOverwriteCaret: TSynEditCaretType;
FInsertCaret: TSynEditCaretType;
FOptions: TSynEditorOptions;
FSynGutter: TSynGutter;
FColor: TColor;
fBlockWidth: integer;
FLineSpacing: integer;
FLineSpacingRule: TLineSpacingRule;
FActiveLine: TSynActiveLine;
FLineDivider: TSynLineDivider;
FWordWrap: TSynWordWrap;
FRightEdge: TSynRightEdge;
FLines: TStrings;
fHighlighter: TSynCustomHighlighter;
FBorderStyle: TBorderStyle;
FReadOnly: Boolean;
FInsertMode: Boolean;
FPopupMenu: TPopupMenu;
FScrollBars: TSynScrollBars;
FSelectionMode: TSynSelectionMode;
{$IFDEF CODEFOLDING}
//### Code Folding ###
fCodeFolding: TSynCodeFolding;
fBackground: TSynEditBackground;
//### End Code Folding ###
{$ENDIF}
procedure SetBookMarks(const Value: TSynBookMarkOpt);
procedure SetFont(const Value: TFont);
procedure SetKeystrokes(const Value: TSynEditKeyStrokes);
procedure SetSynGutter(const Value: TSynGutter);
procedure SetActiveLine(const Value: TSynActiveLine);
procedure SetLineDivider(const Value: TSynLineDivider);
procedure SetRightEdge(const Value: TSynRightEdge);
procedure SetWordWrap(const Value: TSynWordWrap);
procedure SetLines(const Value: TStrings);
procedure SetHighlighter(const Value: TSynCustomHighlighter);
procedure SetPopupMenu(const Value: TPopupMenu);
procedure SetSelectedColor(const Value: TSynSelectedColor);
procedure SetScrollBars(const Value: TSynScrollBars);
procedure SetBackground(const Value: TSynEditBackground);
{$IFDEF CODEFOLDING}
//### Code Folding ###
procedure setCodeFolding(const Value: TSynCodeFolding);
//### End Code Folding ###
{$ENDIF}
protected
procedure Notification(AComponent: TComponent;
Operation: TOperation); override;
function IsMask(Mask : TSynEditSourceMask) : Boolean;
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
//Assign a TSynEditAcess or AssignTo a TSynEditAcess
procedure Assign(Source : TPersistent); override;
procedure AssignTo(Dest : TPersistent); override;
//Save self To a IniFile or Load from a IniFile to Self
procedure SaveToIni(IniFile : TCustomIniFile; Section : string);
procedure LoadFromIni(IniFile : TCustomIniFile; Section : string);
published
property Mask : TSynEditSourceMasks read FMask write FMask;
{$IFDEF CODEFOLDING}
//### Code Folding ###
property CodeFolding: TSynCodeFolding read fCodeFolding write setCodeFolding;
//### End Code Folding ###
{$ENDIF}
property ActiveLine : TSynActiveLine read FActiveLine write SetActiveLine;
property BlockWidth : integer read fBlockWidth write fBlockWidth;
property Background: TSynEditBackground read fBackground write SetBackground;
property BookMarkOptions : TSynBookMarkOpt read FBookmarks write SetBookMarks;
property BorderStyle : TBorderStyle read FBorderStyle write FBorderStyle;
property Color : TColor read FColor write FColor;
property Font : TFont read FFont write SetFont;
property Gutter : TSynGutter read FSynGutter write SetSynGutter;
property HideSelection : Boolean read FHideSelection write FHideSelection;
property Highlighter : TSynCustomHighlighter read fHighlighter write SetHighlighter;
property InsertCaret : TSynEditCaretType read FInsertCaret write FInsertCaret;
property InsertMode : Boolean read FInsertMode write FInsertMode;
property Keystrokes : TSynEditKeyStrokes read FKeystrokes write SetKeystrokes;
property Lines : TStrings read FLines write SetLines;
property LineDivider : TSynLineDivider read FLineDivider write SetLineDivider;
property LineSpacing : integer read FLineSpacing write FLineSpacing;
property LineSpacingRule : TLineSpacingRule read FLineSpacingRule write FLineSpacingRule;
property MaxScrollWidth : Integer read FMaxScrollWidth write FMaxScrollWidth;
property MaxUndo : Integer read FMaxUndo write FMaxUndo;
property Options : TSynEditorOptions read FOptions write FOptions;
property OverwriteCaret : TSynEditCaretType read FOverwriteCaret write FOverwriteCaret;
property PopupMenu : TPopupMenu read FPopupMenu write SetPopupMenu;
property ReadOnly : Boolean read FReadOnly write FReadOnly;
property RightEdge : TSynRightEdge read FRightEdge write SetRightEdge;
property ScrollBars : TSynScrollBars read FScrollBars write SetScrollBars;
property SelectedColor : TSynSelectedColor read FSelectedColor write SetSelectedColor;
property SelectionMode : TSynSelectionMode read FSelectionMode write FSelectionMode;
property TabWidth : Integer read FTabWidth write FTabWidth;
property WantTabs : Boolean read FWantTabs write FWantTabs;
property WordWrap : TSynWordWrap read FWordWrap write SetWordWrap;
end;
TSynEditAcess = class(TCustomSynEdit);
implementation
function FontToStr(Font: TFont): String;
function FontStylesToStr(Styles: TFontStyles): String;
begin
Result := '';
if fsBold in Styles then
Result := Result + 'B';
if fsItalic in Styles then
Result := Result + 'I';
if fsUnderline in Styles then
Result := Result + 'U';
if fsStrikeOut in Styles then
Result := Result + 'S';
end;
begin
with Font do
Result := Format('%s,%d,%s,%d,%s,%d', [Name, Height,
FontStylesToStr(Style), Ord(Pitch),
ColorToString(Color), Charset]);
end;
procedure StrToFont(const s: string; Font: TFont);
function StrToFontStyles(const Styles: string): TFontStyles;
var
i: Integer;
begin
Result := [];
for i := 1 to Length(Styles) do
case Styles[i] of
'B','b': Include(Result, fsBold);
'I','i': Include(Result, fsItalic);
'U','u': Include(Result, fsUnderline);
'S','s': Include(Result, fsStrikeOut);
end;
end;
var
I, j, State: Integer;
s2: string;
begin
i := 1;
State := 1;
while i<=Length(s) do
begin
j := i;
while (j<=Length(s)) and (s[j]<>',') do
inc(j);
if (j<=Length(s)) and (s[j]=',') then
begin
s2 := Copy(s, i, j-i);
i := j+1;
end
else begin
s2 := Copy(s, i, j-i+1);
i := j;
end;
case State of
1: Font.Name := s2;
2: Font.Height := StrToInt(s2);
3: Font.Style := StrToFontStyles(s2);
4: Font.Pitch := TFontPitch(StrToInt(s2));
5: Font.Color := StringToColor(s2);
6: Font.Charset := TFontCharset(StrToInt(s2));
end;
inc(State);
end;
end;
{ TSynEditSource }
procedure TSynEditSource.Assign(Source: TPersistent);
begin
if Assigned(Source) and (Source is TCustomSynEdit) then
begin
if IsMask(smBackground) then
Self.Background := TSynEditAcess(Source).Background;
if IsMask(smActiveLine) then
Self.ActiveLine := TSynEditAcess(Source).ActiveLine;
if IsMask(smBlockWidth) then
self.BlockWidth := TSynEditAcess(Source).BlockWidth;
if IsMask(smBookMarkOptions) then
Self.BookmarkOptions := TSynEditAcess(Source).BookmarkOptions;
if IsMask(smBorderStyle) then
self.BorderStyle := TSynEditAcess(Source).BorderStyle;
if IsMask(smColor) then
Self.Color := TSynEditAcess(Source).Color;
if IsMask(smFont) then
Self.Font := TSynEditAcess(Source).Font;
if IsMask(smGutter) then
Self.Gutter := TSynEditAcess(Source).Gutter;
if IsMask(smHideSelection) then
Self.HideSelection := TSynEditAcess(Source).HideSelection;
if IsMask(smHighlighter) then
self.Highlighter := TSynEditAcess(Source).Highlighter;
if IsMask(smInsertCaret) then
Self.InsertCaret := TSynEditAcess(Source).InsertCaret;
if IsMask(smInsertMode) then
Self.insertMode := TSynEditAcess(Source).insertMode;
if IsMask(smKeystrokes) then
Self.Keystrokes := TSynEditAcess(Source).Keystrokes;
if IsMask(smLines) then
self.Lines := TSynEditAcess(Source).Lines;
if IsMask(smLineDivider) then
Self.LineDivider := TSynEditAcess(Source).LineDivider;
if IsMask(smLineSpacing) then
Self.LineSpacing := TSynEditAcess(Source).LineSpacing;
if IsMask(smLineSpacingRule) then
Self.LineSpacingRule := TSynEditAcess(Source).LineSpacingRule;
if IsMask(smMaxScrollWidth) then
Self.MaxScrollWidth := TSynEditAcess(Source).MaxScrollWidth;
if IsMask(smMaxUndo) then
Self.MaxUndo := TSynEditAcess(Source).MaxUndo;
if IsMask(smOptions) then
Self.Options := TSynEditAcess(Source).Options;
if IsMask(smOverwriteCaret) then
Self.OverwriteCaret := TSynEditAcess(Source).OverwriteCaret;
if IsMask(smPopupMenu) then
Self.PopupMenu := TSynEditAcess(Source).PopupMenu;
if IsMask(smReadOnly) then
Self.ReadOnly := TSynEditAcess(Source).ReadOnly;
if IsMask(smRightEdge) then
Self.RightEdge := TSynEditAcess(Source).RightEdge;
if IsMask(smScrollBars) then
Self.ScrollBars := TSynEditAcess(Source).ScrollBars;
if IsMask(smSelectedColor) then
Self.SelectedColor := TSynEditAcess(Source).SelectedColor;
if IsMask(smSelectionMode) then
Self.SelectionMode := TSynEditAcess(Source).SelectionMode;
if IsMask(smTabWidth) then
Self.TabWidth := TSynEditAcess(Source).TabWidth;
if IsMask(smWantTabs) then
Self.WantTabs := TSynEditAcess(Source).WantTabs;
if IsMask(smWordWrap) then
Self.WordWrap := TSynEditAcess(Source).WordWrap;
{$IFDEF CODEFOLDING}
//### Code Folding ###
if IsMask(smCodeFolding) then
Self.CodeFolding := TSynEditAcess(Source).CodeFolding;
//### End Code Folding ###
{$ENDIF}
end
else if Assigned(Source) and (Source is TSynEditSource) then
begin
if IsMask(smActiveLine) then
Self.ActiveLine := TSynEditSource(Source).ActiveLine;
if IsMask(smBlockWidth) then
self.BlockWidth := TSynEditSource(Source).BlockWidth;
if IsMask(smBookMarkOptions) then
Self.BookmarkOptions := TSynEditSource(Source).BookmarkOptions;
if IsMask(smBorderStyle) then
self.BorderStyle := TSynEditSource(Source).BorderStyle;
if IsMask(smColor) then
Self.Color := TSynEditSource(Source).Color;
if IsMask(smFont) then
Self.Font := TSynEditSource(Source).Font;
if IsMask(smGutter) then
Self.Gutter := TSynEditSource(Source).Gutter;
if IsMask(smHideSelection) then
Self.HideSelection := TSynEditSource(Source).HideSelection;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -