Interactive Ink

Answered

Button "undo" don't cancel the last action when loading the package

The package is saved correctly. But when loading the package, the "undo" button does not cancel the last action

 

class Paint2ViewController: UIViewController{
    
    weak var editorViewController: EditorViewController!
    
    //MARK: - Outlets
    @IBOutlet weak var drawContainer: UIView!

    deinit {
    }
    
    @IBAction func test(_ sender: Any) {
        saveContent()
        print("save package")

    }
    
    // MARK: - Configuring
    
    func configureEditorViewController() {
        editorViewController = children.first as? EditorViewController
        if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
            if appDelegate.engine == nil {
                let alert = UIAlertController(title: "Certificate error", message: appDelegate.engineErrorMessage, preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_: UIAlertAction) -> Void in
                    exit(1)
                }))
                present(alert, animated: true, completion: nil)
                return
            }
            editorViewController.engine = appDelegate.engine
        }
        editorViewController.inputMode = .forcePen
    }
    
    var part: IINKContentPart!
    var package: IINKContentPackage!
    var history = [String]()
    let packageName = "test.iink"
    
    override func viewDidLoad(){
        configureEditorViewController()
        openContent()
    }
    
    func loadHistory() {
        do  {
            if let history =  try part.metadata?.stringArray(forKey: packageName){
                self.history = history
            }
        } catch {
            print("Error get history " + error.localizedDescription)
        }
    }
    
    func saveHistory() {
        var parameterSet: IINKParameterSet
        parameterSet = part.metadata!
        do {
            try parameterSet.setStringArray(self.history, forKey: packageName)
            part.metadata = parameterSet
            print(try parameterSet.stringArray(forKey: packageName))
        } catch {
            print("Error save history " + error.localizedDescription)
        }
    }
    
    func saveContent() {
        saveHistory()
        do {
            try package.save()
        } catch {
            print("error save " + error.localizedDescription)
        }
    }
    
    func openContent() {
        
        let urlwithExtension = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("test", isDirectory: false).appendingPathExtension("iink")
        
        //let fullPath = urlwithExtension.absoluteString.replacingOccurrences(of: "file://", with: "")
        
        let fullPath = FileManager.default.pathForFile(inDocumentDirectory: packageName) + ".iink"
        
        if FileManager.default.fileExists(atPath: fullPath) {
            do {
                if let engine = (UIApplication.shared.delegate as? AppDelegate)?.engine {
                    package = try engine.openPackage(fullPath.decomposedStringWithCanonicalMapping)
                    part = try package.getPartAt(0)
                    editorViewController.editor.part = part
                    loadHistory()
                }
            } catch {
                print("Error open " + error.localizedDescription)
            }
            
        } else {
            do {
                if let engine = (UIApplication.shared.delegate as? AppDelegate)?.engine {
                    package = try engine.createPackage(fullPath.decomposedStringWithCanonicalMapping)
                    try package.createPart("Math")
                    history = []
                }
                part = try package.getPartAt(0)
                editorViewController.editor.part = part
            } catch {
                print("Error while creating package : " + error.localizedDescription)
            }
        }
    }

    
    @IBAction func undo(_ sender: Any){
        print(editorViewController.editor.possibleUndoCount)
        editorViewController.editor.undo()
    }
}

 


Best Answer

Dear Максим Шаптала,

thank you for contacting us and your question.

Currently when saving, closing and re-opening a package, the history is lost. Therefore, a call to undo will not be able to restore "the history before close".

This behavior is similar to the one that is found in most common applications (e.g. MS office).

Best regards,

Olivier

1 Comment

Answer

Dear Максим Шаптала,

thank you for contacting us and your question.

Currently when saving, closing and re-opening a package, the history is lost. Therefore, a call to undo will not be able to restore "the history before close".

This behavior is similar to the one that is found in most common applications (e.g. MS office).

Best regards,

Olivier


1 person likes this