mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-16 19:02:32 +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):
|
||||
self.data.clear()
|
||||
|
||||
if not os.path.isdir(self.dir_path):
|
||||
return
|
||||
|
||||
for filename in os.listdir(self.dir_path):
|
||||
path = os.path.join(self.dir_path, filename)
|
||||
|
||||
|
@ -160,5 +163,9 @@ class Characters:
|
|||
self.data[character.UID.value] = character
|
||||
|
||||
def save(self):
|
||||
if not self.data:
|
||||
return
|
||||
|
||||
os.makedirs(self.dir_path, exist_ok=True)
|
||||
for character in self.data.values():
|
||||
character.save()
|
||||
|
|
|
@ -238,11 +238,15 @@ class Outline:
|
|||
self.labels = labels
|
||||
self.statuses = statuses
|
||||
self.items = list()
|
||||
self.cache = dict()
|
||||
|
||||
def __iter__(self):
|
||||
return self.items.__iter__()
|
||||
|
||||
def getItemByID(self, ID: int) -> OutlineItem | None:
|
||||
if ID in self.cache:
|
||||
return self.cache.get(ID)
|
||||
|
||||
for item in self.all():
|
||||
if item.UID.value == ID:
|
||||
return item
|
||||
|
@ -255,6 +259,7 @@ class Outline:
|
|||
|
||||
while len(queue) > 0:
|
||||
item = queue.pop()
|
||||
self.cache[item.UID.value] = item
|
||||
|
||||
if type(item) is OutlineFolder:
|
||||
for child in item:
|
||||
|
@ -289,6 +294,7 @@ class Outline:
|
|||
|
||||
def load(self):
|
||||
self.items.clear()
|
||||
self.cache.clear()
|
||||
|
||||
names = os.listdir(self.dir_path)
|
||||
names.sort()
|
||||
|
|
Loading…
Reference in a new issue