mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Issue #1659: create dialog for customizing highlighter colors and style, for use on grid text editor
This commit is contained in:
@ -6718,3 +6718,15 @@ msgstr "Foreign key not found for column \"%s\""
|
||||
|
||||
msgid "Empty recent filters"
|
||||
msgstr "Empty recent filters"
|
||||
|
||||
msgid "Customize highlighter"
|
||||
msgstr "Customize highlighter"
|
||||
|
||||
msgid "Example text"
|
||||
msgstr "Example text"
|
||||
|
||||
msgid "Color picker"
|
||||
msgstr "Color picker"
|
||||
|
||||
msgid "Style:"
|
||||
msgstr "Style:"
|
||||
|
3
packages/Delphi11.1/heidisql.dpr
vendored
3
packages/Delphi11.1/heidisql.dpr
vendored
@ -53,7 +53,8 @@ uses
|
||||
Vcl.Graphics,
|
||||
theme_preview in '..\..\source\theme_preview.pas' {frmThemePreview},
|
||||
csv_detector in '..\..\source\csv_detector.pas' {frmCsvDetector},
|
||||
generic_types in '..\..\source\generic_types.pas';
|
||||
generic_types in '..\..\source\generic_types.pas',
|
||||
customize_highlighter in '..\..\source\customize_highlighter.pas' {frmCustomizeHighlighter};
|
||||
|
||||
{.$R *.RES}
|
||||
{$R ..\..\res\icon.RES}
|
||||
|
4
packages/Delphi11.1/heidisql.dproj
vendored
4
packages/Delphi11.1/heidisql.dproj
vendored
@ -257,6 +257,10 @@
|
||||
<Form>frmCsvDetector</Form>
|
||||
</DCCReference>
|
||||
<DCCReference Include="..\..\source\generic_types.pas"/>
|
||||
<DCCReference Include="..\..\source\customize_highlighter.pas">
|
||||
<Form>frmCustomizeHighlighter</Form>
|
||||
<FormType>dfm</FormType>
|
||||
</DCCReference>
|
||||
<None Include="..\..\source\const.inc"/>
|
||||
<BuildConfiguration Include="Base">
|
||||
<Key>Base</Key>
|
||||
|
@ -280,6 +280,7 @@ type
|
||||
function DirnameUserDocuments: String;
|
||||
function DirnameSnippets: String;
|
||||
function DirnameBackups: String;
|
||||
function DirnameHighlighters: String;
|
||||
// "Static" options, initialized in OnCreate only. For settings which need a restart to take effect.
|
||||
property RestoreTabsInitValue: Boolean read FRestoreTabsInitValue;
|
||||
end;
|
||||
@ -4425,6 +4426,19 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function TAppSettings.DirnameHighlighters: string;
|
||||
begin
|
||||
if PortableMode then begin
|
||||
Result := ExtractFilePath(Application.ExeName) + 'Highlighters\'
|
||||
end else begin
|
||||
Result := DirnameUserAppData + 'Highlighters\';
|
||||
end;
|
||||
if not DirectoryExists(Result) then begin
|
||||
ForceDirectories(Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{ TUTF8NoBOMEncoding }
|
||||
|
||||
|
166
source/customize_highlighter.dfm
Normal file
166
source/customize_highlighter.dfm
Normal file
@ -0,0 +1,166 @@
|
||||
object frmCustomizeHighlighter: TfrmCustomizeHighlighter
|
||||
Left = 0
|
||||
Top = 0
|
||||
BorderStyle = bsDialog
|
||||
Caption = 'Customize highlighter'
|
||||
ClientHeight = 249
|
||||
ClientWidth = 441
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -12
|
||||
Font.Name = 'Segoe UI'
|
||||
Font.Style = []
|
||||
Position = poOwnerFormCenter
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
DesignSize = (
|
||||
441
|
||||
249)
|
||||
TextHeight = 15
|
||||
object lblBackground: TLabel
|
||||
Left = 159
|
||||
Top = 37
|
||||
Width = 67
|
||||
Height = 15
|
||||
Caption = 'Background:'
|
||||
end
|
||||
object lblForeground: TLabel
|
||||
Left = 159
|
||||
Top = 65
|
||||
Width = 65
|
||||
Height = 15
|
||||
Caption = 'Foreground:'
|
||||
end
|
||||
object lblStyle: TLabel
|
||||
Left = 159
|
||||
Top = 90
|
||||
Width = 28
|
||||
Height = 15
|
||||
Caption = 'Style:'
|
||||
end
|
||||
object lblSample: TLabel
|
||||
Left = 277
|
||||
Top = 175
|
||||
Width = 156
|
||||
Height = 26
|
||||
Alignment = taCenter
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
AutoSize = False
|
||||
Caption = 'Example text'
|
||||
Color = clBtnFace
|
||||
ParentColor = False
|
||||
Transparent = False
|
||||
Layout = tlCenter
|
||||
end
|
||||
object comboHighlighter: TComboBox
|
||||
Left = 8
|
||||
Top = 8
|
||||
Width = 145
|
||||
Height = 23
|
||||
Style = csDropDownList
|
||||
Sorted = True
|
||||
TabOrder = 0
|
||||
OnSelect = comboHighlighterSelect
|
||||
end
|
||||
object listboxAttributes: TListBox
|
||||
Left = 8
|
||||
Top = 37
|
||||
Width = 145
|
||||
Height = 173
|
||||
ItemHeight = 15
|
||||
TabOrder = 1
|
||||
OnClick = listboxAttributesClick
|
||||
end
|
||||
object chkBold: TCheckBox
|
||||
Left = 277
|
||||
Top = 90
|
||||
Width = 156
|
||||
Height = 17
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
Caption = 'Bold'
|
||||
TabOrder = 4
|
||||
OnClick = Modified
|
||||
end
|
||||
object chkItalic: TCheckBox
|
||||
Left = 277
|
||||
Top = 113
|
||||
Width = 156
|
||||
Height = 17
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
Caption = 'Italic'
|
||||
TabOrder = 5
|
||||
OnClick = Modified
|
||||
end
|
||||
object btnCancel: TButton
|
||||
Left = 277
|
||||
Top = 216
|
||||
Width = 75
|
||||
Height = 25
|
||||
Anchors = [akRight, akBottom]
|
||||
Cancel = True
|
||||
Caption = 'Cancel'
|
||||
ModalResult = 2
|
||||
TabOrder = 8
|
||||
end
|
||||
object btnOK: TButton
|
||||
Left = 196
|
||||
Top = 216
|
||||
Width = 75
|
||||
Height = 25
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = 'OK'
|
||||
Default = True
|
||||
ModalResult = 1
|
||||
TabOrder = 7
|
||||
OnClick = SaveSettings
|
||||
end
|
||||
object editBackground: TButtonedEdit
|
||||
Left = 277
|
||||
Top = 34
|
||||
Width = 156
|
||||
Height = 23
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
Images = MainForm.VirtualImageListMain
|
||||
RightButton.Hint = 'Color picker'
|
||||
RightButton.ImageIndex = 33
|
||||
RightButton.Visible = True
|
||||
TabOrder = 2
|
||||
OnExit = Modified
|
||||
OnRightButtonClick = editColorRightButtonClick
|
||||
end
|
||||
object editForeground: TButtonedEdit
|
||||
Left = 277
|
||||
Top = 62
|
||||
Width = 156
|
||||
Height = 23
|
||||
Anchors = [akLeft, akTop, akRight]
|
||||
Images = MainForm.VirtualImageListMain
|
||||
RightButton.Hint = 'Color picker'
|
||||
RightButton.ImageIndex = 33
|
||||
RightButton.Visible = True
|
||||
TabOrder = 3
|
||||
OnExit = Modified
|
||||
OnRightButtonClick = editColorRightButtonClick
|
||||
end
|
||||
object pnlSample: TPanel
|
||||
Left = 277
|
||||
Top = 136
|
||||
Width = 156
|
||||
Height = 33
|
||||
Caption = 'Example text'
|
||||
Color = clGradientActiveCaption
|
||||
ParentBackground = False
|
||||
TabOrder = 6
|
||||
end
|
||||
object btnApply: TButton
|
||||
Left = 358
|
||||
Top = 216
|
||||
Width = 75
|
||||
Height = 25
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = 'Apply'
|
||||
TabOrder = 9
|
||||
OnClick = SaveSettings
|
||||
end
|
||||
end
|
205
source/customize_highlighter.pas
Normal file
205
source/customize_highlighter.pas
Normal file
@ -0,0 +1,205 @@
|
||||
unit customize_highlighter;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
||||
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.GraphUtil, System.Math,
|
||||
System.StrUtils, SynEditHighlighter, gnugettext, apphelpers;
|
||||
|
||||
type
|
||||
TfrmCustomizeHighlighter = class(TForm)
|
||||
comboHighlighter: TComboBox;
|
||||
listboxAttributes: TListBox;
|
||||
lblBackground: TLabel;
|
||||
lblForeground: TLabel;
|
||||
lblStyle: TLabel;
|
||||
chkBold: TCheckBox;
|
||||
chkItalic: TCheckBox;
|
||||
btnCancel: TButton;
|
||||
btnOK: TButton;
|
||||
editBackground: TButtonedEdit;
|
||||
editForeground: TButtonedEdit;
|
||||
pnlSample: TPanel;
|
||||
btnApply: TButton;
|
||||
lblSample: TLabel;
|
||||
procedure listboxAttributesClick(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure comboHighlighterSelect(Sender: TObject);
|
||||
procedure SaveSettings(Sender: TObject);
|
||||
procedure editColorRightButtonClick(Sender: TObject);
|
||||
procedure Modified(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
private
|
||||
{ Private-Deklarationen }
|
||||
FHighlighter: TSynCustomHighlighter;
|
||||
FAttr: TSynHighlighterAttributes;
|
||||
FOnChange: TNotifyEvent;
|
||||
procedure SetFriendlyLanguageName(FriendlyLanguageName: String);
|
||||
function GetFriendlyLanguageName: String;
|
||||
procedure UpdateSampleBox;
|
||||
public
|
||||
{ Public-Deklarationen }
|
||||
property FriendlyLanguageName: String read GetFriendlyLanguageName write SetFriendlyLanguageName;
|
||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses main;
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
procedure TfrmCustomizeHighlighter.SaveSettings(Sender: TObject);
|
||||
begin
|
||||
// Save highlighter settings
|
||||
FHighlighter.SaveToFile(AppSettings.DirnameHighlighters + FHighlighter.LanguageName + '.ini');
|
||||
if Assigned(FOnChange) then
|
||||
FOnChange(Self);
|
||||
end;
|
||||
|
||||
procedure TfrmCustomizeHighlighter.Modified(Sender: TObject);
|
||||
begin
|
||||
// Apply modification to current attribute
|
||||
// Silence exception caused by invalid color strings
|
||||
try
|
||||
FAttr.Background := WebColorStrToColor(editBackground.Text);
|
||||
FAttr.Foreground := WebColorStrToColor(editForeground.Text);
|
||||
except
|
||||
end;
|
||||
if chkBold.Checked then
|
||||
FAttr.Style := FAttr.Style + [fsBold]
|
||||
else
|
||||
FAttr.Style := FAttr.Style - [fsBold];
|
||||
if chkItalic.Checked then
|
||||
FAttr.Style := FAttr.Style + [fsItalic]
|
||||
else
|
||||
FAttr.Style := FAttr.Style - [fsItalic];
|
||||
UpdateSampleBox;
|
||||
end;
|
||||
|
||||
procedure TfrmCustomizeHighlighter.comboHighlighterSelect(Sender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
Highlighters: TSynHighlighterList;
|
||||
begin
|
||||
// Highlighter selected
|
||||
listboxAttributes.Clear;
|
||||
if Assigned(FHighlighter) then
|
||||
FHighlighter.Free;
|
||||
Highlighters := SynEditHighlighter.GetPlaceableHighlighters;
|
||||
for i:=0 to Highlighters.Count-1 do begin
|
||||
if Highlighters[i].GetFriendlyLanguageName = comboHighlighter.Text then begin
|
||||
FHighlighter := Highlighters[i].Create(Self);
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
FHighlighter.LoadFromFile(AppSettings.DirnameHighlighters + FHighlighter.GetLanguageName + '.ini');
|
||||
for i:=0 to FHighlighter.AttrCount-1 do begin
|
||||
listboxAttributes.Items.Add(FHighlighter.Attribute[i].FriendlyName);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmCustomizeHighlighter.editColorRightButtonClick(
|
||||
Sender: TObject);
|
||||
var
|
||||
Dialog: TColorDialog;
|
||||
Edit: TButtonedEdit;
|
||||
begin
|
||||
// Color picker
|
||||
Edit := Sender as TButtonedEdit;
|
||||
Dialog := TColorDialog.Create(Self);
|
||||
Dialog.Options := [cdFullOpen, cdAnyColor];
|
||||
try
|
||||
Dialog.Color := WebColorStrToColor(Edit.Text);
|
||||
except
|
||||
end;
|
||||
if Dialog.Execute then begin
|
||||
Edit.Text := ColorToWebColorStr(Dialog.Color);
|
||||
end;
|
||||
Dialog.Free;
|
||||
Modified(Sender);
|
||||
end;
|
||||
|
||||
procedure TfrmCustomizeHighlighter.FormCreate(Sender: TObject);
|
||||
var
|
||||
Highlighters: TSynHighlighterList;
|
||||
i: Integer;
|
||||
begin
|
||||
// Form created
|
||||
FHighlighter := nil;
|
||||
FAttr := nil;
|
||||
FOnChange := nil;
|
||||
Highlighters := SynEditHighlighter.GetPlaceableHighlighters;
|
||||
for i:=0 to Highlighters.Count-1 do begin
|
||||
comboHighlighter.Items.Add(Highlighters[i].GetFriendlyLanguageName);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmCustomizeHighlighter.FormDestroy(Sender: TObject);
|
||||
begin
|
||||
// Form destroyed
|
||||
if Assigned(FHighlighter) then
|
||||
FHighlighter.Free;
|
||||
if Assigned(FAttr) then
|
||||
FAttr.Free;
|
||||
end;
|
||||
|
||||
procedure TfrmCustomizeHighlighter.listboxAttributesClick(Sender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
AttrSelected: Boolean;
|
||||
begin
|
||||
// Attribute selected
|
||||
FAttr := nil;
|
||||
for i:=0 to FHighlighter.AttrCount-1 do begin
|
||||
if listboxAttributes.Items[listboxAttributes.ItemIndex] = FHighlighter.Attribute[i].FriendlyName then begin
|
||||
FAttr := FHighlighter.Attribute[i];
|
||||
end;
|
||||
end;
|
||||
// Enable/disable controls
|
||||
AttrSelected := FAttr <> nil;
|
||||
editBackground.Enabled := AttrSelected;
|
||||
editForeground.Enabled := AttrSelected;
|
||||
chkBold.Enabled := AttrSelected;
|
||||
chkItalic.Enabled := AttrSelected;
|
||||
pnlSample.Enabled := AttrSelected;
|
||||
// Overtake values
|
||||
editBackground.Text := IfThen(AttrSelected, ColorToWebColorStr(FAttr.Background), '');
|
||||
editForeground.Text := IfThen(AttrSelected, ColorToWebColorStr(FAttr.Foreground), '');
|
||||
chkBold.Checked := AttrSelected and (fsBold in FAttr.Style);
|
||||
chkItalic.Checked := AttrSelected and (fsItalic in FAttr.Style);
|
||||
UpdateSampleBox;
|
||||
end;
|
||||
|
||||
procedure TfrmCustomizeHighlighter.SetFriendlyLanguageName(FriendlyLanguageName: String);
|
||||
begin
|
||||
// Set current highlighter by its language name
|
||||
comboHighlighter.ItemIndex := comboHighlighter.Items.IndexOf(FriendlyLanguageName);
|
||||
comboHighlighter.OnSelect(comboHighlighter);
|
||||
end;
|
||||
|
||||
function TfrmCustomizeHighlighter.GetFriendlyLanguageName: String;
|
||||
begin
|
||||
Result := FHighlighter.FriendlyLanguageName;
|
||||
end;
|
||||
|
||||
procedure TfrmCustomizeHighlighter.UpdateSampleBox;
|
||||
var
|
||||
AttrSelected: Boolean;
|
||||
begin
|
||||
// Visualize current colors
|
||||
AttrSelected := FAttr <> nil;
|
||||
pnlSample.Color := TColor(IfThen(AttrSelected, FAttr.Background, clBtnFace));
|
||||
pnlSample.Font.Color := TColor(IfThen(AttrSelected, FAttr.Foreground, clWindowText));
|
||||
if AttrSelected then
|
||||
pnlSample.Font.Style := FAttr.Style;
|
||||
|
||||
lblSample.Color := TColor(IfThen(AttrSelected, FAttr.Background, clBtnFace));
|
||||
lblSample.Font.Color := TColor(IfThen(AttrSelected, FAttr.Foreground, clWindowText));
|
||||
if AttrSelected then
|
||||
lblSample.Font.Style := FAttr.Style;
|
||||
end;
|
||||
|
||||
end.
|
@ -129,9 +129,24 @@ object frmTextEditor: TfrmTextEditor
|
||||
Top = 0
|
||||
Action = MainForm.actQueryReplace
|
||||
end
|
||||
object ToolButton1: TToolButton
|
||||
Left = 211
|
||||
Top = 0
|
||||
Width = 8
|
||||
Caption = 'ToolButton1'
|
||||
ImageIndex = 60
|
||||
Style = tbsSeparator
|
||||
end
|
||||
object btnCustomizeHighlighter: TToolButton
|
||||
Left = 219
|
||||
Top = 0
|
||||
Caption = 'Customize highlighter'
|
||||
ImageIndex = 39
|
||||
OnClick = btnCustomizeHighlighterClick
|
||||
end
|
||||
end
|
||||
object comboHighlighter: TComboBox
|
||||
Left = 207
|
||||
Left = 242
|
||||
Top = 0
|
||||
Width = 145
|
||||
Height = 22
|
||||
|
@ -6,7 +6,7 @@ uses
|
||||
Windows, Classes, Graphics, Forms, Controls, StdCtrls, VirtualTrees,
|
||||
ComCtrls, ToolWin, Dialogs, SysUtils, Menus, ExtDlgs,
|
||||
apphelpers, gnugettext, ActnList, StdActns, extra_controls, System.Actions,
|
||||
Vcl.ExtCtrls, dbconnection, SynEdit, SynMemo, SynEditHighlighter,
|
||||
Vcl.ExtCtrls, dbconnection, SynEdit, SynMemo, SynEditHighlighter, customize_highlighter,
|
||||
|
||||
SynHighlighterADSP21xx, SynHighlighterAWK, SynHighlighterAsm,
|
||||
SynHighlighterBaan, SynHighlighterBat, SynHighlighterCAC, SynHighlighterCPM, SynHighlighterCS,
|
||||
@ -59,6 +59,8 @@ type
|
||||
Findorreplaceagain1: TMenuItem;
|
||||
Replacetext1: TMenuItem;
|
||||
N1: TMenuItem;
|
||||
ToolButton1: TToolButton;
|
||||
btnCustomizeHighlighter: TToolButton;
|
||||
procedure btnApplyClick(Sender: TObject);
|
||||
procedure btnCancelClick(Sender: TObject);
|
||||
procedure btnLoadTextClick(Sender: TObject);
|
||||
@ -73,6 +75,7 @@ type
|
||||
procedure SelectLinebreaks(Sender: TObject);
|
||||
procedure TimerMemoChangeTimer(Sender: TObject);
|
||||
procedure comboHighlighterSelect(Sender: TObject);
|
||||
procedure btnCustomizeHighlighterClick(Sender: TObject);
|
||||
private
|
||||
{ Private declarations }
|
||||
FModified: Boolean;
|
||||
@ -83,6 +86,7 @@ type
|
||||
FTableColumn: TTableColumn;
|
||||
FHighlighter: TSynCustomHighlighter;
|
||||
procedure SetModified(NewVal: Boolean);
|
||||
procedure CustomizeHighlighterChanged(Sender: TObject);
|
||||
public
|
||||
function GetText: String;
|
||||
procedure SetText(text: String);
|
||||
@ -160,6 +164,27 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
procedure TfrmTextEditor.btnCustomizeHighlighterClick(Sender: TObject);
|
||||
var
|
||||
Dialog: TfrmCustomizeHighlighter;
|
||||
begin
|
||||
// let user customize highlighter colors
|
||||
Dialog := TfrmCustomizeHighlighter.Create(Self);
|
||||
Dialog.FriendlyLanguageName := MemoText.Highlighter.FriendlyLanguageName;
|
||||
Dialog.OnChange := CustomizeHighlighterChanged;
|
||||
Dialog.ShowModal;
|
||||
Dialog.Free;
|
||||
end;
|
||||
|
||||
procedure TfrmTextEditor.CustomizeHighlighterChanged(Sender: TObject);
|
||||
var
|
||||
Dialog: TfrmCustomizeHighlighter;
|
||||
begin
|
||||
Dialog := Sender as TfrmCustomizeHighlighter;
|
||||
comboHighlighter.ItemIndex := comboHighlighter.Items.IndexOf(Dialog.FriendlyLanguageName);
|
||||
comboHighlighter.OnSelect(comboHighlighter);
|
||||
end;
|
||||
|
||||
procedure TfrmTextEditor.SelectLinebreaks(Sender: TObject);
|
||||
var
|
||||
Selected, Item: TMenuItem;
|
||||
@ -340,6 +365,8 @@ begin
|
||||
MemoText.Highlighter := FHighlighter;
|
||||
end;
|
||||
|
||||
MemoText.Highlighter.LoadFromFile(AppSettings.DirnameHighlighters + MemoText.Highlighter.LanguageName + '.ini');
|
||||
|
||||
MemoText.SelStart := SelStart;
|
||||
MemoText.SelLength := SelLength;
|
||||
end;
|
||||
|
Reference in New Issue
Block a user