Delete message feature
This commit is contained in:
parent
46b43ca670
commit
db0daa1f41
@ -19,3 +19,10 @@
|
|||||||
.chat_row:hover button {
|
.chat_row:hover button {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
.message .delete-message-button {
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity .05s;
|
||||||
|
}
|
||||||
|
.message:hover .delete-message-button {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
@ -53,6 +53,7 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
local_ollama_instance = None
|
local_ollama_instance = None
|
||||||
local_models = []
|
local_models = []
|
||||||
pulling_models = {}
|
pulling_models = {}
|
||||||
|
current_chat_elements = [] #Used for deleting
|
||||||
chats = {"chats": {_("New Chat"): {"messages": []}}, "selected_chat": "New Chat"}
|
chats = {"chats": {_("New Chat"): {"messages": []}}, "selected_chat": "New Chat"}
|
||||||
attached_image = {"path": None, "base64": None}
|
attached_image = {"path": None, "base64": None}
|
||||||
first_time_setup = False
|
first_time_setup = False
|
||||||
@ -139,6 +140,13 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
if icon: notification.set_icon(icon)
|
if icon: notification.set_icon(icon)
|
||||||
self.get_application().send_notification(None, notification)
|
self.get_application().send_notification(None, notification)
|
||||||
|
|
||||||
|
def delete_message(self, message_element):
|
||||||
|
message_index = self.current_chat_elements.index(message_element)
|
||||||
|
del self.chats["chats"][self.chats["selected_chat"]]["messages"][message_index]
|
||||||
|
self.chat_container.remove(message_element)
|
||||||
|
del self.current_chat_elements[message_index]
|
||||||
|
self.save_history()
|
||||||
|
|
||||||
def show_message(self, msg:str, bot:bool, footer:str=None, image_base64:str=None):
|
def show_message(self, msg:str, bot:bool, footer:str=None, image_base64:str=None):
|
||||||
message_text = Gtk.TextView(
|
message_text = Gtk.TextView(
|
||||||
editable=False,
|
editable=False,
|
||||||
@ -157,7 +165,7 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
delete_button = Gtk.Button(
|
delete_button = Gtk.Button(
|
||||||
icon_name = "user-trash-symbolic",
|
icon_name = "user-trash-symbolic",
|
||||||
css_classes = ["flat", "circular"],
|
css_classes = ["flat", "circular", "delete-message-button"],
|
||||||
valign="end",
|
valign="end",
|
||||||
halign="end",
|
halign="end",
|
||||||
margin_bottom=6,
|
margin_bottom=6,
|
||||||
@ -190,12 +198,12 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
message_box.append(image)
|
message_box.append(image)
|
||||||
|
|
||||||
message_box.append(message_text)
|
message_box.append(message_text)
|
||||||
message_overlay = Gtk.Overlay()
|
self.current_chat_elements.append(Gtk.Overlay(css_classes=["message"]))
|
||||||
message_overlay.set_child(message_box)
|
self.current_chat_elements[-1].set_child(message_box)
|
||||||
#message_overlay.add_overlay(delete_button)
|
|
||||||
# I don't have the energy right now to do this :)
|
delete_button.connect("clicked", lambda button, element=self.current_chat_elements[-1]: self.delete_message(element))
|
||||||
## TODO IDEA: I could count which message it is I'm trying to delete, that way I could get the position on the list, this is probably the best approach, good luck me from the future.
|
self.current_chat_elements[-1].add_overlay(delete_button)
|
||||||
self.chat_container.append(message_overlay)
|
self.chat_container.append(self.current_chat_elements[-1])
|
||||||
|
|
||||||
if bot:
|
if bot:
|
||||||
self.bot_message = message_buffer
|
self.bot_message = message_buffer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user