mirror of https://gitlab.com/basile.b/dexed.git
added shortcut managment to TCEEditorOptions
- editable without any editor opened - new values are assigned
This commit is contained in:
parent
cddf132e8b
commit
f606596544
|
|
@ -6,6 +6,7 @@ interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Graphics, SynEdit, SynEditMouseCmds, SynEditMiscClasses,
|
Classes, SysUtils, Graphics, SynEdit, SynEditMouseCmds, SynEditMiscClasses,
|
||||||
|
SynEditKeyCmds, Menus,
|
||||||
ce_interfaces, ce_observer, ce_common, ce_writableComponent, ce_synmemo,
|
ce_interfaces, ce_observer, ce_common, ce_writableComponent, ce_synmemo,
|
||||||
ce_d2syn, ce_txtsyn;
|
ce_d2syn, ce_txtsyn;
|
||||||
|
|
||||||
|
|
@ -28,6 +29,8 @@ type
|
||||||
fD2Syn: TPersistent;
|
fD2Syn: TPersistent;
|
||||||
fTxtSyn: TPersistent;
|
fTxtSyn: TPersistent;
|
||||||
//
|
//
|
||||||
|
fShortCuts: TCollection;
|
||||||
|
//
|
||||||
fSelCol: TSynSelectedColor;
|
fSelCol: TSynSelectedColor;
|
||||||
fFoldedColor: TSynSelectedColor;
|
fFoldedColor: TSynSelectedColor;
|
||||||
fMouseLinkColor: TSynSelectedColor;
|
fMouseLinkColor: TSynSelectedColor;
|
||||||
|
|
@ -52,6 +55,7 @@ type
|
||||||
procedure setBracketMatchColor(aValue: TSynSelectedColor);
|
procedure setBracketMatchColor(aValue: TSynSelectedColor);
|
||||||
procedure setD2Syn(aValue: TPersistent);
|
procedure setD2Syn(aValue: TPersistent);
|
||||||
procedure setTxtSyn(aValue: TPersistent);
|
procedure setTxtSyn(aValue: TPersistent);
|
||||||
|
procedure setShortcuts(Avalue: TCollection);
|
||||||
published
|
published
|
||||||
property bracketMatchColor: TSynSelectedColor read fBracketMatchColor write setBracketMatchColor;
|
property bracketMatchColor: TSynSelectedColor read fBracketMatchColor write setBracketMatchColor;
|
||||||
property mouseLinkColor: TSynSelectedColor read fMouseLinkColor write setMouseLinkColor;
|
property mouseLinkColor: TSynSelectedColor read fMouseLinkColor write setMouseLinkColor;
|
||||||
|
|
@ -70,6 +74,7 @@ type
|
||||||
property mouseOptions: TSynEditorMouseOptions read fMouseOptions write fMouseOptions;
|
property mouseOptions: TSynEditorMouseOptions read fMouseOptions write fMouseOptions;
|
||||||
property D2Highlighter: TPersistent read fD2Syn write setD2Syn;
|
property D2Highlighter: TPersistent read fD2Syn write setD2Syn;
|
||||||
property TxtHighlighter: TPersistent read fTxtSyn write setTxtSyn;
|
property TxtHighlighter: TPersistent read fTxtSyn write setTxtSyn;
|
||||||
|
property shortcuts: TCollection read fShortCuts write setShortcuts;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
@ -81,9 +86,10 @@ type
|
||||||
* Manages and exposes all the editor and highligther options to an TCEOptionsEditor.
|
* Manages and exposes all the editor and highligther options to an TCEOptionsEditor.
|
||||||
* It's also responsible to give the current options to a new editor.
|
* It's also responsible to give the current options to a new editor.
|
||||||
*)
|
*)
|
||||||
TCEEditorOptions = class(TCEEditorOptionsBase, ICEEditableOptions, ICEMultiDocObserver)
|
TCEEditorOptions = class(TCEEditorOptionsBase, ICEEditableOptions, ICEMultiDocObserver, ICEEDitableShortcut)
|
||||||
private
|
private
|
||||||
fBackup: TCEEditorOptionsBase;
|
fBackup: TCEEditorOptionsBase;
|
||||||
|
fShortcutCount: Integer;
|
||||||
//
|
//
|
||||||
function optionedWantCategory(): string;
|
function optionedWantCategory(): string;
|
||||||
function optionedWantEditorKind: TOptionEditorKind;
|
function optionedWantEditorKind: TOptionEditorKind;
|
||||||
|
|
@ -95,6 +101,10 @@ type
|
||||||
procedure docChanged(aDoc: TCESynMemo);
|
procedure docChanged(aDoc: TCESynMemo);
|
||||||
procedure docClosing(aDoc: TCESynMemo);
|
procedure docClosing(aDoc: TCESynMemo);
|
||||||
//
|
//
|
||||||
|
function scedWantFirst: boolean;
|
||||||
|
function scedWantNext(out category, identifier: string; out aShortcut: TShortcut): boolean;
|
||||||
|
procedure scedSendItem(const category, identifier: string; aShortcut: TShortcut);
|
||||||
|
//
|
||||||
procedure applyChangesFromSelf;
|
procedure applyChangesFromSelf;
|
||||||
procedure applyChangeToEditor(anEditor: TCESynMemo);
|
procedure applyChangeToEditor(anEditor: TCESynMemo);
|
||||||
protected
|
protected
|
||||||
|
|
@ -114,6 +124,9 @@ var
|
||||||
|
|
||||||
{$REGION Standard Comp/Obj -----------------------------------------------------}
|
{$REGION Standard Comp/Obj -----------------------------------------------------}
|
||||||
constructor TCEEditorOptionsBase.Create(AOwner: TComponent);
|
constructor TCEEditorOptionsBase.Create(AOwner: TComponent);
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
shc: TCEPersistentShortcut;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
//
|
//
|
||||||
|
|
@ -160,12 +173,28 @@ begin
|
||||||
//
|
//
|
||||||
mouseOptions := MouseOptions +
|
mouseOptions := MouseOptions +
|
||||||
[emAltSetsColumnMode, emDragDropEditing, emCtrlWheelZoom, emShowCtrlMouseLinks];
|
[emAltSetsColumnMode, emDragDropEditing, emCtrlWheelZoom, emShowCtrlMouseLinks];
|
||||||
|
//
|
||||||
|
fShortCuts := TCollection.Create(TCEPersistentShortcut);
|
||||||
|
with TSynEdit.Create(nil) do
|
||||||
|
try
|
||||||
|
// note cant use a TCESynMemo because it'd be added to the EntitiesConnector
|
||||||
|
SetDefaultKeystrokes;
|
||||||
|
for i:= 0 to Keystrokes.Count-1 do
|
||||||
|
begin
|
||||||
|
shc := TCEPersistentShortcut(fShortCuts.Add);
|
||||||
|
shc.actionName:= EditorCommandToCodeString(Keystrokes.Items[i].Command);
|
||||||
|
shc.shortcut := Keystrokes.Items[i].ShortCut;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
free;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCEEditorOptionsBase.Destroy;
|
destructor TCEEditorOptionsBase.Destroy;
|
||||||
begin
|
begin
|
||||||
fFont.Free;
|
fFont.Free;
|
||||||
fSelCol.Free;
|
fSelCol.Free;
|
||||||
|
fShortCuts.Free;
|
||||||
fFoldedColor.Free;
|
fFoldedColor.Free;
|
||||||
fMouseLinkColor.Free;
|
fMouseLinkColor.Free;
|
||||||
fBracketMatchColor.Free;
|
fBracketMatchColor.Free;
|
||||||
|
|
@ -197,11 +226,17 @@ begin
|
||||||
mouseOptions := srcopt.mouseOptions;
|
mouseOptions := srcopt.mouseOptions;
|
||||||
rightEdge := srcopt.rightEdge;
|
rightEdge := srcopt.rightEdge;
|
||||||
rightEdgeColor := srcopt.rightEdgeColor;
|
rightEdgeColor := srcopt.rightEdgeColor;
|
||||||
|
fShortCuts.Assign(srcopt.fShortCuts);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCEEditorOptionsBase.setShortcuts(aValue: TCollection);
|
||||||
|
begin
|
||||||
|
fShortCuts.Assign(aValue);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCEEditorOptionsBase.setFont(aValue: TFont);
|
procedure TCEEditorOptionsBase.setFont(aValue: TFont);
|
||||||
begin
|
begin
|
||||||
fFont.Assign(aValue);
|
fFont.Assign(aValue);
|
||||||
|
|
@ -264,7 +299,6 @@ begin
|
||||||
D2Syn.Assign(fD2Syn);
|
D2Syn.Assign(fD2Syn);
|
||||||
TxtSyn.Assign(fTxtSyn);
|
TxtSyn.Assign(fTxtSyn);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$ENDREGION}
|
{$ENDREGION}
|
||||||
|
|
||||||
{$REGION ICEMultiDocObserver ----------------------------------------------------}
|
{$REGION ICEMultiDocObserver ----------------------------------------------------}
|
||||||
|
|
@ -284,7 +318,44 @@ end;
|
||||||
procedure TCEEditorOptions.docClosing(aDoc: TCESynMemo);
|
procedure TCEEditorOptions.docClosing(aDoc: TCESynMemo);
|
||||||
begin
|
begin
|
||||||
end;
|
end;
|
||||||
|
{$ENDREGION}
|
||||||
|
|
||||||
|
{$REGION ICEEDitableShortcut ---------------------------------------------------}
|
||||||
|
function TCEEditorOptions.scedWantFirst: boolean;
|
||||||
|
begin
|
||||||
|
result := fShortCuts.Count > 0;
|
||||||
|
fShortcutCount := 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCEEditorOptions.scedWantNext(out category, identifier: string; out aShortcut: TShortcut): boolean;
|
||||||
|
var
|
||||||
|
shrct: TCEPersistentShortcut;
|
||||||
|
begin
|
||||||
|
shrct := TCEPersistentShortcut(fShortCuts.Items[fShortcutCount]);
|
||||||
|
category := 'Code editor';
|
||||||
|
identifier:= shrct.actionName;
|
||||||
|
aShortcut := shrct.shortcut;
|
||||||
|
//
|
||||||
|
fShortcutCount += 1;
|
||||||
|
result := fShortcutCount < fShortCuts.Count;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCEEditorOptions.scedSendItem(const category, identifier: string; aShortcut: TShortcut);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
shc: TCEPersistentShortcut;
|
||||||
|
begin
|
||||||
|
if category <> 'Code editor' then exit;
|
||||||
|
//
|
||||||
|
for i:= 0 to fShortCuts.Count-1 do
|
||||||
|
begin
|
||||||
|
shc := TCEPersistentShortcut(fShortCuts.Items[i]);
|
||||||
|
if shc.actionName <> identifier then
|
||||||
|
continue;
|
||||||
|
shc.shortcut:= aShortcut;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
{$ENDREGION}
|
{$ENDREGION}
|
||||||
|
|
||||||
{$REGION ICEEditableOptions ----------------------------------------------------}
|
{$REGION ICEEditableOptions ----------------------------------------------------}
|
||||||
|
|
@ -344,6 +415,10 @@ begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCEEditorOptions.applyChangeToEditor(anEditor: TCESynMemo);
|
procedure TCEEditorOptions.applyChangeToEditor(anEditor: TCESynMemo);
|
||||||
|
var
|
||||||
|
i, j: Integer;
|
||||||
|
shc: TCEPersistentShortcut;
|
||||||
|
kst: TSynEditKeyStroke;
|
||||||
begin
|
begin
|
||||||
anEditor.defaultFontSize := font.Size;
|
anEditor.defaultFontSize := font.Size;
|
||||||
anEditor.Font.Assign(font);
|
anEditor.Font.Assign(font);
|
||||||
|
|
@ -361,6 +436,25 @@ begin
|
||||||
anEditor.Color := background;
|
anEditor.Color := background;
|
||||||
anEditor.RightEdge := rightEdge;
|
anEditor.RightEdge := rightEdge;
|
||||||
anEditor.RightEdgeColor := rightEdgeColor;
|
anEditor.RightEdgeColor := rightEdgeColor;
|
||||||
|
for i := 0 to anEditor.Keystrokes.Count-1 do
|
||||||
|
begin
|
||||||
|
kst := anEditor.Keystrokes.Items[i];
|
||||||
|
for j := 0 to fShortCuts.Count-1 do
|
||||||
|
begin
|
||||||
|
shc := TCEPersistentShortcut(fShortCuts.Items[j]);
|
||||||
|
if shc.actionName = EditorCommandToCodeString(kst.Command) then
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
kst.ShortCut := shc.shortcut;
|
||||||
|
except
|
||||||
|
//TODO-cfeaure: manage shortcuts conflicts
|
||||||
|
//either here or a the shortcut editor level
|
||||||
|
// by default and if a conflict exists synedit will raise an exception here.
|
||||||
|
end;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$ENDREGION}
|
{$ENDREGION}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue