如何改变Delphi的快捷键

stiwin 2002-09-14 06:20:31
加精
(本文在零点天地 http://myzeroworld.yeah.net 和 SJTU BBS Delphi 板同时发表,转载请保持文章完整性和相关连接)

如果说Delphi的IDE有什么优势的话,那么我想就是它本身就是由Delphi编写而成,因此我们能定制Delphi的IDE环境,通过Delphi的ToolsAPI的Com接口。

下面这个例子使用IOTAKeyboardBinding接口,实现对快捷键的重新绑定,相关的接口定义见ToolsAPI.pas。源码很简单,相信你一看就懂。该例子用来修改与中文环境冲突的Code Completion得快捷键,改成Ctrl+Alt+Shift+P和Ctrl+Alt+Shift+O,如果你遇上什么问题,请写信给我。

//EagleBufferList.pas,2002.5.24

{
Pan Ying,Zero Studio
All Right Reserved.

The Demo show how to change Delphi's Key Binding,just in Delphi
press Ctrl+Alt+Shift+P to use Code Completion.You can contact me by
sending e-mail to me (panying@sina.com)

Some code from Delphi's ToolsAPI Demo.

Attention:
This software is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
for any damages arising from the use of this software.

This unit is free to use but the origin of this software
must not be misrepresented, you must not claim that you
wrote the original software.

Feel free to use this component in your product including
commercial applications.

If You alert this component's code to make it better,
please remember to tell me about it , let's to make it better
together.

This attention may not be removed or altered from any source
distribution.

Feedback:
E-Mail: panying@sina.com
HomePage:http://myzeroworld.yeah.net

Version 1.1
Remove some useless code.
Version 1.0
Initial Version.
}

unit EagleBufferList;

interface

procedure Register;

implementation

uses Windows, Classes, SysUtils,Menus, ToolsAPI, Controls ;

type
TBufferList = class(TNotifierObject, IUnknown, IOTANotifier,
IOTAKeyboardBinding)
function GetBindingType: TBindingType;
function GetDisplayName: string;
function GetName: string;
procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices);
protected
procedure CodeCompletion(const Context: IOTAKeyContext; KeyCode: TShortcut;
var BindingResult: TKeyBindingResult);
end;

resourcestring
sBufferList = 'Eagle''s Buffer List';

//register this key binding
procedure Register;
begin
(BorlandIDEServices as IOTAKeyBoardServices).AddKeyboardBinding(TBufferList.Create);
end;

{ TBufferList }


//the code to bind key
procedure TBufferList.BindKeyboard(const BindingServices: IOTAKeyBindingServices);
begin
BindingServices.AddKeyBinding([ShortCut(Ord('P'), [ssShift, ssCtrl, ssAlt])], CodeCompletion, Pointer(csCodeList or csManual));
BindingServices.AddKeyBinding([ShortCut(Ord('O'), [ssShift, ssCtrl, ssAlt])], CodeCompletion, Pointer(csParamList or csManual));
end;

