Skip to content

Commit

Permalink
Merge pull request henk717#315 from jojorne/jojorne-patch-enable-rena…
Browse files Browse the repository at this point in the history
…ming-deleting-wi-root-folder

Enable renaming/deleting wi root folder by creating a new one
  • Loading branch information
henk717 authored Mar 26, 2023
2 parents bbb554e + 8378ff9 commit 37c3fd0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions koboldai_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2260,16 +2260,16 @@ def add_folder(self, folder):
self._socketio.emit("world_info_folder", {x: self.world_info_folder[x] for x in self.world_info_folder}, broadcast=True, room="UI_2")

def delete_folder(self, folder):
if folder == "root":
raise Exception("removing the root folder is not supported")
keys = [key for key in self.world_info]
for key in keys:
if self.world_info[key]['folder'] == folder:
self.delete(key)
if folder in self.world_info_folder:
del self.world_info_folder[folder]
self.sync_world_info_to_old_format()
if self._socketio is not None:
self._socketio.emit("delete_world_info_folder", folder, broadcast=True, room="UI_2")
self._socketio.emit("world_info_folder", {x: self.world_info_folder[x] for x in self.world_info_folder}, broadcast=True, room="UI_2")
logger.debug("Calcing AI Text from WI Folder Delete")
ignore = self._koboldai_vars.calc_ai_text()

Expand Down Expand Up @@ -2446,9 +2446,6 @@ def edit_item(
self._socketio.emit("world_info_entry", self.world_info[uid], broadcast=True, room="UI_2")

def delete(self, uid):
if self.world_info[uid]['folder'] == "root":
raise Exception("removing the root folder is not supported")

del self.world_info[uid]

try:
Expand All @@ -2470,8 +2467,6 @@ def delete(self, uid):
ignore = self._koboldai_vars.calc_ai_text()

def rename_folder(self, old_folder, folder):
if old_folder == "root":
raise Exception("renaming the root folder is not supported")
self.story_settings.gamesaved = False
if folder in self.world_info_folder:
i=0
Expand All @@ -2498,7 +2493,8 @@ def rename_folder(self, old_folder, folder):
self.story_settings.gamesaved = False
self.sync_world_info_to_old_format()
if self._socketio is not None:
self._socketio.emit("world_info_folder", {x: self.world_info_folder[x] for x in self.world_info_folder}, broadcast=True, room="UI_2")
self._socketio.emit("delete_world_info_folder", old_folder, broadcast=True, room="UI_2")
self.send_to_ui()

def reorder(self, uid, before):
self.add_item_to_folder(uid, self.world_info[before]['folder'], before=before)
Expand Down Expand Up @@ -2576,6 +2572,11 @@ def load_json(self, data, folder=None):

def sync_world_info_to_old_format(self):
#Since the old UI uses world info entries for folders, we need to make some up
if "root" not in self.world_info_folder:
old_world_info_folder = self.world_info_folder
self.world_info_folder = OrderedDict()
self.world_info_folder["root"] = []
self.world_info_folder.update(old_world_info_folder)
folder_entries = {}
i=-1
for folder in self.world_info_folder:
Expand Down

0 comments on commit 37c3fd0

Please sign in to comment.