如何代码改变Delphi的快捷键
2008-05-21 13:07
483 查看
如果说Delphi的IDE有什么优势的话,那么我想就是它本身就是由Delphi编写而成,因此我们能定制Delphi的IDE环境,通过Delphi的ToolsAPI的Com接口。
下面这个例子使用IOTAKeyboardBinding接口,实现对快捷键的重新绑定,相关的接口定义见ToolsAPI.pas。源码很简单,相信你一看就懂。该例子用来修改与中文环境冲突的Code Completion得快捷键,改成Ctrl+Alt+Shift+P和Ctrl+Alt+Shift+O
1 //EagleBufferList.pas,2002.5.24
2
3 {
4 Pan Ying,Zero Studio
5 All Right Reserved.
6
7 The Demo show how to change Delphi's Key Binding,just in Delphi
8 press Ctrl+Alt+Shift+P to use Code Completion.You can contact me by
9 sending e-mail to me (panying@sina.com)
10
11 Some code from Delphi's ToolsAPI Demo.
12
13 Attention:
14 This software is provided 'as-is', without any express or
15 implied warranty. In no event will the author be held liable
16 for any damages arising from the use of this software.
17
18 This unit is free to use but the origin of this software
19 must not be misrepresented, you must not claim that you
20 wrote the original software.
21
22 Feel free to use this component in your product including
23 commercial applications.
24
25 If You alert this component's code to make it better,
26 please remember to tell me about it , let's to make it better
27 together.
28
29 This attention may not be removed or altered from any source
30 distribution.
31
32 Feedback:
33 E-Mail: panying@sina.com
34 HomePage:http://myzeroworld.yeah.net
35
36 Version 1.1
37 Remove some useless code.
38 Version 1.0
39 Initial Version.
40 }
41
42 unit EagleBufferList;
43
44 interface
45
46 procedure Register;
47
48 implementation
49
50 uses Windows, Classes, SysUtils,Menus, ToolsAPI, Controls ;
51
52 type
53 TBufferList = class(TNotifierObject, IUnknown, IOTANotifier,
54 IOTAKeyboardBinding)
55 function GetBindingType: TBindingType;
56 function GetDisplayName: string;
57 function GetName: string;
58 procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices);
59 protected
60 procedure CodeCompletion(const Context: IOTAKeyContext; KeyCode: TShortcut;
61 var BindingResult: TKeyBindingResult);
62 end;
63
64 resourcestring
65 sBufferList = 'Eagle''s Buffer List';
66
67 //register this key binding
68 procedure Register;
69 begin
70 (BorlandIDEServices as IOTAKeyBoardServices).AddKeyboardBinding(TBufferList.Create);
71 end;
72
73 { TBufferList }
74
75
76 //the code to bind key
77 procedure TBufferList.BindKeyboard(const BindingServices: IOTAKeyBindingServices);
78 begin
79 BindingServices.AddKeyBinding([ShortCut(Ord('P'), [ssShift, ssCtrl, ssAlt])], CodeCompletion, Pointer(csCodeList or csManual));
80 BindingServices.AddKeyBinding([ShortCut(Ord('O'), [ssShift, ssCtrl, ssAlt])], CodeCompletion, Pointer(csParamList or csManual));
81 end;
82
83 //do code completion
84 procedure TBufferList.CodeCompletion(const Context: IOTAKeyContext;
85 KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
86 begin
87
88 (Context.EditBuffer.TopView as IOTAEditActions).CodeCompletion(Byte(Context.Context));
89 BindingResult := krHandled;
90
91 end;
92
93 function TBufferList.GetBindingType: TBindingType;
94 begin
95 Result := btPartial;
96 end;
97
98 function TBufferList.GetDisplayName: string;
99 begin
100 Result := sBufferList;
101 end;
102
103 function TBufferList.GetName: string;
104 begin
105 Result := 'EagleKing.BufferList'; //do not localize
106 end;
107
108 end.
109
下面这个例子使用IOTAKeyboardBinding接口,实现对快捷键的重新绑定,相关的接口定义见ToolsAPI.pas。源码很简单,相信你一看就懂。该例子用来修改与中文环境冲突的Code Completion得快捷键,改成Ctrl+Alt+Shift+P和Ctrl+Alt+Shift+O
1 //EagleBufferList.pas,2002.5.24
2
3 {
4 Pan Ying,Zero Studio
5 All Right Reserved.
6
7 The Demo show how to change Delphi's Key Binding,just in Delphi
8 press Ctrl+Alt+Shift+P to use Code Completion.You can contact me by
9 sending e-mail to me (panying@sina.com)
10
11 Some code from Delphi's ToolsAPI Demo.
12
13 Attention:
14 This software is provided 'as-is', without any express or
15 implied warranty. In no event will the author be held liable
16 for any damages arising from the use of this software.
17
18 This unit is free to use but the origin of this software
19 must not be misrepresented, you must not claim that you
20 wrote the original software.
21
22 Feel free to use this component in your product including
23 commercial applications.
24
25 If You alert this component's code to make it better,
26 please remember to tell me about it , let's to make it better
27 together.
28
29 This attention may not be removed or altered from any source
30 distribution.
31
32 Feedback:
33 E-Mail: panying@sina.com
34 HomePage:http://myzeroworld.yeah.net
35
36 Version 1.1
37 Remove some useless code.
38 Version 1.0
39 Initial Version.
40 }
41
42 unit EagleBufferList;
43
44 interface
45
46 procedure Register;
47
48 implementation
49
50 uses Windows, Classes, SysUtils,Menus, ToolsAPI, Controls ;
51
52 type
53 TBufferList = class(TNotifierObject, IUnknown, IOTANotifier,
54 IOTAKeyboardBinding)
55 function GetBindingType: TBindingType;
56 function GetDisplayName: string;
57 function GetName: string;
58 procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices);
59 protected
60 procedure CodeCompletion(const Context: IOTAKeyContext; KeyCode: TShortcut;
61 var BindingResult: TKeyBindingResult);
62 end;
63
64 resourcestring
65 sBufferList = 'Eagle''s Buffer List';
66
67 //register this key binding
68 procedure Register;
69 begin
70 (BorlandIDEServices as IOTAKeyBoardServices).AddKeyboardBinding(TBufferList.Create);
71 end;
72
73 { TBufferList }
74
75
76 //the code to bind key
77 procedure TBufferList.BindKeyboard(const BindingServices: IOTAKeyBindingServices);
78 begin
79 BindingServices.AddKeyBinding([ShortCut(Ord('P'), [ssShift, ssCtrl, ssAlt])], CodeCompletion, Pointer(csCodeList or csManual));
80 BindingServices.AddKeyBinding([ShortCut(Ord('O'), [ssShift, ssCtrl, ssAlt])], CodeCompletion, Pointer(csParamList or csManual));
81 end;
82
83 //do code completion
84 procedure TBufferList.CodeCompletion(const Context: IOTAKeyContext;
85 KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
86 begin
87
88 (Context.EditBuffer.TopView as IOTAEditActions).CodeCompletion(Byte(Context.Context));
89 BindingResult := krHandled;
90
91 end;
92
93 function TBufferList.GetBindingType: TBindingType;
94 begin
95 Result := btPartial;
96 end;
97
98 function TBufferList.GetDisplayName: string;
99 begin
100 Result := sBufferList;
101 end;
102
103 function TBufferList.GetName: string;
104 begin
105 Result := 'EagleKing.BufferList'; //do not localize
106 end;
107
108 end.
109
相关文章推荐
- eclipse的注释字体大小如何修改?不改变代码的字体
- 如何改变EntityFramework的代码生成策略
- Source Insight如何改变代码显示大小
- 在Android java代码中如何改变文件的权限 -
- 如何在代码中动态改变radioButton的图片位置?
- 如何在delphi 中画带箭头的直线(改自网上一位论坛版主的vb代码)
- 请问各位如何用Delphi控制U盘的安全拔出????已经有源代码,但是不知道如何控制指定的U盘
- delphi 修改代码补全的快捷键(由Ctrl+Space 改为 Ctrl + alt + Space)
- delphi中如何使得listbox里为txt后缀的行改变颜色(使listbox根据行内容改变颜色)
- Source Insight如何改变代码显示大小
- 如何在程序中执行动态生成的Delphi代码
- Android程序如何在代码中改变图片原有的颜色
- 【转】Visual Studio快捷键大全||vs改变字体显示||visual assist丰富代码颜色
- 4.28如何在代码中改变控件在布局中的位置
- delphi如何获得一段代码执行消耗的时间
- delphi 如何设置快捷键之2
- 客户端的javascript改变了asp.net webform页面控件的值,后台代码中如何获取修改后的值。
- [置顶] android studio 如何进行格式化代码 快捷键必备
- 如何在Delphi里面利用Word的VBA代码进行一些总结
- 如何在程序中执行动态生成的Delphi代码