[英]Eclipse RCP: save a perspective programmatically
我需要自定義RCP應用程序和透視圖的用法。 特別是,我想提供一個自定義菜單項,該菜單項可讓用戶保存當前透視圖,但不顯示內置對話框:
因此,我不想使用默認的月食方式來注冊“保存透視圖”操作並將其放入菜單中。 也就是說,我不希望這樣做:
@Override
protected void makeActions(IWorkbenchWindow window)
{
// ...
register(ActionFactory.SAVE_PERSPECTIVE.create(window));
// ...
}
@Override
protected void fillMenuBar(IMenuManager menuBar)
{
// ...
windowMenu.add(getAction(ActionFactory.SAVE_PERSPECTIVE.getId()));
// ...
}
因此,如果我編寫了一個自定義Action,那么在那需要做什么來保存當前的透視圖?
這很簡單。 在自定義動作中,我執行以下操作來保存透視圖:
IWorkbenchPage page = window.getActivePage();
IPerspectiveRegistry perspectiveRegistry = window.getWorkbench()
.getPerspectiveRegistry();
IPerspectiveDescriptor personalPerspectiveDescriptor = perspectiveRegistry
.findPerspectiveWithId(perspectiveId);
if (page != null && personalPerspectiveDescriptor != null) {
// ... other stuff like different confirm dialogs
page.savePerspectiveAs(personalPerspectiveDescriptor);
}
一個很好的示例,說明如何使用透視圖來讓用戶自定義其布局而不顯示太多內置透視圖功能:
http://www.subshell.com/en/subshell/blog/article-Eclipse-RCP-Change-Your-Perspective100.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.