Krita Source Code Documentation
Loading...
Searching...
No Matches
documentcontroller.py
Go to the documentation of this file.
1"""
2SPDX-FileCopyrightText: 2017 Eliakin Costa <eliakim170@gmail.com>
3
4SPDX-License-Identifier: GPL-2.0-or-later
5"""
6from .document_scripter import document
7
8
9class DocumentController(object):
10
11 def __init__(self):
12 self._activeDocument = None
13
14 @property
15 def activeDocument(self):
16 return self._activeDocument
17
18 def openDocument(self, filePath):
19 if filePath:
20 newDocument = document.Document(filePath)
21 newDocument.open()
22 self._activeDocument = newDocument
23 return newDocument
24
25 def saveDocument(self, data, filePath, save_as=False):
26 """
27 data - data to be written
28 filePath - file path to write data to
29 save_as = boolean, is this call made from save_as functionality. If so, do not compare data
30 against existing document before save.
31 """
32
33 if save_as or not self._activeDocument:
34 self._activeDocument = document.Document(filePath)
35
36 text = str(data)
37 if save_as or not self._activeDocument.compare(text):
38 # compare is not evaluated if save_as is True
39 self._activeDocument.data = text
40 self._activeDocument.save()
41
42 return self._activeDocument
43
45 self._activeDocument = None
saveDocument(self, data, filePath, save_as=False)