单击 x 时隐藏而不是处置视图部分
我有一个可关闭设置为 true 的视图部分。用户单击 x。我想隐藏视图部分而不是关闭它。这怎么办?
I have a viewpart with closable set to true. The user clicks the x. I want to hide the viewpart rather then close it. how can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是可能的,但是很棘手!
关闭视图实际上从当前角度“隐藏”它。如果该视图未在任何地方显示,则它会被丢弃。
您可以通过向 RCP 应用程序添加两个透视图(包括两个透视图)来检查这一点。现在,关闭透视 A 中的视图不会处理它,因为它在透视 B 中仍然打开。
因此,为了避免处理该视图,您应该确保它包含在另一个透视中。如果您的 RCP 应用程序不使用透视图,您可以使用永远不会显示的“隐藏”透视图,但您可以在其中存储所有“隐藏”视图,这样它们就不会被丢弃。
另请参阅如何在 Eclipse 中关闭 ViewPart? 其中完全相反被要求。
This is possible, but it is tricky!
Closing the view actually 'hides' it from the current perspective. If the view is not shown anywhere, it is disposed.
You can check this by adding two perspectives to your RCP application, including the same view in both. Now, closing your view in perspective A will not dispose of it because it is still open in perspective B.
So to avoid disposing the view, you should just make sure it is included in another perspective. If your RCP application does not use perspectives, you can use a 'hidden' perspective which is never shown, but where you store all 'hidden' views so they are not disposed.
See also How to close a ViewPart in Eclipse? where the exact opposite is requested.
如果您的应用程序是从对 UI 做出贡献的模板创建的,则它应该在预生成的包之一中具有 WorkbenchWindowAdvisor 文件。不确定关闭时隐藏窗口的确切实现细节,但听起来您需要修改应用程序的 WorkbenchWindowAdvisor 实现中的 preWindowShellClose 方法。
If your app was created from a template that makes contributions to the UI it should have a WorkbenchWindowAdvisor file in one of the pregenerated packages. Not sure about the exact implementation details to hide the window on close, but it sounds like you will need to modify the preWindowShellClose method in the WorkbenchWindowAdvisor implementation of your application.
您可以尝试以下操作:
其中
shell
是 Viewpart 的直接父 shell。需要注意的要点是e.doit=false
,它本质上使 close 事件无效。You can try this:
Where
shell
is the immediate parent shell of the Viewpart. Main point to note is thee.doit=false
, which essentially nullifies the close event.据我所知,这一般来说是不可能的。基本上,工作台部分在编辑器或视图“打开”的工作台窗口的所有透视图之间共享。因此,当您切换透视图时,该部分的“复合”部分会简单地调整大小以匹配应显示该部分的新演示网站。
当某个部件因特定视角而关闭时,它会按照您想要的方式隐藏。当该部件对于窗口的所有视角都是隐藏的时,它就会被丢弃。据我所知,没有办法阻止这种情况。
To my knowledge this is not possible in general. Basically a workbench part is shared between all the perspectives of a workbench window that has the editor or view "open". So when you switch perspective the to
Composite
of the part is simply resized to match the new presentation site where the part should be shown.When a part is closed on for a specific perspective, it is hidden as you want it to be. When the part is hidden for all perspectives of the window, it is disposed. And as far as I can see, there are no way to prevent that.