mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-16 11:29:31 +02:00
EditorMacros: Allow assigning custom keys
git-svn-id: trunk@38359 -
This commit is contained in:
parent
dbb987ca5b
commit
e191d86627
@ -257,6 +257,7 @@ type
|
||||
fCurrentEditor: TCustomSynEdit;
|
||||
fState: TSynMacroState;
|
||||
fEvents: TList;
|
||||
procedure SetMacroName(AValue: string); virtual;
|
||||
procedure SetShortCut(const Index: Integer; const Value: TShortCut);
|
||||
function GetIsEmpty: boolean;
|
||||
procedure StateChanged;
|
||||
@ -317,7 +318,7 @@ type
|
||||
property SaveMarkerPos: boolean read fSaveMarkerPos
|
||||
write fSaveMarkerPos default False;
|
||||
property AsString : string read GetAsString write SetAsString;
|
||||
property MacroName : string read fMacroName write fMacroName;
|
||||
property MacroName : string read fMacroName write SetMacroName;
|
||||
property OnStateChange: TNotifyEvent read fOnStateChange write fOnStateChange;
|
||||
property OnUserCommand: TSynUserCommandEvent read fOnUserCommand
|
||||
write fOnUserCommand;
|
||||
@ -894,6 +895,12 @@ begin
|
||||
HookEditor(Editors[cEditor], c, AnOldShortCut, fShortCuts[ACmd], []);
|
||||
end;
|
||||
|
||||
procedure TCustomSynMacroRecorder.SetMacroName(AValue: string);
|
||||
begin
|
||||
if fMacroName = AValue then Exit;
|
||||
fMacroName := AValue;
|
||||
end;
|
||||
|
||||
procedure TCustomSynMacroRecorder.UnHookEditorCmd(ACmd: TSynMacroCommand);
|
||||
var
|
||||
c: TSynEditorCommand;
|
||||
|
@ -1,12 +1,12 @@
|
||||
object MacroListView: TMacroListView
|
||||
Left = 390
|
||||
Height = 300
|
||||
Height = 330
|
||||
Top = 249
|
||||
Width = 340
|
||||
Caption = 'MacroListView'
|
||||
ClientHeight = 300
|
||||
ClientHeight = 330
|
||||
ClientWidth = 340
|
||||
Constraints.MinHeight = 300
|
||||
Constraints.MinHeight = 330
|
||||
Constraints.MinWidth = 300
|
||||
OnActivate = FormActivate
|
||||
OnDeactivate = FormActivate
|
||||
@ -14,28 +14,28 @@ object MacroListView: TMacroListView
|
||||
object Panel1: TPanel
|
||||
AnchorSideRight.Control = pnlButtons
|
||||
Left = 6
|
||||
Height = 241
|
||||
Height = 278
|
||||
Top = 6
|
||||
Width = 208
|
||||
Width = 211
|
||||
Align = alLeft
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Right = 6
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 241
|
||||
ClientWidth = 208
|
||||
ClientHeight = 278
|
||||
ClientWidth = 211
|
||||
TabOrder = 0
|
||||
object lbRecordedView: TListView
|
||||
Left = 0
|
||||
Height = 170
|
||||
Height = 229
|
||||
Top = 24
|
||||
Width = 208
|
||||
Width = 211
|
||||
Align = alClient
|
||||
AutoWidthLastColumn = True
|
||||
Columns = <
|
||||
item
|
||||
Width = 204
|
||||
Width = 207
|
||||
end>
|
||||
PopupMenu = PopupMenu1
|
||||
RowSelect = True
|
||||
@ -49,7 +49,7 @@ object MacroListView: TMacroListView
|
||||
Left = 0
|
||||
Height = 24
|
||||
Top = 0
|
||||
Width = 208
|
||||
Width = 211
|
||||
AutoSize = True
|
||||
BorderSpacing.InnerBorder = 1
|
||||
EdgeBorders = [ebLeft, ebTop, ebRight]
|
||||
@ -69,7 +69,7 @@ object MacroListView: TMacroListView
|
||||
end
|
||||
object tbProject: TToolButton
|
||||
Tag = 1
|
||||
Left = 83
|
||||
Left = 72
|
||||
Top = 2
|
||||
Caption = 'tbProject'
|
||||
Grouped = True
|
||||
@ -78,7 +78,7 @@ object MacroListView: TMacroListView
|
||||
end
|
||||
object tbIDE: TToolButton
|
||||
Tag = 1
|
||||
Left = 148
|
||||
Left = 128
|
||||
Top = 2
|
||||
Caption = 'tbIDE'
|
||||
Grouped = True
|
||||
@ -88,9 +88,9 @@ object MacroListView: TMacroListView
|
||||
end
|
||||
object ToolBar2: TToolBar
|
||||
Left = 0
|
||||
Height = 44
|
||||
Top = 197
|
||||
Width = 208
|
||||
Height = 22
|
||||
Top = 256
|
||||
Width = 211
|
||||
Align = alBottom
|
||||
AutoSize = True
|
||||
BorderSpacing.Top = 3
|
||||
@ -100,23 +100,23 @@ object MacroListView: TMacroListView
|
||||
TabOrder = 2
|
||||
object lbMoveTo: TLabel
|
||||
Left = 1
|
||||
Height = 44
|
||||
Height = 22
|
||||
Top = 0
|
||||
Width = 58
|
||||
Width = 54
|
||||
Align = alLeft
|
||||
Caption = 'lbMoveTo'
|
||||
Layout = tlCenter
|
||||
ParentColor = False
|
||||
end
|
||||
object tbMoveProject: TToolButton
|
||||
Left = 59
|
||||
Left = 55
|
||||
Top = 0
|
||||
Caption = 'tbMoveProject'
|
||||
OnClick = tbMoveProjectClick
|
||||
end
|
||||
object tbMoveIDE: TToolButton
|
||||
Left = 59
|
||||
Top = 22
|
||||
Left = 141
|
||||
Top = 0
|
||||
Caption = 'tbMoveIDE'
|
||||
OnClick = tbMoveIDEClick
|
||||
end
|
||||
@ -124,8 +124,8 @@ object MacroListView: TMacroListView
|
||||
end
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 41
|
||||
Top = 253
|
||||
Height = 34
|
||||
Top = 290
|
||||
Width = 328
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
@ -140,15 +140,15 @@ object MacroListView: TMacroListView
|
||||
ShowButtons = [pbClose, pbHelp]
|
||||
end
|
||||
object pnlButtons: TPanel
|
||||
Left = 220
|
||||
Height = 250
|
||||
Left = 223
|
||||
Height = 284
|
||||
Top = 0
|
||||
Width = 120
|
||||
Width = 117
|
||||
Align = alRight
|
||||
AutoSize = True
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 250
|
||||
ClientWidth = 120
|
||||
ClientHeight = 284
|
||||
ClientWidth = 117
|
||||
Constraints.MinHeight = 250
|
||||
TabOrder = 2
|
||||
object btnSelect: TButton
|
||||
@ -158,9 +158,9 @@ object MacroListView: TMacroListView
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 27
|
||||
Height = 25
|
||||
Top = 6
|
||||
Width = 108
|
||||
Width = 105
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 6
|
||||
@ -172,15 +172,15 @@ object MacroListView: TMacroListView
|
||||
end
|
||||
object btnRename: TButton
|
||||
AnchorSideLeft.Control = pnlButtons
|
||||
AnchorSideTop.Control = btnSelect
|
||||
AnchorSideTop.Control = btnSetKeys
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = pnlButtons
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 27
|
||||
Top = 39
|
||||
Width = 108
|
||||
Height = 25
|
||||
Top = 68
|
||||
Width = 105
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 6
|
||||
@ -192,15 +192,14 @@ object MacroListView: TMacroListView
|
||||
end
|
||||
object btnPlay: TButton
|
||||
AnchorSideLeft.Control = pnlButtons
|
||||
AnchorSideTop.Control = btnRename
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = pnlButtons
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = chkRepeat
|
||||
Left = 6
|
||||
Height = 27
|
||||
Top = 102
|
||||
Width = 108
|
||||
Height = 25
|
||||
Top = 145
|
||||
Width = 105
|
||||
Anchors = [akLeft, akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 6
|
||||
@ -218,9 +217,9 @@ object MacroListView: TMacroListView
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = btnRecordStop
|
||||
Left = 6
|
||||
Height = 27
|
||||
Top = 190
|
||||
Width = 108
|
||||
Height = 25
|
||||
Top = 228
|
||||
Width = 105
|
||||
Anchors = [akLeft, akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 6
|
||||
@ -239,9 +238,9 @@ object MacroListView: TMacroListView
|
||||
AnchorSideBottom.Control = pnlButtons
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 27
|
||||
Top = 223
|
||||
Width = 108
|
||||
Height = 25
|
||||
Top = 259
|
||||
Width = 105
|
||||
Anchors = [akLeft, akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 6
|
||||
@ -258,9 +257,9 @@ object MacroListView: TMacroListView
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = edRepeat
|
||||
Left = 6
|
||||
Height = 22
|
||||
Top = 132
|
||||
Width = 108
|
||||
Height = 19
|
||||
Top = 173
|
||||
Width = 105
|
||||
Anchors = [akLeft, akRight, akBottom]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 3
|
||||
@ -278,8 +277,8 @@ object MacroListView: TMacroListView
|
||||
AnchorSideBottom.Control = btnRecord
|
||||
Left = 6
|
||||
Height = 23
|
||||
Top = 157
|
||||
Width = 108
|
||||
Top = 195
|
||||
Width = 105
|
||||
Anchors = [akLeft, akRight, akBottom]
|
||||
AutoSize = False
|
||||
BorderSpacing.Left = 6
|
||||
@ -299,9 +298,9 @@ object MacroListView: TMacroListView
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 27
|
||||
Top = 72
|
||||
Width = 108
|
||||
Height = 25
|
||||
Top = 99
|
||||
Width = 105
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 6
|
||||
@ -311,6 +310,26 @@ object MacroListView: TMacroListView
|
||||
OnClick = btnDeleteClick
|
||||
TabOrder = 7
|
||||
end
|
||||
object btnSetKeys: TButton
|
||||
AnchorSideLeft.Control = pnlButtons
|
||||
AnchorSideTop.Control = btnSelect
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = pnlButtons
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 25
|
||||
Top = 37
|
||||
Width = 105
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Right = 6
|
||||
Caption = 'btnSetKeys'
|
||||
OnClick = btnSetKeysClick
|
||||
TabOrder = 8
|
||||
end
|
||||
end
|
||||
object PopupMenu1: TPopupMenu
|
||||
left = 144
|
||||
|
@ -7,8 +7,9 @@ interface
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, Laz2_XMLCfg, SynMacroRecorder, SynEdit, SynEditKeyCmds,
|
||||
FileProcs, Forms, Controls, Graphics, Dialogs, StdCtrls, ButtonPanel, ComCtrls, ExtCtrls,
|
||||
Spin, Menus, MainBar, IDEWindowIntf, IDEImagesIntf, LazarusIDEStrConsts, ProjectDefs,
|
||||
LazConf, Project, SrcEditorIntf, IDEHelpIntf;
|
||||
Spin, Menus, LCLType, MainBar, IDEWindowIntf, IDEImagesIntf, LazarusIDEStrConsts,
|
||||
ProjectDefs, LazConf, Project, KeyMapping, KeyMapShortCutDlg, SrcEditorIntf, IDEHelpIntf,
|
||||
IDECommands;
|
||||
|
||||
type
|
||||
|
||||
@ -18,12 +19,20 @@ type
|
||||
private
|
||||
FHasError: Boolean;
|
||||
FFailedText: String;
|
||||
FIdeCmd: TIDECommand;
|
||||
procedure ExecMacro(Sender: TObject);
|
||||
function GetIdeCmd: TKeyCommandRelation;
|
||||
protected
|
||||
procedure SetMacroName(AValue: string); override;
|
||||
property IdeCmd: TKeyCommandRelation read GetIdeCmd;
|
||||
public
|
||||
constructor Create(aOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
function GetAsText: String;
|
||||
procedure SetFromText(const AText: String);
|
||||
procedure WriteToXmlConf(AConf: TXMLConfig; const APath: String);
|
||||
procedure ReadFromXmlConf(AConf: TXMLConfig; const APath: String);
|
||||
function ShortCutAsText: String;
|
||||
property HasError: Boolean read FHasError;
|
||||
end;
|
||||
|
||||
@ -75,12 +84,19 @@ type
|
||||
|
||||
{ TEditorMacroList }
|
||||
|
||||
TEditorMacroList = class;
|
||||
TMacroAddedEvent = procedure(AList: TEditorMacroList; AMacro: TEditorMacro) of object;
|
||||
|
||||
TEditorMacroList = class
|
||||
private
|
||||
FList: TList;
|
||||
FOnAdded: TMacroAddedEvent;
|
||||
FOnChange: TNotifyEvent;
|
||||
FOnRemove: TMacroAddedEvent;
|
||||
function GetMacros(Index: Integer): TEditorMacro;
|
||||
procedure DoChanged;
|
||||
procedure DoAdded(AMacro: TEditorMacro);
|
||||
procedure DoRemove(AMacro: TEditorMacro);
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
@ -94,11 +110,14 @@ type
|
||||
procedure Remove(AMacro: TEditorMacro);
|
||||
property Macros[Index: Integer]: TEditorMacro read GetMacros;
|
||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||
property OnAdded: TMacroAddedEvent read FOnAdded write FOnAdded;
|
||||
property OnRemove: TMacroAddedEvent read FOnRemove write FOnRemove;
|
||||
end;
|
||||
|
||||
{ TMacroListView }
|
||||
|
||||
TMacroListView = class(TForm)
|
||||
btnSetKeys: TButton;
|
||||
btnPlay: TButton;
|
||||
btnRecord: TButton;
|
||||
btnRecordStop: TButton;
|
||||
@ -131,6 +150,7 @@ type
|
||||
procedure btnRecordStopClick(Sender: TObject);
|
||||
procedure btnRenameClick(Sender: TObject);
|
||||
procedure btnSelectClick(Sender: TObject);
|
||||
procedure btnSetKeysClick(Sender: TObject);
|
||||
procedure FormActivate(Sender: TObject);
|
||||
procedure HelpButtonClick(Sender: TObject);
|
||||
procedure lbRecordedViewSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
|
||||
@ -154,9 +174,11 @@ type
|
||||
procedure DoEditorMacroStateChanged;
|
||||
public
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
procedure ShowMacroListViewer;
|
||||
procedure UpdateMacroListViewer;
|
||||
procedure DoEditorMacroStateChanged;
|
||||
|
||||
procedure LoadProjectSpecificInfo(XMLConfig: TXMLConfig; Merge: boolean);
|
||||
@ -166,6 +188,7 @@ procedure SaveGlobalInfo;
|
||||
|
||||
var
|
||||
EditorMacroRecorder: TEditorMacro = nil; // set by SourceEditor
|
||||
OnKeyMapReloaded: procedure of object;
|
||||
|
||||
implementation
|
||||
|
||||
@ -176,6 +199,8 @@ var
|
||||
CurrentRecordingMacro: TEditorMacro = nil; // Points to a Macro in the list (copy)
|
||||
CurrentActiveMacro: TEditorMacro = nil; // Points to a Macro in the list (copy)
|
||||
MacroRecCounter: Integer = 1;
|
||||
KeyCategory: TIDECommandCategory = nil;
|
||||
|
||||
const
|
||||
GlobalConfFileName = 'EditorMacros.xml';
|
||||
|
||||
@ -186,6 +211,12 @@ begin
|
||||
IDEWindowCreators.ShowForm(MacroListView, True);
|
||||
end;
|
||||
|
||||
procedure UpdateMacroListViewer;
|
||||
begin
|
||||
if MacroListView <> nil then
|
||||
MacroListView.UpdateDisplay;
|
||||
end;
|
||||
|
||||
procedure DoEditorMacroStateChanged;
|
||||
begin
|
||||
if EditorMacroRecorder= nil then exit;
|
||||
@ -252,12 +283,72 @@ end;
|
||||
|
||||
{ TEditorMacro }
|
||||
|
||||
procedure TEditorMacro.ExecMacro(Sender: TObject);
|
||||
begin
|
||||
if EditorMacroRecorder.State <> msStopped then exit;
|
||||
try
|
||||
EditorMacroRecorder.AssignEventsFrom(Self);
|
||||
EditorMacroRecorder.PlaybackMacro(TCustomSynEdit(SourceEditorManagerIntf.ActiveEditor.EditorControl));
|
||||
finally
|
||||
EditorMacroRecorder.AssignEventsFrom(CurrentActiveMacro);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TEditorMacro.GetIdeCmd: TKeyCommandRelation;
|
||||
begin
|
||||
Result := TKeyCommandRelation(FIdeCmd);
|
||||
end;
|
||||
|
||||
procedure TEditorMacro.SetMacroName(AValue: string);
|
||||
begin
|
||||
inherited SetMacroName(AValue);
|
||||
|
||||
if (IDECommandList = nil) then
|
||||
exit;
|
||||
|
||||
if HasError then begin
|
||||
if FIdeCmd <> nil then begin
|
||||
(IDECommandList as TKeyCommandRelationList).RemoveCommand(FIdeCmd);
|
||||
FreeAndNil(FIdeCmd);
|
||||
end;
|
||||
exit;
|
||||
end;
|
||||
|
||||
if KeyCategory = nil then
|
||||
KeyCategory := IDECommandList.CreateCategory(nil, 'EditorMacros',
|
||||
'Editor Macros', IDECmdScopeSrcEditOnly);
|
||||
|
||||
if FIdeCmd = nil then begin
|
||||
FIdeCmd := (IDECommandList as TKeyCommandRelationList).CreateCommand(
|
||||
KeyCategory,
|
||||
'EdtMacro'+MacroName,
|
||||
MacroName,
|
||||
IDEShortCut(VK_UNKNOWN, [], VK_UNKNOWN, []),
|
||||
IDEShortCut(VK_UNKNOWN, [], VK_UNKNOWN, []),
|
||||
@ExecMacro, nil
|
||||
);
|
||||
TKeyCommandRelation(FIdeCmd).SkipSaving := True;
|
||||
end
|
||||
else
|
||||
FIdeCmd.LocalizedName := MacroName;
|
||||
|
||||
end;
|
||||
|
||||
constructor TEditorMacro.Create(aOwner: TComponent);
|
||||
begin
|
||||
inherited Create(aOwner);
|
||||
FHasError := False;
|
||||
end;
|
||||
|
||||
destructor TEditorMacro.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
if (FIdeCmd <> nil) and (IDECommandList <> nil) then begin
|
||||
(IDECommandList as TKeyCommandRelationList).RemoveCommand(FIdeCmd);
|
||||
FreeAndNil(FIdeCmd);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TEditorMacro.GetAsText: String;
|
||||
var
|
||||
i : integer;
|
||||
@ -304,6 +395,7 @@ begin
|
||||
if R.HasError then begin
|
||||
FHasError := True;
|
||||
FFailedText := AText;
|
||||
MacroName := MacroName;
|
||||
end;
|
||||
finally
|
||||
R.Free;
|
||||
@ -311,14 +403,55 @@ begin
|
||||
end;
|
||||
|
||||
procedure TEditorMacro.WriteToXmlConf(AConf: TXMLConfig; const APath: String);
|
||||
procedure Clear(const SubPath: string);
|
||||
begin
|
||||
AConf.DeleteValue(SubPath+'Key1');
|
||||
AConf.DeleteValue(SubPath+'Shift1');
|
||||
AConf.DeleteValue(SubPath+'Key2');
|
||||
AConf.DeleteValue(SubPath+'Shift2');
|
||||
end;
|
||||
procedure Store(const SubPath: string; Key: TIDEShortCut);
|
||||
var
|
||||
s: TShiftState;
|
||||
begin
|
||||
AConf.SetDeleteValue(SubPath+'Key1', key.Key1, VK_UNKNOWN);
|
||||
if key.Key1=VK_UNKNOWN then
|
||||
s:=[]
|
||||
else
|
||||
s:=key.Shift1;
|
||||
AConf.SetDeleteValue(SubPath+'Shift1',ShiftStateToCfgStr(s),ShiftStateToCfgStr([]));
|
||||
AConf.SetDeleteValue(SubPath+'Key2',key.Key2,VK_UNKNOWN);
|
||||
if key.Key2=VK_UNKNOWN then
|
||||
s:=[]
|
||||
else
|
||||
s:=key.Shift2;
|
||||
AConf.SetDeleteValue(SubPath+'Shift2',ShiftStateToCfgStr(s),ShiftStateToCfgStr([]));
|
||||
end;
|
||||
|
||||
begin
|
||||
AConf.SetValue(APath + 'Name', MacroName);
|
||||
AConf.SetValue(APath + 'Code/Value', GetAsText);
|
||||
|
||||
if (FIdeCmd = nil) then begin
|
||||
Clear(APath + 'KeyA/');
|
||||
Clear(APath + 'KeyB/');
|
||||
end else begin
|
||||
Store(APath + 'KeyA/', FIdeCmd.ShortcutA);
|
||||
Store(APath + 'KeyB/', FIdeCmd.ShortcutB);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TEditorMacro.ReadFromXmlConf(AConf: TXMLConfig; const APath: String);
|
||||
procedure Load(SubPath: string; out Key: TIDEShortCut);
|
||||
begin
|
||||
key.Key1 := AConf.GetValue(SubPath+'Key1',VK_UNKNOWN);
|
||||
key.Shift1 := CfgStrToShiftState(AConf.GetValue(SubPath+'Shift1',''));
|
||||
key.Key2 := AConf.GetValue(SubPath+'Key2',VK_UNKNOWN);
|
||||
key.Shift2 := CfgStrToShiftState(AConf.GetValue(SubPath+'Shift2',''));
|
||||
end;
|
||||
var
|
||||
s: String;
|
||||
SCut: TIDEShortCut;
|
||||
begin
|
||||
s := AConf.GetValue(APath + 'Name', '');
|
||||
if s <> '' then MacroName := s;
|
||||
@ -328,6 +461,27 @@ begin
|
||||
FHasError := True;
|
||||
FFailedText := s;
|
||||
end;
|
||||
|
||||
if (FIdeCmd <> nil) then begin
|
||||
Load(APath+'KeyA/', SCut);
|
||||
if (IDECommandList as TKeyCommandRelationList).Find(SCut, TSourceEditorWindowInterface) = nil then
|
||||
FIdeCmd.ShortcutA := SCut;
|
||||
|
||||
Load(APath+'KeyB/', SCut);
|
||||
if (IDECommandList as TKeyCommandRelationList).Find(SCut, TSourceEditorWindowInterface) = nil then
|
||||
FIdeCmd.ShortcutB := SCut;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TEditorMacro.ShortCutAsText: String;
|
||||
begin
|
||||
Result := '';
|
||||
If FIdeCmd = nil then
|
||||
exit;
|
||||
if not IDEShortCutEmpty(FIdeCmd.ShortcutA) then
|
||||
Result := Result + ' (' + KeyAndShiftStateToEditorKeyString(FIdeCmd.ShortcutA) + ')';
|
||||
if not IDEShortCutEmpty(FIdeCmd.ShortcutB) then
|
||||
Result := Result + ' (' + KeyAndShiftStateToEditorKeyString(FIdeCmd.ShortcutB) + ')';
|
||||
end;
|
||||
|
||||
{ TIdeMacroEventReader }
|
||||
@ -659,6 +813,24 @@ begin
|
||||
UpdateDisplay;
|
||||
end;
|
||||
|
||||
procedure TMacroListView.btnSetKeysClick(Sender: TObject);
|
||||
var
|
||||
i: integer;
|
||||
M: TEditorMacro;
|
||||
begin
|
||||
if lbRecordedView.ItemIndex < 0 then exit;
|
||||
M := CurrentEditorMacroList.Macros[lbRecordedView.ItemIndex];
|
||||
|
||||
if M.IdeCmd = nil then // only for error macros
|
||||
exit;
|
||||
|
||||
i := (IDECommandList as TKeyCommandRelationList).IndexOf(M.IdeCmd);
|
||||
if (i >= 0) then
|
||||
ShowKeyMappingEditForm(i, (IDECommandList as TKeyCommandRelationList));
|
||||
UpdateDisplay;
|
||||
if OnKeyMapReloaded <> nil then OnKeyMapReloaded();
|
||||
end;
|
||||
|
||||
procedure TMacroListView.FormActivate(Sender: TObject);
|
||||
begin
|
||||
lbRecordedView.HideSelection := Active;
|
||||
@ -773,7 +945,7 @@ begin
|
||||
for i := 0 to CurrentEditorMacroList.Count - 1 do begin
|
||||
M := CurrentEditorMacroList.Macros[i];
|
||||
NewItem := lbRecordedView.Items.Add;
|
||||
NewItem.Caption := M.MacroName;
|
||||
NewItem.Caption := M.MacroName + M.ShortCutAsText;
|
||||
if M.HasError then
|
||||
NewItem.ImageIndex := FImageErr
|
||||
else
|
||||
@ -809,6 +981,7 @@ begin
|
||||
|
||||
|
||||
btnSelect.Enabled := IsStopped and IsSel and (not FIsPlaying) and (not IsErr);
|
||||
btnSetKeys.Enabled := IsStopped and IsSel and (not FIsPlaying) and (not IsErr);
|
||||
btnRename.Enabled := IsStopped and IsSel and (not FIsPlaying) and (not IsErr);
|
||||
btnDelete.Enabled := IsStopped and IsSel and (not FIsPlaying);
|
||||
|
||||
@ -859,6 +1032,7 @@ begin
|
||||
lbMoveTo.Caption := lisMoveTo;
|
||||
|
||||
btnSelect.Caption := lisMenuSelect;
|
||||
btnSetKeys.Caption := lisEditKey;
|
||||
btnRename.Caption := lisRename2;
|
||||
btnDelete.Caption := lisDelete;
|
||||
btnPlay.Caption := lisPlay;
|
||||
@ -881,6 +1055,11 @@ begin
|
||||
UpdateDisplay;
|
||||
end;
|
||||
|
||||
destructor TMacroListView.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{ TEditorMacroList }
|
||||
|
||||
function TEditorMacroList.GetMacros(Index: Integer): TEditorMacro;
|
||||
@ -894,6 +1073,18 @@ begin
|
||||
FOnChange(Self);
|
||||
end;
|
||||
|
||||
procedure TEditorMacroList.DoAdded(AMacro: TEditorMacro);
|
||||
begin
|
||||
if Assigned(FOnAdded) then
|
||||
FOnAdded(Self, AMacro);
|
||||
end;
|
||||
|
||||
procedure TEditorMacroList.DoRemove(AMacro: TEditorMacro);
|
||||
begin
|
||||
if Assigned(FOnRemove) then
|
||||
FOnRemove(Self, AMacro);
|
||||
end;
|
||||
|
||||
constructor TEditorMacroList.Create;
|
||||
begin
|
||||
FList := TList.Create;
|
||||
@ -954,17 +1145,20 @@ end;
|
||||
function TEditorMacroList.Add(AMacro: TEditorMacro): Integer;
|
||||
begin
|
||||
Result := FList.Add(AMacro);
|
||||
DoAdded(AMacro);
|
||||
DoChanged;
|
||||
end;
|
||||
|
||||
procedure TEditorMacroList.Delete(AnIndex: Integer);
|
||||
begin
|
||||
DoRemove(Macros[AnIndex]);
|
||||
FList.Delete(AnIndex);
|
||||
DoChanged;
|
||||
end;
|
||||
|
||||
procedure TEditorMacroList.Remove(AMacro: TEditorMacro);
|
||||
begin
|
||||
DoRemove(AMacro);
|
||||
FList.Remove(AMacro);
|
||||
DoChanged;
|
||||
end;
|
||||
|
@ -84,6 +84,7 @@ type
|
||||
|
||||
TKeyCommandRelation = class(TIDECommand)
|
||||
private
|
||||
FSkipSaving: Boolean;
|
||||
procedure SetSingle(NewKeyA: word; NewShiftA: TShiftState;
|
||||
NewKeyB: word; NewShiftB: TShiftState);
|
||||
procedure SetSingle(NewKeyA: word; NewShiftA: TShiftState);
|
||||
@ -100,8 +101,10 @@ type
|
||||
procedure GetDefaultKeyForMacOSXScheme;
|
||||
procedure GetDefaultKeyForMacOSXLazScheme;
|
||||
protected
|
||||
procedure Init; override;
|
||||
public
|
||||
function GetLocalizedName: string; override;
|
||||
property SkipSaving: Boolean read FSkipSaving write FSkipSaving;
|
||||
end;
|
||||
|
||||
{ TLoadedKeyCommand
|
||||
@ -181,6 +184,7 @@ type
|
||||
const OnExecuteMethod: TNotifyEvent = nil;
|
||||
const OnExecuteProc: TNotifyProcedure = nil
|
||||
): TIDECommand; override;
|
||||
procedure RemoveCommand(ACommand: TIDECommand);
|
||||
public
|
||||
property ExtToolCount: integer read fExtToolCount write SetExtToolCount;// in menu
|
||||
property Relations[Index:integer]:TKeyCommandRelation read GetRelation; default;
|
||||
@ -2423,6 +2427,12 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TKeyCommandRelation.Init;
|
||||
begin
|
||||
inherited;
|
||||
FSkipSaving := False;
|
||||
end;
|
||||
|
||||
{ TKeyCommandRelationList }
|
||||
|
||||
constructor TKeyCommandRelationList.Create;
|
||||
@ -3287,6 +3297,7 @@ begin
|
||||
for a:=0 to FRelations.Count-1 do begin
|
||||
Name:=Relations[a].Name;
|
||||
if Name='' then continue;
|
||||
if Relations[a].SkipSaving then continue;
|
||||
AVLNode:=fLoadedKeyCommands.FindKey(Pointer(Name),
|
||||
@CompareNameWithLoadedKeyCommand);
|
||||
if AVLNode<>nil then begin
|
||||
@ -3576,11 +3587,9 @@ begin
|
||||
Result:=Categories[AddCategory(CreateUniqueCategoryName(AName),Description,Scope)];
|
||||
end;
|
||||
|
||||
function TKeyCommandRelationList.CreateCommand(Category: TIDECommandCategory;
|
||||
const AName, Description: string;
|
||||
const TheShortcutA, TheShortcutB: TIDEShortCut;
|
||||
const OnExecuteMethod: TNotifyEvent;
|
||||
const OnExecuteProc: TNotifyProcedure): TIDECommand;
|
||||
function TKeyCommandRelationList.CreateCommand(Category: TIDECommandCategory; const AName,
|
||||
Description: string; const TheShortcutA, TheShortcutB: TIDEShortCut;
|
||||
const OnExecuteMethod: TNotifyEvent; const OnExecuteProc: TNotifyProcedure): TIDECommand;
|
||||
var
|
||||
NewName: String;
|
||||
cmd: word;
|
||||
@ -3596,6 +3605,11 @@ begin
|
||||
Result:=CmdRel;
|
||||
end;
|
||||
|
||||
procedure TKeyCommandRelationList.RemoveCommand(ACommand: TIDECommand);
|
||||
begin
|
||||
fRelations.Remove(ACommand);
|
||||
end;
|
||||
|
||||
function TKeyCommandRelationList.GetCategory(Index: integer): TIDECommandCategory;
|
||||
begin
|
||||
Result:=TIDECommandCategory(fCategories[Index]);
|
||||
|
@ -5564,6 +5564,7 @@ resourcestring
|
||||
lisSavedWithIDESettings = 'Saved with IDE settings';
|
||||
lisMoveTo = 'Move to: ';
|
||||
lisFailedToSaveFile = 'Failed to save file.';
|
||||
lisEditKey = 'Edit Key';
|
||||
|
||||
implementation
|
||||
|
||||
|
@ -1334,7 +1334,6 @@ begin
|
||||
Application.ShowButtonGlyphs := ShowButtonGlyphs;
|
||||
Application.ShowMenuGlyphs := ShowMenuGlyphs;
|
||||
end;
|
||||
EditorMacroListViewer.LoadGlobalInfo;
|
||||
|
||||
OldVer:=EnvironmentOptions.OldLazarusVersion;
|
||||
NowVer:=GetLazarusVersionString;
|
||||
@ -1390,6 +1389,10 @@ begin
|
||||
SetupIDECommands;
|
||||
SetupIDEMsgQuickFixItems;
|
||||
EditorOpts.Load;
|
||||
EditorMacroListViewer.LoadGlobalInfo;
|
||||
// Defered till created
|
||||
//EditorMacroListViewer.OnKeyMapReloaded := @SourceEditorManager.ReloadEditorOptions;
|
||||
|
||||
|
||||
ExternalTools.LoadShortCuts(EditorOpts.KeyMap);
|
||||
|
||||
@ -1642,6 +1645,7 @@ begin
|
||||
FreeThenNil(CodeExplorerOptions);
|
||||
FreeThenNil(MiscellaneousOptions);
|
||||
FreeThenNil(EditorOpts);
|
||||
IDECommandList := nil;
|
||||
FreeThenNil(DebuggerOptions);
|
||||
FreeThenNil(EnvironmentOptions);
|
||||
FreeThenNil(IDECommandScopes);
|
||||
@ -2181,6 +2185,7 @@ begin
|
||||
MainIDEBar.itmOpenFileAtCursor.OnClick:=@mnuOpenFileAtCursorClicked;
|
||||
|
||||
SourceEditorManager.InitMacros(GlobalMacroList);
|
||||
EditorMacroListViewer.OnKeyMapReloaded := @SourceEditorManager.ReloadEditorOptions;
|
||||
end;
|
||||
|
||||
procedure TMainIDE.SetupCodeMacros;
|
||||
@ -5131,6 +5136,7 @@ begin
|
||||
UpdateHighlighters(True);
|
||||
SourceEditorManager.ReloadEditorOptions;
|
||||
ReloadMenuShortCuts;
|
||||
UpdateMacroListViewer;
|
||||
end;
|
||||
|
||||
procedure TMainIDE.DoCodetoolsOptionsAfterWrite(Sender: TObject; Restore: boolean);
|
||||
|
@ -528,6 +528,7 @@ type
|
||||
procedure SetShortcutA(const AValue: TIDEShortCut); virtual;
|
||||
procedure SetShortcutB(const AValue: TIDEShortCut); virtual;
|
||||
procedure Change;
|
||||
procedure Init; virtual;
|
||||
public
|
||||
function AsShortCut: TShortCut; virtual;
|
||||
constructor Create(TheCategory: TIDECommandCategory;
|
||||
@ -852,6 +853,11 @@ begin
|
||||
if Assigned(OnChange) then OnChange(Self);
|
||||
end;
|
||||
|
||||
procedure TIDECommand.Init;
|
||||
begin
|
||||
//
|
||||
end;
|
||||
|
||||
function TIDECommand.GetLocalizedName: string;
|
||||
begin
|
||||
if FLocalizedName<>'' then
|
||||
@ -918,6 +924,7 @@ begin
|
||||
FOnExecute:=ExecuteMethod;
|
||||
FOnExecuteProc:=ExecuteProc;
|
||||
//DebugLn('TIDECommand.Create Name=',Name,' ',ShortCutToText(AsShortCut),' ',dbgs(Pointer(Self)));
|
||||
Init;
|
||||
end;
|
||||
|
||||
constructor TIDECommand.Create(TheCategory: TIDECommandCategory;
|
||||
|
Loading…
Reference in New Issue
Block a user