mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
svn: convert to Kotlin
This commit is contained in:
committed by
Aleksey Pivovarov
parent
789074ec25
commit
56d5ebacab
@@ -13,108 +13,83 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.svn.difftool;
|
||||
package org.jetbrains.idea.svn.difftool
|
||||
|
||||
import com.intellij.diff.util.DiffPlaces;
|
||||
import com.intellij.diff.util.DiffUtil;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.xmlb.annotations.MapAnnotation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.intellij.diff.util.DiffPlaces
|
||||
import com.intellij.diff.util.DiffUtil
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.components.State
|
||||
import com.intellij.openapi.components.Storage
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.util.xmlb.annotations.MapAnnotation
|
||||
import java.util.*
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@State(name = "SvnDiffSettings", storages = @Storage(DiffUtil.DIFF_CONFIG))
|
||||
public class SvnDiffSettingsHolder implements PersistentStateComponent<SvnDiffSettingsHolder.State> {
|
||||
public static final Key<SvnDiffSettings> KEY = Key.create("SvnDiffSettings");
|
||||
@State(
|
||||
name = "SvnDiffSettings",
|
||||
storages = arrayOf(Storage(value = DiffUtil.DIFF_CONFIG))
|
||||
)
|
||||
class SvnDiffSettingsHolder : PersistentStateComponent<SvnDiffSettingsHolder.State> {
|
||||
class SharedSettings(
|
||||
)
|
||||
|
||||
private static class SharedSettings {
|
||||
}
|
||||
data class PlaceSettings(
|
||||
var SPLITTER_PROPORTION: Float = 0.9f,
|
||||
var HIDE_PROPERTIES: Boolean = false
|
||||
)
|
||||
|
||||
private static class PlaceSettings {
|
||||
public float SPLITTER_PROPORTION = 0.9f;
|
||||
public boolean HIDE_PROPERTIES = false;
|
||||
}
|
||||
class SvnDiffSettings internal constructor(private val SHARED_SETTINGS: SharedSettings,
|
||||
private val PLACE_SETTINGS: PlaceSettings) {
|
||||
constructor() : this(SharedSettings(), PlaceSettings())
|
||||
|
||||
public static class SvnDiffSettings {
|
||||
@NotNull public SharedSettings SHARED_SETTINGS = new SharedSettings();
|
||||
@NotNull public PlaceSettings PLACE_SETTINGS = new PlaceSettings();
|
||||
var isHideProperties: Boolean
|
||||
get() = PLACE_SETTINGS.HIDE_PROPERTIES
|
||||
set(value) { PLACE_SETTINGS.HIDE_PROPERTIES = value }
|
||||
|
||||
public SvnDiffSettings() {
|
||||
}
|
||||
var splitterProportion: Float
|
||||
get() = PLACE_SETTINGS.SPLITTER_PROPORTION
|
||||
set(value) { PLACE_SETTINGS.SPLITTER_PROPORTION = value }
|
||||
|
||||
public SvnDiffSettings(@NotNull SharedSettings SHARED_SETTINGS,
|
||||
@NotNull PlaceSettings PLACE_SETTINGS) {
|
||||
this.SHARED_SETTINGS = SHARED_SETTINGS;
|
||||
this.PLACE_SETTINGS = PLACE_SETTINGS;
|
||||
}
|
||||
companion object {
|
||||
@JvmField val KEY: Key<SvnDiffSettings> = Key.create("SvnDiffSettings")
|
||||
|
||||
public boolean isHideProperties() {
|
||||
return PLACE_SETTINGS.HIDE_PROPERTIES;
|
||||
}
|
||||
|
||||
public void setHideProperties(boolean value) {
|
||||
PLACE_SETTINGS.HIDE_PROPERTIES = value;
|
||||
}
|
||||
|
||||
public float getSplitterProportion() {
|
||||
return PLACE_SETTINGS.SPLITTER_PROPORTION;
|
||||
}
|
||||
|
||||
public void setSplitterProportion(float value) {
|
||||
PLACE_SETTINGS.SPLITTER_PROPORTION = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Impl
|
||||
//
|
||||
|
||||
@NotNull
|
||||
public static SvnDiffSettings getSettings() {
|
||||
return getSettings(null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SvnDiffSettings getSettings(@Nullable String place) {
|
||||
return getInstance().getSettings(place);
|
||||
@JvmStatic fun getSettings(): SvnDiffSettings = getSettings(null)
|
||||
@JvmStatic fun getSettings(place: String?): SvnDiffSettings = service<SvnDiffSettingsHolder>().getSettings(place)
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SvnDiffSettings getSettings(@Nullable String place) {
|
||||
if (place == null) place = DiffPlaces.DEFAULT;
|
||||
|
||||
PlaceSettings placeSettings = myState.PLACES_MAP.get(place);
|
||||
if (placeSettings == null) {
|
||||
placeSettings = new PlaceSettings();
|
||||
myState.PLACES_MAP.put(place, placeSettings);
|
||||
}
|
||||
return new SvnDiffSettings(myState.SHARED_SETTINGS, placeSettings);
|
||||
fun getSettings(place: String?): SvnDiffSettings {
|
||||
val placeKey = place ?: DiffPlaces.DEFAULT
|
||||
val placeSettings = myState.PLACES_MAP.getOrPut(placeKey, { defaultPlaceSettings(placeKey) })
|
||||
return SvnDiffSettings(myState.SHARED_SETTINGS, placeSettings)
|
||||
}
|
||||
|
||||
public static class State {
|
||||
private fun copyStateWithoutDefaults(): State {
|
||||
val result = State()
|
||||
result.SHARED_SETTINGS = myState.SHARED_SETTINGS
|
||||
result.PLACES_MAP = DiffUtil.trimDefaultValues(myState.PLACES_MAP, { defaultPlaceSettings(it) })
|
||||
return result
|
||||
}
|
||||
|
||||
private fun defaultPlaceSettings(place: String): PlaceSettings {
|
||||
return PlaceSettings()
|
||||
}
|
||||
|
||||
|
||||
class State {
|
||||
@MapAnnotation(surroundWithTag = false, surroundKeyWithTag = false, surroundValueWithTag = false)
|
||||
public Map<String, PlaceSettings> PLACES_MAP = new HashMap<>();
|
||||
public SharedSettings SHARED_SETTINGS = new SharedSettings();
|
||||
var PLACES_MAP: TreeMap<String, PlaceSettings> = TreeMap()
|
||||
var SHARED_SETTINGS = SharedSettings()
|
||||
}
|
||||
|
||||
private State myState = new State();
|
||||
private var myState: State = State()
|
||||
|
||||
@NotNull
|
||||
public State getState() {
|
||||
return myState;
|
||||
override fun getState(): State {
|
||||
return copyStateWithoutDefaults()
|
||||
}
|
||||
|
||||
public void loadState(State state) {
|
||||
myState = state;
|
||||
}
|
||||
|
||||
public static SvnDiffSettingsHolder getInstance() {
|
||||
return ServiceManager.getService(SvnDiffSettingsHolder.class);
|
||||
override fun loadState(state: State) {
|
||||
myState = state
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,10 +234,10 @@ public class SvnDiffViewer implements DiffViewer {
|
||||
|
||||
@NotNull
|
||||
private static SvnDiffSettings initSettings(@NotNull DiffContext context) {
|
||||
SvnDiffSettings settings = context.getUserData(SvnDiffSettingsHolder.KEY);
|
||||
SvnDiffSettings settings = context.getUserData(SvnDiffSettings.KEY);
|
||||
if (settings == null) {
|
||||
settings = SvnDiffSettings.getSettings();
|
||||
context.putUserData(SvnDiffSettingsHolder.KEY, settings);
|
||||
context.putUserData(SvnDiffSettings.KEY, settings);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user