gpt4 book ai didi

java - 菜单项的显示/隐藏取决于plugin.xml中的os.name

转载 作者:行者123 更新时间:2023-11-30 07:25:10 24 4
gpt4 key购买 nike

我在plugin.xml中使用这种代码,以便根据操作系统类型显示/隐藏菜单项:

<menu label="Help">
<command commandId="org.eclipse.ui.help.aboutAction" style="push">
<visibleWhen checkEnabled="false">
<not>
<systemTest property="os.name" value="Mac OS X">
</systemTest>
</not>
</visibleWhen>
</command>
</menu>

问题在于,由 System.getProperty("os.name") 返回的 os.name 似乎不太标准化。它可能取决于操作系统版本,特别是对于 Microsoft Windows。

我想知道是否有最佳实践?

最佳答案

osgi.os 环境变量为操作系统提供了更明确的值。其值在 org.eclipse.osgi.service.environment.Constants 中定义:

public static final String OS_WIN32 = "win32";
public static final String OS_LINUX = "linux";
public static final String OS_AIX = "aix";
public static final String OS_SOLARIS = "solaris";
public static final String OS_HPUX = "hpux";
public static final String OS_QNX = "qnx";
public static final String OS_MACOSX = "macosx";
public static final String OS_EPOC32 = "epoc32";
public static final String OS_OS400 = "os/400";
public static final String OS_OS390 = "os/390";
public static final String OS_ZOS = "z/os";
public static final String OS_UNKNOWN = "unknown";

注意:尽管它的名称(以及 Constants 类中的注释),win32 适用于 32 位和 64 位 Windows。

还有用于处理器架构的osgi.arch:

public static final String ARCH_X86 = "x86";
public static final String ARCH_X86_64 = "x86_64";
public static final String ARCH_PA_RISC = "PA_RISC";
public static final String ARCH_PPC = "ppc";
public static final String ARCH_PPC64 = "ppc64";
public static final String ARCH_SPARC = "sparc";
public static final String ARCH_IA64 = "ia64";
public static final String ARCH_IA64_32 = "ia64_32";

最后osgi.ws给出了窗口系统:

public static final String WS_WIN32 = "win32";
public static final String WS_WPF = "wpf";
public static final String WS_MOTIF = "motif";
public static final String WS_GTK = "gtk";
public static final String WS_PHOTON = "photon";
public static final String WS_CARBON = "carbon";
public static final String WS_COCOA = "cocoa";
public static final String WS_S60 = "s60";
public static final String WS_UNKNOWN = "unknown";

关于java - 菜单项的显示/隐藏取决于plugin.xml中的os.name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36906962/

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