Added file preview before sending message
This commit is contained in:
parent
5420bcb92d
commit
9ccf46663d
@ -150,11 +150,12 @@ def delete_model(self, model_name):
|
|||||||
|
|
||||||
# REMOVE IMAGE | WORKS
|
# REMOVE IMAGE | WORKS
|
||||||
|
|
||||||
def remove_attached_file_response(self, dialog, task, button):
|
def remove_attached_file_response(self, dialog, task, name):
|
||||||
if dialog.choose_finish(task) == 'remove':
|
if dialog.choose_finish(task) == 'remove':
|
||||||
self.remove_attached_file(button)
|
self.remove_attached_file(name)
|
||||||
|
|
||||||
def remove_attached_file(self, button):
|
def remove_attached_file(self, name):
|
||||||
|
self.file_preview_dialog.close()
|
||||||
dialog = Adw.AlertDialog(
|
dialog = Adw.AlertDialog(
|
||||||
heading=_("Remove Attachment?"),
|
heading=_("Remove Attachment?"),
|
||||||
body=_("Are you sure you want to remove attachment?"),
|
body=_("Are you sure you want to remove attachment?"),
|
||||||
@ -166,7 +167,7 @@ def remove_attached_file(self, button):
|
|||||||
dialog.choose(
|
dialog.choose(
|
||||||
parent = self,
|
parent = self,
|
||||||
cancellable = None,
|
cancellable = None,
|
||||||
callback = lambda dialog, task, button=button: remove_attached_file_response(self, dialog, task, button)
|
callback = lambda dialog, task, name=name: remove_attached_file_response(self, dialog, task, name)
|
||||||
)
|
)
|
||||||
|
|
||||||
# RECONNECT REMOTE | WORKS
|
# RECONNECT REMOTE | WORKS
|
||||||
|
@ -107,6 +107,7 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
model_tag_list_box = Gtk.Template.Child()
|
model_tag_list_box = Gtk.Template.Child()
|
||||||
navigation_view_manage_models = Gtk.Template.Child()
|
navigation_view_manage_models = Gtk.Template.Child()
|
||||||
file_preview_open_button = Gtk.Template.Child()
|
file_preview_open_button = Gtk.Template.Child()
|
||||||
|
file_preview_remove_button = Gtk.Template.Child()
|
||||||
secondary_menu_button = Gtk.Template.Child()
|
secondary_menu_button = Gtk.Template.Child()
|
||||||
model_searchbar = Gtk.Template.Child()
|
model_searchbar = Gtk.Template.Child()
|
||||||
no_results_page = Gtk.Template.Child()
|
no_results_page = Gtk.Template.Child()
|
||||||
@ -488,9 +489,14 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
self.editing_message = {"text_view": text_view, "id": id, "button_container": button_container, "footer": footer}
|
self.editing_message = {"text_view": text_view, "id": id, "button_container": button_container, "footer": footer}
|
||||||
|
|
||||||
def preview_file(self, file_path, file_type):
|
def preview_file(self, file_path, file_type, presend_name):
|
||||||
file_path = file_path.replace("{selected_chat}", self.chats["selected_chat"])
|
file_path = file_path.replace("{selected_chat}", self.chats["selected_chat"])
|
||||||
content = self.get_content_of_file(file_path, file_type)
|
content = self.get_content_of_file(file_path, file_type)
|
||||||
|
if presend_name:
|
||||||
|
self.file_preview_remove_button.set_visible(True)
|
||||||
|
self.file_preview_remove_button.connect('clicked', lambda button, name=presend_name : dialogs.remove_attached_file(self, name))
|
||||||
|
else:
|
||||||
|
self.file_preview_remove_button.set_visible(False)
|
||||||
if content:
|
if content:
|
||||||
buffer = self.file_preview_text_view.get_buffer()
|
buffer = self.file_preview_text_view.get_buffer()
|
||||||
buffer.delete(buffer.get_start_iter(), buffer.get_end_iter())
|
buffer.delete(buffer.get_start_iter(), buffer.get_end_iter())
|
||||||
@ -688,7 +694,7 @@ Generate a title following these rules:
|
|||||||
child=button_content
|
child=button_content
|
||||||
)
|
)
|
||||||
file_path = os.path.join(self.data_dir, "chats", "{selected_chat}", id, name)
|
file_path = os.path.join(self.data_dir, "chats", "{selected_chat}", id, name)
|
||||||
button.connect("clicked", lambda button, file_path=file_path, file_type=file_type: self.preview_file(file_path, file_type))
|
button.connect("clicked", lambda button, file_path=file_path, file_type=file_type: self.preview_file(file_path, file_type, None))
|
||||||
file_container.append(button)
|
file_container.append(button)
|
||||||
message_box.append(file_scroller)
|
message_box.append(file_scroller)
|
||||||
|
|
||||||
@ -1330,17 +1336,18 @@ Generate a title following these rules:
|
|||||||
text += f"\n- Page {i}\n{page.extract_text()}\n"
|
text += f"\n- Page {i}\n{page.extract_text()}\n"
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def remove_attached_file(self, button):
|
def remove_attached_file(self, name):
|
||||||
del self.attachments[button.get_name()]
|
button = self.attachments[name]['button']
|
||||||
button.get_parent().remove(button)
|
button.get_parent().remove(button)
|
||||||
|
del self.attachments[name]
|
||||||
if len(self.attachments) == 0: self.attachment_box.set_visible(False)
|
if len(self.attachments) == 0: self.attachment_box.set_visible(False)
|
||||||
|
|
||||||
def attach_file(self, file_path, file_type):
|
def attach_file(self, file_path, file_type):
|
||||||
name = self.generate_numbered_name(os.path.basename(file_path), self.attachments.keys())
|
file_name = self.generate_numbered_name(os.path.basename(file_path), self.attachments.keys())
|
||||||
content = self.get_content_of_file(file_path, file_type)
|
content = self.get_content_of_file(file_path, file_type)
|
||||||
if content:
|
if content:
|
||||||
button_content = Adw.ButtonContent(
|
button_content = Adw.ButtonContent(
|
||||||
label=name,
|
label=file_name,
|
||||||
icon_name={
|
icon_name={
|
||||||
"image": "image-x-generic-symbolic",
|
"image": "image-x-generic-symbolic",
|
||||||
"plain_text": "document-text-symbolic",
|
"plain_text": "document-text-symbolic",
|
||||||
@ -1352,13 +1359,14 @@ Generate a title following these rules:
|
|||||||
button = Gtk.Button(
|
button = Gtk.Button(
|
||||||
vexpand=True,
|
vexpand=True,
|
||||||
valign=3,
|
valign=3,
|
||||||
name=name,
|
name=file_name,
|
||||||
css_classes=["flat"],
|
css_classes=["flat"],
|
||||||
tooltip_text=name,
|
tooltip_text=file_name,
|
||||||
child=button_content
|
child=button_content
|
||||||
)
|
)
|
||||||
self.attachments[name] = {"path": file_path, "type": file_type, "content": content, "button": button}
|
self.attachments[file_name] = {"path": file_path, "type": file_type, "content": content, "button": button}
|
||||||
button.connect("clicked", lambda button: dialogs.remove_attached_file(self, button))
|
#button.connect("clicked", lambda button: dialogs.remove_attached_file(self, button))
|
||||||
|
button.connect("clicked", lambda button : self.preview_file(file_path, file_type, file_name))
|
||||||
self.attachment_container.append(button)
|
self.attachment_container.append(button)
|
||||||
self.attachment_box.set_visible(True)
|
self.attachment_box.set_visible(True)
|
||||||
|
|
||||||
|
@ -744,12 +744,20 @@
|
|||||||
<child type="start">
|
<child type="start">
|
||||||
<object class="GtkButton" id="file_preview_open_button">
|
<object class="GtkButton" id="file_preview_open_button">
|
||||||
<signal name="clicked" handler="link_button_handler"/>
|
<signal name="clicked" handler="link_button_handler"/>
|
||||||
<property name="tooltip-text" translatable="yes">Open with Default App</property>
|
<property name="tooltip-text" translatable="yes">Open With Default App</property>
|
||||||
<property name="vexpand">false</property>
|
<property name="vexpand">false</property>
|
||||||
<property name="valign">3</property>
|
<property name="valign">3</property>
|
||||||
<property name="icon-name">share-symbolic</property>
|
<property name="icon-name">share-symbolic</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child type="start">
|
||||||
|
<object class="GtkButton" id="file_preview_remove_button">
|
||||||
|
<property name="tooltip-text" translatable="yes">Remove Attachment</property>
|
||||||
|
<property name="vexpand">false</property>
|
||||||
|
<property name="valign">3</property>
|
||||||
|
<property name="icon-name">user-trash-symbolic</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user