New chat order backend system / fixed secondary menu not working if context menu was cancelled
This commit is contained in:
parent
6a825f534f
commit
107ef2c3d0
@ -23,7 +23,7 @@ import gi
|
|||||||
gi.require_version('Gtk', '4.0')
|
gi.require_version('Gtk', '4.0')
|
||||||
gi.require_version('Adw', '1')
|
gi.require_version('Adw', '1')
|
||||||
|
|
||||||
from gi.repository import Gtk, Gio, Adw
|
from gi.repository import Gtk, Gio, Adw, GLib
|
||||||
from .window import AlpacaWindow
|
from .window import AlpacaWindow
|
||||||
|
|
||||||
class AlpacaApplication(Adw.Application):
|
class AlpacaApplication(Adw.Application):
|
||||||
|
@ -953,6 +953,7 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
def delete_chat(self, chat_name):
|
def delete_chat(self, chat_name):
|
||||||
del self.chats['chats'][chat_name]
|
del self.chats['chats'][chat_name]
|
||||||
|
self.chats['order'].remove(chat_name)
|
||||||
if os.path.exists(os.path.join(self.data_dir, "chats", self.chats['selected_chat'])):
|
if os.path.exists(os.path.join(self.data_dir, "chats", self.chats['selected_chat'])):
|
||||||
shutil.rmtree(os.path.join(self.data_dir, "chats", self.chats['selected_chat']))
|
shutil.rmtree(os.path.join(self.data_dir, "chats", self.chats['selected_chat']))
|
||||||
self.save_history()
|
self.save_history()
|
||||||
@ -966,6 +967,7 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
new_chat_name = self.generate_numbered_name(new_chat_name, self.chats["chats"].keys())
|
new_chat_name = self.generate_numbered_name(new_chat_name, self.chats["chats"].keys())
|
||||||
if self.chats["selected_chat"] == old_chat_name: self.chats["selected_chat"] = new_chat_name
|
if self.chats["selected_chat"] == old_chat_name: self.chats["selected_chat"] = new_chat_name
|
||||||
self.chats["chats"][new_chat_name] = self.chats["chats"][old_chat_name]
|
self.chats["chats"][new_chat_name] = self.chats["chats"][old_chat_name]
|
||||||
|
self.chats["order"][self.chats["order"].index(old_chat_name)] = new_chat_name
|
||||||
del self.chats["chats"][old_chat_name]
|
del self.chats["chats"][old_chat_name]
|
||||||
if os.path.exists(os.path.join(self.data_dir, "chats", old_chat_name)):
|
if os.path.exists(os.path.join(self.data_dir, "chats", old_chat_name)):
|
||||||
shutil.move(os.path.join(self.data_dir, "chats", old_chat_name), os.path.join(self.data_dir, "chats", new_chat_name))
|
shutil.move(os.path.join(self.data_dir, "chats", old_chat_name), os.path.join(self.data_dir, "chats", new_chat_name))
|
||||||
@ -976,8 +978,9 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
def new_chat(self):
|
def new_chat(self):
|
||||||
chat_name = self.generate_numbered_name(_("New Chat"), self.chats["chats"].keys())
|
chat_name = self.generate_numbered_name(_("New Chat"), self.chats["chats"].keys())
|
||||||
self.chats["chats"][chat_name] = {"messages": {}}
|
self.chats["chats"][chat_name] = {"messages": {}}
|
||||||
|
self.chats["order"].insert(0, chat_name)
|
||||||
self.save_history()
|
self.save_history()
|
||||||
self.new_chat_element(chat_name, True)
|
self.new_chat_element(chat_name, True, False)
|
||||||
|
|
||||||
def stop_pull_model(self, model_name):
|
def stop_pull_model(self, model_name):
|
||||||
self.pulling_models[model_name]['overlay'].get_parent().get_parent().remove(self.pulling_models[model_name]['overlay'].get_parent())
|
self.pulling_models[model_name]['overlay'].get_parent().get_parent().remove(self.pulling_models[model_name]['overlay'].get_parent())
|
||||||
@ -999,7 +1002,7 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
has_arrow=False,
|
has_arrow=False,
|
||||||
halign=1,
|
halign=1,
|
||||||
)
|
)
|
||||||
self.right_clicked_chat_row = chat_row
|
self.selected_chat_row = chat_row
|
||||||
position = Gdk.Rectangle()
|
position = Gdk.Rectangle()
|
||||||
position.x = x
|
position.x = x
|
||||||
position.y = y
|
position.y = y
|
||||||
@ -1007,7 +1010,7 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
popover.set_pointing_to(position)
|
popover.set_pointing_to(position)
|
||||||
popover.popup()
|
popover.popup()
|
||||||
|
|
||||||
def new_chat_element(self, chat_name:str, select:bool):
|
def new_chat_element(self, chat_name:str, select:bool, append:bool):
|
||||||
chat_label = Gtk.Label(
|
chat_label = Gtk.Label(
|
||||||
label=chat_name,
|
label=chat_name,
|
||||||
hexpand=True,
|
hexpand=True,
|
||||||
@ -1028,13 +1031,15 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
gesture.connect("released", self.chat_click_handler)
|
gesture.connect("released", self.chat_click_handler)
|
||||||
chat_row.add_controller(gesture)
|
chat_row.add_controller(gesture)
|
||||||
|
|
||||||
self.chat_list_box.append(chat_row)
|
if append: self.chat_list_box.append(chat_row)
|
||||||
|
else: self.chat_list_box.prepend(chat_row)
|
||||||
if select: self.chat_list_box.select_row(chat_row)
|
if select: self.chat_list_box.select_row(chat_row)
|
||||||
|
|
||||||
def update_chat_list(self):
|
def update_chat_list(self):
|
||||||
self.chat_list_box.remove_all()
|
self.chat_list_box.remove_all()
|
||||||
for name, content in self.chats['chats'].items():
|
for name in self.chats['order']:
|
||||||
self.new_chat_element(name, self.chats["selected_chat"] == name)
|
if name in self.chats['chats'].keys():
|
||||||
|
self.new_chat_element(name, self.chats["selected_chat"] == name, True)
|
||||||
|
|
||||||
def show_preferences_dialog(self):
|
def show_preferences_dialog(self):
|
||||||
self.preferences_dialog.present(self)
|
self.preferences_dialog.present(self)
|
||||||
@ -1235,20 +1240,20 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
self.attachment_box.set_visible(True)
|
self.attachment_box.set_visible(True)
|
||||||
|
|
||||||
def chat_actions(self, action, user_data):
|
def chat_actions(self, action, user_data):
|
||||||
action_name = action.get_name()
|
chat_row = self.selected_chat_row
|
||||||
if self.right_clicked_chat_row:
|
|
||||||
chat_row = self.right_clicked_chat_row
|
|
||||||
else:
|
|
||||||
chat_row = self.chat_list_box.get_selected_row()
|
|
||||||
chat_name = chat_row.get_name()
|
chat_name = chat_row.get_name()
|
||||||
self.right_clicked_chat_row = None
|
action_name = action.get_name()
|
||||||
if action_name == 'delete_chat':
|
if action_name == 'delete_chat':
|
||||||
dialogs.delete_chat(self, chat_name)
|
dialogs.delete_chat(self, chat_name)
|
||||||
elif action_name == 'rename_chat':
|
elif action_name in ('rename_chat', 'rename_current_chat'):
|
||||||
dialogs.rename_chat(self, chat_name, chat_row.get_child())
|
dialogs.rename_chat(self, chat_name, chat_row.get_child())
|
||||||
elif action_name == 'export_chat':
|
elif action_name in ('export_chat', 'export_current_chat'):
|
||||||
self.export_chat(chat_name)
|
self.export_chat(chat_name)
|
||||||
|
|
||||||
|
def current_chat_actions(self, action, user_data):
|
||||||
|
self.selected_chat_row = self.chat_list_box.get_selected_row()
|
||||||
|
self.chat_actions(action, user_data)
|
||||||
|
|
||||||
def text_received(self, clipboard, result):
|
def text_received(self, clipboard, result):
|
||||||
text = clipboard.read_text_finish(result)
|
text = clipboard.read_text_finish(result)
|
||||||
#Check if text is a Youtube URL
|
#Check if text is a Youtube URL
|
||||||
@ -1302,7 +1307,9 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
self.get_application().create_action('create_model_from_file', lambda *_: dialogs.create_model_from_file(self))
|
self.get_application().create_action('create_model_from_file', lambda *_: dialogs.create_model_from_file(self))
|
||||||
self.get_application().create_action('delete_chat', self.chat_actions)
|
self.get_application().create_action('delete_chat', self.chat_actions)
|
||||||
self.get_application().create_action('rename_chat', self.chat_actions)
|
self.get_application().create_action('rename_chat', self.chat_actions)
|
||||||
|
self.get_application().create_action('rename_current_chat', self.current_chat_actions, ['F2'])
|
||||||
self.get_application().create_action('export_chat', self.chat_actions)
|
self.get_application().create_action('export_chat', self.chat_actions)
|
||||||
|
self.get_application().create_action('export_current_chat', self.current_chat_actions)
|
||||||
self.message_text_view.connect("paste-clipboard", self.on_clipboard_paste)
|
self.message_text_view.connect("paste-clipboard", self.on_clipboard_paste)
|
||||||
self.add_chat_button.connect("clicked", lambda button : self.new_chat())
|
self.add_chat_button.connect("clicked", lambda button : self.new_chat())
|
||||||
self.attachment_button.connect("clicked", lambda button, file_filter=self.file_filter_attachments: dialogs.attach_file(self, file_filter))
|
self.attachment_button.connect("clicked", lambda button, file_filter=self.file_filter_attachments: dialogs.attach_file(self, file_filter))
|
||||||
|
@ -934,11 +934,11 @@
|
|||||||
<menu id="secondary_menu">
|
<menu id="secondary_menu">
|
||||||
<item>
|
<item>
|
||||||
<attribute name="label" translatable="yes">Rename chat</attribute>
|
<attribute name="label" translatable="yes">Rename chat</attribute>
|
||||||
<attribute name="action">app.rename_chat</attribute>
|
<attribute name="action">app.rename_current_chat</attribute>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<attribute name="label" translatable="yes">Export chat</attribute>
|
<attribute name="label" translatable="yes">Export chat</attribute>
|
||||||
<attribute name="action">app.export_chat</attribute>
|
<attribute name="action">app.export_current_chat</attribute>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<attribute name="label" translatable="yes">Clear chat</attribute>
|
<attribute name="label" translatable="yes">Clear chat</attribute>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user