📄 syneditoptionsdialog.pas
字号:
var I : Integer;
C : TColor;
B : TBitmap;
begin
{$IFDEF SYN_COMPILER_4_UP}
KeyList.OnSelectItem := KeyListSelectItem;
{$ELSE}
FOldWndProc := KeyList.WindowProc;
KeyList.WindowProc := OverridingWndProc;
FOnSelectItem := KeyListSelectItem;
{$ENDIF}
InChanging := False;
B:= TBitmap.Create;
try
B.Width:= 16;
B.Height:= 16;
//Loop through and create colored images
for I:= 0 to ColorPopup.Items.Count-1 do
begin
if ColorPopup.Items[I].Tag = -1 then Continue;
C:= GetColor(ColorPopup.Items[I]);
B.Canvas.Brush.Color:= C;
B.Canvas.Brush.Style:= bsSolid;
B.Canvas.Pen.Style:= psSolid;
B.Canvas.Pen.Color:= clBlack;
B.Canvas.Rectangle(0,0,16,16);
ImageList1.Add(B, nil);
{$IFDEF SYN_COMPILER_4_UP}
ColorPopup.Items[I].ImageIndex:= ColorPopup.Items[I].Tag;
{$ENDIF}
end;
finally
B.Free;
end;
eKeyShort1:= TSynHotKey.Create(Self);
with eKeyShort1 do
begin
Parent := gbKeystrokes;
Left := 120;
Top := 55;
Width := 185;
Height := 21;
HotKey := 0;
InvalidKeys := [];
Modifiers := [];
TabOrder := 1;
end;
eKeyShort2:= TSynHotKey.Create(Self);
with eKeyShort2 do
begin
Parent := gbKeystrokes;
Left := 120;
Top := 87;
Width := 185;
Height := 21;
HotKey := 0;
InvalidKeys := [];
Modifiers := [];
TabOrder := 2;
end;
end;
procedure TfmEditorOptionsDialog.pGutterColorClick(Sender: TObject);
begin
ColorDialog.Color:= pGutterColor.Color;
if (ColorDialog.Execute) then
begin
pGutterColor.Color:= ColorDialog.Color;
end;
end;
procedure TfmEditorOptionsDialog.pRightEdgeColorClick(Sender: TObject);
begin
ColorDialog.Color:= pRightEdgeColor.Color;
if (ColorDialog.Execute) then
begin
pRightEdgeColor.Color:= ColorDialog.Color;
end;
end;
procedure TfmEditorOptionsDialog.btnFontClick(Sender: TObject);
begin
FontDialog.Font.Assign(labFont.Font);
if FontDialog.Execute then
begin
labFont.Font.Assign(FontDialog.Font);
labFont.Caption:= labFont.Font.Name;
labFont.Caption:= labFont.Font.Name + ' ' + IntToStr(labFont.Font.Size) + 'pt';
end;
end;
procedure TfmEditorOptionsDialog.KeyListSelectItem(Sender: TObject;
Item: TListItem; Selected: Boolean);
begin
if KeyList.Selected = nil then Exit;
cKeyCommand.Text := KeyList.Selected.Caption;
cKeyCommand.ItemIndex := cKeyCommand.Items.IndexOf(KeyList.Selected.Caption);
eKeyShort1.HotKey := TSynEditKeyStroke(KeyList.Selected.Data).ShortCut;
eKeyShort2.HotKey := TSynEditKeyStroke(KeyList.Selected.Data).ShortCut2;
OldSelected := Item;
end;
procedure TfmEditorOptionsDialog.btnUpdateKeyClick(Sender: TObject);
var Cmd : Integer;
{ KeyLoc : Integer;
TmpCommand : String;
OldShortcut : TShortcut;
OldShortcut2 : TShortcut;
}
begin
if (KeyList.Selected = nil) and (Sender <> btnAddKey) then
begin
btnAddKey.Click;
Exit;
end;
if KeyList.Selected = nil then Exit;
if cKeyCommand.ItemIndex < 0 then Exit;
Cmd := Integer(cKeyCommand.Items.Objects[cKeyCommand.ItemIndex]);
TSynEditKeyStroke(OldSelected.Data).Command:= Cmd;
if eKeyShort1.HotKey <> 0 then
TSynEditKeyStroke(OldSelected.Data).ShortCut := eKeyShort1.HotKey;
if eKeyShort2.HotKey <> 0 then
TSynEditKeyStroke(OldSelected.Data).ShortCut2:= eKeyShort2.HotKey;
FillInKeystrokeInfo(TSynEditKeyStroke(OldSelected.Data), KeyList.Selected);
end;
procedure TfmEditorOptionsDialog.btnAddKeyClick(Sender: TObject);
var Item : TListItem;
begin
Item:= KeyList.Items.Add;
Item.Data:= FSynEdit.Keystrokes.Add;
Item.Selected:= True;
btnUpdateKeyClick(btnAddKey);
end;
procedure TfmEditorOptionsDialog.btnRemKeyClick(Sender: TObject);
begin
if KeyList.Selected = nil then Exit;
TSynEditKeyStroke(KeyList.Selected.Data).Free;
KeyList.Selected.Delete;
end;
procedure TfmEditorOptionsDialog.EditStrCallback(const S: string);
begin
//Add the Item
if FExtended then
cKeyCommand.Items.AddObject(S, TObject(ConvertExtendedToCommand(S)))
else cKeyCommand.Items.AddObject(S, TObject(ConvertCodeStringToCommand(S)));
end;
procedure TfmEditorOptionsDialog.FormShow(Sender: TObject);
var Commands: TStringList;
i : Integer;
begin
//We need to do this now because it will not have been assigned when
//create occurs
cKeyCommand.Items.Clear;
//Start the callback to add the strings
if FExtended then
GetEditorCommandExtended(EditStrCallback)
else
GetEditorCommandValues(EditStrCallBack);
//Now add in the user defined ones if they have any
if Assigned(FAllUserCommands) then
begin
Commands := TStringList.Create;
try
FAllUserCommands(Commands);
for i := 0 to Commands.Count - 1 do
if Commands.Objects[i] <> nil then
cKeyCommand.Items.AddObject(Commands[i], Commands.Objects[i]);
finally
Commands.Free;
end;
end;
PageControl1.ActivePage := PageControl1.Pages[0];
end;
procedure TfmEditorOptionsDialog.KeyListEditing(Sender: TObject;
Item: TListItem; var AllowEdit: Boolean);
begin
AllowEdit:= False;
end;
procedure TfmEditorOptionsDialog.btnOkClick(Sender: TObject);
begin
btnUpdateKey.Click;
ModalResult:= mrOk;
end;
procedure TfmEditorOptionsDialog.btnGutterFontClick(Sender: TObject);
begin
FontDialog.Font.Assign(lblGutterFont.Font);
if FontDialog.Execute then
begin
lblGutterFont.Font.Assign(FontDialog.Font);
lblGutterFont.Caption:= lblGutterFont.Font.Name + ' ' + IntToStr(lblGutterFont.Font.Size) + 'pt';
end;
end;
procedure TfmEditorOptionsDialog.cbGutterFontClick(Sender: TObject);
begin
lblGutterFont.Enabled := cbGutterFont.Checked;
btnGutterFont.Enabled := cbGutterFont.Checked;
end;
procedure TfmEditorOptionsDialog.btnRightEdgeMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var P : TPoint;
begin
FPoppedFrom:= cpRightEdge;
P:= pRightEdgeColor.ClientToScreen(Point(-1, pRightEdgeColor.Height-1));
btnRightEdge.BevelOuter := bvLowered;
ColorPopup.Popup(P.X, P.Y);
btnRightEdge.BevelOuter := bvNone;
end;
procedure TfmEditorOptionsDialog.btnGutterColorMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var P : TPoint;
begin
FPoppedFrom:= cpGutter;
P:= pGutterColor.ClientToScreen(Point(-1, pGutterColor.Height-1));
btnGutterColor.BevelOuter := bvLowered;
ColorPopup.Popup(P.X, P.Y);
btnGutterColor.BevelOuter := bvNone;
end;
procedure TfmEditorOptionsDialog.FillInKeystrokeInfo(
AKey: TSynEditKeystroke; AItem: TListItem);
var TmpString: String;
begin
with AKey do
begin
if Command >= ecUserFirst then
begin
TmpString := 'User Command';
if Assigned(GetUserCommandNames) then
GetUserCommandNames(Command, TmpString);
end else begin
if FExtended then
TmpString := ConvertCodeStringToExtended(EditorCommandToCodeString(Command))
else TmpString := EditorCommandToCodeString(Command);
end;
AItem.Caption:= TmpString;
AItem.SubItems.Clear;
TmpString := '';
if Shortcut <> 0 then
TmpString := ShortCutToText(ShortCut);
if (TmpString <> '') and (Shortcut2 <> 0) then
TmpString := TmpString + ' ' + ShortCutToText(ShortCut2);
AItem.SubItems.Add(TmpString);
end;
end;
procedure TfmEditorOptionsDialog.cKeyCommandExit(Sender: TObject);
VAR TmpIndex : Integer;
begin
TmpIndex := cKeyCommand.Items.IndexOf(cKeyCommand.Text);
if TmpIndex = -1 then
begin
if FExtended then
cKeyCommand.ItemIndex := cKeyCommand.Items.IndexOf(ConvertCodeStringToExtended('ecNone'))
else cKeyCommand.ItemIndex := cKeyCommand.Items.IndexOf('ecNone');
end else cKeyCommand.ItemIndex := TmpIndex; //need to force it incase they just typed something in
end;
procedure TfmEditorOptionsDialog.cKeyCommandKeyPress(Sender: TObject;
var Key: Char);
var WorkStr : String;
i : Integer;
begin
//This would be better if componentized, but oh well...
WorkStr := AnsiUppercase(Copy(cKeyCommand.Text, 1, cKeyCommand.SelStart) + Key);
i := 0;
While i < cKeyCommand.Items.Count do
begin
if pos(WorkStr, AnsiUppercase(cKeyCommand.Items[i])) = 1 then
begin
cKeyCommand.Text := cKeyCommand.Items[i];
cKeyCommand.SelStart := length(WorkStr);
cKeyCommand.SelLength := Length(cKeyCommand.Text) - cKeyCommand.SelStart;
Key := #0;
break;
end else inc(i);
end;
end;
procedure TfmEditorOptionsDialog.cKeyCommandKeyUp(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
if Key = SYNEDIT_RETURN then btnUpdateKey.Click;
end;
procedure TfmEditorOptionsDialog.KeyListChanging(Sender: TObject;
Item: TListItem; Change: TItemChange; var AllowChange: Boolean);
begin
//make sure that it's saved.
if InChanging then exit;
InChanging := True;
if Visible then
begin
if (Item = OldSelected) and
((Item.Caption <> cKeyCommand.Text) or
(TSynEditKeystroke(Item.Data).ShortCut <> eKeyShort1.HotKey) or
(TSynEditKeystroke(Item.Data).ShortCut2 <> eKeyShort2.HotKey)) then
begin
btnUpdateKeyClick(btnUpdateKey);
end;
end;
InChanging := False;
end;
{$IFNDEF SYN_COMPILER_4_UP}
procedure TfmEditorOptionsDialog.OverridingWndProc(var Message: TMessage);
var
Item: TListItem;
begin
FOldWndProc(Message);
if Message.Msg = CN_NOTIFY then
with TWMNotify(Message) do
if NMHdr.code = LVN_ITEMCHANGED then
with PNMListView(NMHdr)^ do
begin
Item := KeyList.Items[iItem];
if Assigned(FOnSelectItem) and (uChanged = LVIF_STATE) then
begin
if (uOldState and LVIS_SELECTED <> 0) and
(uNewState and LVIS_SELECTED = 0) then
FOnSelectItem(Self, Item, False)
else if (uOldState and LVIS_SELECTED = 0) and
(uNewState and LVIS_SELECTED <> 0) then
FOnSelectItem(Self, Item, True);
end;
end;
end;
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -