Skip to content

Commit

Permalink
Support changing hotkeys for completion & param hint.
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Sep 6, 2023
1 parent 0db1b70 commit c6f95fc
Show file tree
Hide file tree
Showing 15 changed files with 605 additions and 294 deletions.
22 changes: 16 additions & 6 deletions Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,24 @@
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages Count="4">
<RequiredPackages Count="5">
<Item1>
<PackageName Value="SynEdit"/>
<PackageName Value="LazControlDsgn"/>
</Item1>
<Item2>
<PackageName Value="AnchorDocking"/>
<PackageName Value="SynEdit"/>
</Item2>
<Item3>
<PackageName Value="LazControls"/>
<PackageName Value="AnchorDocking"/>
</Item3>
<Item4>
<PackageName Value="LCL"/>
<PackageName Value="LazControls"/>
</Item4>
<Item5>
<PackageName Value="LCL"/>
</Item5>
</RequiredPackages>
<Units Count="138">
<Units Count="139">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -969,6 +972,13 @@
<Filename Value="simba.rgbsumtable.pas"/>
<IsPartOfProject Value="True"/>
</Unit137>
<Unit138>
<Filename Value="forms/simba.settingsform_codetools.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="SimbaCodetoolsFrame"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Frame"/>
</Unit138>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
27 changes: 22 additions & 5 deletions Source/editor/simba.editor_autocomplete.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface
uses
Classes, SysUtils, Graphics, StdCtrls, Controls, Forms, LCLType, Types,
SynEdit, SynEditTypes, SynCompletion, SynEditKeyCmds, SynEditHighlighter,
simba.mufasatypes, simba.ide_codetools_parser, simba.ide_codetools_insight,
simba.mufasatypes, simba.settings, simba.ide_codetools_parser, simba.ide_codetools_insight,
simba.component_scrollbar;

type
Expand Down Expand Up @@ -69,6 +69,8 @@ TSimbaAutoComplete = class(TSynCompletion)
FColumnWidth: Integer;
FDrawOffsetY: Integer;

procedure DoSettingChanged_CompletionKey(Setting: TSimbaSetting);

function GetHintText(Decl: TDeclaration; IsHint: Boolean): String;

function GetDecl(Index: Integer): TDeclaration;
Expand Down Expand Up @@ -105,7 +107,7 @@ TSimbaAutoComplete = class(TSynCompletion)
implementation

uses
simba.settings, simba.algo_sort, simba.editor, simba.ide_codetools_setup, simba.theme;
simba.algo_sort, simba.editor, simba.ide_codetools_setup, simba.theme;

{$IFDEF WINDOWS}
function SetClassLong(Handle: HWND; Index: Integer = -26; Value: Integer = 0): UInt32; stdcall; external 'user32' name 'SetClassLongA';
Expand Down Expand Up @@ -460,6 +462,18 @@ procedure TSimbaAutoComplete.DoExecute(Sender: TObject);
end;
end;

procedure TSimbaAutoComplete.DoSettingChanged_CompletionKey(Setting: TSimbaSetting);
var
Index: Integer;
begin
Index := Editor.Keystrokes.FindCommand(AutoCompleteCommand);
if (Index > -1) then
begin
Editor.Keystrokes[Index].Key := SimbaSettings.CodeTools.CompletionKey.Value;
Editor.Keystrokes[Index].Shift := TShiftState(Integer(SimbaSettings.CodeTools.CompletionKeyModifiers.Value));
end;
end;

function TSimbaAutoComplete.GetHintText(Decl: TDeclaration; IsHint: Boolean): String;

function GetMethodText(Decl: TDeclaration_Method): String;
Expand Down Expand Up @@ -581,8 +595,8 @@ procedure TSimbaAutoComplete.DoEditorAdded(Value: TCustomSynEdit);

with KeyStrokes.Add() do
begin
Key := VK_SPACE;
Shift := [ssCtrl];
Key := SimbaSettings.CodeTools.CompletionKey.Value;
Shift := TShiftState(Int32(SimbaSettings.CodeTools.CompletionKeyModifiers.Value));
Command := AutoCompleteCommand;
end;
end;
Expand Down Expand Up @@ -797,6 +811,9 @@ constructor TSimbaAutoComplete.Create(AOwner: TComponent);
OnExecute := @DoExecute;

LongLineHintType := sclpExtendRightOnly;

SimbaSettings.RegisterChangeHandler(Self, SimbaSettings.CodeTools.CompletionKey, @DoSettingChanged_CompletionKey);
SimbaSettings.RegisterChangeHandler(Self, SimbaSettings.CodeTools.CompletionKeyModifiers, @DoSettingChanged_CompletionKey);
end;

destructor TSimbaAutoComplete.Destroy;
Expand All @@ -809,7 +826,7 @@ destructor TSimbaAutoComplete.Destroy;

class function TSimbaAutoComplete.IsAutoCompleteCommand(Command: TSynEditorCommand; AChar: TUTF8Char): Boolean;
begin
Result := ((Command = ecChar) and (AChar = '.')) or (Command = AutoCompleteCommand);
Result := (SimbaSettings.CodeTools.CompletionOpenAutomatically.Value and (Command = ecChar) and (AChar = '.')) or (Command = AutoCompleteCommand);
end;

class constructor TSimbaAutoComplete.Create;
Expand Down
26 changes: 22 additions & 4 deletions Source/editor/simba.editor_paramhint.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface
uses
Classes, SysUtils, Forms, Controls, Graphics, LCLType,
SynEdit, SynEditTypes, SynEditKeyCmds,
simba.mufasatypes, simba.settings,
simba.ide_codetools_insight, simba.ide_codetools_parser;

type
Expand Down Expand Up @@ -45,6 +46,8 @@ TSimbaParamHint = class(TLazSynEditPlugin)
function IsShowing: Boolean;
function GetParameterIndexAtCaret: Integer;

procedure DoSettingChanged_ParamHintKey(Setting: TSimbaSetting);

procedure DoEditorTopLineChanged(Sender: TObject; Changes: TSynStatusChanges);
procedure DoEditorCaretMove(Sender: TObject);
procedure DoEditorCommand(Sender: TObject; AfterProcessing: Boolean; var Handled: Boolean; var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: Pointer; HandlerData: Pointer);
Expand All @@ -66,7 +69,7 @@ implementation

uses
mPasLexTypes, mPasLex,
simba.editor, simba.mufasatypes, simba.ide_codetools_setup, simba.theme;
simba.editor, simba.ide_codetools_setup, simba.theme;

procedure TSimbaParamHintForm.SetBoldIndex(AValue: Integer);
begin
Expand Down Expand Up @@ -321,6 +324,18 @@ function TSimbaParamHint.GetParameterIndexAtCaret: Integer;
end;
end;

procedure TSimbaParamHint.DoSettingChanged_ParamHintKey(Setting: TSimbaSetting);
var
Index: Integer;
begin
Index := Editor.Keystrokes.FindCommand(ParamHintCommand);
if (Index > -1) then
begin
Editor.Keystrokes[Index].Key := SimbaSettings.CodeTools.ParamHintKey.Value;
Editor.Keystrokes[Index].Shift := TShiftState(Integer(SimbaSettings.CodeTools.ParamHintKeyModifiers.Value));
end;
end;

procedure TSimbaParamHint.DoEditorTopLineChanged(Sender: TObject; Changes: TSynStatusChanges);
begin
if IsShowing then
Expand Down Expand Up @@ -434,8 +449,8 @@ procedure TSimbaParamHint.DoEditorAdded(Value: TCustomSynEdit);

with KeyStrokes.Add() do
begin
Key := VK_SPACE;
Shift := [ssCtrl, ssShift];
Key := SimbaSettings.CodeTools.ParamHintKey.Value;
Shift := TShiftState(Int32(SimbaSettings.CodeTools.ParamHintKeyModifiers.Value));
Command := ParamHintCommand;
end;
end;
Expand Down Expand Up @@ -465,7 +480,7 @@ destructor TSimbaParamHint.Destroy;

class function TSimbaParamHint.IsParamHintCommand(Command: TSynEditorCommand; AChar: TUTF8Char): Boolean;
begin
Result := ((Command = ecChar) and (AChar = '(')) or (Command = ParamHintCommand);
Result := (SimbaSettings.CodeTools.ParamHintOpenAutomatically.Value and (Command = ecChar) and (AChar = '(')) or (Command = ParamHintCommand);
end;

class constructor TSimbaParamHint.Create;
Expand All @@ -479,6 +494,9 @@ constructor TSimbaParamHint.Create(AOwner: TComponent);

FCodeinsight := TCodeinsight.Create();
FHintForm := TSimbaParamHintForm.Create(Self);

SimbaSettings.RegisterChangeHandler(Self, SimbaSettings.CodeTools.ParamHintKey, @DoSettingChanged_ParamHintKey);
SimbaSettings.RegisterChangeHandler(Self, SimbaSettings.CodeTools.ParamHintKeyModifiers, @DoSettingChanged_ParamHintKey);
end;

end.
Expand Down
18 changes: 10 additions & 8 deletions Source/forms/simba.settingsform.lfm
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
object SimbaSettingsForm: TSimbaSettingsForm
Left = 3652
Left = 3352
Height = 625
Top = 427
Top = 69
Width = 750
Caption = 'Settings'
ClientHeight = 625
ClientWidth = 750
DesignTimePPI = 120
OnShow = FormShow
Position = poMainFormCenter
LCLVersion = '2.2.4.0'
LCLVersion = '3.0.0.1'
object TreeView: TTreeView
Left = 0
Height = 571
Expand All @@ -21,18 +21,20 @@ object SimbaSettingsForm: TSimbaSettingsForm
ReadOnly = True
ScrollBars = ssAutoBoth
ShowRoot = False
ShowSeparators = False
TabOrder = 0
OnSelectionChanged = TreeViewSelectionChanged
Options = [tvoAutoExpand, tvoAutoItemHeight, tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoToolTips, tvoThemedDraw]
end
object Notebook: TNotebook
Left = 211
Height = 571
Top = 0
Left = 212
Height = 561
Top = 10
Width = 533
Align = alClient
BorderSpacing.Left = 4
BorderSpacing.Right = 6
BorderSpacing.Left = 5
BorderSpacing.Top = 10
BorderSpacing.Right = 5
TabOrder = 1
end
object ButtonPanel: TButtonPanel
Expand Down
27 changes: 10 additions & 17 deletions Source/forms/simba.settingsform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, ExtCtrls, ButtonPanel, Spin,
simba.settingsform_editor_font, simba.settingsform_editor_colors, simba.settingsform_editor_general,
simba.settingsform_simba_general, simba.settingsform_outputbox, simba.settingsform_backup;
simba.settingsform_simba_general, simba.settingsform_outputbox, simba.settingsform_backup,
simba.settingsform_codetools;

type
TSimbaSettingsForm = class(TForm)
Expand All @@ -26,6 +27,7 @@ TSimbaSettingsForm = class(TForm)
procedure TreeViewSelectionChanged(Sender: TObject);
public
SimbaGeneralFrame: TSimbaGeneralFrame;
SimbaCodetoolsFrame: TSimbaCodetoolsFrame;
SimbaOutputBoxFrame: TSimbaOutputBoxFrame;
SimbaBackupFrame: TSimbaBackupFrame;

