IDE: Code Templates dialog improvements. Based on patch by n7800, issue #40654.

This commit is contained in:
Maxim Ganetsky 2024-01-08 02:40:55 +03:00
parent 889c2339f6
commit 3515118a09
3 changed files with 86 additions and 87 deletions

View File

@ -14,7 +14,6 @@ object CodeTemplateDialog: TCodeTemplateDialog
OnKeyDown = FormKeyDown OnKeyDown = FormKeyDown
OnShow = FormShow OnShow = FormShow
Position = poScreenCenter Position = poScreenCenter
LCLVersion = '2.1.0.0'
object FilenameGroupBox: TGroupBox object FilenameGroupBox: TGroupBox
Left = 6 Left = 6
Height = 46 Height = 46
@ -63,74 +62,64 @@ object CodeTemplateDialog: TCodeTemplateDialog
ClientWidth = 713 ClientWidth = 713
TabOrder = 1 TabOrder = 1
object TemplateListBox: TListBox object TemplateListBox: TListBox
AnchorSideLeft.Control = TemplatesGroupBox
AnchorSideTop.Control = TemplatesGroupBox
AnchorSideRight.Control = AddButton
AnchorSideBottom.Control = TemplatesGroupBox
AnchorSideBottom.Side = asrBottom
Left = 6 Left = 6
Height = 136 Height = 137
Top = 6 Top = 6
Width = 555 Width = 598
Anchors = [akTop, akLeft, akRight, akBottom] Align = alClient
BorderSpacing.Left = 6 BorderSpacing.Left = 6
BorderSpacing.Top = 6 BorderSpacing.Top = 6
BorderSpacing.Right = 6
BorderSpacing.Bottom = 6 BorderSpacing.Bottom = 6
ItemHeight = 0 ItemHeight = 0
OnSelectionChange = TemplateListBoxSelectionChange
ScrollWidth = 553
TabOrder = 3
end
object AddButton: TButton
AnchorSideTop.Control = TemplateListBox
AnchorSideRight.Control = TemplatesGroupBox
AnchorSideRight.Side = asrBottom
Left = 567
Height = 29
Top = 6
Width = 140
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Right = 6
Caption = 'AddButton'
Constraints.MinWidth = 140
OnClick = AddButtonClick
TabOrder = 0
end
object DeleteButton: TButton
AnchorSideLeft.Control = AddButton
AnchorSideTop.Control = AddButton
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AddButton
AnchorSideRight.Side = asrBottom
Left = 567
Height = 29
Top = 41
Width = 140
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Top = 6
Caption = 'DeleteButton'
OnClick = DeleteButtonClick
TabOrder = 1 TabOrder = 1
OnSelectionChange = TemplateListBoxSelectionChange
end end
object RenameButton: TButton object ControlPanel: TPanel
AnchorSideLeft.Control = AddButton Left = 604
AnchorSideTop.Control = DeleteButton Height = 149
AnchorSideTop.Side = asrBottom Top = 0
AnchorSideRight.Control = DeleteButton Width = 109
AnchorSideRight.Side = asrBottom Align = alRight
Left = 567
Height = 29
Top = 76
Width = 140
Anchors = [akTop, akLeft, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Top = 6 BevelOuter = bvNone
Caption = 'RenameButton' ChildSizing.LeftRightSpacing = 6
OnClick = RenameButtonClick ChildSizing.TopBottomSpacing = 6
TabOrder = 2 ChildSizing.VerticalSpacing = 6
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 149
ClientWidth = 109
TabOrder = 0
object AddButton: TButton
Left = 6
Height = 23
Top = 6
Width = 97
AutoSize = True
Caption = 'AddButton'
TabOrder = 0
OnClick = AddButtonClick
end
object DeleteButton: TButton
Left = 6
Height = 23
Top = 35
Width = 97
AutoSize = True
Caption = 'DeleteButton'
TabOrder = 1
OnClick = DeleteButtonClick
end
object RenameButton: TButton
Left = 6
Height = 23
Top = 64
Width = 97
AutoSize = True
Caption = 'RenameButton'
TabOrder = 2
OnClick = RenameButtonClick
end
end end
end end
object EditTemplateGroupBox: TGroupBox object EditTemplateGroupBox: TGroupBox
@ -694,7 +683,7 @@ object CodeTemplateDialog: TCodeTemplateDialog
AutoSize = True AutoSize = True
BorderSpacing.Left = 10 BorderSpacing.Left = 10
BorderSpacing.Top = 2 BorderSpacing.Top = 2
BorderSpacing.Right = 2 BorderSpacing.Right = 6
Caption = 'AutoOnOptionsCheckGroup' Caption = 'AutoOnOptionsCheckGroup'
ChildSizing.LeftRightSpacing = 6 ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6 ChildSizing.TopBottomSpacing = 6
@ -702,8 +691,8 @@ object CodeTemplateDialog: TCodeTemplateDialog
ChildSizing.EnlargeVertical = crsHomogenousChildResize ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.Layout = cclTopToBottomThenLeftToRight
ChildSizing.ControlsPerLine = 2 ChildSizing.ControlsPerLine = 1
Columns = 2 Columns = 2
Constraints.MinHeight = 70 Constraints.MinHeight = 70
TabOrder = 2 TabOrder = 2

View File

@ -80,6 +80,7 @@ type
InsertMacroButton: TButton; InsertMacroButton: TButton;
KeepSubIndentCheckBox: TCheckBox; KeepSubIndentCheckBox: TCheckBox;
OptionsPanel: TPanel; OptionsPanel: TPanel;
ControlPanel: TPanel;
Splitter1: TSplitter; Splitter1: TSplitter;
UseMacrosCheckBox: TCheckBox; UseMacrosCheckBox: TCheckBox;
RenameButton: TButton; RenameButton: TButton;
@ -849,9 +850,6 @@ var
begin begin
IDEDialogLayoutList.ApplyLayout(Self,600,550); IDEDialogLayoutList.ApplyLayout(Self,600,550);
SynAutoComplete:=TSynEditAutoComplete.Create(Self);
LastTemplate:=-1;
// init captions // init captions
Caption:=dlgEdCodeTempl; Caption:=dlgEdCodeTempl;
AddButton.Caption:=lisAdd; AddButton.Caption:=lisAdd;
@ -869,6 +867,8 @@ begin
KeepSubIndentCheckBox.Caption:=lisKeepSubIndentation; KeepSubIndentCheckBox.Caption:=lisKeepSubIndentation;
KeepSubIndentCheckBox.Hint:=lisKeepRelativeIndentationOfMultiLineTemplate; KeepSubIndentCheckBox.Hint:=lisKeepRelativeIndentationOfMultiLineTemplate;
AutoOnOptionsCheckGroup.Caption:=lisCodeTemplAutoCompleteOn; AutoOnOptionsCheckGroup.Caption:=lisCodeTemplAutoCompleteOn;
// the order matches the TAutoCompleteOption enumeration!
AutoOnOptionsCheckGroup.Items.Add(lisAutomaticallyOnLineBreak); AutoOnOptionsCheckGroup.Items.Add(lisAutomaticallyOnLineBreak);
AutoOnOptionsCheckGroup.Items.Add(lisAutomaticallyOnSpace); AutoOnOptionsCheckGroup.Items.Add(lisAutomaticallyOnSpace);
AutoOnOptionsCheckGroup.Items.Add(lisAutomaticallyOnTab); AutoOnOptionsCheckGroup.Items.Add(lisAutomaticallyOnTab);
@ -893,21 +893,22 @@ begin
EditorOpts.AssignKeyMapTo(TemplateSynEdit); EditorOpts.AssignKeyMapTo(TemplateSynEdit);
TemplateSynEdit.Gutter.Visible:=false; TemplateSynEdit.Gutter.Visible:=false;
TemplateSynEdit.WantTabs := false; TemplateSynEdit.WantTabs := false;
TemplateSynEdit.ScrollBars := ssAutoBoth;
TemplateSynEdit.Options := TemplateSynEdit.Options - [eoScrollPastEof];
TemplateSynEdit.Options := TemplateSynEdit.Options - [eoScrollPastEol]; TemplateSynEdit.Options := TemplateSynEdit.Options - [eoScrollPastEol];
TemplateSynEdit.Options2 := TemplateSynEdit.Options2 - [eoScrollPastEolAddPage]; TemplateSynEdit.Options2 := TemplateSynEdit.Options2 - [eoScrollPastEolAddPage];
TemplateSynEdit.Options2 := TemplateSynEdit.Options2 - [eoScrollPastEolAutoCaret]; TemplateSynEdit.Options2 := TemplateSynEdit.Options2 - [eoScrollPastEolAutoCaret];
// init SynAutoComplete // init SynAutoComplete
SynAutoComplete:=TSynEditAutoComplete.Create(Self);
EditorOpts.LoadCodeTemplates(SynAutoComplete); EditorOpts.LoadCodeTemplates(SynAutoComplete);
// init listbox // init listbox
LastTemplate:=-1;
FillCodeTemplateListBox; FillCodeTemplateListBox;
with TemplateListBox do if TemplateListBox.Items.Count>0 then
if Items.Count>0 then begin TemplateListBox.ItemIndex:=0; // this call ShowCurCodeTemplate
ItemIndex:=0;
ShowCurCodeTemplate;
end;
BuildPopupMenu; BuildPopupMenu;
end; end;
@ -989,6 +990,9 @@ begin
TemplateListBox.ItemIndex:=Index; TemplateListBox.ItemIndex:=Index;
ShowCurCodeTemplate; ShowCurCodeTemplate;
UseMacrosCheckBox.Checked:=true;
if TemplateSynEdit.CanSetFocus then if TemplateSynEdit.CanSetFocus then
TemplateSynEdit.SetFocus; TemplateSynEdit.SetFocus;
end; end;
@ -1143,6 +1147,7 @@ end;
procedure TCodeTemplateDialog.UseMacrosCheckBoxChange(Sender: TObject); procedure TCodeTemplateDialog.UseMacrosCheckBoxChange(Sender: TObject);
begin begin
InsertMacroButton.Enabled:=UseMacrosCheckBox.Checked; InsertMacroButton.Enabled:=UseMacrosCheckBox.Checked;
CodeTemplateInsertMacroIDEMenuCommand.Enabled:=UseMacrosCheckBox.Checked;
end; end;
procedure TCodeTemplateDialog.BuildPopupMenu; procedure TCodeTemplateDialog.BuildPopupMenu;
@ -1158,7 +1163,7 @@ begin
CodeTemplatesMenuRoot.MenuItem := MainPopupMenu.Items; CodeTemplatesMenuRoot.MenuItem := MainPopupMenu.Items;
//MainPopupMenu.Items.WriteDebugReport('TMessagesView.Create '); //MainPopupMenu.Items.WriteDebugReport('TMessagesView.Create ');
PopupMenu:=MainPopupMenu; TemplateSynEdit.PopupMenu:=MainPopupMenu;
end; end;
procedure TCodeTemplateDialog.DoInsertMacro; procedure TCodeTemplateDialog.DoInsertMacro;
@ -1196,19 +1201,23 @@ procedure TCodeTemplateDialog.ShowCurCodeTemplate;
var var
EnableMacros, KeepSubIndent: boolean; EnableMacros, KeepSubIndent: boolean;
LineCount: integer; LineCount: integer;
Attributes: TStrings;
idx, a, sp, ep: integer;
s: string;
AutoOnCat: array[TAutoCompleteOption] of Boolean;
c: TAutoCompleteOption;
//
procedure AddLine(const s: string); procedure AddLine(const s: string);
begin begin
TemplateSynEdit.Lines.Add(s); TemplateSynEdit.Lines.Add(s);
inc(LineCount); inc(LineCount);
end; end;
//
var function GetBooleanAttribute(const AttrName: string): boolean; inline;
idx, a, sp, ep: integer; begin
s: string; result:=StrToBoolDef(Attributes.Values[AttrName], false);
AutoOnCat: array[TAutoCompleteOption] of Boolean; end;
Attributes: TStrings; //
c: TAutoCompleteOption;
begin begin
EnableMacros:=false; EnableMacros:=false;
KeepSubIndent:=false; KeepSubIndent:=false;
@ -1231,10 +1240,10 @@ begin
EditTemplateGroupBox.Caption:=dbgstr(SynAutoComplete.Completions[a]) EditTemplateGroupBox.Caption:=dbgstr(SynAutoComplete.Completions[a])
+' - '+dbgstr(SynAutoComplete.CompletionComments[a]); +' - '+dbgstr(SynAutoComplete.CompletionComments[a]);
Attributes:=SynAutoComplete.CompletionAttributes[a]; Attributes:=SynAutoComplete.CompletionAttributes[a];
EnableMacros:=Attributes.IndexOfName(CodeTemplateEnableMacros)>=0; EnableMacros:=GetBooleanAttribute(CodeTemplateEnableMacros);
KeepSubIndent:=Attributes.IndexOfName(CodeTemplateKeepSubIndent)>=0; KeepSubIndent:=GetBooleanAttribute(CodeTemplateKeepSubIndent);
for c:=Low(TAutoCompleteOption) to High(TAutoCompleteOption) do for c:=Low(TAutoCompleteOption) to High(TAutoCompleteOption) do
AutoOnCat[c]:=Attributes.IndexOfName(AutoCompleteOptionNames[c])>=0; AutoOnCat[c]:=GetBooleanAttribute(AutoCompleteOptionNames[c]);
LastTemplate := -1; LastTemplate := -1;
s:=SynAutoComplete.CompletionValues[a]; s:=SynAutoComplete.CompletionValues[a];
//debugln('TCodeTemplateDialog.ShowCurCodeTemplate s="',s,'"'); //debugln('TCodeTemplateDialog.ShowCurCodeTemplate s="',s,'"');
@ -1259,6 +1268,7 @@ begin
TemplateSynEdit.Invalidate; TemplateSynEdit.Invalidate;
UseMacrosCheckBox.Checked:=EnableMacros; UseMacrosCheckBox.Checked:=EnableMacros;
InsertMacroButton.Enabled:=EnableMacros; InsertMacroButton.Enabled:=EnableMacros;
CodeTemplateInsertMacroIDEMenuCommand.Enabled:=EnableMacros;
KeepSubIndentCheckBox.Checked:=KeepSubIndent; KeepSubIndentCheckBox.Checked:=KeepSubIndent;
for c:=Low(TAutoCompleteOption) to High(TAutoCompleteOption) do for c:=Low(TAutoCompleteOption) to High(TAutoCompleteOption) do
AutoOnOptionsCheckGroup.Checked[ord(c)]:=AutoOnCat[c]; AutoOnOptionsCheckGroup.Checked[ord(c)]:=AutoOnCat[c];

View File

@ -5385,7 +5385,7 @@ resourcestring
lisAutomaticallyOnWordEnd = 'word end'; lisAutomaticallyOnWordEnd = 'word end';
lisAutomaticallyIgnoreForSelection = 'do not complete selection'; lisAutomaticallyIgnoreForSelection = 'do not complete selection';
lisAutomaticallyRemoveCharacter = 'do not add character'; lisAutomaticallyRemoveCharacter = 'do not add character';
lisKeepSubIndentation = 'Keep indentation'; lisKeepSubIndentation = 'Absolute indentation';
lisPckOptsThisPackageProvidesTheSameAsTheFollowingPackages = 'This package ' lisPckOptsThisPackageProvidesTheSameAsTheFollowingPackages = 'This package '
+'provides the same as the following packages:'; +'provides the same as the following packages:';
lisPLDPackageLinks = 'Package Links'; lisPLDPackageLinks = 'Package Links';
@ -5885,8 +5885,8 @@ resourcestring
//IDE info dialog //IDE info dialog
lisIDEInfoInformationAboutTheIDE = 'Information about the IDE'; lisIDEInfoInformationAboutTheIDE = 'Information about the IDE';
lisKeepRelativeIndentationOfMultiLineTemplate = 'Keep relative indentation ' lisKeepRelativeIndentationOfMultiLineTemplate = 'Keep absolute indentation, regardless '
+'of multi line template'; +'of the current cursor indentation in the text.';
lisTheCurrentFPCHasNoConfigFileItWillProbablyMissSome = 'The current FPC ' lisTheCurrentFPCHasNoConfigFileItWillProbablyMissSome = 'The current FPC '
+'has no config file. It will probably miss some units. Check your ' +'has no config file. It will probably miss some units. Check your '
+'installation of fpc.'; +'installation of fpc.';