mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
Facade API for IDE-wide region settings stored in Preferences (IJPL-149501)
GitOrigin-RevId: fb875ad7a2fbf4ee1eafad99329a7d7f0c6b6b48
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7c88ab72c0
commit
7976429135
@@ -652,6 +652,11 @@ f:com.intellij.ide.Prefs
|
||||
- s:putInt(java.lang.String,I):V
|
||||
- s:putLong(java.lang.String,J):V
|
||||
- s:remove(java.lang.String):V
|
||||
f:com.intellij.ide.RegionSettings
|
||||
- s:getCountry():java.lang.String
|
||||
- s:getCountry(java.lang.String):java.lang.String
|
||||
- s:resetCountry():V
|
||||
- s:setCountry(java.lang.String):Z
|
||||
a:com.intellij.ide.RemoteDesktopService
|
||||
- <init>():V
|
||||
- s:getInstance():com.intellij.ide.RemoteDesktopService
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ide;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public final class RegionSettings {
|
||||
private static final Set<String> COUNTRIES = Set.of(Locale.getISOCountries());
|
||||
/**
|
||||
* A Preferences key to access ISO 3166-1 2-digit country code, see also "user.country" system property
|
||||
*/
|
||||
private static final String REGION_CODE_KEY = "JetBrains.regional.country";
|
||||
|
||||
private RegionSettings() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Configured ISO 3166-1 2-digit country code. If not specified, the country code from default locale is returned, see {@link Locale#getCountry()}
|
||||
*/
|
||||
@NotNull
|
||||
public static String getCountry() {
|
||||
return getCountry(Locale.getDefault().getCountry());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param def a value to be returned if country is not explicitly configured.
|
||||
* @return Configured ISO 3166-1 2-digit country code. If not specified, the specified default value is returned
|
||||
*/
|
||||
@Contract("!null -> !null")
|
||||
public static String getCountry(String def) {
|
||||
return Prefs.get(REGION_CODE_KEY, def);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value a 2-letter ISO country code
|
||||
* @return true if the code is successfully set, otherwise false. False value would mean incorrect country value format or an unknown country code
|
||||
*/
|
||||
public static boolean setCountry(@NotNull String value) {
|
||||
value = value.toUpperCase(Locale.ENGLISH);
|
||||
if (COUNTRIES.contains(value)) {
|
||||
Prefs.put(REGION_CODE_KEY, value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear region country setting
|
||||
*/
|
||||
public static void resetCountry() {
|
||||
Prefs.remove(REGION_CODE_KEY);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user