Expand Down Expand Up @@ -75,9 +77,6 @@ procedure TSimbaSettingsForm.FormShow(Sender: TObject);
EditorGeneralFrame.RightMarginEdit.Value := SimbaSettings.Editor.RightMargin.Value;
EditorGeneralFrame.VisibleRightMarginCheckbox.Checked := SimbaSettings.Editor.RightMarginVisible.Value;
EditorGeneralFrame.CaretPastEOLCheckBox.Checked := SimbaSettings.Editor.AllowCaretPastEOL.Value;
EditorGeneralFrame.OpenAutoCompletionCheckbox.Checked := SimbaSettings.Editor.AutomaticallyOpenAutoCompletion.Value;
EditorGeneralFrame.ShowParameterHintsCheckbox.Checked := SimbaSettings.Editor.AutomaticallyShowParameterHints.Value;
EditorGeneralFrame.IgnoreCodeToolsDirectiveCheckbox.Checked := SimbaSettings.Editor.IgnoreCodeToolsIDEDirective.Value;

EditorGeneralFrame.CompleteBeginCheckbox.Checked := SimbaSettings.Editor.AutomaticallyCompleteBegin.Value;
EditorGeneralFrame.CompleteParenthesesCheckbox.Checked := SimbaSettings.Editor.AutomaticallyCompleteParentheses.Value;
Expand All @@ -89,6 +88,7 @@ procedure TSimbaSettingsForm.FormShow(Sender: TObject);
SimbaGeneralFrame.FontSizeTrackBar.OnChange(nil);

SimbaGeneralFrame.Load();
SimbaCodetoolsFrame.Load();
EditorGeneralFrame.Load();
EditorColorsFrame.Load();
SimbaOutputBoxFrame.Load();
Expand All @@ -104,25 +104,13 @@ procedure TSimbaSettingsForm.OKButtonClick(Sender: TObject);
SimbaSettings.Editor.AllowCaretPastEOL.Value := EditorGeneralFrame.CaretPastEOLCheckBox.Checked;
SimbaSettings.Editor.RightMargin.Value := EditorGeneralFrame.RightMarginEdit.Value;
SimbaSettings.Editor.RightMarginVisible.Value := EditorGeneralFrame.VisibleRightMarginCheckbox.Checked;
SimbaSettings.Editor.AutomaticallyOpenAutoCompletion.Value := EditorGeneralFrame.OpenAutoCompletionCheckbox.Checked;
SimbaSettings.Editor.AutomaticallyShowParameterHints.Value := EditorGeneralFrame.ShowParameterHintsCheckbox.Checked;
SimbaSettings.Editor.IgnoreCodeToolsIDEDirective.Value := EditorGeneralFrame.IgnoreCodeToolsDirectiveCheckbox.Checked;

SimbaSettings.Editor.AutomaticallyCompleteBegin.Value := EditorGeneralFrame.CompleteBeginCheckbox.Checked;
SimbaSettings.Editor.AutomaticallyCompleteIndex.Value := EditorGeneralFrame.CompleteIndexCheckbox.Checked;
SimbaSettings.Editor.AutomaticallyCompleteParentheses.Value := EditorGeneralFrame.CompleteParenthesesCheckbox.Checked;

//if (SimbaGeneralFrame.ToolbarSizeTrackBar.Position = SimbaGeneralFrame.ToolbarSizeTrackBar.Min) then
// SimbaSettings.General.ToolbarSize.Value := SimbaSettings.General.ToolbarSize.DefaultValue
//else
// SimbaSettings.General.ToolbarSize.Value := SimbaGeneralFrame.ToolbarSizeTrackBar.Position;
//
//if (SimbaGeneralFrame.FontSizeTrackBar.Position = SimbaGeneralFrame.FontSizeTrackBar.Min) then
// SimbaSettings.General.CustomFontSize.Value := SimbaSettings.General.CustomFontSize.DefaultValue
//else
// SimbaSettings.General.CustomFontSize.Value := SimbaGeneralFrame.FontSizeTrackBar.Position;

