Solved

Customize Application ShortCuts

Posted on 2002-06-04
6
200 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:xenfung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 7054958
Hello

  Take a look at this article, it may help you

http://www.blong.com/Conferences/BorCon2002/Actions/2110.htm
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7054989
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.Actions[I]);
       with lvActions.Items.Add do
       begin
         Data:=tmpAct;
         ImageIndex:=tmpAct.ImageIndex;
         Caption:=tmpAct.Caption;
         SubItems.Add(tmpAct.Hint);
       end;
     end;
end;

procedure TForm1.btnClearClick(Sender: 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:=ImageIndex;
           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.Caption;
     txtHint.Text:=Item.SubItems[0];
     udImage.Position:=Item.ImageIndex;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     udImage.Max:=Images.Count-1;
end;

procedure TForm1.btnApplyClick(Sender: TObject);
begin
     if lvActions.Selected = nil then exit;
     with lvActions.Selected do
     begin
       Caption:=txtCaption.Text;
       SubItems[0]:=txtHint.Text;
       ImageIndex:=udImage.Position;
     end;
end;

procedure TForm1.btnRestoreClick(Sender: TObject);
begin
     lvActionsSelectItem(lvActions, lvActions.Selected, true);
end;

end.



0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7054999
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Accepted Solution

by:
Lee_Nover earned 500 total points
ID: 7055029
ok shortcuts added :)

the source from the above link or this :

-------------------------------------------------------


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;
    hkShortCut: THotKey;
    Label4: TLabel;
    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.Actions[I]);
       with lvActions.Items.Add do
       begin
         Data:=tmpAct;
         ImageIndex:=tmpAct.ImageIndex;
         Caption:=tmpAct.Caption;
         SubItems.Add(tmpAct.Hint);
         SubItems.Add(IntToStr(tmpAct.ShortCut));
       end;
     end;
end;

procedure TForm1.btnClearClick(Sender: 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:=ImageIndex;
           tmpAct.Caption:=Caption;
           tmpAct.Hint:=SubItems[0];
           tmpAct.ShortCut:=StrToIntDef(SubItems[1], 0);
         end;
end;

procedure TForm1.lvActionsSelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
begin
     if Item = nil then exit;
     with TAction(Item.Data) do
     begin
       txtCaption.Text:=Caption;
       txtHint.Text:=Hint;
       udImage.Position:=ImageIndex;
       hkShortCut.HotKey:=ShortCut;
     end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     udImage.Max:=Images.Count-1;
end;

procedure TForm1.btnApplyClick(Sender: TObject);
begin
     if lvActions.Selected = nil then exit;
     with lvActions.Selected do
     begin
       Caption:=txtCaption.Text;
       SubItems[0]:=txtHint.Text;
       SubItems[1]:=IntToStr(hkShortCut.HotKey);
       ImageIndex:=udImage.Position;
     end;
end;

procedure TForm1.btnRestoreClick(Sender: TObject);
begin
     lvActionsSelectItem(lvActions, lvActions.Selected, true);
end;

end.
0
 

Author Comment

by:xenfung
ID: 7059549
Lee,

Nice code! BTW, how did you get such a custom URL like this?

http://lee.nover.has.his.evilside.org
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7059874
tnx, from a 'friend' :)
traded some hosts hehe
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mobile Keyboard covers the display of the TMemo 3 102
Drag & Drop... Data from one grid to another 2 47
Delphi: making a BW image transparent 10 88
Firemonkey Queue list 1 25
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question