                 do {
                     try strongSelf.revert(toContentsOf: fileURL, ofType: fileType)
                 } catch let error {
-                    if let window = self?.windowForSheet {
-                        strongSelf.presentError(error, modalFor: window, delegate: nil, didPresent: nil, contextInfo: nil)
-                    } else {
-                        strongSelf.presentError(error)
-                    }
+                    strongSelf.presentErrorAsSheet(error)
                 }
             }
         }

        }
    }
    
    
    /// perform didRecoverBlock after recovering presented error
    private var recoverBlock: ((Bool) -> Void)? = nil
    func didPresentErrorWithRecovery(didRecover: Bool, block: UnsafeMutableRawPointer) {
        
        self.recoverBlock?(didRecover)
        self.recoverBlock = nil
    }
    
}



// MARK: - Protocol

extension Document: Editable {
    
    var textView: NSTextView? {
        
        return self.viewController?.focusedTextView
    }
}



        let encodingName = String.localizedName(of: encoding, withUTF8BOM: withUTF8BOM)
        
        // ask lossy
        if askLossy {
            guard self.string.canBeConverted(to: encoding) else {
                let error = EncodingError(kind: .lossyEncodingConversion, encoding: encoding, withUTF8BOM: withUTF8BOM, attempter: self)
                self.presentErrorAsSheet(error)
                return false
            }
        }
        
        // register undo
