added support for catching new shortcut value

This commit is contained in:
Basile Burg 2015-02-21 13:59:41 +01:00
parent 4bcb2c6dcf
commit 8bd0bcae68
2 changed files with 141 additions and 19 deletions

View File

@ -1,28 +1,28 @@
object CEShortcutEditor: TCEShortcutEditor
Left = 0
Height = 471
Height = 463
Top = 0
Width = 431
ClientHeight = 471
ClientWidth = 431
Width = 424
ClientHeight = 463
ClientWidth = 424
TabOrder = 0
DesignLeft = 796
DesignTop = 213
object Panel1: TPanel
Left = 0
Height = 471
Height = 463
Top = 0
Width = 431
Width = 424
Align = alClient
BevelOuter = bvNone
ClientHeight = 471
ClientWidth = 431
ClientHeight = 463
ClientWidth = 424
TabOrder = 0
object fltItems: TTreeFilterEdit
Left = 0
Height = 23
Top = 0
Width = 407
Width = 400
ButtonWidth = 23
NumGlyphs = 1
Align = alCustom
@ -33,24 +33,64 @@ object CEShortcutEditor: TCEShortcutEditor
end
object tree: TTreeView
Left = 1
Height = 389
Height = 400
Top = 28
Width = 430
Width = 423
Align = alCustom
Anchors = [akTop, akLeft, akRight, akBottom]
AutoExpand = True
DefaultItemHeight = 18
HideSelection = False
ReadOnly = True
ScrollBars = ssAutoBoth
TabOrder = 1
OnSelectionChanged = treeSelectionChanged
Options = [tvoAutoExpand, tvoAutoItemHeight, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw]
end
object Panel2: TPanel
Left = 0
Height = 50
Top = 421
Width = 431
Height = 31
Top = 432
Width = 424
Align = alBottom
BevelOuter = bvNone
Caption = 'Controls to edit the shortcut...'
ClientHeight = 31
ClientWidth = 424
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

View File

@ -5,8 +5,8 @@ unit ce_shortcutseditor;
interface
uses
Classes, SysUtils, FileUtil, TreeFilterEdit, Forms, Controls, Menus,
ExtCtrls, LCLProc, ComCtrls,
Classes, SysUtils, FileUtil, TreeFilterEdit, Forms, Controls, Menus, Graphics,
ExtCtrls, LCLProc, ComCtrls, StdCtrls, LMessages, Buttons, LCLType,
ce_observer, ce_interfaces, ce_common, ce_writableComponent;
type
@ -41,11 +41,21 @@ type
property item[index: Integer]: TShortcutItem read getShortcut; default;
end;
{ TCEShortcutEditor }
TCEShortcutEditor = class(TFrame, ICEEditableOptions)
shcCatch: TEdit;
Panel1: TPanel;
fltItems: TTreeFilterEdit;
Panel2: TPanel;
schrtText: TStaticText;
btnActivate: TSpeedButton;
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
fObservers: TCEEditableShortCutSubject;
fShortcuts: TShortCutCollection;
@ -58,6 +68,9 @@ type
//
function findCategory(const aName: string; aData: Pointer): TTreeNode;
procedure updateFromObservers;
procedure updateEditCtrls;
protected
procedure UpdateShowing; override;
public
constructor create(TheOwner: TComponent); override;
destructor destroy; override;
@ -139,6 +152,22 @@ begin
fObservers.Free;
inherited;
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}
{$REGION ICEEditableOptions ----------------------------------------------------}
@ -165,6 +194,57 @@ end;
{$ENDREGION}
{$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;
var
i: Integer;
@ -197,11 +277,13 @@ begin
if obs.scedWantFirst then while obs.scedWantNext(cat, idt, sht) do
begin
// root category
if cat = '' then
continue;
if idt = '' then
continue;
prt := findCategory(cat, obs);
if prt = nil then
prt := tree.Items.AddObject(nil, cat, obs);
if idt = '' then
continue;
// item as child
itm := TShortcutItem(fShortcuts.items.Add);
itm.identifier := idt;