User can now delete last chat, this would create a 'New Chat' chat
This commit is contained in:
parent
208e24b17e
commit
d8138a80de
@ -650,9 +650,9 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
with open(os.path.join(self.config_dir, "chats.json"), "r") as f:
|
with open(os.path.join(self.config_dir, "chats.json"), "r") as f:
|
||||||
self.chats = json.load(f)
|
self.chats = json.load(f)
|
||||||
if "selected_chat" not in self.chats or self.chats["selected_chat"] not in self.chats["chats"]: self.chats["selected_chat"] = list(self.chats["chats"].keys())[0]
|
if "selected_chat" not in self.chats or self.chats["selected_chat"] not in self.chats["chats"]: self.chats["selected_chat"] = list(self.chats["chats"].keys())[0]
|
||||||
if len(list(self.chats["chats"].keys())) == 0: self.chats["chats"]["New chat"] = {"messages": []}
|
if len(list(self.chats["chats"].keys())) == 0: self.chats["chats"]["New Chat"] = {"messages": []}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.chats = {"chats": {"New chat": {"messages": []}}, "selected_chat": "New chat"}
|
self.chats = {"chats": {"New Chat": {"messages": []}}, "selected_chat": "New Chat"}
|
||||||
self.load_history_into_chat()
|
self.load_history_into_chat()
|
||||||
|
|
||||||
def load_image(self, file_dialog, result):
|
def load_image(self, file_dialog, result):
|
||||||
@ -710,11 +710,10 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
del self.chats['chats'][chat_name]
|
del self.chats['chats'][chat_name]
|
||||||
self.save_history()
|
self.save_history()
|
||||||
self.update_chat_list()
|
self.update_chat_list()
|
||||||
|
if len(self.chats['chats'])==0:
|
||||||
|
self.chat_new()
|
||||||
|
|
||||||
def chat_delete_dialog(self, chat_name):
|
def chat_delete_dialog(self, chat_name):
|
||||||
if len(self.chats['chats'])==1:
|
|
||||||
self.show_toast("error", 6, self.main_overlay)
|
|
||||||
return
|
|
||||||
dialog = Adw.AlertDialog(
|
dialog = Adw.AlertDialog(
|
||||||
heading=_("Delete Chat"),
|
heading=_("Delete Chat"),
|
||||||
body=_("Are you sure you want to delete '{}'?").format(chat_name),
|
body=_("Are you sure you want to delete '{}'?").format(chat_name),
|
||||||
@ -741,7 +740,6 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
self.save_history()
|
self.save_history()
|
||||||
self.update_chat_list()
|
self.update_chat_list()
|
||||||
|
|
||||||
|
|
||||||
def chat_rename_dialog(self, chat_name:str, body:str, error:bool=False):
|
def chat_rename_dialog(self, chat_name:str, body:str, error:bool=False):
|
||||||
entry = Gtk.Entry(
|
entry = Gtk.Entry(
|
||||||
css_classes = ["error"] if error else None
|
css_classes = ["error"] if error else None
|
||||||
@ -763,8 +761,9 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def chat_new(self, dialog=None, task=None, entry=None):
|
def chat_new(self, dialog=None, task=None, entry=None):
|
||||||
if not entry: return
|
#if not entry: return
|
||||||
chat_name = entry.get_text()
|
chat_name = None
|
||||||
|
if entry is not None: chat_name = entry.get_text()
|
||||||
if not chat_name:
|
if not chat_name:
|
||||||
chat_name=_("New Chat")
|
chat_name=_("New Chat")
|
||||||
if chat_name in self.chats["chats"]:
|
if chat_name in self.chats["chats"]:
|
||||||
@ -773,7 +772,7 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
chat_name += f" {i+1}"
|
chat_name += f" {i+1}"
|
||||||
break
|
break
|
||||||
if not task or dialog.choose_finish(task) == "create":
|
if not task or dialog.choose_finish(task) == "create":
|
||||||
dialog.force_close()
|
if dialog is not None: dialog.force_close()
|
||||||
if chat_name in self.chats["chats"]: self.chat_new_dialog(_("The name '{}' is already in use").format(chat_name), True)
|
if chat_name in self.chats["chats"]: self.chat_new_dialog(_("The name '{}' is already in use").format(chat_name), True)
|
||||||
else:
|
else:
|
||||||
self.chats["chats"][chat_name] = {"messages": []}
|
self.chats["chats"][chat_name] = {"messages": []}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user