IDE: Code Templates dialog improvements by n7800, issue #40654

This commit is contained in:
Maxim Ganetsky 2023-12-21 03:24:26 +03:00
parent b2b86ebaef
commit c4773c0a42
2 changed files with 119 additions and 17 deletions

View File

@ -3,12 +3,15 @@ object CodeTemplateDialog: TCodeTemplateDialog
Height = 540
Top = 174
Width = 729
ActiveControl = TemplateListBox
BorderIcons = [biSystemMenu]
Caption = 'CodeTemplateDialog'
ClientHeight = 540
ClientWidth = 729
KeyPreview = True
OnClose = FormClose
OnCreate = FormCreate
OnKeyDown = FormKeyDown
OnShow = FormShow
Position = poScreenCenter
LCLVersion = '2.1.0.0'
@ -39,7 +42,9 @@ object CodeTemplateDialog: TCodeTemplateDialog
NumGlyphs = 1
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 6
BorderSpacing.Top = 6
BorderSpacing.Right = 6
BorderSpacing.Bottom = 6
MaxLength = 0
TabOrder = 0
Text = 'FilenameEdit'
@ -51,7 +56,8 @@ object CodeTemplateDialog: TCodeTemplateDialog
Top = 58
Width = 717
Align = alTop
BorderSpacing.Around = 6
BorderSpacing.Left = 6
BorderSpacing.Right = 6
Caption = 'TemplatesGroupBox'
ClientHeight = 148
ClientWidth = 713
@ -74,8 +80,7 @@ object CodeTemplateDialog: TCodeTemplateDialog
ItemHeight = 0
OnSelectionChange = TemplateListBoxSelectionChange
ScrollWidth = 553
TabOrder = 0
TopIndex = -1
TabOrder = 3
end
object AddButton: TButton
AnchorSideTop.Control = TemplateListBox
@ -91,7 +96,7 @@ object CodeTemplateDialog: TCodeTemplateDialog
Caption = 'AddButton'
Constraints.MinWidth = 140
OnClick = AddButtonClick
TabOrder = 1
TabOrder = 0
end
object DeleteButton: TButton
AnchorSideLeft.Control = AddButton
@ -108,7 +113,7 @@ object CodeTemplateDialog: TCodeTemplateDialog
BorderSpacing.Top = 6
Caption = 'DeleteButton'
OnClick = DeleteButtonClick
TabOrder = 2
TabOrder = 1
end
object RenameButton: TButton
AnchorSideLeft.Control = AddButton
@ -125,7 +130,7 @@ object CodeTemplateDialog: TCodeTemplateDialog
BorderSpacing.Top = 6
Caption = 'RenameButton'
OnClick = RenameButtonClick
TabOrder = 3
TabOrder = 2
end
end
object EditTemplateGroupBox: TGroupBox
@ -137,7 +142,8 @@ object CodeTemplateDialog: TCodeTemplateDialog
Top = 231
Width = 717
Align = alClient
BorderSpacing.Around = 6
BorderSpacing.Left = 6
BorderSpacing.Right = 6
Caption = 'EditTemplateGroupBox'
ClientHeight = 249
ClientWidth = 713
@ -161,7 +167,7 @@ object CodeTemplateDialog: TCodeTemplateDialog
Font.Quality = fqNonAntialiased
ParentColor = False
ParentFont = False
TabOrder = 2
TabOrder = 0
Gutter.Width = 57
Gutter.MouseActions = <
item
@ -700,7 +706,7 @@ object CodeTemplateDialog: TCodeTemplateDialog
ChildSizing.ControlsPerLine = 2
Columns = 2
Constraints.MinHeight = 70
TabOrder = 1
TabOrder = 2
end
object OptionsPanel: TPanel
AnchorSideLeft.Control = EditTemplateGroupBox
@ -713,7 +719,7 @@ object CodeTemplateDialog: TCodeTemplateDialog
BevelOuter = bvNone
ClientHeight = 95
ClientWidth = 200
TabOrder = 0
TabOrder = 1
object KeepSubIndentCheckBox: TCheckBox
AnchorSideLeft.Control = OptionsPanel
AnchorSideTop.Control = OptionsPanel
@ -737,6 +743,7 @@ object CodeTemplateDialog: TCodeTemplateDialog
Top = 30
Width = 167
BorderSpacing.Left = 6
BorderSpacing.Top = 6
Caption = 'UseMacrosCheckBox'
OnChange = UseMacrosCheckBoxChange
ParentShowHint = False
@ -780,6 +787,15 @@ object CodeTemplateDialog: TCodeTemplateDialog
ShowButtons = [pbOK, pbCancel, pbHelp]
ShowBevel = False
end
object Splitter1: TSplitter
Cursor = crVSplit
Left = 0
Height = 5
Top = 230
Width = 729
Align = alTop
ResizeAnchor = akTop
end
object ASynPasSyn: TSynFreePascalSyn
Enabled = False
CompilerMode = pcmObjFPC

View File

