mirror of https://gitlab.com/basile.b/dexed.git
added support for catching new shortcut value
This commit is contained in:
parent
4bcb2c6dcf
commit
8bd0bcae68
|
@ -1,28 +1,28 @@
|
||||||
object CEShortcutEditor: TCEShortcutEditor
|
object CEShortcutEditor: TCEShortcutEditor
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 471
|
Height = 463
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 431
|
Width = 424
|
||||||
ClientHeight = 471
|
ClientHeight = 463
|
||||||
ClientWidth = 431
|
ClientWidth = 424
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
DesignLeft = 796
|
DesignLeft = 796
|
||||||
DesignTop = 213
|
DesignTop = 213
|
||||||
object Panel1: TPanel
|
object Panel1: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 471
|
Height = 463
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 431
|
Width = 424
|
||||||
Align = alClient
|
Align = alClient
|
||||||
BevelOuter = bvNone
|
BevelOuter = bvNone
|
||||||
ClientHeight = 471
|
ClientHeight = 463
|
||||||
ClientWidth = 431
|
ClientWidth = 424
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
object fltItems: TTreeFilterEdit
|
object fltItems: TTreeFilterEdit
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 23
|
Height = 23
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 407
|
Width = 400
|
||||||
ButtonWidth = 23
|
ButtonWidth = 23
|
||||||
NumGlyphs = 1
|
NumGlyphs = 1
|
||||||
Align = alCustom
|
Align = alCustom
|
||||||
|
@ -33,24 +33,64 @@ object CEShortcutEditor: TCEShortcutEditor
|
||||||
end
|
end
|
||||||
object tree: TTreeView
|
object tree: TTreeView
|
||||||
Left = 1
|
Left = 1
|
||||||
Height = 389
|
Height = 400
|
||||||
Top = 28
|
Top = 28
|
||||||
Width = 430
|
Width = 423
|
||||||
Align = alCustom
|
Align = alCustom
|
||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
|
AutoExpand = True
|
||||||
DefaultItemHeight = 18
|
DefaultItemHeight = 18
|
||||||
|
HideSelection = False
|
||||||
|
ReadOnly = True
|
||||||
ScrollBars = ssAutoBoth
|
ScrollBars = ssAutoBoth
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
|
OnSelectionChanged = treeSelectionChanged
|
||||||
|
Options = [tvoAutoExpand, tvoAutoItemHeight, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw]
|
||||||
end
|
end
|
||||||
object Panel2: TPanel
|
object Panel2: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 50
|
Height = 31
|
||||||
Top = 421
|
Top = 432
|
||||||
Width = 431
|
Width = 424
|
||||||
Align = alBottom
|
Align = alBottom
|
||||||
BevelOuter = bvNone
|
BevelOuter = bvNone
|
||||||
Caption = 'Controls to edit the shortcut...'
|
ClientHeight = 31
|
||||||
|
ClientWidth = 424
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
|
object schrtText: TStaticText
|
||||||
|
Left = 4
|
||||||
|
Height = 23
|
||||||
|
Top = 4
|
||||||
|
Width = 277
|
||||||
|
Align = alClient
|
||||||
|
Alignment = taCenter
|
||||||
|
BorderSpacing.Around = 4
|
||||||
|
BorderStyle = sbsSunken
|
||||||
|
TabOrder = 0
|
||||||
|
end
|
||||||
|
object shcCatch: TEdit
|
||||||
|
Left = 312
|
||||||
|
Height = 25
|
||||||
|
Top = 3
|
||||||
|
Width = 112
|
||||||
|
Align = alRight
|
||||||
|
BorderSpacing.Top = 3
|
||||||
|
BorderSpacing.Bottom = 3
|
||||||
|
Enabled = False
|
||||||
|
OnExit = shcCatchExit
|
||||||
|
OnKeyDown = LabeledEdit1KeyDown
|
||||||
|
OnMouseLeave = shcCatchMouseLeave
|
||||||
|
TabOrder = 1
|
||||||
|
end
|
||||||
|
object btnActivate: TSpeedButton
|
||||||
|
Left = 285
|
||||||
|
Height = 23
|
||||||
|
Top = 4
|
||||||
|
Width = 23
|
||||||
|
Align = alRight
|
||||||
|
BorderSpacing.Around = 4
|
||||||
|
OnClick = btnActivateClick
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,8 +5,8 @@ unit ce_shortcutseditor;
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, TreeFilterEdit, Forms, Controls, Menus,
|
Classes, SysUtils, FileUtil, TreeFilterEdit, Forms, Controls, Menus, Graphics,
|
||||||
ExtCtrls, LCLProc, ComCtrls,
|
ExtCtrls, LCLProc, ComCtrls, StdCtrls, LMessages, Buttons, LCLType,
|
||||||
ce_observer, ce_interfaces, ce_common, ce_writableComponent;
|
ce_observer, ce_interfaces, ce_common, ce_writableComponent;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -41,11 +41,21 @@ type
|
||||||
property item[index: Integer]: TShortcutItem read getShortcut; default;
|
property item[index: Integer]: TShortcutItem read getShortcut; default;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCEShortcutEditor }
|
||||||
|
|
||||||
TCEShortcutEditor = class(TFrame, ICEEditableOptions)
|
TCEShortcutEditor = class(TFrame, ICEEditableOptions)
|
||||||
|
shcCatch: TEdit;
|
||||||
Panel1: TPanel;
|
Panel1: TPanel;
|
||||||
fltItems: TTreeFilterEdit;
|
fltItems: TTreeFilterEdit;
|
||||||
Panel2: TPanel;
|
Panel2: TPanel;
|
||||||
|
schrtText: TStaticText;
|
||||||
|
btnActivate: TSpeedButton;
|
||||||
tree: TTreeView;
|
tree: TTreeView;
|
||||||
|
procedure btnActivateClick(Sender: TObject);
|
||||||
|
procedure LabeledEdit1KeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
|
||||||
|
procedure shcCatchExit(Sender: TObject);
|
||||||
|
procedure shcCatchMouseLeave(Sender: TObject);
|
||||||
|
procedure treeSelectionChanged(Sender: TObject);
|
||||||
private
|
private
|
||||||
fObservers: TCEEditableShortCutSubject;
|
fObservers: TCEEditableShortCutSubject;
|
||||||
fShortcuts: TShortCutCollection;
|
fShortcuts: TShortCutCollection;
|
||||||
|
@ -58,6 +68,9 @@ type
|
||||||
//
|
//
|
||||||
function findCategory(const aName: string; aData: Pointer): TTreeNode;
|
function findCategory(const aName: string; aData: Pointer): TTreeNode;
|
||||||
procedure updateFromObservers;
|
procedure updateFromObservers;
|
||||||
|
procedure updateEditCtrls;
|
||||||
|
protected
|
||||||
|
procedure UpdateShowing; override;
|
||||||
public
|
public
|
||||||
constructor create(TheOwner: TComponent); override;
|
constructor create(TheOwner: TComponent); override;
|
||||||
destructor destroy; override;
|
destructor destroy; override;
|
||||||
|
@ -139,6 +152,22 @@ begin
|
||||||
fObservers.Free;
|
fObservers.Free;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCEShortcutEditor.UpdateShowing;
|
||||||
|
var
|
||||||
|
png : TPortableNetworkGraphic;
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
if not visible then exit;
|
||||||
|
//
|
||||||
|
png := TPortableNetworkGraphic.Create;
|
||||||
|
try
|
||||||
|
png.LoadFromLazarusResource('keyboard_pencil');
|
||||||
|
btnActivate.Glyph.Assign(png);
|
||||||
|
finally
|
||||||
|
png.free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
{$ENDREGION}
|
{$ENDREGION}
|
||||||
|
|
||||||
{$REGION ICEEditableOptions ----------------------------------------------------}
|
{$REGION ICEEditableOptions ----------------------------------------------------}
|
||||||
|
@ -165,6 +194,57 @@ end;
|
||||||
{$ENDREGION}
|
{$ENDREGION}
|
||||||
|
|
||||||
{$REGION shortcut editor things ------------------------------------------------}
|
{$REGION shortcut editor things ------------------------------------------------}
|
||||||
|
procedure TCEShortcutEditor.treeSelectionChanged(Sender: TObject);
|
||||||
|
begin
|
||||||
|
updateEditCtrls;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCEShortcutEditor.shcCatchExit(Sender: TObject);
|
||||||
|
begin
|
||||||
|
shcCatch.Enabled := false;
|
||||||
|
updateEditCtrls;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCEShortcutEditor.shcCatchMouseLeave(Sender: TObject);
|
||||||
|
begin
|
||||||
|
shcCatch.Enabled := false;
|
||||||
|
updateEditCtrls;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCEShortcutEditor.btnActivateClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
if tree.Selected = nil then exit;
|
||||||
|
if tree.Selected.Level = 0 then exit;
|
||||||
|
if tree.Selected.Data = nil then exit;
|
||||||
|
//
|
||||||
|
shcCatch.Enabled := not shcCatch.Enabled;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCEShortcutEditor.LabeledEdit1KeyDown(Sender: TObject; var Key: Word;
|
||||||
|
Shift: TShiftState);
|
||||||
|
begin
|
||||||
|
if tree.Selected = nil then exit;
|
||||||
|
if tree.Selected.Level = 0 then exit;
|
||||||
|
if tree.Selected.Data = nil then exit;
|
||||||
|
//
|
||||||
|
if Key = VK_RETURN then shcCatch.Enabled := false
|
||||||
|
else TShortcutItem(tree.Selected.Data).data := Shortcut(Key, Shift);
|
||||||
|
//
|
||||||
|
updateEditCtrls;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCEShortcutEditor.updateEditCtrls;
|
||||||
|
begin
|
||||||
|
schrtText.Caption := '';
|
||||||
|
//
|
||||||
|
if tree.Selected = nil then exit;
|
||||||
|
if tree.Selected.Level = 0 then exit;
|
||||||
|
if tree.Selected.Data = nil then exit;
|
||||||
|
//
|
||||||
|
schrtText.Caption := TShortcutItem(tree.Selected.Data).combination;
|
||||||
|
shcCatch.Text:= '';
|
||||||
|
end;
|
||||||
|
|
||||||
function TCEShortcutEditor.findCategory(const aName: string; aData: Pointer): TTreeNode;
|
function TCEShortcutEditor.findCategory(const aName: string; aData: Pointer): TTreeNode;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
@ -197,11 +277,13 @@ begin
|
||||||
if obs.scedWantFirst then while obs.scedWantNext(cat, idt, sht) do
|
if obs.scedWantFirst then while obs.scedWantNext(cat, idt, sht) do
|
||||||
begin
|
begin
|
||||||
// root category
|
// root category
|
||||||
|
if cat = '' then
|
||||||
|
continue;
|
||||||
|
if idt = '' then
|
||||||
|
continue;
|
||||||
prt := findCategory(cat, obs);
|
prt := findCategory(cat, obs);
|
||||||
if prt = nil then
|
if prt = nil then
|
||||||
prt := tree.Items.AddObject(nil, cat, obs);
|
prt := tree.Items.AddObject(nil, cat, obs);
|
||||||
if idt = '' then
|
|
||||||
continue;
|
|
||||||
// item as child
|
// item as child
|
||||||
itm := TShortcutItem(fShortcuts.items.Add);
|
itm := TShortcutItem(fShortcuts.items.Add);
|
||||||
itm.identifier := idt;
|
itm.identifier := idt;
|
||||||
|
|
Loading…
Reference in New Issue