📄 jvhleditorpropertyform.pas
字号:
for I := 0 to 15 do
if GetCell(I).Color = AColor then
begin
Result := I;
Exit;
end;
end;
function TJvHLEditorParamsForm.GetColorIndex(const ColorName: string): Integer;
var
I: Integer;
begin
Result := -1;
for I := 0 to 15 do
if (GetCell(I).Caption = 'FB') or (GetCell(I).Caption = ColorName) then
begin
Result := I;
Exit;
end;
end;
function TJvHLEditorParamsForm.GetForegroundIndex: Integer;
begin
Result := GetColorIndex('FC');
end;
function TJvHLEditorParamsForm.GetBackgroundIndex: Integer;
begin
Result := GetColorIndex('BC');
end;
function TJvHLEditorParamsForm.GetColorColor(const ColorName: string): TColor;
var
Index: Integer;
begin
Index := GetColorIndex(ColorName);
if Index > -1 then
Result := GetCell(Index).Color
else
Result := clBlack;
end;
function TJvHLEditorParamsForm.GetForegroundColor: TColor;
begin
Result := GetColorColor('FC');
end;
function TJvHLEditorParamsForm.GetBackgroundColor: TColor;
begin
Result := GetColorColor('BC');
end;
procedure TJvHLEditorParamsForm.SetColorIndex(const Index: Integer;
const ColorName, OtherColorName: string);
var
I: Integer;
begin
for I := 0 to 15 do
if (GetCell(I).Caption = 'FB') or (GetCell(I).Caption = ColorName) then
GetCell(I).Caption := ColorName
else
GetCell(I).Caption := '';
if Index > -1 then
if GetCell(Index).Caption = ColorName then
GetCell(Index).Caption := 'FB'
else
GetCell(Index).Caption := OtherColorName;
end;
procedure TJvHLEditorParamsForm.SetForegroundIndex(const Index: Integer);
begin
SetColorIndex(Index, 'BC', 'FC');
end;
procedure TJvHLEditorParamsForm.SetBackgroundIndex(const Index: Integer);
begin
SetColorIndex(Index, 'FC', 'BC');
end;
procedure TJvHLEditorParamsForm.CellMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
SetForegroundIndex((Sender as TPanel).Tag)
else
if Button = mbRight then
SetBackgroundIndex((Sender as TPanel).Tag);
ColorChange(Sender);
end;
{ color grid ### }
procedure TJvHLEditorParamsForm.lbElementsClick(Sender: TObject);
var
FC, BC: TColor;
ST: TFontStyles;
begin
InChanging := True;
try
SC := nil;
ST := [];
FC := clWindowText;
BC := clWindow;
case lbElements.ItemIndex of
0: { Whitespace }
begin
FC := JvHLEditorPreview.Font.Color;
BC := JvHLEditorPreview.Color;
end;
1: { Comment }
SC := JvHLEditorPreview.Colors.Comment;
2: { Reserved word }
SC := JvHLEditorPreview.Colors.Reserved;
3: { Identifier }
SC := JvHLEditorPreview.Colors.Identifier;
4: { Symbol }
SC := JvHLEditorPreview.Colors.Symbol;
5: { String }
SC := JvHLEditorPreview.Colors.Strings;
6: { Number }
SC := JvHLEditorPreview.Colors.Number;
7: { Preprocessor }
SC := JvHLEditorPreview.Colors.Preproc;
8: { Declaration }
SC := JvHLEditorPreview.Colors.Declaration;
9: { Function call }
SC := JvHLEditorPreview.Colors.FunctionCall;
10: { VB Statement }
SC := JvHLEditorPreview.Colors.Statement;
11: { PlainText }
SC := JvHLEditorPreview.Colors.PlainText;
12: { Marked block }
begin
FC := JvHLEditorPreview.SelForeColor;
BC := JvHLEditorPreview.SelBackColor;
end;
13: { Right margin }
begin
FC := JvHLEditorPreview.RightMarginColor;
BC := -1;
end;
end;
if SC <> nil then
begin
FC := SC.ForeColor;
BC := SC.BackColor;
ST := SC.Style;
end;
cbDefForeground.Checked := ((lbElements.ItemIndex < 12) and (FC = clWindowText)) or
((lbElements.ItemIndex = 12) and (FC = clHighlightText));
cbDefBackground.Checked := ((lbElements.ItemIndex < 12) and (BC = clWindow)) or
((lbElements.ItemIndex = 12) and (BC = clHighlight));
if not cbDefForeground.Checked then
SetForegroundIndex(ColorToIndex(FC))
else
SetForegroundIndex(-1);
if not cbDefBackground.Checked then
SetBackgroundIndex(ColorToIndex(BC))
else
SetBackgroundIndex(-1);
cbBold.Checked := fsBold in ST;
cbItalic.Checked := fsItalic in ST;
cbUnderline.Checked := fsUnderline in ST;
finally
InChanging := False;
end;
end;
procedure TJvHLEditorParamsForm.ColorChange(Sender: TObject);
var
FC, BC: TColor;
ST: TFontStyles;
begin
if InChanging then
Exit;
InChanging := True;
try
ST := [];
if GetForegroundIndex <> -1 then
cbDefForeground.Checked := False;
if GetBackgroundIndex <> -1 then
cbDefBackground.Checked := False;
if cbDefForeground.Checked then
begin
if lbElements.ItemIndex = 12 then
FC := clHighlightText
else
FC := clWindowText;
SetForegroundIndex(-1);
end
else
FC := GetForegroundColor;
if cbDefBackground.Checked then
begin
if lbElements.ItemIndex = 12 then { marked block }
BC := clHighlight
else
BC := clWindow;
SetBackgroundIndex(-1);
end
else
BC := GetBackgroundColor;
if cbBold.Checked then
Include(ST, fsBold);
if cbItalic.Checked then
Include(ST, fsItalic);
if cbUnderline.Checked then
Include(ST, fsUnderline);
if SC <> nil then
begin
SC.Style := ST;
SC.ForeColor := FC;
SC.BackColor := BC;
end
else
if lbElements.ItemIndex = 12 then { marked block }
begin
JvHLEditorPreview.SelForeColor := FC;
JvHLEditorPreview.SelBackColor := BC;
end
else
if lbElements.ItemIndex = 0 then { whitespace }
JvHLEditorPreview.Color := BC
else
if lbElements.ItemIndex = 13 then { right margin }
JvHLEditorPreview.RightMarginColor := FC;
JvHLEditorPreview.Invalidate;
finally
InChanging := False;
end;
end;
procedure TJvHLEditorParamsForm.DefClick(Sender: TObject);
begin
if InChanging then
Exit;
if cbDefForeground.Checked then
SetForegroundIndex(-1);
if cbDefBackground.Checked then
SetBackgroundIndex(-1);
ColorChange(nil);
end;
procedure TJvHLEditorParamsForm.lbElementsDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
with (Control as TListBox).Canvas do { draw on control canvas, not on the form }
begin
FillRect(Rect); { clear the rectangle }
TextOut(Rect.Left, Rect.Top, (Control as TListBox).Items[Index]) { display the text }
end;
end;
procedure ReadColorSampleSection(Ini: TStrings; const Section: string; Lines: TStrings);
var
I: Integer;
S: string;
InSection: Boolean;
begin
Lines.Clear;
InSection := False;
for I := 0 to Ini.Count - 1 do
begin
S := Ini[I];
if (S <> '') and (S[1] = '[') and (S[Length(S)] = ']') then
begin
if AnsiSameText(Copy(S, 2, Length(S) - 2), Section) then
InSection := True
else
if InSection then
Break;
Continue;
end;
if InSection then
Lines.Add(Ini[I]);
end;
end;
procedure TJvHLEditorParamsForm.cbColorSettingsChange(Sender: TObject);
var
I: Integer;
begin
if (Sender <> nil) and (Params.Storage <> nil) then
Params.SaveHighlighterColors(JvHLEditorPreview, JvHLEditorPreview.Highlighter);
if cbColorSettings.Visible then
ReadColorSampleSection(ColorSamples, cbColorSettings.Text, JvHLEditorPreview.Lines)
else
ReadColorSampleSection(ColorSamples, HighlighterNames[FHighlighter], JvHLEditorPreview.Lines);
JvHLEditorPreview.Highlighter := TJvHighlighter(cbColorSettings.ItemIndex);
if JvHLEditorPreview.Highlighter = hlIni then
for I := 0 to JvHLEditorPreview.Lines.Count - 1 do
JvHLEditorPreview.Lines[I] := Copy(JvHLEditorPreview.Lines[I], 2, 10000);
if Params.Storage <> nil then
Params.LoadHighlighterColors(JvHLEditorPreview, JvHLEditorPreview.Highlighter);
lbElementsClick(nil);
end;
procedure TJvHLEditorParamsForm.LoadLocale;
begin
Caption := RsHLEdPropDlg_Caption;
tsEditor.Caption := RsHLEdPropDlg_tsEditor;
tsColors.Caption := RsHLEdPropDlg_tsColors;
lblEditorSpeedSettings.Caption := RsHLEdPropDlg_lblEditorSpeedSettings;
cbKeyboardLayout.Items[0] := RsHLEdPropDlg_cbKeyboardLayoutDefault;
gbEditor.Caption := RsHLEdPropDlg_gbEditor;
cbAutoIndent.Caption := RsHLEdPropDlg_cbAutoIndent;
cbSmartTab.Caption := RsHLEdPropDlg_cbSmartTab;
cbBackspaceUnindents.Caption := RsHLEdPropDlg_cbBackspaceUnindents;
cbGroupUndo.Caption := RsHLEdPropDlg_cbGroupUndo;
cbCursorBeyondEOF.Caption := RsHLEdPropDlg_cbCursorBeyondEOF;
cbUndoAfterSave.Caption := RsHLEdPropDlg_cbUndoAfterSave;
cbKeepTrailingBlanks.Caption := RsHLEdPropDlg_cbKeepTrailingBlanks;
cbDoubleClickLine.Caption := RsHLEdPropDlg_cbDoubleClickLine;
cbSytaxHighlighting.Caption := RsHLEdPropDlg_cbSytaxHighlighting;
lblTabStops.Caption := RsHLEdPropDlg_lblTabStops;
lblColorSpeedSettingsFor.Caption := RsHLEdPropDlg_lblColorSpeedSettingsFor;
lblElement.Caption := RsHLEdPropDlg_lblElement;
lblColor.Caption := RsHLEdPropDlg_lblColor;
gbTextAttributes.Caption := RsHLEdPropDlg_gbTextAttributes;
gbUseDefaultsFor.Caption := RsHLEdPropDlg_gbUseDefaultsFor;
cbBold.Caption := RsHLEdPropDlg_cbBold;
cbItalic.Caption := RsHLEdPropDlg_cbItalic;
cbUnderline.Caption := RsHLEdPropDlg_cbUnderline;
cbDefForeground.Caption := RsHLEdPropDlg_cbDefForeground;
cbDefBackground.Caption := RsHLEdPropDlg_cbDefBackground;
bOK.Caption := RsButtonOKCaption;
bCancel.Caption := RsButtonCancelCaption;
end;
function GetHardCodedExamples: string;
begin
Result :=
'[Default]'#10 +
'Plain text'#10 +
'Selected text'#10 +
''#10 +
'[Pascal]'#10 +
'{ Syntax highlighting }'#10 +
'{$DEFINE DELPHI}'#10 +
'procedure TMain.JvHLEditorPreviewChangeStatus(Sender: TObject);'#10 +
'const'#10 +
' Modi: array [Boolean] of string[10] = ('#39#39', '#39'Modified'#39');'#10 +
' Modes: array [Boolean] of string[10] = ('#39'Overwrite'#39', '#39'Insert'#39');'#10 +
'begin'#10 +
' with StatusBar, JvHLEditorPreview do'#10 +
' begin'#10 +
' Panels[0].Text := IntToStr(CaretY) + '#39':'#39' + IntToStr(CaretX);'#10 +
' Panels[1].Text := Modi[Modified];'#10 +
' if ReadOnly then'#10 +
' Panels[2].Text := '#39'ReadOnly'#39 +
' else'#10 +
' if Recording then'#10 +
' Panels[2].Text := '#39'Recording'#39 +
' else'#10 +
' Panels[2].Text := Modes[InsertMode];'#10 +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -