xenfung
asked on
Customize Application ShortCuts
I have an ActionList with my various commands and their corresponding ShortCuts.
I am trying to make a dialog that loads all the actions from the ActionList (along with their associated images, captions, and shortcuts) into a ListView so that the user can customize the shortcuts for each action.
Can anyone show me an example of how to do this? I am using Delphi 4/5 if that matters.
Thanks
I am trying to make a dialog that loads all the actions from the ActionList (along with their associated images, captions, and shortcuts) into a ListView so that the user can customize the shortcuts for each action.
Can anyone show me an example of how to do this? I am using Delphi 4/5 if that matters.
Thanks
this seemed fun so i did it :)
here's the unit code .. it won't be hard to reproduce
but if you wish you can get the whole project at:
http://lee.nover.has.his.evilside.org/isapi/pas2html.dll/pas2html?File=/delphi/Projects/ActionListEditor
zipped source in the Backups dir
------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, ActnList, ComCtrls, ImgList;
type
TForm1 = class(TForm)
Images: TImageList;
lvActions: TListView;
actsMain: TActionList;
btnLoad: TButton;
btnClear: TButton;
btnSave: TButton;
pmMain: TPopupMenu;
txtCaption: TEdit;
Label1: TLabel;
txtHint: TEdit;
Label2: TLabel;
txtImage: TEdit;
Label3: TLabel;
Action1: TAction;
Action2: TAction;
Action3: TAction;
Action4: TAction;
Action5: TAction;
btnApply: TButton;
udImage: TUpDown;
Action11: TMenuItem;
Action21: TMenuItem;
Action31: TMenuItem;
Action41: TMenuItem;
Action51: TMenuItem;
StatusBar1: TStatusBar;
btnRestore: TButton;
procedure btnLoadClick(Sender: TObject);
procedure btnClearClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure lvActionsSelectItem(Sender : TObject; Item: TListItem;
Selected: Boolean);
procedure FormCreate(Sender: TObject);
procedure btnApplyClick(Sender: TObject);
procedure btnRestoreClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnLoadClick(Sender : TObject);
var I: Integer;
tmpAct: TAction;
begin
lvActions.Clear;
for I:=0 to actsMain.ActionCount-1 do
begin
tmpAct:=TAction(actsMain.A ctions[I]) ;
with lvActions.Items.Add do
begin
Data:=tmpAct;
ImageIndex:=tmpAct.ImageIn dex;
Caption:=tmpAct.Caption;
SubItems.Add(tmpAct.Hint);
end;
end;
end;
procedure TForm1.btnClearClick(Sende r: TObject);
begin
lvActions.Clear;
end;
procedure TForm1.btnSaveClick(Sender : TObject);
var I: Integer;
tmpAct: TAction;
begin
for I:=0 to lvActions.Items.Count-1 do
with lvActions.Items[I] do
begin
tmpAct:=TAction(Data);
tmpAct.ImageIndex:=ImageIn dex;
tmpAct.Caption:=Caption;
tmpAct.Hint:=SubItems[0];
end;
end;
procedure TForm1.lvActionsSelectItem (Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
if Item = nil then exit;
txtCaption.Text:=Item.Capt ion;
txtHint.Text:=Item.SubItem s[0];
udImage.Position:=Item.Ima geIndex;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
udImage.Max:=Images.Count- 1;
end;
procedure TForm1.btnApplyClick(Sende r: TObject);
begin
if lvActions.Selected = nil then exit;
with lvActions.Selected do
begin
Caption:=txtCaption.Text;
SubItems[0]:=txtHint.Text;
ImageIndex:=udImage.Positi on;
end;
end;
procedure TForm1.btnRestoreClick(Sen der: TObject);
begin
lvActionsSelectItem(lvActi ons, lvActions.Selected, true);
end;
end.
here's the unit code .. it won't be hard to reproduce
but if you wish you can get the whole project at:
http://lee.nover.has.his.evilside.org/isapi/pas2html.dll/pas2html?File=/delphi/Projects/ActionListEditor
zipped source in the Backups dir
------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, ActnList, ComCtrls, ImgList;
type
TForm1 = class(TForm)
Images: TImageList;
lvActions: TListView;
actsMain: TActionList;
btnLoad: TButton;
btnClear: TButton;
btnSave: TButton;
pmMain: TPopupMenu;
txtCaption: TEdit;
Label1: TLabel;
txtHint: TEdit;
Label2: TLabel;
txtImage: TEdit;
Label3: TLabel;
Action1: TAction;
Action2: TAction;
Action3: TAction;
Action4: TAction;
Action5: TAction;
btnApply: TButton;
udImage: TUpDown;
Action11: TMenuItem;
Action21: TMenuItem;
Action31: TMenuItem;
Action41: TMenuItem;
Action51: TMenuItem;
StatusBar1: TStatusBar;
btnRestore: TButton;
procedure btnLoadClick(Sender: TObject);
procedure btnClearClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure lvActionsSelectItem(Sender
Selected: Boolean);
procedure FormCreate(Sender: TObject);
procedure btnApplyClick(Sender: TObject);
procedure btnRestoreClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnLoadClick(Sender
var I: Integer;
tmpAct: TAction;
begin
lvActions.Clear;
for I:=0 to actsMain.ActionCount-1 do
begin
tmpAct:=TAction(actsMain.A
with lvActions.Items.Add do
begin
Data:=tmpAct;
ImageIndex:=tmpAct.ImageIn
Caption:=tmpAct.Caption;
SubItems.Add(tmpAct.Hint);
end;
end;
end;
procedure TForm1.btnClearClick(Sende
begin
lvActions.Clear;
end;
procedure TForm1.btnSaveClick(Sender
var I: Integer;
tmpAct: TAction;
begin
for I:=0 to lvActions.Items.Count-1 do
with lvActions.Items[I] do
begin
tmpAct:=TAction(Data);
tmpAct.ImageIndex:=ImageIn
tmpAct.Caption:=Caption;
tmpAct.Hint:=SubItems[0];
end;
end;
procedure TForm1.lvActionsSelectItem
Selected: Boolean);
begin
if Item = nil then exit;
txtCaption.Text:=Item.Capt
txtHint.Text:=Item.SubItem
udImage.Position:=Item.Ima
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
udImage.Max:=Images.Count-
end;
procedure TForm1.btnApplyClick(Sende
begin
if lvActions.Selected = nil then exit;
with lvActions.Selected do
begin
Caption:=txtCaption.Text;
SubItems[0]:=txtHint.Text;
ImageIndex:=udImage.Positi
end;
end;
procedure TForm1.btnRestoreClick(Sen
begin
lvActionsSelectItem(lvActi
end;
end.
ohh I forgot about Shortcut :)
well that's easy .. simply put a THotKey on the form and use it like any other edits in the example
well that's easy .. simply put a THotKey on the form and use it like any other edits in the example
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Lee,
Nice code! BTW, how did you get such a custom URL like this?
http://lee.nover.has.his.evilside.org
Nice code! BTW, how did you get such a custom URL like this?
http://lee.nover.has.his.evilside.org
tnx, from a 'friend' :)
traded some hosts hehe
traded some hosts hehe
Take a look at this article, it may help you
http://www.blong.com/Conferences/BorCon2002/Actions/2110.htm