2006-03-05
如何有条件的设置Action
最近做的一个PrettyPro的plugin有这样一个需求:用户在Editor中的右键菜单中有Format和Format Selection两个Action,根据用户是否选择了Editor中的内容而决定其中那个是enable的,哪个是disable的。本来以为实现这个功能要动态的添加action而不是在plugin.xml中声明能做到的,但是苦于找不到动态添加action的方法,就回头去啃plugin.xml的dtd,终于让我找到了~
注意加重斜体的地方,这就是声明当选中1或多个("+")和不选中("!")时是否要enable这个action。我一开始还以为这个东西只能在outline view或browser view中有具体选择项(如:文件)时才能用,没想到在editor里面判断用户是否选中内容的时候也可以用,真是有趣~
1 <extension point="org.eclipse.ui.popupMenus">
2 <viewerContribution id="com.qad.progress.prettypro.ui.editor.PopupMenuContribution" targetID="#TextEditorContext" >
3 <menu label="%editorPopupMenuLabel" path="additions" id="com.qad.progress.prettypro.ui.menu.FormatSubPopupMenu">
4 <separator name="%editorPopupMenuSeparatorName"/>
5 </menu>
6 <action
7 label = "%editorPopupMenuAction1Label"
8 icon = "%editorPopupMenuAction1Icon"
9 class = "com.qad.progress.prettypro.ui.actions.FormatSelectionAction"
10 tooltip = "%editorPopupMenuAction1ToolTip"
11 menubarPath = "com.qad.progress.prettypro.ui.menu.FormatSubPopupMenu/%editorPopupMenuSeparatorName"
12 id = "com.qad.progress.prettypro.ui.actions.editorPopupMenu.FormatSelectionAction"
13 enablesFor="+">
14 </action>
15 <action
16 label="%editorPopupMenuAction2Label"
17 icon="%editorPopupMenuAction2Icon"
18 class="com.qad.progress.prettypro.ui.actions.FormatAction"
19 tooltip="%editorPopupMenuAction2ToolTip"
20 menubarPath="com.qad.progress.prettypro.ui.menu.FormatSubPopupMenu/%editorPopupMenuSeparatorName"
21 id="com.qad.progress.prettypro.ui.actions.editorPopupMenu.FormatAction"
22 enablesFor="!">
23 </action>
24 </viewerContribution>
25 </extension>
2 <viewerContribution id="com.qad.progress.prettypro.ui.editor.PopupMenuContribution" targetID="#TextEditorContext" >
3 <menu label="%editorPopupMenuLabel" path="additions" id="com.qad.progress.prettypro.ui.menu.FormatSubPopupMenu">
4 <separator name="%editorPopupMenuSeparatorName"/>
5 </menu>
6 <action
7 label = "%editorPopupMenuAction1Label"
8 icon = "%editorPopupMenuAction1Icon"
9 class = "com.qad.progress.prettypro.ui.actions.FormatSelectionAction"
10 tooltip = "%editorPopupMenuAction1ToolTip"
11 menubarPath = "com.qad.progress.prettypro.ui.menu.FormatSubPopupMenu/%editorPopupMenuSeparatorName"
12 id = "com.qad.progress.prettypro.ui.actions.editorPopupMenu.FormatSelectionAction"
13 enablesFor="+">
14 </action>
15 <action
16 label="%editorPopupMenuAction2Label"
17 icon="%editorPopupMenuAction2Icon"
18 class="com.qad.progress.prettypro.ui.actions.FormatAction"
19 tooltip="%editorPopupMenuAction2ToolTip"
20 menubarPath="com.qad.progress.prettypro.ui.menu.FormatSubPopupMenu/%editorPopupMenuSeparatorName"
21 id="com.qad.progress.prettypro.ui.actions.editorPopupMenu.FormatAction"
22 enablesFor="!">
23 </action>
24 </viewerContribution>
25 </extension>
注意加重斜体的地方,这就是声明当选中1或多个("+")和不选中("!")时是否要enable这个action。我一开始还以为这个东西只能在outline view或browser view中有具体选择项(如:文件)时才能用,没想到在editor里面判断用户是否选中内容的时候也可以用,真是有趣~
BTW:注意我的两个action action的顺序是Format selection和Format entire file,但是在显示的时候却是反的,不知道是为什么...
- 13:30
- 浏览 (598)
- 评论 (0)
- 分类: Eclipse Plug-in开发
- 相关推荐
发表评论
- 浏览: 142263 次
- 来自: 上海交通大学软件学院

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
另一只眼看Eclipse,所谓 ...
其他不管你学什么都会遇到一定的困惑的,一定的。
-- by mylvan -
我的第一关rake文件
robbin 写道每次当我想操起ruby写rake file的时候,都发现我三行 ...
-- by rubynroll -
我的第一关rake文件
抛出异常的爱 写道rake是建表结构的....不是用来导数据的 不如用exce ...
-- by liusong1111 -
我的第一关rake文件
不知大家有没有这种需求,用户的日常操作中,原始数据可能是其他人员发给他的exce ...
-- by zengyinbo -
使用ruby生成zip文件
如果已经拿到了csv文件,就用OO转成Excel成么? ---非程序员思路
-- by lgn21st






评论排行榜