gpt4 book ai didi

eclipse-plugin - Eclipse 在 View 关闭时调用 ViewPart saveState

转载 作者:行者123 更新时间:2023-12-04 04:24:55 25 4
gpt4 key购买 nike

我有一个 Eclipse 插件,它使用的 View 扩展了 ViewPart . ViewPart有一个 saveState需要 IMemento 的方法.

我将我的代码添加到 saveState和相应的 init方法和它的工作原理。不幸的是,saveState仅在整个工作区关闭时才调用。我的观点不是很重要,我可以期望它一直打开。因此,如果 saveState 会很酷将在 View 关闭时调用。

我发现一个 View 部分监听器可以对 View 关闭使用react,但我没有得到的是 IMemento来自。我从哪里获得在工作区关闭时使用的纪念品对象?或者我必须在哪里存储我自己的纪念品对象才能让 View 部分在 init 中使用它方法是否(重新)打开 View ?

@Override
public void saveState(IMemento memento) {
super.saveState(memento);
memento = memento.createChild(MEMENTO_GUI_STATE);
memento.putBoolean(MEMENTO_IS_FLAT, !isHierarchicalModeActive());
memento.putBoolean(MEMENTO_IS_CATEGORY_MODE_ACTIVE, comboViewer.isVisible());
}

这是我的 saveState - 我可以告诉我的 View 以某种方式告诉每次 View 关闭时调用它吗?

最佳答案

看看这个question在 Eclipse 常见问题解答中:

Storing view state is done in two commons ways, depending on whether you want to store settings between workbench sessions or across invocations of your view. The first of these facilities is found directly on IViewPart. When the workbench is shut down, the method saveState is called on all open views.

Another mechanism for persisting view state is the JFace IDialogSettings facility. The advantage of dialog settings over the view save/init mechanism is that you can control when settings are persisted. The saveState method is called only if your view is open when the workbench shuts down, so it is not useful for storing view state when the view is closed by the user. Dialog settings, on the other hand, can be changed and persisted whenever you want.



转到另一个 question或到 Eclipse documentation本身为设置机制。

关于eclipse-plugin - Eclipse 在 View 关闭时调用 ViewPart saveState,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9472279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com