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

View File

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

View File

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