SimbaGeneralFrame.Save();
SimbaCodetoolsFrame.Save();
EditorGeneralFrame.Save();
EditorColorsFrame.Save();
SimbaOutputBoxFrame.Save();
Expand Down Expand Up @@ -163,6 +151,11 @@ constructor TSimbaSettingsForm.Create(AOwner: TComponent);
SimbaGeneralFrame.Align := alClient;
SimbaGeneralFrame.ParentFont := True;

SimbaCodetoolsFrame := TSimbaCodetoolsFrame.Create(Self);
SimbaCodetoolsFrame.Parent := AddPage('Code Tools', Node);
SimbaCodetoolsFrame.Align := alClient;
SimbaCodetoolsFrame.ParentFont := True;

SimbaOutputBoxFrame := TSimbaOutputBoxFrame.Create(Self);
SimbaOutputBoxFrame.Parent := AddPage('Output Box', Node);
SimbaOutputBoxFrame.Align := alClient;
Expand Down
20 changes: 10 additions & 10 deletions Source/forms/simba.settingsform_backup.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ object SimbaBackupFrame: TSimbaBackupFrame
ClientHeight = 305
ClientWidth = 668
DesignTimePPI = 120
ParentFont = False
TabOrder = 0
DesignLeft = 4331
DesignTop = 1010
Expand All @@ -16,7 +17,7 @@ object SimbaBackupFrame: TSimbaBackupFrame
AnchorSideTop.Side = asrBottom
Left = 106
Height = 28
Top = 86
Top = 81
Width = 144
BorderSpacing.Left = 5
BorderSpacing.Top = 10
Expand All @@ -29,7 +30,7 @@ object SimbaBackupFrame: TSimbaBackupFrame
AnchorSideBottom.Side = asrBottom
Left = 0
Height = 28
Top = 86
Top = 81
Width = 101
Anchors = [akTop, akLeft, akBottom]
Caption = 'Backup Interval'
Expand All @@ -41,9 +42,8 @@ object SimbaBackupFrame: TSimbaBackupFrame
AnchorSideTop.Control = Owner
Left = 0
Height = 20
Top = 5
Top = 0
Width = 195
BorderSpacing.Top = 5
Caption = 'Script backups are located at:'
Layout = tlCenter
ParentColor = False
Expand All @@ -55,7 +55,7 @@ object SimbaBackupFrame: TSimbaBackupFrame
AnchorSideBottom.Side = asrBottom
Left = 0
Height = 1
Top = 30
Top = 25
Width = 1
BorderSpacing.Top = 5
Layout = tlCenter
Expand All @@ -69,7 +69,7 @@ object SimbaBackupFrame: TSimbaBackupFrame
AnchorSideBottom.Side = asrBottom
Left = 255
Height = 28
Top = 86
Top = 81
Width = 52
Anchors = [akTop, akLeft, akBottom]
BorderSpacing.Left = 5
Expand All @@ -84,7 +84,7 @@ object SimbaBackupFrame: TSimbaBackupFrame
AnchorSideBottom.Side = asrBottom
Left = 0
Height = 20
Top = 56
Top = 51
Width = 192
Caption = 'Automatically Backup Scripts'
Layout = tlCenter
Expand All @@ -98,8 +98,8 @@ object SimbaBackupFrame: TSimbaBackupFrame
AnchorSideBottom.Side = asrBottom
Left = 202
Height = 20
Top = 56
Width = 24
Top = 51
Width = 21
Anchors = [akTop, akLeft, akBottom]
BorderSpacing.Left = 10
TabOrder = 1
Expand All @@ -112,7 +112,7 @@ object SimbaBackupFrame: TSimbaBackupFrame
AnchorSideRight.Side = asrBottom
Left = 0
Height = 20
Top = 36
Top = 31
Width = 668
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 5
Expand Down
Loading

0 comments on commit c6f95fc

Please sign in to comment.