@ -34,11 +34,11 @@ uses
Classes, SysUtils, RegExpr,
// LCL
LCLProc, Forms, Controls, Dialogs, ClipBrd, StdCtrls, ExtCtrls, Menus,
ButtonPanel, EditBtn,
ButtonPanel, EditBtn, LCLType,
// LazUtils
FileUtil, LazFileUtils, LazLoggerBase, LazStringUtils, LazUTF8,
// synedit
SynEdit, SynHighlighterPas, SynEditAutoComplete,
SynEdit, SynHighlighterPas, SynEditAutoComplete, SynEditTypes,
// codetools
CodeToolManager, CodeCache, KeywordFuncLists, BasicCodeTools, PascalParserTool,
// IDEIntf
@ -80,6 +80,7 @@ type
InsertMacroButton: TButton;
KeepSubIndentCheckBox: TCheckBox;
OptionsPanel: TPanel;
Splitter1: TSplitter;
UseMacrosCheckBox: TCheckBox;
RenameButton: TButton;
DeleteButton: TButton;
@ -90,6 +91,7 @@ type
MainPopupMenu: TPopupMenu;
procedure AddButtonClick(Sender: TObject);
procedure DeleteButtonClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure RenameButtonClick(Sender: TObject);
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
@ -824,7 +826,7 @@ procedure TCodeTemplateDialog.FormCreate(Sender: TObject);
var
ColorScheme: String;
begin
IDEDialogLayoutList.ApplyLayout(Self,600,450);
IDEDialogLayoutList.ApplyLayout(Self,600,550);
SynAutoComplete:=TSynEditAutoComplete.Create(Self);
LastTemplate:=-1;
@ -869,6 +871,10 @@ begin
EditorOpts.GetSynEditSettings(TemplateSynEdit);
EditorOpts.AssignKeyMapTo(TemplateSynEdit);
TemplateSynEdit.Gutter.Visible:=false;
TemplateSynEdit.WantTabs := false;
TemplateSynEdit.Options := TemplateSynEdit.Options - [eoScrollPastEol];
TemplateSynEdit.Options2 := TemplateSynEdit.Options2 - [eoScrollPastEolAddPage];
TemplateSynEdit.Options2 := TemplateSynEdit.Options2 - [eoScrollPastEolAutoCaret];
// init SynAutoComplete
EditorOpts.LoadCodeTemplates(SynAutoComplete);
@ -956,12 +962,14 @@ begin
SynAutoComplete.AddCompletion(Token, '', Comment);
FillCodeTemplateListBox;
Index := SynAutoComplete.Completions.IndexOf(Token);
if Index >= 0
then Index := TemplateListBox.Items.IndexOfObject(TObject({%H-}Pointer(Index)));
if Index >= 0
then TemplateListBox.ItemIndex:=Index;
if Index >= 0 then
Index := TemplateListBox.Items.IndexOfObject(TObject({%H-}Pointer(Index)));
if Index >= 0 then
TemplateListBox.ItemIndex:=Index;
ShowCurCodeTemplate;
if TemplateSynEdit.CanSetFocus then
TemplateSynEdit.SetFocus;
end;
end;
@ -991,6 +999,82 @@ begin
TemplateListBox.OnSelectionChange(Self, false); //update btn state
end;
procedure TCodeTemplateDialog.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
// cancel
if (Key = VK_ESCAPE) and (Shift = []) then
begin
Key := 0;
Close;
end
// apply
else if (Key = VK_RETURN) and (Shift = [ssCtrl]) then
begin
Key := 0;
OkButtonClick(Sender);
end
// call help
else if (Key = VK_F1) and (Shift = []) then
begin
HelpButtonClick(Sender);
Key := 0;
end
// open file
else if (Key = VK_O) and (Shift = [ssCtrl]) then
begin
FilenameEdit.RunDialog;
Key := 0;
end
// create a new template
else if (Key = VK_N) and (Shift = [ssCtrl]) then
begin
AddButtonClick(Sender);
Key := 0;
end
// delete current template
else if (Key = VK_DELETE) and (Shift = [ssCtrl]) then
begin
DeleteButtonClick(Sender);
Key := 0;
end
// rename current template
else if (Key = VK_F2) and (Shift = []) then
begin
RenameButtonClick(Sender);
Key := 0;
end
// select next template
else if (Key = VK_DOWN) and (Shift = [ssCtrl, ssShift]) then
begin
with TemplateListBox do
if ItemIndex >= 0 then
begin
if ItemIndex + 1 < Items.Count then
ItemIndex := ItemIndex + 1;
end else begin
if Items.Count > 0 then
ItemIndex := 0;
end;
Key := 0;
end
// select previous template
else if (Key = VK_UP) and (Shift = [ssCtrl, ssShift]) then
begin
with TemplateListBox do
if ItemIndex >= 0 then
begin
if ItemIndex - 1 >= 0 then
ItemIndex := ItemIndex - 1;
end else begin
if Items.Count > 0 then
ItemIndex := Items.Count - 1;
end;
Key := 0;
end;
end;
procedure TCodeTemplateDialog.FormShow(Sender: TObject);
begin
TemplateListBox.OnSelectionChange(Self, true); //update btn states
@ -1005,6 +1089,8 @@ begin
a := PtrInt(TemplateListBox.Items.Objects[idx]);
if a < 0 then exit;
SaveCurCodeTemplate;
if EditCodeTemplate(SynAutoComplete, a)=mrOk then begin
TemplateListBox.Items[idx]:=
SynAutoComplete.Completions[a]