Skip to content

Commit

Permalink
Remove usages of deprecated API (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
sczerwinski authored Nov 10, 2024
1 parent 3cda60a commit 3c1373b
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 34 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
### Removed

### Fixed
- Remove usages of internal API
- Remove usages of deprecated API

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ abstract class BaseSplitEditorProvider(
TextEditorWithPreview.MyFileEditorState(
readSplitLayoutState(sourceElement),
readTextEditorState(sourceElement, project, file),
readPreviewEditorState(sourceElement, project, file)
readPreviewEditorState(sourceElement, project, file),
readVerticalState(sourceElement)
)

private fun readSplitLayoutState(sourceElement: Element): TextEditorWithPreview.Layout? =
Expand All @@ -77,6 +78,9 @@ abstract class BaseSplitEditorProvider(
sourceElement.getChild(PREVIEW_EDITOR)
?.let { childElement -> previewEditorProvider.readState(childElement, project, file) }

private fun readVerticalState(sourceElement: Element): Boolean =
sourceElement.getAttribute(IS_VERTICAL)?.value?.toBoolean() ?: false

/**
* Serializes state of split editor.
*/
Expand All @@ -85,6 +89,7 @@ abstract class BaseSplitEditorProvider(
writeSplitLayoutState(splitEditorState.splitLayout, targetElement)
writeTextEditorState(splitEditorState.firstState, project, targetElement)
writePreviewEditorState(splitEditorState.secondState, project, targetElement)
writeVerticalState(splitEditorState.isVerticalSplit, targetElement)
}

private fun writeSplitLayoutState(layout: TextEditorWithPreview.Layout?, targetElement: Element) {
Expand All @@ -107,9 +112,14 @@ abstract class BaseSplitEditorProvider(
}
}

private fun writeVerticalState(isVertical: Boolean, targetElement: Element) {
targetElement.setAttribute(IS_VERTICAL, isVertical.toString())
}

companion object {
private const val TEXT_EDITOR = "text_editor"
private const val PREVIEW_EDITOR = "preview_editor"
private const val SPLIT_LAYOUT = "split_layout"
private const val IS_VERTICAL = "is_vertical"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class EditorToolbarHeader(
add(it, constraints(index = 1, anchor = GridBagConstraints.EAST, fill = GridBagConstraints.NONE))
}

leftActionToolbar?.updateActionsImmediately()
rightActionToolbar?.updateActionsImmediately()
leftActionToolbar?.updateActionsAsync()
rightActionToolbar?.updateActionsAsync()
}

private fun constraints(index: Int, anchor: Int, fill: Int): GridBagConstraints =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.PsiManager
import com.intellij.psi.PsiTreeChangeAdapter
import com.intellij.psi.PsiTreeChangeEvent
import com.intellij.refactoring.suggested.startOffset
import com.intellij.ui.dsl.builder.panel
import it.czerwinski.intellij.common.editor.BaseSplitEditor
import it.czerwinski.intellij.wavefront.WavefrontObjBundle
Expand Down Expand Up @@ -109,7 +108,7 @@ class MtlMaterialComponent(
val materialAtCaret = myMaterialComboBoxModel.findItemAtOffset(caretModel.offset)
if (selectedMaterial != null && selectedMaterial != materialAtCaret) {
invokeLater {
caretModel.moveToOffset(selectedMaterial.startOffset)
caretModel.moveToOffset(selectedMaterial.textRange.startOffset)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@ class MtlMaterialPreviewComponent(
set(value) {
field = value
updateScene()
myActionToolbar.updateActionsImmediately()
myActionToolbar.updateActionsAsync()
}

var shadingMethod: ShadingMethod = ShadingMethod.MTL_DEFAULT
set(value) {
field = value
updateScene()
myActionToolbar.updateActionsImmediately()
myActionToolbar.updateActionsAsync()
}

var environment: PBREnvironment = PBREnvironment.DEFAULT
set(value) {
field = value
updateScene()
myActionToolbar.updateActionsImmediately()
myActionToolbar.updateActionsAsync()
}

var isCroppingTextures: Boolean = ObjPreviewSettingsState.DEFAULT_CROP_TEXTURES
set(value) {
field = value
updateScene()
myActionToolbar.updateActionsImmediately()
myActionToolbar.updateActionsAsync()
}

var previewSceneConfig: PreviewSceneConfig = PreviewSceneConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ObjPreviewComponent(
set(value) {
field = value
updateScene()
myActionToolbar.updateActionsImmediately()
myActionToolbar.updateActionsAsync()
}

var freeFormCurveResolution: Int = ObjPreviewSettingsState.DEFAULT_FREE_FORM_CURVE_RESOLUTION
Expand All @@ -105,14 +105,14 @@ class ObjPreviewComponent(
set(value) {
field = value
updateScene()
myActionToolbar.updateActionsImmediately()
myActionToolbar.updateActionsAsync()
}

var isCroppingTextures: Boolean = ObjPreviewSettingsState.DEFAULT_CROP_TEXTURES
set(value) {
field = value
updateScene()
myActionToolbar.updateActionsImmediately()
myActionToolbar.updateActionsAsync()
}

var upVector: UpVector = UpVector.DEFAULT
Expand All @@ -122,21 +122,21 @@ class ObjPreviewComponent(
oldCameraModel.copy(upVector = upVector)
}
updateScene()
myActionToolbar.updateActionsImmediately()
myActionToolbar.updateActionsAsync()
}

var isShowingAxes: Boolean = ObjPreviewSettingsState.DEFAULT_SHOW_AXES
set(value) {
field = value
updateScene()
myActionToolbar.updateActionsImmediately()
myActionToolbar.updateActionsAsync()
}

var isShowingGrid: Boolean = ObjPreviewSettingsState.DEFAULT_SHOW_GRID
set(value) {
field = value
updateScene()
myActionToolbar.updateActionsImmediately()
myActionToolbar.updateActionsAsync()
}

var previewSceneConfig: PreviewSceneConfig = PreviewSceneConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package it.czerwinski.intellij.wavefront.editor.model

import com.intellij.openapi.application.runReadAction
import com.intellij.psi.PsiElement
import com.intellij.refactoring.suggested.endOffset
import com.intellij.refactoring.suggested.startOffset
import it.czerwinski.intellij.wavefront.lang.psi.MtlMaterial
import it.czerwinski.intellij.wavefront.lang.psi.ObjFace
import it.czerwinski.intellij.wavefront.lang.psi.ObjFreeFormCurve
Expand Down Expand Up @@ -69,7 +67,7 @@ data class GLModel(
return if (indexValue > 0) {
getOrNull(index = indexValue - 1)
} else {
filter { it.endOffset < (index?.startOffset ?: 0) }
filter { it.textRange.endOffset < (index?.textRange?.startOffset ?: 0) }
.reversed()
.getOrNull(index = abs(indexValue) - 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.childrenOfType
import com.intellij.refactoring.suggested.endOffset
import com.intellij.refactoring.suggested.startOffset
import it.czerwinski.intellij.wavefront.lang.psi.MtlCommentBlock
import it.czerwinski.intellij.wavefront.lang.psi.MtlDocumentation
import it.czerwinski.intellij.wavefront.lang.psi.MtlMaterialElement
Expand All @@ -43,18 +41,18 @@ class MtlFoldingBuilder : FoldingBuilderEx(), DumbAware {
private fun buildMtlMaterialElements(root: PsiElement): List<FoldingDescriptor> =
PsiTreeUtil.findChildrenOfType(root, MtlMaterialElement::class.java)
.map { element ->
val startOffset = element.childrenOfType<MtlDocumentation>().singleOrNull()?.endOffset
?: element.startOffset
val endOffset = element.endOffset
val startOffset = element.childrenOfType<MtlDocumentation>().singleOrNull()?.textRange?.endOffset
?: element.textRange.startOffset
val endOffset = element.textRange.endOffset
FoldingDescriptor(element.node, TextRange.create(startOffset, endOffset))
}

private fun buildMtlCommentBlocks(root: PsiElement): List<FoldingDescriptor> =
PsiTreeUtil.findChildrenOfType(root, MtlCommentBlock::class.java)
.filter { commentBlock -> commentBlock.commentLineList.size > 1 }
.map { element ->
val startOffset = element.startOffset
val endOffset = element.startOffset + element.text.trimEnd().length
val startOffset = element.textRange.startOffset
val endOffset = element.textRange.startOffset + element.text.trimEnd().length
FoldingDescriptor(element.node, TextRange.create(startOffset, endOffset))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.childrenOfType
import com.intellij.refactoring.suggested.endOffset
import com.intellij.refactoring.suggested.startOffset
import it.czerwinski.intellij.wavefront.lang.psi.ObjCommentBlock
import it.czerwinski.intellij.wavefront.lang.psi.ObjDocumentation
import it.czerwinski.intellij.wavefront.lang.psi.ObjFreeForm2DCurve
Expand All @@ -49,9 +47,9 @@ class ObjFoldingBuilder : FoldingBuilderEx(), DumbAware {
private fun buildObjGroupingElements(root: PsiElement): List<FoldingDescriptor> =
PsiTreeUtil.findChildrenOfType(root, ObjGroupingElement::class.java)
.map { element ->
val startOffset = element.childrenOfType<ObjDocumentation>().singleOrNull()?.endOffset
?: element.startOffset
val endOffset = element.endOffset
val startOffset = element.childrenOfType<ObjDocumentation>().singleOrNull()?.textRange?.endOffset
?: element.textRange.startOffset
val endOffset = element.textRange.endOffset
FoldingDescriptor(element.node, TextRange.create(startOffset, endOffset))
}

Expand All @@ -69,8 +67,8 @@ class ObjFoldingBuilder : FoldingBuilderEx(), DumbAware {
PsiTreeUtil.findChildrenOfType(root, ObjCommentBlock::class.java)
.filter { commentBlock -> commentBlock.commentLineList.size > 1 }
.map { element ->
val startOffset = element.startOffset
val endOffset = element.startOffset + element.text.trimEnd().length
val startOffset = element.textRange.startOffset
val endOffset = element.textRange.startOffset + element.text.trimEnd().length
FoldingDescriptor(element.node, TextRange.create(startOffset, endOffset))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package it.czerwinski.intellij.wavefront.lang.psi.util

import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.refactoring.suggested.startOffset
import it.czerwinski.intellij.wavefront.lang.psi.ObjFile

val PsiElement.containingObjFile: ObjFile? get() = containingFile as? ObjFile
Expand All @@ -31,5 +30,5 @@ inline fun <reified T : PsiElement> PsiElement.countChildrenOfType(): Int =

inline fun <reified T : PsiElement> PsiElement.countChildrenOfTypeBefore(element: PsiElement): Int =
getChildrenOfType<T>()
.filter { child -> child.startOffset < element.startOffset }
.filter { child -> child.textRange.startOffset < element.textRange.startOffset }
.size

0 comments on commit 3c1373b

Please sign in to comment.