Move SSD session null checks to typed Kotlin
ober
4dfa950fce99a91b454c202442168e118d26b562
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -538,6 +538,7 @@ SsdSession-cells SsdSession-groups SsdSession-ocrWords SsdSession-suppressedGroups SsdSession-ssdArea SsdSession-ssdArea-set! + ssdSessionOrEmpty ssdSessionCellInsideSsdArea ssdSessionGroupInsideSsdArea ssdSessionSuppressedGroupPresent? ssdSessionFindGroupById ssdSessionSelectedGroup @@ -577,6 +578,24 @@ (ocrWords : (MutableList OcrWord)) (suppressedGroups : (MutableList SsdGroup)) (mut ssdArea : (Nullable FloatArray)))) + (def (ssdSessionOrEmpty (session : (Nullable SsdSession))) : SsdSession + (if (nullable-null? session) + (make-SsdSession + "" + "" + "" + "" + (int32 0) + (int32 0) + (int32 0) + (int32 0) + (int32 0) + (mutable-list-empty SsdCell) + (mutable-list-empty SsdGroup) + (mutable-list-empty OcrWord) + (mutable-list-empty SsdGroup) + (nullable-none FloatArray)) + (nullable-get session))) (def (ssdSessionCellInsideSsdArea (session : SsdSession) (cell : SsdCell)) : Bool (if (nullable-null? (SsdSession-ssdArea session)) #t @@ -6802,7 +6821,7 @@ "" " private fun showApproveDialog(rect: FloatArray, detectedIds: List<String>) {" " val session = currentSession" - " if (session == null) {" + " if (sessionMissing(session)) {" " setStatus(\"Selection ignored: truth/detection is still loading\")" " return" " }" @@ -8144,15 +8163,16 @@ " dragEnd = null" " invalidate()" " val sess = session" - " if (sess == null) {" + " if (sessionMissing(sess)) {" " onStatus?.invoke(\"Selection ignored: truth/detection is still loading\")" " return" " }" + " val activeSession = ssdSessionOrEmpty(sess)" " if (selectionRectTooSmall(rect, 4f)) {" " onStatus?.invoke(\"Selection ignored: drag a larger area\")" " return" " }" - " val matching = if (shouldCollectSelectionMatches(snapSelectionToCells)) selectionMatchingCells(sess.cells, rect) else mutableListOf()" + " val matching = if (shouldCollectSelectionMatches(snapSelectionToCells)) selectionMatchingCells(activeSession.cells, rect) else mutableListOf()" " val snapped = if (selectionUsesRawRect(snapSelectionToCells)) {" " rect" " } else if (selectionHasMatches(matching.size)) {"