gpt4 book ai didi

java - 如何在 session 之间存储 Eclipse 插件状态?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:02:07 26 4
gpt4 key购买 nike

我正在开发一个 Eclipse 插件。每次在本地保存工作时,该插件都会提醒用户将其工作保存在中央存储库中。

但是,一旦用户成功将他的工作保存在中央存储库上 10 次,他将不再被提醒保存他的工作。

这在单个 session 中效果很好。也就是说,当用户开始在工作区中工作并启用插件时。

但是,如果用户在将他的工作保存到中央存储库后退出工作区9 次,他将继续被提醒 10 次,即从头开始,下次他打开工作区时。

我想知道,是否可以增加一个计数器并将其存储在内存中,以便插件按预期工作。

最佳答案

您可以使用插件设置来存储和检索插件的值。
来自 Eclipse FAQ 的示例:

 private void savePluginSettings() {
// saves plugin preferences at the workspace level
Preferences prefs =
//Platform.getPreferencesService().getRootNode().node(Plugin.PLUGIN_PREFEERENCES_SCOPE).node(MY_PLUGIN_ID);
new InstanceScope().getNode(MY_PLUGIN_ID); // does all the above behind the scenes

prefs.put(KEY1, this.someStr);
prefs.put(KEY2, this.someBool);

try {
// prefs are automatically flushed during a plugin's "super.stop()".
prefs.flush();
} catch(BackingStoreException e) {
//TODO write a real exception handler.
e.printStackTrace();
}
}

private void loadPluginSettings() {
Preferences prefs = new InstanceScope().getNode(MY_PLUGIN_ID);
// you might want to call prefs.sync() if you're worried about others changing your settings
this.someStr = prefs.get(KEY1);
this.someBool= prefs.getBoolean(KEY2);
}

关于java - 如何在 session 之间存储 Eclipse 插件状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4788315/

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