//do code completion
procedure TBufferList.CodeCompletion(const Context: IOTAKeyContext;
KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
begin

(Context.EditBuffer.TopView as IOTAEditActions).CodeCompletion(Byte(Context.Context));
BindingResult := krHandled;

end;

function TBufferList.GetBindingType: TBindingType;
begin
Result := btPartial;
end;

function TBufferList.GetDisplayName: string;
begin
Result := sBufferList;
end;

function TBufferList.GetName: string;
begin
Result := 'EagleKing.BufferList'; //do not localize
end;

end.

如果你对组件或者向导编写感兴趣,到CNPack( http://cnpack.yeah.net )来看看。
...全文
818 38 打赏 收藏 转发到动态 举报
写回复
用AI写文章
38 条回复
切换为时间正序
请发表友善的回复…
发表回复
lvluogang 2002-09-22
  • 打赏
  • 举报
回复
谢谢,好好学习!!!
DelUser 2002-09-19
  • 打赏
  • 举报
回复
太需要关注了up,up,再up!
shmilyjiujiu 2002-09-19
  • 打赏
  • 举报
回复
POPOPOPOIPIPIP
好贴子啊!
daniel007 2002-09-18
  • 打赏
  • 举报
回复
cnPack得主页在哪里啊?
cool_afei 2002-09-18
  • 打赏
  • 举报
回复
gz
popmailzjw 2002-09-18
  • 打赏
  • 举报
回复
请问一个菜问题:cnPack上有一个coolctls.exe的控件,请问怎样注册? 谢谢
alian1974 2002-09-18
  • 打赏
  • 举报
回复
Mark
RobinHZ 2002-09-17
  • 打赏
  • 举报
回复
收藏
jianlinlong 2002-09-17
  • 打赏
  • 举报
回复
up
man8888 2002-09-17
  • 打赏
  • 举报
回复
简单的打开文件专家(向导,Expert)代码,可当专家模板用:
安装方法:Component\Install components\选择此文件\OK
然后看Help菜单下多出了个项,看到了么?:) (Delphi5 enterprise compile test)
unit u_FileOpenExpert;

interface

uses
Dialogs, WIndows, ExptIntf;

type
TFileOpenExpert = class(TIExpert)
public
{ Expert UI strings }
function GetName: string; override;
function GetAuthor: string; override;
function GetComment: string; override;
function GetPage: string; override;
function GetGlyph: HICON; override;
function GetStyle: TExpertStyle; override;
function GetState: TExpertState; override;
function GetIDString: string; override;
function GetMenuText: string; override;

{ Launch the Expert }
procedure Execute; override;
end;

procedure Register;

implementation

{ TFileOpenExpert }

procedure TFileOpenExpert.Execute;
begin
with TOpenDialog.Create(nil) do
begin
try
Title:= GetName;
Filter:= '所有文件(*.*)|*.*';
if Execute then
begin
//其他工程已经打开,则先保存并关闭
ToolServices.SaveProject;
ToolServices.CloseProject;
//打开工程
ToolServices.OpenProject(FileName);
end;
finally
Free;
end;
end;
end;

{$IFDEF WIN32}
function TFileOpenExpert.GetAuthor: string;
begin
Result:= 'TZhuang';
end;
{$ENDIF}

function TFileOpenExpert.GetComment: string;
begin
Result:= '';
end;

{$IFDEF WIN32}
function TFileOpenExpert.GetGlyph: HICON;
{$ELSE}
function TFileOpenExpert.GetGlyph: HBitmap;
{$ENDIF}
begin
Result:= 0;
end;

function TFileOpenExpert.GetIDString: string;
begin
Result:= 'BOCO.TFileOpenExpert';
end;

function TFileOpenExpert.GetMenuText: string;
begin
Result:= '&File Open Expert...';
end;

function TFileOpenExpert.GetName: string;
begin
Result:= 'File Open Expert';
end;

{$IFDEF WIN32}
function TFileOpenExpert.GetPage: string;
begin
Result:= '';
end;
{$ENDIF}

function TFileOpenExpert.GetState: TExpertState;
begin
Result:= [esEnabled];
end;

function TFileOpenExpert.GetStyle: TExpertStyle;
begin
Result:= esStandard;
end;

procedure Register;
begin
RegisterLibraryExpert(TFileOpenExpert.Create);
end;

end.
sdlxj 2002-09-17
  • 打赏
  • 举报
回复
珍藏
lulu99 2002-09-16
  • 打赏
  • 举报
回复
up
Crystal_Boy 2002-09-16
  • 打赏
  • 举报
回复
up
easetoo 2002-09-16
  • 打赏
  • 举报
回复
文章不全,提议很好!
ocool 2002-09-16
  • 打赏
  • 举报
回复
up
neilwq 2002-09-16
  • 打赏
  • 举报
回复
mark
zhaoyong886 2002-09-16
  • 打赏
  • 举报
回复
我 不 知道怎么
god263 2002-09-16
  • 打赏
  • 举报
回复
太多了, 好难看哦
up
PeakChen 2002-09-16
  • 打赏
  • 举报
回复
up
chao_jian 2002-09-16
  • 打赏
  • 举报
回复
收藏!
加载更多回复(18)

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