mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-06-01 10:39:34 +12:00
Fix loading characters and improve access to outline items
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
parent
172a5b6b1c
commit
d15871676c
|
@ -144,6 +144,9 @@ class Characters:
|
||||||
def load(self):
|
def load(self):
|
||||||
self.data.clear()
|
self.data.clear()
|
||||||
|
|
||||||
|
if not os.path.isdir(self.dir_path):
|
||||||
|
return
|
||||||
|
|
||||||
for filename in os.listdir(self.dir_path):
|
for filename in os.listdir(self.dir_path):
|
||||||
path = os.path.join(self.dir_path, filename)
|
path = os.path.join(self.dir_path, filename)
|
||||||
|
|
||||||
|
@ -160,5 +163,9 @@ class Characters:
|
||||||
self.data[character.UID.value] = character
|
self.data[character.UID.value] = character
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
if not self.data:
|
||||||
|
return
|
||||||
|
|
||||||
|
os.makedirs(self.dir_path, exist_ok=True)
|
||||||
for character in self.data.values():
|
for character in self.data.values():
|
||||||
character.save()
|
character.save()
|
||||||
|
|
|
@ -238,11 +238,15 @@ class Outline:
|
||||||
self.labels = labels
|
self.labels = labels
|
||||||
self.statuses = statuses
|
self.statuses = statuses
|
||||||
self.items = list()
|
self.items = list()
|
||||||
|
self.cache = dict()
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self.items.__iter__()
|
return self.items.__iter__()
|
||||||
|
|
||||||
def getItemByID(self, ID: int) -> OutlineItem | None:
|
def getItemByID(self, ID: int) -> OutlineItem | None:
|
||||||
|
if ID in self.cache:
|
||||||
|
return self.cache.get(ID)
|
||||||
|
|
||||||
for item in self.all():
|
for item in self.all():
|
||||||
if item.UID.value == ID:
|
if item.UID.value == ID:
|
||||||
return item
|
return item
|
||||||
|
@ -255,6 +259,7 @@ class Outline:
|
||||||
|
|
||||||
while len(queue) > 0:
|
while len(queue) > 0:
|
||||||
item = queue.pop()
|
item = queue.pop()
|
||||||
|
self.cache[item.UID.value] = item
|
||||||
|
|
||||||
if type(item) is OutlineFolder:
|
if type(item) is OutlineFolder:
|
||||||
for child in item:
|
for child in item:
|
||||||
|
@ -289,6 +294,7 @@ class Outline:
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
self.items.clear()
|
self.items.clear()
|
||||||
|
self.cache.clear()
|
||||||
|
|
||||||
names = os.listdir(self.dir_path)
|
names = os.listdir(self.dir_path)
|
||||||
names.sort()
|
names.sort()
|
||||||
|
|
Loading…
Reference in a new issue