📄 jvhleditorpropertyform.pas
字号:
begin
FJvHLEditor.DoubleClickLine := DefaultValue['DoubleClickLine', FJvHLEditor.DoubleClickLine];
FJvHLEditor.UndoAfterSave := DefaultValue['UndoAfterSave', FJvHLEditor.UndoAfterSave];
FJvHLEditor.KeepTrailingBlanks := DefaultValue['KeepTrailingBlanks', FJvHLEditor.KeepTrailingBlanks];
FJvHLEditor.AutoIndent := DefaultValue['AutoIndent', FJvHLEditor.AutoIndent];
FJvHLEditor.SmartTab := DefaultValue['SmartTab', FJvHLEditor.SmartTab];
FJvHLEditor.BackSpaceUnindents := DefaultValue['BackspaceUnindents', FJvHLEditor.BackSpaceUnindents];
FJvHLEditor.GroupUndo := DefaultValue['GroupUndo', FJvHLEditor.GroupUndo];
FJvHLEditor.CursorBeyondEOF := DefaultValue['CursorBeyondEOF', FJvHLEditor.CursorBeyondEOF];
HLed.SyntaxHighlighting := DefaultValue['SyntaxHighlighting', HLed.SyntaxHighlighting];
FJvHLEditor.TabStops := DefaultValue['TabStops', FJvHLEditor.TabStops];
FJvHLEditor.RightMargin := DefaultValue['RightMargin', FJvHLEditor.RightMargin];
end;
end;
end;
type
TJvCustomEditorBaseAccessProtected = class(TJvCustomEditorBase);
procedure TJvHLEdPropDlg.SaveHighlighterColors(AJvHLEditor: TJvCustomEditorBase;
AHighlighter: TJvHighlighter);
var
Section: string;
procedure SaveColor(AColor: TJvSymbolColor; const Prefix: string);
begin
Storage.StoredValue[Section + Prefix] :=
ColorToString(AColor.ForeColor) + ', ' + ColorToString(AColor.BackColor) +
', ' + IntToStr(byte(AColor.Style));
end;
var
ed: TJvCustomEditorBaseAccessProtected;
HLed: IJvHLEditor;
begin
if Storage <> nil then
begin
// raise Exception.CreateRes(@RsEHLEdPropDlg_RegAutoNotAssigned);
ed := TJvCustomEditorBaseAccessProtected(AJvHLEditor);
FJvHLEditor.GetInterface(IJvHLEditor, HLed);
Section := AddSlash2(Storage.AppStoragePath) + AddSlash2(StorageSection) +
Highlighters[AHighlighter];
Storage.StoredValue[Section + 'BackColor'] := ColorToString(ed.Color);
Storage.StoredValue[Section + 'FontName'] := ed.Font.Name;
Storage.StoredValue[Section + 'Charset'] := IntToStr(ed.Font.CharSet);
Storage.StoredValue[Section + 'FontSize'] := ed.Font.Size;
Storage.StoredValue[Section + 'RightMarginColor'] := ColorToString(ed.RightMarginColor);
SaveColor(HLed.Colors.Number, 'Number');
SaveColor(HLed.Colors.Strings, 'Strings');
SaveColor(HLed.Colors.Symbol, 'Symbol');
SaveColor(HLed.Colors.Comment, 'Comment');
SaveColor(HLed.Colors.Reserved, 'Reserved');
SaveColor(HLed.Colors.Identifier, 'Identifier');
SaveColor(HLed.Colors.Preproc, 'Preproc');
SaveColor(HLed.Colors.FunctionCall, 'FunctionCall');
SaveColor(HLed.Colors.Declaration, 'Declaration');
SaveColor(HLed.Colors.Statement, 'Statement');
SaveColor(HLed.Colors.PlainText, 'PlainText');
end;
end;
procedure TJvHLEdPropDlg.LoadHighlighterColors(AJvHLEditor: TJvCustomEditorBase;
AHighlighter: TJvHighlighter);
var
Section: string;
procedure LoadColor(AColor: TJvSymbolColor; DefaultForeColor,
DefaultBackColor: TColor; DefaultStyle: TFontStyles; const Prefix: string);
var
S, S1: string;
begin
S := Storage.DefaultValue[Section + Prefix, ColorToString(DefaultForeColor) + ', ' + ColorToString(DefaultBackColor)
+ ', ' + IntToStr(byte(DefaultStyle))];
S1 := Trim(SubStr(S, 0, ','));
if S1 <> '' then
AColor.ForeColor := StringToColor(S1)
else
AColor.ForeColor := DefaultForeColor;
S1 := Trim(SubStr(S, 1, ','));
if S1 <> '' then
AColor.BackColor := StringToColor(S1)
else
AColor.BackColor := DefaultBackColor;
S1 := Trim(SubStr(S, 2, ','));
if S1 <> '' then
AColor.Style := TFontStyles(byte(StrToInt(S1)))
else
AColor.Style := DefaultStyle;
end;
var
ed: TJvCustomEditorBaseAccessProtected;
HLed: IJvHLEditor;
begin
if Storage <> nil then
begin
// raise Exception.CreateRes(@RsEHLEdPropDlg_RegAutoNotAssigned);
ed := TJvCustomEditorBaseAccessProtected(AJvHLEditor);
FJvHLEditor.GetInterface(IJvHLEditor, HLed);
Section := AddSlash2(StorageSection) + Highlighters[AHighlighter];
LoadColor(HLed.Colors.Number, clNavy, clWindow, [], 'Number');
LoadColor(HLed.Colors.Strings, clMaroon, clWindow, [], 'Strings');
LoadColor(HLed.Colors.Symbol, clBlue, clWindow, [], 'Symbol');
LoadColor(HLed.Colors.Comment, clOlive, clWindow, [fsItalic], 'Comment');
LoadColor(HLed.Colors.Reserved, clWindowText, clWindow, [fsBold], 'Reserved');
LoadColor(HLed.Colors.Identifier, clWindowText, clWindow, [], 'Identifier');
LoadColor(HLed.Colors.Preproc, clGreen, clWindow, [], 'Preproc');
LoadColor(HLed.Colors.FunctionCall, clWindowText, clWindow, [], 'FunctionCall');
LoadColor(HLed.Colors.Declaration, clWindowText, clWindow, [], 'Declaration');
LoadColor(HLed.Colors.Statement, clWindowText, clWindow, [], 'Statement');
LoadColor(HLed.Colors.PlainText, clWindowText, clWindow, [], 'PlainText');
try
AJvHLEditor.Color := StringToColor(Storage.ReadString(Section + 'BackColor', 'clWindow'));
except
on E: EConvertError do
AJvHLEditor.RightMarginColor := clWindow;
end;
ed.Font.Name := Storage.ReadString(Section + 'FontName', 'Courier New');
ed.Font.CharSet := Storage.ReadInteger(Section + 'Charset', DEFAULT_CHARSET);
ed.Font.Size := Storage.ReadInteger(Section + 'FontSize', 10);
try
ed.RightMarginColor := StringToColor(Storage.ReadString(Section + 'RightMarginColor', 'clSilver'));
except
on E: EConvertError do
AJvHLEditor.RightMarginColor := clSilver;
end;
end;
end;
function TJvHLEdPropDlg.Execute: Boolean;
var
F: Integer;
Form: TJvHLEditorParamsForm;
HLed: IJvHLEditor;
begin
if FJvHLEditor = nil then
raise EJVCLException.CreateRes(@RsEHLEdPropDlg_RAHLEditorNotAssigned);
Form := TJvHLEditorParamsForm.Create(Application);
Form.ColorSamples.Assign(ColorSamples);
with Form do
try
FJvHLEditor.GetInterface(IJvHLEditor, HLed);
FHighlighter := HLed.Highlighter;
Params := Self;
ParamsToControls;
if FReadFrom = rfHLEditor then
JvHLEditorPreview.Assign(FJvHLEditor);
tsEditor.TabVisible := epEditor in FPages;
tsColors.TabVisible := epColors in FPages;
F := FActivePage;
if Assigned(FOnDialogPopup) then
FOnDialogPopup(Self, Form);
if Storage <> nil then
F := Storage.ReadInteger(AddSlash2(StorageSection) + 'Params' + 'ActivePage', F);
F := Max(Min(F, Pages.PageCount - 1), 0);
if not Pages.Pages[F].TabVisible then
Pages.ActivePage := Pages.FindNextPage(Pages.Pages[F], True, True)
else
Pages.ActivePage := Pages.Pages[F];
Result := ShowModal = mrOK;
if Result then
begin
ControlsToParams;
FJvHLEditor.Assign(JvHLEditorPreview);
end;
if (Storage <> nil) and (Pages.ActivePage <> nil) then
Storage.WriteInteger(AddSlash2(StorageSection) + 'Params' +
'ActivePage', Pages.ActivePage.PageIndex);
if Assigned(FOnDialogClosed) then
FOnDialogClosed(Self, Form, Result);
finally
Free;
end;
end;
procedure TJvHLEdPropDlg.LoadCurrentHighlighterColors;
var
HLed: IJvHLEditor;
begin
if FJvHLEditor.GetInterface(IJvHLEditor, HLed) then
LoadHighlighterColors(FJvHLEditor, HLed.Highlighter);
end;
procedure TJvHLEdPropDlg.SaveCurrentHighlighterColors;
var
HLed: IJvHLEditor;
begin
if FJvHLEditor.GetInterface(IJvHLEditor, HLed) then
SaveHighlighterColors(FJvHLEditor, HLed.Highlighter);
end;
function TJvHLEdPropDlg.GetColorSamples: TStrings;
begin
Result := FColorSamples;
end;
procedure TJvHLEdPropDlg.SetColorSamples(Value: TStrings);
begin
FColorSamples.Assign(Value);
end;
function TJvHLEdPropDlg.IsPagesStored: Boolean;
begin
Result := FPages <> [epColors];
end;
procedure TJvHLEdPropDlg.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if Operation = opRemove then
begin
if AComponent = JvHLEditor then
FJvHLEditor := nil // do not call SetJvHLEditor
else
if AComponent = Storage then
FStorage := nil;
end;
end;
procedure TJvHLEdPropDlg.SetJvHLEditor(const Value: TJvCustomEditorBase);
var
HLed: IJvHLEditor;
begin
if Value <> FJvHLEditor then
begin
if Value <> nil then
begin
if Value.GetInterface(IJvHLEditor, HLed) then
FJvHLEditor := Value;
end
else
FJvHLEditor := nil;
end;
end;
//=== { TJvHLEditorParamsForm } ==============================================
constructor TJvHLEditorParamsForm.Create(AOwner: TComponent);
var
HL: TJvHighlighter;
begin
inherited Create(AOwner);
FColorSamples := TStringList.Create;
cbColorSettings.Clear;
for HL := Low(TJvHighlighter) to Pred(High(TJvHighlighter)) do
cbColorSettings.Items.AddObject(HighlighterNames[HL], nil);
end;
destructor TJvHLEditorParamsForm.Destroy;
begin
FColorSamples.Free;
inherited Destroy;
end;
function TJvHLEditorParamsForm.GetColorSamples: TStrings;
begin
Result := FColorSamples;
end;
procedure TJvHLEditorParamsForm.SetColorSamples(Value: TStrings);
begin
FColorSamples.Assign(Value);
end;
procedure TJvHLEditorParamsForm.ParamsToControls;
var
I: Integer;
HLed: IJvHLEditor;
begin
Params.FJvHLEditor.GetInterface(IJvHLEditor, HLed);
cbDoubleClickLine.Checked := Params.FJvHLEditor.DoubleClickLine;
cbUndoAfterSave.Checked := Params.FJvHLEditor.UndoAfterSave;
cbKeepTrailingBlanks.Checked := Params.FJvHLEditor.KeepTrailingBlanks;
cbAutoIndent.Checked := Params.FJvHLEditor.AutoIndent;
cbSmartTab.Checked := Params.FJvHLEditor.SmartTab;
cbBackspaceUnindents.Checked := Params.FJvHLEditor.BackSpaceUnindents;
cbGroupUndo.Checked := Params.FJvHLEditor.GroupUndo;
cbCursorBeyondEOF.Checked := Params.FJvHLEditor.CursorBeyondEOF;
cbSytaxHighlighting.Checked := HLed.SyntaxHighlighting;
eTabStops.Text := Params.FJvHLEditor.TabStops;
cbColorSettings.ItemIndex := Integer(FHighlighter);
cbColorSettingsChange(nil);
JvHLEditorPreview.RightMargin := Params.FJvHLEditor.RightMargin;
cbColorSettings.Visible := Params.FHighlighterCombo;
lblColorSpeedSettingsFor.Visible := Params.FHighlighterCombo;
if not Params.FHighlighterCombo then
begin
for I := 0 to tsColors.ControlCount - 1 do
tsColors.Controls[I].Top := tsColors.Controls[I].Top - Pixels(tsColors, 24);
JvHLEditorPreview.Height := JvHLEditorPreview.Height + Pixels(tsColors, 24);
end;
end;
procedure TJvHLEditorParamsForm.ControlsToParams;
var
HLed: IJvHLEditor;
begin
Params.FJvHLEditor.GetInterface(IJvHLEditor, HLed);
Params.FJvHLEditor.DoubleClickLine := cbDoubleClickLine.Checked;
Params.FJvHLEditor.UndoAfterSave := cbUndoAfterSave.Checked;
Params.FJvHLEditor.KeepTrailingBlanks := cbKeepTrailingBlanks.Checked;
Params.FJvHLEditor.AutoIndent := cbAutoIndent.Checked;
Params.FJvHLEditor.SmartTab := cbSmartTab.Checked;
Params.FJvHLEditor.BackSpaceUnindents := cbBackspaceUnindents.Checked;
Params.FJvHLEditor.GroupUndo := cbGroupUndo.Checked;
Params.FJvHLEditor.CursorBeyondEOF := cbCursorBeyondEOF.Checked;
HLed.SyntaxHighlighting := cbSytaxHighlighting.Checked;
Params.FJvHLEditor.TabStops := eTabStops.Text;
if Params.Storage <> nil then
Params.SaveHighlighterColors(JvHLEditorPreview, JvHLEditorPreview.Highlighter);
end;
procedure TJvHLEditorParamsForm.FormCreate(Sender: TObject);
begin
LoadLocale;
JvHLEditorPreview := TJvSampleViewer.Create(Self);
JvHLEditorPreview.Parent := tsColors;
JvHLEditorPreview.SetBounds(8, 176, 396, 110);
JvHLEditorPreview.TabStop := False;
cbKeyboardLayout.ItemIndex := 0;
cbColorSettings.ItemIndex := 0;
lbElements.ItemIndex := 0;
lbElementsClick(nil);
end;
procedure TJvHLEditorParamsForm.NotImplemented(Sender: TObject);
begin
//(Sender as TCheckBox).Checked := True;
//raise Exception.CreateRes(@RsEHLEdPropDlg_OptionCantBeChanged);
end;
{ Color tab }
{ Color grid }
function TJvHLEditorParamsForm.GetCell(const Index: Integer): TPanel;
begin
Result := FindComponent('Cell' + IntToStr(Index)) as TPanel;
if Result = nil then
raise EJVCLException.CreateRes(@RsEHLEdPropDlg_GridCellNotFound);
end;
function TJvHLEditorParamsForm.ColorToIndex(const AColor: TColor): Integer;
var
I: Integer;
begin
Result := -1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -