mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: convert to Kotlin
This commit is contained in:
@@ -13,125 +13,91 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.diff.impl;
|
||||
package com.intellij.diff.impl
|
||||
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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 java.util.*
|
||||
|
||||
@State(
|
||||
name = "DiffSettings",
|
||||
storages = @Storage(DiffUtil.DIFF_CONFIG)
|
||||
storages = arrayOf(Storage(value = DiffUtil.DIFF_CONFIG))
|
||||
)
|
||||
public class DiffSettingsHolder implements PersistentStateComponent<DiffSettingsHolder.State> {
|
||||
public static final Key<DiffSettings> KEY = Key.create("DiffSettings");
|
||||
class DiffSettingsHolder : PersistentStateComponent<DiffSettingsHolder.State> {
|
||||
companion object {
|
||||
@JvmField val KEY: Key<DiffSettings> = Key.create("DiffSettings")
|
||||
|
||||
private static class SharedSettings {
|
||||
public boolean GO_TO_NEXT_FILE_ON_NEXT_DIFFERENCE = true;
|
||||
}
|
||||
|
||||
private static class PlaceSettings {
|
||||
@NotNull public List<String> DIFF_TOOLS_ORDER = new ArrayList<>();
|
||||
public boolean SYNC_BINARY_EDITOR_SETTINGS = true;
|
||||
}
|
||||
|
||||
public static class DiffSettings {
|
||||
@NotNull public SharedSettings SHARED_SETTINGS = new SharedSettings();
|
||||
@NotNull public PlaceSettings PLACE_SETTINGS = new PlaceSettings();
|
||||
|
||||
public DiffSettings() {
|
||||
}
|
||||
|
||||
public DiffSettings(@NotNull SharedSettings SHARED_SETTINGS,
|
||||
@NotNull PlaceSettings PLACE_SETTINGS) {
|
||||
this.SHARED_SETTINGS = SHARED_SETTINGS;
|
||||
this.PLACE_SETTINGS = PLACE_SETTINGS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getDiffToolsOrder() {
|
||||
return PLACE_SETTINGS.DIFF_TOOLS_ORDER;
|
||||
}
|
||||
|
||||
public void setDiffToolsOrder(@NotNull List<String> order) {
|
||||
PLACE_SETTINGS.DIFF_TOOLS_ORDER = order;
|
||||
}
|
||||
|
||||
public boolean isGoToNextFileOnNextDifference() {
|
||||
return SHARED_SETTINGS.GO_TO_NEXT_FILE_ON_NEXT_DIFFERENCE;
|
||||
}
|
||||
|
||||
public void setGoToNextFileOnNextDifference(boolean value) {
|
||||
SHARED_SETTINGS.GO_TO_NEXT_FILE_ON_NEXT_DIFFERENCE = value;
|
||||
}
|
||||
|
||||
public boolean isSyncBinaryEditorSettings() {
|
||||
return PLACE_SETTINGS.SYNC_BINARY_EDITOR_SETTINGS;
|
||||
}
|
||||
|
||||
public void setSyncBinaryEditorSettings(boolean value) {
|
||||
PLACE_SETTINGS.SYNC_BINARY_EDITOR_SETTINGS= value;
|
||||
}
|
||||
|
||||
//
|
||||
// Impl
|
||||
//
|
||||
|
||||
@NotNull
|
||||
public static DiffSettings getSettings() {
|
||||
return getSettings(null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static DiffSettings getSettings(@Nullable String place) {
|
||||
return getInstance().getSettings(place);
|
||||
@JvmStatic
|
||||
fun getInstance(): DiffSettingsHolder {
|
||||
return ServiceManager.getService(DiffSettingsHolder::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DiffSettings 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 DiffSettings(myState.SHARED_SETTINGS, placeSettings);
|
||||
internal class SharedSettings {
|
||||
var GO_TO_NEXT_FILE_ON_NEXT_DIFFERENCE: Boolean = true
|
||||
}
|
||||
|
||||
public static class State {
|
||||
internal class PlaceSettings {
|
||||
var DIFF_TOOLS_ORDER: List<String> = ArrayList()
|
||||
var SYNC_BINARY_EDITOR_SETTINGS: Boolean = true
|
||||
}
|
||||
|
||||
class DiffSettings internal constructor(val SHARED_SETTINGS: SharedSettings,
|
||||
val PLACE_SETTINGS: PlaceSettings) {
|
||||
constructor() : this(SharedSettings(), PlaceSettings())
|
||||
|
||||
var diffToolsOrder: List<String>
|
||||
get() = PLACE_SETTINGS.DIFF_TOOLS_ORDER
|
||||
set(order) { PLACE_SETTINGS.DIFF_TOOLS_ORDER = order }
|
||||
|
||||
var isGoToNextFileOnNextDifference: Boolean
|
||||
get() = SHARED_SETTINGS.GO_TO_NEXT_FILE_ON_NEXT_DIFFERENCE
|
||||
set(value) { SHARED_SETTINGS.GO_TO_NEXT_FILE_ON_NEXT_DIFFERENCE = value }
|
||||
|
||||
var isSyncBinaryEditorSettings: Boolean
|
||||
get() = PLACE_SETTINGS.SYNC_BINARY_EDITOR_SETTINGS
|
||||
set(value) { PLACE_SETTINGS.SYNC_BINARY_EDITOR_SETTINGS = value }
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getSettings(): DiffSettings {
|
||||
return getSettings(null)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getSettings(place: String?): DiffSettings {
|
||||
return getInstance().getSettings(place)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getSettings(place: String?): DiffSettings {
|
||||
val placeKey = place ?: DiffPlaces.DEFAULT
|
||||
val placeSettings = myState.PLACES_MAP.getOrPut(placeKey, { PlaceSettings() })
|
||||
return DiffSettings(myState.SHARED_SETTINGS, placeSettings)
|
||||
}
|
||||
|
||||
|
||||
class State {
|
||||
@MapAnnotation(surroundWithTag = false, surroundKeyWithTag = false, surroundValueWithTag = false)
|
||||
public Map<String, PlaceSettings> PLACES_MAP = new HashMap<>();
|
||||
public SharedSettings SHARED_SETTINGS = new SharedSettings();
|
||||
internal var PLACES_MAP: MutableMap<String, PlaceSettings> = HashMap()
|
||||
internal var SHARED_SETTINGS = SharedSettings()
|
||||
}
|
||||
|
||||
private State myState = new State();
|
||||
private var myState : State = State()
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public State getState() {
|
||||
return myState;
|
||||
override fun getState(): State {
|
||||
return myState
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(State state) {
|
||||
myState = state;
|
||||
}
|
||||
|
||||
public static DiffSettingsHolder getInstance() {
|
||||
return ServiceManager.getService(DiffSettingsHolder.class);
|
||||
override fun loadState(state: State) {
|
||||
myState = state
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user